languageUtils.js 16 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import e from"../arcade/FunctionWrapper.js";import t from"../arcade/ImmutableArray.js";import n from"../arcade/ImmutablePathArray.js";import r from"../arcade/ImmutablePointArray.js";import i from"../geometry/Extent.js";import a from"../geometry/Geometry.js";import o from"../geometry/Multipoint.js";import s from"../geometry/Point.js";import u from"../geometry/Polygon.js";import l from"../geometry/Polyline.js";import{DateTime as f}from"luxon";import{isNone as c}from"../core/maybe.js";import{format as m,parse as d}from"../core/number.js";import{isClockwise as y}from"../geometry/support/coordsUtils.js";import{getLocale as p}from"../intl/locale.js";import{esriFieldToJson as g,layerGeometryEsriRestConstants as h}from"../arcade/featureset/support/shared.js";class S{constructor(e){this.value=e}}class x{constructor(e){this.value=e}}class b{constructor(e){this.fn=e}}class T{constructor(e,t){this.paramCount=t,this.fn=e}}const N=b,k=x,D=S,M=T,j={type:"VOID"},A={type:"BREAK"},R={type:"CONTINUE"};function F(e,t,n){return""===t||null==t||t===n||t===n?e:e=e.split(t).join(n)}function v(t){return t instanceof b||t instanceof e||t instanceof T}function C(e){return!!w(e)||(!!O(e)||(!!z(e)||(!!_(e)||(null===e||(e===j||"number"==typeof e)))))}function I(e,t){return void 0===e?t:e}function w(e){return"string"==typeof e||e instanceof String}function _(e){return"boolean"==typeof e}function O(e){return"number"==typeof e}function Z(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e}function L(e){return e instanceof Array}function Y(e){return"esri.arcade.Feature"===e?.arcadeDeclaredClass}function J(e){return!0===(e&&e.declaredRootClass&&"esri.arcade.featureset.support.FeatureSet"===e.declaredRootClass)}function P(e){return!0===(e&&e.declaredRootClass&&"esri.arcade.featureSetCollection"===e.declaredRootClass)}function E(e){return e instanceof t}function z(e){return e instanceof Date}function G(e,t,n){if(e.length<t||e.length>n)throw new Error("Function called with wrong number of Parameters")}function V(e){return e<0?-Math.round(-e):Math.round(e)}function H(){let e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){const n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)}))}function U(e,t){return!1===isNaN(e)?null==t||""===t?e.toString():(t=F(t,"‰",""),t=F(t,"¤",""),m(e,{pattern:t})):e.toString()}function q(e,t){const n=f.fromJSDate(e);return null==t||""===t?n.toISO({suppressMilliseconds:!0}):n.toFormat($(t),{locale:p(),numberingSystem:"latn"})}function $(e){e=e.replace(/LTS|LT|LL?L?L?|l{1,4}/g,"[$&]");let t="";const n=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;for(const r of e.match(n))switch(r){case"D":t+="d";break;case"DD":t+="dd";break;case"DDD":t+="o";break;case"d":t+="c";break;case"ddd":t+="ccc";break;case"dddd":t+="cccc";break;case"M":t+="L";break;case"MM":t+="LL";break;case"MMM":t+="LLL";break;case"MMMM":t+="LLLL";break;case"YY":t+="yy";break;case"Y":case"YYYY":t+="yyyy";break;case"Q":t+="q";break;case"Z":t+="ZZ";break;case"ZZ":t+="ZZZ";break;case"S":t+="'S'";break;case"SS":t+="'SS'";break;case"SSS":t+="u";break;case"A":case"a":t+="a";break;case"m":case"mm":case"h":case"hh":case"H":case"HH":case"s":case"ss":case"X":case"x":t+=r;break;default:r.length>=2&&"["===r.slice(0,1)&&"]"===r.slice(-1)?t+=`'${r.slice(1,-1)}'`:t+=`'${r}'`}return t}function B(e,t,n){switch(n){case">":return e>t;case"<":return e<t;case">=":return e>=t;case"<=":return e<=t}return!1}function W(e,t,n){if(null===e){if(null===t||t===j)return B(null,null,n);if(O(t))return B(0,t,n);if(w(t))return B(0,ne(t),n);if(_(t))return B(0,ne(t),n);if(z(t))return B(0,t.getTime(),n)}if(e===j){if(null===t||t===j)return B(null,null,n);if(O(t))return B(0,t,n);if(w(t))return B(0,ne(t),n);if(_(t))return B(0,ne(t),n);if(z(t))return B(0,t.getTime(),n)}else if(O(e)){if(O(t))return B(e,t,n);if(_(t))return B(e,ne(t),n);if(null===t||t===j)return B(e,0,n);if(w(t))return B(e,ne(t),n);if(z(t))return B(e,t.getTime(),n)}else if(w(e)){if(w(t))return B(X(e),X(t),n);if(z(t))return B(ne(e),t.getTime(),n);if(O(t))return B(ne(e),t,n);if(null===t||t===j)return B(ne(e),0,n);if(_(t))return B(ne(e),ne(t),n)}else if(z(e)){if(z(t))return B(e,t,n);if(null===t||t===j)return B(e.getTime(),0,n);if(O(t))return B(e.getTime(),t,n);if(_(t))return B(e.getTime(),ne(t),n);if(w(t))return B(e.getTime(),ne(t),n)}else if(_(e)){if(_(t))return B(e,t,n);if(O(t))return B(ne(e),ne(t),n);if(z(t))return B(ne(e),t.getTime(),n);if(null===t||t===j)return B(ne(e),0,n);if(w(t))return B(ne(e),ne(t),n)}return!!Q(e,t)&&("<="===n||">="===n)}function Q(e,t){if(e===t)return!0;if(null===e&&t===j||null===t&&e===j)return!0;if(z(e)&&z(t))return e.getTime()===t.getTime();if(e instanceof n)return e.equalityTest(t);if(e instanceof r)return e.equalityTest(t);if(e instanceof s&&t instanceof s){const n=e.cache._arcadeCacheId,r=t.cache._arcadeCacheId;if(null!=n)return n===r}if(void 0!==e&&void 0!==t&&null!==e&&null!==t&&"object"==typeof e&&"object"==typeof t){if(e._arcadeCacheId===t._arcadeCacheId&&void 0!==e._arcadeCacheId&&null!==e._arcadeCacheId)return!0;if(e._underlyingGraphic===t._underlyingGraphic&&void 0!==e._underlyingGraphic&&null!==e._underlyingGraphic)return!0}return!1}function X(e,n){if(w(e))return e;if(null===e)return"";if(O(e))return U(e,n);if(_(e))return e.toString();if(z(e))return q(e,n);if(e instanceof a)return JSON.stringify(e.toJSON());if(L(e)){const t=[];for(let n=0;n<e.length;n++)t[n]=te(e[n]);return"["+t.join(",")+"]"}if(e instanceof t){const t=[];for(let n=0;n<e.length();n++)t[n]=te(e.get(n));return"["+t.join(",")+"]"}return null!==e&&"object"==typeof e&&void 0!==e.castToText?e.castToText():v(e)?"object, Function":""}function K(e){const n=[];if(!1===L(e))return null;if(e instanceof t){for(let t=0;t<e.length();t++)n[t]=ne(e.get(t));return n}for(let t=0;t<e.length;t++)n[t]=ne(e[t]);return n}function ee(e,n){if(w(e))return e;if(null===e)return"";if(O(e))return U(e,n);if(_(e))return e.toString();if(z(e))return q(e,n);if(e instanceof a)return e instanceof i?'{"xmin":'+e.xmin.toString()+',"ymin":'+e.ymin.toString()+","+(e.hasZ?'"zmin":'+e.zmin.toString()+",":"")+(e.hasM?'"mmin":'+e.mmin.toString()+",":"")+'"xmax":'+e.xmax.toString()+',"ymax":'+e.ymax.toString()+","+(e.hasZ?'"zmax":'+e.zmax.toString()+",":"")+(e.hasM?'"mmax":'+e.mmax.toString()+",":"")+'"spatialReference":'+de(e.spatialReference)+"}":de(e.toJSON(),((e,t)=>e.key===t.key?0:"spatialReference"===e.key?1:"spatialReference"===t.key||e.key<t.key?-1:e.key>t.key?1:0));if(L(e)){const t=[];for(let n=0;n<e.length;n++)t[n]=te(e[n]);return"["+t.join(",")+"]"}if(e instanceof t){const t=[];for(let n=0;n<e.length();n++)t[n]=te(e.get(n));return"["+t.join(",")+"]"}return null!==e&&"object"==typeof e&&void 0!==e.castToText?e.castToText():v(e)?"object, Function":""}function te(e){if(null===e)return"null";if(_(e)||O(e)||w(e))return JSON.stringify(e);if(e instanceof a)return ee(e);if(e instanceof t)return ee(e);if(e instanceof Array)return ee(e);if(e instanceof Date)return JSON.stringify(q(e,""));if(null!==e&&"object"==typeof e){if(void 0!==e.castToText)return e.castToText()}else if(e===j)return"null";return"null"}function ne(e,t){return O(e)?e:null===e||""===e?0:z(e)?NaN:_(e)?e?1:0:L(e)||""===e||void 0===e?NaN:void 0!==t&&w(e)?(t=F(t,"‰",""),t=F(t,"¤",""),d(e,{pattern:t})):e===j?0:Number(e)}function re(e){if(z(e))return e;if(w(e)){const t=ae(e);if(t)return t.toJSDate()}return null}function ie(e){return z(e)?f.fromJSDate(e):w(e)?ae(e):null}function ae(e){const t=/ (\d\d)/;let n=f.fromISO(e);return n.isValid||t.test(e)&&(e=e.replace(t,"T$1"),n=f.fromISO(e),n.isValid)?n:null}function oe(e){return _(e)?e:w(e)?"true"===(e=e.toLowerCase()):!!O(e)&&(0!==e&&!isNaN(e))}function se(e,t){return c(e)?null:(null!==e.spatialReference&&void 0!==e.spatialReference||(e.spatialReference=t),e)}function ue(e){if(null===e)return null;if(e instanceof s)return"NaN"===e.x||null===e.x||isNaN(e.x)?null:e;if(e instanceof u){if(0===e.rings.length)return null;for(const t of e.rings)if(t.length>0)return e;return null}if(e instanceof l){if(0===e.paths.length)return null;for(const t of e.paths)if(t.length>0)return e;return null}return e instanceof o?0===e.points.length?null:e:e instanceof i?"NaN"===e.xmin||null===e.xmin||isNaN(e.xmin)?null:e:null}function le(e,t){if(!e)return t;if(!e.domain)return t;let n=null;if("string"===e.field.type||"esriFieldTypeString"===e.field.type)t=X(t);else{if(null==t)return null;if(""===t)return t;t=ne(t)}for(let r=0;r<e.domain.codedValues.length;r++){const i=e.domain.codedValues[r];i.code===t&&(n=i)}return null===n?t:n.name}function fe(e,t){if(!e)return t;if(!e.domain)return t;let n=null;t=X(t);for(let r=0;r<e.domain.codedValues.length;r++){const i=e.domain.codedValues[r];i.name===t&&(n=i)}return null===n?t:n.code}function ce(e,t,n=null,r=null){if(!t)return null;if(!t.fields)return null;let i,a,o=null;for(let s=0;s<t.fields.length;s++){const n=t.fields[s];n.name.toLowerCase()===e.toString().toLowerCase()&&(o=n)}if(null===o)throw new Error("Field not found");return null===r&&n&&t.typeIdField&&(r=n.hasField(t.typeIdField)?n.field(t.typeIdField):null),null!=r&&t.types.some((function(e){return e.id===r&&(i=e.domains&&e.domains[o.name],i&&"inherited"===i.type&&(i=me(o.name,t),a=!0),!0)})),a||i||(i=me(e,t)),{field:o,domain:i}}function me(e,t){let n;return t.fields.some((function(t){return t.name.toLowerCase()===e.toLowerCase()&&(n=t.domain),!!n})),n}function de(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});const n="boolean"==typeof t.cycles&&t.cycles,r=t.cmp&&(i=t.cmp,function(e){return function(t,n){const r={key:t,value:e[t]},a={key:n,value:e[n]};return i(r,a)}});var i;const a=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0===t)return;if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);let i,o;if(Array.isArray(t)){for(o="[",i=0;i<t.length;i++)i&&(o+=","),o+=e(t[i])||"null";return o+"]"}if(null===t)return"null";if(a.includes(t)){if(n)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}const s=a.push(t)-1,u=Object.keys(t).sort(r&&r(t));for(o="",i=0;i<u.length;i++){const n=u[i],r=e(t[n]);r&&(o&&(o+=","),o+=JSON.stringify(n)+":"+r)}return a.splice(s,1),"{"+o+"}"}(e)}function ye(e){if(null===e)return null;const t=[];for(const n of e)n&&n.arcadeDeclaredClass&&"esri.arcade.Feature"===n.arcadeDeclaredClass?t.push(n.geometry()):t.push(n);return t}function pe(e,t){if(!(t instanceof s))throw new Error("Invalid Argument");e.push(t.hasZ?t.hasM?[t.x,t.y,t.z,t.m]:[t.x,t.y,t.z]:[t.x,t.y])}function ge(e,t){if(L(e)||E(e)){let n=!1,i=!1,a=[],o=t;if(L(e)){for(const t of e)pe(a,t);a.length>0&&(o=e[0].spatialReference,n=e[0].hasZ,i=e[0].hasM)}else if(e instanceof r)a=e._elements,a.length>0&&(n=e._hasZ,i=e._hasM,o=e.get(0).spatialReference);else{if(!E(e))throw new Error("Invalid Argument");for(const t of e.toArray())pe(a,t);a.length>0&&(o=e.get(0).spatialReference,n=!0===e.get(0).hasZ,i=!0===e.get(0).hasM)}if(0===a.length)return null;return!1===y(a,i,n)&&(a=a.slice(0).reverse()),new u({rings:[a],spatialReference:o,hasZ:n,hasM:i})}return e}function he(e,t){if(L(e)||E(e)){let n=!1,i=!1,a=[],o=t;if(L(e)){for(const t of e)pe(a,t);a.length>0&&(o=e[0].spatialReference,n=!0===e[0].hasZ,i=!0===e[0].hasM)}else if(e instanceof r)a=e._elements,a.length>0&&(n=e._hasZ,i=e._hasM,o=e.get(0).spatialReference);else if(E(e)){for(const t of e.toArray())pe(a,t);a.length>0&&(o=e.get(0).spatialReference,n=!0===e.get(0).hasZ,i=!0===e.get(0).hasM)}return 0===a.length?null:new l({paths:[a],spatialReference:o,hasZ:n,hasM:i})}return e}function Se(e,t){if(L(e)||E(e)){let n=!1,i=!1,a=[],s=t;if(L(e)){for(const t of e)pe(a,t);a.length>0&&(s=e[0].spatialReference,n=!0===e[0].hasZ,i=!0===e[0].hasM)}else if(e instanceof r)a=e._elements,a.length>0&&(n=e._hasZ,i=e._hasM,s=e.get(0).spatialReference);else if(E(e)){for(const t of e.toArray())pe(a,t);a.length>0&&(s=e.get(0).spatialReference,n=!0===e.get(0).hasZ,i=!0===e.get(0).hasM)}return 0===a.length?null:new o({points:a,spatialReference:s,hasZ:n,hasM:i})}return e}function xe(e,n=!1){const r=[];if(null===e)return r;if(!0===L(e)){for(let t=0;t<e.length;t++){const i=X(e[t]);""===i&&!0!==n||r.push(i)}return r}if(e instanceof t){for(let t=0;t<e.length();t++){const i=X(e.get(t));""===i&&!0!==n||r.push(i)}return r}if(C(e)){const t=X(e);return""===t&&!0!==n||r.push(t),r}return[]}let be=0;function Te(e){return be++,be%100==0?(be=0,new Promise((t=>{setTimeout((()=>{t(e)}),0)}))):e}function Ne(e,t,n){switch(n){case"&":return e&t;case"|":return e|t;case"^":return e^t;case"<<":return e<<t;case">>":return e>>t;case">>>":return e>>>t}}function ke(e,n=null){return null==e?null:_(e)||O(e)||w(e)?e:e instanceof a?!0===n?.keepGeometryType?e:e.toJSON():e instanceof t?e.toArray().map((e=>ke(e,n))):e instanceof Array?e.map((e=>ke(e,n))):e instanceof Date?e:null!==e&&"object"==typeof e&&void 0!==e.castAsJson?e.castAsJson(n):null}async function De(e,t,n,r,i){const a=await Me(e,t,n);i[r]=a}async function Me(e,n=null,r=null){if(e instanceof t&&(e=e.toArray()),null==e)return null;if(C(e)||e instanceof a||e instanceof Date)return ke(e,r);if(e instanceof Array){const t=[],i=[];for(const o of e)null===o||C(o)||o instanceof a||o instanceof Date?i.push(ke(o,r)):(i.push(null),t.push(De(o,n,r,i.length-1,i)));return t.length>0&&await Promise.all(t),i}return null!==e&&"object"==typeof e&&void 0!==e.castAsJsonAsync?e.castAsJsonAsync(n,r):null}function je(e,t,n){const r=e.fullSchema();if(null===r)return null;if(!r.fields)return null;return ce(t,r,e,n)}function Ae(e){const t=e.fullSchema();return null===t?null:t.fields&&t.typeIdField?{subtypeField:t.typeIdField,subtypes:t.types?t.types.map((e=>({name:e.name,code:e.id}))):[]}:null}function Re(e,t,n,r){const i=e.fullSchema();if(null===i)return null;if(!i.fields)return null;const a=ce(t,i,e,r);if(void 0===n)try{n=e.field(t)}catch(o){return null}return le(a,n)}function Fe(e,t,n,r){const i=e.fullSchema();if(null===i)return null;if(!i.fields)return null;if(void 0===n){try{n=e.field(t)}catch(a){return null}return n}return fe(ce(t,i,e,r),n)}function ve(e){const t=e.fullSchema();if(null===t)return null;if(!t.fields)return null;const n=[];for(const r of t.fields)n.push(g(r));return{objectIdField:t.objectIdField,globalIdField:t.globalIdField,geometryType:void 0===h[t.geometryType]?"":h[t.geometryType],fields:n}}const Ce=Object.freeze(Object.defineProperty({__proto__:null,ReturnResultE:S,ImplicitResultE:x,NativeFunctionE:b,SizzleFunctionE:T,NativeFunction:N,ImplicitResult:k,ReturnResult:D,SizzleFunction:M,voidOperation:j,breakResult:A,continueResult:R,multiReplace:F,isFunctionParameter:v,isSimpleType:C,defaultUndefined:I,isString:w,isBoolean:_,isNumber:O,isInteger:Z,isArray:L,isFeature:Y,isFeatureSet:J,isFeatureSetCollection:P,isImmutableArray:E,isDate:z,pcCheck:G,absRound:V,generateUUID:H,formatNumber:U,formatDate:q,standardiseDateFormat:$,greaterThanLessThan:W,equalityTest:Q,toString:X,toNumberArray:K,toStringExplicit:ee,toNumber:ne,toDate:re,toDateTime:ie,toBoolean:oe,fixSpatialReference:se,fixNullGeometry:ue,getDomainValue:le,getDomainCode:fe,getDomain:ce,stableStringify:de,autoCastFeatureToGeometry:ye,autoCastArrayOfPointsToPolygon:ge,autoCastArrayOfPointsToPolyline:he,autoCastArrayOfPointsToMultiPoint:Se,toStringArray:xe,tick:Te,binaryOperator:Ne,castAsJson:ke,castAsJsonAsync:Me,featureFullDomain:je,featureSubtypes:Ae,featureDomainValueLookup:Re,featureDomainCodeLookup:Fe,featureSchema:ve},Symbol.toStringTag,{value:"Module"}));export{fe as $,se as A,Z as B,I as C,$ as D,ie as E,V as F,ue as G,ye as H,k as I,he as J,ge as K,Se as L,F as M,N,H as O,ve as P,Ae as Q,D as R,M as S,je as T,Re as U,Fe as V,K as W,Te as X,xe as Y,ce as Z,le as _,O as a,S as a0,x as a1,b as a2,T as a3,U as a4,q as a5,de as a6,w as b,ke as c,Me as d,C as e,ne as f,oe as g,X as h,_ as i,z as j,re as k,L as l,Q as m,E as n,v as o,G as p,W as q,Ne as r,Y as s,ee as t,Ce as u,j as v,A as w,R as x,J as y,P as z};