8 lines
60 KiB
JavaScript
8 lines
60 KiB
JavaScript
import{A as m,B as _,jh as We,C as oe,ji as Ye,jj as N,jk as lt,jl as je,D as Re,u as ct,a6 as Xe,fR as Ze,bc as R,jm as Qe,I as ke,aj as le,gZ as se,s as C,g$ as ut,cX as H,fV as Y,ar as M,ew as ce,jn as Ae,gy as Te,e7 as qe,jo as ht,ay as Ue,fY as dt,jp as pt,i3 as ue,e9 as Le,bd as ft,jq as vt}from"./index-b5c8f851.js";import{e as gt}from"./widget-88f2c959.js";const he="esri-identity-form",q={base:he,group:`${he}__group`,label:`${he}__label`,footer:`${he}__footer`,esriInput:"esri-input",esriButton:"esri-button",esriButtonSecondary:"esri-button--secondary"},mt="ArcGIS Online";let z=class extends Ye{constructor(e,t){super(e,t),this._usernameInputNode=null,this._passwordInputNode=null,this.signingIn=!1,this.server=null,this.resource=null,this.error=null,this.oAuthPrompt=!1}render(){var c;const{error:e,server:t,resource:r,signingIn:i,oAuthPrompt:s,messages:n}=this,l=N("div",{class:q.group},lt(s?n.oAuthInfo:n.info,{server:t&&/\.arcgis\.com/i.test(t)?mt:t,resource:`(${r||n.lblItem})`})),d=s?null:N("div",{class:q.group,key:"username"},N("label",{class:q.label},n.lblUser,N("input",{afterCreate:je,autocomplete:"off",bind:this,class:q.esriInput,"data-node-ref":"_usernameInputNode",required:!0,spellcheck:!1,type:"text",value:""}))),a=s?null:N("div",{class:q.group,key:"password"},N("label",{class:q.label},n.lblPwd,N("input",{afterCreate:je,bind:this,class:q.esriInput,"data-node-ref":"_passwordInputNode",required:!0,type:"password",value:""}))),p=N("div",{class:this.classes(q.group,q.footer)},N("input",{class:q.esriButton,disabled:!!i,type:"submit",value:i?n.lblSigning:n.lblOk}),N("input",{bind:this,class:this.classes(q.esriButton,q.esriButtonSecondary),onclick:this._cancel,type:"button",value:n.lblCancel})),f=e?N("div",null,(c=e.details)!=null&&c.httpStatus?n.invalidUser:n.noAuthService):null;return N("form",{bind:this,class:q.base,onsubmit:this._submit},l,f,d,a,p)}_cancel(){this._set("signingIn",!1),this._usernameInputNode&&(this._usernameInputNode.value=""),this._passwordInputNode&&(this._passwordInputNode.value=""),this.emit("cancel")}_submit(e){e.preventDefault(),this._set("signingIn",!0);const t=this.oAuthPrompt?{}:{username:this._usernameInputNode&&this._usernameInputNode.value,password:this._passwordInputNode&&this._passwordInputNode.value};this.emit("submit",t)}};m([_(),We("esri/identity/t9n/identity")],z.prototype,"messages",void 0),m([_()],z.prototype,"signingIn",void 0),m([_()],z.prototype,"server",void 0),m([_()],z.prototype,"resource",void 0),m([_()],z.prototype,"error",void 0),m([_()],z.prototype,"oAuthPrompt",void 0),z=m([oe("esri.identity.IdentityForm")],z);const _t=z;/*!
|
|
* tabbable 6.2.0
|
|
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
|
|
*/var $e=["input:not([inert])","select:not([inert])","textarea:not([inert])","a[href]:not([inert])","button:not([inert])","[tabindex]:not(slot):not([inert])","audio[controls]:not([inert])","video[controls]:not([inert])",'[contenteditable]:not([contenteditable="false"]):not([inert])',"details>summary:first-of-type:not([inert])","details:not([inert])"],ge=$e.join(","),et=typeof Element>"u",Z=et?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,me=!et&&Element.prototype.getRootNode?function(o){var e;return o==null||(e=o.getRootNode)===null||e===void 0?void 0:e.call(o)}:function(o){return o==null?void 0:o.ownerDocument},_e=function o(e,t){var r;t===void 0&&(t=!0);var i=e==null||(r=e.getAttribute)===null||r===void 0?void 0:r.call(e,"inert"),s=i===""||i==="true",n=s||t&&e&&o(e.parentNode);return n},bt=function(e){var t,r=e==null||(t=e.getAttribute)===null||t===void 0?void 0:t.call(e,"contenteditable");return r===""||r==="true"},tt=function(e,t,r){if(_e(e))return[];var i=Array.prototype.slice.apply(e.querySelectorAll(ge));return t&&Z.call(e,ge)&&i.unshift(e),i=i.filter(r),i},rt=function o(e,t,r){for(var i=[],s=Array.from(e);s.length;){var n=s.shift();if(!_e(n,!1))if(n.tagName==="SLOT"){var l=n.assignedElements(),d=l.length?l:n.children,a=o(d,!0,r);r.flatten?i.push.apply(i,a):i.push({scopeParent:n,candidates:a})}else{var p=Z.call(n,ge);p&&r.filter(n)&&(t||!e.includes(n))&&i.push(n);var f=n.shadowRoot||typeof r.getShadowRoot=="function"&&r.getShadowRoot(n),c=!_e(f,!1)&&(!r.shadowRootFilter||r.shadowRootFilter(n));if(f&&c){var v=o(f===!0?n.children:f.children,!0,r);r.flatten?i.push.apply(i,v):i.push({scopeParent:n,candidates:v})}else s.unshift.apply(s,n.children)}}return i},st=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},X=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||bt(e))&&!st(e)?0:e.tabIndex},yt=function(e,t){var r=X(e);return r<0&&t&&!st(e)?0:r},wt=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},it=function(e){return e.tagName==="INPUT"},St=function(e){return it(e)&&e.type==="hidden"},It=function(e){var t=e.tagName==="DETAILS"&&Array.prototype.slice.apply(e.children).some(function(r){return r.tagName==="SUMMARY"});return t},kt=function(e,t){for(var r=0;r<e.length;r++)if(e[r].checked&&e[r].form===t)return e[r]},At=function(e){if(!e.name)return!0;var t=e.form||me(e),r=function(l){return t.querySelectorAll('input[type="radio"][name="'+l+'"]')},i;if(typeof window<"u"&&typeof window.CSS<"u"&&typeof window.CSS.escape=="function")i=r(window.CSS.escape(e.name));else try{i=r(e.name)}catch(n){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",n.message),!1}var s=kt(i,e.form);return!s||s===e},Tt=function(e){return it(e)&&e.type==="radio"},Ut=function(e){return Tt(e)&&!At(e)},xt=function(e){var t,r=e&&me(e),i=(t=r)===null||t===void 0?void 0:t.host,s=!1;if(r&&r!==e){var n,l,d;for(s=!!((n=i)!==null&&n!==void 0&&(l=n.ownerDocument)!==null&&l!==void 0&&l.contains(i)||e!=null&&(d=e.ownerDocument)!==null&&d!==void 0&&d.contains(e));!s&&i;){var a,p,f;r=me(i),i=(a=r)===null||a===void 0?void 0:a.host,s=!!((p=i)!==null&&p!==void 0&&(f=p.ownerDocument)!==null&&f!==void 0&&f.contains(i))}}return s},Be=function(e){var t=e.getBoundingClientRect(),r=t.width,i=t.height;return r===0&&i===0},Ot=function(e,t){var r=t.displayCheck,i=t.getShadowRoot;if(getComputedStyle(e).visibility==="hidden")return!0;var s=Z.call(e,"details>summary:first-of-type"),n=s?e.parentElement:e;if(Z.call(n,"details:not([open]) *"))return!0;if(!r||r==="full"||r==="legacy-full"){if(typeof i=="function"){for(var l=e;e;){var d=e.parentElement,a=me(e);if(d&&!d.shadowRoot&&i(d)===!0)return Be(e);e.assignedSlot?e=e.assignedSlot:!d&&a!==e.ownerDocument?e=a.host:e=d}e=l}if(xt(e))return!e.getClientRects().length;if(r!=="legacy-full")return!0}else if(r==="non-zero-area")return Be(e);return!1},Pt=function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var t=e.parentElement;t;){if(t.tagName==="FIELDSET"&&t.disabled){for(var r=0;r<t.children.length;r++){var i=t.children.item(r);if(i.tagName==="LEGEND")return Z.call(t,"fieldset[disabled] *")?!0:!i.contains(e)}return!0}t=t.parentElement}return!1},be=function(e,t){return!(t.disabled||_e(t)||St(t)||Ot(t,e)||It(t)||Pt(t))},Ce=function(e,t){return!(Ut(t)||X(t)<0||!be(e,t))},Rt=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(t)||t>=0)},Ct=function o(e){var t=[],r=[];return e.forEach(function(i,s){var n=!!i.scopeParent,l=n?i.scopeParent:i,d=yt(l,n),a=n?o(i.candidates):l;d===0?n?t.push.apply(t,a):t.push(l):r.push({documentOrder:s,tabIndex:d,item:i,isScope:n,content:a})}),r.sort(wt).reduce(function(i,s){return s.isScope?i.push.apply(i,s.content):i.push(s.content),i},[]).concat(t)},Nt=function(e,t){t=t||{};var r;return t.getShadowRoot?r=rt([e],t.includeContainer,{filter:Ce.bind(null,t),flatten:!1,getShadowRoot:t.getShadowRoot,shadowRootFilter:Rt}):r=tt(e,t.includeContainer,Ce.bind(null,t)),Ct(r)},Dt=function(e,t){t=t||{};var r;return t.getShadowRoot?r=rt([e],t.includeContainer,{filter:be.bind(null,t),flatten:!0,getShadowRoot:t.getShadowRoot}):r=tt(e,t.includeContainer,be.bind(null,t)),r},Q=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return Z.call(e,ge)===!1?!1:Ce(t,e)},Et=$e.concat("iframe").join(","),xe=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return Z.call(e,Et)===!1?!1:be(t,e)};/*!
|
|
* focus-trap 7.5.4
|
|
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
|
|
*/function Ve(o,e){var t=Object.keys(o);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(o);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(o,i).enumerable})),t.push.apply(t,r)}return t}function Me(o){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Ve(Object(t),!0).forEach(function(r){Ft(o,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(t)):Ve(Object(t)).forEach(function(r){Object.defineProperty(o,r,Object.getOwnPropertyDescriptor(t,r))})}return o}function Ft(o,e,t){return e=qt(e),e in o?Object.defineProperty(o,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):o[e]=t,o}function jt(o,e){if(typeof o!="object"||o===null)return o;var t=o[Symbol.toPrimitive];if(t!==void 0){var r=t.call(o,e||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(o)}function qt(o){var e=jt(o,"string");return typeof e=="symbol"?e:String(e)}var ze={activateTrap:function(e,t){if(e.length>0){var r=e[e.length-1];r!==t&&r.pause()}var i=e.indexOf(t);i===-1||e.splice(i,1),e.push(t)},deactivateTrap:function(e,t){var r=e.indexOf(t);r!==-1&&e.splice(r,1),e.length>0&&e[e.length-1].unpause()}},Lt=function(e){return e.tagName&&e.tagName.toLowerCase()==="input"&&typeof e.select=="function"},Bt=function(e){return(e==null?void 0:e.key)==="Escape"||(e==null?void 0:e.key)==="Esc"||(e==null?void 0:e.keyCode)===27},ne=function(e){return(e==null?void 0:e.key)==="Tab"||(e==null?void 0:e.keyCode)===9},Vt=function(e){return ne(e)&&!e.shiftKey},Mt=function(e){return ne(e)&&e.shiftKey},Ge=function(e){return setTimeout(e,0)},He=function(e,t){var r=-1;return e.every(function(i,s){return t(i)?(r=s,!1):!0}),r},ie=function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i<t;i++)r[i-1]=arguments[i];return typeof e=="function"?e.apply(void 0,r):e},de=function(e){return e.target.shadowRoot&&typeof e.composedPath=="function"?e.composedPath()[0]:e.target},zt=[],Gt=function(e,t){var r=(t==null?void 0:t.document)||document,i=(t==null?void 0:t.trapStack)||zt,s=Me({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:Vt,isKeyBackward:Mt},t),n={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0,recentNavEvent:void 0},l,d=function(h,u,g){return h&&h[u]!==void 0?h[u]:s[g||u]},a=function(h,u){var g=typeof(u==null?void 0:u.composedPath)=="function"?u.composedPath():void 0;return n.containerGroups.findIndex(function(T){var U=T.container,P=T.tabbableNodes;return U.contains(h)||(g==null?void 0:g.includes(U))||P.find(function(D){return D===h})})},p=function(h){var u=s[h];if(typeof u=="function"){for(var g=arguments.length,T=new Array(g>1?g-1:0),U=1;U<g;U++)T[U-1]=arguments[U];u=u.apply(void 0,T)}if(u===!0&&(u=void 0),!u){if(u===void 0||u===!1)return u;throw new Error("`".concat(h,"` was specified but was not a node, or did not return a node"))}var P=u;if(typeof u=="string"&&(P=r.querySelector(u),!P))throw new Error("`".concat(h,"` as selector refers to no known node"));return P},f=function(){var h=p("initialFocus");if(h===!1)return!1;if(h===void 0||!xe(h,s.tabbableOptions))if(a(r.activeElement)>=0)h=r.activeElement;else{var u=n.tabbableGroups[0],g=u&&u.firstTabbableNode;h=g||p("fallbackFocus")}if(!h)throw new Error("Your focus-trap needs to have at least one focusable element");return h},c=function(){if(n.containerGroups=n.containers.map(function(h){var u=Nt(h,s.tabbableOptions),g=Dt(h,s.tabbableOptions),T=u.length>0?u[0]:void 0,U=u.length>0?u[u.length-1]:void 0,P=g.find(function(F){return Q(F)}),D=g.slice().reverse().find(function(F){return Q(F)}),j=!!u.find(function(F){return X(F)>0});return{container:h,tabbableNodes:u,focusableNodes:g,posTabIndexesFound:j,firstTabbableNode:T,lastTabbableNode:U,firstDomTabbableNode:P,lastDomTabbableNode:D,nextTabbableNode:function(J){var te=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,G=u.indexOf(J);return G<0?te?g.slice(g.indexOf(J)+1).find(function(re){return Q(re)}):g.slice(0,g.indexOf(J)).reverse().find(function(re){return Q(re)}):u[G+(te?1:-1)]}}}),n.tabbableGroups=n.containerGroups.filter(function(h){return h.tabbableNodes.length>0}),n.tabbableGroups.length<=0&&!p("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times");if(n.containerGroups.find(function(h){return h.posTabIndexesFound})&&n.containerGroups.length>1)throw new Error("At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.")},v=function O(h){var u=h.activeElement;if(u)return u.shadowRoot&&u.shadowRoot.activeElement!==null?O(u.shadowRoot):u},b=function O(h){if(h!==!1&&h!==v(document)){if(!h||!h.focus){O(f());return}h.focus({preventScroll:!!s.preventScroll}),n.mostRecentlyFocusedNode=h,Lt(h)&&h.select()}},y=function(h){var u=p("setReturnFocus",h);return u||(u===!1?!1:h)},I=function(h){var u=h.target,g=h.event,T=h.isBackward,U=T===void 0?!1:T;u=u||de(g),c();var P=null;if(n.tabbableGroups.length>0){var D=a(u,g),j=D>=0?n.containerGroups[D]:void 0;if(D<0)U?P=n.tabbableGroups[n.tabbableGroups.length-1].lastTabbableNode:P=n.tabbableGroups[0].firstTabbableNode;else if(U){var F=He(n.tabbableGroups,function(Se){var Ie=Se.firstTabbableNode;return u===Ie});if(F<0&&(j.container===u||xe(u,s.tabbableOptions)&&!Q(u,s.tabbableOptions)&&!j.nextTabbableNode(u,!1))&&(F=D),F>=0){var J=F===0?n.tabbableGroups.length-1:F-1,te=n.tabbableGroups[J];P=X(u)>=0?te.lastTabbableNode:te.lastDomTabbableNode}else ne(g)||(P=j.nextTabbableNode(u,!1))}else{var G=He(n.tabbableGroups,function(Se){var Ie=Se.lastTabbableNode;return u===Ie});if(G<0&&(j.container===u||xe(u,s.tabbableOptions)&&!Q(u,s.tabbableOptions)&&!j.nextTabbableNode(u))&&(G=D),G>=0){var re=G===n.tabbableGroups.length-1?0:G+1,Fe=n.tabbableGroups[re];P=X(u)>=0?Fe.firstTabbableNode:Fe.firstDomTabbableNode}else ne(g)||(P=j.nextTabbableNode(u))}}else P=p("fallbackFocus");return P},w=function(h){var u=de(h);if(!(a(u,h)>=0)){if(ie(s.clickOutsideDeactivates,h)){l.deactivate({returnFocus:s.returnFocusOnDeactivate});return}ie(s.allowOutsideClick,h)||h.preventDefault()}},B=function(h){var u=de(h),g=a(u,h)>=0;if(g||u instanceof Document)g&&(n.mostRecentlyFocusedNode=u);else{h.stopImmediatePropagation();var T,U=!0;if(n.mostRecentlyFocusedNode)if(X(n.mostRecentlyFocusedNode)>0){var P=a(n.mostRecentlyFocusedNode),D=n.containerGroups[P].tabbableNodes;if(D.length>0){var j=D.findIndex(function(F){return F===n.mostRecentlyFocusedNode});j>=0&&(s.isKeyForward(n.recentNavEvent)?j+1<D.length&&(T=D[j+1],U=!1):j-1>=0&&(T=D[j-1],U=!1))}}else n.containerGroups.some(function(F){return F.tabbableNodes.some(function(J){return X(J)>0})})||(U=!1);else U=!1;U&&(T=I({target:n.mostRecentlyFocusedNode,isBackward:s.isKeyBackward(n.recentNavEvent)})),b(T||n.mostRecentlyFocusedNode||f())}n.recentNavEvent=void 0},ae=function(h){var u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;n.recentNavEvent=h;var g=I({event:h,isBackward:u});g&&(ne(h)&&h.preventDefault(),b(g))},$=function(h){if(Bt(h)&&ie(s.escapeDeactivates,h)!==!1){h.preventDefault(),l.deactivate();return}(s.isKeyForward(h)||s.isKeyBackward(h))&&ae(h,s.isKeyBackward(h))},S=function(h){var u=de(h);a(u,h)>=0||ie(s.clickOutsideDeactivates,h)||ie(s.allowOutsideClick,h)||(h.preventDefault(),h.stopImmediatePropagation())},k=function(){if(n.active)return ze.activateTrap(i,l),n.delayInitialFocusTimer=s.delayInitialFocus?Ge(function(){b(f())}):b(f()),r.addEventListener("focusin",B,!0),r.addEventListener("mousedown",w,{capture:!0,passive:!1}),r.addEventListener("touchstart",w,{capture:!0,passive:!1}),r.addEventListener("click",S,{capture:!0,passive:!1}),r.addEventListener("keydown",$,{capture:!0,passive:!1}),l},A=function(){if(n.active)return r.removeEventListener("focusin",B,!0),r.removeEventListener("mousedown",w,!0),r.removeEventListener("touchstart",w,!0),r.removeEventListener("click",S,!0),r.removeEventListener("keydown",$,!0),l},ye=function(h){var u=h.some(function(g){var T=Array.from(g.removedNodes);return T.some(function(U){return U===n.mostRecentlyFocusedNode})});u&&b(f())},we=typeof window<"u"&&"MutationObserver"in window?new MutationObserver(ye):void 0,ee=function(){we&&(we.disconnect(),n.active&&!n.paused&&n.containers.map(function(h){we.observe(h,{subtree:!0,childList:!0})}))};return l={get active(){return n.active},get paused(){return n.paused},activate:function(h){if(n.active)return this;var u=d(h,"onActivate"),g=d(h,"onPostActivate"),T=d(h,"checkCanFocusTrap");T||c(),n.active=!0,n.paused=!1,n.nodeFocusedBeforeActivation=r.activeElement,u==null||u();var U=function(){T&&c(),k(),ee(),g==null||g()};return T?(T(n.containers.concat()).then(U,U),this):(U(),this)},deactivate:function(h){if(!n.active)return this;var u=Me({onDeactivate:s.onDeactivate,onPostDeactivate:s.onPostDeactivate,checkCanReturnFocus:s.checkCanReturnFocus},h);clearTimeout(n.delayInitialFocusTimer),n.delayInitialFocusTimer=void 0,A(),n.active=!1,n.paused=!1,ee(),ze.deactivateTrap(i,l);var g=d(u,"onDeactivate"),T=d(u,"onPostDeactivate"),U=d(u,"checkCanReturnFocus"),P=d(u,"returnFocus","returnFocusOnDeactivate");g==null||g();var D=function(){Ge(function(){P&&b(y(n.nodeFocusedBeforeActivation)),T==null||T()})};return P&&U?(U(y(n.nodeFocusedBeforeActivation)).then(D,D),this):(D(),this)},pause:function(h){if(n.paused||!n.active)return this;var u=d(h,"onPause"),g=d(h,"onPostPause");return n.paused=!0,u==null||u(),A(),ee(),g==null||g(),this},unpause:function(h){if(!n.paused||!n.active)return this;var u=d(h,"onUnpause"),g=d(h,"onPostUnpause");return n.paused=!1,u==null||u(),c(),k(),ee(),g==null||g(),this},updateContainerElements:function(h){var u=[].concat(h).filter(Boolean);return n.containers=u.map(function(g){return typeof g=="string"?r.querySelector(g):g}),n.active&&c(),ee(),this}},l.updateContainerElements(e),l};const W="esri-identity-modal",V={base:W,open:`${W}--open`,closed:`${W}--closed`,title:`${W}__title`,dialog:`${W}__dialog`,content:`${W}__content`,closeButton:`${W}__close-button`,iconClose:"esri-icon-close"};let K=class extends Ye{constructor(o,e){super(o,e),this.container=document.createElement("div"),this.content=null,this.open=!1,this._focusTrap=null,this._close=()=>{this.open=!1},document.body.appendChild(this.container),this.addHandles(Re(()=>this.open,()=>this._toggleFocusTrap()))}destroy(){this._destroyFocusTrap()}get title(){var o;return(o=this.messages)==null?void 0:o.auth.signIn}render(){const o=this.id,{open:e,content:t,title:r,messages:i}=this,s=e&&!!t,n={[V.open]:s,[V.closed]:!s},l=N("button",{"aria-label":i.close,bind:this,class:V.closeButton,onclick:this._close,title:i.close,type:"button"},N("span",{"aria-hidden":"true",class:V.iconClose})),d=`${o}_title`,a=`${o}_content`,p=r?N("h1",{class:V.title,id:d},r):null,f=s?N("div",{afterCreate:this._createFocusTrap,"aria-describedby":a,"aria-labelledby":d,bind:this,class:V.dialog,role:"dialog"},l,p,this._renderContent(a)):null;return N("div",{class:this.classes(V.base,n),tabIndex:-1},f)}_destroyFocusTrap(){var o;(o=this._focusTrap)==null||o.deactivate({onDeactivate:()=>{}}),this._focusTrap=null}_toggleFocusTrap(){const{_focusTrap:o,open:e}=this;o&&(e?o.activate():o.deactivate())}_createFocusTrap(o){this._destroyFocusTrap();const e=requestAnimationFrame(()=>{this._focusTrap=Gt(o,{initialFocus:"input",onDeactivate:this._close}),this._toggleFocusTrap()});this.addHandles(ct(()=>cancelAnimationFrame(e)))}_renderContent(o){const e=this.content;return typeof e=="string"?N("div",{class:V.content,id:o,innerHTML:e}):gt(e)?N("div",{class:V.content,id:o},e.render()):e instanceof HTMLElement?N("div",{afterCreate:this._attachToNode,bind:e,class:V.content,id:o}):null}_attachToNode(o){const e=this;o.appendChild(e)}};m([_({readOnly:!0})],K.prototype,"container",void 0),m([_()],K.prototype,"content",void 0),m([_()],K.prototype,"open",void 0),m([_(),We("esri/t9n/common")],K.prototype,"messages",void 0),m([_()],K.prototype,"title",null),K=m([oe("esri.identity.IdentityModal")],K);const Ke=K,Oe="esriJSAPIOAuth";class Ne{constructor(e,t){this.oAuthInfo=null,this.storage=null,this.appId=null,this.codeVerifier=null,this.expires=null,this.refreshToken=null,this.ssl=null,this.stateUID=null,this.token=null,this.userId=null,this.oAuthInfo=e,this.storage=t,this._init()}isValid(){let e=!1;if(this.oAuthInfo&&this.userId&&(this.refreshToken||this.token)){if(this.expires==null&&this.refreshToken)e=!0;else if(this.expires){const t=Date.now();this.expires>t&&(this.expires-t)/1e3>60*this.oAuthInfo.minTimeUntilExpiration&&(e=!0)}}return e}save(){if(!this.storage)return!1;const e=this._load(),t=this.oAuthInfo;if(t&&t.authNamespace&&t.portalUrl){let r=e[t.authNamespace];r||(r=e[t.authNamespace]={}),this.appId||(this.appId=t.appId),r[t.portalUrl]={appId:this.appId,codeVerifier:this.codeVerifier,expires:this.expires,refreshToken:this.refreshToken,ssl:this.ssl,stateUID:this.stateUID,token:this.token,userId:this.userId};try{this.storage.setItem(Oe,JSON.stringify(e))}catch(i){return console.warn(i),!1}return!0}return!1}destroy(){const e=this._load(),t=this.oAuthInfo;if(t!=null&&t.appId&&(t!=null&&t.portalUrl)&&(this.expires==null||this.expires>Date.now())&&(this.refreshToken||this.token)){const r=t.portalUrl.replace(/^http:/i,"https:")+"/sharing/rest/oauth2/revokeToken",i=new FormData;if(i.append("f","json"),i.append("auth_token",this.refreshToken||this.token),i.append("client_id",t.appId),i.append("token_type_hint",this.refreshToken?"refresh_token":"access_token"),typeof navigator.sendBeacon=="function")navigator.sendBeacon(r,i);else{const s=new XMLHttpRequest;s.open("POST",r),s.send(i)}}if(t&&t.authNamespace&&t.portalUrl&&this.storage){const r=e[t.authNamespace];if(r){delete r[t.portalUrl];try{this.storage.setItem(Oe,JSON.stringify(e))}catch(i){console.log(i)}}}t&&(t._oAuthCred=null,this.oAuthInfo=null)}_init(){const e=this._load(),t=this.oAuthInfo;if(t&&t.authNamespace&&t.portalUrl){let r=e[t.authNamespace];r&&(r=r[t.portalUrl],r&&(this.appId=r.appId,this.codeVerifier=r.codeVerifier,this.expires=r.expires,this.refreshToken=r.refreshToken,this.ssl=r.ssl,this.stateUID=r.stateUID,this.token=r.token,this.userId=r.userId))}}_load(){let e={};if(this.storage){const t=this.storage.getItem(Oe);if(t)try{e=JSON.parse(t)}catch(r){console.warn(r)}}return e}}Ne.prototype.declaredClass="esri.identity.OAuthCredential";var De;let E=De=class extends Xe{constructor(o){super(o),this._oAuthCred=null,this.appId=null,this.authNamespace="/",this.expiration=20160,this.flowType="auto",this.forceLogin=!1,this.forceUserId=!1,this.locale=null,this.minTimeUntilExpiration=30,this.popup=!1,this.popupCallbackUrl="oauth-callback.html",this.popupWindowFeatures="height=490,width=800,resizable,scrollbars,status",this.portalUrl="https://www.arcgis.com",this.preserveUrlHash=!1,this.userId=null}clone(){return De.fromJSON(this.toJSON())}};m([_({json:{write:!0}})],E.prototype,"appId",void 0),m([_({json:{write:!0}})],E.prototype,"authNamespace",void 0),m([_({json:{write:!0}})],E.prototype,"expiration",void 0),m([_({json:{write:!0}})],E.prototype,"flowType",void 0),m([_({json:{write:!0}})],E.prototype,"forceLogin",void 0),m([_({json:{write:!0}})],E.prototype,"forceUserId",void 0),m([_({json:{write:!0}})],E.prototype,"locale",void 0),m([_({json:{write:!0}})],E.prototype,"minTimeUntilExpiration",void 0),m([_({json:{write:!0}})],E.prototype,"popup",void 0),m([_({json:{write:!0}})],E.prototype,"popupCallbackUrl",void 0),m([_({json:{write:!0}})],E.prototype,"popupWindowFeatures",void 0),m([_({json:{write:!0}})],E.prototype,"portalUrl",void 0),m([_({json:{write:!0}})],E.prototype,"preserveUrlHash",void 0),m([_({json:{write:!0}})],E.prototype,"userId",void 0),E=De=m([oe("esri.identity.OAuthInfo")],E);const Je=E;let L=class extends Xe{constructor(e){super(e),this.adminTokenServiceUrl=null,this.currentVersion=null,this.hasPortal=null,this.hasServer=null,this.owningSystemUrl=null,this.owningTenant=null,this.server=null,this.shortLivedTokenValidity=null,this.tokenServiceUrl=null,this.webTierAuth=null}};m([_({json:{write:!0}})],L.prototype,"adminTokenServiceUrl",void 0),m([_({json:{write:!0}})],L.prototype,"currentVersion",void 0),m([_({json:{write:!0}})],L.prototype,"hasPortal",void 0),m([_({json:{write:!0}})],L.prototype,"hasServer",void 0),m([_({json:{write:!0}})],L.prototype,"owningSystemUrl",void 0),m([_({json:{write:!0}})],L.prototype,"owningTenant",void 0),m([_({json:{write:!0}})],L.prototype,"server",void 0),m([_({json:{write:!0}})],L.prototype,"shortLivedTokenValidity",void 0),m([_({json:{write:!0}})],L.prototype,"tokenServiceUrl",void 0),m([_({json:{write:!0}})],L.prototype,"webTierAuth",void 0),L=m([oe("esri.identity.ServerInfo")],L);const Pe=L,pe={},nt=o=>{const e=new Y(o.owningSystemUrl).host,t=new Y(o.server).host,r=/.+\.arcgis\.com$/i;return r.test(e)&&r.test(t)},Ee=(o,e)=>!!(nt(o)&&e&&e.some(t=>t.test(o.server)));let fe=null,ve=null;try{fe=window.localStorage,ve=window.sessionStorage}catch{}class ot extends Ze{constructor(){super(),this._portalConfig=globalThis.esriGeowConfig,this.serverInfos=[],this.oAuthInfos=[],this.credentials=[],this._soReqs=[],this._xoReqs=[],this._portals=[],this._defaultOAuthInfo=null,this._defaultTokenValidity=60,this.dialog=null,this.formConstructor=_t,this.tokenValidity=null,this.normalizeWebTierAuth=!1,this._appOrigin=window.origin!=="null"?window.origin:window.location.origin,this._appUrlObj=ke(window.location.href),this._busy=null,this._rejectOnPersistedPageShow=!1,this._oAuthLocationParams=null,this._gwTokenUrl="/sharing/rest/generateToken",this._agsRest="/rest/services",this._agsPortal=/\/sharing(\/|$)/i,this._agsAdmin=/(https?:\/\/[^\/]+\/[^\/]+)\/admin\/?(\/.*)?$/i,this._adminSvcs=/\/rest\/admin\/services(\/|$)/i,this._gwDomains=[{regex:/^https?:\/\/www\.arcgis\.com/i,customBaseUrl:"maps.arcgis.com",tokenServiceUrl:"https://www.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:dev|[a-z\d-]+\.mapsdev)\.arcgis\.com/i,customBaseUrl:"mapsdev.arcgis.com",tokenServiceUrl:"https://dev.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:devext|[a-z\d-]+\.mapsdevext)\.arcgis\.com/i,customBaseUrl:"mapsdevext.arcgis.com",tokenServiceUrl:"https://devext.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:qaext|[a-z\d-]+\.mapsqa)\.arcgis\.com/i,customBaseUrl:"mapsqa.arcgis.com",tokenServiceUrl:"https://qaext.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/[a-z\d-]+\.maps\.arcgis\.com/i,customBaseUrl:"maps.arcgis.com",tokenServiceUrl:"https://www.arcgis.com/sharing/rest/generateToken"}],this._legacyFed=[],this._regexSDirUrl=/http.+\/rest\/services\/?/gi,this._regexServerType=/(\/(FeatureServer|GPServer|GeoDataServer|GeocodeServer|GeoenrichmentServer|GeometryServer|GlobeServer|ImageServer|KnowledgeGraphServer|MapServer|MissionServer|MobileServer|NAServer|NetworkDiagramServer|OGCFeatureServer|ParcelFabricServer|RelationalCatalogServer|SceneServer|StreamServer|UtilityNetworkServer|ValidationServer|VectorTileServer|VersionManagementServer|VideoServer)).*/gi,this._gwUser=/http.+\/users\/([^\/]+)\/?.*/i,this._gwItem=/http.+\/items\/([^\/]+)\/?.*/i,this._gwGroup=/http.+\/groups\/([^\/]+)\/?.*/i,this._rePortalTokenSvc=/\/sharing(\/rest)?\/generatetoken/i,this._createDefaultOAuthInfo=!0,this._hasTestedIfAppIsOnPortal=!1,this._getOAuthLocationParams(),window.addEventListener("pageshow",e=>{this._pageShowHandler(e)})}registerServers(e){const t=this.serverInfos;t?(e=e.filter(r=>!this.findServerInfo(r.server)),this.serverInfos=t.concat(e)):this.serverInfos=e,e.forEach(r=>{r.owningSystemUrl&&this._portals.push(r.owningSystemUrl),r.hasPortal&&this._portals.push(r.server)})}registerOAuthInfos(e){const t=this.oAuthInfos;if(t){for(const r of e){const i=this.findOAuthInfo(r.portalUrl);i&&t.splice(t.indexOf(i),1)}this.oAuthInfos=t.concat(e)}else this.oAuthInfos=e}registerToken(e){e={...e};const t=this._sanitizeUrl(e.server),r=this._isServerRsrc(t);let i,s=this.findServerInfo(t),n=!0;s||(s=new Pe,s.server=this._getServerInstanceRoot(t),r?s.hasServer=!0:(s.tokenServiceUrl=this._getTokenSvcUrl(t),s.hasPortal=!0),this.registerServers([s])),i=this._findCredential(t),i?(delete e.server,Object.assign(i,e),n=!1):(i=new x({userId:e.userId,server:s.server,token:e.token,expires:e.expires,ssl:e.ssl,scope:r?"server":"portal"}),i.resources=[t],this.credentials.push(i)),i.emitTokenChange(!1),n||i.refreshServerTokens()}toJSON(){return Qe({serverInfos:this.serverInfos.map(e=>e.toJSON()),oAuthInfos:this.oAuthInfos.map(e=>e.toJSON()),credentials:this.credentials.map(e=>e.toJSON())})}initialize(e){if(!e)return;typeof e=="string"&&(e=JSON.parse(e));const t=e.serverInfos,r=e.oAuthInfos,i=e.credentials;if(t){const s=[];t.forEach(n=>{n.server&&n.tokenServiceUrl&&s.push(n.declaredClass?n:new Pe(n))}),s.length&&this.registerServers(s)}if(r){const s=[];r.forEach(n=>{n.appId&&s.push(n.declaredClass?n:new Je(n))}),s.length&&this.registerOAuthInfos(s)}i&&i.forEach(s=>{s.server&&s.token&&s.expires&&s.expires>Date.now()&&((s=s.declaredClass?s:new x(s)).emitTokenChange(),this.credentials.push(s))})}findServerInfo(e){let t;e=this._sanitizeUrl(e);for(const r of this.serverInfos)if(this._hasSameServerInstance(r.server,e)){t=r;break}return t}findOAuthInfo(e){let t;e=this._sanitizeUrl(e);for(const r of this.oAuthInfos)if(this._hasSameServerInstance(r.portalUrl,e)){t=r;break}return t}findCredential(e,t){if(!e)return;let r;e=this._sanitizeUrl(e);const i=this._isServerRsrc(e)?"server":"portal";if(t){for(const s of this.credentials)if(this._hasSameServerInstance(s.server,e)&&t===s.userId&&s.scope===i){r=s;break}}else for(const s of this.credentials)if(this._hasSameServerInstance(s.server,e)&&this._getIdenticalSvcIdx(e,s)!==-1&&s.scope===i){r=s;break}return r}getCredential(e,t){let r,i,s=!0;t&&(r=!!t.token,i=t.error,s=t.prompt!==!1),t={...t},e=this._sanitizeUrl(e);const n=new AbortController,l=le();if(t.signal&&se(t.signal,()=>{n.abort()}),se(n,()=>{l.reject(new C("identity-manager:user-aborted","ABORTED"))}),ut(n))return l.promise;t.signal=n.signal;const d=this._isAdminResource(e),a=r?this.findCredential(e):null;let p;if(a&&i&&i.details&&i.details.httpStatus===498)a.destroy();else if(a)return p=new C("identity-manager:not-authorized","You are currently signed in as: '"+a.userId+"'. You do not have access to this resource: "+e,{error:i}),l.reject(p),l.promise;const f=this._findCredential(e,t);if(f)return l.resolve(f),l.promise;let c=this.findServerInfo(e);if(c)!c.hasPortal&&c.server&&c.owningSystemUrl&&this._hasSameServerInstance(c.server,c.owningSystemUrl)&&(c.hasPortal=!0),!c.hasServer&&this._isServerRsrc(e)&&(c._restInfoPms=this._getTokenSvcUrl(e),c.hasServer=!0);else{const v=this._getTokenSvcUrl(e);if(!v)return p=new C("identity-manager:unknown-resource","Unknown resource - could not find token service endpoint."),l.reject(p),l.promise;c=new Pe,c.server=this._getServerInstanceRoot(e),typeof v=="string"?(c.tokenServiceUrl=v,c.hasPortal=!0):(c._restInfoPms=v,c.hasServer=!0),this.registerServers([c])}return c.hasPortal&&c._selfReq===void 0&&(s||H(c.tokenServiceUrl,this._appOrigin)||this._gwDomains.some(v=>v.tokenServiceUrl===c.tokenServiceUrl))&&(c._selfReq={owningTenant:t==null?void 0:t.owningTenant,selfDfd:this._getPortalSelf(c.tokenServiceUrl.replace(this._rePortalTokenSvc,"/sharing/rest/portals/self"),e)}),this._enqueue(e,c,t,l,d)}getResourceName(e){return this._isRESTService(e)?e.replace(this._regexSDirUrl,"").replace(this._regexServerType,"")||"":this._gwUser.test(e)&&e.replace(this._gwUser,"$1")||this._gwItem.test(e)&&e.replace(this._gwItem,"$1")||this._gwGroup.test(e)&&e.replace(this._gwGroup,"$1")||""}generateToken(e,t,r){const i=this._rePortalTokenSvc.test(e.tokenServiceUrl),s=new Y(this._appOrigin),n=e.shortLivedTokenValidity;let l,d,a,p,f,c,v,b;t&&(b=this.tokenValidity||n||this._defaultTokenValidity,b>n&&n>0&&(b=n)),r&&(l=r.isAdmin,d=r.serverUrl,a=r.token,c=r.signal,v=r.ssl,e.customParameters=r.customParameters),l?p=e.adminTokenServiceUrl:(p=e.tokenServiceUrl,f=new Y(p.toLowerCase()),e.webTierAuth&&(r!=null&&r.serverUrl)&&!v&&s.scheme==="http"&&(H(s.uri,p,!0)||f.scheme==="https"&&s.host===f.host&&s.port==="7080"&&f.port==="7443")&&(p=p.replace(/^https:/i,"http:").replace(/:7443/i,":7080")));const y={query:{request:"getToken",username:t==null?void 0:t.username,password:t==null?void 0:t.password,serverUrl:d,token:a,expiration:b,referer:l||i?this._appOrigin:null,client:l?"referer":null,f:"json",...e.customParameters},method:"post",authMode:"anonymous",useProxy:this._useProxy(e,r),signal:c,...r==null?void 0:r.ioArgs};return i||(y.withCredentials=!1),M(p,y).then(I=>{const w=I.data;if(!(w!=null&&w.token))return new C("identity-manager:authentication-failed","Unable to generate token");const B=e.server;return pe[B]||(pe[B]={}),t&&(pe[B][t.username]=t.password),w.validity=b,w})}isBusy(){return!!this._busy}checkSignInStatus(e){return this.checkAppAccess(e,"").then(t=>t.credential)}checkAppAccess(e,t,r){let i=!1;return this.getCredential(e,{prompt:!1}).then(s=>{let n;const l={f:"json"};if(s.scope==="portal")if(t&&(this._doPortalSignIn(e)||r!=null&&r.force))n=s.server+"/sharing/rest/oauth2/validateAppAccess",l.client_id=t;else{if(!s.token)return{credential:s};n=s.server+"/sharing/rest"}else{if(!s.token)return{credential:s};n=s.server+"/rest/services"}return s.token&&(l.token=s.token),M(n,{query:l,authMode:"anonymous"}).then(d=>{if(d.data.valid===!1)throw new C("identity-manager:not-authorized",`You are currently signed in as: '${s.userId}'.`,d.data);return i=!!d.data.viewOnlyUserTypeApp,{credential:s}}).catch(d=>{var p;if(d.name==="identity-manager:not-authorized")throw d;const a=(p=d.details)==null?void 0:p.httpStatus;if(a===498)throw s.destroy(),new C("identity-manager:not-authenticated","User is not signed in.");if(a===400)throw new C("identity-manager:invalid-request");return{credential:s}})}).then(s=>({credential:s.credential,viewOnly:i}))}setOAuthResponseHash(e){e&&(e.charAt(0)==="#"&&(e=e.substring(1)),this._processOAuthPopupParams(ce(e)))}setOAuthRedirectionHandler(e){this._oAuthRedirectFunc=e}setProtocolErrorHandler(e){this._protocolFunc=e}signIn(e,t,r={}){const i=le(),s=()=>{var f;d==null||d.remove(),a==null||a.remove(),p==null||p.remove(),l==null||l.destroy(),(f=this.dialog)==null||f.destroy(),this.dialog=l=d=a=p=null},n=()=>{s(),this._oAuthDfd=null,i.reject(new C("identity-manager:user-aborted","ABORTED"))};r.signal&&se(r.signal,()=>{n()});let l=new this.formConstructor;l.resource=this.getResourceName(e),l.server=t.server,this.dialog=new Ke,this.dialog.content=l,this.dialog.open=!0,this.emit("dialog-create");let d=l.on("cancel",n),a=Re(()=>this.dialog.open,n),p=l.on("submit",f=>{this.generateToken(t,f,{isAdmin:r.isAdmin,signal:r.signal}).then(c=>{s();const v=new x({userId:f.username,server:t.server,token:c.token,expires:c.expires!=null?Number(c.expires):null,ssl:!!c.ssl,isAdmin:r.isAdmin,validity:c.validity});i.resolve(v)}).catch(c=>{l.error=c,l.signingIn=!1})});return i.promise}oAuthSignIn(e,t,r,i){this._oAuthDfd=le();const s=this._oAuthDfd;let n;i!=null&&i.signal&&se(i.signal,()=>{const b=this._oAuthDfd&&this._oAuthDfd.oAuthWin_;b&&!b.closed?b.close():this.dialog&&c()}),s.resUrl_=e,s.sinfo_=t,s.oinfo_=r;const l=r._oAuthCred;if(l.storage&&(r.flowType==="authorization-code"||r.flowType==="auto"&&t.currentVersion>=8.4)){let b=crypto.getRandomValues(new Uint8Array(32));n=Ae(b),l.codeVerifier=n,b=crypto.getRandomValues(new Uint8Array(32)),l.stateUID=Ae(b),l.save()||(l.codeVerifier=n=null)}else l.codeVerifier=null;let d,a,p,f;this._getCodeChallenge(n).then(b=>{const y=!i||i.oAuthPopupConfirmation!==!1;r.popup&&y?(d=new this.formConstructor,d.oAuthPrompt=!0,d.server=t.server,this.dialog=new Ke,this.dialog.content=d,this.dialog.open=!0,this.emit("dialog-create"),a=d.on("cancel",c),p=Re(()=>this.dialog.open,c),f=d.on("submit",()=>{v(),this._doOAuthSignIn(e,t,r,b)})):this._doOAuthSignIn(e,t,r,b)});const c=()=>{v(),this._oAuthDfd=null,s.reject(new C("identity-manager:user-aborted","ABORTED"))},v=()=>{var b;a==null||a.remove(),p==null||p.remove(),f==null||f.remove(),d==null||d.destroy(),(b=this.dialog)==null||b.destroy(),this.dialog=null};return s.promise}destroyCredentials(){this.credentials&&this.credentials.slice().forEach(e=>{e.destroy()}),this.emit("credentials-destroy")}enablePostMessageAuth(e="https://www.arcgis.com/sharing/rest"){this._postMessageAuthHandle&&this._postMessageAuthHandle.remove(),this._postMessageAuthHandle=Te(window,"message",t=>{var r;if((t.origin===this._appOrigin||t.origin.endsWith(".arcgis.com"))&&((r=t.data)==null?void 0:r.type)==="arcgis:auth:requestCredential"){const i=t.source;this.getCredential(e).then(s=>{i.postMessage({type:"arcgis:auth:credential",credential:{expires:s.expires,server:s.server,ssl:s.ssl,token:s.token,userId:s.userId}},t.origin)}).catch(s=>{i.postMessage({type:"arcgis:auth:error",error:{name:s.name,message:s.message}},t.origin)})}})}disablePostMessageAuth(){this._postMessageAuthHandle&&(this._postMessageAuthHandle.remove(),this._postMessageAuthHandle=null)}_getOAuthLocationParams(){var r,i;let e=window.location.hash;if(e){e.charAt(0)==="#"&&(e=e.substring(1));const s=ce(e);let n=!1;if(s.access_token&&s.expires_in&&s.state&&s.hasOwnProperty("username"))try{s.state=JSON.parse(s.state),s.state.portalUrl&&(this._oAuthLocationParams=s,n=!0)}catch{}else if(s.error&&s.error_description&&(console.log("IdentityManager OAuth Error: ",s.error," - ",s.error_description),s.error==="access_denied"&&(n=!0,s.state)))try{s.state=JSON.parse(s.state)}catch{}n&&(window.location.hash=((r=s.state)==null?void 0:r.hash)||"")}let t=window.location.search;if(t){t.charAt(0)==="?"&&(t=t.substring(1));const s=ce(t);let n=!1;if(s.code&&s.state)try{s.state=JSON.parse(s.state),s.state.portalUrl&&s.state.uid&&(this._oAuthLocationParams=s,n=!0)}catch{}else if(s.error&&s.error_description&&(console.log("IdentityManager OAuth Error: ",s.error," - ",s.error_description),s.error==="access_denied"&&(n=!0,s.state)))try{s.state=JSON.parse(s.state)}catch{}if(n){const l={...s};["code","error","error_description","message_code","persist","state"].forEach(p=>{delete l[p]});const d=qe(l),a=window.location.pathname+(d?`?${d}`:"")+(((i=s.state)==null?void 0:i.hash)||"");window.history.replaceState(window.history.state,"",a)}}}_getOAuthToken(e,t,r,i,s){return e=e.replace(/^http:/i,"https:"),M(`${e}/sharing/rest/oauth2/token`,{authMode:"anonymous",method:"post",query:i&&s?{grant_type:"authorization_code",code:t,redirect_uri:i,client_id:r,code_verifier:s}:{grant_type:"refresh_token",refresh_token:t,client_id:r}}).then(n=>n.data)}_getCodeChallenge(e){if(e&&globalThis.isSecureContext){const t=new TextEncoder().encode(e);return crypto.subtle.digest("SHA-256",t).then(r=>Ae(new Uint8Array(r)))}return Promise.resolve(null)}_pageShowHandler(e){if(e.persisted&&this.isBusy()&&this._rejectOnPersistedPageShow){const t=new C("identity-manager:user-aborted","ABORTED");this._errbackFunc(t)}}_findCredential(e,t){let r,i,s,n,l=-1;const d=t==null?void 0:t.token,a=t==null?void 0:t.resource,p=this._isServerRsrc(e)?"server":"portal",f=this.credentials.filter(c=>this._hasSameServerInstance(c.server,e)&&c.scope===p);if(e=a||e,f.length)if(f.length===1){if(r=f[0],s=this.findServerInfo(r.server),i=s==null?void 0:s.owningSystemUrl,n=i?this.findCredential(i,r.userId):void 0,l=this._getIdenticalSvcIdx(e,r),!d)return l===-1&&r.resources.push(e),this._addResource(e,n),r;l!==-1&&(r.resources.splice(l,1),this._removeResource(e,n))}else{let c,v;if(f.some(b=>(v=this._getIdenticalSvcIdx(e,b),v!==-1&&(c=b,s=this.findServerInfo(c.server),i=s==null?void 0:s.owningSystemUrl,n=i?this.findCredential(i,c.userId):void 0,l=v,!0))),d)c&&(c.resources.splice(l,1),this._removeResource(e,n));else if(c)return this._addResource(e,n),c}}_findOAuthInfo(e){let t=this.findOAuthInfo(e);if(!t){for(const r of this.oAuthInfos)if(this._isIdProvider(r.portalUrl,e)){t=r;break}}return t}_addResource(e,t){t&&this._getIdenticalSvcIdx(e,t)===-1&&t.resources.push(e)}_removeResource(e,t){let r=-1;t&&(r=this._getIdenticalSvcIdx(e,t),r>-1&&t.resources.splice(r,1))}_useProxy(e,t){return(t==null?void 0:t.isAdmin)&&!H(e.adminTokenServiceUrl,this._appOrigin)||!this._isPortalDomain(e.tokenServiceUrl)&&String(e.currentVersion)==="10.1"&&!H(e.tokenServiceUrl,this._appOrigin)}_getOrigin(e){const t=new Y(e);return t.scheme+"://"+t.host+(t.port!=null?":"+t.port:"")}_getServerInstanceRoot(e){const t=e.toLowerCase();let r=t.indexOf(this._agsRest);return r===-1&&this._isAdminResource(e)&&(r=this._agsAdmin.test(e)?e.replace(this._agsAdmin,"$1").length:e.search(this._adminSvcs)),r!==-1||ht(t)||(r=t.indexOf("/sharing")),r===-1&&t.substr(-1)==="/"&&(r=t.length-1),r>-1?e.substring(0,r):e}_hasSameServerInstance(e,t){return e.substr(-1)==="/"&&(e=e.slice(0,-1)),e=e.toLowerCase(),t=this._getServerInstanceRoot(t).toLowerCase(),e=this._normalizeAGOLorgDomain(e),t=this._normalizeAGOLorgDomain(t),(e=e.substr(e.indexOf(":")))===(t=t.substr(t.indexOf(":")))}_normalizeAGOLorgDomain(e){const t=/^https?:\/\/(?:cdn|[a-z\d-]+\.maps)\.arcgis\.com/i,r=/^https?:\/\/(?:cdndev|[a-z\d-]+\.mapsdevext)\.arcgis\.com/i,i=/^https?:\/\/(?:cdnqa|[a-z\d-]+\.mapsqa)\.arcgis\.com/i;return t.test(e)?e=e.replace(t,"https://www.arcgis.com"):r.test(e)?e=e.replace(r,"https://devext.arcgis.com"):i.test(e)&&(e=e.replace(i,"https://qaext.arcgis.com")),e}_sanitizeUrl(e){const t=(Ue.request.proxyUrl||"").toLowerCase(),r=t?e.toLowerCase().indexOf(t+"?"):-1;return r!==-1&&(e=e.substring(r+t.length+1)),e=dt(e),ke(e).path}_isRESTService(e){return e.includes(this._agsRest)}_isAdminResource(e){return this._agsAdmin.test(e)||this._adminSvcs.test(e)}_isServerRsrc(e){return this._isRESTService(e)||this._isAdminResource(e)}_isIdenticalService(e,t){let r=!1;if(this._isRESTService(e)&&this._isRESTService(t)){const i=this._getSuffix(e).toLowerCase(),s=this._getSuffix(t).toLowerCase();if(r=i===s,!r){const n=/(.*)\/(MapServer|FeatureServer|UtilityNetworkServer).*/gi;r=i.replaceAll(n,"$1")===s.replaceAll(n,"$1")}}else this._isAdminResource(e)&&this._isAdminResource(t)?r=!0:this._isServerRsrc(e)||this._isServerRsrc(t)||!this._isPortalDomain(e)||(r=!0);return r}_isPortalDomain(e){const t=new Y(e.toLowerCase()),r=this._portalConfig;let i=this._gwDomains.some(s=>s.regex.test(t.uri));return!i&&r&&(i=this._hasSameServerInstance(this._getServerInstanceRoot(r.restBaseUrl),t.uri)),i||Ue.portalUrl&&(i=H(t,Ue.portalUrl,!0)),i||(i=this._portals.some(s=>this._hasSameServerInstance(s,t.uri))),i=i||this._agsPortal.test(t.path),i}_isIdProvider(e,t){let r=-1,i=-1;this._gwDomains.forEach((n,l)=>{r===-1&&n.regex.test(e)&&(r=l),i===-1&&n.regex.test(t)&&(i=l)});let s=!1;if(r>-1&&i>-1&&(r===0||r===4?i!==0&&i!==4||(s=!0):r===1?i!==1&&i!==2||(s=!0):r===2?i===2&&(s=!0):r===3&&i===3&&(s=!0)),!s){const n=this.findServerInfo(t),l=n==null?void 0:n.owningSystemUrl;l&&nt(n)&&this._isPortalDomain(l)&&this._isIdProvider(e,l)&&(s=!0)}return s}_getIdenticalSvcIdx(e,t){let r=-1;for(let i=0;i<t.resources.length;i++){const s=t.resources[i];if(this._isIdenticalService(e,s)){r=i;break}}return r}_getSuffix(e){return e.replace(this._regexSDirUrl,"").replace(this._regexServerType,"$1")}_getTokenSvcUrl(e){let t,r,i;if(this._isRESTService(e)||this._isAdminResource(e)){const s=this._getServerInstanceRoot(e);return t=s+"/admin/generateToken",r=M(e=s+"/rest/info",{query:{f:"json"}}).then(n=>n.data),{adminUrl:t,promise:r}}if(this._isPortalDomain(e)){let s="";if(this._gwDomains.some(n=>(n.regex.test(e)&&(s=n.tokenServiceUrl),!!s)),s||this._portals.some(n=>(this._hasSameServerInstance(n,e)&&(s=n+this._gwTokenUrl),!!s)),s||(i=e.toLowerCase().indexOf("/sharing"),i!==-1&&(s=e.substring(0,i)+this._gwTokenUrl)),s||(s=this._getOrigin(e)+this._gwTokenUrl),s){const n=new Y(e).port;/^http:\/\//i.test(e)&&n==="7080"&&(s=s.replace(/:7080/i,":7443")),s=s.replace(/http:/i,"https:")}return s}if(e.toLowerCase().includes("premium.arcgisonline.com"))return"https://premium.arcgisonline.com/server/tokens"}_processOAuthResponseParams(e,t,r){const i=t._oAuthCred;if(e.code){const n=i.codeVerifier;return i.codeVerifier=null,i.stateUID=null,i.save(),this._getOAuthToken(r.server,e.code,t.appId,this._getRedirectURI(t,!0),n).then(l=>{const d=new x({userId:l.username,server:r.server,token:l.access_token,expires:Date.now()+1e3*l.expires_in,ssl:l.ssl,oAuthState:e.state,_oAuthCred:i});return t.userId=d.userId,i.storage=l.persist?fe:ve,i.refreshToken=l.refresh_token,i.token=null,i.expires=l.refresh_token_expires_in?Date.now()+1e3*l.refresh_token_expires_in:null,i.userId=d.userId,i.ssl=d.ssl,i.save(),d})}const s=new x({userId:e.username,server:r.server,token:e.access_token,expires:Date.now()+1e3*Number(e.expires_in),ssl:e.ssl==="true",oAuthState:e.state,_oAuthCred:i});return t.userId=s.userId,i.storage=e.persist?fe:ve,i.refreshToken=null,i.token=s.token,i.expires=s.expires,i.userId=s.userId,i.ssl=s.ssl,i.save(),Promise.resolve(s)}_processOAuthPopupParams(e){var r;const t=this._oAuthDfd;if(this._oAuthDfd=null,t)if(clearInterval(this._oAuthIntervalId),(r=this._oAuthOnPopupHandle)==null||r.remove(),e.error){const i=e.error==="access_denied",s=new C(i?"identity-manager:user-aborted":"identity-manager:authentication-failed",i?"ABORTED":"OAuth: "+e.error+" - "+e.error_description);t.reject(s)}else this._processOAuthResponseParams(e,t.oinfo_,t.sinfo_).then(i=>{t.resolve(i)}).catch(i=>{t.reject(i)})}_setOAuthResponseQueryString(e){e&&(e.charAt(0)==="?"&&(e=e.substring(1)),this._processOAuthPopupParams(ce(e)))}_exchangeToken(e,t,r){return M(`${e}/sharing/rest/oauth2/exchangeToken`,{authMode:"anonymous",method:"post",query:{f:"json",client_id:t,token:r}}).then(i=>i.data.token)}_getPlatformSelf(e,t){return e=e.replace(/^http:/i,"https:"),M(`${e}/sharing/rest/oauth2/platformSelf`,{authMode:"anonymous",headers:{"X-Esri-Auth-Client-Id":t,"X-Esri-Auth-Redirect-Uri":window.location.href.replace(/#.*$/,"")},method:"post",query:{f:"json",expiration:30},withCredentials:!0}).then(r=>r.data)}_getPortalSelf(e,t){let r;return this._gwDomains.some(i=>(i.regex.test(e)&&(r=i.customBaseUrl),!!r)),r?Promise.resolve({allSSL:!0,currentVersion:"8.4",customBaseUrl:r,portalMode:"multitenant",supportsOAuth:!0}):(this._appOrigin.startsWith("https:")?e=e.replace(/^http:/i,"https:").replace(/:7080/i,":7443"):/^http:/i.test(t)&&(e=e.replace(/^https:/i,"http:").replace(/:7443/i,":7080")),M(e,{query:{f:"json"},authMode:"anonymous",withCredentials:!0}).then(i=>i.data))}_doPortalSignIn(e){const t=this._portalConfig,r=window.location.href,i=this.findServerInfo(e);return!(!t&&!this._isPortalDomain(r)||!(i?i.hasPortal||i.owningSystemUrl&&this._isPortalDomain(i.owningSystemUrl):this._isPortalDomain(e))||!(this._isIdProvider(r,e)||t&&(this._hasSameServerInstance(this._getServerInstanceRoot(t.restBaseUrl),e)||this._isIdProvider(t.restBaseUrl,e))||H(r,e,!0)))}_checkProtocol(e,t,r,i){let s=!0;const n=i?t.adminTokenServiceUrl:t.tokenServiceUrl;return n.trim().toLowerCase().startsWith("https:")&&!this._appOrigin.startsWith("https:")&&pt(n)&&(s=!!this._protocolFunc&&!!this._protocolFunc({resourceUrl:e,serverInfo:t}),!s)&&r(new C("identity-manager:aborted","Aborted the Sign-In process to avoid sending password over insecure connection.")),s}_enqueue(e,t,r,i,s,n){return i||(i=le()),i.resUrl_=e,i.sinfo_=t,i.options_=r,i.admin_=s,i.refresh_=n,this._busy?this._hasSameServerInstance(this._getServerInstanceRoot(e),this._busy.resUrl_)?(this._oAuthDfd&&this._oAuthDfd.oAuthWin_&&this._oAuthDfd.oAuthWin_.focus(),this._soReqs.push(i)):this._xoReqs.push(i):this._doSignIn(i),i.promise}_doSignIn(e){this._busy=e,this._rejectOnPersistedPageShow=!1;const t=a=>{var I;const p=(I=e.options_)==null?void 0:I.resource,f=e.resUrl_,c=e.refresh_;let v=!1;this.credentials.includes(a)||(c&&this.credentials.includes(c)?(c.userId=a.userId,c.token=a.token,c.expires=a.expires,c.validity=a.validity,c.ssl=a.ssl,c.creationTime=a.creationTime,v=!0,a=c):this.credentials.push(a)),a.resources||(a.resources=[]),a.resources.includes(p||f)||a.resources.push(p||f),a.scope=this._isServerRsrc(f)?"server":"portal",a.emitTokenChange();const b=this._soReqs,y={};this._soReqs=[],b.forEach(w=>{if(!this._isIdenticalService(f,w.resUrl_)){const B=this._getSuffix(w.resUrl_);y[B]||(y[B]=!0,a.resources.push(w.resUrl_))}}),e.resolve(a),b.forEach(w=>{this._hasSameServerInstance(this._getServerInstanceRoot(f),w.resUrl_)?w.resolve(a):this._soReqs.push(w)}),this._busy=e.resUrl_=e.sinfo_=e.refresh_=null,v||this.emit("credential-create",{credential:a}),this._soReqs.length?this._doSignIn(this._soReqs.shift()):this._xoReqs.length&&this._doSignIn(this._xoReqs.shift())},r=a=>{e.reject(a),this._busy=e.resUrl_=e.sinfo_=e.refresh_=null,this._soReqs.length?this._doSignIn(this._soReqs.shift()):this._xoReqs.length&&this._doSignIn(this._xoReqs.shift())},i=(a,p,f,c)=>{var B,ae,$;const v=e.sinfo_,b=!e.options_||e.options_.prompt!==!1,y=v.hasPortal&&this._findOAuthInfo(e.resUrl_);let I,w;if(a)t(new x({userId:a,server:v.server,token:f||null,expires:c!=null?Number(c):null,ssl:!!p}));else if(window!==window.parent&&((B=this._appUrlObj.query)!=null&&B["arcgis-auth-origin"])&&((ae=this._appUrlObj.query)!=null&&ae["arcgis-auth-portal"])&&this._hasSameServerInstance(this._getServerInstanceRoot(this._appUrlObj.query["arcgis-auth-portal"]),e.resUrl_)){window.parent.postMessage({type:"arcgis:auth:requestCredential"},this._appUrlObj.query["arcgis-auth-origin"]);const S=Te(window,"message",k=>{k.source===window.parent&&k.data&&(k.data.type==="arcgis:auth:credential"?(S.remove(),k.data.credential.expires<Date.now()?r(new C("identity-manager:credential-request-failed","Parent application's token has expired.")):t(new x(k.data.credential))):k.data.type==="arcgis:auth:error"&&(S.remove(),k.data.error.name==="tokenExpiredError"?r(new C("identity-manager:credential-request-failed","Parent application's token has expired.")):r(C.fromJSON(k.data.error))))});se(($=e.options_)==null?void 0:$.signal,()=>{S.remove()})}else if(y){let S=y._oAuthCred;if(!S){const k=new Ne(y,fe),A=new Ne(y,ve);k.isValid()&&A.isValid()?k.expires>A.expires?(S=k,A.destroy()):(S=A,k.destroy()):S=k.isValid()?k:A,y._oAuthCred=S}if(S.isValid()){I=new x({userId:S.userId,server:v.server,token:S.token,expires:S.expires,ssl:S.ssl,_oAuthCred:S});const k=y.appId!==S.appId&&this._doPortalSignIn(e.resUrl_);k||S.refreshToken?(e._pendingDfd=S.refreshToken?this._getOAuthToken(v.server,S.refreshToken,S.appId).then(A=>(I.expires=Date.now()+1e3*A.expires_in,I.token=A.access_token,I)):Promise.resolve(I),e._pendingDfd.then(A=>k?this._exchangeToken(A.server,y.appId,A.token).then(ye=>(A.token=ye,A)).catch(()=>A):A).then(A=>{t(A)}).catch(()=>{S==null||S.destroy(),i()})):t(I)}else if(this._oAuthLocationParams&&this._hasSameServerInstance(y.portalUrl,this._oAuthLocationParams.state.portalUrl)&&(this._oAuthLocationParams.access_token||this._oAuthLocationParams.code&&this._oAuthLocationParams.state.uid===S.stateUID&&S.codeVerifier)){const k=this._oAuthLocationParams;this._oAuthLocationParams=null,e._pendingDfd=this._processOAuthResponseParams(k,y,v).then(A=>{t(A)}).catch(r)}else{const k=()=>{b?e._pendingDfd=this.oAuthSignIn(e.resUrl_,v,y,e.options_).then(t,r):(w=new C("identity-manager:not-authenticated","User is not signed in."),r(w))};this._doPortalSignIn(e.resUrl_)?e._pendingDfd=this._getPlatformSelf(v.server,y.appId).then(A=>{H(A.portalUrl,this._appOrigin,!0)?(I=new x({userId:A.username,server:v.server,expires:Date.now()+1e3*A.expires_in,token:A.token}),t(I)):k()}).catch(k):k()}}else if(b){if(this._checkProtocol(e.resUrl_,v,r,e.admin_)){let S=e.options_;e.admin_&&(S=S||{},S.isAdmin=!0),e._pendingDfd=this.signIn(e.resUrl_,v,S).then(t,r)}}else w=new C("identity-manager:not-authenticated","User is not signed in."),r(w)},s=()=>{const a=e.sinfo_,p=a.owningSystemUrl,f=e.options_;let c,v,b,y;if(f&&(c=f.token,v=f.error,b=f.prompt),y=this._findCredential(p,{token:c,resource:e.resUrl_}),!y){for(const I of this.credentials)if(this._isIdProvider(p,I.server)){y=I;break}}if(y){const I=this.findCredential(e.resUrl_,y.userId);if(I)t(I);else if(Ee(a,this._legacyFed)){const w=y.toJSON();w.server=a.server,w.resources=null,t(new x(w))}else(e._pendingDfd=this.generateToken(this.findServerInfo(y.server),null,{serverUrl:e.resUrl_,token:y.token,signal:e.options_.signal,ssl:y.ssl})).then(w=>{t(new x({userId:y==null?void 0:y.userId,server:a.server,token:w.token,expires:w.expires!=null?Number(w.expires):null,ssl:!!w.ssl,isAdmin:e.admin_,validity:w.validity}))},r)}else this._busy=null,c&&(e.options_.token=null),(e._pendingDfd=this.getCredential(p.replace(/\/?$/,"/sharing"),{resource:e.resUrl_,owningTenant:a.owningTenant,signal:e.options_.signal,token:c,error:v,prompt:b})).then(()=>{this._enqueue(e.resUrl_,e.sinfo_,e.options_,e,e.admin_)},I=>{e.resUrl_=e.sinfo_=e.refresh_=null,e.reject(I)})};this._errbackFunc=r;const n=e.sinfo_.owningSystemUrl,l=this._isServerRsrc(e.resUrl_),d=e.sinfo_._restInfoPms;d?d.promise.then(a=>{const p=e.sinfo_;if(p._restInfoPms){p.adminTokenServiceUrl=p._restInfoPms.adminUrl,p._restInfoPms=null,p.tokenServiceUrl=(ue("authInfo.tokenServicesUrl",a)||ue("authInfo.tokenServiceUrl",a)||ue("tokenServiceUrl",a))??null,p.shortLivedTokenValidity=ue("authInfo.shortLivedTokenValidity",a)??null,p.currentVersion=a.currentVersion,p.owningTenant=a.owningTenant;const f=p.owningSystemUrl=a.owningSystemUrl;f&&this._portals.push(f)}l&&p.owningSystemUrl?s():i()},()=>{e.sinfo_._restInfoPms=null;const a=new C("identity-manager:server-identification-failed","Unknown resource - could not find token service endpoint.");r(a)}):l&&n?s():e.sinfo_._selfReq?e.sinfo_._selfReq.selfDfd.then(a=>{var y;const p={};let f,c,v,b;return a&&(f=(y=a.user)==null?void 0:y.username,p.username=f,p.allSSL=a.allSSL,c=a.supportsOAuth,b=parseFloat(a.currentVersion),a.portalMode==="multitenant"&&(v=a.customBaseUrl),e.sinfo_.currentVersion=b),e.sinfo_.webTierAuth=!!f,f&&this.normalizeWebTierAuth?this.generateToken(e.sinfo_,null,{ssl:p.allSSL}).catch(()=>null).then(I=>(p.portalToken=I&&I.token,p.tokenExpiration=I&&I.expires,p)):!f&&c&&b>=4.4&&!this._findOAuthInfo(e.resUrl_)?this._generateOAuthInfo({portalUrl:e.sinfo_.server,customBaseUrl:v,owningTenant:e.sinfo_._selfReq.owningTenant}).catch(()=>null).then(()=>p):p}).catch(()=>null).then(a=>{e.sinfo_._selfReq=null,a?i(a.username,a.allSSL,a.portalToken,a.tokenExpiration):i()}):i()}_generateOAuthInfo(e){let t,r=null,i=e.portalUrl;const s=e.customBaseUrl,n=e.owningTenant,l=!this._defaultOAuthInfo&&this._createDefaultOAuthInfo&&!this._hasTestedIfAppIsOnPortal;if(l){r=window.location.href;let d=r.indexOf("?");d>-1&&(r=r.slice(0,d)),d=r.search(/\/(apps|home)\//),r=d>-1?r.slice(0,d):null}return l&&r?(this._hasTestedIfAppIsOnPortal=!0,t=M(r+"/sharing/rest",{query:{f:"json"}}).then(()=>{this._defaultOAuthInfo=new Je({appId:"arcgisonline",popupCallbackUrl:r+"/home/oauth-callback.html"})})):t=Promise.resolve(),t.then(()=>{if(this._defaultOAuthInfo)return i=i.replace(/^http:/i,"https:"),M(i+"/sharing/rest/oauth2/validateRedirectUri",{query:{accountId:n,client_id:this._defaultOAuthInfo.appId,redirect_uri:Le(this._defaultOAuthInfo.popupCallbackUrl),f:"json"}}).then(d=>{if(d.data.valid){const a=this._defaultOAuthInfo.clone();d.data.urlKey&&s?a.portalUrl="https://"+d.data.urlKey.toLowerCase()+"."+s:a.portalUrl=i,a.popup=window!==window.top||!(H(i,this._appOrigin)||this._gwDomains.some(p=>p.regex.test(i)&&p.regex.test(this._appOrigin))),this.oAuthInfos.push(a)}})})}_doOAuthSignIn(e,t,r,i){const s=r._oAuthCred,n={portalUrl:r.portalUrl};!r.popup&&r.preserveUrlHash&&window.location.hash&&(n.hash=window.location.hash),s.stateUID&&(n.uid=s.stateUID);const l={client_id:r.appId,response_type:s.codeVerifier?"code":"token",state:JSON.stringify(n),expiration:r.expiration,locale:r.locale,redirect_uri:this._getRedirectURI(r,!!s.codeVerifier)};r.forceLogin&&(l.force_login=!0),r.forceUserId&&r.userId&&(l.prepopulatedusername=r.userId),!r.popup&&this._doPortalSignIn(e)&&(l.redirectToUserOrgUrl=!0),s.codeVerifier&&(l.code_challenge=i||s.codeVerifier,l.code_challenge_method=i?"S256":"plain");const d=r.portalUrl.replace(/^http:/i,"https:")+"/sharing/oauth2/authorize",a=d+"?"+qe(l);if(r.popup){const p=window.open(a,"esriJSAPIOAuth",r.popupWindowFeatures);if(p)p.focus(),this._oAuthDfd.oAuthWin_=p,this._oAuthIntervalId=setInterval(()=>{if(p.closed){clearInterval(this._oAuthIntervalId),this._oAuthOnPopupHandle.remove();const f=this._oAuthDfd;if(f){const c=new C("identity-manager:user-aborted","ABORTED");f.reject(c)}}},500),this._oAuthOnPopupHandle=Te(window,["arcgis:auth:hash","arcgis:auth:location:search"],f=>{f.type==="arcgis:auth:hash"?this.setOAuthResponseHash(f.detail):this._setOAuthResponseQueryString(f.detail)});else{const f=new C("identity-manager:popup-blocked","ABORTED");this._oAuthDfd.reject(f)}}else this._rejectOnPersistedPageShow=!0,this._oAuthRedirectFunc?this._oAuthRedirectFunc({authorizeParams:l,authorizeUrl:d,resourceUrl:e,serverInfo:t,oAuthInfo:r}):window.location.href=a}_getRedirectURI(e,t){const r=window.location.href.replace(/#.*$/,"");if(e.popup)return Le(e.popupCallbackUrl);if(t){const i=ke(r);return i.query&&["code","error","error_description","message_code","persist","state"].forEach(s=>{delete i.query[s]}),ft(i.path,i.query)}return r}}ot.prototype.declaredClass="esri.identity.IdentityManagerBase";let x=class extends Ze.EventedAccessor{constructor(o){super(o),this._oAuthCred=null,this.tokenRefreshBuffer=2,o!=null&&o._oAuthCred&&(this._oAuthCred=o._oAuthCred)}initialize(){this.resources=this.resources||[],this.creationTime==null&&(this.creationTime=Date.now())}refreshToken(){const o=R.findServerInfo(this.server),e=o==null?void 0:o.owningSystemUrl,t=!!e&&this.scope==="server",r=t&&Ee(o,R._legacyFed),i=o.webTierAuth,s=i&&R.normalizeWebTierAuth,n=pe[this.server],l=n==null?void 0:n[this.userId];let d,a=this.resources&&this.resources[0],p=t?R.findServerInfo(e):null,f={username:this.userId,password:l};if(i&&!s)return;t&&!p&&R.serverInfos.some(v=>(R._isIdProvider(e,v.server)&&(p=v),!!p));const c=p?R.findCredential(p.server,this.userId):null;if(!t||c){if(!r){if(t)d={serverUrl:a,token:c==null?void 0:c.token,ssl:c&&c.ssl};else if(s)f=null,d={ssl:this.ssl};else{if(!l){let v;return a&&(a=R._sanitizeUrl(a),this._enqueued=1,v=R._enqueue(a,o,null,null,this.isAdmin,this),v.then(()=>{this._enqueued=0,this.refreshServerTokens()}).catch(()=>{this._enqueued=0})),v}this.isAdmin&&(d={isAdmin:!0})}return R.generateToken(t?p:o,t?null:f,d).then(v=>{this.token=v.token,this.expires=v.expires!=null?Number(v.expires):null,this.creationTime=Date.now(),this.validity=v.validity,this.emitTokenChange(),this.refreshServerTokens()}).catch(()=>{})}c==null||c.refreshToken()}}refreshServerTokens(){this.scope==="portal"&&R.credentials.forEach(o=>{const e=R.findServerInfo(o.server),t=e==null?void 0:e.owningSystemUrl;o!==this&&o.userId===this.userId&&t&&o.scope==="server"&&(R._hasSameServerInstance(this.server,t)||R._isIdProvider(t,this.server))&&(Ee(e,R._legacyFed)?(o.token=this.token,o.expires=this.expires,o.creationTime=this.creationTime,o.validity=this.validity,o.emitTokenChange()):o.refreshToken())})}emitTokenChange(o){clearTimeout(this._refreshTimer);const e=this.server?R.findServerInfo(this.server):null,t=e==null?void 0:e.owningSystemUrl,r=t?R.findServerInfo(t):null;o===!1||t&&this.scope!=="portal"&&(!(r!=null&&r.webTierAuth)||R.normalizeWebTierAuth)||this.expires==null&&this.validity==null||this._startRefreshTimer(),this.emit("token-change")}destroy(){this.userId=this.server=this.token=this.expires=this.validity=this.resources=this.creationTime=null,this._oAuthCred&&(this._oAuthCred.destroy(),this._oAuthCred=null);const o=R.credentials.indexOf(this);o>-1&&R.credentials.splice(o,1),this.emitTokenChange(),this.emit("destroy")}toJSON(){const o=Qe({userId:this.userId,server:this.server,token:this.token,expires:this.expires,validity:this.validity,ssl:this.ssl,isAdmin:this.isAdmin,creationTime:this.creationTime,scope:this.scope}),e=this.resources;return e&&e.length>0&&(o.resources=e.slice()),o}_startRefreshTimer(){clearTimeout(this._refreshTimer);const o=6e4*this.tokenRefreshBuffer,e=2**31-1;let t=(this.validity?this.creationTime+6e4*this.validity:this.expires)-Date.now();t<0?t=0:t>e&&(t=e),this._refreshTimer=setTimeout(this.refreshToken.bind(this),t>o?t-o:t)}};m([_()],x.prototype,"creationTime",void 0),m([_()],x.prototype,"expires",void 0),m([_()],x.prototype,"isAdmin",void 0),m([_()],x.prototype,"oAuthState",void 0),m([_()],x.prototype,"resources",void 0),m([_()],x.prototype,"scope",void 0),m([_()],x.prototype,"server",void 0),m([_()],x.prototype,"ssl",void 0),m([_()],x.prototype,"token",void 0),m([_()],x.prototype,"tokenRefreshBuffer",void 0),m([_()],x.prototype,"userId",void 0),m([_()],x.prototype,"validity",void 0),x=m([oe("esri.identity.Credential")],x);class at extends ot{}at.prototype.declaredClass="esri.identity.IdentityManager";const Ht=new at;vt(Ht);export{Ht as default};
|