@nextgis/geocoder 2.2.3 → 2.3.0

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
- var Geocoder=function(e){"use strict";var t=Object.defineProperty,r=(e,r,n)=>(((e,r,n)=>{r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n})(e,"symbol"!=typeof r?r+"":r,n),n);class n extends Error{constructor(){super(),r(this,"name","CancelError"),Object.setPrototypeOf(this,n.prototype)}}var s=Object.defineProperty,o=(e,t,r)=>(((e,t,r)=>{t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class i{constructor(e={}){this.options=e,o(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()}}var a=Object.defineProperty,c=(e,t,r)=>(((e,t,r)=>{t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class l extends Error{constructor(){super(),c(this,"name","TimeoutError"),Object.setPrototypeOf(this,l.prototype)}}var u,h=Object.defineProperty,f=(e,t,r)=>(((e,t,r)=>{t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);const p=(e,t,r,n)=>{try{e(r(n))}catch(s){t(s)}};let d=0;const y=class e{constructor(t,r){f(this,u),f(this,"id",d++),f(this,"_isCanceled",!1),f(this,"_isPending",!0),f(this,"_promise"),f(this,"_cancelPromise"),f(this,"_cancelHandlers",[]),f(this,"_setCanceledCallback"),f(this,"_parentPromise"),f(this,"_children",[]),this._cancelPromise=new Promise(((e,t)=>{this._setCanceledCallback=t=>e(t||new n)}));const s=[this._cancelPromise,new Promise(((r,n)=>t((t=>{t instanceof e?this.attach(t):this._isPending=!1,r(t)}),(e=>{this._isPending=!1,n(e)}),(e=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(e)}))))];r&&s.push(new Promise(((e,t)=>{setTimeout((()=>{if(this._isPending)try{this.cancel()}finally{t(new l)}}),r)}))),this._promise=Promise.race(s)}static createControl(e){return new i(e)}static resolve(t){return new e((e=>e(t)))}static reject(t){return new e(((e,r)=>r(t)))}static all(t){return new e(((e,r)=>{Promise.all(t).then(e).catch(r)})).catch((e=>{if(e instanceof this.CancelError)for(const r of t){"cancel"in r&&r.cancel()}throw e}))}attach(e){this._isCanceled?e.cancel():this._children.push(e)}then(t,r){const n=new e(((e,n)=>{if(this._promise){const s=t=>{r?p(e,n,r,t):n(t)};this._promise.then((r=>{this._isCanceled?s(r):t?p(e,n,t,r):e(r)}),s)}}));return n._parentPromise=this,this._children.push(n),n}catch(e){return this._isCanceled&&e&&e(new n),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new n:e)}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}};u=Symbol.toStringTag,f(y,"CancelError",n),f(y,"TimeoutError",l),f(y,"PromiseControl",i);let m=y;function v(e){return null!=e}function g(e){return"string"==typeof e?!!e:v(e)}function b(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:w(e,t));return e===t}function w(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(!b(e[r[s]],t[n[s]],e,t))return!1}return!0}function _(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]=_(e[r])})),t}function O(e){return e.replace(/([^:]\/)\/+/g,"$1")}Object.setPrototypeOf(m.prototype,Promise.prototype);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)}}var j=Object.defineProperty,x=Object.defineProperties,E=Object.getOwnPropertyDescriptors,C=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,L=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),k=(e,t,r)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,S=(e,t)=>{for(var r in t||(t={}))R.call(t,r)&&k(e,r,t[r]);if(C)for(var r of C(t))I.call(t,r)&&k(e,r,t[r]);return e},q=(e,t)=>x(e,E(t)),T=function(e,t){this[0]=e,this[1]=t},A=(e,t,r)=>{var n=(e,t,s,o)=>{try{var i=r[e](t),a=(t=i.value)instanceof T,c=i.done;Promise.resolve(a?t[0]:t).then((r=>a?n("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,s,o):s({value:r,done:c}))).catch((e=>n("throw",e,s,o)))}catch(l){o(l)}},s=e=>o[e]=t=>new Promise(((r,s)=>n(e,t,r,s))),o={};return r=r.apply(e,t),o[L("asyncIterator")]=()=>o,s("next"),s("throw"),s("return"),o},U=(e,t,r)=>(t=e[L("asyncIterator")])?t.call(e):(e=e[L("iterator")](),t={},(r=(r,n)=>(n=e[r])&&(t[r]=t=>new Promise(((r,s,o)=>(t=n.call(e,t),o=t.done,Promise.resolve(t.value).then((e=>r({value:e,done:o})),s))))))("next"),r("return"),t);let N=0;class F extends P{constructor(e){var t;super(e),k(this,"symbol"!=typeof(t="providers")?t+"":t,[]),e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}search(e){return A(this,null,(function*(){this.abort();let t=!0;const r=[];for(const c of this.providers)try{const r=c.search(e);try{for(var n,s,o,i=U(r);n=!(s=yield new T(i.next())).done;n=!1){const e=s.value;t=!1,yield q(S({},e),{provider:c,_id:N++})}}catch(s){o=[s]}finally{try{n&&(s=i.return)&&(yield new T(s.call(i)))}finally{if(o)throw o[0]}}}catch(a){"CancelError"!==a.name&&r.push(a)}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):m.resolve(void 0)}reverse(e){return A(this,null,(function*(){for(const i of this.providers)if(i.reverse)try{const o=i.reverse(e);try{for(var t,r,n,s=U(o);t=!(r=yield new T(s.next())).done;t=!1){const e=r.value;yield q(S({},e),{provider:i,_id:N++})}}catch(r){n=[r]}finally{try{t&&(r=s.return)&&(yield new T(r.call(s)))}finally{if(n)throw n[0]}}}catch(o){}}))}reverseGeocodeFirstResult(e){return t=this,r=null,n=function*(){for(const i of this.providers)if("function"==typeof i.reverse)try{try{for(var t,r,n,s=U(i.reverse(e));t=!(r=yield s.next()).done;t=!1)return r.value}catch(r){n=[r]}finally{try{t&&(r=s.return)&&(yield r.call(s))}finally{if(n)throw n[0]}}}catch(o){console.error("Error in reverse geocoding:",o)}},new Promise(((e,s)=>{var o=e=>{try{a(n.next(e))}catch(t){s(t)}},i=e=>{try{a(n.throw(e))}catch(t){s(t)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,i);a((n=n.apply(t,r)).next())}));var t,r,n}}var $=Object.defineProperty,M=(e,t,r)=>(((e,t,r)=>{t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class D extends P{constructor(){super(...arguments),M(this,"searchUrl"),M(this,"label")}}function H(){}function B(){B.init.call(this)}function G(e){return void 0===e._maxListeners?B.defaultMaxListeners:e._maxListeners}function z(e,t,r,n){var s,o,i,a;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),i=o[t]):(o=e._events=new H,e._eventsCount=0),i){if("function"==typeof i?i=o[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),!i.warned&&(s=G(e))&&s>0&&i.length>s){i.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=i.length,a=c,"function"==typeof console.warn?console.warn(a):console.log(a)}}else i=o[t]=r,++e._eventsCount;return e}function J(e,t,r){var n=!1;function s(){e.removeListener(t,s),n||(n=!0,r.apply(e,arguments))}return s.listener=r,s}function Q(e){var t=this._events;if(t){var r=t[e];if("function"==typeof r)return 1;if(r)return r.length}return 0}function W(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}H.prototype=Object.create(null),B.EventEmitter=B,B.usingDomains=!1,B.prototype.domain=void 0,B.prototype._events=void 0,B.prototype._maxListeners=void 0,B.defaultMaxListeners=10,B.init=function(){this.domain=null,B.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new H,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},B.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},B.prototype.getMaxListeners=function(){return G(this)},B.prototype.emit=function(e){var t,r,n,s,o,i,a,c="error"===e;if(i=this._events)c=c&&null==i.error;else if(!c)return!1;if(a=this.domain,c){if(t=arguments[1],!a){if(t instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=a,t.domainThrown=!1,a.emit("error",t),!1}if(!(r=i[e]))return!1;var u="function"==typeof r;switch(n=arguments.length){case 1:!function(e,t,r){if(t)e.call(r);else for(var n=e.length,s=W(e,n),o=0;o<n;++o)s[o].call(r)}(r,u,this);break;case 2:!function(e,t,r,n){if(t)e.call(r,n);else for(var s=e.length,o=W(e,s),i=0;i<s;++i)o[i].call(r,n)}(r,u,this,arguments[1]);break;case 3:!function(e,t,r,n,s){if(t)e.call(r,n,s);else for(var o=e.length,i=W(e,o),a=0;a<o;++a)i[a].call(r,n,s)}(r,u,this,arguments[1],arguments[2]);break;case 4:!function(e,t,r,n,s,o){if(t)e.call(r,n,s,o);else for(var i=e.length,a=W(e,i),c=0;c<i;++c)a[c].call(r,n,s,o)}(r,u,this,arguments[1],arguments[2],arguments[3]);break;default:for(s=new Array(n-1),o=1;o<n;o++)s[o-1]=arguments[o];!function(e,t,r,n){if(t)e.apply(r,n);else for(var s=e.length,o=W(e,s),i=0;i<s;++i)o[i].apply(r,n)}(r,u,this,s)}return!0},B.prototype.on=B.prototype.addListener=function(e,t){return z(this,e,t,!1)},B.prototype.prependListener=function(e,t){return z(this,e,t,!0)},B.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,J(this,e,t)),this},B.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,J(this,e,t)),this},B.prototype.removeListener=function(e,t){var r,n,s,o,i;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(n=this._events))return this;if(!(r=n[e]))return this;if(r===t||r.listener&&r.listener===t)0==--this._eventsCount?this._events=new H:(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(s=-1,o=r.length;o-- >0;)if(r[o]===t||r[o].listener&&r[o].listener===t){i=r[o].listener,s=o;break}if(s<0)return this;if(1===r.length){if(r[0]=void 0,0==--this._eventsCount)return this._events=new H,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,s=e.length;n<s;r+=1,n+=1)e[r]=e[n];e.pop()}(r,s);n.removeListener&&this.emit("removeListener",e,i||t)}return this},B.prototype.off=function(e,t){return this.removeListener(e,t)},B.prototype.removeAllListeners=function(e){var t,r;if(!(r=this._events))return this;if(!r.removeListener)return 0===arguments.length?(this._events=new H,this._eventsCount=0):r[e]&&(0==--this._eventsCount?this._events=new H:delete r[e]),this;if(0===arguments.length){for(var n,s=Object.keys(r),o=0;o<s.length;++o)"removeListener"!==(n=s[o])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=new H,this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},B.prototype.listeners=function(e){var t,r=this._events;return r&&(t=r[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(t):[]},B.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Q.call(e,t)},B.prototype.listenerCount=Q,B.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var X=Object.defineProperty,K=(e,t,r)=>(((e,t,r)=>{t in e?X(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);const V=class e{constructor(t={}){var r;K(this,"cache",[]);const n=null!=(r=t.namespace)?r:"default";return e.instance[n]?e.instance[n]:(e.instance[n]=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(_(r))),i={key:e,value:s,props:o,options:o};return n&&!g(s)?s:(this.cache.push(i),s instanceof Promise?(s.catch((t=>{throw this.delete(e,r),t})),n&&s.then((t=>(g(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 w(e.props||e.options||{},_(r))}return!0}return!1}};K(V,"instance",{});let Y=V;var Z=Object.defineProperty,ee=(e,t,r)=>(((e,t,r)=>{t in e?Z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class te extends Error{constructor(e){super(),ee(this,"name","NgwError"),ee(this,"title"),ee(this,"message"),ee(this,"detail"),ee(this,"exception"),ee(this,"status_code"),ee(this,"data"),ee(this,"guru_meditation"),Object.assign(this,e),Object.setPrototypeOf(this,te.prototype)}}var re=Object.defineProperty,ne=(e,t,r)=>(((e,t,r)=>{t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class se extends te{constructor(e){super(e),ne(this,"name","ResourceNotFoundError"),ne(this,"exception","nextgisweb.resource.exception.ResourceNotFound"),Object.setPrototypeOf(this,se.prototype)}}function oe(e){return"[object Object]"===Object.prototype.toString.call(e)}const ie=["description"];function ae(e,t=""){t=t?t+"__":"";const r={};for(const[n,s]of Object.entries(e))if(-1===ie.indexOf(n))if(oe(s))if("owner_user"===n){const e=ae(s,n);Object.assign(r,e)}else"parent"===n&&"id"in s&&(r.parent_id=s.id);else v(s)&&(r[t+n]=s);return r}var ce=Object.defineProperty,le=Object.defineProperties,ue=Object.getOwnPropertyDescriptors,he=Object.getOwnPropertySymbols,fe=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable,de=(e,t,r)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ye=(e,t)=>{for(var r in t||(t={}))fe.call(t,r)&&de(e,r,t[r]);if(he)for(var r of he(t))pe.call(t,r)&&de(e,r,t[r]);return e};class me{constructor(e){var t,r,n;this.connector=e,t=this,r="cache",n=new Y,de(t,"symbol"!=typeof r?r+"":r,n)}getOne(e,t){const r=new Y,n={},s=(o=ye({},t),le(o,ue({cache:!1})));var o;"string"==typeof e?n.keyname=e:"number"==typeof e?n.id=e:oe(e)&&(void 0!==e.id?n.id=e.id:(e.keyname&&(n.keyname=e.keyname),e.display_name&&(n.display_name=e.display_name)));return r.addFull("resource",(()=>"string"==typeof e?this._fetchResourceBy({keyname:e},s):"number"==typeof e?this._fetchResourceById(e,s):oe(e)?this._fetchResourceBy(e,s):m.resolve(void 0)),n)}getOneOrFail(e,t){return this.getOne(e,t).then((e=>{if(e)return e;throw new se}))}getId(e,t){return"number"==typeof e?m.resolve(e):"string"==typeof e||oe(e)?this.getOne(e,t).then((e=>{if(e)return e.resource.id})):m.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,ae(e)),this.connector.get("resource.search",t,ye({serialization:"full"},r)).then((e=>{if(e)for(const t of e)this.cache.add("resource.item",m.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):m.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",ye({cache:!0},t),{parent:e}).then((e=>{const n=[];for(const s of e)this.cache.add("resource.item",m.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?m.all(n).then((()=>r)):r}))}_cleanResourceItemCache(e){return t=this,r=null,n=function*(){const t=this.cache.all(),r=[];for(const n of t){const t=n.options&&n.options.id;["resource.item","resource"].includes(n.key)&&void 0!==t&&("number"==typeof t?t===e&&r.push(n):(yield this.getId(t))===e&&r.push(n))}for(const e of r)this.cache.delete(e)},new Promise(((e,s)=>{var o=e=>{try{a(n.next(e))}catch(t){s(t)}},i=e=>{try{a(n.throw(e))}catch(t){s(t)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,i);a((n=n.apply(t,r)).next())}));var t,r,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 se))throw e}))}_fetchResourceBy(e,t){return this.getMany(e,t).then((e=>e[0]))}_resourceCacheFilter(e){return m.all(this.cache.matchAll("resource.item")).then((t=>(t.filter((t=>{if(t)return e.keyname&&t.resource.keyname?e.keyname===t.resource.keyname:v(e.id)&&v(t.resource.id)?e.id===t.resource.id:w(e,t.resource)})),[])))}}const ve=[];function ge(e){ve.push(e)}var be=Object.defineProperty,we=(e,t,r)=>(((e,t,r)=>{t in e?be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class _e extends te{constructor(e){super(e),we(this,"name","InsufficientPermissionsError"),we(this,"exception","nextgisweb.core.exception.InsufficientPermissions"),Object.setPrototypeOf(this,_e.prototype)}}const Oe=/\{ *([\w_-]+) *\}/g;function Pe(e,t){return e.replace(Oe,((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}))}var je=Object.defineProperty,xe=(e,t,r)=>(((e,t,r)=>{t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class Ee extends Error{constructor(e){super(),xe(this,"name","NetworkError"),Object.setPrototypeOf(this,Ee.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}let Ce;Ce=(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 te(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 Ee(e):t)},o.upload.onprogress=function(e){if(e.lengthComputable){r.onProgress&&r.onProgress(e.loaded/e.total*100,e)}};const a=r.headers;if(a)for(const l in a){const e=a[l];"string"==typeof e&&o.setRequestHeader(l,e)}let c;if(void 0!==r.withCredentials&&(o.withCredentials=r.withCredentials),r.file){if(c=new FormData,c.append("file",r.file),r.data)for(const l in r.data)c.append(l,c[l])}else c=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;s&&s((()=>{o.abort()})),o.send(c)};var Re=Object.defineProperty,Ie=Object.getOwnPropertySymbols,Le=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable,Se=(e,t,r)=>t in e?Re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,qe=(e,t)=>{for(var r in t||(t={}))Le.call(t,r)&&Se(e,r,t[r]);if(Ie)for(var r of Ie(t))ke.call(t,r)&&Se(e,r,t[r]);return e},Te=(e,t,r)=>(Se(e,"symbol"!=typeof t?t+"":t,r),r);let Ae=0;class Ue{constructor(e){this.options=e,Te(this,"id",Ae++),Te(this,"emitter",new B),Te(this,"user"),Te(this,"resources"),Te(this,"routeStr","/api/component/pyramid/route"),Te(this,"activeRequests",[]),Te(this,"requestTransform");const t=function(e){return ve.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return w(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 me(this),ge(this)}static create(e){return new this(e)}setRequestTransform(e){this.requestTransform=e}setNgw(e){this.logout(),this.options.baseUrl=e,ge(this)}connect(){const e=new Y,t=this.options.auth;return e.add("route",(()=>new m(((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(),ge(this),this._login(e,t)}logout(){this.abort(),function(e){const t=ve.indexOf(e);-1!==t&&ve.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 m.resolve(this.user);e&&(this.options.auth=e);const r=qe({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:i,withCredentials:a,responseType:c}=r,l=_(t=null!=(n=r.params)?n:t),u=()=>function(e){const t=e.params;return new m(((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=Pe(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:l,requestOptions:r,connector:this});if(r.cache&&"GET"===o){return(new Y).add(e,u,qe({params:l},_({headers:i,withCredentials:a,responseType:c,baseUrl:this.options.baseUrl,userId:null==(s=this.user)?void 0:s.id})))}return u()}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=Pe(e,t)),e=encodeURI(O(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){if(t.responseType=t.responseType||"json",t.signal&&t.signal.aborted)return m.reject(new m.CancelError);const r=new m(((r,n,s)=>{if(this.user&&((t=t||{}).headers=qe(qe({},this.getAuthorizationHeaders()),t.headers)),this.requestTransform){const[r,n]=this.requestTransform(e,t);e=r,t=n}Ce(e,r,t,n,s)})).then((e=>(this._cleanActiveRequests(r),e))).catch((e=>{if(this._cleanActiveRequests(r),e instanceof m.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 te){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new se(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new _e(e)}return e}}function Ne(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)}Te(Ue,"errors",{NgwError:te,ResourceNotFoundError:se});const Fe={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)=>Ne(e,t),ilike:(e,t)=>Ne(e,t,!0)};function $e(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function Me(e,t){const r="string"==typeof t[0]?t[0]:"all",n=t=>{if($e(t)){const[r,n,s]=t,o=Fe[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 Me(e,t)},s=t.filter((e=>Array.isArray(e)));return"any"===r?s.some(n):s.every(n)}var De=Object.defineProperty,He=Object.defineProperties,Be=Object.getOwnPropertyDescriptors,Ge=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Je=Object.prototype.propertyIsEnumerable,Qe=(e,t,r)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,We=(e,t)=>{for(var r in t||(t={}))ze.call(t,r)&&Qe(e,r,t[r]);if(Ge)for(var r of Ge(t))Je.call(t,r)&&Qe(e,r,t[r]);return e},Xe=(e,t)=>He(e,Be(t));const Ke={srs:4326,geom_format:"geojson"};function Ve(e){const t=Ze(e);return m.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 Ye(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 Ze(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)$e(i)?t.push(tt(Xe(We({},e),{paramList:[...r,Ye(i)]}))):Ze(Xe(We({},e),{filters:i}),t,[...r]);else if("all"===s){const n=[],s=[];for(const e of o)$e(e)?n.push(Ye(e)):s.push(e);if(s.length)for(const o of s)Ze(Xe(We({},e),{filters:o}),t,[...r,...n]);else t.push(tt(Xe(We({},e),{paramList:[...r,...n]})))}return t}function et(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 tt(e){const t=We({},Ke),{limit:r,cache:n,signal:s,offset:o,orderBy:i,paramList:a,connector:c,geomFormat:l,intersects:u,resourceId:h}=e;if(r?r!==Number.POSITIVE_INFINITY&&(t.limit=r):t.limit=7e3,o&&(t.offset=o),l&&(t.geom_format=l),function(e,t){const{extensions:r,geom:n,fields:s,srs:o,ilike:i,like:a}=t,c=r?r.join(","):"";"*"!==c&&(e.extensions=c),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)),v(i)?e.ilike=i:v(a)&&(e.like=a),v(o)&&(e.srs=o)}(t,e),i&&(t.order_by=i.join(",")),Array.isArray(u)){const e=(f=u,Array.isArray(f)&&4===f.length&&f.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]}(u):u);t.intersects=et(e)}else"string"==typeof u&&(t.intersects=u);var f;a&&(t.paramList=a);const p=We({id:h},t);return c.get("feature_layer.feature.collection",{cache:n,signal:s},p)}var rt=Object.defineProperty,nt=Object.defineProperties,st=Object.getOwnPropertyDescriptors,ot=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,ct=(e,t,r)=>t in e?rt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,lt=(e,t)=>{for(var r in t||(t={}))it.call(t,r)&&ct(e,r,t[r]);if(ot)for(var r of ot(t))at.call(t,r)&&ct(e,r,t[r]);return e},ut=(e,t)=>nt(e,st(t));function ht(e){const t=e.filters;return t?Ve(ut(lt({},e),{filters:t})).then((r=>{var n;return(null!=(n=e.clientFilterValidate)?n:ft(t))&&(r=r.filter((e=>Me(function(e){let t;for(t in e){const r=e[t];if("[object Object]"===Object.prototype.toString.call(r)){const n=r;if(v(n.year)&&v(n.month)&&v(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}(ut(lt({},e.fields),{id:e.id})),t)))),r})):tt(e)}function ft(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(ft(r))return!0}}return!1}var pt=Object.defineProperty,dt=Object.getOwnPropertySymbols,yt=Object.prototype.hasOwnProperty,mt=Object.prototype.propertyIsEnumerable,vt=(e,t,r)=>t in e?pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,gt=(e,t,r)=>(vt(e,"symbol"!=typeof t?t+"":t,r),r),bt=function(e,t){this[0]=e,this[1]=t},wt=(e,t,r)=>{var n,s,o=(e,t,n,s)=>{try{var i=r[e](t),a=(t=i.value)instanceof bt,c=i.done;Promise.resolve(a?t[0]:t).then((r=>a?o("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,n,s):n({value:r,done:c}))).catch((e=>o("throw",e,n,s)))}catch(l){s(l)}},i=e=>a[e]=t=>new Promise(((r,n)=>o(e,t,r,n))),a={};return r=r.apply(e,t),a[(n="asyncIterator",(s=Symbol[n])?s:Symbol.for("Symbol."+n))]=()=>a,i("next"),i("throw"),i("return"),a};const _t=class e extends D{constructor(e){var t;if(super(e),gt(this,"searchResources",[]),gt(this,"connector"),gt(this,"_abortControllers",[]),!e.searchUrl&&!(null==(t=e.connectorOptions)?void 0:t.baseUrl))throw new Error("The `searchUrl` of `connectorOptions.baseUrl` are required");this.connector=e.connector||new Ue(((e,t)=>{for(var r in t||(t={}))yt.call(t,r)&&vt(e,r,t[r]);if(dt)for(var r of dt(t))mt.call(t,r)&&vt(e,r,t[r]);return e})({baseUrl:this.searchUrl},e.connectorOptions)),this.searchResources=e.searchResources}abort(){this._abortControllers.forEach((e=>{e.abort()})),this._abortControllers.length=0}search(t){return wt(this,null,(function*(){var r,n;const s=this._makeSignal();for(const i of this.searchResources){if(s.aborted)break;const{searchMethod:a}=i,c=null!=(r=i.limit)?r:e.limit,l=null!=(n=i.id)?n:i.resourceId;try{const e=yield new bt(this.connector.getResourceOrFail(l,{cache:!0})),r={connector:this.connector,resourceId:l,signal:s,limit:c};"like"===a?r.like=t:r.ilike=t;const n=ht(r),o=yield new bt(n);for(const s of this._items({entries:o,query:t,config:i,resourceItem:e}))s.result=()=>this.result(s),yield s}catch(o){o&&"name"in o&&"CancelError"!==o.name&&console.warn(o)}}}))}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]}}))}reverse(e){return wt(this,null,(function*(){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.keyname);return this.searchResources.find((e=>{var t;return null!=(t=e.id)?t:e.resourceId===n.resource.id}))&&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}};gt(_t,"limit",300);let Ot=_t;var Pt=Object.defineProperty,jt=(e,t,r)=>(((e,t,r)=>{t in e?Pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r),xt=function(e,t){this[0]=e,this[1]=t},Et=(e,t,r)=>{var n,s,o=(e,t,n,s)=>{try{var i=r[e](t),a=(t=i.value)instanceof xt,c=i.done;Promise.resolve(a?t[0]:t).then((r=>a?o("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,n,s):n({value:r,done:c}))).catch((e=>o("throw",e,n,s)))}catch(l){s(l)}},i=e=>a[e]=t=>new Promise(((r,n)=>o(e,t,r,n))),a={};return r=r.apply(e,t),a[(n="asyncIterator",(s=Symbol[n])?s:Symbol.for("Symbol."+n))]=()=>a,i("next"),i("throw"),i("return"),a};return e.BaseProvider=D,e.Geocoder=F,e.NgwProvider=Ot,e.NominatimProvider=class extends D{constructor(e){super(e),jt(this,"searchUrl","https://nominatim.openstreetmap.org"),jt(this,"_requests",[]),e&&e.searchUrl&&(this.searchUrl=e.searchUrl)}abort(){this._requests.forEach((e=>e.cancel())),this._requests=[]}search(e){return Et(this,null,(function*(){const t=O(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${e}`),r=new m(((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=yield new xt(r);if(n)for(const e of n)e.result=()=>this.result(e),yield e}))}result(e){return m.resolve({text:e.text,extent:e.extent||[],geom:e.geom})}reverse(e){return Et(this,null,(function*(){const[t,r]=e,n=O(`${this.searchUrl}/reverse?format=geojson&lat=${r}&lon=${t}`),s=new m(((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=yield new xt(s);o&&(o.result=()=>this.result(o),yield o)}))}},e.create=function(e){return new F(e)},e}({});
1
+ var Geocoder=function(e){"use strict";var t=Object.defineProperty,r=(e,r,n)=>((e,r,n)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n)(e,"symbol"!=typeof r?r+"":r,n);class n extends Error{constructor(){super(),r(this,"name","CancelError"),Object.setPrototypeOf(this,n.prototype)}}var s=Object.defineProperty,o=(e,t,r)=>((e,t,r)=>t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class i{constructor(e={}){this.options=e,o(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()}}var c=Object.defineProperty,a=(e,t,r)=>((e,t,r)=>t in e?c(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class l extends Error{constructor(){super(),a(this,"name","TimeoutError"),Object.setPrototypeOf(this,l.prototype)}}var u,h=Object.defineProperty,f=(e,t,r)=>((e,t,r)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);const p=(e,t,r,n)=>{try{e(r(n))}catch(s){t(s)}};let d=0;u=Symbol.toStringTag;const y=class e{constructor(t,r){f(this,u),f(this,"id",d++),f(this,"_isCanceled",!1),f(this,"_isPending",!0),f(this,"_promise"),f(this,"_cancelPromise"),f(this,"_cancelHandlers",[]),f(this,"_setCanceledCallback"),f(this,"_parentPromise"),f(this,"_children",[]),this._cancelPromise=new Promise(((e,t)=>{this._setCanceledCallback=t=>e(t||new n)}));const s=[this._cancelPromise,new Promise(((r,n)=>t((t=>{t instanceof e?this.attach(t):this._isPending=!1,r(t)}),(e=>{this._isPending=!1,n(e)}),(e=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(e)}))))];r&&s.push(new Promise(((e,t)=>{setTimeout((()=>{if(this._isPending)try{this.cancel()}finally{t(new l)}}),r)}))),this._promise=Promise.race(s)}static createControl(e){return new i(e)}static resolve(t){return new e((e=>e(t)))}static reject(t){return new e(((e,r)=>r(t)))}static all(t){return new e(((e,r)=>{Promise.all(t).then(e).catch(r)})).catch((e=>{if(e instanceof this.CancelError)for(const r of t){"cancel"in r&&r.cancel()}throw e}))}attach(e){this._isCanceled?e.cancel():this._children.push(e)}then(t,r){const n=new e(((e,n)=>{if(this._promise){const s=t=>{r?p(e,n,r,t):n(t)};this._promise.then((r=>{this._isCanceled?s(r):t?p(e,n,t,r):e(r)}),s)}}));return n._parentPromise=this,this._children.push(n),n}catch(e){return this._isCanceled&&e&&e(new n),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new n:e)}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}};f(y,"CancelError",n),f(y,"TimeoutError",l),f(y,"PromiseControl",i);let m=y;function v(e){return null!=e}function g(e){return"string"==typeof e?!!e:v(e)}function b(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:w(e,t));return e===t}function w(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(!b(e[r[s]],t[n[s]],e,t))return!1}return!0}function _(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]=_(e[r])})),t}function O(e){return e.replace(/([^:]\/)\/+/g,"$1")}Object.setPrototypeOf(m.prototype,Promise.prototype);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)}}var j=Object.defineProperty,x=Object.defineProperties,E=Object.getOwnPropertyDescriptors,C=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,L=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),k=(e,t,r)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,S=(e,t)=>{for(var r in t||(t={}))I.call(t,r)&&k(e,r,t[r]);if(C)for(var r of C(t))R.call(t,r)&&k(e,r,t[r]);return e},q=(e,t)=>x(e,E(t)),T=function(e,t){this[0]=e,this[1]=t},A=(e,t,r)=>{var n=(e,t,s,o)=>{try{var i=r[e](t),c=(t=i.value)instanceof T,a=i.done;Promise.resolve(c?t[0]:t).then((r=>c?n("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,s,o):s({value:r,done:a}))).catch((e=>n("throw",e,s,o)))}catch(l){o(l)}},s=e=>o[e]=t=>new Promise(((r,s)=>n(e,t,r,s))),o={};return r=r.apply(e,t),o[L("asyncIterator")]=()=>o,s("next"),s("throw"),s("return"),o},U=(e,t,r)=>(t=e[L("asyncIterator")])?t.call(e):(e=e[L("iterator")](),t={},(r=(r,n)=>(n=e[r])&&(t[r]=t=>new Promise(((r,s,o)=>(t=n.call(e,t),o=t.done,Promise.resolve(t.value).then((e=>r({value:e,done:o})),s))))))("next"),r("return"),t);let N=0;class F extends P{constructor(e){var t;super(e),k(this,"symbol"!=typeof(t="providers")?t+"":t,[]),e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}search(e){return A(this,null,(function*(){this.abort();let t=!0;const r=[];for(const a of this.providers)try{const r=a.search(e);try{for(var n,s,o,i=U(r);n=!(s=yield new T(i.next())).done;n=!1){const e=s.value;t=!1,yield q(S({},e),{provider:a,_id:N++})}}catch(s){o=[s]}finally{try{n&&(s=i.return)&&(yield new T(s.call(i)))}finally{if(o)throw o[0]}}}catch(c){"CancelError"!==c.name&&r.push(c)}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):m.resolve(void 0)}reverse(e){return A(this,null,(function*(){for(const i of this.providers)if(i.reverse)try{const o=i.reverse(e);try{for(var t,r,n,s=U(o);t=!(r=yield new T(s.next())).done;t=!1){const e=r.value;yield q(S({},e),{provider:i,_id:N++})}}catch(r){n=[r]}finally{try{t&&(r=s.return)&&(yield new T(r.call(s)))}finally{if(n)throw n[0]}}}catch(o){}}))}reverseGeocodeFirstResult(e){return t=this,r=null,n=function*(){for(const i of this.providers)if("function"==typeof i.reverse)try{try{for(var t,r,n,s=U(i.reverse(e));t=!(r=yield s.next()).done;t=!1)return r.value}catch(r){n=[r]}finally{try{t&&(r=s.return)&&(yield r.call(s))}finally{if(n)throw n[0]}}}catch(o){console.error("Error in reverse geocoding:",o)}},new Promise(((e,s)=>{var o=e=>{try{c(n.next(e))}catch(t){s(t)}},i=e=>{try{c(n.throw(e))}catch(t){s(t)}},c=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,i);c((n=n.apply(t,r)).next())}));var t,r,n}}var $=Object.defineProperty,M=(e,t,r)=>((e,t,r)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class D extends P{constructor(){super(...arguments),M(this,"searchUrl"),M(this,"label")}}function H(){}function B(){B.init.call(this)}function G(e){return void 0===e._maxListeners?B.defaultMaxListeners:e._maxListeners}function z(e,t,r,n){var s,o,i,c;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),i=o[t]):(o=e._events=new H,e._eventsCount=0),i){if("function"==typeof i?i=o[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),!i.warned&&(s=G(e))&&s>0&&i.length>s){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=i.length,c=a,"function"==typeof console.warn?console.warn(c):console.log(c)}}else i=o[t]=r,++e._eventsCount;return e}function J(e,t,r){var n=!1;function s(){e.removeListener(t,s),n||(n=!0,r.apply(e,arguments))}return s.listener=r,s}function Q(e){var t=this._events;if(t){var r=t[e];if("function"==typeof r)return 1;if(r)return r.length}return 0}function W(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}H.prototype=Object.create(null),B.EventEmitter=B,B.usingDomains=!1,B.prototype.domain=void 0,B.prototype._events=void 0,B.prototype._maxListeners=void 0,B.defaultMaxListeners=10,B.init=function(){this.domain=null,B.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new H,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},B.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},B.prototype.getMaxListeners=function(){return G(this)},B.prototype.emit=function(e){var t,r,n,s,o,i,c,a="error"===e;if(i=this._events)a=a&&null==i.error;else if(!a)return!1;if(c=this.domain,a){if(t=arguments[1],!c){if(t instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=c,t.domainThrown=!1,c.emit("error",t),!1}if(!(r=i[e]))return!1;var u="function"==typeof r;switch(n=arguments.length){case 1:!function(e,t,r){if(t)e.call(r);else for(var n=e.length,s=W(e,n),o=0;o<n;++o)s[o].call(r)}(r,u,this);break;case 2:!function(e,t,r,n){if(t)e.call(r,n);else for(var s=e.length,o=W(e,s),i=0;i<s;++i)o[i].call(r,n)}(r,u,this,arguments[1]);break;case 3:!function(e,t,r,n,s){if(t)e.call(r,n,s);else for(var o=e.length,i=W(e,o),c=0;c<o;++c)i[c].call(r,n,s)}(r,u,this,arguments[1],arguments[2]);break;case 4:!function(e,t,r,n,s,o){if(t)e.call(r,n,s,o);else for(var i=e.length,c=W(e,i),a=0;a<i;++a)c[a].call(r,n,s,o)}(r,u,this,arguments[1],arguments[2],arguments[3]);break;default:for(s=new Array(n-1),o=1;o<n;o++)s[o-1]=arguments[o];!function(e,t,r,n){if(t)e.apply(r,n);else for(var s=e.length,o=W(e,s),i=0;i<s;++i)o[i].apply(r,n)}(r,u,this,s)}return!0},B.prototype.on=B.prototype.addListener=function(e,t){return z(this,e,t,!1)},B.prototype.prependListener=function(e,t){return z(this,e,t,!0)},B.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,J(this,e,t)),this},B.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,J(this,e,t)),this},B.prototype.removeListener=function(e,t){var r,n,s,o,i;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(n=this._events))return this;if(!(r=n[e]))return this;if(r===t||r.listener&&r.listener===t)0==--this._eventsCount?this._events=new H:(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(s=-1,o=r.length;o-- >0;)if(r[o]===t||r[o].listener&&r[o].listener===t){i=r[o].listener,s=o;break}if(s<0)return this;if(1===r.length){if(r[0]=void 0,0==--this._eventsCount)return this._events=new H,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,s=e.length;n<s;r+=1,n+=1)e[r]=e[n];e.pop()}(r,s);n.removeListener&&this.emit("removeListener",e,i||t)}return this},B.prototype.off=function(e,t){return this.removeListener(e,t)},B.prototype.removeAllListeners=function(e){var t,r;if(!(r=this._events))return this;if(!r.removeListener)return 0===arguments.length?(this._events=new H,this._eventsCount=0):r[e]&&(0==--this._eventsCount?this._events=new H:delete r[e]),this;if(0===arguments.length){for(var n,s=Object.keys(r),o=0;o<s.length;++o)"removeListener"!==(n=s[o])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=new H,this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},B.prototype.listeners=function(e){var t,r=this._events;return r&&(t=r[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(t):[]},B.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Q.call(e,t)},B.prototype.listenerCount=Q,B.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var X=Object.defineProperty,K=(e,t,r)=>((e,t,r)=>t in e?X(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);const V=class e{constructor(t={}){var r;K(this,"cache",[]);const n=null!=(r=t.namespace)?r:"default";return e.instance[n]?e.instance[n]:(e.instance[n]=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(_(r))),i={key:e,value:s,props:o,options:o};return n&&!g(s)?s:(this.cache.push(i),s instanceof Promise?(s.catch((t=>{throw this.delete(e,r),t})),n&&s.then((t=>(g(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 w(e.props||e.options||{},_(r))}return!0}return!1}};K(V,"instance",{});let Y=V;var Z=Object.defineProperty,ee=(e,t,r)=>((e,t,r)=>t in e?Z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class te extends Error{constructor(e){super(),ee(this,"name","NgwError"),ee(this,"title"),ee(this,"message"),ee(this,"detail"),ee(this,"exception"),ee(this,"status_code"),ee(this,"data"),ee(this,"guru_meditation"),Object.assign(this,e),Object.setPrototypeOf(this,te.prototype)}}var re=Object.defineProperty,ne=(e,t,r)=>((e,t,r)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class se extends te{constructor(e){super(e),ne(this,"name","ResourceNotFoundError"),ne(this,"exception","nextgisweb.resource.exception.ResourceNotFound"),Object.setPrototypeOf(this,se.prototype)}}function oe(e){return"[object Object]"===Object.prototype.toString.call(e)}const ie=["description"];function ce(e,t=""){t=t?t+"__":"";const r={};for(const[n,s]of Object.entries(e))if(-1===ie.indexOf(n))if(oe(s))if("owner_user"===n){const e=ce(s,n);Object.assign(r,e)}else"parent"===n&&"id"in s&&(r.parent_id=s.id);else v(s)&&(r[t+n]=s);return r}var ae=Object.defineProperty,le=Object.defineProperties,ue=Object.getOwnPropertyDescriptors,he=Object.getOwnPropertySymbols,fe=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable,de=(e,t,r)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ye=(e,t)=>{for(var r in t||(t={}))fe.call(t,r)&&de(e,r,t[r]);if(he)for(var r of he(t))pe.call(t,r)&&de(e,r,t[r]);return e},me=(e,t,r)=>de(e,"symbol"!=typeof t?t+"":t,r);class ve{constructor({connector:e,cacheId:t}){me(this,"cache"),me(this,"connector"),this.connector=e,this.cache=new Y({namespace:t})}getOne(e,t){const r=this.cache,n={},s=(o=ye({},t),le(o,ue({cache:!1})));var o;"string"==typeof e?n.keyname=e:"number"==typeof e?n.id=e:oe(e)&&(void 0!==e.id?n.id=e.id:(e.keyname&&(n.keyname=e.keyname),e.display_name&&(n.display_name=e.display_name)));return r.addFull("resource",(()=>"string"==typeof e?this._fetchResourceBy({keyname:e},s):"number"==typeof e?this._fetchResourceById(e,s):oe(e)?this._fetchResourceBy(e,s):m.resolve(void 0)),n)}getOneOrFail(e,t){return this.getOne(e,t).then((e=>{if(e)return e;throw new se}))}getId(e,t){return"number"==typeof e?m.resolve(e):"string"==typeof e||oe(e)?this.getOne(e,t).then((e=>{if(e)return e.resource.id})):m.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,ce(e)),this.connector.get("resource.search",t,ye({serialization:"full"},r)).then((e=>{if(e)for(const t of e)this.cache.add("resource.item",m.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):m.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",ye({cache:!0},t),{parent:e}).then((e=>{const n=[];for(const s of e)this.cache.add("resource.item",m.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?m.all(n).then((()=>r)):r}))}_cleanResourceItemCache(e){return t=this,r=null,n=function*(){const t=this.cache.all(),r=[];for(const n of t){const t=n.options&&n.options.id;["resource.item","resource"].includes(n.key)&&void 0!==t&&("number"==typeof t?t===e&&r.push(n):(yield this.getId(t))===e&&r.push(n))}for(const e of r)this.cache.delete(e)},new Promise(((e,s)=>{var o=e=>{try{c(n.next(e))}catch(t){s(t)}},i=e=>{try{c(n.throw(e))}catch(t){s(t)}},c=t=>t.done?e(t.value):Promise.resolve(t.value).then(o,i);c((n=n.apply(t,r)).next())}));var t,r,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 se))throw e}))}_fetchResourceBy(e,t){return this.getMany(e,t).then((e=>e[0]))}_resourceCacheFilter(e){return m.all(this.cache.matchAll("resource.item")).then((t=>(t.filter((t=>{if(t)return e.keyname&&t.resource.keyname?e.keyname===t.resource.keyname:v(e.id)&&v(t.resource.id)?e.id===t.resource.id:w(e,t.resource)})),[])))}}const ge=[];function be(e){ge.push(e)}var we=Object.defineProperty,_e=(e,t,r)=>((e,t,r)=>t in e?we(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class Oe extends te{constructor(e){super(e),_e(this,"name","InsufficientPermissionsError"),_e(this,"exception","nextgisweb.core.exception.InsufficientPermissions"),Object.setPrototypeOf(this,Oe.prototype)}}const Pe=/\{ *([\w_-]+) *\}/g;function je(e,t){return e.replace(Pe,((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}))}var xe=Object.defineProperty,Ee=(e,t,r)=>((e,t,r)=>t in e?xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);class Ce extends Error{constructor(e){super(),Ee(this,"name","NetworkError"),Object.setPrototypeOf(this,Ce.prototype),this.message=`Unable to request ${e}.\n Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`}}let Ie;Ie=(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 te(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 Ce(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 l in c){const e=c[l];"string"==typeof e&&o.setRequestHeader(l,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 l in r.data)a.append(l,a[l])}else a=r.data?"string"==typeof r.data?r.data:JSON.stringify(r.data):null;s&&s((()=>{o.abort()})),o.send(a)};var Re=Object.defineProperty,Le=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable,qe=(e,t,r)=>t in e?Re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Te=(e,t)=>{for(var r in t||(t={}))ke.call(t,r)&&qe(e,r,t[r]);if(Le)for(var r of Le(t))Se.call(t,r)&&qe(e,r,t[r]);return e},Ae=(e,t,r)=>qe(e,"symbol"!=typeof t?t+"":t,r);let Ue=0;class Ne{constructor(e){this.options=e,Ae(this,"id",Ue++),Ae(this,"emitter",new B),Ae(this,"user"),Ae(this,"resources"),Ae(this,"cache"),Ae(this,"routeStr","/api/component/pyramid/route"),Ae(this,"activeRequests",[]),Ae(this,"requestTransform");const t=function(e){return ge.find((t=>{if(t.options.baseUrl===e.baseUrl){if(!e.auth)return!0;if(t.options.auth)return w(t.options.auth,e.auth)}}))}(e);if(this.cache=new Y({namespace:e.cacheId}),t)return t;this.options.route&&(this.routeStr=this.options.route),this.options.requestTransform&&(this.requestTransform=this.options.requestTransform),this.resources=new ve({connector:this,cacheId:e.cacheId}),be(this)}static create(e){return new this(e)}clearCache(){this.cache.clean(),this.resources.cache.clean()}setRequestTransform(e){this.requestTransform=e}setNgw(e){this.logout(),this.options.baseUrl=e,be(this)}connect(){const e=this.options.auth;return this.cache.add("route",(()=>new m(((t,r)=>{const n=()=>this.makeQuery(this.routeStr,{},{}).then((e=>{t(e)})).catch((e=>{r(e)}));if(e){const{login:t,password:s}=e;if(t&&s)return this._login({login:t,password:s}).then((()=>n())).catch((e=>r(e)))}return n()}))),{id:this.id,auth:e,baseUrl:this.options.baseUrl})}login(e,t){return this.logout(),be(this),this._login(e,t)}logout(){this.abort(),function(e){const t=ge.indexOf(e);-1!==t&&ge.splice(t,1)}(this),this.options.auth=void 0,this.user=void 0,this.clearCache(),this.emitter.emit("logout")}getUserInfo(e,t){if(this.user&&this.user.id)return m.resolve(this.user);e&&(this.options.auth=e);const r=Te({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:i,withCredentials:c,responseType:a}=r,l=_(t=null!=(n=r.params)?n:t),u=()=>function(e){const t=e.params;return new m(((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=je(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:l,requestOptions:r,connector:this});return r.cache&&"GET"===o?this.cache.add(e,u,Te({params:l},_({headers:i,withCredentials:c,responseType:a,baseUrl:this.options.baseUrl,userId:null==(s=this.user)?void 0:s.id}))):u()}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=je(e,t)),e=encodeURI(O(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){if(t.responseType=t.responseType||"json",t.signal&&t.signal.aborted)return m.reject(new m.CancelError);const r=new m(((r,n,s)=>{if(this.user&&((t=t||{}).headers=Te(Te({},this.getAuthorizationHeaders()),t.headers)),this.requestTransform){const[r,n]=this.requestTransform(e,t);e=r,t=n}Ie(e,r,t,n,s)})).then((e=>(this._cleanActiveRequests(r),e))).catch((e=>{if(this._cleanActiveRequests(r),e instanceof m.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 te){if("nextgisweb.resource.exception.ResourceNotFound"===e.exception)throw new se(e);if("nextgisweb.core.exception.InsufficientPermissions"===e.exception)throw new Oe(e)}return e}}function Fe(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)}Ae(Ne,"errors",{NgwError:te,ResourceNotFoundError:se});const $e={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)=>Fe(e,t),ilike:(e,t)=>Fe(e,t,!0)};function Me(e){return 3===e.length&&"string"==typeof e[0]&&"string"==typeof e[1]}function De(e,t){const r="string"==typeof t[0]?t[0]:"all",n=t=>{if(Me(t)){const[r,n,s]=t,o=$e[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 De(e,t)},s=t.filter((e=>Array.isArray(e)));return"any"===r?s.some(n):s.every(n)}var He=Object.defineProperty,Be=Object.defineProperties,Ge=Object.getOwnPropertyDescriptors,ze=Object.getOwnPropertySymbols,Je=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,We=(e,t,r)=>t in e?He(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Xe=(e,t)=>{for(var r in t||(t={}))Je.call(t,r)&&We(e,r,t[r]);if(ze)for(var r of ze(t))Qe.call(t,r)&&We(e,r,t[r]);return e},Ke=(e,t)=>Be(e,Ge(t));const Ve={srs:4326,geom_format:"geojson"};function Ye(e){const t=et(e);return m.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 Ze(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 et(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)Me(i)?t.push(rt(Ke(Xe({},e),{paramList:[...r,Ze(i)]}))):et(Ke(Xe({},e),{filters:i}),t,[...r]);else if("all"===s){const n=[],s=[];for(const e of o)Me(e)?n.push(Ze(e)):s.push(e);if(s.length)for(const o of s)et(Ke(Xe({},e),{filters:o}),t,[...r,...n]);else t.push(rt(Ke(Xe({},e),{paramList:[...r,...n]})))}return t}function tt(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 rt(e){const t=Xe({},Ve),{limit:r,cache:n,signal:s,offset:o,orderBy:i,paramList:c,connector:a,geomFormat:l,intersects:u,resourceId:h}=e;if(r?r!==Number.POSITIVE_INFINITY&&(t.limit=r):t.limit=7e3,o&&(t.offset=o),l&&(t.geom_format=l),function(e,t){const{extensions:r,geom:n,fields:s,srs:o,ilike:i,like:c}=t,a=r?r.join(","):"";"*"!==a&&(e.extensions=a),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)),v(i)?e.ilike=i:v(c)&&(e.like=c),v(o)&&(e.srs=o)}(t,e),i&&(t.order_by=i.join(",")),Array.isArray(u)){const e=(f=u,Array.isArray(f)&&4===f.length&&f.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]}(u):u);t.intersects=tt(e)}else"string"==typeof u&&(t.intersects=u);var f;c&&(t.paramList=c);const p=Xe({id:h},t);return a.get("feature_layer.feature.collection",{cache:n,signal:s},p)}var nt=Object.defineProperty,st=Object.defineProperties,ot=Object.getOwnPropertyDescriptors,it=Object.getOwnPropertySymbols,ct=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,lt=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ut=(e,t)=>{for(var r in t||(t={}))ct.call(t,r)&&lt(e,r,t[r]);if(it)for(var r of it(t))at.call(t,r)&&lt(e,r,t[r]);return e},ht=(e,t)=>st(e,ot(t));function ft(e){const t=e.filters;return t?Ye(ht(ut({},e),{filters:t})).then((r=>{var n;return(null!=(n=e.clientFilterValidate)?n:pt(t))&&(r=r.filter((e=>De(function(e){let t;for(t in e){const r=e[t];if("[object Object]"===Object.prototype.toString.call(r)){const n=r;if(v(n.year)&&v(n.month)&&v(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}(ht(ut({},e.fields),{id:e.id})),t)))),r})):rt(e)}function pt(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(pt(r))return!0}}return!1}var dt=Object.defineProperty,yt=Object.getOwnPropertySymbols,mt=Object.prototype.hasOwnProperty,vt=Object.prototype.propertyIsEnumerable,gt=(e,t,r)=>t in e?dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,bt=(e,t,r)=>gt(e,"symbol"!=typeof t?t+"":t,r),wt=function(e,t){this[0]=e,this[1]=t},_t=(e,t,r)=>{var n,s,o=(e,t,n,s)=>{try{var i=r[e](t),c=(t=i.value)instanceof wt,a=i.done;Promise.resolve(c?t[0]:t).then((r=>c?o("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,n,s):n({value:r,done:a}))).catch((e=>o("throw",e,n,s)))}catch(l){s(l)}},i=e=>c[e]=t=>new Promise(((r,n)=>o(e,t,r,n))),c={};return r=r.apply(e,t),c[(n="asyncIterator",(s=Symbol[n])?s:Symbol.for("Symbol."+n))]=()=>c,i("next"),i("throw"),i("return"),c};const Ot=class e extends D{constructor(e){var t;if(super(e),bt(this,"searchResources",[]),bt(this,"connector"),bt(this,"_abortControllers",[]),!e.searchUrl&&!(null==(t=e.connectorOptions)?void 0:t.baseUrl))throw new Error("The `searchUrl` of `connectorOptions.baseUrl` are required");this.connector=e.connector||new Ne(((e,t)=>{for(var r in t||(t={}))mt.call(t,r)&&gt(e,r,t[r]);if(yt)for(var r of yt(t))vt.call(t,r)&&gt(e,r,t[r]);return e})({baseUrl:this.searchUrl},e.connectorOptions)),this.searchResources=e.searchResources}abort(){this._abortControllers.forEach((e=>{e.abort()})),this._abortControllers.length=0}search(t){return _t(this,null,(function*(){var r,n;const s=this._makeSignal();for(const i of this.searchResources){if(s.aborted)break;const{searchMethod:c}=i,a=null!=(r=i.limit)?r:e.limit,l=null!=(n=i.id)?n:i.resourceId;try{const e=yield new wt(this.connector.getResourceOrFail(l,{cache:!0})),r={connector:this.connector,resourceId:l,signal:s,limit:a};"like"===c?r.like=t:r.ilike=t;const n=ft(r),o=yield new wt(n);for(const s of this._items({entries:o,query:t,config:i,resourceItem:e}))s.result=()=>this.result(s),yield s}catch(o){o&&"name"in o&&"CancelError"!==o.name&&console.warn(o)}}}))}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]}}))}reverse(e){return _t(this,null,(function*(){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.keyname);return this.searchResources.find((e=>{var t;return null!=(t=e.id)?t:e.resourceId===n.resource.id}))&&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}};bt(Ot,"limit",300);let Pt=Ot;var jt=Object.defineProperty,xt=(e,t,r)=>((e,t,r)=>t in e?jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r),Et=function(e,t){this[0]=e,this[1]=t},Ct=(e,t,r)=>{var n,s,o=(e,t,n,s)=>{try{var i=r[e](t),c=(t=i.value)instanceof Et,a=i.done;Promise.resolve(c?t[0]:t).then((r=>c?o("return"===e?e:"next",t[1]?{done:r.done,value:r.value}:r,n,s):n({value:r,done:a}))).catch((e=>o("throw",e,n,s)))}catch(l){s(l)}},i=e=>c[e]=t=>new Promise(((r,n)=>o(e,t,r,n))),c={};return r=r.apply(e,t),c[(n="asyncIterator",(s=Symbol[n])?s:Symbol.for("Symbol."+n))]=()=>c,i("next"),i("throw"),i("return"),c};return e.BaseProvider=D,e.Geocoder=F,e.NgwProvider=Pt,e.NominatimProvider=class extends D{constructor(e){super(e),xt(this,"searchUrl","https://nominatim.openstreetmap.org"),xt(this,"_requests",[]),e&&e.searchUrl&&(this.searchUrl=e.searchUrl)}abort(){this._requests.forEach((e=>e.cancel())),this._requests=[]}search(e){return Ct(this,null,(function*(){const t=O(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${e}`),r=new m(((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=yield new Et(r);if(n)for(const e of n)e.result=()=>this.result(e),yield e}))}result(e){return m.resolve({text:e.text,extent:e.extent||[],geom:e.geom})}reverse(e){return Ct(this,null,(function*(){const[t,r]=e,n=O(`${this.searchUrl}/reverse?format=geojson&lat=${r}&lon=${t}`),s=new m(((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=yield new Et(s);o&&(o.result=()=>this.result(o),yield o)}))}},e.create=function(e){return new F(e)},e}({});
2
2
  //# sourceMappingURL=geocoder.global.prod.js.map