@nextgis/utils
Version:
Common development tools
3 lines (2 loc) • 9.92 kB
JavaScript
function t(t,n,o={}){const r=e(t.prototype),i=void 0===o.replace||o.replace;n.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(n=>{const o=-1!==r.indexOf(n);if(!i&&!o||i){const o=Object.getOwnPropertyDescriptor(e.prototype,n);o&&Object.defineProperty(t.prototype,n,o)}})})}function e(t){return function(t,e=[]){for(;null!==t;t=Object.getPrototypeOf(t)){const n=Object.getOwnPropertyNames(t);for(let t=0;t<n.length;t++)-1==e.indexOf(n[t])&&e.push(n[t])}return e}(t)}function n(t,e,n){n.forEach(n=>{const o=Object.getOwnPropertyDescriptor(e.prototype,n);o&&Object.defineProperty(t.prototype,n,o)})}function o(t,e){return Array.from({length:Math.ceil(t.length/e)},(n,o)=>t.slice(o*e,o*e+e))}function r(t,e){return c(t=Array.from(t).sort(),e=Array.from(e).sort())}function i(t,e){return c(t=Array.from(t),e=Array.from(e))}function c(t,e){return t.length===e.length&&t.every(function(t,n){return t===e[n]})}function a(t){return t.filter((t,e,n)=>n.indexOf(t)==e)}var u=Object.defineProperty,s=(t,e,n)=>((t,e,n)=>e in t?u(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n)(t,e+"",n);class f{constructor(t){s(this,"silent",!0),t&&this.copy(t)}static copy(t){return(new f).copy(t)}copy(t){try{return navigator.clipboard?navigator.clipboard.writeText(t):window.clipboardData?window.clipboardData.setData("text",t):this.copyToClipboard(t),this.silent||console.log("Copied to Clipboard"),!0}catch(e){this.silent||console.log("Please copy manually")}return!1}copyToClipboard(t){const e=document.createElement("input");e.value=t;try{document.body.appendChild(e),this.copyNodeContentsToClipboard(e)}finally{document.body.removeChild(e)}}copyNodeContentsToClipboard(t){t.select(),t.setSelectionRange(0,99999),document.execCommand("copy")}}function l(t,e=10){let n;function o(...r){o.clear(),n=setTimeout(()=>{n=null,t.apply(this,r)},e)}return o.clear=function(){n&&(clearTimeout(n),n=null)},o}function p(t=10){return function(e,n,o){return{configurable:!0,enumerable:o.enumerable,get:function(){return Object.defineProperty(this,n,{configurable:!0,enumerable:o.enumerable,value:l(o.value,t)}),this[n]}}}}function y(t){return"production"!==process.env.NODE_ENV&&(console.trace("DEBUG: "+t),!0)}function h(t,e,n=!1){let o=t;const r=e,i=Array.isArray(r);let c=i&&[]||{};return i&&Array.isArray(r)?n?(o=o||[],c=c.concat(o),r.forEach((t,e)=>{void 0===c[e]?c[e]=t:"object"==typeof t?c[e]=h(o[e],t,n):-1===o.indexOf(t)&&c.push(t)})):c=r:(o&&"object"==typeof o&&Object.keys(o).forEach(function(t){c[t]=o[t]}),Object.keys(r).forEach(function(t){c[t]="object"==typeof r[t]&&r[t]&&"object"==typeof o[t]&&"object"==typeof r[t]?h(o[t],r[t],n):r[t]})),c}function g(t){return null!=t}function d(t){return"string"==typeof t?!!t:g(t)}function b(t){if(!t.lngLat&&t.latLng){y("deprecated use of latLng in MapClickEvent, use lngLat instead");t.lngLat=[t.latLng.lng,t.latLng.lat]}return t}function m(t){console.warn(`DEPRECATED WARN: ${t}`)}var j=Object.defineProperty,O=(t,e,n)=>((t,e,n)=>e in t?j(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n)(t,e+"",n);class P{constructor(t){this.emitter=t,O(this,"_eventsStatus",{})}setEventStatus(t,e){this._eventsStatus[t]=e}onLoad(t){const e=(Array.isArray(t)?t:[t]).map(t=>new Promise(e=>{if(this.getEventStatus(t))e(this);else{this.emitter.once(t,()=>{this.setEventStatus(t,!0),e(this)})}}));return Promise.all(e).then(()=>this)}getEventStatus(t){const e=this._eventsStatus[t];return void 0!==e&&!!e}}function M(t,e={}){var n;const o=null==(n=e.flatArray)||n,r={};return function t(e,n){if(Object(e)!==e)r[n]=e;else if(Array.isArray(e)&&o){const o=e.length;for(let r=0;r<o;r++)t(e[r],n+"["+r+"]");0===o&&(r[n]=[])}else{let o=!0;for(const r in e)o=!1,t(e[r],n?n+"."+r:r);o&&n&&(r[n]={})}}(t,""),r}function v(t){const[e,n,o,r]=t,i=e<o&&n<r;if(!i){console.log("Error: The extent coordinates are not in the correct order."),console.log(`Received extent: [${e}, ${n}, ${o}, ${r}]`);const t=[Math.min(e,o),Math.min(n,r),Math.max(e,o),Math.max(r,n)];console.log(`Expected order: [${t.join(", ")}]`)}const c=e>=-180&&o<=180,a=n>=-90&&r<=90;return c&&a||console.log("Warning: The coordinates may not be within valid geographic ranges."),i&&c&&a}const w=6371;function E(t,e){e=e>85.06?85.06:e<-85.06?-85.06:e;const n=20037508.34*t/180;let o=Math.log(Math.tan((90+e)*Math.PI/360))/(Math.PI/180);return o=20037508.34*o/180,[n,o]}function A(t,e){return[180*t/20037508.34,360*Math.atan(Math.exp(e*Math.PI/20037508.34))/Math.PI-90]}function C(t){return t*Math.PI/180}function S(t){let e=0;return L(t,()=>e++),e}function x(t){const e=[];return L(t,t=>e.push(t)),e}function L(t,e){D(t,t=>{if("coordinates"in t)if("Polygon"===t.type||"MultiLineString"===t.type)for(const n of t.coordinates)n.forEach(t=>e(t));else if("MultiPolygon"===t.type)for(const n of t.coordinates)n.forEach(t=>t.forEach(t=>e(t)));else if("Point"===t.type)e(t.coordinates);else if("MultiPoint"===t.type||"LineString"===t.type)for(const n of t.coordinates)e(n);return t})}function $(t){const e=[];return D(t,t=>{if("coordinates"in t)if("Polygon"===t.type)t.coordinates.forEach(t=>e.push(t));else if("MultiPolygon"===t.type)for(const n of t.coordinates)for(const t of n)e.push(t);return t}),e}function D(t,e){if("FeatureCollection"===t.type)for(const n of t.features)e(n.geometry);else"Feature"===t.type?e(t.geometry):"coordinates"in t&&e(t)}function I(t){return[t.lng,t.lat]}function T(t){return{lat:t[1],lng:t[0]}}function N(t){return{type:"Polygon",coordinates:[k(t)]}}function k(t){const e=[t[0],t[1]];return[e,[t[2],t[1]],[t[2],t[3]],[t[0],t[3]],e]}function F(t){return{type:"Feature",properties:{},geometry:N(t)}}const R=Math.PI/180,U=180/Math.PI;function _(t,e,n=10,o=6){const r=n/w*U,i=r/Math.cos(e*R),c=[];for(let a=0;a<o+1;a++){const n=Math.PI*(a/(o/2)),u=t+i*Math.cos(n),s=e+r*Math.sin(n);c.push([u,s])}return c}function B(t,e,n=10,o=6){return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[_(t,e,n,o)]}}}function W(t,e,n){return(n=null!=n?n:10)*(40075016.686*Math.abs(Math.cos(180*t[1]/Math.PI))/Math.pow(2,e+8))*5e-4}const G=Math.PI/180,V=180/Math.PI;function q(t,e,n=10){const o=n/w*V,r=o/Math.cos(e*G),i=[t-r,e+o];return[i,[t+r,e+o],[t+r,e-o],[t-r,e-o],i]}function z(t){return Array.isArray(t)&&4===t.length&&t.every(t=>"number"==typeof t)}function H(t,e){const n=e?Number("1e+"+e):1;return Math.round((t+Number.EPSILON)*n)/n}function J(t,...e){for(const n of e)for(const e of Object.getOwnPropertyNames(n))t[e]=n[e]}function K(t,e,n,o){if(t instanceof Array)return e instanceof Array&&e.sort().join("")===t.sort().join("");if(t instanceof Date)return e instanceof Date&&""+t==""+e;if(t instanceof Function){if(!(e instanceof Function))return!1}else if(t instanceof Object)return e instanceof Object&&(t===n?e===o:Q(t,e));return t===e}function Q(t,e){const n=Object.keys(t).sort(),o=Object.keys(e).sort();if(n.length!==o.length)return!1;if(n.join("")!==o.join(""))return!1;for(let r=0;r<n.length;r++){if(!K(t[n[r]],e[o[r]],t,e))return!1}return!0}function X(t){const e={};return Object.keys(t).forEach(n=>{t[n]instanceof Array||t[n]!==Object(t[n])?void 0!==t[n]&&(e[n]=t[n]):e[n]=X(t[n])}),e}const Y="undefined"!=typeof window&&void 0!==window.document,Z=Y?"browser":"node";function tt(){return Y?window:global}function et(t){return t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function nt(t=0){return new Promise(e=>setTimeout(e,t))}function ot(t,e=/[_.\- ]/){const n=t.split(e);let o="";for(let r=0;r<n.length;r++){const t=n[r];o+=t.charAt(0).toUpperCase()+t.slice(1)}return o}function rt(t){return(t=String(t).toLowerCase())[0].toUpperCase()+t.slice(1)}function it(t){const e=t.toString().split(".");return e[0]=e[0].replace(/\B(?=(\d{3})+(?!\d))/g," "),e.join(".")}function ct(t,e){return("string"==typeof e||"number"==typeof e)&&e in t}function at(t,e){return ct(t,e)}function ut(t){return"boolean"==typeof t||"number"==typeof t||"string"==typeof t||null===t||(lt(t)?ft(t):!!pt(t)&&st(t))}function st(t){return!!pt(t)&&t.every(ut)}function ft(t){if(lt(t))for(const e in t)if(!ut(e))return!1;return!1}function lt(t){return"[object Object]"===Object.prototype.toString.call(t)}function pt(t){return"[object Array]"===Object.prototype.toString.call(t)}function yt(t){if(Object(t)!==t||Array.isArray(t))return t;const e=/\.?([^.[\]]+)|\[(\d+)\]/g,n={};for(const o in t){let r,i=n,c="";for(;r=e.exec(o);)i=i[c]||(i[c]=r[2]?[]:{}),c=r[2]||r[1];i[c]=t[o]}return n[""]||n}function ht(t){return t.replace(/([^:]\/)\/+/g,"$1")}function gt(t,e){const n=new URL(t),o=new URLSearchParams(n.search);Object.entries(e).forEach(([t,e])=>{void 0===e?o.delete(t):o.set(t,e)}),o.set("timestamp",String((new Date).getTime()));const r=[...o.entries()].map(([t,e])=>`${t}=${e}`).join("&");return`${n.origin}${n.pathname}?${r}`}export{f as Clipboard,p as DebounceDecorator,w as EARTHS_RADIUS,P as Events,e as allProperties,t as applyMixins,o as arrayChunk,r as arrayCompare,i as arrayCompareStrict,a as arrayUnique,ot as camelize,rt as capitalize,v as checkExtent,S as coordinatesCount,l as debounce,y as debugLog,h as deepmerge,g as defined,C as degrees2Radian,E as degrees2meters,b as deprecatedMapClick,m as deprecatedWarn,L as eachCoordinates,D as eachGeometry,ht as fixUrlStr,M as flatten,d as full,k as getBoundsCoordinates,F as getBoundsFeature,N as getBoundsPolygon,B as getCircleFeature,_ as getCirclePolygonCoordinates,x as getCoordinates,tt as getGlobalVariable,W as getIdentifyRadius,$ as getPolygons,q as getSquarePolygonCoordinates,ut as isAnyJson,pt as isArray,Y as isBrowser,st as isJsonArray,ft as isJsonMap,z as isLngLatBoundsArray,ct as isObjKey,lt as isObject,at as keyInObj,I as latLngToLngLatArray,T as lngLatArrayToLatLng,A as meters2degrees,n as mixinProperties,it as numberWithSpaces,J as objectAssign,Q as objectDeepEqual,X as objectRemoveEmpty,et as reEscape,H as round,nt as sleep,Z as type,yt as unflatten,gt as updateUrlParams};
//# sourceMappingURL=utils.esm-bundler.prod.js.map