@kalisio/common-geospatial 0.4.1 → 0.5.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.
package/dist/index.cjs CHANGED
@@ -1,5 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@kalisio/common-core"),b={LATITUDE:"LAT",LONGITUDE:"LON",ALTITUDE:"ALT"};function Te(t){return l.assert.that(t,l.is.string,"axis must be a string"),Object.values(b).includes(t)}function z(t){return l.assert.that(t,l.is.string,"axis must be a string"),t===b.LATITUDE}function ue(t){return l.assert.that(t,l.is.string,"axis must be a string"),t===b.LONGITUDE}function Xe(t){return l.assert.that(t,l.is.string,"axis must be a string"),t===b.ALTITUDE}const Qe={NORTH:{label:"Nord",symbol:"N"},SOUTH:{label:"Sud",symbol:"S"},EAST:{label:"Est",symbol:"E"},WEST:{label:"Ouest",symbol:"O"}},et={DIRECTIONS:Qe},tt={NORTH:{label:"North",symbol:"N"},SOUTH:{label:"South",symbol:"S"},EAST:{label:"East",symbol:"E"},WEST:{label:"West",symbol:"W"}},rt={DIRECTIONS:tt},nt={DIRECTIONS:{NORTH:{label:l.is.string,symbol:l.is.string},SOUTH:{label:l.is.string,symbol:l.is.string},EAST:{label:l.is.string,symbol:l.is.string},WEST:{label:l.is.string,symbol:l.is.string}}},$={en:rt,fr:et};let ae="en";function it(){return Object.keys($)}function at(t,e){l.assert.all([{value:t,validator:l.is.string,message:"code must be a string"},{value:t,validator:r=>!l.has.key($,r),message:"locale already registered"},{value:e,validator:l.is.plainObject,message:"content must be an object"},{value:e,validator:r=>l.conform.schema(r,nt),message:"content does not conform to schema"}]),$[t]=e}function st(t){l.assert.all([{value:t,validator:l.is.string,message:"code must be a string"},{value:t,validator:e=>l.has.key($,e),message:"code is unknown"}]),ae=t}function Ce(){return{code:ae,content:$[ae]}}function x(){return Ce().content.DIRECTIONS}function W(t,e){const r=x(),n=r[t].label.toUpperCase(),i=r[t].symbol.toUpperCase();return e.toUpperCase()===n||e.toUpperCase()===i}function ot(t=null){const e=x();return l.is.defined(t)?(l.assert.that(t,Te,"axis must be a valid axis"),z(t)?[e.SOUTH,e.NORTH]:ue(t)?[e.EAST,e.WEST]:[]):[e.SOUTH,e.NORTH,e.EAST,e.WEST]}function lt(){return x().NORTH}function ut(){return x().SOUTH}function ct(){return x().EAST}function ft(){return x().WEST}function I(t){return l.assert.that(t,l.is.string,"dir must be a string"),Ie(t)||ce(t)||fe(t)||j(t)}function Ie(t){return l.assert.that(t,l.is.string,"dir must be a string"),W("NORTH",t)}function ce(t){return l.assert.that(t,l.is.string,"dir must be a string"),W("SOUTH",t)}function fe(t){return l.assert.that(t,l.is.string,"dir must be a string"),W("EAST",t)}function j(t){return l.assert.that(t,l.is.string,"dir must be a string"),W("WEST",t)}function Ne(t){return l.assert.that(t,I,"dir must be a direction"),j(t)||fe(t)?b.LONGITUDE:b.LATITUDE}const ht={degrees:l.is.number,direction:l.optional(I)},pt=/^(-?\d{1,3}(?:\.\d+)?)°?$/,gt=/^(\d{1,3}(?:\.\d+)?)°?([NSEW])$/;function G(t){let e=null,r=null;if(l.is.plainObject(t)&&l.conform.schema(t,ht))l.is.defined(t.direction)?t.degrees>=0&&(e=t.degrees,r=t.direction):e=t.degrees;else if(l.is.string(t)){const n=t.replace(/\s+/g,""),i=n.match(pt)??n.match(gt);i&&(e=parseFloat(i[1]),r=i[2]??null)}return{get degrees(){return e},get direction(){return r},get format(){return"DD"},isValid(){return l.is.number(e)},toString(n){if(l.assert.that(n,l.is.positiveInteger,"decimalPlaces must be a positive integer"),!this.isValid())return"";let i=`${e.toFixed(n)}°`;return r&&(i+=` ${r}`),i},toDecimal(){return this.isValid()?G({degrees:e,direction:r}):null}}}const yt={degrees:l.is.integer,minutes:t=>l.is.inRangeExclusiveMax(t,0,60),direction:l.optional(I)},dt=/^(-?\d{1,3})°(\d{1,2}(?:\.\d+)?)'?$/,mt=/^(\d{1,3})°(\d{1,2}(?:\.\d+)?)'?([NSEW])$/;function De(t){let e=null,r=null,n=null;if(l.is.plainObject(t)&&l.conform.schema(t,yt))l.is.defined(t.direction)?t.degrees>=0&&(e=t.degrees,r=t.minutes,n=t.direction):(e=t.degrees,r=t.minutes);else if(l.is.string(t)){const i=t.replace(/\s+/g,""),a=i.match(dt)??i.match(mt);a&&(e=parseFloat(a[1]),r=parseFloat(a[2]),n=a[3]??null)}return{get degrees(){return e},get minutes(){return r},get direction(){return n},get format(){return"DDM"},isValid(){return l.is.integer(e)&&l.is.inRangeExclusiveMax(r,0,60)},toString(i){if(l.assert.that(i,l.is.positiveInteger,"decimalPlaces must be a positive integer"),!this.isValid())return"";let a=`${e}° ${r.toFixed(i)}'`;return n&&(a+=` ${n}`),a},toDecimal(){return this.isValid()?G({degrees:e+r/60,direction:n}):null}}}const vt={degrees:l.is.nonNegativeInteger,minutes:t=>l.is.inRangeExclusiveMax(t,0,60),direction:I},bt=/^(\d{2})(\d{3})([NS])$/,At=/^(\d{3})(\d{3})([EW])$/;function _e(t){let e=null,r=null,n=null;if(l.is.plainObject(t)&&l.conform.schema(t,vt))e=t.degrees,r=t.minutes,n=t.direction;else if(l.is.string(t)){const i=t.trim(),a=i.match(bt)??i.match(At);a&&(e=parseFloat(a[1]),r=parseFloat(a[2])/10,n=a[3])}return{get degrees(){return e},get minutes(){return r},get direction(){return n},get format(){return"DDM_AERO"},isValid(){return l.is.nonNegativeInteger(e)&&l.is.inRangeExclusiveMax(r,0,60)&&I(n)},toString(){if(!this.isValid())return"";const i=n==="E"||n==="W",a=String(e).padStart(i?3:2,"0"),s=Math.floor(r*10).toString().padStart(3,"0");return`${a}${s}${n}`},toDecimal(){return this.isValid()?G({degrees:e+r/60,direction:n}):null}}}const wt={degrees:l.is.integer,minutes:t=>l.is.integer(t)&&l.is.inRange(t,0,59),seconds:t=>l.is.inRangeExclusiveMax(t,0,60),direction:l.optional(I)},Et=/^(-?\d{1,3})°(\d{1,2})'(\d{1,2}(?:\.\d+)?)"?$/,Ot=/^(\d{1,3})°(\d{1,2})'(\d{1,2}(?:\.\d+)?)"?([NSEW])$/;function xe(t){let e=null,r=null,n=null,i=null;if(l.is.plainObject(t)&&l.conform.schema(t,wt))l.is.defined(t.direction)?t.degrees>=0&&(e=t.degrees,r=t.minutes,n=t.seconds,i=t.direction):(e=t.degrees,r=t.minutes,n=t.seconds);else if(l.is.string(t)){const a=t.replace(/\s+/g,""),s=a.match(Et)??a.match(Ot);s&&(e=parseFloat(s[1]),r=parseFloat(s[2]),n=parseFloat(s[3]),i=s[4]??null)}return{get degrees(){return e},get minutes(){return r},get seconds(){return n},get direction(){return i},get format(){return"DMS"},isValid(){return l.is.integer(e)&&l.is.integer(r)&&l.is.inRange(r,0,59)&&l.is.inRangeExclusiveMax(n,0,60)},toString(a){if(l.assert.that(a,l.is.positiveInteger,"decimalPlaces must be a positive integer"),!this.isValid())return"";let s=`${e}° ${r}' ${n.toFixed(a)}"`;return i&&(s+=` ${i}`),s},toDecimal(){return this.isValid()?G({degrees:e+r/60+n/3600,direction:i}):null}}}function me(t){const e=Math.floor(t.degrees),r=(t.degrees-e)*60;return{degrees:e,minutes:r,direction:t.direction}}function St(t){const e=Math.floor(t.degrees),r=(t.degrees-e)*60,n=Math.floor(r),i=(r-n)*60;return{degrees:e,minutes:n,seconds:i,direction:t.direction}}const ve={DD:t=>(l.assert.that(t,e=>e.isValid(),"dd must be a valid coordinate"),t),DDM:t=>{l.assert.that(t,i=>i.isValid(),"dd must be a valid coordinate");const{degrees:e,minutes:r,direction:n}=me(t);return De(n?{degrees:e,minutes:r,direction:n}:{degrees:e,minutes:r})},DMS:t=>{l.assert.that(t,a=>a.isValid(),"dd must be a valid coordinate");const{degrees:e,minutes:r,seconds:n,direction:i}=St(t);return xe(i?{degrees:e,minutes:r,seconds:n,direction:i}:{degrees:e,minutes:r,seconds:n})},DDM_AERO:t=>{l.assert.that(t,i=>i.isValid(),"dd must be a valid coordinate");const{degrees:e,minutes:r,direction:n}=me(t);return _e({degrees:e,minutes:r,direction:n})}},B={DD:"DD",DDM:"DDM",DDM_AERO:"DDM_AERO",DMS:"DMS"},Re={DD:G,DDM:De,DDM_AERO:_e,DMS:xe},V=Array.from({length:9},(t,e)=>10**e);function se(t,e){if(l.assert.that(t,l.is.number,"coord must be a number"),l.is.defined(e))return l.assert.that(e,I,"dir must be a direction"),Ne(e);if(Math.abs(t)>90)return b.LONGITUDE}function oe(t){l.assert.that(t,l.is.number,"coord must be a number");const e=t.toExponential(),[r,n]=e.split("e").map(Number),i=(r.toString().split(".")[1]||"").length;return Math.max(0,i-n)}function Lt(t,e=7){l.assert.all([{value:t,validator:l.is.number,message:"coord must be a number"},{value:e,validator:n=>l.is.inRange(n,0,8),message:"precision must be in range [0, 8]"}]);const r=V[e];return Math.round(t*r)/r}function Tt(t,e){if(l.assert.all([{value:t,validator:l.is.number,message:"coord must be a number"},{value:e,validator:n=>ue(n)||z(n),message:"axis must be either a longitude or latitude"}]),z(e))return Math.max(-90,Math.min(90,t));let r=((t+180)%360+360)%360-180;return r===-180&&(r=180),Object.is(r,-0)&&(r=0),r}function Ct(t,e){l.assert.all([{value:t,validator:n=>l.is.defined(n)&&n.isValid(),message:"from must be a valid coordinate"},{value:e,validator:n=>l.has.key(ve,n),message:`unknown format: ${e}`}]);const r=t.format===B.DD?t:t.toDecimal();return r.isValid()?e===B.DD?r:ve[e](r):null}function Me(t){l.assert.that(t,l.is.nonEmptyString,"pattern must be a non empty string");for(const e of Object.keys(B)){const r=Re[e](t);if(r.isValid())return r}return null}function It(t){l.assert.that(t,o=>l.is.nonEmptyString(o),"pattern must be a non-empty string");const e=t.split(/[,;|]/);if(e.length!==2)return null;const[r,n]=e.map(Me);if(!r||!n)return null;const i=r.toDecimal(),a=n.toDecimal(),s=se(i.degrees,i.direction),u=se(a.degrees,a.direction),c=o=>{const{degrees:f,direction:h}=o;return h&&(j(h)||ce(h))?-f:f};if(s===b.LONGITUDE&&u===b.LATITUDE)return[c(i),c(a)];if(u===b.LONGITUDE&&s===b.LATITUDE)return[c(a),c(i)];if(s===b.LONGITUDE&&!u)return[c(i),a];if(s===b.LATITUDE&&!u)return[c(a),c(i)];if(u===b.LONGITUDE&&!s)return[c(a),c(i)];if(u===b.LATITUDE&&!s)return[c(i),c(a)];if(!s&&!u)return[[c(i),c(a)],[c(a),c(i)]]}function $e(t){return!l.is.arrayOfLength(t,4)&&!l.is.arrayOfLength(t,6)?!1:t.every(l.is.number)}const k={NAME:"name",LINK:"link"};function Nt(t){return l.is.plainObject(t)?t.type===k.NAME?l.is.nonEmptyString(t.properties?.name):t.type===k.LINK?l.is.nonEmptyString(t.properties?.href):!1:!1}const m={POINT:"Point",MULTI_POINT:"MultiPoint",LINESTRING:"LineString",MULTI_LINESTRING:"MultiLineString",POLYGON:"Polygon",MULTI_POLYGON:"MultiPolygon",GEOMETRY_COLLECTION:"GeometryCollection"};function K(t){return!l.is.plainObject(t)||!l.is.oneOf(t.type,Object.values(m))?!1:t.type===m.GEOMETRY_COLLECTION?l.is.array(t.geometries):l.is.array(t.coordinates)}const L={FEATURE:"Feature",FEATURE_COLLECTION:"FeatureCollection"};function ke(t){return l.is.plainObject(t)?L.FEATURE===t.type:!1}function Pe(t){return!l.is.plainObject(t)||t.type!==L.FEATURE_COLLECTION?!1:l.is.array(t.features)}function he(t){return l.is.plainObject(t)?K(t)||ke(t)?!0:Pe(t):!1}function Ge(t){return l.is.arrayOfLengthBetween(t,2,3)?t.every(l.is.number):!1}const Dt={},H=_t(globalThis,Dt);function _t(t,e){return new Proxy(t,{get(r,n,i){return n in e?e[n]:t[n]},set(r,n,i){return n in e&&delete e[n],t[n]=i,!0},deleteProperty(r,n){let i=!1;return n in e&&(delete e[n],i=!0),n in t&&(delete t[n],i=!0),i},ownKeys(r){const n=Reflect.ownKeys(t),i=Reflect.ownKeys(e),a=new Set(i);return[...n.filter(s=>!a.has(s)),...i]},defineProperty(r,n,i){return n in e&&delete e[n],Reflect.defineProperty(t,n,i),!0},getOwnPropertyDescriptor(r,n){return n in e?Reflect.getOwnPropertyDescriptor(e,n):Reflect.getOwnPropertyDescriptor(t,n)},has(r,n){return n in e||n in t}})}function Ue(t=[]){return C.getLogger(t)}const X=Symbol.for("logtape.rootLogger");class C{static getLogger(e=[]){let r=X in H?H[X]??null:null;return r==null&&(r=new C(null,[]),H[X]=r),typeof e=="string"?r.getChild(e):e.length===0?r:r.getChild(e)}constructor(e,r){Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"children",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"category",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sinks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"parentSinks",{enumerable:!0,configurable:!0,writable:!0,value:"inherit"}),Object.defineProperty(this,"filters",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"contextLocalStorage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.parent=e,this.children={},this.category=r,this.sinks=[],this.filters=[]}getChild(e){const r=typeof e=="string"?e:e[0],n=this.children[r];let i=n instanceof C?n:n?.deref();return i==null&&(i=new C(this,[...this.category,r]),this.children[r]="WeakRef"in H?new WeakRef(i):i),typeof e=="string"||e.length===1?i:i.getChild(e.slice(1))}reset(){for(;this.sinks.length>0;)this.sinks.shift();for(this.parentSinks="inherit";this.filters.length>0;)this.filters.shift()}resetDescendants(){for(const e of Object.values(this.children)){const r=e instanceof C?e:e.deref();r?.resetDescendants()}this.reset()}with(e){return new pe(this,{...e})}filter(e){for(const r of this.filters)if(!r(e))return!1;return this.filters.length<1?this.parent?.filter(e)??!0:!0}*getSinks(){if(this.parent!=null&&this.parentSinks==="inherit")for(const e of this.parent.getSinks())yield e;for(const e of this.sinks)yield e}emit(e,r){if(this.filter(e)){for(const n of this.getSinks())if(!r?.has(n))try{n(e)}catch(i){const a=new Set(r);a.add(n),xt.log("fatal","Failed to emit a log record to sink {sink}: {error}",{sink:n,error:i,record:e},a)}}}log(e,r,n,i){const a=C.getLogger().contextLocalStorage?.getStore()??{};let s;const u=typeof n=="function"?{category:this.category,level:e,timestamp:Date.now(),get message(){return be(r,this.properties)},rawMessage:r,get properties(){return s==null&&(s={...a,...n()}),s}}:{category:this.category,level:e,timestamp:Date.now(),message:be(r,{...a,...n}),rawMessage:r,properties:{...a,...n}};this.emit(u,i)}logLazily(e,r,n={}){const i=C.getLogger().contextLocalStorage?.getStore()??{};let a,s;function u(){if((s==null||a==null)&&(s=r((c,...o)=>(a=c,Ae(c,o))),a==null))throw new TypeError("No log record was made.");return[s,a]}this.emit({category:this.category,level:e,get message(){return u()[0]},get rawMessage(){return u()[1]},timestamp:Date.now(),properties:{...i,...n}})}logTemplate(e,r,n,i={}){const a=C.getLogger().contextLocalStorage?.getStore()??{};this.emit({category:this.category,level:e,message:Ae(r,n),rawMessage:r,timestamp:Date.now(),properties:{...a,...i}})}debug(e,...r){typeof e=="string"?this.log("debug",e,r[0]??{}):typeof e=="function"?this.logLazily("debug",e):this.logTemplate("debug",e,r)}info(e,...r){typeof e=="string"?this.log("info",e,r[0]??{}):typeof e=="function"?this.logLazily("info",e):this.logTemplate("info",e,r)}warn(e,...r){typeof e=="string"?this.log("warning",e,r[0]??{}):typeof e=="function"?this.logLazily("warning",e):this.logTemplate("warning",e,r)}error(e,...r){typeof e=="string"?this.log("error",e,r[0]??{}):typeof e=="function"?this.logLazily("error",e):this.logTemplate("error",e,r)}fatal(e,...r){typeof e=="string"?this.log("fatal",e,r[0]??{}):typeof e=="function"?this.logLazily("fatal",e):this.logTemplate("fatal",e,r)}}class pe{constructor(e,r){Object.defineProperty(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"properties",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=e,this.properties=r}get category(){return this.logger.category}get parent(){return this.logger.parent}getChild(e){return this.logger.getChild(e).with(this.properties)}with(e){return new pe(this.logger,{...this.properties,...e})}log(e,r,n,i){this.logger.log(e,r,typeof n=="function"?()=>({...this.properties,...n()}):{...this.properties,...n},i)}logLazily(e,r){this.logger.logLazily(e,r,this.properties)}logTemplate(e,r,n){this.logger.logTemplate(e,r,n,this.properties)}debug(e,...r){typeof e=="string"?this.log("debug",e,r[0]??{}):typeof e=="function"?this.logLazily("debug",e):this.logTemplate("debug",e,r)}info(e,...r){typeof e=="string"?this.log("info",e,r[0]??{}):typeof e=="function"?this.logLazily("info",e):this.logTemplate("info",e,r)}warn(e,...r){typeof e=="string"?this.log("warning",e,r[0]??{}):typeof e=="function"?this.logLazily("warning",e):this.logTemplate("warning",e,r)}error(e,...r){typeof e=="string"?this.log("error",e,r[0]??{}):typeof e=="function"?this.logLazily("error",e):this.logTemplate("error",e,r)}fatal(e,...r){typeof e=="string"?this.log("fatal",e,r[0]??{}):typeof e=="function"?this.logLazily("fatal",e):this.logTemplate("fatal",e,r)}}const xt=C.getLogger(["logtape","meta"]);function be(t,e){const r=[];let n="";for(let i=0;i<t.length;i++){const a=t.charAt(i),s=t.charAt(i+1);if(a==="{"&&s==="{")n=n+a,i++;else if(a==="}"&&s==="}")n=n+a,i++;else if(a==="{")r.push(n),n="";else if(a==="}"){let u;n.match(/^\s|\s$/)?u=n in e?e[n]:e[n.trim()]:u=e[n],r.push(u),n=""}else n=n+a}return r.push(n),r}function Ae(t,e){const r=[];for(let n=0;n<t.length;n++)r.push(t[n]),n<e.length&&r.push(e[n]);return r}function Fe(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function He(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Q,we;function Rt(){if(we)return Q;we=1;let t=null;if(typeof window>"u"&&("process"in globalThis&&"versions"in globalThis.process&&"node"in globalThis.process.versions&&typeof globalThis.caches>"u"&&typeof globalThis.addEventListener!="function"||"Bun"in globalThis))try{t=[He][0](`${["node","util"].join(":")}`)}catch{t=null}return Q=t,Q}var Mt=Rt();const q=Fe(Mt),Ee={debug:"DBG",info:"INF",warning:"WRN",error:"ERR",fatal:"FTL"},qe="Deno"in globalThis&&"inspect"in globalThis.Deno&&typeof globalThis.Deno.inspect=="function"?(t,e)=>globalThis.Deno.inspect(t,{strAbbreviateSize:1/0,iterableLimit:1/0,...e}):q!=null&&"inspect"in q&&typeof q.inspect=="function"?(t,e)=>q.inspect(t,{maxArrayLength:1/0,maxStringLength:1/0,...e}):t=>JSON.stringify(t);function ze(t={}){const e=t.timestamp==null||t.timestamp==="date-time-timezone"?s=>new Date(s).toISOString().replace("T"," ").replace("Z"," +00:00"):t.timestamp==="date-time-tz"?s=>new Date(s).toISOString().replace("T"," ").replace("Z"," +00"):t.timestamp==="date-time"?s=>new Date(s).toISOString().replace("T"," ").replace("Z",""):t.timestamp==="time-timezone"?s=>new Date(s).toISOString().replace(/.*T/,"").replace("Z"," +00:00"):t.timestamp==="time-tz"?s=>new Date(s).toISOString().replace(/.*T/,"").replace("Z"," +00"):t.timestamp==="time"?s=>new Date(s).toISOString().replace(/.*T/,"").replace("Z",""):t.timestamp==="date"?s=>new Date(s).toISOString().replace(/T.*/,""):t.timestamp==="rfc3339"?s=>new Date(s).toISOString():t.timestamp,r=t.category??"·",n=t.value??qe,i=t.level==null||t.level==="ABBR"?s=>Ee[s]:t.level==="abbr"?s=>Ee[s].toLowerCase():t.level==="FULL"?s=>s.toUpperCase():t.level==="full"?s=>s:t.level==="L"?s=>s.charAt(0).toUpperCase():t.level==="l"?s=>s.charAt(0):t.level,a=t.format??(({timestamp:s,level:u,category:c,message:o})=>`${s} [${u}] ${c}: ${o}`);return s=>{let u="";for(let p=0;p<s.message.length;p++)p%2===0?u+=s.message[p]:u+=n(s.message[p]);const c=e(s.timestamp),o=i(s.level),f=typeof r=="function"?r(s.category):s.category.join(r);return`${a({timestamp:c,level:o,category:f,message:u,record:s})}
2
- `}}ze();const ee="\x1B[0m",te={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"},re={bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",strikethrough:"\x1B[9m"},$t={debug:"blue",info:"green",warning:"yellow",error:"red",fatal:"magenta"};function kt(t={}){const e=t.format,r=typeof t.timestampStyle>"u"?"dim":t.timestampStyle,n=t.timestampColor??null,i=`${r==null?"":re[r]}${n==null?"":te[n]}`,a=r==null&&n==null?"":ee,s=typeof t.levelStyle>"u"?"bold":t.levelStyle,u=t.levelColors??$t,c=typeof t.categoryStyle>"u"?"dim":t.categoryStyle,o=t.categoryColor??null,f=`${c==null?"":re[c]}${o==null?"":te[o]}`,h=c==null&&o==null?"":ee;return ze({timestamp:"date-time-tz",value(p){return qe(p,{colors:!0})},...t,format({timestamp:p,level:d,category:O,message:U,record:F}){const S=u[F.level];return p=`${i}${p}${a}`,d=`${s==null?"":re[s]}${S==null?"":te[S]}${d}${s==null&&S==null?"":ee}`,e==null?`${p} ${d} ${f}${O}:${h} ${U}`:e({timestamp:p,level:d,category:`${f}${O}${h}`,message:U,record:F})}})}kt();var ne,Oe;function Pt(){if(Oe)return ne;Oe=1;let t=null;if(typeof window>"u"&&("process"in globalThis&&"versions"in globalThis.process&&"node"in globalThis.process.versions&&typeof globalThis.caches>"u"&&typeof globalThis.addEventListener!="function"||"Bun"in globalThis))try{t=[He][0](`${["node","fs"].join(":")}`)}catch{t=null}return ne=t,ne}var Gt=Pt();const Ut=Fe(Gt),Ft={},_=Ut;_==null||(_.writeSync,_.fsyncSync,_.closeSync,_.statSync,_.renameSync);var y=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function u(f){try{o(n.next(f))}catch(h){s(h)}}function c(f){try{o(n.throw(f))}catch(h){s(h)}}function o(f){f.done?a(f.value):i(f.value).then(u,c)}o((n=n.apply(t,e||[])).next())})},g=function(t,e){var r={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},n,i,a,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=u(0),s.throw=u(1),s.return=u(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(o){return function(f){return c([o,f])}}function c(o){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,o[0]&&(r=0)),r;)try{if(n=1,i&&(a=o[0]&2?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[o[0]&2,a.value]),o[0]){case 0:case 1:a=o;break;case 4:return r.label++,{value:o[1],done:!1};case 5:r.label++,i=o[1],o=[0];continue;case 7:o=r.ops.pop(),r.trys.pop();continue;default:if(a=r.trys,!(a=a.length>0&&a[a.length-1])&&(o[0]===6||o[0]===2)){r=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){r.label=o[1];break}if(o[0]===6&&r.label<a[1]){r.label=a[1],a=o;break}if(a&&r.label<a[2]){r.label=a[2],r.ops.push(o);break}a[2]&&r.ops.pop(),r.trys.pop();continue}o=e.call(t,r)}catch(f){o=[6,f],i=0}finally{n=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}},w=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],s;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(u){s={error:u}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return a},E=function(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},Se=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};(function(){function t(e){e===void 0&&(e=t.minComparator);var r=this;this.compare=e,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this._invertedCompare=function(n,i){return r.compare(n,i).then(function(a){return-1*a})}}return t.getChildrenIndexOf=function(e){return[e*2+1,e*2+2]},t.getParentIndexOf=function(e){if(e<=0)return-1;var r=e%2?1:2;return Math.floor((e-r)/2)},t.getSiblingIndexOf=function(e){if(e<=0)return-1;var r=e%2?1:-1;return e+r},t.minComparator=function(e,r){return y(this,void 0,void 0,function(){return g(this,function(n){return e>r?[2,1]:e<r?[2,-1]:[2,0]})})},t.maxComparator=function(e,r){return y(this,void 0,void 0,function(){return g(this,function(n){return r>e?[2,1]:r<e?[2,-1]:[2,0]})})},t.minComparatorNumber=function(e,r){return y(this,void 0,void 0,function(){return g(this,function(n){return[2,e-r]})})},t.maxComparatorNumber=function(e,r){return y(this,void 0,void 0,function(){return g(this,function(n){return[2,r-e]})})},t.defaultIsEqual=function(e,r){return y(this,void 0,void 0,function(){return g(this,function(n){return[2,e===r]})})},t.print=function(e){function r(f){var h=t.getParentIndexOf(f);return Math.floor(Math.log2(h+1))}function n(f,h){for(var p="";h>0;--h)p+=f;return p}for(var i=0,a=[],s=r(e.length-1)+2,u=0;i<e.length;){var c=r(i)+1;i===0&&(c=0);var o=String(e.get(i));o.length>u&&(u=o.length),a[c]=a[c]||[],a[c].push(o),i+=1}return a.map(function(f,h){var p=Math.pow(2,s-h)-1;return n(" ",Math.floor(p/2)*u)+f.map(function(d){var O=(u-d.length)/2;return n(" ",Math.ceil(O))+d+n(" ",Math.floor(O))}).join(n(" ",p*u))}).join(`
3
- `)},t.heapify=function(e,r){return y(this,void 0,void 0,function(){var n;return g(this,function(i){switch(i.label){case 0:return n=new t(r),n.heapArray=e,[4,n.init()];case 1:return i.sent(),[2,n]}})})},t.heappop=function(e,r){var n=new t(r);return n.heapArray=e,n.pop()},t.heappush=function(e,r,n){return y(this,void 0,void 0,function(){var i;return g(this,function(a){switch(a.label){case 0:return i=new t(n),i.heapArray=e,[4,i.push(r)];case 1:return a.sent(),[2]}})})},t.heappushpop=function(e,r,n){var i=new t(n);return i.heapArray=e,i.pushpop(r)},t.heapreplace=function(e,r,n){var i=new t(n);return i.heapArray=e,i.replace(r)},t.heaptop=function(e,r,n){r===void 0&&(r=1);var i=new t(n);return i.heapArray=e,i.top(r)},t.heapbottom=function(e,r,n){r===void 0&&(r=1);var i=new t(n);return i.heapArray=e,i.bottom(r)},t.nlargest=function(e,r,n){return y(this,void 0,void 0,function(){var i;return g(this,function(a){switch(a.label){case 0:return i=new t(n),i.heapArray=E([],w(r),!1),[4,i.init()];case 1:return a.sent(),[2,i.top(e)]}})})},t.nsmallest=function(e,r,n){return y(this,void 0,void 0,function(){var i;return g(this,function(a){switch(a.label){case 0:return i=new t(n),i.heapArray=E([],w(r),!1),[4,i.init()];case 1:return a.sent(),[2,i.bottom(e)]}})})},t.prototype.add=function(e){return y(this,void 0,void 0,function(){return g(this,function(r){switch(r.label){case 0:return[4,this._sortNodeUp(this.heapArray.push(e)-1)];case 1:return r.sent(),this._applyLimit(),[2,!0]}})})},t.prototype.addAll=function(e){return y(this,void 0,void 0,function(){var r,n,i;return g(this,function(a){switch(a.label){case 0:r=this.length,(i=this.heapArray).push.apply(i,E([],w(e),!1)),n=this.length,a.label=1;case 1:return r<n?[4,this._sortNodeUp(r)]:[3,4];case 2:a.sent(),a.label=3;case 3:return++r,[3,1];case 4:return this._applyLimit(),[2,!0]}})})},t.prototype.bottom=function(){return y(this,arguments,void 0,function(e){return e===void 0&&(e=1),g(this,function(r){return this.heapArray.length===0||e<=0?[2,[]]:this.heapArray.length===1?[2,[this.heapArray[0]]]:e>=this.heapArray.length?[2,E([],w(this.heapArray),!1)]:[2,this._bottomN_push(~~e)]})})},t.prototype.check=function(){return y(this,void 0,void 0,function(){var e,r,n,i,a,s,u,c,o;return g(this,function(f){switch(f.label){case 0:e=0,f.label=1;case 1:if(!(e<this.heapArray.length))return[3,10];r=this.heapArray[e],n=this.getChildrenOf(e),f.label=2;case 2:f.trys.push([2,7,8,9]),i=(c=void 0,Se(n)),a=i.next(),f.label=3;case 3:return a.done?[3,6]:(s=a.value,[4,this.compare(r,s)]);case 4:if(f.sent()>0)return[2,r];f.label=5;case 5:return a=i.next(),[3,3];case 6:return[3,9];case 7:return u=f.sent(),c={error:u},[3,9];case 8:try{a&&!a.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}return[7];case 9:return++e,[3,1];case 10:return[2]}})})},t.prototype.clear=function(){this.heapArray=[]},t.prototype.clone=function(){var e=new t(this.comparator());return e.heapArray=this.toArray(),e._limit=this._limit,e},t.prototype.comparator=function(){return this.compare},t.prototype.contains=function(e){return y(this,arguments,void 0,function(r,n){var i,a,s,u,c,o;return n===void 0&&(n=t.defaultIsEqual),g(this,function(f){switch(f.label){case 0:f.trys.push([0,5,6,7]),i=Se(this.heapArray),a=i.next(),f.label=1;case 1:return a.done?[3,4]:(s=a.value,[4,n(s,r)]);case 2:if(f.sent())return[2,!0];f.label=3;case 3:return a=i.next(),[3,1];case 4:return[3,7];case 5:return u=f.sent(),c={error:u},[3,7];case 6:try{a&&!a.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}return[7];case 7:return[2,!1]}})})},t.prototype.init=function(e){return y(this,void 0,void 0,function(){var r;return g(this,function(n){switch(n.label){case 0:e&&(this.heapArray=E([],w(e),!1)),r=t.getParentIndexOf(this.length-1),n.label=1;case 1:return r>=0?[4,this._sortNodeDown(r)]:[3,4];case 2:n.sent(),n.label=3;case 3:return--r,[3,1];case 4:return this._applyLimit(),[2]}})})},t.prototype.isEmpty=function(){return this.length===0},t.prototype.leafs=function(){if(this.heapArray.length===0)return[];var e=t.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(e+1)},Object.defineProperty(t.prototype,"length",{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"limit",{get:function(){return this._limit},set:function(e){this._limit=~~e,this._applyLimit()},enumerable:!1,configurable:!0}),t.prototype.peek=function(){return this.heapArray[0]},t.prototype.pop=function(){return y(this,void 0,void 0,function(){var e;return g(this,function(r){return e=this.heapArray.pop(),this.length>0&&e!==void 0?[2,this.replace(e)]:[2,e]})})},t.prototype.push=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return y(this,void 0,void 0,function(){return g(this,function(n){return e.length<1?[2,!1]:e.length===1?[2,this.add(e[0])]:[2,this.addAll(e)]})})},t.prototype.pushpop=function(e){return y(this,void 0,void 0,function(){var r;return g(this,function(n){switch(n.label){case 0:return[4,this.compare(this.heapArray[0],e)];case 1:return n.sent()<0?(r=w([this.heapArray[0],e],2),e=r[0],this.heapArray[0]=r[1],[4,this._sortNodeDown(0)]):[3,3];case 2:n.sent(),n.label=3;case 3:return[2,e]}})})},t.prototype.remove=function(e){return y(this,arguments,void 0,function(r,n){var i,a,s,u=this;return n===void 0&&(n=t.defaultIsEqual),g(this,function(c){switch(c.label){case 0:return this.heapArray.length?r!==void 0?[3,2]:[4,this.pop()]:[2,!1];case 1:return c.sent(),[2,!0];case 2:i=[0],c.label=3;case 3:return i.length?(a=i.shift(),[4,n(this.heapArray[a],r)]):[3,13];case 4:return c.sent()?a!==0?[3,6]:[4,this.pop()]:[3,11];case 5:return c.sent(),[3,10];case 6:return a!==this.heapArray.length-1?[3,7]:(this.heapArray.pop(),[3,10]);case 7:return this.heapArray.splice(a,1,this.heapArray.pop()),[4,this._sortNodeUp(a)];case 8:return c.sent(),[4,this._sortNodeDown(a)];case 9:c.sent(),c.label=10;case 10:return[2,!0];case 11:s=t.getChildrenIndexOf(a).filter(function(o){return o<u.heapArray.length}),i.push.apply(i,E([],w(s),!1)),c.label=12;case 12:return[3,3];case 13:return[2,!1]}})})},t.prototype.replace=function(e){return y(this,void 0,void 0,function(){var r;return g(this,function(n){switch(n.label){case 0:return r=this.heapArray[0],this.heapArray[0]=e,[4,this._sortNodeDown(0)];case 1:return n.sent(),[2,r]}})})},t.prototype.size=function(){return this.length},t.prototype.top=function(){return y(this,arguments,void 0,function(e){return e===void 0&&(e=1),g(this,function(r){return this.heapArray.length===0||e<=0?[2,[]]:this.heapArray.length===1||e===1?[2,[this.heapArray[0]]]:e>=this.heapArray.length?[2,E([],w(this.heapArray),!1)]:[2,this._topN_push(~~e)]})})},t.prototype.toArray=function(){return E([],w(this.heapArray),!1)},t.prototype.toString=function(){return this.heapArray.toString()},t.prototype.get=function(e){return this.heapArray[e]},t.prototype.getChildrenOf=function(e){var r=this;return t.getChildrenIndexOf(e).map(function(n){return r.heapArray[n]}).filter(function(n){return n!==void 0})},t.prototype.getParentOf=function(e){var r=t.getParentIndexOf(e);return this.heapArray[r]},t.prototype[Symbol.iterator]=function(){return g(this,function(e){switch(e.label){case 0:return this.length?[4,this.pop()]:[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}})},t.prototype.iterator=function(){return this},t.prototype._applyLimit=function(){if(this._limit&&this._limit<this.heapArray.length)for(var e=this.heapArray.length-this._limit;e;)this.heapArray.pop(),--e},t.prototype._bottomN_push=function(e){return y(this,void 0,void 0,function(){var r,n,i,a,u,s,u;return g(this,function(c){switch(c.label){case 0:return r=new t(this.compare),r.limit=e,r.heapArray=this.heapArray.slice(-e),[4,r.init()];case 1:for(c.sent(),n=this.heapArray.length-1-e,i=t.getParentIndexOf(n),a=[],u=n;u>i;--u)a.push(u);s=this.heapArray,c.label=2;case 2:return a.length?(u=a.shift(),[4,this.compare(s[u],r.peek())]):[3,6];case 3:return c.sent()>0?[4,r.replace(s[u])]:[3,5];case 4:c.sent(),u%2&&a.push(t.getParentIndexOf(u)),c.label=5;case 5:return[3,2];case 6:return[2,r.toArray()]}})})},t.prototype._moveNode=function(e,r){var n=this.heapArray[e];this.heapArray[e]=this.heapArray[r],this.heapArray[r]=n},t.prototype._sortNodeDown=function(e){return y(this,void 0,void 0,function(){var r,n,i,a,s,u,c;return g(this,function(o){switch(o.label){case 0:r=this.heapArray.length,n=e,i=this.heapArray[e],a=2*e+1,o.label=1;case 1:return a<r?(s=a+1,c=s>=r,c?[3,3]:[4,this.compare(this.heapArray[a],this.heapArray[s])]):[3,5];case 2:c=o.sent()<0,o.label=3;case 3:return u=c?a:s,[4,this.compare(this.heapArray[u],i)];case 4:if(o.sent()<0)this.heapArray[e]=this.heapArray[u],e=u,a=2*e+1;else return[3,5];return[3,1];case 5:return e!==n&&(this.heapArray[e]=i),[2]}})})},t.prototype._sortNodeUp=function(e){return y(this,void 0,void 0,function(){var r,n,i;return g(this,function(a){switch(a.label){case 0:r=this.heapArray[e],n=e,a.label=1;case 1:return e>0?(i=t.getParentIndexOf(e),[4,this.compare(r,this.heapArray[i])]):[3,3];case 2:if(a.sent()<0)this.heapArray[e]=this.heapArray[i],e=i;else return[3,3];return[3,1];case 3:return e!==n&&(this.heapArray[e]=r),[2]}})})},t.prototype._topN_push=function(e){return y(this,void 0,void 0,function(){var r,n,i,a;return g(this,function(s){switch(s.label){case 0:r=new t(this._invertedCompare),r.limit=e,n=[0],i=this.heapArray,s.label=1;case 1:return n.length?(a=n.shift(),a<i.length?r.length<e?[4,r.push(i[a])]:[3,3]:[3,6]):[3,7];case 2:return s.sent(),n.push.apply(n,E([],w(t.getChildrenIndexOf(a)),!1)),[3,6];case 3:return[4,this.compare(i[a],r.peek())];case 4:return s.sent()<0?[4,r.replace(i[a])]:[3,6];case 5:s.sent(),n.push.apply(n,E([],w(t.getChildrenIndexOf(a)),!1)),s.label=6;case 6:return[3,1];case 7:return[2,r.toArray()]}})})},t.prototype._topN_fill=function(e){return y(this,void 0,void 0,function(){var r,n,i,a,s,s;return g(this,function(u){switch(u.label){case 0:return r=this.heapArray,n=new t(this._invertedCompare),n.limit=e,n.heapArray=r.slice(0,e),[4,n.init()];case 1:for(u.sent(),i=t.getParentIndexOf(e-1)+1,a=[],s=i;s<e;++s)a.push.apply(a,E([],w(t.getChildrenIndexOf(s).filter(function(c){return c<r.length})),!1));(e-1)%2&&a.push(e),u.label=2;case 2:return a.length?(s=a.shift(),s<r.length?[4,this.compare(r[s],n.peek())]:[3,5]):[3,6];case 3:return u.sent()<0?[4,n.replace(r[s])]:[3,5];case 4:u.sent(),a.push.apply(a,E([],w(t.getChildrenIndexOf(s)),!1)),u.label=5;case 5:return[3,2];case 6:return[2,n.toArray()]}})})},t.prototype._topN_heap=function(e){return y(this,void 0,void 0,function(){var r,n,i,a,s;return g(this,function(u){switch(u.label){case 0:r=this.clone(),n=[],i=0,u.label=1;case 1:return i<e?(s=(a=n).push,[4,r.pop()]):[3,4];case 2:s.apply(a,[u.sent()]),u.label=3;case 3:return++i,[3,1];case 4:return[2,n]}})})},t.prototype._topIdxOf=function(e){return y(this,void 0,void 0,function(){var r,n,i,a;return g(this,function(s){switch(s.label){case 0:if(!e.length)return[2,-1];r=0,n=e[r],i=1,s.label=1;case 1:return i<e.length?[4,this.compare(e[i],n)]:[3,4];case 2:a=s.sent(),a<0&&(r=i,n=e[i]),s.label=3;case 3:return++i,[3,1];case 4:return[2,r]}})})},t.prototype._topOf=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return y(this,void 0,void 0,function(){var n;return g(this,function(i){switch(i.label){case 0:return n=new t(this.compare),[4,n.init(e)];case 1:return i.sent(),[2,n.peek()]}})})},t})();var Ht=function(t,e){var r={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},n,i,a,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=u(0),s.throw=u(1),s.return=u(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(o){return function(f){return c([o,f])}}function c(o){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,o[0]&&(r=0)),r;)try{if(n=1,i&&(a=o[0]&2?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[o[0]&2,a.value]),o[0]){case 0:case 1:a=o;break;case 4:return r.label++,{value:o[1],done:!1};case 5:r.label++,i=o[1],o=[0];continue;case 7:o=r.ops.pop(),r.trys.pop();continue;default:if(a=r.trys,!(a=a.length>0&&a[a.length-1])&&(o[0]===6||o[0]===2)){r=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){r.label=o[1];break}if(o[0]===6&&r.label<a[1]){r.label=a[1],a=o;break}if(a&&r.label<a[2]){r.label=a[2],r.ops.push(o);break}a[2]&&r.ops.pop(),r.trys.pop();continue}o=e.call(t,r)}catch(f){o=[6,f],i=0}finally{n=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}},v=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],s;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(u){s={error:u}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return a},A=function(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},qt=(function(){function t(e){e===void 0&&(e=t.minComparator);var r=this;this.compare=e,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this.removeAll=this.clear,this._invertedCompare=function(n,i){return-1*r.compare(n,i)}}return t.getChildrenIndexOf=function(e){return[e*2+1,e*2+2]},t.getParentIndexOf=function(e){return e<=0?-1:e-1>>1},t.getSiblingIndexOf=function(e){if(e<=0)return-1;var r=e%2?1:-1;return e+r},t.minComparator=function(e,r){return e>r?1:e<r?-1:0},t.maxComparator=function(e,r){return r>e?1:r<e?-1:0},t.minComparatorNumber=function(e,r){return e-r},t.maxComparatorNumber=function(e,r){return r-e},t.defaultIsEqual=function(e,r){return e===r},t.print=function(e){function r(f){var h=t.getParentIndexOf(f);return Math.floor(Math.log2(h+1))}function n(f,h){for(var p="";h>0;--h)p+=f;return p}for(var i=0,a=[],s=r(e.length-1)+2,u=0;i<e.length;){var c=r(i)+1;i===0&&(c=0);var o=String(e.get(i));o.length>u&&(u=o.length),a[c]=a[c]||[],a[c].push(o),i+=1}return a.map(function(f,h){var p=Math.pow(2,s-h)-1;return n(" ",Math.floor(p/2)*u)+f.map(function(d){var O=(u-d.length)/2;return n(" ",Math.ceil(O))+d+n(" ",Math.floor(O))}).join(n(" ",p*u))}).join(`
4
- `)},t.heapify=function(e,r){var n=new t(r);return n.heapArray=e,n.init(),n},t.heappop=function(e,r){var n=new t(r);return n.heapArray=e,n.pop()},t.heappush=function(e,r,n){var i=new t(n);i.heapArray=e,i.push(r)},t.heappushpop=function(e,r,n){var i=new t(n);return i.heapArray=e,i.pushpop(r)},t.heapreplace=function(e,r,n){var i=new t(n);return i.heapArray=e,i.replace(r)},t.heaptop=function(e,r,n){r===void 0&&(r=1);var i=new t(n);return i.heapArray=e,i.top(r)},t.heapbottom=function(e,r,n){r===void 0&&(r=1);var i=new t(n);return i.heapArray=e,i.bottom(r)},t.nlargest=function(e,r,n){var i=new t(n);return i.heapArray=A([],v(r),!1),i.init(),i.top(e)},t.nsmallest=function(e,r,n){var i=new t(n);return i.heapArray=A([],v(r),!1),i.init(),i.bottom(e)},t.prototype.add=function(e){return this._sortNodeUp(this.heapArray.push(e)-1),this._applyLimit(),!0},t.prototype.addAll=function(e){var r,n=this.length;(r=this.heapArray).push.apply(r,A([],v(e),!1));for(var i=this.length;n<i;++n)this._sortNodeUp(n);return this._applyLimit(),!0},t.prototype.bottom=function(e){return e===void 0&&(e=1),this.heapArray.length===0||e<=0?[]:this.heapArray.length===1?[this.heapArray[0]]:e>=this.heapArray.length?A([],v(this.heapArray),!1):this._bottomN_push(~~e)},t.prototype.check=function(){var e=this;return this.heapArray.find(function(r,n){return!!e.getChildrenOf(n).find(function(i){return e.compare(r,i)>0})})},t.prototype.clear=function(){this.heapArray=[]},t.prototype.clone=function(){var e=new t(this.comparator());return e.heapArray=this.toArray(),e._limit=this._limit,e},t.prototype.comparator=function(){return this.compare},t.prototype.contains=function(e,r){return r===void 0&&(r=t.defaultIsEqual),this.indexOf(e,r)!==-1},t.prototype.init=function(e){e&&(this.heapArray=A([],v(e),!1));for(var r=t.getParentIndexOf(this.length-1);r>=0;--r)this._sortNodeDown(r);this._applyLimit()},t.prototype.isEmpty=function(){return this.length===0},t.prototype.indexOf=function(e,r){if(r===void 0&&(r=t.defaultIsEqual),this.heapArray.length===0)return-1;for(var n=[],i=0;i<this.heapArray.length;){var a=this.heapArray[i];if(r(a,e))return i;this.compare(a,e)<=0&&n.push.apply(n,A([],v(t.getChildrenIndexOf(i)),!1)),i=n.shift()||this.heapArray.length}return-1},t.prototype.indexOfEvery=function(e,r){if(r===void 0&&(r=t.defaultIsEqual),this.heapArray.length===0)return[];for(var n=[],i=[],a=0;a<this.heapArray.length;){var s=this.heapArray[a];r(s,e)?(i.push(a),n.push.apply(n,A([],v(t.getChildrenIndexOf(a)),!1))):this.compare(s,e)<=0&&n.push.apply(n,A([],v(t.getChildrenIndexOf(a)),!1)),a=n.shift()||this.heapArray.length}return i},t.prototype.leafs=function(){if(this.heapArray.length===0)return[];var e=t.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(e+1)},Object.defineProperty(t.prototype,"length",{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"limit",{get:function(){return this._limit},set:function(e){e<0||isNaN(e)?this._limit=0:this._limit=~~e,this._applyLimit()},enumerable:!1,configurable:!0}),t.prototype.setLimit=function(e){return this.limit=e,e<0||isNaN(e)?NaN:this._limit},t.prototype.peek=function(){return this.heapArray[0]},t.prototype.pop=function(){var e=this.heapArray.pop();return this.length>0&&e!==void 0?this.replace(e):e},t.prototype.push=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return e.length<1?!1:e.length===1?this.add(e[0]):this.addAll(e)},t.prototype.pushpop=function(e){var r;return this.compare(this.heapArray[0],e)<0&&(r=v([this.heapArray[0],e],2),e=r[0],this.heapArray[0]=r[1],this._sortNodeDown(0)),e},t.prototype.remove=function(e,r){var n=this;if(r===void 0&&(r=t.defaultIsEqual),!this.heapArray.length)return!1;if(e===void 0)return this.pop(),!0;for(var i=[0];i.length;){var a=i.shift();if(r(this.heapArray[a],e))return a===0?this.pop():a===this.heapArray.length-1?this.heapArray.pop():(this.heapArray.splice(a,1,this.heapArray.pop()),this._sortNodeUp(a),this._sortNodeDown(a)),!0;if(this.compare(this.heapArray[a],e)<=0){var s=t.getChildrenIndexOf(a).filter(function(u){return u<n.heapArray.length});i.push.apply(i,A([],v(s),!1))}}return!1},t.prototype.replace=function(e){var r=this.heapArray[0];return this.heapArray[0]=e,this._sortNodeDown(0),r},t.prototype.size=function(){return this.length},t.prototype.top=function(e){return e===void 0&&(e=1),this.heapArray.length===0||e<=0?[]:this.heapArray.length===1||e===1?[this.heapArray[0]]:e>=this.heapArray.length?A([],v(this.heapArray),!1):this._topN_push(~~e)},t.prototype.toArray=function(){return A([],v(this.heapArray),!1)},t.prototype.toString=function(){return this.heapArray.toString()},t.prototype.get=function(e){return this.heapArray[e]},t.prototype.getChildrenOf=function(e){var r=this;return t.getChildrenIndexOf(e).map(function(n){return r.heapArray[n]}).filter(function(n){return n!==void 0})},t.prototype.getParentOf=function(e){var r=t.getParentIndexOf(e);return this.heapArray[r]},t.prototype[Symbol.iterator]=function(){return Ht(this,function(e){switch(e.label){case 0:return this.length?[4,this.pop()]:[3,2];case 1:return e.sent(),[3,0];case 2:return[2]}})},t.prototype.iterator=function(){return this.toArray()},t.prototype._applyLimit=function(){if(this._limit>0&&this._limit<this.heapArray.length)for(var e=this.heapArray.length-this._limit;e;)this.heapArray.pop(),--e},t.prototype._bottomN_push=function(e){var r=new t(this.compare);r.limit=e,r.heapArray=this.heapArray.slice(-e),r.init();for(var n=this.heapArray.length-1-e,i=t.getParentIndexOf(n),a=[],s=n;s>i;--s)a.push(s);for(var u=this.heapArray;a.length;){var s=a.shift();this.compare(u[s],r.peek())>0&&(r.replace(u[s]),s%2&&a.push(t.getParentIndexOf(s)))}return r.toArray()},t.prototype._moveNode=function(e,r){var n=this.heapArray[e];this.heapArray[e]=this.heapArray[r],this.heapArray[r]=n},t.prototype._sortNodeDown=function(e){for(var r=this.heapArray.length,n=e,i=this.heapArray[e],a=2*e+1;a<r;){var s=a+1,u=s>=r||this.compare(this.heapArray[a],this.heapArray[s])<0?a:s;if(this.compare(this.heapArray[u],i)<0)this.heapArray[e]=this.heapArray[u],e=u,a=2*e+1;else break}e!==n&&(this.heapArray[e]=i)},t.prototype._sortNodeUp=function(e){for(var r=this.heapArray[e],n=e;e>0;){var i=t.getParentIndexOf(e);if(this.compare(r,this.heapArray[i])<0)this.heapArray[e]=this.heapArray[i],e=i;else break}e!==n&&(this.heapArray[e]=r)},t.prototype._topN_push=function(e){var r=new t(this._invertedCompare);r.limit=e;for(var n=[0],i=this.heapArray;n.length;){var a=n.shift();a<i.length&&(r.length<e?(r.push(i[a]),n.push.apply(n,A([],v(t.getChildrenIndexOf(a)),!1))):this.compare(i[a],r.peek())<0&&(r.replace(i[a]),n.push.apply(n,A([],v(t.getChildrenIndexOf(a)),!1))))}return r.toArray()},t.prototype._topN_fill=function(e){var r=this.heapArray,n=new t(this._invertedCompare);n.limit=e,n.heapArray=r.slice(0,e),n.init();for(var i=t.getParentIndexOf(e-1)+1,a=[],s=i;s<e;++s)a.push.apply(a,A([],v(t.getChildrenIndexOf(s).filter(function(u){return u<r.length})),!1));for((e-1)%2&&a.push(e);a.length;){var s=a.shift();s<r.length&&this.compare(r[s],n.peek())<0&&(n.replace(r[s]),a.push.apply(a,A([],v(t.getChildrenIndexOf(s)),!1)))}return n.toArray()},t.prototype._topN_heap=function(e){for(var r=this.clone(),n=[],i=0;i<e;++i)n.push(r.pop());return n},t.prototype._topIdxOf=function(e){if(!e.length)return-1;for(var r=0,n=e[r],i=1;i<e.length;++i){var a=this.compare(e[i],n);a<0&&(r=i,n=e[i])}return r},t.prototype._topOf=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=new t(this.compare);return n.init(e),n.peek()},t})();function zt(t,e,r){return Math.abs((t[0]*(e[1]-r[1])+e[0]*(r[1]-t[1])+r[0]*(t[1]-e[1]))/2)}function ie(t,{tolerance:e=0,getWeight:r=()=>1}={}){if(t.length<=2)return t;const n=t.map((o,f)=>({coord:o,i:f,area:1/0,removed:!1,prev:null,next:null}));for(let o=0;o<n.length;o++)o>0&&(n[o].prev=n[o-1]),o<n.length-1&&(n[o].next=n[o+1]);const i=o=>!o.prev||!o.next?1/0:zt(o.prev.coord,o.coord,o.next.coord)*r(o.coord,o.i),a=new qt((o,f)=>o.area-f.area);for(let o=1;o<n.length-1;o++)n[o].area=i(n[o]),n[o]._currentArea=n[o].area,a.push(n[o]);let s=0;for(;a.size()>0;){const o=a.pop();if(!o.removed&&o.area===o._currentArea){if(o.area<s?o.area=s:s=o.area,o.area>=e)break;o.removed=!0,o.prev&&(o.prev.next=o.next),o.next&&(o.next.prev=o.prev),o.prev?.prev&&(o.prev.area=i(o.prev),o.prev._currentArea=o.prev.area,a.push(o.prev)),o.next?.next&&(o.next.area=i(o.next),o.next._currentArea=o.next.area,a.push(o.next))}}const u=[];let c=n[0];for(;c;)c.removed||u.push(c.coord),c=c.next;return u}function Y(t,e){switch(l.assert.all([{value:t,validator:K,message:"geometry must be a GeoJson geometry"}]),t.type){case m.LINESTRING:t.coordinates=ie(t.coordinates,e);break;case m.POLYGON:case m.MULTI_LINESTRING:t.coordinates=t.coordinates.map(r=>ie(r,e));break;case m.MULTI_POLYGON:t.coordinates=t.coordinates.map(r=>r.map(n=>ie(n,e)));break;case m.GEOMETRY_COLLECTION:t.geometries.forEach(r=>Y(r,e));break}return t}const Bt=Ue(["common-ekosystem","simplify","geojson"]);function Be(t,e){if(t.type===L.FEATURE)t.geometry&&Y(t.geometry,e);else if(t.type===L.FEATURE_COLLECTION)for(const r of t.features)Be(r,e);else Bt.warn('Unknown feature type "{type}", skipping.',{type:t.type});return t}function Wt(t,e){return l.assert.all([{value:t,validator:he,message:"geoJson must be a GeoJson object"}]),l.is.oneOf(t.type,Object.values(m))?Y(t,e):Be(t,e)}function ge(t,e=7){l.assert.all([{value:t,validator:$e,message:"bbox must be bounding box"},{value:e,validator:n=>l.is.inRange(n,0,8),message:"precision must be in range [0, 8]"}]);const r=V[e];for(let n=0;n<t.length;n++)t[n]=Math.round(t[n]*r)/r;return t}function jt(t,e,r={}){const n={type:"Feature"};return(r.id===0||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties={},n.geometry=t,n}function Vt(t,e,r={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!Le(t[0])||!Le(t[1]))throw new Error("coordinates must contain numbers");return jt({type:"Point",coordinates:t},e,r)}function Le(t){return!isNaN(t)&&t!==null&&!Array.isArray(t)}function Kt(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function We(t,e,r){if(t!==null)for(var n,i,a,s,u,c,o,f=0,h=0,p,d=t.type,O=d==="FeatureCollection",U=d==="Feature",F=O?t.features.length:1,S=0;S<F;S++){o=O?t.features[S].geometry:U?t.geometry:t,p=o?o.type==="GeometryCollection":!1,u=p?o.geometries.length:1;for(var Z=0;Z<u;Z++){var T=0,N=0;if(s=p?o.geometries[Z]:o,s!==null){c=s.coordinates;var D=s.type;switch(f=0,D){case null:break;case"Point":if(e(c,h,S,T,N)===!1)return!1;h++,T++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(e(c[n],h,S,T,N)===!1)return!1;h++,D==="MultiPoint"&&T++}D==="LineString"&&T++;break;case"Polygon":case"MultiLineString":for(n=0;n<c.length;n++){for(i=0;i<c[n].length-f;i++){if(e(c[n][i],h,S,T,N)===!1)return!1;h++}D==="MultiLineString"&&T++,D==="Polygon"&&N++}D==="Polygon"&&T++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(N=0,i=0;i<c[n].length;i++){for(a=0;a<c[n][i].length-f;a++){if(e(c[n][i][a],h,S,T,N)===!1)return!1;h++}N++}T++}break;case"GeometryCollection":for(n=0;n<s.geometries.length;n++)if(We(s.geometries[n],e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Yt(t,e){if(e=e??{},!Kt(e))throw new Error("options is invalid");var r=e.precision,n=e.coordinates,i=e.mutate;if(r=r==null||isNaN(r)?6:r,n=n==null||isNaN(n)?3:n,!t)throw new Error("<geojson> is required");if(typeof r!="number")throw new Error("<precision> must be a number");if(typeof n!="number")throw new Error("<coordinates> must be a number");(i===!1||i===void 0)&&(t=JSON.parse(JSON.stringify(t)));var a=Math.pow(10,r);return We(t,function(s){Jt(s,a,n)}),t}function Jt(t,e,r){t.length>r&&t.splice(r,t.length);for(var n=0;n<t.length;n++)t[n]=Math.round(t[n]*e)/e;return t}var Zt=Yt;function ye(t,e=7){l.assert.all([{value:t,validator:K,message:"geometry must be a GeoJson geometry"},{value:e,validator:n=>l.is.inRange(n,0,8),message:"precision must be in range [0, 8]"}]);const r=Zt(t,{precision:e,mutate:!0});return r.bbox&&ge(r.bbox,e),r}const Xt=Ue(["common-ekosystem","truncate","geojson"]);function je(t,e){if(t.type===L.FEATURE)t.geometry&&ye(t.geometry,e);else if(t.type===L.FEATURE_COLLECTION)for(const r of t.features)je(r,e);else Xt.warn('Unknown feature type "{type}", skipping.',{type:t.type});return t.bbox&&ge(t.bbox,e),t}function Qt(t,e=7){return l.assert.all([{value:t,validator:he,message:"geoJson must be a valid GeoJson"},{value:e,validator:r=>l.is.inRange(r,0,8),message:"precision must be in range [0, 8]"}]),l.is.oneOf(t.type,Object.values(m))?ye(t,e):je(t,e)}function er(t,e=7){l.assert.all([{value:t,validator:Ge,message:"position must be a position"},{value:e,validator:n=>l.is.inRange(n,0,8),message:"precision must be in range [0, 8]"}]);const r=V[e];for(let n=0;n<t.length;n++)t[n]=Math.round(t[n]*r)/r;return t}function P(t){if(!l.is.arrayOfLengthBetween(t,2,3))return{valid:!1,errors:[{message:"Invalid coordinates: must be an array of 2 or 3 coordinates"}],warnings:[]};if(!l.is.inRange(t[0],-180,180))return{valid:!1,errors:[{message:"Invalid coordinates: longitude must be in the range -180 to 180"}],warnings:[]};if(!l.is.inRange(t[1],-90,90))return{valid:!1,errors:[{message:"Invalid coordinates: latitude must be in the range -90 to 90"}],warnings:[]};if(t.length===3&&!l.is.number(t[2]))return{valid:!1,errors:[{message:"Invalid coordinates: altitude must be a number"}],warnings:[]};const e={valid:!0,errors:[],warnings:[]},r=oe(t[0]);r>6&&e.warnings.push({message:`longitude precision is high (${r} decimals, max recommended: 6)`});const n=oe(t[1]);return n>6&&e.warnings.push({message:`latitude precision is high (${n} decimals, max recommended: 6)`}),e}function Ve(t){if(!l.is.arrayOfLength(t,4)&&!l.is.arrayOfLength(t,6))return{valid:!1,errors:[{message:"Invalid bbox: must be an array of 4 (2D) or 6 (3D) numbers"}],warnings:[]};const e=t.length===4,r=e?[t[0],t[1]]:[t[0],t[1],t[2]],n=e?[t[2],t[3]]:[t[3],t[4],t[5]],i=P(r);if(!i.valid)return{valid:!1,errors:i.errors.map(h=>({...h,message:`Invalid bbox south-west: ${h.message}`})),warnings:[]};const a=P(n);if(!a.valid)return{valid:!1,errors:a.errors.map(h=>({...h,message:`Invalid bbox north-east: ${h.message}`})),warnings:[]};const[s,u]=r,[c,o]=n;if(u>o)return{valid:!1,errors:[{message:`Invalid bbox: south (${u}) must be <= north (${o})`}],warnings:[]};const f={valid:!0,errors:[],warnings:[]};return s>c&&f.warnings.push({message:`bbox crosses the antimeridian (west: ${s} > east: ${c})`}),f.warnings.push(...i.warnings.map(h=>({...h,message:`south-west: ${h.message}`}))),f.warnings.push(...a.warnings.map(h=>({...h,message:`north-east: ${h.message}`}))),f}function Ke(t){if(!l.is.plainObject(t))return{valid:!1,errors:[{message:"Invalid crs: must be an object"}],warnings:[]};switch(t.type){case k.NAME:return l.is.nonEmptyString(t.properties?.name)?{valid:!0,errors:[],warnings:[]}:{valid:!1,errors:[{message:"Invalid crs: linked crs must have a non-empty properties.name string"}],warnings:[]};case k.LINK:return l.is.nonEmptyString(t.properties?.href)?{valid:!0,errors:[],warnings:[]}:{valid:!1,errors:[{message:"Invalid crs: linked crs must have a non-empty properties.href string"}],warnings:[]};default:return{valid:!1,errors:[{message:`Invalid crs: unknown type: ${t.type}`}],warnings:[]}}}function tr(t){if(Array.isArray(t))return t;if(t.type==="Feature"){if(t.geometry!==null)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function rr(t){const e=tr(t);let r=0,n=1,i,a;for(;n<e.length;)i=a||e[0],a=e[n],r+=(a[0]-i[0])*(a[1]+i[1]),n++;return r>0}var nr=rr;function ir(t){let e,r;const n={type:"FeatureCollection",features:[]};if(t.type==="Feature"?r=t.geometry:r=t,r.type==="LineString")e=[r.coordinates];else if(r.type==="MultiLineString")e=r.coordinates;else if(r.type==="MultiPolygon")e=[].concat(...r.coordinates);else if(r.type==="Polygon")e=r.coordinates;else throw new Error("Input must be a LineString, MultiLineString, Polygon, or MultiPolygon Feature or Geometry");return e.forEach(i=>{e.forEach(a=>{for(let s=0;s<i.length-1;s++)for(let u=s;u<a.length-1;u++){if(i===a&&(Math.abs(s-u)===1||s===0&&u===i.length-2&&i[s][0]===i[i.length-1][0]&&i[s][1]===i[i.length-1][1]))continue;const c=ar(i[s][0],i[s][1],i[s+1][0],i[s+1][1],a[u][0],a[u][1],a[u+1][0],a[u+1][1]);c&&n.features.push(Vt([c[0],c[1]]))}})}),n}function ar(t,e,r,n,i,a,s,u){let c,o,f,h,p;const d={x:null,y:null,onLine1:!1,onLine2:!1};return c=(u-a)*(r-t)-(s-i)*(n-e),c===0?d.x!==null&&d.y!==null?d:!1:(o=e-a,f=t-i,h=(s-i)*o-(u-a)*f,p=(r-t)*o-(n-e)*f,o=h/c,f=p/c,d.x=t+o*(r-t),d.y=e+o*(n-e),o>=0&&o<=1&&(d.onLine1=!0),f>=0&&f<=1&&(d.onLine2=!0),d.onLine1&&d.onLine2?[d.x,d.y]:!1)}var sr=ir;function M(){return{Feature:0,FeatureCollection:0,geometries:{}}}function or(...t){const e=M();for(const r of t){const n=r.statistics;if(n){e.Feature+=n.Feature??0,e.FeatureCollection+=n.FeatureCollection??0;for(const[i,a]of Object.entries(n.geometries??{}))e.geometries[i]=(e.geometries[i]??0)+a}}return e}function R(t,e,r=""){const n={valid:!0,errors:[],warnings:[]};for(let i=0;i<t.length;i++){const a=`${r}/${i}`,s=e(t[i],a,i);if(!s.valid){n.valid=!1,n.errors=n.errors.concat(s.errors.map(u=>({...u,path:u.path||a,index:i})));continue}l.is.empty(s.warnings)||(n.warnings=n.warnings.concat(s.warnings.map(u=>({...u,path:u.path||a,index:i})))),s.statistics&&(n.statistics=or(n,s))}return n}function lr(t,e){if(!l.is.defined(t.crs))return e;const r=Ke(t.crs);return r.valid||(e.valid=!1,e.errors.push(...r.errors.map(n=>({...n,path:"/crs"})))),e.warnings.push(...r.warnings.map(n=>({...n,path:"/crs"}))),e}function le(t,e,r=""){if(!l.is.defined(t.bbox))return e;const n=Ve(t.bbox);return n.valid||(e.valid=!1,e.errors.push(...n.errors.map(i=>({...i,path:`${r}/bbox`})))),e.warnings.push(...n.warnings.map(i=>({...i,path:`${r}/bbox`}))),e}function de(t,e=0,r=""){return l.is.arrayOfLengthAtLeast(t,e)?R(t,P,r):{valid:!1,errors:[{message:`Invalid coordinates: must have at least ${e} positions`,path:r}],warnings:[]}}function Ye(t,e=""){const r=de(t,2,e);if(!r.valid)return r;for(let n=0;n<t.length-1;n++){const i=t[n][0],a=t[n+1][0];Math.abs(a-i)>180&&r.warnings.push({message:`LineString crosses the antimeridian between positions ${n} and ${n+1}, consider using MultiLineString`,path:`${e}/${n}`})}return r}function ur(t,e=""){return l.is.nonEmptyArray(t)?R(t,Ye,e):{valid:!1,errors:[{message:"Invalid MultiLineString: coordinates must be a non empty array",path:e}],warnings:[]}}function cr(t,e,r=""){const n=de(t,4,r);if(!n.valid)return n;const i=t[0],a=t[t.length-1];if(i[0]!==a[0]||i[1]!==a[1])return n.valid=!1,n.errors.push({message:"Invalid LinearRing: first and last position must be identical",path:r}),n;const u=nr(t)?"clockwise":"counter-clockwise";u!==e&&n.warnings.push({message:`Ring must be ${e} but is ${u}`,path:r});const c=sr({type:"Polygon",coordinates:[t]});return c.features.length>0&&(n.valid=!1,n.errors.push({message:`Invalid LinearRing: ${c.features.length} self-intersection(s) detected`,path:r})),n}function Je(t,e=""){return l.is.nonEmptyArray(t)?R(t,(r,n,i)=>cr(r,i===0?"counter-clockwise":"clockwise",n),e):{valid:!1,errors:[{message:"Invalid Polygon: coordinates must be a non empty array",path:e}],warnings:[]}}function fr(t,e=""){return l.is.nonEmptyArray(t)?R(t,(r,n)=>Je(r,n),e):{valid:!1,errors:[{message:"Invalid MultiPolygon: coordinates must be a non empty array",path:e}],warnings:[]}}function hr(t,e=""){return l.is.nonEmptyArray(t)?R(t,(r,n)=>J(r,n),e):{valid:!1,errors:[{message:"Invalid geometries: geometries must be a non empty array",path:e}],warnings:[]}}function J(t,e=""){if(!l.is.nonEmptyObject(t))return{valid:!1,errors:[{message:"Invalid geometry: geometry must be a non empty object",path:e}],warnings:[]};const r=`${e}/coordinates`;let n;switch(t.type){case m.POINT:{const i=P(t.coordinates);n={valid:i.valid,errors:i.errors.map(a=>({...a,path:r})),warnings:i.warnings.map(a=>({...a,path:r}))};break}case m.MULTI_POINT:{n=de(t.coordinates,0,r);break}case m.LINESTRING:{n=Ye(t.coordinates,r);break}case m.MULTI_LINESTRING:{n=ur(t.coordinates,r);break}case m.POLYGON:{n=Je(t.coordinates,r);break}case m.MULTI_POLYGON:{n=fr(t.coordinates,r);break}case m.GEOMETRY_COLLECTION:{n=hr(t.geometries,`${e}/geometries`);break}default:return{valid:!1,errors:[{message:`Invalid geometry type: ${t.type}`,path:e}],warnings:[]}}return le(t,n,e)}function Ze(t,e=""){if(!l.is.nonEmptyObject(t))return{valid:!1,errors:[{message:"Invalid feature: must be a non empty object",path:e}],warnings:[],statistics:M()};if(t.type===L.FEATURE){if(l.is.nonEmptyObject(t.geometry)){const r=J(t.geometry,`${e}/geometry`);return{...le(t,r,e),statistics:{Feature:1,FeatureCollection:0,geometries:{[t.geometry.type]:1}}}}return{valid:!0,errors:[],warnings:[{message:"Feature has no geometry",path:e}],statistics:{Feature:1,FeatureCollection:0,geometries:{}}}}if(t.type===L.FEATURE_COLLECTION){if(l.is.nonEmptyArray(t.features)){const r=R(t.features,Ze,`${e}/features`);return{...le(t,r,e),statistics:{...r.statistics,FeatureCollection:r.statistics.FeatureCollection+1}}}return{valid:!1,errors:[{message:"Invalid FeatureCollection: features must be a non empty array",path:e}],warnings:[],statistics:M()}}return{valid:!1,errors:[{message:`Invalid feature: unknown type: ${t.type}`,path:e}],warnings:[],statistics:M()}}function pr(t){if(l.assert.that(t,l.is.nonEmptyObject,"geojson must be a non empty object"),l.is.oneOf(t.type,Object.values(m)))return{...J(t,""),statistics:{Feature:0,FeatureCollection:0,geometries:{[t.type]:1}}};if(t.type===L.FEATURE||t.type===L.FEATURE_COLLECTION){const e=Ze(t,"");return lr(t,e)}return{valid:!1,errors:[{message:"Invalid GeoJson: type must be either a Geometry, a Feature or a FeatureCollection"}],warnings:[],statistics:M()}}exports.AXES=b;exports.COORDINATE_FORMATS=B;exports.COORDINATE_MODELS=Re;exports.COORDINATE_TRUNCATION_FACTORS=V;exports.CRS_TYPES=k;exports.FEATURE_TYPES=L;exports.GEOMETRY_TYPES=m;exports.convertCoordinate=Ct;exports.getCoordinatePrecision=oe;exports.getDirectionAxis=Ne;exports.getDirections=ot;exports.getEast=ct;exports.getLocale=Ce;exports.getNorth=lt;exports.getSouth=ut;exports.getWest=ft;exports.guessCoordinateAxis=se;exports.isAltitude=Xe;exports.isAxis=Te;exports.isDirection=I;exports.isEast=fe;exports.isLatitude=z;exports.isLikeBBox=$e;exports.isLikeCRS=Nt;exports.isLikeFeature=ke;exports.isLikeFeatureCollection=Pe;exports.isLikeGeoJson=he;exports.isLikeGeometry=K;exports.isLikePosition=Ge;exports.isLongitude=ue;exports.isNorth=Ie;exports.isSouth=ce;exports.isWest=j;exports.listLocales=it;exports.normalizeCoordinate=Tt;exports.parseCoordinate=Me;exports.parsePosition=It;exports.registerLocale=at;exports.setLocale=st;exports.simplifyGeoJson=Wt;exports.simplifyGeometry=Y;exports.truncateBBox=ge;exports.truncateCoordinate=Lt;exports.truncateGeoJson=Qt;exports.truncateGeometry=ye;exports.truncatePosition=er;exports.validateBBox=Ve;exports.validateCRS=Ke;exports.validateGeoJson=pr;exports.validateGeometry=J;exports.validatePosition=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@kalisio/common-core"),j=require("@logtape/logtape"),me=require("heap-js"),de=require("@turf/truncate"),pe=require("@turf/boolean-clockwise"),ve=require("@turf/kinks"),f={LATITUDE:"LAT",LONGITUDE:"LON",ALTITUDE:"ALT"};function X(e){return n.assert.that(e,n.is.string,"axis must be a string"),Object.values(f).includes(e)}function I(e){return n.assert.that(e,n.is.string,"axis must be a string"),e===f.LATITUDE}function F(e){return n.assert.that(e,n.is.string,"axis must be a string"),e===f.LONGITUDE}function Ee(e){return n.assert.that(e,n.is.string,"axis must be a string"),e===f.ALTITUDE}const be={NORTH:{label:"Nord",symbol:"N"},SOUTH:{label:"Sud",symbol:"S"},EAST:{label:"Est",symbol:"E"},WEST:{label:"Ouest",symbol:"O"}},ye={DIRECTIONS:be},he={NORTH:{label:"North",symbol:"N"},SOUTH:{label:"South",symbol:"S"},EAST:{label:"East",symbol:"E"},WEST:{label:"West",symbol:"W"}},Oe={DIRECTIONS:he},Te={DIRECTIONS:{NORTH:{label:n.is.string,symbol:n.is.string},SOUTH:{label:n.is.string,symbol:n.is.string},EAST:{label:n.is.string,symbol:n.is.string},WEST:{label:n.is.string,symbol:n.is.string}}},h={en:Oe,fr:ye};let _="en";function Le(){return Object.keys(h)}function Ie(e,t){n.assert.all([{value:e,validator:n.is.string,message:"code must be a string"},{value:e,validator:s=>!n.has.key(h,s),message:"locale already registered"},{value:t,validator:n.is.plainObject,message:"content must be an object"},{value:t,validator:s=>n.conform.schema(s,Te),message:"content does not conform to schema"}]),h[e]=t}function Se(e){n.assert.all([{value:e,validator:n.is.string,message:"code must be a string"},{value:e,validator:t=>n.has.key(h,t),message:"code is unknown"}]),_=e}function q(){return{code:_,content:h[_]}}function E(){return q().content.DIRECTIONS}function D(e,t){const s=E(),r=s[e].label.toUpperCase(),i=s[e].symbol.toUpperCase();return t.toUpperCase()===r||t.toUpperCase()===i}function De(e=null){const t=E();return n.is.defined(e)?(n.assert.that(e,X,"axis must be a valid axis"),I(e)?[t.SOUTH,t.NORTH]:F(e)?[t.EAST,t.WEST]:[]):[t.SOUTH,t.NORTH,t.EAST,t.WEST]}function Re(){return E().NORTH}function Ae(){return E().SOUTH}function Ce(){return E().EAST}function Ne(){return E().WEST}function v(e){return n.assert.that(e,n.is.string,"dir must be a string"),z(e)||U(e)||k(e)||R(e)}function z(e){return n.assert.that(e,n.is.string,"dir must be a string"),D("NORTH",e)}function U(e){return n.assert.that(e,n.is.string,"dir must be a string"),D("SOUTH",e)}function k(e){return n.assert.that(e,n.is.string,"dir must be a string"),D("EAST",e)}function R(e){return n.assert.that(e,n.is.string,"dir must be a string"),D("WEST",e)}function J(e){return n.assert.that(e,v,"dir must be a direction"),R(e)||k(e)?f.LONGITUDE:f.LATITUDE}const we={degrees:n.is.number,direction:n.optional(v)},Me=/^(-?\d{1,3}(?:\.\d+)?)°?$/,_e=/^(\d{1,3}(?:\.\d+)?)°?([NSEW])$/;function L(e){let t=null,s=null;if(n.is.plainObject(e)&&n.conform.schema(e,we))n.is.defined(e.direction)?e.degrees>=0&&(t=e.degrees,s=e.direction):t=e.degrees;else if(n.is.string(e)){const r=e.replace(/\s+/g,""),i=r.match(Me)??r.match(_e);i&&(t=parseFloat(i[1]),s=i[2]??null)}return{get degrees(){return t},get direction(){return s},get format(){return"DD"},isValid(){return n.is.number(t)},toString(r){if(n.assert.that(r,n.is.positiveInteger,"decimalPlaces must be a positive integer"),!this.isValid())return"";let i=`${t.toFixed(r)}°`;return s&&(i+=` ${s}`),i},toDecimal(){return this.isValid()?L({degrees:t,direction:s}):null}}}const Ge={degrees:n.is.integer,minutes:e=>n.is.inRangeExclusiveMax(e,0,60),direction:n.optional(v)},xe=/^(-?\d{1,3})°(\d{1,2}(?:\.\d+)?)'?$/,$e=/^(\d{1,3})°(\d{1,2}(?:\.\d+)?)'?([NSEW])$/;function K(e){let t=null,s=null,r=null;if(n.is.plainObject(e)&&n.conform.schema(e,Ge))n.is.defined(e.direction)?e.degrees>=0&&(t=e.degrees,s=e.minutes,r=e.direction):(t=e.degrees,s=e.minutes);else if(n.is.string(e)){const i=e.replace(/\s+/g,""),o=i.match(xe)??i.match($e);o&&(t=parseFloat(o[1]),s=parseFloat(o[2]),r=o[3]??null)}return{get degrees(){return t},get minutes(){return s},get direction(){return r},get format(){return"DDM"},isValid(){return n.is.integer(t)&&n.is.inRangeExclusiveMax(s,0,60)},toString(i){if(n.assert.that(i,n.is.positiveInteger,"decimalPlaces must be a positive integer"),!this.isValid())return"";let o=`${t}° ${s.toFixed(i)}'`;return r&&(o+=` ${r}`),o},toDecimal(){return this.isValid()?L({degrees:t+s/60,direction:r}):null}}}const Fe={degrees:n.is.nonNegativeInteger,minutes:e=>n.is.inRangeExclusiveMax(e,0,60),direction:v},Ue=/^(\d{2})(\d{3})([NS])$/,ke=/^(\d{3})(\d{3})([EW])$/;function Q(e){let t=null,s=null,r=null;if(n.is.plainObject(e)&&n.conform.schema(e,Fe))t=e.degrees,s=e.minutes,r=e.direction;else if(n.is.string(e)){const i=e.trim(),o=i.match(Ue)??i.match(ke);o&&(t=parseFloat(o[1]),s=parseFloat(o[2])/10,r=o[3])}return{get degrees(){return t},get minutes(){return s},get direction(){return r},get format(){return"DDM_AERO"},isValid(){return n.is.nonNegativeInteger(t)&&n.is.inRangeExclusiveMax(s,0,60)&&v(r)},toString(){if(!this.isValid())return"";const i=r==="E"||r==="W",o=String(t).padStart(i?3:2,"0"),l=Math.floor(s*10).toString().padStart(3,"0");return`${o}${l}${r}`},toDecimal(){return this.isValid()?L({degrees:t+s/60,direction:r}):null}}}const Pe={degrees:n.is.integer,minutes:e=>n.is.integer(e)&&n.is.inRange(e,0,59),seconds:e=>n.is.inRangeExclusiveMax(e,0,60),direction:n.optional(v)},He=/^(-?\d{1,3})°(\d{1,2})'(\d{1,2}(?:\.\d+)?)"?$/,Ve=/^(\d{1,3})°(\d{1,2})'(\d{1,2}(?:\.\d+)?)"?([NSEW])$/;function Z(e){let t=null,s=null,r=null,i=null;if(n.is.plainObject(e)&&n.conform.schema(e,Pe))n.is.defined(e.direction)?e.degrees>=0&&(t=e.degrees,s=e.minutes,r=e.seconds,i=e.direction):(t=e.degrees,s=e.minutes,r=e.seconds);else if(n.is.string(e)){const o=e.replace(/\s+/g,""),l=o.match(He)??o.match(Ve);l&&(t=parseFloat(l[1]),s=parseFloat(l[2]),r=parseFloat(l[3]),i=l[4]??null)}return{get degrees(){return t},get minutes(){return s},get seconds(){return r},get direction(){return i},get format(){return"DMS"},isValid(){return n.is.integer(t)&&n.is.integer(s)&&n.is.inRange(s,0,59)&&n.is.inRangeExclusiveMax(r,0,60)},toString(o){if(n.assert.that(o,n.is.positiveInteger,"decimalPlaces must be a positive integer"),!this.isValid())return"";let l=`${t}° ${s}' ${r.toFixed(o)}"`;return i&&(l+=` ${i}`),l},toDecimal(){return this.isValid()?L({degrees:t+s/60+r/3600,direction:i}):null}}}function Y(e){const t=Math.floor(e.degrees),s=(e.degrees-t)*60;return{degrees:t,minutes:s,direction:e.direction}}function We(e){const t=Math.floor(e.degrees),s=(e.degrees-t)*60,r=Math.floor(s),i=(s-r)*60;return{degrees:t,minutes:r,seconds:i,direction:e.direction}}const B={DD:e=>(n.assert.that(e,t=>t.isValid(),"dd must be a valid coordinate"),e),DDM:e=>{n.assert.that(e,i=>i.isValid(),"dd must be a valid coordinate");const{degrees:t,minutes:s,direction:r}=Y(e);return K(r?{degrees:t,minutes:s,direction:r}:{degrees:t,minutes:s})},DMS:e=>{n.assert.that(e,o=>o.isValid(),"dd must be a valid coordinate");const{degrees:t,minutes:s,seconds:r,direction:i}=We(e);return Z(i?{degrees:t,minutes:s,seconds:r,direction:i}:{degrees:t,minutes:s,seconds:r})},DDM_AERO:e=>{n.assert.that(e,i=>i.isValid(),"dd must be a valid coordinate");const{degrees:t,minutes:s,direction:r}=Y(e);return Q({degrees:t,minutes:s,direction:r})}},S={DD:"DD",DDM:"DDM",DDM_AERO:"DDM_AERO",DMS:"DMS"},ee={DD:L,DDM:K,DDM_AERO:Q,DMS:Z},A=Array.from({length:9},(e,t)=>10**t);function G(e,t){if(n.assert.that(e,n.is.number,"coord must be a number"),n.is.defined(t))return n.assert.that(t,v,"dir must be a direction"),J(t);if(Math.abs(e)>90)return f.LONGITUDE}function x(e){n.assert.that(e,n.is.number,"coord must be a number");const t=e.toExponential(),[s,r]=t.split("e").map(Number),i=(s.toString().split(".")[1]||"").length;return Math.max(0,i-r)}function Ye(e,t=7){n.assert.all([{value:e,validator:n.is.number,message:"coord must be a number"},{value:t,validator:r=>n.is.inRange(r,0,8),message:"precision must be in range [0, 8]"}]);const s=A[t];return Math.round(e*s)/s}function Be(e,t){if(n.assert.all([{value:e,validator:n.is.number,message:"coord must be a number"},{value:t,validator:r=>F(r)||I(r),message:"axis must be either a longitude or latitude"}]),I(t))return Math.max(-90,Math.min(90,e));let s=((e+180)%360+360)%360-180;return s===-180&&(s=180),Object.is(s,-0)&&(s=0),s}function je(e,t){n.assert.all([{value:e,validator:r=>n.is.defined(r)&&r.isValid(),message:"from must be a valid coordinate"},{value:t,validator:r=>n.has.key(B,r),message:`unknown format: ${t}`}]);const s=e.format===S.DD?e:e.toDecimal();return s.isValid()?t===S.DD?s:B[t](s):null}function te(e){n.assert.that(e,n.is.nonEmptyString,"pattern must be a non empty string");for(const t of Object.keys(S)){const s=ee[t](e);if(s.isValid())return s}return null}function Xe(e){n.assert.that(e,a=>n.is.nonEmptyString(a),"pattern must be a non-empty string");const t=e.split(/[,;|]/);if(t.length!==2)return null;const[s,r]=t.map(te);if(!s||!r)return null;const i=s.toDecimal(),o=r.toDecimal(),l=G(i.degrees,i.direction),c=G(o.degrees,o.direction),u=a=>{const{degrees:d,direction:m}=a;return m&&(R(m)||U(m))?-d:d};if(l===f.LONGITUDE&&c===f.LATITUDE)return[u(i),u(o)];if(c===f.LONGITUDE&&l===f.LATITUDE)return[u(o),u(i)];if(l===f.LONGITUDE&&!c)return[u(i),o];if(l===f.LATITUDE&&!c)return[u(o),u(i)];if(c===f.LONGITUDE&&!l)return[u(o),u(i)];if(c===f.LATITUDE&&!l)return[u(i),u(o)];if(!l&&!c)return[[u(i),u(o)],[u(o),u(i)]]}function ne(e){return!n.is.arrayOfLength(e,4)&&!n.is.arrayOfLength(e,6)?!1:e.every(n.is.number)}const O={NAME:"name",LINK:"link"};function qe(e){return n.is.plainObject(e)?e.type===O.NAME?n.is.nonEmptyString(e.properties?.name):e.type===O.LINK?n.is.nonEmptyString(e.properties?.href):!1:!1}const g={POINT:"Point",MULTI_POINT:"MultiPoint",LINESTRING:"LineString",MULTI_LINESTRING:"MultiLineString",POLYGON:"Polygon",MULTI_POLYGON:"MultiPolygon",GEOMETRY_COLLECTION:"GeometryCollection"};function C(e){return!n.is.plainObject(e)||!n.is.oneOf(e.type,Object.values(g))?!1:e.type===g.GEOMETRY_COLLECTION?n.is.array(e.geometries):n.is.array(e.coordinates)}const p={FEATURE:"Feature",FEATURE_COLLECTION:"FeatureCollection"};function re(e){return n.is.plainObject(e)?p.FEATURE===e.type:!1}function se(e){return!n.is.plainObject(e)||e.type!==p.FEATURE_COLLECTION?!1:n.is.array(e.features)}function P(e){return n.is.plainObject(e)?C(e)||re(e)?!0:se(e):!1}function ie(e){return n.is.arrayOfLengthBetween(e,2,3)?e.every(n.is.number):!1}function ze(e,t,s){return Math.abs((e[0]*(t[1]-s[1])+t[0]*(s[1]-e[1])+s[0]*(e[1]-t[1]))/2)}function M(e,{tolerance:t=0,getWeight:s=()=>1}={}){if(e.length<=2)return e;const r=e.map((a,d)=>({coord:a,i:d,area:1/0,removed:!1,prev:null,next:null}));for(let a=0;a<r.length;a++)a>0&&(r[a].prev=r[a-1]),a<r.length-1&&(r[a].next=r[a+1]);const i=a=>!a.prev||!a.next?1/0:ze(a.prev.coord,a.coord,a.next.coord)*s(a.coord,a.i),o=new me.Heap((a,d)=>a.area-d.area);for(let a=1;a<r.length-1;a++)r[a].area=i(r[a]),r[a]._currentArea=r[a].area,o.push(r[a]);let l=0;for(;o.size()>0;){const a=o.pop();if(!a.removed&&a.area===a._currentArea){if(a.area<l?a.area=l:l=a.area,a.area>=t)break;a.removed=!0,a.prev&&(a.prev.next=a.next),a.next&&(a.next.prev=a.prev),a.prev?.prev&&(a.prev.area=i(a.prev),a.prev._currentArea=a.prev.area,o.push(a.prev)),a.next?.next&&(a.next.area=i(a.next),a.next._currentArea=a.next.area,o.push(a.next))}}const c=[];let u=r[0];for(;u;)u.removed||c.push(u.coord),u=u.next;return c}function N(e,t){switch(n.assert.all([{value:e,validator:C,message:"geometry must be a GeoJson geometry"}]),e.type){case g.LINESTRING:e.coordinates=M(e.coordinates,t);break;case g.POLYGON:case g.MULTI_LINESTRING:e.coordinates=e.coordinates.map(s=>M(s,t));break;case g.MULTI_POLYGON:e.coordinates=e.coordinates.map(s=>s.map(r=>M(r,t)));break;case g.GEOMETRY_COLLECTION:e.geometries.forEach(s=>N(s,t));break}return e}const Je=j.getLogger(["common-ekosystem","simplify","geojson"]);function ae(e,t){if(e.type===p.FEATURE)e.geometry&&N(e.geometry,t);else if(e.type===p.FEATURE_COLLECTION)for(const s of e.features)ae(s,t);else Je.warn('Unknown feature type "{type}", skipping.',{type:e.type});return e}function Ke(e,t){return n.assert.all([{value:e,validator:P,message:"geoJson must be a GeoJson object"}]),n.is.oneOf(e.type,Object.values(g))?N(e,t):ae(e,t)}function H(e,t=7){n.assert.all([{value:e,validator:ne,message:"bbox must be bounding box"},{value:t,validator:r=>n.is.inRange(r,0,8),message:"precision must be in range [0, 8]"}]);const s=A[t];for(let r=0;r<e.length;r++)e[r]=Math.round(e[r]*s)/s;return e}function V(e,t=7){n.assert.all([{value:e,validator:C,message:"geometry must be a GeoJson geometry"},{value:t,validator:r=>n.is.inRange(r,0,8),message:"precision must be in range [0, 8]"}]);const s=de(e,{precision:t,mutate:!0});return s.bbox&&H(s.bbox,t),s}const Qe=j.getLogger(["common-ekosystem","truncate","geojson"]);function oe(e,t){if(e.type===p.FEATURE)e.geometry&&V(e.geometry,t);else if(e.type===p.FEATURE_COLLECTION)for(const s of e.features)oe(s,t);else Qe.warn('Unknown feature type "{type}", skipping.',{type:e.type});return e.bbox&&H(e.bbox,t),e}function Ze(e,t=7){return n.assert.all([{value:e,validator:P,message:"geoJson must be a valid GeoJson"},{value:t,validator:s=>n.is.inRange(s,0,8),message:"precision must be in range [0, 8]"}]),n.is.oneOf(e.type,Object.values(g))?V(e,t):oe(e,t)}function et(e,t=7){n.assert.all([{value:e,validator:ie,message:"position must be a position"},{value:t,validator:r=>n.is.inRange(r,0,8),message:"precision must be in range [0, 8]"}]);const s=A[t];for(let r=0;r<e.length;r++)e[r]=Math.round(e[r]*s)/s;return e}function T(e){if(!n.is.arrayOfLengthBetween(e,2,3))return{valid:!1,errors:[{message:"Invalid coordinates: must be an array of 2 or 3 coordinates"}],warnings:[]};if(!n.is.inRange(e[0],-180,180))return{valid:!1,errors:[{message:"Invalid coordinates: longitude must be in the range -180 to 180"}],warnings:[]};if(!n.is.inRange(e[1],-90,90))return{valid:!1,errors:[{message:"Invalid coordinates: latitude must be in the range -90 to 90"}],warnings:[]};if(e.length===3&&!n.is.number(e[2]))return{valid:!1,errors:[{message:"Invalid coordinates: altitude must be a number"}],warnings:[]};const t={valid:!0,errors:[],warnings:[]},s=x(e[0]);s>6&&t.warnings.push({message:`longitude precision is high (${s} decimals, max recommended: 6)`});const r=x(e[1]);return r>6&&t.warnings.push({message:`latitude precision is high (${r} decimals, max recommended: 6)`}),t}function le(e){if(!n.is.arrayOfLength(e,4)&&!n.is.arrayOfLength(e,6))return{valid:!1,errors:[{message:"Invalid bbox: must be an array of 4 (2D) or 6 (3D) numbers"}],warnings:[]};const t=e.length===4,s=t?[e[0],e[1]]:[e[0],e[1],e[2]],r=t?[e[2],e[3]]:[e[3],e[4],e[5]],i=T(s);if(!i.valid)return{valid:!1,errors:i.errors.map(m=>({...m,message:`Invalid bbox south-west: ${m.message}`})),warnings:[]};const o=T(r);if(!o.valid)return{valid:!1,errors:o.errors.map(m=>({...m,message:`Invalid bbox north-east: ${m.message}`})),warnings:[]};const[l,c]=s,[u,a]=r;if(c>a)return{valid:!1,errors:[{message:`Invalid bbox: south (${c}) must be <= north (${a})`}],warnings:[]};const d={valid:!0,errors:[],warnings:[]};return l>u&&d.warnings.push({message:`bbox crosses the antimeridian (west: ${l} > east: ${u})`}),d.warnings.push(...i.warnings.map(m=>({...m,message:`south-west: ${m.message}`}))),d.warnings.push(...o.warnings.map(m=>({...m,message:`north-east: ${m.message}`}))),d}function ue(e){if(!n.is.plainObject(e))return{valid:!1,errors:[{message:"Invalid crs: must be an object"}],warnings:[]};switch(e.type){case O.NAME:return n.is.nonEmptyString(e.properties?.name)?{valid:!0,errors:[],warnings:[]}:{valid:!1,errors:[{message:"Invalid crs: linked crs must have a non-empty properties.name string"}],warnings:[]};case O.LINK:return n.is.nonEmptyString(e.properties?.href)?{valid:!0,errors:[],warnings:[]}:{valid:!1,errors:[{message:"Invalid crs: linked crs must have a non-empty properties.href string"}],warnings:[]};default:return{valid:!1,errors:[{message:`Invalid crs: unknown type: ${e.type}`}],warnings:[]}}}function y(){return{Feature:0,FeatureCollection:0,geometries:{}}}function tt(...e){const t=y();for(const s of e){const r=s.statistics;if(r){t.Feature+=r.Feature??0,t.FeatureCollection+=r.FeatureCollection??0;for(const[i,o]of Object.entries(r.geometries??{}))t.geometries[i]=(t.geometries[i]??0)+o}}return t}function b(e,t,s=""){const r={valid:!0,errors:[],warnings:[]};for(let i=0;i<e.length;i++){const o=`${s}/${i}`,l=t(e[i],o,i);if(!l.valid){r.valid=!1,r.errors=r.errors.concat(l.errors.map(c=>({...c,path:c.path||o,index:i})));continue}n.is.empty(l.warnings)||(r.warnings=r.warnings.concat(l.warnings.map(c=>({...c,path:c.path||o,index:i})))),l.statistics&&(r.statistics=tt(r,l))}return r}function nt(e,t){if(!n.is.defined(e.crs))return t;const s=ue(e.crs);return s.valid||(t.valid=!1,t.errors.push(...s.errors.map(r=>({...r,path:"/crs"})))),t.warnings.push(...s.warnings.map(r=>({...r,path:"/crs"}))),t}function $(e,t,s=""){if(!n.is.defined(e.bbox))return t;const r=le(e.bbox);return r.valid||(t.valid=!1,t.errors.push(...r.errors.map(i=>({...i,path:`${s}/bbox`})))),t.warnings.push(...r.warnings.map(i=>({...i,path:`${s}/bbox`}))),t}function W(e,t=0,s=""){return n.is.arrayOfLengthAtLeast(e,t)?b(e,T,s):{valid:!1,errors:[{message:`Invalid coordinates: must have at least ${t} positions`,path:s}],warnings:[]}}function ce(e,t=""){const s=W(e,2,t);if(!s.valid)return s;for(let r=0;r<e.length-1;r++){const i=e[r][0],o=e[r+1][0];Math.abs(o-i)>180&&s.warnings.push({message:`LineString crosses the antimeridian between positions ${r} and ${r+1}, consider using MultiLineString`,path:`${t}/${r}`})}return s}function rt(e,t=""){return n.is.nonEmptyArray(e)?b(e,ce,t):{valid:!1,errors:[{message:"Invalid MultiLineString: coordinates must be a non empty array",path:t}],warnings:[]}}function st(e,t,s=""){const r=W(e,4,s);if(!r.valid)return r;const i=e[0],o=e[e.length-1];if(i[0]!==o[0]||i[1]!==o[1])return r.valid=!1,r.errors.push({message:"Invalid LinearRing: first and last position must be identical",path:s}),r;const c=pe(e)?"clockwise":"counter-clockwise";c!==t&&r.warnings.push({message:`Ring must be ${t} but is ${c}`,path:s});const u=ve({type:"Polygon",coordinates:[e]});return u.features.length>0&&(r.valid=!1,r.errors.push({message:`Invalid LinearRing: ${u.features.length} self-intersection(s) detected`,path:s})),r}function ge(e,t=""){return n.is.nonEmptyArray(e)?b(e,(s,r,i)=>st(s,i===0?"counter-clockwise":"clockwise",r),t):{valid:!1,errors:[{message:"Invalid Polygon: coordinates must be a non empty array",path:t}],warnings:[]}}function it(e,t=""){return n.is.nonEmptyArray(e)?b(e,(s,r)=>ge(s,r),t):{valid:!1,errors:[{message:"Invalid MultiPolygon: coordinates must be a non empty array",path:t}],warnings:[]}}function at(e,t=""){return n.is.nonEmptyArray(e)?b(e,(s,r)=>w(s,r),t):{valid:!1,errors:[{message:"Invalid geometries: geometries must be a non empty array",path:t}],warnings:[]}}function w(e,t=""){if(!n.is.nonEmptyObject(e))return{valid:!1,errors:[{message:"Invalid geometry: geometry must be a non empty object",path:t}],warnings:[]};const s=`${t}/coordinates`;let r;switch(e.type){case g.POINT:{const i=T(e.coordinates);r={valid:i.valid,errors:i.errors.map(o=>({...o,path:s})),warnings:i.warnings.map(o=>({...o,path:s}))};break}case g.MULTI_POINT:{r=W(e.coordinates,0,s);break}case g.LINESTRING:{r=ce(e.coordinates,s);break}case g.MULTI_LINESTRING:{r=rt(e.coordinates,s);break}case g.POLYGON:{r=ge(e.coordinates,s);break}case g.MULTI_POLYGON:{r=it(e.coordinates,s);break}case g.GEOMETRY_COLLECTION:{r=at(e.geometries,`${t}/geometries`);break}default:return{valid:!1,errors:[{message:`Invalid geometry type: ${e.type}`,path:t}],warnings:[]}}return $(e,r,t)}function fe(e,t=""){if(!n.is.nonEmptyObject(e))return{valid:!1,errors:[{message:"Invalid feature: must be a non empty object",path:t}],warnings:[],statistics:y()};if(e.type===p.FEATURE){if(n.is.nonEmptyObject(e.geometry)){const s=w(e.geometry,`${t}/geometry`);return{...$(e,s,t),statistics:{Feature:1,FeatureCollection:0,geometries:{[e.geometry.type]:1}}}}return{valid:!0,errors:[],warnings:[{message:"Feature has no geometry",path:t}],statistics:{Feature:1,FeatureCollection:0,geometries:{}}}}if(e.type===p.FEATURE_COLLECTION){if(n.is.nonEmptyArray(e.features)){const s=b(e.features,fe,`${t}/features`);return{...$(e,s,t),statistics:{...s.statistics,FeatureCollection:s.statistics.FeatureCollection+1}}}return{valid:!1,errors:[{message:"Invalid FeatureCollection: features must be a non empty array",path:t}],warnings:[],statistics:y()}}return{valid:!1,errors:[{message:`Invalid feature: unknown type: ${e.type}`,path:t}],warnings:[],statistics:y()}}function ot(e){if(n.assert.that(e,n.is.nonEmptyObject,"geojson must be a non empty object"),n.is.oneOf(e.type,Object.values(g)))return{...w(e,""),statistics:{Feature:0,FeatureCollection:0,geometries:{[e.type]:1}}};if(e.type===p.FEATURE||e.type===p.FEATURE_COLLECTION){const t=fe(e,"");return nt(e,t)}return{valid:!1,errors:[{message:"Invalid GeoJson: type must be either a Geometry, a Feature or a FeatureCollection"}],warnings:[],statistics:y()}}exports.AXES=f;exports.COORDINATE_FORMATS=S;exports.COORDINATE_MODELS=ee;exports.COORDINATE_TRUNCATION_FACTORS=A;exports.CRS_TYPES=O;exports.FEATURE_TYPES=p;exports.GEOMETRY_TYPES=g;exports.convertCoordinate=je;exports.getCoordinatePrecision=x;exports.getDirectionAxis=J;exports.getDirections=De;exports.getEast=Ce;exports.getLocale=q;exports.getNorth=Re;exports.getSouth=Ae;exports.getWest=Ne;exports.guessCoordinateAxis=G;exports.isAltitude=Ee;exports.isAxis=X;exports.isDirection=v;exports.isEast=k;exports.isLatitude=I;exports.isLikeBBox=ne;exports.isLikeCRS=qe;exports.isLikeFeature=re;exports.isLikeFeatureCollection=se;exports.isLikeGeoJson=P;exports.isLikeGeometry=C;exports.isLikePosition=ie;exports.isLongitude=F;exports.isNorth=z;exports.isSouth=U;exports.isWest=R;exports.listLocales=Le;exports.normalizeCoordinate=Be;exports.parseCoordinate=te;exports.parsePosition=Xe;exports.registerLocale=Ie;exports.setLocale=Se;exports.simplifyGeoJson=Ke;exports.simplifyGeometry=N;exports.truncateBBox=H;exports.truncateCoordinate=Ye;exports.truncateGeoJson=Ze;exports.truncateGeometry=V;exports.truncatePosition=et;exports.validateBBox=le;exports.validateCRS=ue;exports.validateGeoJson=ot;exports.validateGeometry=w;exports.validatePosition=T;
5
2
  //# sourceMappingURL=index.cjs.map