UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) • 11.9 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import t from"../ArcadePortal.js";import e from"../Attachment.js";import r from"../Dictionary.js";import{StringEnum as n}from"../enum.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as o,s as i,O as u,r as s,v as l,J as p,H as f,t as c,j as d,$ as h,K as y,a0 as g,e as m,f as A,g as w,k as I,i as v,m as U,l as j}from"../../chunks/languageUtils.js";import{convertDirection as x}from"./convertdirection.js";import{XXH as N}from"./hash.js";import{hasSamePortal as k}from"../../core/urlUtils.js";import{generateUUID as C}from"../../core/uuid.js";import P from"../../geometry/Extent.js";import O from"../../geometry/Multipoint.js";import z from"../../geometry/Point.js";import S from"../../geometry/Polygon.js";import F from"../../geometry/Polyline.js";import T from"../../geometry/SpatialReference.js";import L from"../../portal/Portal.js";import{isArray as R,isString as H,isBoolean as M,isNumber as b}from"../../support/guards.js";function D(t){if("loaded"===t.loadStatus&&t.user?.sourceJSON){return t.user.sourceJSON}return null}function J(t,e){return!!t&&k(t,e?.restUrl||"")}function W(t,e){if(!t||!e)return t===e;if(t.x===e.x&&t.y===e.y){if(t.hasZ){if(t.z!==e.z)return!1}else if(e.hasZ)return!1;if(t.hasM){if(t.m!==e.m)return!1}else if(e.hasM)return!1;return!0}return!1}function B(n,o,i){if(null!==n)if(R(n)){if(o.updateUint8Array([61]),i.map.has(n)){const t=i.map.get(n);o.updateIntArray([61237541^t])}else{i.map.set(n,i.currentLength++);for(const t of n)B(t,o,i);i.map.delete(n),i.currentLength--}o.updateUint8Array([199])}else if(d(n)){if(o.updateUint8Array([61]),i.map.has(n)){const t=i.map.get(n);o.updateIntArray([61237541^t])}else{i.map.set(n,i.currentLength++);for(const t of n.toArray())B(t,o,i);i.map.delete(n),i.currentLength--}o.updateUint8Array([199])}else{if(m(n))return o.updateIntArray([n.toNumber()]),void o.updateUint8Array([241]);if(A(n))return o.updateIntArray([n.toNumber()]),void o.updateIntArray([257]);if(w(n))return o.updateIntArray([n.toNumber()]),void o.updateIntArray([263]);if(H(n))return o.updateIntArray([n.length]),o.updateWithString(n),void o.updateUint8Array([41]);if(M(n))o.updateUint8Array([!0===n?1:0,113]);else{if(b(n))return o.updateFloatArray([n]),void o.updateUint8Array([173]);if(n instanceof e)throw new a(i.context,"UnsupportedHashType",i.node);if(n instanceof t)throw new a(i.context,"UnsupportedHashType",i.node);if(!(n instanceof r)){if(I(n))throw new a(i.context,"UnsupportedHashType",i.node);if(n instanceof z)return o.updateIntArray([3833836621]),o.updateIntArray([0]),o.updateFloatArray([n.x]),o.updateIntArray([1]),o.updateFloatArray([n.y]),n.hasZ&&(o.updateIntArray([2]),o.updateFloatArray([n.z])),n.hasM&&(o.updateIntArray([3]),o.updateFloatArray([n.m])),o.updateIntArray([3765347959]),void B(n.spatialReference.wkid,o,i);if(n instanceof S){o.updateIntArray([1266616829]);for(let t=0;t<n.rings.length;t++){const e=n.rings[t],r=[];let a=null,u=null;for(let o=0;o<e.length;o++){const i=n.getPoint(t,o);if(0===o)a=i;else if(W(u,i))continue;u=i,o===e.length-1&&W(a,i)||r.push(i)}o.updateIntArray([1397116793,r.length]);for(let t=0;t<r.length;t++){const e=r[t];o.updateIntArray([3962308117,t]),B(e,o,i),o.updateIntArray([2716288009])}o.updateIntArray([2278822459])}return o.updateIntArray([3878477243]),void B(n.spatialReference.wkid,o,i)}if(n instanceof F){o.updateIntArray([4106883559]);for(let t=0;t<n.paths.length;t++){const e=n.paths[t];o.updateIntArray([1397116793,e.length]);for(let r=0;r<e.length;r++)o.updateIntArray([3962308117,r]),B(n.getPoint(t,r),o,i),o.updateIntArray([2716288009]);o.updateIntArray([2278822459])}return o.updateIntArray([2568784753]),void B(n.spatialReference.wkid,o,i)}if(n instanceof O){o.updateIntArray([588535921,n.points.length]);for(let t=0;t<n.points.length;t++){const e=n.getPoint(t);o.updateIntArray([t]),B(e,o,i)}return o.updateIntArray([1700171621]),void B(n.spatialReference.wkid,o,i)}if(n instanceof P)return o.updateIntArray([3483648373]),o.updateIntArray([0]),o.updateFloatArray([n.xmax]),o.updateIntArray([1]),o.updateFloatArray([n.xmin]),o.updateIntArray([2]),o.updateFloatArray([n.ymax]),o.updateIntArray([3]),o.updateFloatArray([n.ymin]),n.hasZ&&(o.updateIntArray([4]),o.updateFloatArray([n.zmax]),o.updateIntArray([5]),o.updateFloatArray([n.zmin])),n.hasM&&(o.updateIntArray([6]),o.updateFloatArray([n.mmax]),o.updateIntArray([7]),o.updateFloatArray([n.mmin])),o.updateIntArray([3622027469]),void B(n.spatialReference.wkid,o,i);if(n instanceof T)return o.updateIntArray([14]),void 0!==n.wkid&&null!==n.wkid&&o.updateIntArray([n.wkid]),n.wkt&&o.updateWithString(n.wkt),void(n.wkt2&&o.updateWithString(n.wkt2));if(v(n))throw new a(i.context,"UnsupportedHashType",i.node);if(U(n))throw new a(i.context,"UnsupportedHashType",i.node);if(j(n))throw new a(i.context,"UnsupportedHashType",i.node);if(n===l)throw new a(i.context,"UnsupportedHashType",i.node);throw new a(i.context,"UnsupportedHashType",i.node)}if(o.updateUint8Array([223]),i.map.has(n)){const t=i.map.get(n);o.updateIntArray([61237541^t])}else{i.map.set(n,i.currentLength++);for(const t of n.keys()){o.updateIntArray([t.length]),o.updateWithString(t),o.updateUint8Array([251]);B(n.field(t),o,i),o.updateUint8Array([239])}i.map.delete(n),i.currentLength--}o.updateUint8Array([73])}}else o.updateUint8Array([0,139])}function E(e,m){e.portal=function(e,r){return m(e,r,(n,a,u)=>(o(u,1,1,e,r),new t(i(u[0]))))},e.typeof=function(t,e){return m(t,e,(r,n,i)=>{o(i,1,1,t,e);const s=u(i[0]);if("Unrecognized Type"===s)throw new a(t,"UnrecognizedType",e);return s})},e.trim=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,1,t,e),i(a[0]).trim()))},e.tohex=function(t,e){return m(t,e,(r,n,a)=>{o(a,1,1,t,e);const i=s(a[0]);return isNaN(i)?i:i.toString(16)})},e.upper=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,1,t,e),i(a[0]).toUpperCase()))};const A=new n(["every-word","first-word"]);e.proper=function(t,e){return m(t,e,(r,n,a)=>{o(a,1,2,t,e);const u=(a.length>=2?A.lookup(i(a[1])):null)??"every-word",s=/\s/,l=i(a[0]);let p="",f=!0;for(let t=0;t<l.length;t++){let e=l[t];if(s.test(e))"every-word"===u&&(f=!0);else{e.toUpperCase()!==e.toLowerCase()&&(f?(e=e.toUpperCase(),f=!1):e=e.toLowerCase())}p+=e}return p})},e.lower=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,1,t,e),i(a[0]).toLowerCase()))};const w=new n(["digits","digits-hyphen","digits-hyphen-braces","digits-hyphen-parentheses"]);e.guid=function(t,e){return m(t,e,(r,n,a)=>{o(a,0,1,t,e);switch(a.length>0?w.lookup(i(a[0])):null){case"digits":return C().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return C();case"digits-hyphen-parentheses":return"("+C()+")";default:return"{"+C()+"}"}})},e.standardizeguid=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,2,t,e);let u=i(a[0]);if(""===u||null===u)return"";const s=/^(\{|\()?(?<partA>[0-9a-z]{8})(-?)(?<partB>[0-9a-z]{4})(-?)(?<partC>[0-9a-z]{4})(-?)(?<partD>[0-9a-z]{4})(-?)(?<partE>[0-9a-z]{12})(\}|\))?$/gim.exec(u);if(!s)return"";const l=s.groups;switch(u=l.partA+"-"+l.partB+"-"+l.partC+"-"+l.partD+"-"+l.partE,w.lookup(i(a[1]))){case"digits":return u.replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return u;case"digits-hyphen-parentheses":return"("+u+")";default:return"{"+u+"}"}})},e.console=function(t,e){return m(t,e,(e,r,n)=>(0===n.length||(1===n.length?t.console(i(n[0])):t.console(i(n))),l))},e.mid=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,3,t,e);let u=s(a[1]);if(isNaN(u))return"";if(u=Math.max(0,u),2===a.length)return i(a[0]).slice(u);let l=s(a[2]);return isNaN(l)?"":(l<0&&(l=0),i(a[0]).slice(u,u+l))})},e.find=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,3,t,e);let u=0;if(a.length>2){if(u=s(p(a[2],0)),isNaN(u))return-1;u<0&&(u=0)}return i(a[1]).indexOf(i(a[0]),u)})},e.left=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).slice(0,u))})},e.right=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,2,t,e);const u=s(a[1]);if(isNaN(u)||u<=0)return"";return i(a[0]).slice(-u)})},e.split=function(t,e){return m(t,e,(r,n,a)=>{let u;o(a,2,4,t,e);let l=s(p(a[2],-1));const c=f(p(a[3],!1));if(-1===l||null===l||!0===c?u=i(a[0]).split(i(a[1])):(isNaN(l)&&(l=-1),l<-1&&(l=-1),u=i(a[0]).split(i(a[1]),l)),!1===c)return u;const d=[];for(let t=0;t<u.length&&!(-1!==l&&d.length>=l);t++)""!==u[t]&&void 0!==u[t]&&d.push(u[t]);return d})},e.text=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,2,t,e),c(a[0],a[1])))},e.concatenate=function(t,e){return m(t,e,(t,e,r)=>{const n=[];if(r.length<1)return"";if(R(r[0])){const t=p(r[2],"");for(let e=0;e<r[0].length;e++)n[e]=c(r[0][e],t);return r.length>1?n.join(r[1]):n.join("")}if(d(r[0])){const t=p(r[2],"");for(let e=0;e<r[0].length();e++)n[e]=c(r[0].get(e),t);return r.length>1?n.join(r[1]):n.join("")}for(let a=0;a<r.length;a++)n[a]=c(r[a]);return n.join("")})},e.reverse=function(t,e){return m(t,e,(r,n,i)=>{if(o(i,1,1,t,e),R(i[0])){const t=i[0].slice();return t.reverse(),t}if(d(i[0])){const t=i[0].toArray().slice();return t.reverse(),t}throw new a(t,"InvalidParameter",e)})},e.replace=function(t,e){return m(t,e,(r,n,a)=>{o(a,3,4,t,e);const u=i(a[0]),s=i(a[1]),l=i(a[2]);return 4!==a.length||f(a[3])?h(u,s,l):u.replace(s,l)})},e.urlencode=function(t,e){return m(t,e,(n,a,u)=>{if(o(u,1,1,t,e),null===u[0])return"";if(u[0]instanceof r){let t="";for(const e of u[0].keys()){const r=u[0].field(e);""!==t&&(t+="&"),t+=null===r?encodeURIComponent(e)+"=":encodeURIComponent(e)+"="+encodeURIComponent(r)}return t}return encodeURIComponent(i(u[0]))})},e.hash=function(t,e){return m(t,e,(r,n,a)=>{o(a,1,1,t,e);const i=new N(0);return B(a[0],i,{context:t,node:e,map:new Map,currentLength:0}),i.digest()})},e.convertdirection=function(t,e){return m(t,e,(r,n,a)=>(o(a,3,3,t,e),x(a[0],a[1],a[2])))},e.fromjson=function(t,e){return m(t,e,(n,u,s)=>{if(o(s,1,1,t,e),!1===H(s[0]))throw new a(t,"InvalidParameter",e);return r.convertJsonToArcade(JSON.parse(i(s[0])),y(t))})},e.tocharcode=function(t,e){return m(t,e,(r,n,u)=>{o(u,1,2,t,e);const l=s(p(u[1],0)),f=i(u[0]);if(0===f.length&&1===u.length)return null;if(f.length<=l||l<0)throw new a(t,"OutOfBounds",e);return f.charCodeAt(l)})},e.tocodepoint=function(t,e){return m(t,e,(r,n,u)=>{o(u,1,2,t,e);const l=s(p(u[1],0)),f=i(u[0]);if(0===f.length&&1===u.length)return null;if(f.length<=l||l<0)throw new a(t,"OutOfBounds",e);return f.codePointAt(l)})},e.fromcharcode=function(t,e){return m(t,e,(r,n,o)=>{if(o.length<1)throw new a(t,"WrongNumberOfParameters",e);const i=o.map(t=>Math.trunc(s(t))).filter(t=>t>=0&&t<=65535);return 0===i.length?null:String.fromCharCode.apply(null,i)})},e.fromcodepoint=function(t,e){return m(t,e,(r,n,o)=>{if(o.length<1)throw new a(t,"WrongNumberOfParameters",e);let i;try{i=o.map(t=>Math.trunc(s(t))).filter(t=>t<=1114111&&t>>>0===t)}catch(u){return null}return 0===i.length?null:String.fromCodePoint.apply(null,i)})},e.getuser=function(e,n){return m(e,n,(u,s,l)=>{o(l,0,2,e,n);let f=p(l[1],"");if(f=!0===f||!1===f?"":i(f),null!==f&&""!==f)return null;if(0===l.length||l[0]instanceof t){let t=null;if(t=e.services?.portal?e.services.portal:L.getDefault(),l.length>0){if(!J(l[0].field("url"),t))return null}if(!t)return null;if(""===f){const n=D(t);if(n){const t=JSON.parse(JSON.stringify(n));for(const e of["lastLogin","created","modified"])void 0!==t[e]&&null!==t[e]&&(t[e]=new Date(t[e]));return r.convertObjectToArcadeDictionary(t,y(e))}}return null}throw new a(e,"InvalidParameter",n)})},e.getenvironment=function(t,e){return m(t,e,(n,a,i)=>(o(i,0,0,t,e),r.convertObjectToArcadeDictionary(g(y(t),t.spatialReference),y(t),!0)))},e.standardizefilename=function(t,e){return m(t,e,(t,e,r)=>{o(r,1,1,t,e);const[n]=r;if(null==n)return"";if(!H(n))throw new a(t,"InvalidParameter",e);return n.replaceAll(/[<>"?*]/g,"_").replaceAll(/[/\\|]/g,"-").replaceAll(":",", ")})}}export{E as registerFunctions};