UNPKG

@arcgis/core

Version:

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

1 lines • 11.3 kB
"use strict";(self.webpackChunkRemoteClient=self.webpackChunkRemoteClient||[]).push([[6343],{3367(t,e,r){r.d(e,{A:()=>C,B:()=>_,P:()=>f,g:()=>w,r:()=>v});var s=r(48938),n=r(66395),o=r(85935),a=r(78878),i=r(49186),l=r(53966),u=r(91869),c=r(20655),h=r(45475),d=r(67090),p=r(62791),g=r(14942),y=r(54218);class f{constructor(t,e){this.portal=t,this._debugLog=e}async translate(t){this.portal.loaded||await this.portal.load();const e=this.portal.helperServices?.aiUtilityServices;if(null==e)return{success:!1};const r=e.url+e.translateUtility;try{return t.requestSource??="arcade",{success:!0,results:(await(0,h.T)(r,t,{authMode:"no-prompt"})).map(t=>t.toJSON())}}catch(t){return null!=this._debugLog&&(t instanceof Error||t instanceof i.A)&&this._debugLog(`TranslateText error: ${t.message}`),l.A.getLogger("esri.arcade.functions.aiServices").error(t),{success:!1}}}}class m{constructor(t,e,r){this._parameters=t,this._maxTotalContentSize=e,this._maxContentsLength=r,this._requests=[],this._normalizedContents=new Map,this._contentsTotalSize=0}tryAdd(t){const e=new Set(t.filter(t=>!this._normalizedContents.has(t.text)).map(t=>t.text));if(this._requests.length+e.size>this._maxContentsLength)return null;let r=0;for(const t of e)r+=t.length;if((r+this._contentsTotalSize)*(this._parameters.to.length??1)>this._maxTotalContentSize)return null;const s=this._requests.length;for(const{key:e,text:r}of t)(0,u.tE)(this._normalizedContents,r,()=>[]).push({batchIdx:s,key:e});return this._requests.push(t),this._contentsTotalSize+=r,s}async send(t){const e=[],r=[];let s=0;for(const[t,n]of this._normalizedContents)e.push(new d.A({key:String(s++),text:t})),r.push(n);const n=new p.A(this._parameters);n.contents=e;const o=await t.translate(n);if(!o.success)return Array.from(this._requests,()=>o);const a=Array.from(this._requests,()=>({success:!0,results:[]}));for(const t of o.results){const e=Number(t.key);for(const s of r[e])a[s.batchIdx].results.push({...t,key:s.key})}return a}}function w(t){const e=[...new Set(t.to)].sort(),r=t.from??null,s=t.portalUrl,n=t.translator,o=t.apiKey??null;return JSON.stringify([e,r,s,n,o])}async function b(t,e,r){try{return(await t.yieldFor(r))[e]}catch{return{success:!1}}}class _{constructor(t,e,{maxTotalContentSize:r=5e4,maxContentsLength:s=1e3}={}){this._executor=t,this._service=e,this._openBatches=new Map,this._maxTotalContentSize=r,this._maxContentsLength=s}create(t){return{translate:async e=>{const r=w(e),{contents:s,to:n,from:o,translator:a,portalUrl:i,apiKey:l}=e;if(null==n)return{success:!1};if(null==s||s.every(t=>0===t.text.length))return{success:!1};const u=this._openBatches.get(r);if(null!=u){const e=u.data.tryAdd(s);if(null!=e)return await b(t,e,u);u.send()}const c=new m({to:n,from:o,translator:a,portalUrl:i,apiKey:l},this._maxTotalContentSize,this._maxContentsLength),h=c.tryAdd(s);if(null!=h){const e=this._executor.openBatch(c,{open:t=>{this._openBatches.set(r,t)},execute:t=>t.send(this._service),close:t=>{this._openBatches.get(r)===t&&this._openBatches.delete(r)}});return await b(t,h,e)}return await this._service.translate(e)}}}}function v(t){"async"===t.mode&&(t.functions[(0,s.X)("TranslateText")]=function(e,r){return t.standardFunctionAsync(e,r,async(t,e,r)=>{if((0,a.B)(r,2,3,t,e),!(0,y.Kg)(r[0])&&!(0,y.cy)(r[0])&&!(0,a.j)(r[0]))throw new o.D$(t,"InvalidParameter",e);const s=(0,a.N)(r[0]);if(!(0,y.Kg)(r[1])&&!(0,y.cy)(r[1])&&!(0,a.j)(r[1]))throw new o.D$(t,"InvalidParameter",e);const i=(0,a.N)(r[1]);let l=null;if(r.length>=3){if(!(0,y.Kg)(r[2]))throw new o.D$(t,"InvalidParameter",e);l=r[2]}const u=s.map((t,e)=>new d.A({key:String(e),text:t})),h=t.services?.portal??c.A.getDefault(),m=new p.A({to:i,contents:u,from:l,portalUrl:h.restUrl.replace(/\/sharing\/rest$/,"")}),b=new Map;let _=null;if(null!=t.lrucache){const e=t.lrucache;_??=w(m),m.contents=m.contents?.filter(t=>{const r=e.getCachedTranslation(_,t.text);return null==r||(b.set(t.key,{...r,key:t.key,text:t.text}),!1)})}if(m.contents?.length){const e=t.services?.translation??new f(h,t.console),r=await e.translate(m);if(!r.success)return new n.A({__proto__:null,success:!1});for(const e of r.results){const r=m.contents?.find(t=>t.key===e.key)?.text;if(null==r)throw new o.D$(null,"NeverReach",null);b.set(e.key,e),null!=t.lrucache&&(_??=w(m),t.lrucache.setCachedTranslation(_,r,{detectedLanguage:e.detectedLanguage,translation:e.translation}))}}const v=Array.from(u,e=>{const r=g.A.fromJSON(b.get(e.key));if(null==r)throw new o.D$(null,"NeverReach",null);return r.text=e.text,n.A.convertJsonToArcade(r.toJSON(),t.timeZone??"system",!0)});return new n.A({__proto__:null,success:!0,results:v})})})}const C=Object.freeze(Object.defineProperty({__proto__:null,BatchTranslationServiceFactory:_,PortalTranslationService:f,getTranslateParametersKey:w,registerFunctions:v},Symbol.toStringTag,{value:"Module"}))},14942(t,e,r){r.d(e,{A:()=>i});var s=r(5482),n=r(25482),o=r(10107),a=r(64108);let i=class extends n.o{constructor(t){super(t),this.text=null,this.detectedLanguage="en",this.detectedLanguageScore=-1}};(0,s.Cg)([(0,o.MZ)({type:String,json:{write:!0}})],i.prototype,"key",void 0),(0,s.Cg)([(0,o.MZ)({type:String,json:{write:!0}})],i.prototype,"text",void 0),(0,s.Cg)([(0,o.MZ)({type:String,json:{read:{source:"detectedLanguage.language"},write:{target:"detectedLanguage.language"}}})],i.prototype,"detectedLanguage",void 0),(0,s.Cg)([(0,o.MZ)({type:Number,json:{read:{source:"detectedLanguage.score"},write:{target:"detectedLanguage.score"}}})],i.prototype,"detectedLanguageScore",void 0),(0,s.Cg)([(0,o.MZ)({type:Object,json:{write:!0}})],i.prototype,"translation",void 0),i=(0,s.Cg)([(0,a.$)("esri.rest.support.TranslateResult")],i)},24097(t,e,r){r.d(e,{K:()=>s});const s={type:String,json:{read:{source:"token"},write:{target:"token"}}}},45475(t,e,r){r.d(e,{T:()=>a});var s=r(11254),n=r(2272),o=r(14942);async function a(t,e,r){const a=e.toJSON();a.contents=JSON.stringify(a.contents),a.token=await(0,n.gf)(e.portalUrl,e.apiKey,{signal:r?.signal,prompt:"no-prompt"!==r?.authMode});const i=(0,n.Dl)(t),l=(0,n.jV)(i.query,{...r,query:a,method:"post",authMode:"anonymous"});return(await(0,s.A)(i.path,l)).data.results.map(t=>o.A.fromJSON(t))}},48938(t,e,r){r.d(e,{X:()=>n,_:()=>o});var s=r(85935);function n(t){if("string"==typeof t)return t.toLowerCase();if("name"in t)return t.name.toLowerCase();if("string"!=typeof t.value)throw new s.D$(null,"InvalidIdentifier",null);return t.value.toLowerCase()}const o=Object.freeze({aborted:!1})},62791(t,e,r){r.d(e,{A:()=>u});var s=r(5482),n=r(25482),o=r(10107),a=r(64108),i=r(24097),l=r(67090);let u=class extends n.o{constructor(t){super(t),this.to=null,this.contents=null,this.portalUrl="https://www.arcgis.com",this.translator="esri",this.from=null,this.apiKey=null,this.requestSource=null}};(0,s.Cg)([(0,o.MZ)({type:[String],json:{write:!0}})],u.prototype,"to",void 0),(0,s.Cg)([(0,o.MZ)({type:[l.A],json:{write:!0}})],u.prototype,"contents",void 0),(0,s.Cg)([(0,o.MZ)({type:String,json:{write:!0}})],u.prototype,"portalUrl",void 0),(0,s.Cg)([(0,o.MZ)({type:String,json:{write:!0,default:"esri"}})],u.prototype,"translator",void 0),(0,s.Cg)([(0,o.MZ)({type:String,json:{write:!0}})],u.prototype,"from",void 0),(0,s.Cg)([(0,o.MZ)(i.K)],u.prototype,"apiKey",void 0),(0,s.Cg)([(0,o.MZ)({type:String,json:{name:"x-esri-request-source"}})],u.prototype,"requestSource",void 0),u=(0,s.Cg)([(0,a.$)("esri.rest.support.TranslateParameters")],u)},66395(t,e,r){r.d(e,{A:()=>c});var s=r(66131),n=r(6800),o=r(85935),a=r(78878),i=r(91075),l=r(54218);function u(t,e,r=!1,s=!1){if(null==t)return null;if((0,l.Et)(t)||(0,l.Lm)(t)||(0,l.Kg)(t)||(0,a.e)(t)||(0,a.f)(t)||(0,a.g)(t))return t;if((0,l.cy)(t)){const n=[];for(const o of t)n.push(u(o,e,r,s));return n}if(s&&(0,a.h)(t))return t;const n=new c;n.immutable=!1;for(const[o,a]of Object.entries(t))void 0!==a&&n.setField(o,u(a,e,r,s));return n.immutable=r,n}class c{constructor(t){this.declaredClass="esri.arcade.Dictionary",this.plain=!1,this.immutable=!0,t instanceof c?this.attributes=t.attributes:null==t?this.attributes=Object.create(null):null!=Object.getPrototypeOf(t)?this.attributes={__proto__:null,...t}:this.attributes=t}static containerEntry(t,e){return new c({__proto__:null,key:t,value:e})}static textFormatting(){const t=new c({__proto__:null,newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});return t.immutable=!1,t}field(t){const e=t.toLowerCase(),r=this.attributes[t];if(void 0!==r)return r;for(const t in this.attributes)if(t.toLowerCase()===e)return this.attributes[t];throw new o.D$(null,"FieldNotFound",null,{key:t})}setField(t,e){if(this.immutable)throw new o.D$(null,"Immutable",null);if((0,a.i)(e))throw new o.D$(null,"NoFunctionInDictionary",null);const r=t.toLowerCase();if(e instanceof Date&&(e=s.lY.dateJSToArcadeDate(e)),void 0===this.attributes[t]){for(const t in this.attributes)if(t.toLowerCase()===r)return void(this.attributes[t]=e);this.attributes[t]=e}else this.attributes[t]=e}eraseField(t){if(this.immutable)throw new o.D$(null,"Immutable",null);if(t in this.attributes)return void delete this.attributes[t];const e=t.toLowerCase();for(const t in this.attributes)if(t.toLowerCase()===e)return void delete this.attributes[t]}hasField(t){const e=t.toLowerCase();if(void 0!==this.attributes[t])return!0;for(const t in this.attributes)if(t.toLowerCase()===e)return!0;return!1}keys(){let t=[];for(const e in this.attributes)t.push(e);return t=t.sort(),t}values(){return this.keys().map(t=>this.attributes[t])}entryCount(){return Object.keys(this.attributes).length}isEmpty(){return this.entryCount()<=0}castToText(t=!1){return(0,a.c)(this.attributes,{useNumbersForDates:t})}static convertObjectToArcadeDictionary(t,e,r=!0,s=!1){const n=new c;n.immutable=!1;for(const o in t){const a=t[o];void 0!==a&&n.setField(o.toString(),u(a,e,r,s))}return n.immutable=r,n}static convertJsonToArcade(t,e,r=!1,s=!1){return u(t,e,r,s)}castAsJson(t=null){const e=Object.create(null);for(let r in this.attributes){const s=this.attributes[r];void 0!==s&&(t?.keyTranslate&&(r=t.keyTranslate(r)),e[r]=(0,a.a)(s,t))}return e}async castDictionaryValueAsJsonAsync(t,e,r,s=null,n){const o=await(0,a.b)(r,s,n);return t[e]=o,o}async castAsJsonAsync(t=null,e=null){const r=Object.create(null),n=[];for(let o in this.attributes){const l=this.attributes[o];e?.keyTranslate&&(o=e.keyTranslate(o)),void 0!==l&&((0,a.d)(l)||l instanceof i.A||l instanceof s.lY?r[o]=(0,a.a)(l,e):n.push(this.castDictionaryValueAsJsonAsync(r,o,l,t,e)))}return n.length>0&&await Promise.all(n),r}deepClone(){const t=new c;t.immutable=!1;for(const e of this.keys())t.setField(e,(0,n.G)(this.field(e)));return t}}},67090(t,e,r){r.d(e,{A:()=>i});var s=r(5482),n=r(25482),o=r(10107),a=r(64108);let i=class extends n.o{constructor(t){super(t)}};(0,s.Cg)([(0,o.MZ)({type:String,json:{write:!0}})],i.prototype,"key",void 0),(0,s.Cg)([(0,o.MZ)({type:String,json:{write:!0}})],i.prototype,"text",void 0),i=(0,s.Cg)([(0,a.$)("esri.rest.support.TranslateContent")],i)},76343(t,e,r){r.r(e),r.d(e,{BatchTranslationServiceFactory:()=>s.B,PortalTranslationService:()=>s.P,getTranslateParametersKey:()=>s.g,registerFunctions:()=>s.r}),r(48938),r(66395),r(85935),r(78878),r(49186),r(53966),r(20655),r(45475),r(67090),r(62791),r(14942);var s=r(3367)}}]);