@arcgis/core 5.0.0-next.44 → 5.0.0-next.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/bf5f9da0837ed09729c6.js +316 -0
  3. package/assets/esri/core/workers/chunks/{7c08c0824ad354177787.js → d7878fba02814adaf19f.js} +1 -1
  4. package/chunks/GaussianSplat.glsl.js +2 -2
  5. package/config.js +1 -1
  6. package/core/urlUtils.d.ts +1 -0
  7. package/core/workers/workerFactory.js +1 -1
  8. package/interfaces.d.ts +26 -7
  9. package/kernel.js +1 -1
  10. package/package.json +2 -2
  11. package/rest/print.js +1 -1
  12. package/rest/support/LegendLayer.js +1 -1
  13. package/support/revision.js +1 -1
  14. package/views/3d/analysis/ShadowCastAnalysisView3D.js +1 -1
  15. package/views/3d/layers/graphics/pipeline/rendering/DirectRenderer.js +1 -1
  16. package/views/3d/layers/graphics/pipeline/rendering/RenderCommandContext.js +1 -1
  17. package/views/3d/layers/graphics/pipeline/symbolization/IconSymbolLayerRenderer.js +1 -1
  18. package/views/3d/webgl-engine/lib/GaussianSplatRenderNode.js +1 -1
  19. package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
  20. package/views/3d/webgl-engine/materials/HeatmapDensityMaterial.js +1 -1
  21. package/views/3d/webgl-engine/materials/renderers/MergedBuffer.js +1 -1
  22. package/views/3d/webgl-engine/materials/renderers/PerBufferData.js +1 -1
  23. package/views/3d/webgl-engine/materials/renderers/PerOriginData.js +1 -1
  24. package/views/3d/webgl-engine/materials/renderers/VaoWriter.js +1 -1
  25. package/views/3d/webgl-engine/shaders/GaussianSplatColorTechnique.js +5 -0
  26. package/views/3d/webgl-engine/shaders/GaussianSplatDepthTechnique.js +5 -0
  27. package/views/3d/webgl-engine/shaders/GaussianSplatTechniqueConfiguration.js +1 -1
  28. package/widgets/FeatureTable/AttachmentsColumn.js +1 -1
  29. package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
  30. package/widgets/FeatureTable/Grid/Column.js +1 -1
  31. package/widgets/FeatureTable/Grid/EditorColumn.js +1 -1
  32. package/widgets/FeatureTable/Grid/Grid.js +1 -1
  33. package/widgets/FeatureTable/Grid/GridViewModel.js +1 -1
  34. package/widgets/FeatureTable/support/FeatureStore.js +1 -1
  35. package/widgets/Print/CustomTemplate.js +1 -1
  36. package/widgets/Print/PrintViewModel.js +1 -1
  37. package/widgets/Print/TemplateOptions.js +1 -1
  38. package/widgets/Print.js +1 -1
  39. package/assets/esri/core/workers/chunks/ea3cba01c60d9bc72719.js +0 -316
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as t}from"tslib";import{id as o}from"../../kernel.js";import e from"../../core/Error.js";import{JSONSupport as r}from"../../core/JSONSupport.js";import{createMD5Hash as s}from"../../core/MD5.js";import{isAbortError as a}from"../../core/promiseUtils.js";import{property as i,subclass as n}from"../../core/accessorSupport/decorators.js";import l from"../../portal/PortalItem.js";import{formatJsonMap as p}from"../../rest/support/fileFormat.js";import{fromJSON as u}from"../../rest/support/layoutTemplate.js";import{valueUnitKebabDict as m,fetchLayoutTemplateInfos as y}from"./utils.js";import{enumeration as d}from"../../core/accessorSupport/decorators/enumeration.js";let h=class extends r{constructor(t){super(t),this.description=null,this.format=null,this.state="not-loaded",this.label=null,this.layoutInfoTaskUrl=null,this.layout=null,this.layoutItem=null,this.layoutOptions=null,this.layoutTemplateInfo=null,this.type=null}get id(){return this.layoutItem?.id??`${this.layout}-${s(JSON.stringify(this.toJSON()))}`}get mapSurroundInfoOptions(){const t=this.layoutTemplateInfo?.layoutOptions?.mapSurroundInfos;if(!t)return null;const o={northArrow:[],scaleBar:[],legend:[]};for(const e of t)switch(e.type){case"CIMMarkerNorthArrow":o.northArrow.push(e);break;case"CIMScaleLine":o.scaleBar.push(e);break;case"CIMGroupElement":e.elements?.some(t=>"CIMScaleLine"===t.type)&&o.scaleBar.push(e);break;case"CIMLegend":o.legend.push(e)}return o}get pageUnits(){return m.fromJSON(this.layoutTemplateInfo?.pageUnits?.toLowerCase())}_updateLayoutOptions(t){const o=this.layoutOptions?.legend??t.layoutOptions?.hasLegend,e=this.layoutOptions?.northArrow??(this.mapSurroundInfoOptions?.northArrow.length?this.mapSurroundInfoOptions?.northArrow.some(({visible:t})=>t):void 0),r=this.layoutOptions?.scaleBar??(this.mapSurroundInfoOptions?.scaleBar.length?this.mapSurroundInfoOptions?.scaleBar.some(({visible:t})=>t):void 0);this._set("layoutOptions",{legend:o,northArrow:e,scaleBar:r})}async fetchLayoutItemTemplateInfo(t){const{layoutItem:r}=this;if(r?.id&&!this.layoutTemplateInfo&&"loaded"!==this.state)try{this._set("state","loading");const s=this.layoutInfoTaskUrl;if(!s)throw new e("print:invalid-layout-info-task-url","Can't fetch layout template info",{url:s});"public"!==r.access&&o&&await o.getCredential(s);const a={Layout_Item_ID:JSON.stringify({id:r.id})},i=(await y(s,a,t))[0];this.setLayoutTemplateInfo(i)}catch(s){this._set("state",a(s)?"not-loaded":"error")}}setLayoutTemplateInfo(t){this._set("layoutTemplateInfo",t),this._updateLayoutOptions(t),this._set("state","loaded")}};t([i({json:{write:!0}})],h.prototype,"description",void 0),t([d(p)],h.prototype,"format",void 0),t([i({readOnly:!0})],h.prototype,"id",null),t([i({readOnly:!0})],h.prototype,"state",void 0),t([i({json:{write:!0}})],h.prototype,"label",void 0),t([i()],h.prototype,"layoutInfoTaskUrl",void 0),t([i({json:{read:u,write:!0}})],h.prototype,"layout",void 0),t([i({type:l,json:{write:!0}})],h.prototype,"layoutItem",void 0),t([i({readOnly:!0,json:{write:!0}})],h.prototype,"layoutOptions",void 0),t([i({readOnly:!0})],h.prototype,"layoutTemplateInfo",void 0),t([i({readOnly:!0})],h.prototype,"mapSurroundInfoOptions",null),t([i({readOnly:!0})],h.prototype,"pageUnits",null),t([i()],h.prototype,"type",void 0),h=t([n("esri.widgets.Print.CustomTemplate")],h);const c=h;export{c as default};
5
+ import{__decorate as t}from"tslib";import{id as o}from"../../kernel.js";import e from"../../core/Error.js";import{JSONSupport as r}from"../../core/JSONSupport.js";import{createMD5Hash as s}from"../../core/MD5.js";import{isAbortError as a}from"../../core/promiseUtils.js";import{property as n,subclass as i}from"../../core/accessorSupport/decorators.js";import l from"../../portal/PortalItem.js";import{formatJsonMap as p}from"../../rest/support/fileFormat.js";import{fromJSON as u}from"../../rest/support/layoutTemplate.js";import{valueUnitKebabDict as d,fetchLayoutTemplateInfos as m}from"./utils.js";import{enumeration as y}from"../../core/accessorSupport/decorators/enumeration.js";let h=class extends r{constructor(t){super(t),this.description=null,this.format=null,this.state="not-loaded",this.label=null,this.layoutInfoTaskUrl=null,this.layout=null,this.layoutItem=null,this.layoutOptions=null,this.layoutTemplateInfo=null,this.type=null}get id(){return this.layoutItem?.id??`${this.layout}-${s(JSON.stringify(this.toJSON()))}`}get mapSurroundInfoOptions(){const t=this.layoutTemplateInfo?.layoutOptions?.mapSurroundInfos;if(!t)return null;const o={northArrow:[],scaleBar:[],legend:[]};for(const e of t)switch(e.type){case"CIMMarkerNorthArrow":o.northArrow.push(e);break;case"CIMScaleLine":o.scaleBar.push(e);break;case"CIMGroupElement":e.elements?.some(t=>"CIMScaleLine"===t.type)&&o.scaleBar.push(e);break;case"CIMLegend":o.legend.push(e)}return o}get pageUnits(){return d.fromJSON(this.layoutTemplateInfo?.pageUnits?.toLowerCase())}_updateLayoutOptions(t){const o=this.layoutOptions?.legend??t.layoutOptions?.hasLegend,e=this.layoutOptions?.dynamicLegend??(this.mapSurroundInfoOptions?.legend.length?this.mapSurroundInfoOptions?.legend.some(({defaultLegendItem:t})=>t?.dynamicLegends):void 0),r=this.layoutOptions?.northArrow??(this.mapSurroundInfoOptions?.northArrow.length?this.mapSurroundInfoOptions?.northArrow.some(({visible:t})=>t):void 0),s=this.layoutOptions?.scaleBar??(this.mapSurroundInfoOptions?.scaleBar.length?this.mapSurroundInfoOptions?.scaleBar.some(({visible:t})=>t):void 0);this._set("layoutOptions",{legend:o,northArrow:r,scaleBar:s,dynamicLegend:e})}async fetchLayoutItemTemplateInfo(t){const{layoutItem:r}=this;if(r?.id&&!this.layoutTemplateInfo&&"loaded"!==this.state)try{this._set("state","loading");const s=this.layoutInfoTaskUrl;if(!s)throw new e("print:invalid-layout-info-task-url","Can't fetch layout template info",{url:s});"public"!==r.access&&o&&await o.getCredential(s);const a={Layout_Item_ID:JSON.stringify({id:r.id})},n=(await m(s,a,t))[0];this.setLayoutTemplateInfo(n)}catch(s){this._set("state",a(s)?"not-loaded":"error")}}setLayoutTemplateInfo(t){this._set("layoutTemplateInfo",t),this._updateLayoutOptions(t),this._set("state","loaded")}};t([n({json:{write:!0}})],h.prototype,"description",void 0),t([y(p)],h.prototype,"format",void 0),t([n({readOnly:!0})],h.prototype,"id",null),t([n({readOnly:!0})],h.prototype,"state",void 0),t([n({json:{write:!0}})],h.prototype,"label",void 0),t([n()],h.prototype,"layoutInfoTaskUrl",void 0),t([n({json:{read:u,write:!0}})],h.prototype,"layout",void 0),t([n({type:l,json:{write:!0}})],h.prototype,"layoutItem",void 0),t([n({readOnly:!0,json:{write:!0}})],h.prototype,"layoutOptions",void 0),t([n({readOnly:!0})],h.prototype,"layoutTemplateInfo",void 0),t([n({readOnly:!0})],h.prototype,"mapSurroundInfoOptions",null),t([n({readOnly:!0})],h.prototype,"pageUnits",null),t([n()],h.prototype,"type",void 0),h=t([i("esri.widgets.Print.CustomTemplate")],h);const c=h;export{c as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as t}from"tslib";import{isSome as e}from"../../core/arrayUtils.js";import s from"../../core/Collection.js";import i from"../../core/Error.js";import{EventedAccessor as o}from"../../core/Evented.js";import{clone as a}from"../../core/lang.js";import{LoadableMixin as r}from"../../core/Loadable.js";import{EsriPromiseMixin as l}from"../../core/Promise.js";import n from"../../core/ReactiveMap.js";import{watch as p,initial as m}from"../../core/reactiveUtils.js";import{createScreenPoint as h}from"../../core/screenUtils.js";import{unitType as d,convertUnit as u,getMetersPerUnitForSR as c,inchesPerMeter as f}from"../../core/units.js";import{property as y,subclass as T}from"../../core/accessorSupport/decorators.js";import v from"../../geometry/Extent.js";import w from"../../geometry/SpatialReference.js";import{formatDate as _,convertDateFormatToIntlOptions as I}from"../../intl/date.js";import{getLocaleLanguage as g}from"../../intl/locale.js";import x from"../../portal/Portal.js";import O from"../../portal/PortalQueryParams.js";import{reArcGISOnlineDomain as b}from"../../portal/support/urlUtils.js";import{execute as E,getTaskInfo as P}from"../../rest/print.js";import{formatJsonMap as L}from"../../rest/support/fileFormat.js";import{fromJSON as S}from"../../rest/support/layoutTemplate.js";import U from"../../rest/support/PrintParameters.js";import k from"../../rest/support/PrintTemplate.js";import{getExtent as C}from"../../views/2d/viewpointUtils.js";import{ViewEventPriorities as j}from"../../views/input/InputManager.js";import F from"../../views/overlay/BoxOverlayItem.js";import H from"./CustomTemplate.js";import M from"./FileLink.js";import D from"./TemplateOptions.js";import{fetchLayoutTemplateInfos as A,valueUnitKebabDict as W}from"./utils.js";const R=[30,144,255,255],N=[237,211,23,255],z=[216,48,32,255],V=new Set(["GISProfessionalStdUT","GISProfessionalAdvUT"]),B=/(\/GPServer\/).+/i,G=96,q=s.ofType(H),$=s.ofType(M);function J(t){t.layoutOptions??={},t.layoutOptions.customTextElements??=[];const e="date";if(!t.layoutOptions.customTextElements.find(t=>e in t)){const{customTextElements:e}=t.layoutOptions;let s=_(Date.now(),I("short-date"));"ar"===g()&&(s="‏"+s),e.push({date:s})}}function Q(t,e,s){if(!e)return;!(e.visible===s)&&t.layoutOptions&&(t.layoutOptions.elementOverrides?t.layoutOptions.elementOverrides[e.name]={visible:s}:t.layoutOptions.elementOverrides={[e.name]:{visible:s}})}let K=class extends(r(l(o))){constructor(t){super(t),this._serviceTemplateCustomTextElements=null,this._templateIdToCustomTemplate=new n,this._isFreeHand=!1,this._freeHandWidth=0,this._freehandHeight=0,this._asyncPrintTaskUrl=null,this._layoutInfoTaskUrl=null,this._portalLayoutInfoTaskUrl=null,this._customLayoutOptions=null,this._exportedFileNameMap={},this._layoutTemplateInfosCache=new Map,this._tasksInfoCache=new Map,this.allowedFormats="all",this.allowedLayouts="all",this.browseTemplates=new q,this.defaultTemplates=new q,this.error=null,this.exportedLinks=new $,this.extraParameters=null,this.includeDefaultTemplates=!0,this.outSpatialReference=null,this.portal=x.getDefault(),this.portalTemplateIds=[],this.printServiceTemplates=new q,this.defaultTemplate=null,this.showPrintAreaEnabled=!1,this.printServiceUrl=null,this.printTimeout=12e4,this.saveExportEnabled=!1,this.templatesInfo=null,this.updateDelay=1e3,this.view=null,this.templateCustomTextElements=null,this.templateOptions=new D}initialize(){this.addHandles([p(()=>[this.showPrintAreaEnabled,this.view],()=>{this.showPrintAreaEnabled?this._enablePrintPreview():(this.removeHandles("overlay-handler"),this.view?.overlay?.removeItem(this._getOverlayItem()))}),p(()=>[this.templateOptions.layout,this.templateOptions.layoutItem],()=>{this.loaded&&this._processTemplateOptions()}),p(()=>[this.allowedFormats,this.allowedLayouts],()=>{this.loaded&&this._loadTemplateInfos()}),p(()=>this.exportedLinks,()=>{for(const{name:t,extension:e}of this.exportedLinks)t&&e&&this._updateExportedFileNameMap(`${t}${e}`)},m)])}destroy(){this.removeHandles("overlay-handler"),this.view&&(this._overlayItem&&(this.view.overlay?.removeItem(this._overlayItem),this._overlayItem.destroy(),this._overlayItem=null),this.view=null)}get effectivePrintServiceUrl(){return this.printServiceUrl??null}get effectiveTemplateCustomTextElements(){if(!this._serviceTemplateCustomTextElements)return{};const t=a(this._serviceTemplateCustomTextElements);return this.templateCustomTextElements&&Object.keys(this.templateCustomTextElements).forEach(e=>{const s=t[e];if(s){const t=this.templateCustomTextElements?.[e];s.forEach(e=>{const[s]=Object.entries(e)[0];t?.forEach(t=>{const[i,o]=Object.entries(t)[0];s===i&&(e[s]=o)})})}}),Object.freeze(t)}get state(){return"loading"===this.loadStatus?"initializing":"failed"===this.loadStatus||this.error?"error":"loaded"===this.loadStatus&&this.view?.ready?"ready":"disabled"}async print(t){const{view:e,extraParameters:s,updateDelay:o,outSpatialReference:a}=this;if(!e)throw new i("print:view-required","view is not set");J(t);const r=this._getOverlayItem(),l=t.scalePreserved||!this.showPrintAreaEnabled?void 0:C(new v,e.viewpoint,"map-only"===t.layout?[t.exportOptions.width,t.exportOptions.height]:[r.boxWidth,r.boxHeight]),n=new U({view:e,template:t,extent:l,extraParameters:s,updateDelay:o,outSpatialReference:a});try{const e=!!t.layoutItem?.id&&(this.portalTemplateIds.includes(t.layoutItem.id)||this.browseTemplates.some(e=>e.layoutItem?.id===t.layoutItem?.id));return await E(e&&this._asyncPrintTaskUrl?this._asyncPrintTaskUrl:this.effectivePrintServiceUrl,n,{timeout:this.printTimeout})}catch(p){throw new i("print:export-error","An error occurred while exporting the web map.",{error:p})}}async load(t){return this.addResolvingPromise(this._loadResources(t).catch(t=>this.error=t)),this}toPrintTemplate({attributionEnabled:t,author:e,copyright:s,customTextElements:o,dpi:a,forceFeatureAttributes:r,format:l,height:n,id:p,includeTables:m,layout:h,layoutItem:d,legendEnabled:u,northArrowEnabled:c,scale:f,scaleBarEnabled:y,scaleEnabled:T,title:v,width:w}){if(!h&&!d)throw new i("print:layout-required","layout is not set");const _=new k({attributionVisible:t,forceFeatureAttributes:r,format:l,includeTables:m,layout:h,layoutItem:d,layoutOptions:{authorText:e||"",copyrightText:s||"",customTextElements:o,titleText:v||""},outScale:f??0,scalePreserved:T});if(w&&(_.exportOptions.width=w),n&&(_.exportOptions.height=n),a&&(_.exportOptions.dpi=a),_.layoutOptions){u||(_.layoutOptions.legendLayers=[]);const t=this.getLayoutTemplateById(p)?.mapSurroundInfoOptions;if(t){const e=t.northArrow;for(const t of e)Q(_,t,c);const s=t.scaleBar;for(const t of s)Q(_,t,y);const i=t.legend;for(const t of i)Q(_,t,u)}}return _}getLayoutTemplateById(t){return t?this._templateIdToCustomTemplate.get(t):null}async addPortalTemplate(t){if(!this.portal||!t?.id)return;try{t.loaded||await t.load()}catch{return void this.applyTemplate(this.defaultTemplate)}const e=new H({type:"browse-template",layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl,label:t.title,layoutItem:t});this._templateIdToCustomTemplate.set(e.id,e),this.browseTemplates.add(e)}removePortalTemplate(t){t.layoutItem&&this.templateOptions.id===t.layoutItem.id&&(this.defaultTemplate?this.applyTemplate(this.defaultTemplate):this.templateOptions.reset()),this.browseTemplates.remove(t),this._templateIdToCustomTemplate.delete(t.id)}async applyTemplate(t){if(t&&t===this.getLayoutTemplateById(this.templateOptions.id))return;if(this.templateOptions.reset(),!t)return;if("map-only"===t)return void(this.templateOptions.layout="map-only");!t.layout||!this.templatesInfo||this.templatesInfo.layout.choiceList.includes(t.layout)||(this.defaultTemplate?t=this.defaultTemplate:this.templateOptions.reset());const e=t.layout||t.layoutItem?.id,s=e?this.templateCustomTextElements?.[e]:void 0;if(await this.templateOptions.applyTemplate(t,{customTextElements:s,customLayoutOptions:this._customLayoutOptions}),e&&this._serviceTemplateCustomTextElements&&!this._serviceTemplateCustomTextElements[e]&&t.layoutTemplateInfo?.layoutOptions?.customTextElements){const s=a(this._serviceTemplateCustomTextElements);s[e]=t.layoutTemplateInfo.layoutOptions.customTextElements,this._serviceTemplateCustomTextElements=Object.freeze(s)}}createExportedFileLink(t){const e=this.toPrintTemplate(this.templateOptions).format.toLowerCase(),s=e.includes("png")?"png":e,i=t+s;return this._updateExportedFileNameMap(i),new M({name:t,extension:s,count:this._exportedFileNameMap[i]})}export(t){const e=this.createExportedFileLink(t);this.exportedLinks.add(e);const s=this.print(this.toPrintTemplate(this.templateOptions)).then(t=>e.set({url:t?.url,state:"ready"})).catch(t=>e.set({error:t,state:"error"}));return this.emit("submit",{link:e,saveExportEnabled:this.saveExportEnabled}),s.then(t=>this.emit("complete",{link:t,saveExportEnabled:this.saveExportEnabled})),{link:e,promise:s}}async _loadResources(t){this.destroyed||(await this._loadUrls(t),await this._loadTemplateInfos(t),this._updateOverLayItem())}async _loadTemplateInfos(t){const e=[...this.defaultTemplates,...this.printServiceTemplates];for(const{id:o}of e)this._templateIdToCustomTemplate.delete(o);this.defaultTemplates.removeAll(),this.printServiceTemplates.removeAll();const[s,i]=await Promise.all([this._getLayoutToLayoutTemplateInfos(t),this._getPrintServiceTemplatesInfo(t)]);await this._loadAllTemplates(s,i,t),this._processPrintServiceTemplatesInfo(i),await this._processTemplateOptions()}_updateExportedFileNameMap(t){void 0!==this._exportedFileNameMap[t]?this._exportedFileNameMap[t]++:this._exportedFileNameMap[t]=0}async _processTemplateOptions(){const{layout:t,layoutItem:e}=this.templateOptions;if("map-only"!==t)if(this._customLayoutOptions={legend:this.templateOptions.legendEnabled,northArrow:this.templateOptions.northArrowEnabled,scaleBar:this.templateOptions.scaleBarEnabled},e?.id){try{e.loaded||await e.load()}catch{return void this.applyTemplate(this.defaultTemplate)}let t=this._templateIdToCustomTemplate.get(e.id);t||(t=new H({label:e.title,layoutItem:e,layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl}),this._templateIdToCustomTemplate.set(t.id,t)),await this.applyTemplate(t)}else if(t){const t=this.defaultTemplates.find(t=>t.layout===this.templateOptions.layout)??this.printServiceTemplates.find(t=>t.layout===this.templateOptions.layout);await this.applyTemplate(t??this.defaultTemplate)}}async _loadPortal(t){try{await this.portal.load(t)}catch(e){throw new i("print:could-not-load-portal","Cannot load print resource information from portal",{error:e,url:this.effectivePrintServiceUrl})}}async _loadUrls(t){if(this.printServiceUrl)this._set("effectivePrintServiceUrl",this.printServiceUrl),this._layoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(this.effectivePrintServiceUrl,t);else{await this._loadPortal(t);const{printTask:e,asyncPrintTask:s,layoutInfoTask:i}=this.portal?.helperServices??{};this._set("effectivePrintServiceUrl",e?.url),this._asyncPrintTaskUrl=s?.url,this._layoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(this.effectivePrintServiceUrl,t),i?.url&&this.effectivePrintServiceUrl!==i.url?this._portalLayoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(i.url,t):this._portalLayoutInfoTaskUrl=this._layoutInfoTaskUrl}const e=this.effectivePrintServiceUrl?.toLowerCase().split("/");if(!e?.includes("gpserver"))throw new i("print:invalid-print-service-url","Can't fetch print templates information from provided URL",{url:this.effectivePrintServiceUrl})}async _getLayoutInfoTaskUrl(t,e){if(!t)return null;const s=await P(t,"GetLayoutTemplatesInfo",e);return s?t.replace(B,`$1${encodeURI(s.displayName)}`):null}_getPortalDefaultTemplates(t,e){return this.portal?.helperServices?.printTask?.templates?.filter(t=>"map_only"!==t.layout.toLowerCase()&&(!e||e.includes(S(t.layout))))?.map(e=>{const s=H.fromJSON(e);if(s.type="default-template",s.layoutInfoTaskUrl=this._layoutInfoTaskUrl,s.layout){const e=t.get(s.layout);e&&s.setLayoutTemplateInfo(e)}return s})??[]}async _getPortalCustomTemplates(t){if(this.printServiceUrl||!this.portal)return[];const{layoutGroupQuery:e,user:s}=this.portal,i=b.test(this.portal.url),o=s?.userLicenseTypeId,a=o&&V.has(o);if(!e||i&&!a)return[];const r=new O({query:e,disableExtraQuery:!0}),l=await this.portal.queryGroups(r,t);if(!l.total)return[];const n=l.results[0],p=new O({num:100,query:"type:Layout",sortField:n.sortField,sortOrder:n.sortOrder??void 0}),m=(await n.queryItems(p,t)).results;if(!m.length)return[];return m.map(t=>(this.portalTemplateIds.push(t.id),new H({type:"default-template",label:t.title,layoutItem:t,layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl})))}async _loadAllTemplates(t,e,s){let i=!1;const o=e?.layout?.choiceList;if(this.includeDefaultTemplates&&this.portal&&!this.printServiceUrl){const e=this._getPortalDefaultTemplates(t,o);i=!!e.length,this.defaultTemplates.addMany(e);const a=await this._getPortalCustomTemplates(s);this.defaultTemplates.addMany(a);for(const t of this.defaultTemplates)this._templateIdToCustomTemplate.set(t.id,t)}i||t.forEach((t,e)=>{if(!o||o.includes(e)){const s=new H({type:"print-service-template",layout:e,layoutInfoTaskUrl:this._layoutInfoTaskUrl});s.setLayoutTemplateInfo(t),this.printServiceTemplates.add(s),this._templateIdToCustomTemplate.set(s.id,s)}})}_processPrintServiceTemplatesInfo(t){this._set("templatesInfo",t);const e=t?.layout?.defaultValue;if(e&&"map-only"!==e){const t=this.defaultTemplates.find(t=>t.layout===e)??this.printServiceTemplates.find(t=>t.layout===e)??this.defaultTemplates.at(0)??this.printServiceTemplates.at(0);this._set("defaultTemplate",t)}}async _getLayoutToLayoutTemplateInfos(t){const e=this._layoutInfoTaskUrl,s=e?this._layoutTemplateInfosCache.get(e):void 0,i=s??await A(e,void 0,t);s||this._layoutTemplateInfosCache.set(e,i);const o=new Map,a={};for(const r of i){const t=S(r.layoutTemplate);o.set(t,r),a[t]=r.layoutOptions.customTextElements}return this._serviceTemplateCustomTextElements=Object.freeze(a),o}async _getPrintServiceTemplatesInfo(t){const e=this.effectivePrintServiceUrl?this._tasksInfoCache.get(this.effectivePrintServiceUrl):void 0,s=e??await P(this.effectivePrintServiceUrl,"ExportWebMap",t);if(!s)throw new i("print:unavailable-service-info","Can't fetch templates info from service");e||this._tasksInfoCache.set(this.effectivePrintServiceUrl,s);const{parameters:o}=s,a=o.find(({name:t})=>"Format"===t),r=o.find(({name:t})=>"Layout_Template"===t);return{format:this._getFormat(a),layout:this._getLayout(r)}}_getFormat(t){const s="all"===this.allowedFormats?t.choiceList:t.choiceList.filter(t=>"string"!=typeof this.allowedFormats&&this.allowedFormats.some(e=>new RegExp(`\\b${e}\\b`,"i").test(t))),i=(s.length?s:t.choiceList).map(t=>L.fromJSON(t)).filter(e),o=L.fromJSON(t.defaultValue),a=i.some(t=>new RegExp(`\\b${o}\\b`,"i").test(t))?o:i[0];return{choiceList:i,defaultValue:a}}_getLayout(t){const s=t.choiceList.filter(t=>"map_only"!==t.toLowerCase()),i="all"===this.allowedLayouts?s:s.filter(t=>this.allowedLayouts.includes(S(t))),o=(i.length?i:s).map(S).filter(e),a=S(t.defaultValue),r=o.includes(a)?a:o.find(t=>/(?=.*letter)(?=.*landscape)/i.test(t))??o.find(t=>/(?=.*a4)(?=.*landscape)/i.test(t))??o[0];return{choiceList:o,defaultValue:r}}_getOverlayItem(){return this._overlayItem||(this._overlayItem=new F({strokeDash:[5],strokeWidth:2,strokeColor:[30,144,255,255]})),this._overlayItem}_enablePrintPreview(){if(!this.view?.overlay)return;const t=this.templateOptions,e=this._getOverlayItem();this.addHandles([p(()=>[t.width,t.height,t.scaleEnabled,t.scale,t.layout,t.layoutItem,t.id,t.state,t.dpi,this.view?.scale,this.view?.size,this.view?.state.paddedViewState.size,this.view?.state.padding,this.loaded],()=>this._updateOverLayItem(),m),this.view?.on("drag",["Shift"],t=>this._handleDrag(t),j.WIDGET),this.view?.on("key-down",["Escape"],()=>this._resetDrag(),j.WIDGET)],"overlay-handler"),this.view.overlay.addItem(e)}_updateOverLayItem(){if(!this.view)return;const t=this.templateOptions,e=this._getOverlayItem(),s=t.layoutItem?.id??t.layout,i=this.view,o=i.spatialReference,[a,r]=i.state.paddedViewState.size,l=i.state.padding;let n=0,p=0;if("map-only"===s)null!=t.width&&null!=t.height&&(n=t.width,p=t.height);else if(s){const e=t.id?this._templateIdToCustomTemplate.get(t.id):null,{webMapFrameSize:s,pageUnits:i}=e?.layoutTemplateInfo??{};let l=!1;if(s&&i)if(this._isFreeHand){const t=s[0]/s[1];n=this._freeHandWidth,p=this._freehandHeight,n>p?p=n/t:n=p*t}else{const t=W.fromJSON(i.toLowerCase()),e=o.unit;d(t)===d(e)?(n=u(s[0],t,e),p=u(s[1],t,e)):(l=!0,n=s[0],p=s[1])}if(!this._isFreeHand)if(t.scaleEnabled&&t.scale){const e=l?Math.min(a/n,r/p):c(o)*f*t.dpi;n*=e,p*=e}else if(0===n||0===p)n=a,p=r;else{const t=(a-.1*a)/n,e=(r-.1*r)/p,s=Math.min(t,e);n*=s,p*=s}}const{scaleEnabled:m,scale:h}=t,y=m&&h?h/this.view.scale:1,T=m&&h?G/t.dpi:1;if(e.boxWidth=n*y*T||a,e.boxHeight=p*y*T||r,l&&(e.padding=l),e.backgroundWidth=a??0,e.backgroundHeight=r??0,"loading"===this.loadStatus)e.strokeColor=N;else if("loaded"===this.loadStatus)switch(this.templateOptions.state){case"pending":e.strokeColor=N;break;case"ready":e.strokeColor=R;break;case"error":e.strokeColor=z}}_resetDrag(){this._isFreeHand=!1,this._updateOverLayItem()}_handleDrag(t){switch(t.action){case"start":this._start();break;case"update":this._update(t);break;case"end":this._end()}t.stopPropagation()}_start(){this._isFreeHand=!0}_update(t){const e=this._getOverlayItem(),{x:s,y:i}=t,{x:o,y:a}=t.origin;s>o?(e.x=o,e.boxWidth=s-o):(e.x=s,e.boxWidth=o-s),i>a?(e.y=a,e.boxHeight=i-a):(e.y=i,e.boxHeight=a-i)}_end(){const t=this._getOverlayItem();if(!this.view||null==t.x||null==t.y)return;const e=this.view,s=e.toMap(h(t.x+.5*t.boxWidth,t.y+.5*t.boxHeight));t.x=null,t.y=null,e.goTo({center:s}),this._freeHandWidth=t.boxWidth,this._freehandHeight=t.boxHeight,"map-only"===this.templateOptions.layout&&(this.templateOptions.width=this._freeHandWidth,this.templateOptions.height=this._freehandHeight),this.templateOptions.scale=this.view.scale,this._updateOverLayItem()}};t([y()],K.prototype,"_serviceTemplateCustomTextElements",void 0),t([y()],K.prototype,"_templateIdToCustomTemplate",void 0),t([y()],K.prototype,"allowedFormats",void 0),t([y()],K.prototype,"allowedLayouts",void 0),t([y({type:q})],K.prototype,"browseTemplates",void 0),t([y({type:q})],K.prototype,"defaultTemplates",void 0),t([y()],K.prototype,"error",void 0),t([y({type:$})],K.prototype,"exportedLinks",void 0),t([y()],K.prototype,"extraParameters",void 0),t([y()],K.prototype,"includeDefaultTemplates",void 0),t([y({readOnly:!0})],K.prototype,"effectivePrintServiceUrl",null),t([y()],K.prototype,"effectiveTemplateCustomTextElements",null),t([y({type:w})],K.prototype,"outSpatialReference",void 0),t([y({type:x})],K.prototype,"portal",void 0),t([y()],K.prototype,"portalTemplateIds",void 0),t([y({type:q})],K.prototype,"printServiceTemplates",void 0),t([y({readOnly:!0})],K.prototype,"defaultTemplate",void 0),t([y()],K.prototype,"showPrintAreaEnabled",void 0),t([y()],K.prototype,"printServiceUrl",void 0),t([y()],K.prototype,"printTimeout",void 0),t([y()],K.prototype,"saveExportEnabled",void 0),t([y({readOnly:!0})],K.prototype,"state",null),t([y({readOnly:!0})],K.prototype,"templatesInfo",void 0),t([y()],K.prototype,"updateDelay",void 0),t([y()],K.prototype,"view",void 0),t([y()],K.prototype,"templateCustomTextElements",void 0),t([y({type:D})],K.prototype,"templateOptions",void 0),K=t([T("esri.widgets.Print.PrintViewModel")],K);const X=K;export{X as default};
5
+ import{__decorate as t}from"tslib";import{isSome as e}from"../../core/arrayUtils.js";import i from"../../core/Collection.js";import s from"../../core/Error.js";import{EventedAccessor as o}from"../../core/Evented.js";import{JSONMap as a}from"../../core/jsonMap.js";import{clone as r}from"../../core/lang.js";import{LoadableMixin as l}from"../../core/Loadable.js";import{EsriPromiseMixin as n}from"../../core/Promise.js";import p from"../../core/ReactiveMap.js";import{watch as m,initial as h,whenOnce as d}from"../../core/reactiveUtils.js";import{createScreenPoint as u}from"../../core/screenUtils.js";import{unitType as c,convertUnit as f,getMetersPerUnitForSR as y,inchesPerMeter as v}from"../../core/units.js";import{property as T,subclass as w}from"../../core/accessorSupport/decorators.js";import _ from"../../geometry/Extent.js";import I from"../../geometry/SpatialReference.js";import{formatDate as g,convertDateFormatToIntlOptions as x}from"../../intl/date.js";import{getLocaleLanguage as O}from"../../intl/locale.js";import b from"../../portal/Portal.js";import E from"../../portal/PortalQueryParams.js";import{reArcGISOnlineDomain as L}from"../../portal/support/urlUtils.js";import{execute as P,getTaskInfo as S}from"../../rest/print.js";import{formatJsonMap as U}from"../../rest/support/fileFormat.js";import{fromJSON as k}from"../../rest/support/layoutTemplate.js";import C from"../../rest/support/LegendLayer.js";import j from"../../rest/support/PrintParameters.js";import{getVisibleLayerViews as F}from"../../rest/support/printTaskUtils.js";import M from"../../rest/support/PrintTemplate.js";import{getExtent as H}from"../../views/2d/viewpointUtils.js";import{ViewEventPriorities as D}from"../../views/input/InputManager.js";import A from"../../views/overlay/BoxOverlayItem.js";import W from"./CustomTemplate.js";import N from"./FileLink.js";import R from"./TemplateOptions.js";import{fetchLayoutTemplateInfos as V,valueUnitKebabDict as z}from"./utils.js";const B=[30,144,255,255],G=[237,211,23,255],q=[216,48,32,255],$=new Set(["GISProfessionalStdUT","GISProfessionalAdvUT"]),J=/(\/GPServer\/).+/i,Q=96,K=i.ofType(W),X=i.ofType(N),Y=new a({Feet:"feet",Miles:"miles",Meters:"meters",Kilometers:"kilometers"});function Z(t){t.layoutOptions??={},t.layoutOptions.customTextElements??=[];const e="date";if(!t.layoutOptions.customTextElements.find(t=>e in t)){const{customTextElements:e}=t.layoutOptions;let i=g(Date.now(),x("short-date"));"ar"===O()&&(i="‏"+i),e.push({date:i})}}function tt(t,e,i,s){if(!e.layoutOptions)return;if(!i)return void(e.layoutOptions.legendLayers=[]);if(!t)return;const o=F(t);e.layoutOptions.legendLayers=o.map(t=>new C({layerId:t.layer.id,title:t.layer.title||void 0,dynamicLegend:s}))}function et(t,e,i){if(!e)return;!(e.visible===i)&&t.layoutOptions&&(t.layoutOptions.elementOverrides?t.layoutOptions.elementOverrides[e.name]={visible:i}:t.layoutOptions.elementOverrides={[e.name]:{visible:i}})}let it=class extends(l(n(o))){constructor(t){super(t),this._serviceTemplateCustomTextElements=null,this._templateIdToCustomTemplate=new p,this._isFreeHand=!1,this._freeHandWidth=0,this._freehandHeight=0,this._asyncPrintTaskUrl=null,this._layoutInfoTaskUrl=null,this._portalLayoutInfoTaskUrl=null,this._customLayoutOptions=null,this._exportedFileNameMap={},this._layoutTemplateInfosCache=new Map,this._tasksInfoCache=new Map,this.allowedFormats="all",this.allowedLayouts="all",this.browseTemplates=new K,this.defaultTemplates=new K,this.error=null,this.exportedLinks=new X,this.extraParameters=null,this.includeDefaultTemplates=!0,this.outSpatialReference=null,this.portal=b.getDefault(),this.portalTemplateIds=[],this.printServiceTemplates=new K,this.defaultTemplate=null,this.showPrintAreaEnabled=!1,this.printServiceUrl=null,this.printTimeout=12e4,this.saveExportEnabled=!1,this.templatesInfo=null,this.updateDelay=1e3,this.view=null,this.templateCustomTextElements=null,this.templateOptions=new R}initialize(){this.addHandles([m(()=>[this.showPrintAreaEnabled,this.view],()=>{this.showPrintAreaEnabled?this._enablePrintPreview():(this.removeHandles("overlay-handler"),this.view?.overlay?.removeItem(this._getOverlayItem()))}),m(()=>[this.templateOptions.layout,this.templateOptions.layoutItem],()=>{this.loaded&&this._processTemplateOptions()}),m(()=>[this.allowedFormats,this.allowedLayouts],()=>{this.loaded&&this._loadTemplateInfos()}),m(()=>this.exportedLinks,()=>{for(const{name:t,extension:e}of this.exportedLinks)t&&e&&this._updateExportedFileNameMap(`${t}${e}`)},h)])}destroy(){this.removeHandles("overlay-handler"),this.view&&(this._overlayItem&&(this.view.overlay?.removeItem(this._overlayItem),this._overlayItem.destroy(),this._overlayItem=null),this.view=null)}get effectivePrintServiceUrl(){return this.printServiceUrl??null}get effectiveTemplateCustomTextElements(){if(!this._serviceTemplateCustomTextElements)return{};const t=r(this._serviceTemplateCustomTextElements);return this.templateCustomTextElements&&Object.keys(this.templateCustomTextElements).forEach(e=>{const i=t[e];if(i){const t=this.templateCustomTextElements?.[e];i.forEach(e=>{const[i]=Object.entries(e)[0];t?.forEach(t=>{const[s,o]=Object.entries(t)[0];i===s&&(e[i]=o)})})}}),Object.freeze(t)}get state(){return"loading"===this.loadStatus?"initializing":"failed"===this.loadStatus||this.error?"error":"loaded"===this.loadStatus&&this.view?.ready?"ready":"disabled"}async print(t){const{view:e,extraParameters:i,updateDelay:o,outSpatialReference:a}=this;if(!e)throw new s("print:view-required","view is not set");Z(t);const r=this._getOverlayItem(),l=t.scalePreserved||!this.showPrintAreaEnabled?void 0:H(new _,e.viewpoint,"map-only"===t.layout?[t.exportOptions.width,t.exportOptions.height]:[r.boxWidth,r.boxHeight]),n=new j({view:e,template:t,extent:l,extraParameters:i,updateDelay:o,outSpatialReference:a});try{const e=!!t.layoutItem?.id&&(this.defaultTemplates.some(e=>e.layoutItem?.id===t.layoutItem?.id)||this.browseTemplates.some(e=>e.layoutItem?.id===t.layoutItem?.id));return await P(e&&this._asyncPrintTaskUrl?this._asyncPrintTaskUrl:this.effectivePrintServiceUrl,n,{timeout:this.printTimeout})}catch(p){throw new s("print:export-error","An error occurred while exporting the web map.",{error:p})}}async load(t){return this.addResolvingPromise(this._loadResources(t).catch(t=>this.error=t)),this}toPrintTemplate({attributionEnabled:t,author:e,copyright:i,customTextElements:o,dpi:a,forceFeatureAttributes:r,format:l,height:n,id:p,includeTables:m,layout:h,layoutItem:d,legendEnabled:u,dynamicLegendEnabled:c,northArrowEnabled:f,scale:y,scaleBarEnabled:v,scaleBarUnit:T,scaleEnabled:w,title:_,width:I}){if(!h&&!d)throw new s("print:layout-required","layout is not set");const g=new M({attributionVisible:t,forceFeatureAttributes:r,format:l,includeTables:m,layout:h,layoutItem:d,layoutOptions:{authorText:e||"",copyrightText:i||"",customTextElements:o,titleText:_||"",scalebarUnit:v&&T?Y.toJSON(T):void 0},outScale:y??0,scalePreserved:w});if(I&&(g.exportOptions.width=I),n&&(g.exportOptions.height=n),a&&(g.exportOptions.dpi=a),g.layoutOptions){tt(this.view,g,u,c);const t=this.getLayoutTemplateById(p)?.mapSurroundInfoOptions;if(t){const e=t.northArrow;for(const t of e)et(g,t,f);const i=t.scaleBar;for(const t of i)et(g,t,v);const s=t.legend;for(const t of s)et(g,t,u)}}return g}getLayoutTemplateById(t){return t?this._templateIdToCustomTemplate.get(t):null}async addPortalTemplate(t){if(!this.portal||!t?.id)return;try{if("loading"===this.loadStatus&&await d(()=>this.loaded),!this.loaded)throw new s("print:load-required","PrintViewModel must be loaded before adding portal templates.");t.loaded||await t.load()}catch{return void this.applyTemplate(this.defaultTemplate)}const e=new W({type:"browse-template",layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl,label:t.title,layoutItem:t});this._templateIdToCustomTemplate.set(e.id,e),this.browseTemplates.add(e)}removePortalTemplate(t){t.layoutItem&&this.templateOptions.id===t.layoutItem.id&&(this.defaultTemplate?this.applyTemplate(this.defaultTemplate):this.templateOptions.reset()),this.browseTemplates.remove(t),this._templateIdToCustomTemplate.delete(t.id)}async applyTemplate(t){if(t&&t===this.getLayoutTemplateById(this.templateOptions.id))return;if(this.templateOptions.reset(),!t)return;if("map-only"===t)return void(this.templateOptions.layout="map-only");!t.layout||!this.templatesInfo||this.templatesInfo.layout.choiceList.includes(t.layout)||(this.defaultTemplate?t=this.defaultTemplate:this.templateOptions.reset());const e=t.layout||t.layoutItem?.id,i=e?this.templateCustomTextElements?.[e]:void 0;if(await this.templateOptions.applyTemplate(t,{customTextElements:i,customLayoutOptions:this._customLayoutOptions}),e&&this._serviceTemplateCustomTextElements&&!this._serviceTemplateCustomTextElements[e]&&t.layoutTemplateInfo?.layoutOptions?.customTextElements){const i=r(this._serviceTemplateCustomTextElements);i[e]=t.layoutTemplateInfo.layoutOptions.customTextElements,this._serviceTemplateCustomTextElements=Object.freeze(i)}}createExportedFileLink(t){const e=this.toPrintTemplate(this.templateOptions).format.toLowerCase(),i=e.includes("png")?"png":e,s=t+i;return this._updateExportedFileNameMap(s),new N({name:t,extension:i,count:this._exportedFileNameMap[s]})}export(t){const e=this.createExportedFileLink(t);this.exportedLinks.add(e);const i=this.print(this.toPrintTemplate(this.templateOptions)).then(t=>e.set({url:t?.url,state:"ready"})).catch(t=>e.set({error:t,state:"error"}));return this.emit("submit",{link:e,saveExportEnabled:this.saveExportEnabled}),i.then(t=>this.emit("complete",{link:t,saveExportEnabled:this.saveExportEnabled})),{link:e,promise:i}}async _loadResources(t){this.destroyed||(await this._loadUrls(t),await this._loadTemplateInfos(t),this._updateOverLayItem())}async _loadTemplateInfos(t){const e=[...this.defaultTemplates,...this.printServiceTemplates];for(const{id:o}of e)this._templateIdToCustomTemplate.delete(o);this.defaultTemplates.removeAll(),this.printServiceTemplates.removeAll();const[i,s]=await Promise.all([this._getLayoutToLayoutTemplateInfos(t),this._getPrintServiceTemplatesInfo(t)]);await this._loadAllTemplates(i,s,t),this._processPrintServiceTemplatesInfo(s),await this._processTemplateOptions()}_updateExportedFileNameMap(t){void 0!==this._exportedFileNameMap[t]?this._exportedFileNameMap[t]++:this._exportedFileNameMap[t]=0}async _processTemplateOptions(){const{layout:t,layoutItem:e}=this.templateOptions;if("map-only"!==t)if(this._customLayoutOptions={legend:this.templateOptions.legendEnabled,northArrow:this.templateOptions.northArrowEnabled,scaleBar:this.templateOptions.scaleBarEnabled},e?.id){try{e.loaded||await e.load()}catch{return void this.applyTemplate(this.defaultTemplate)}let t=this._templateIdToCustomTemplate.get(e.id);t||(t=new W({label:e.title,layoutItem:e,layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl}),this._templateIdToCustomTemplate.set(t.id,t)),await this.applyTemplate(t)}else if(t){const t=this.defaultTemplates.find(t=>t.layout===this.templateOptions.layout)??this.printServiceTemplates.find(t=>t.layout===this.templateOptions.layout);await this.applyTemplate(t??this.defaultTemplate)}}async _loadPortal(t){try{await this.portal.load(t)}catch(e){throw new s("print:could-not-load-portal","Cannot load print resource information from portal",{error:e,url:this.effectivePrintServiceUrl})}}async _loadUrls(t){if(this.printServiceUrl)this._set("effectivePrintServiceUrl",this.printServiceUrl),this._layoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(this.effectivePrintServiceUrl,t);else{await this._loadPortal(t);const{printTask:e,asyncPrintTask:i,layoutInfoTask:s}=this.portal?.helperServices??{};this._set("effectivePrintServiceUrl",e?.url),this._asyncPrintTaskUrl=i?.url,this._layoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(this.effectivePrintServiceUrl,t),s?.url&&this.effectivePrintServiceUrl!==s.url?this._portalLayoutInfoTaskUrl=await this._getLayoutInfoTaskUrl(s.url,t):this._portalLayoutInfoTaskUrl=this._layoutInfoTaskUrl}const e=this.effectivePrintServiceUrl?.toLowerCase().split("/");if(!e?.includes("gpserver"))throw new s("print:invalid-print-service-url","Can't fetch print templates information from provided URL",{url:this.effectivePrintServiceUrl})}async _getLayoutInfoTaskUrl(t,e){if(!t)return null;const i=await S(t,"GetLayoutTemplatesInfo",e);return i?t.replace(J,`$1${encodeURI(i.displayName)}`):null}_getPortalDefaultTemplates(t,e){return this.portal?.helperServices?.printTask?.templates?.filter(t=>"map_only"!==t.layout.toLowerCase()&&(!e||e.includes(k(t.layout))))?.map(e=>{const i=W.fromJSON(e);if(i.type="default-template",i.layoutInfoTaskUrl=this._layoutInfoTaskUrl,i.layout){const e=t.get(i.layout);e&&i.setLayoutTemplateInfo(e)}return i})??[]}async _getPortalCustomTemplates(t){if(this.printServiceUrl||!this.portal)return[];const{layoutGroupQuery:e,user:i}=this.portal,s=L.test(this.portal.url),o=i?.userLicenseTypeId,a=o&&$.has(o);if(!e||s&&!a)return[];const r=new E({query:e,disableExtraQuery:!0}),l=await this.portal.queryGroups(r,t);if(!l.total)return[];const n=l.results[0],p=new E({num:100,query:"type:Layout",sortField:n.sortField,sortOrder:n.sortOrder??void 0}),m=(await n.queryItems(p,t)).results;if(!m.length)return[];return m.map(t=>(this.portalTemplateIds.push(t.id),new W({type:"default-template",label:t.title,layoutItem:t,layoutInfoTaskUrl:this._portalLayoutInfoTaskUrl})))}async _loadAllTemplates(t,e,i){let s=!1;const o=e?.layout?.choiceList;if(this.includeDefaultTemplates&&this.portal&&!this.printServiceUrl){const e=this._getPortalDefaultTemplates(t,o);s=!!e.length,this.defaultTemplates.addMany(e);const a=await this._getPortalCustomTemplates(i);this.defaultTemplates.addMany(a);for(const t of this.defaultTemplates)this._templateIdToCustomTemplate.set(t.id,t)}s||t.forEach((t,e)=>{if(!o||o.includes(e)){const i=new W({type:"print-service-template",layout:e,layoutInfoTaskUrl:this._layoutInfoTaskUrl});i.setLayoutTemplateInfo(t),this.printServiceTemplates.add(i),this._templateIdToCustomTemplate.set(i.id,i)}})}_processPrintServiceTemplatesInfo(t){this._set("templatesInfo",t);const e=t?.layout?.defaultValue;if(e&&"map-only"!==e){const t=this.defaultTemplates.find(t=>t.layout===e)??this.printServiceTemplates.find(t=>t.layout===e)??this.defaultTemplates.at(0)??this.printServiceTemplates.at(0);this._set("defaultTemplate",t)}}async _getLayoutToLayoutTemplateInfos(t){const e=this._layoutInfoTaskUrl,i=e?this._layoutTemplateInfosCache.get(e):void 0,s=i??await V(e,void 0,t);i||this._layoutTemplateInfosCache.set(e,s);const o=new Map,a={};for(const r of s){const t=k(r.layoutTemplate);o.set(t,r),a[t]=r.layoutOptions.customTextElements}return this._serviceTemplateCustomTextElements=Object.freeze(a),o}async _getPrintServiceTemplatesInfo(t){const e=this.effectivePrintServiceUrl?this._tasksInfoCache.get(this.effectivePrintServiceUrl):void 0,i=e??await S(this.effectivePrintServiceUrl,"ExportWebMap",t);if(!i)throw new s("print:unavailable-service-info","Can't fetch templates info from service");e||this._tasksInfoCache.set(this.effectivePrintServiceUrl,i);const{parameters:o}=i,a=o.find(({name:t})=>"Format"===t),r=o.find(({name:t})=>"Layout_Template"===t);return{format:this._getFormat(a),layout:this._getLayout(r)}}_getFormat(t){const i="all"===this.allowedFormats?t.choiceList:t.choiceList.filter(t=>"string"!=typeof this.allowedFormats&&this.allowedFormats.some(e=>new RegExp(`\\b${e}\\b`,"i").test(t))),s=(i.length?i:t.choiceList).map(t=>U.fromJSON(t)).filter(e),o=U.fromJSON(t.defaultValue),a=s.some(t=>new RegExp(`\\b${o}\\b`,"i").test(t))?o:s[0];return{choiceList:s,defaultValue:a}}_getLayout(t){const i=t.choiceList.filter(t=>"map_only"!==t.toLowerCase()),s="all"===this.allowedLayouts?i:i.filter(t=>this.allowedLayouts.includes(k(t))),o=(s.length?s:i).map(k).filter(e),a=k(t.defaultValue),r=o.includes(a)?a:o.find(t=>/(?=.*letter)(?=.*landscape)/i.test(t))??o.find(t=>/(?=.*a4)(?=.*landscape)/i.test(t))??o[0];return{choiceList:o,defaultValue:r}}_getOverlayItem(){return this._overlayItem||(this._overlayItem=new A({strokeDash:[5],strokeWidth:2,strokeColor:[30,144,255,255]})),this._overlayItem}_enablePrintPreview(){if(!this.view?.overlay)return;const t=this.templateOptions,e=this._getOverlayItem();this.addHandles([m(()=>[t.width,t.height,t.scaleEnabled,t.scale,t.layout,t.layoutItem,t.id,t.state,t.dpi,this.view?.scale,this.view?.size,this.view?.state.paddedViewState.size,this.view?.state.padding,this.loaded],()=>this._updateOverLayItem(),h),this.view?.on("drag",["Shift"],t=>this._handleDrag(t),D.WIDGET),this.view?.on("key-down",["Escape"],()=>this._resetDrag(),D.WIDGET)],"overlay-handler"),this.view.overlay.addItem(e)}_updateOverLayItem(){if(!this.view)return;const t=this.templateOptions,e=this._getOverlayItem(),i=t.layoutItem?.id??t.layout,s=this.view,o=s.spatialReference,[a,r]=s.state.paddedViewState.size,l=s.state.padding;let n=0,p=0;if("map-only"===i)null!=t.width&&null!=t.height&&(n=t.width,p=t.height);else if(i){const e=t.id?this._templateIdToCustomTemplate.get(t.id):null,{webMapFrameSize:i,pageUnits:s}=e?.layoutTemplateInfo??{};let l=!1;if(i&&s)if(this._isFreeHand){const t=i[0]/i[1];n=this._freeHandWidth,p=this._freehandHeight,n>p?p=n/t:n=p*t}else{const t=z.fromJSON(s.toLowerCase()),e=o.unit;c(t)===c(e)?(n=f(i[0],t,e),p=f(i[1],t,e)):(l=!0,n=i[0],p=i[1])}if(!this._isFreeHand)if(t.scaleEnabled&&t.scale){const t=l?Math.min(a/n,r/p):y(o)*v*Q;n*=t,p*=t}else if(0===n||0===p)n=a,p=r;else{const t=(a-.1*a)/n,e=(r-.1*r)/p,i=Math.min(t,e);n*=i,p*=i}}const{scaleEnabled:m,scale:h}=t,d=m&&h?h/this.view.scale:1;if(e.boxWidth=n*d||a,e.boxHeight=p*d||r,l&&(e.padding=l),e.backgroundWidth=a??0,e.backgroundHeight=r??0,"loading"===this.loadStatus)e.strokeColor=G;else if("loaded"===this.loadStatus)switch(this.templateOptions.state){case"pending":e.strokeColor=G;break;case"ready":e.strokeColor=B;break;case"error":e.strokeColor=q}}_resetDrag(){this._isFreeHand=!1,this._updateOverLayItem()}_handleDrag(t){switch(t.action){case"start":this._start();break;case"update":this._update(t);break;case"end":this._end()}t.stopPropagation()}_start(){this._isFreeHand=!0}_update(t){const e=this._getOverlayItem(),{x:i,y:s}=t,{x:o,y:a}=t.origin;i>o?(e.x=o,e.boxWidth=i-o):(e.x=i,e.boxWidth=o-i),s>a?(e.y=a,e.boxHeight=s-a):(e.y=s,e.boxHeight=a-s)}_end(){const t=this._getOverlayItem();if(!this.view||null==t.x||null==t.y)return;const e=this.view,i=e.toMap(u(t.x+.5*t.boxWidth,t.y+.5*t.boxHeight));t.x=null,t.y=null,e.goTo({center:i}),this._freeHandWidth=t.boxWidth,this._freehandHeight=t.boxHeight,"map-only"===this.templateOptions.layout&&(this.templateOptions.width=this._freeHandWidth,this.templateOptions.height=this._freehandHeight),this.templateOptions.scale=this.view.scale,this._updateOverLayItem()}};t([T()],it.prototype,"_serviceTemplateCustomTextElements",void 0),t([T()],it.prototype,"_templateIdToCustomTemplate",void 0),t([T()],it.prototype,"allowedFormats",void 0),t([T()],it.prototype,"allowedLayouts",void 0),t([T({type:K})],it.prototype,"browseTemplates",void 0),t([T({type:K})],it.prototype,"defaultTemplates",void 0),t([T()],it.prototype,"error",void 0),t([T({type:X})],it.prototype,"exportedLinks",void 0),t([T()],it.prototype,"extraParameters",void 0),t([T()],it.prototype,"includeDefaultTemplates",void 0),t([T({readOnly:!0})],it.prototype,"effectivePrintServiceUrl",null),t([T()],it.prototype,"effectiveTemplateCustomTextElements",null),t([T({type:I})],it.prototype,"outSpatialReference",void 0),t([T({type:b})],it.prototype,"portal",void 0),t([T()],it.prototype,"portalTemplateIds",void 0),t([T({type:K})],it.prototype,"printServiceTemplates",void 0),t([T({readOnly:!0})],it.prototype,"defaultTemplate",void 0),t([T()],it.prototype,"showPrintAreaEnabled",void 0),t([T()],it.prototype,"printServiceUrl",void 0),t([T()],it.prototype,"printTimeout",void 0),t([T()],it.prototype,"saveExportEnabled",void 0),t([T({readOnly:!0})],it.prototype,"state",null),t([T({readOnly:!0})],it.prototype,"templatesInfo",void 0),t([T()],it.prototype,"updateDelay",void 0),t([T()],it.prototype,"view",void 0),t([T()],it.prototype,"templateCustomTextElements",void 0),t([T({type:R})],it.prototype,"templateOptions",void 0),it=t([w("esri.widgets.Print.PrintViewModel")],it);const st=it;export{st as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as t}from"tslib";import o from"../../core/Accessor.js";import{clone as e}from"../../core/lang.js";import{property as r,subclass as l}from"../../core/accessorSupport/decorators.js";import s from"../../portal/PortalItem.js";let i=class extends o{constructor(t){super(t),this._abortController=null,this.attributionEnabled=!0,this.author=null,this.copyright=null,this.customTextElements=null,this.dpi=96,this.fileName=null,this.forceFeatureAttributes=!1,this.format="pdf",this.height=null,this.includeTables=!0,this.id=null,this.state="ready",this.layout="letter-ansi-a-landscape",this.layoutItem=null,this.legendEnabled=void 0,this.northArrowEnabled=void 0,this.scale=null,this.scaleBarEnabled=void 0,this.scaleEnabled=!1,this.title=null,this.width=null}async applyTemplate(t,o){if(t?.id===this.id&&"error"!==t?.state)return;if(this._abortController&&(this._abortController.abort(),this._abortController=null),!t)return;if(this._set("state","pending"),this._resetMapSurroundInfoOptions(),this._set("id",t.id),this.set({layout:t.layout,layoutItem:t.layoutItem}),!t.layoutOptions&&t.layoutItem){const o=new AbortController;if(this._abortController=o,await t.fetchLayoutItemTemplateInfo({signal:this._abortController.signal}),"loaded"!==t.state){if("error"===t.state&&this._set("state","error"),this._abortController!==o)return;return void(this._abortController=null)}this._abortController=null}const r=o?.customLayoutOptions,l=o?.customTextElements??t.layoutTemplateInfo?.layoutOptions?.customTextElements??this.customTextElements;this.set({customTextElements:l?e(l):void 0,format:this.format??t.format,legendEnabled:r?.legend??t.layoutOptions?.legend??this.legendEnabled,northArrowEnabled:r?.northArrow??t.layoutOptions?.northArrow??this.northArrowEnabled,scaleBarEnabled:r?.scaleBar??t.layoutOptions?.scaleBar??this.scaleBarEnabled}),this._set("state","ready")}reset(){this._set("id",null),this._set("state","ready"),this.set({layout:null,layoutItem:null,customTextElements:null}),this._resetMapSurroundInfoOptions()}_resetMapSurroundInfoOptions(){this.set({legendEnabled:void 0,northArrowEnabled:void 0,scaleBarEnabled:void 0})}};t([r()],i.prototype,"attributionEnabled",void 0),t([r()],i.prototype,"author",void 0),t([r()],i.prototype,"copyright",void 0),t([r()],i.prototype,"customTextElements",void 0),t([r()],i.prototype,"dpi",void 0),t([r()],i.prototype,"fileName",void 0),t([r()],i.prototype,"forceFeatureAttributes",void 0),t([r()],i.prototype,"format",void 0),t([r()],i.prototype,"height",void 0),t([r()],i.prototype,"includeTables",void 0),t([r({readOnly:!0})],i.prototype,"id",void 0),t([r({readOnly:!0})],i.prototype,"state",void 0),t([r()],i.prototype,"layout",void 0),t([r({type:s})],i.prototype,"layoutItem",void 0),t([r()],i.prototype,"legendEnabled",void 0),t([r()],i.prototype,"northArrowEnabled",void 0),t([r()],i.prototype,"scale",void 0),t([r()],i.prototype,"scaleBarEnabled",void 0),t([r()],i.prototype,"scaleEnabled",void 0),t([r()],i.prototype,"title",void 0),t([r()],i.prototype,"width",void 0),i=t([l("esri.widgets.Print.TemplateOptions")],i);const a=i;export{a as default};
5
+ import{__decorate as t}from"tslib";import e from"../../core/Accessor.js";import{clone as o}from"../../core/lang.js";import{property as r,subclass as l}from"../../core/accessorSupport/decorators.js";import i from"../../portal/PortalItem.js";let s=class extends e{constructor(t){super(t),this._abortController=null,this.attributionEnabled=!0,this.author=null,this.copyright=null,this.customTextElements=null,this.dpi=96,this.dynamicLegendEnabled=void 0,this.fileName=null,this.forceFeatureAttributes=!1,this.format="pdf",this.height=null,this.includeTables=!0,this.id=null,this.state="ready",this.layout="letter-ansi-a-landscape",this.layoutItem=null,this.legendEnabled=void 0,this.northArrowEnabled=void 0,this.scale=null,this.scaleBarEnabled=void 0,this.scaleBarUnit=null,this.scaleEnabled=!1,this.title=null,this.width=null}async applyTemplate(t,e){if(t?.id===this.id&&"error"!==t?.state)return;if(this._abortController&&(this._abortController.abort(),this._abortController=null),!t)return;if(this._set("state","pending"),this._resetMapSurroundInfoOptions(),this._set("id",t.id),this.set({layout:t.layout,layoutItem:t.layoutItem}),!t.layoutOptions&&t.layoutItem){const e=new AbortController;if(this._abortController=e,await t.fetchLayoutItemTemplateInfo({signal:this._abortController.signal}),"loaded"!==t.state){if("error"===t.state&&this._set("state","error"),this._abortController!==e)return;return void(this._abortController=null)}this._abortController=null}const r=e?.customLayoutOptions,l=e?.customTextElements??t.layoutTemplateInfo?.layoutOptions?.customTextElements??this.customTextElements;this.set({customTextElements:l?o(l):void 0,format:this.format??t.format,legendEnabled:r?.legend??t.layoutOptions?.legend??this.legendEnabled,dynamicLegendEnabled:r?.dynamicLegend??t.layoutOptions?.dynamicLegend??this.dynamicLegendEnabled,northArrowEnabled:r?.northArrow??t.layoutOptions?.northArrow??this.northArrowEnabled,scaleBarEnabled:r?.scaleBar??t.layoutOptions?.scaleBar??this.scaleBarEnabled}),this._set("state","ready")}reset(){this._set("id",null),this._set("state","ready"),this.set({layout:null,layoutItem:null,customTextElements:null}),this._resetMapSurroundInfoOptions()}_resetMapSurroundInfoOptions(){this.set({legendEnabled:void 0,dynamicLegendEnabled:void 0,northArrowEnabled:void 0,scaleBarEnabled:void 0})}};t([r()],s.prototype,"attributionEnabled",void 0),t([r()],s.prototype,"author",void 0),t([r()],s.prototype,"copyright",void 0),t([r()],s.prototype,"customTextElements",void 0),t([r()],s.prototype,"dpi",void 0),t([r()],s.prototype,"dynamicLegendEnabled",void 0),t([r()],s.prototype,"fileName",void 0),t([r()],s.prototype,"forceFeatureAttributes",void 0),t([r()],s.prototype,"format",void 0),t([r()],s.prototype,"height",void 0),t([r()],s.prototype,"includeTables",void 0),t([r({readOnly:!0})],s.prototype,"id",void 0),t([r({readOnly:!0})],s.prototype,"state",void 0),t([r()],s.prototype,"layout",void 0),t([r({type:i})],s.prototype,"layoutItem",void 0),t([r()],s.prototype,"legendEnabled",void 0),t([r()],s.prototype,"northArrowEnabled",void 0),t([r()],s.prototype,"scale",void 0),t([r()],s.prototype,"scaleBarEnabled",void 0),t([r()],s.prototype,"scaleBarUnit",void 0),t([r()],s.prototype,"scaleEnabled",void 0),t([r()],s.prototype,"title",void 0),t([r()],s.prototype,"width",void 0),s=t([l("esri.widgets.Print.TemplateOptions")],s);const a=s;export{a as default};
package/widgets/Print.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{formatNumber as t}from"../intl.js";import i from"../core/Collection.js";import{deprecateWidget as a}from"../core/deprecate.js";import{JSONMap as l}from"../core/jsonMap.js";import o from"../core/Logger.js";import{watch as n,on as s,whenOnce as r}from"../core/reactiveUtils.js";import{unitName as c}from"../core/unitFormatUtils.js";import{addProxy as p,hasSameOrigin as d}from"../core/urlUtils.js";import{property as m,subclass as u}from"../core/accessorSupport/decorators.js";import{ensureInteger as h}from"../core/accessorSupport/ensureType.js";import b from"../geometry/SpatialReference.js";import{isValid as _}from"../geometry/support/spatialReferenceUtils.js";import v from"../portal/Portal.js";import{reArcGISOnlineDomain as g}from"../portal/support/urlUtils.js";import{findToken as f}from"../rest/utils.js";import{formatJsonMap as y}from"../rest/support/fileFormat.js";import T from"./Widget.js";import w from"./Print/FileLink.js";import k from"./Print/PrintViewModel.js";import x from"./Print/TemplateOptions.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{globalCss as S}from"./support/globalCss.js";import{Heading as I}from"./support/Heading.js";import{legacyIcon as O}from"./support/legacyIcon.js";import{messageBundle as E,tsx as L,isRTL as $,tsxFragment as M,isActivationKey as F}from"./support/widget.js";const P="map-only",A="esri-print",R={base:A,headerTitle:`${A}__header-title`,layoutTabList:`${A}__layout-tab-list`,layoutTab:`${A}__layout-tab`,layoutSection:`${A}__layout-section`,mapOnlySection:`${A}__map-only-section`,panelItemsCentered:`${A}__panel-items--centered`,loader:`${A}__loader`,swapButton:`${A}__swap-button`,printButton:`${A}__export-button`,printButtonSection:`${A}__export-button-section`,printButtonSectionDivider:`${A}__export-button-section--divider`,templateSelectContainer:`${A}__template-select-container`,templateSelectIcon:`${A}__template-select-icon`,templateSelectError:`${A}__template-select-error`,templateSelectArrow:`${A}__template-select-arrow`,formSectionContainer:`${A}__form-section-container`,advancedOptionsSection:`${A}__advanced-options-section`,advancedOptionsContainer:`${A}__advanced-options-container`,browseTemplateButtonContainer:`${A}__browse-template-button-container`,browseTemplateButtonContainerFilter:`${A}__browse-template-button-container-filter`,exportedFilesContainer:`${A}__export-panel-container`,exportedFilesTitle:`${A}__export-title`,exportedFile:`${A}__exported-file`,exportedFileLinkTitle:`${A}__exported-file-link-title`,exportedFileLinkDescription:`${A}__exported-file-link-description`,exportedFilesEmpty:`${A}__exported-files-empty`,printWidgetContainer:`${A}__container`,content:`${A}__content`,panelContainer:`${A}__panel-container`,scaleInfoContainer:`${A}__scale-info-container`,scaleInputContainer:`${A}__scale-input-container`,scaleInput:`${A}__scale-input`,sizeContainer:`${A}__size-container`,panelError:`${A}__panel--error`,exportedFileLoader:`${A}__exported-file--loader`,exportSection:`${A}__export-section`,exportSectionCentered:`${A}__export-section--centered`,templateButtonContainer:`${A}__template-button-container`,templateDoneButton:`${A}__template-done-button`,templateSelectFlowItemContainer:`${A}__template-select-flow-item-container`,templateSelectFlowItemContent:`${A}__template-select-flow-item-content`,templateSelectFlowItemListHeading:`${A}__template-select-flow-item-list-heading`,srLabel:`${A}__sr-label`,invalidWkidText:`${A}__invalid-wkid-text`};function B(e){return!isNaN(e)&&e>0&&Number.isFinite(e)}function N(e){return e?.toLowerCase()===P}function V(e){const{state:t,extension:i}=e;switch(t){case"pending":return"spinner";case"error":return"exclamation-mark-circle";default:return i?.toLowerCase()?.includes("pdf")?"file-pdf":"file"}}const D=new l({inch:"inches",foot:"feet",yard:"yards",mile:"miles","nautical-mile":"nautical-miles",millimeter:"millimeters",centimeter:"centimeters",decimeter:"decimeters",meter:"meters",kilometer:"kilometers"}),j=new Map([["a3-landscape","a3-landscape"],["a3-portrait","a3-portrait"],["a4-landscape","a4-landscape"],["a4-portrait","a4-portrait"],["letter-ansi-a-landscape","ansi-a-landscape"],["letter-ansi-a-portrait","ansi-a-portrait"],["tabloid-ansi-b-landscape","ansi-b-landscape"],["tabloid-ansi-b-portrait","ansi-b-portrait"]]);let U=class extends T{constructor(e,t){super(e,t),this._activeTabFocusRequested=!1,this._awaitingServerResponse=!1,this._selectedTab="layoutTab",this._pendingExportScroll=!1,this._rootNode=null,this._selectedTemplate=null,this._formats=[],this._showTemplates=!1,this._isValidSpatialReference=!0,this.allowedFormatsForSaving=null,this.browseTemplateButtonOnClick=null,this.headerVisible=!0,this.headingLevel=3,this.includeOrganizationTemplates=!0,this.messagesCommon=null,this.messagesUnits=null,this.saveExportHidden=!0,this.saveAsButtonCallback=null,this.viewModel=new k,this._onInput=e=>{"layoutTab"===this._selectedTab?this.templateOptions.title=e.currentTarget.value:"mapOnlyTab"===this._selectedTab&&(this.templateOptions.fileName=e.currentTarget.value)},this._handleLinkClick=e=>{const t=e.currentTarget["data-item"];if(!t||"ready"!==t.state||!t.url)return;const i=f(this.viewModel.effectivePrintServiceUrl),a=t.url,l=document.createElement("a");if(l.target="_blank",l.href=a,l.rel="noreferrer",l.download=t.formattedName??"",!i)return l.click(),void e.stopPropagation();e.preventDefault();const o=new URL(a);o.searchParams.set("token",i),l.href=o.href,l.click(),l.href=a},a(o.getLogger(this),"Print","arcgis-print",{version:"4.33"}),this._focusOnTabChange=this._focusOnTabChange.bind(this)}initialize(){this.addHandles([n(()=>[this.templateOptions.format,this.viewModel.templatesInfo?.format],()=>{const{templatesInfo:e}=this.viewModel;if(!e)return;if(this._formats.length!==e.format.choiceList.length){const t=y.apiValues;this._formats=e.format.choiceList.map(e=>{const i=t.find(t=>new RegExp(`\\b${t}\\b`,"i").test(e))??e;return{value:i,label:e===i?e.toUpperCase():e}}).sort((e,t)=>e.label.localeCompare(t.label))}const t=this._formats.some(({value:e})=>new RegExp(`\\b${e}\\b`,"i").test(this.templateOptions.format));if(e.format.defaultValue&&!t){const t=this._formats.find(({value:t})=>new RegExp(`\\b${t}\\b`,"i").test(e.format.defaultValue))?.value;return void(t&&(this.templateOptions.format=t))}}),n(()=>[this.templateOptions.id,this.viewModel.loaded],()=>{const{layout:e}=this.templateOptions;this._selectedTab=N(e)?"mapOnlyTab":"layoutTab","layoutTab"===this._selectedTab&&this.viewModel.loaded&&(this._selectedTemplate=this.viewModel.getLayoutTemplateById(this.templateOptions.id))}),n(()=>this.templateOptions.dpi,e=>{e<=0&&(this.templateOptions.dpi=1)}),n(()=>this.viewModel.view?.scale,e=>{!e||this.templateOptions.scaleEnabled&&this.templateOptions.scale||(this.templateOptions.scale=e)}),s(()=>this.viewModel,"submit",e=>this.emit("submit",e)),s(()=>this.viewModel,"complete",e=>this.emit("complete",e))]);const{height:e,width:t}=this.templateOptions;this.templateOptions.width=t||800,this.templateOptions.height=e||1100;const i=setTimeout(()=>{this._awaitingServerResponse=!0,this.scheduleRender()},500);this.viewModel.load().then(()=>{clearTimeout(i),this._awaitingServerResponse=!1})}loadDependencies(){return C({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),block:()=>import("@esri/calcite-components/dist/components/calcite-block"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),checkbox:()=>import("@esri/calcite-components/dist/components/calcite-checkbox"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch"),chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),popover:()=>import("@esri/calcite-components/dist/components/calcite-popover"),link:()=>import("@esri/calcite-components/dist/components/calcite-link")})}destroy(){this.viewModel.destroy()}get allowedFormats(){return this.viewModel.allowedFormats}set allowedFormats(e){this.viewModel.allowedFormats=e}get allowedLayouts(){return this.viewModel.allowedLayouts}set allowedLayouts(e){this.viewModel.allowedLayouts=e}get error(){return this.viewModel.error}get exportedLinks(){return this.viewModel.exportedLinks}set exportedLinks(e){this.viewModel.exportedLinks=e}get extraParameters(){return this.viewModel.extraParameters}set extraParameters(e){this.viewModel.extraParameters=e}get icon(){return"print"}set icon(e){this._overrideIfSome("icon",e)}get includeDefaultTemplates(){return this.viewModel.includeDefaultTemplates}set includeDefaultTemplates(e){this.viewModel.includeDefaultTemplates=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get outSpatialReference(){return this.viewModel.outSpatialReference}set outSpatialReference(e){this.viewModel.outSpatialReference=e}get portal(){return this.viewModel.portal}set portal(e){this.viewModel.portal=e}get saveExportEnabled(){return this.viewModel.saveExportEnabled}set saveExportEnabled(e){this.viewModel.saveExportEnabled=e}get showPrintAreaEnabled(){return this.viewModel.showPrintAreaEnabled}set showPrintAreaEnabled(e){this.viewModel.showPrintAreaEnabled=e}get printServiceUrl(){return this.viewModel.printServiceUrl}set printServiceUrl(e){this.viewModel.printServiceUrl=e}get templateCustomTextElements(){return this.viewModel.templateCustomTextElements}set templateCustomTextElements(e){this.viewModel.templateCustomTextElements=e}get templateOptions(){return this.viewModel.templateOptions}set templateOptions(e){this.viewModel.templateOptions=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}render(){const{messages:e,templateOptions:t,viewModel:i,view:a}=this,{attributionEnabled:l,author:o,copyright:n,dpi:s,format:r,height:c,layout:p,layoutItem:d,legendEnabled:m,northArrowEnabled:u,scaleBarEnabled:v,scaleEnabled:g,scale:f,width:y}=t,T="ready"!==i.state||this._awaitingServerResponse||!(p||d),w=this._renderTitleOrFileNameSection(),k=L("div",{class:R.formSectionContainer},L("calcite-label",null,e.fileFormatTitle,L("calcite-combobox",{clearDisabled:!0,label:e.formatDefaultOption,maxItems:6,placeholder:e.formatDefaultOption,selectionMode:"single-persist",onCalciteComboboxChange:({currentTarget:e})=>{this.templateOptions.format=e.selectedItems[0]?.value??"pdf"}},this._formats.map(({value:e,label:t},i)=>L("calcite-combobox-item",{key:`file-format-${i}`,selected:e===this.templateOptions.format,textLabel:t,value:e}))))),x=L("calcite-label",{layout:"inline"},L("calcite-switch",{checked:this.showPrintAreaEnabled,onCalciteSwitchChange:e=>{this.showPrintAreaEnabled=!!e.currentTarget.checked}}),e.printPreview),C=L("div",null,L("div",{class:R.formSectionContainer},L("calcite-label",null,e.template,L("calcite-block",{class:R.templateSelectContainer,collapsible:!1,description:this._getPageSizeLabel(this._selectedTemplate),heading:this._getTemplateLabel(this._selectedTemplate,!0),key:"template-select-block",label:e.template,loading:"loading"===this._selectedTemplate?.state,onclick:()=>this._showTemplates=!0,onkeydown:e=>{"Enter"!==e.key&&" "!==e.key||(this._showTemplates=!0)},tabIndex:0},L("calcite-icon",{class:R.templateSelectIcon,icon:(this._selectedTemplate?.layout?j.get(this._selectedTemplate.layout):null)||"custom-print",key:"template-select-icon",scale:"l",slot:"content-start"}),"error"===this._selectedTemplate?.state?L("calcite-icon",{class:R.templateSelectError,icon:"exclamation-mark-circle",key:"template-select-error",scale:"s",slot:"actions-end"}):null,L("calcite-icon",{class:R.templateSelectArrow,icon:$()?"chevron-left":"chevron-right",key:"template-select-arrow",scale:"s",slot:"actions-end"})))),x),E=L("div",{class:R.formSectionContainer},L("calcite-label",null,e.dpi,L("calcite-input-number",{bind:this,"data-input-name":"dpi",min:1,value:`${s}`,onCalciteInputNumberInput:this._updateNumberInputValue}))),M=L("div",{class:R.formSectionContainer},L("calcite-label",null,L("div",{class:R.srLabel},e.outSpatialReference,L("calcite-link",{href:"https://developers.arcgis.com/rest/services-reference/enterprise/using-spatial-references/",target:"_blank"},"(WKID)")),L("calcite-input-number",{bind:this,"data-input-name":"outSpatialReference",integer:!0,numberButtonType:"none",value:i.outSpatialReference?.wkid?.toString()??"",onCalciteInputNumberInput:({currentTarget:e})=>{const t=h(e.value);i.outSpatialReference=Number.isNaN(t)||null==t?null:new b({wkid:t}),this._isValidSpatialReference=!i.outSpatialReference||_(i.outSpatialReference)}}),this._isValidSpatialReference?null:L("div",{class:R.invalidWkidText,key:`out-sr-${i.outSpatialReference?.wkid}`},e.invalidWkid))),F=L("div",{class:this.classes(R.scaleInfoContainer,R.formSectionContainer)},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:g,"data-option-name":"scaleEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.scale),L("div",{class:R.scaleInputContainer},L("calcite-input-number",{"aria-label":e.scaleLabel,"aria-valuenow":`${f}`,bind:this,class:R.scaleInput,"data-input-name":"scale",disabled:!g,value:`${f}`,onCalciteInputNumberInput:this._updateNumberInputValue}),L("calcite-button",{appearance:"outline","aria-label":e.reset,bind:this,disabled:!g,iconStart:"refresh",kind:"neutral",onclick:this._resetToCurrentScale}))),P=L("div",{"aria-labelledby":`${this.id}__advancedOptionsForLayout`,class:R.advancedOptionsContainer,key:"advanced-section-for-layout"},F,this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasAuthorText??1?L("div",{class:R.formSectionContainer,key:"author-info"},L("calcite-label",null,e.author,L("calcite-input",{bind:this,"data-input-name":"author",value:o??"",onCalciteInputInput:this._updateInputValue}))):null,this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasCopyrightText??1?L("div",{class:R.formSectionContainer,key:"copyright-text"},L("calcite-label",null,e.copyright,L("calcite-input",{bind:this,"data-input-name":"copyright",value:n??"",onCalciteInputInput:this._updateInputValue}))):null,E,M,this._renderCustomTextElementSection(),this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasLegend??1?L("div",{class:R.formSectionContainer,key:"legend-info"},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:!!m,"data-option-name":"legendEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.legend)):null,this._selectedTemplate?.mapSurroundInfoOptions?.northArrow.length?L("div",{class:R.formSectionContainer,key:"north-arrow"},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:!!u,"data-option-name":"northArrowEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.northArrow)):null,this._selectedTemplate?.mapSurroundInfoOptions?.scaleBar.length?L("div",{class:R.formSectionContainer,key:"scale-bar"},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:!!v,"data-option-name":"scaleBarEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.scaleBar)):null),A=L("div",{"aria-labelledby":`${this.id}__advancedOptionsForMapOnly`,class:R.advancedOptionsContainer},F,E,M,L("div",{class:R.formSectionContainer},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:l,"data-option-name":"attributionEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.attribution)),this._renderCustomTextElementSection()),B=this.exportedLinks.toArray(),N=this._renderExportedLinkItems(B),V={[R.exportSectionCentered]:!B.length},D="layoutTab"===this._selectedTab?L("section",{"aria-labelledby":`${this.id}__layoutTab`,class:R.layoutSection,id:`${this.id}__layoutContent`,key:"esri-print__layoutContent",role:"tabpanel"},L("div",{class:R.panelContainer},this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasTitleText??1?w:null,C,"layoutTab"===this._selectedTab?k:null,L("calcite-block",{"aria-label":e.advancedOptions,class:this.classes(R.panelContainer,R.advancedOptionsSection),collapsible:!0,disabled:!(p||d?.id),heading:e.advancedOptions,id:"advancedOptionsForLayout",key:"advanced-options-for-layout"},P))):"mapOnlyTab"===this._selectedTab?L("section",{"aria-labelledby":`${this.id}__mapOnlyTab`,class:R.mapOnlySection,id:`${this.id}__mapOnlyContent`,key:"esri-print__mapOnlyContent",role:"tabpanel"},L("div",{class:R.panelContainer},w,k,L("div",null,L("div",{class:this.classes(R.sizeContainer,R.formSectionContainer)},L("calcite-label",null,e.width,L("calcite-input-number",{bind:this,"data-input-name":"width",value:`${y}`,onCalciteInputNumberInput:this._updateNumberInputValue})),L("calcite-label",null,e.height,L("calcite-input-number",{bind:this,"data-input-name":"height",value:`${c}`,onCalciteInputNumberInput:this._updateNumberInputValue})),L("button",{"aria-label":e.swap,bind:this,class:this.classes(S.widgetButton,R.swapButton,O.swap),onclick:this._switchInput,type:"button"})),x),L("calcite-block",{"aria-label":e.advancedOptions,class:this.classes(R.panelContainer,R.advancedOptionsSection),collapsible:!0,heading:e.advancedOptions,id:"advancedOptionsForMapOnly",key:"advanced-options-for-map-only"},A))):L("section",{"aria-labelledby":`${this.id}__exportTab`,class:this.classes(R.exportSection,V),id:`${this.id}__exportContent`,key:"esri-print__exportContent",role:"tabpanel"},L("div",{class:R.panelContainer},L("div",{afterUpdate:this._scrollExportIntoView,bind:this,class:R.exportedFilesContainer},0===B.length?L("div",{class:R.exportedFilesEmpty},L("calcite-icon",{icon:"file",scale:"l"}),L("div",null,L(I,{class:R.exportedFilesTitle,level:this.headingLevel},e.noExportedFiles),L("div",null,e.exportHint))):N))),U="2d"!==a?.type,H=L("div",{class:R.panelError},a?U?e.sceneViewError:e.serviceError:e.noViewError),z=B.some(({state:e})=>"pending"===e),W=L("div",{class:R.content,key:"panel"},L("div",null,L("ul",{bind:this,class:R.layoutTabList,onclick:this._toggleLayoutPanel,onkeydown:this._handleLayoutPanelKeyDown,role:"tablist"},L("li",{afterCreate:this._focusOnTabChange,afterUpdate:this._focusOnTabChange,"aria-selected":`${"layoutTab"===this._selectedTab}`,class:R.layoutTab,"data-tab-id":"layoutTab",id:`${this.id}__layoutTab`,role:"tab",tabIndex:0},e.layoutTab),L("li",{afterCreate:this._focusOnTabChange,afterUpdate:this._focusOnTabChange,"aria-selected":`${"mapOnlyTab"===this._selectedTab}`,class:R.layoutTab,"data-tab-id":"mapOnlyTab",id:`${this.id}__mapOnlyTab`,role:"tab",tabIndex:0},e.mapOnlyTab),L("li",{afterCreate:this._focusOnTabChange,afterUpdate:this._focusOnTabChange,"aria-selected":`${"exportTab"===this._selectedTab}`,class:R.layoutTab,"data-tab-id":"exportTab",id:`${this.id}__exportedFilesTab`,role:"tab",tabIndex:0},z?L("calcite-loader",{inline:!0,label:"loading",scale:"s"}):null,e.exportsTab)),D),"exportTab"!==this._selectedTab?L("div",{class:this.classes(R.printButtonSection,!this.saveExportHidden&&this.portal?R.printButtonSectionDivider:null),key:"export-button-section"},!this.saveExportHidden&&this.portal?L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:this.saveExportEnabled,onCalciteCheckboxChange:e=>{this.saveExportEnabled=!!e.currentTarget.checked}}),e.saveExportToMyContent):null,L("calcite-button",{"aria-label":e.exportDescription,bind:this,class:this.classes(R.printButton),disabled:T||!(p||d?.id)&&!r,onclick:this._handlePrintMap,scale:"l",width:"full"},e.export)):null),q=L("calcite-flow",{key:"root-flow"},L("calcite-flow-item",{bind:this,key:"root-flow-item",selected:!this._showTemplates},L("div",{class:R.printWidgetContainer},this.headerVisible?L("header",{class:R.headerTitle},e.export):null,this.error||U||!a?H:W)),this._renderChooseTemplateFlowItem()),K="initializing"===i.state,J=K?this._renderLoader():q,G={[R.panelItemsCentered]:K};return L("div",{bind:this,class:this.classes(R.base,S.widget,S.panel,G)},J)}_getPageSizeLabel(e){if(!e)return;const i=e.layoutTemplateInfo;if(!i)return;const a=D.fromJSON(i.pageUnits.toLowerCase());return`${t(i.pageSize[0])} × ${t(i.pageSize[1])} ${c(this.messagesUnits,a,"abbr")}`}_getTemplateLabel(e,t=!1){if(!e)return t?this.messages.selectTemplate:this.messages.untitled;const{label:i,layout:a,layoutItem:l,type:o}=e;if("print-service-template"===o&&this.messages[a])return this.messages[a];const n=i??a??l?.id;return n?.replaceAll("_"," ")??this.messages.untitled}_getPortalTemplates(){const{portalTemplateIds:e}=this.viewModel;return this.includeDefaultTemplates&&this.includeOrganizationTemplates?this.viewModel.defaultTemplates.toArray().filter(({layout:t,layoutItem:i})=>!N(t)&&!!i?.id&&e.includes(i.id)):[]}_getDefaultTemplates(){const{portalTemplateIds:e}=this.viewModel;return this.includeDefaultTemplates?this.viewModel.defaultTemplates.toArray().filter(({layout:t,layoutItem:i})=>!(N(t)||i?.id&&e.includes(i.id))):[]}_getPrintServiceTemplates(){return this.includeDefaultTemplates&&this._getDefaultTemplates().length?[]:this.viewModel.printServiceTemplates.toArray().filter(({layout:e})=>!N(e))}_renderLayoutTemplates(e,t=!1,i=!1){return t&&e.sort((e,t)=>(e.label??"")>(t.label??"")?1:-1),e.map(e=>L("calcite-list-item",{description:this._getPageSizeLabel(e),key:`template-${e.id}-${e.id===this.templateOptions.id}`,label:this._getTemplateLabel(e),selected:e.id===this.templateOptions.id,title:e.description??"",value:e},L("calcite-icon",{icon:(e.layout?j.get(e.layout):null)||"custom-print",slot:"content-start"}),"loading"===e.state?L("calcite-loader",{inline:!0,key:`template-loader-${e.id}`,label:"loading",scale:"s",slot:"content-end"}):null,"error"===e?.state?L("calcite-icon",{class:R.templateSelectError,icon:"exclamation-mark-circle",key:`template-error-${e.id}`,scale:"s",slot:"content-end"}):null,i?L("calcite-action",{icon:"trash",onclick:()=>this.viewModel.removePortalTemplate(e),slot:"actions-end",text:"delete"}):null))}_renderChooseTemplateFlowItem(){if(!this._showTemplates)return null;const{messages:e}=this,t=g.test(this.portal?.url),i=this.viewModel.browseTemplates.toArray(),a=this._getPortalTemplates(),l=this._getDefaultTemplates(),o=this._getPrintServiceTemplates(),n=i.length+a.length+l.length+o.length>15,s=this.browseTemplateButtonOnClick?L("calcite-button",{appearance:"outline",class:n?R.browseTemplateButtonContainerFilter:R.browseTemplateButtonContainer,iconStart:"folder",key:"browse-template-button",onclick:this.browseTemplateButtonOnClick,slot:n?"filter-actions-end":"default"},n?null:e.browseTemplates):null;return L("calcite-flow-item",{bind:this,closable:!1,heading:e.chooseTemplate,key:"template-flow-item",selected:this._showTemplates,onCalciteFlowItemBack:e=>{e.preventDefault(),this._showTemplates=!1}},L("div",{class:R.templateSelectFlowItemContainer},L("div",{class:R.templateSelectFlowItemContent},n?null:s,L("calcite-list",{filterEnabled:n,filterProps:["label"],key:"template-list",label:e.templateList,selectionMode:"single-persist",onCalciteListChange:({currentTarget:e})=>this.viewModel.applyTemplate(e.selectedItems[0]?.value)},n?s:null,i.length?L("div",{key:"my-templates"},L("div",{class:R.templateSelectFlowItemListHeading},e.myTemplates,t?L("calcite-chip",{appearance:"outline",kind:"neutral",label:e.beta,scale:"s"},e.beta):null),this._renderLayoutTemplates(i,!0,!0)):null,a.length?L("div",{key:"org-templates"},L("div",{class:R.templateSelectFlowItemListHeading},e.organizationTemplates,t?L("calcite-chip",{appearance:"outline",kind:"neutral",label:e.beta,scale:"s"},e.beta):null),this._renderLayoutTemplates(a)):null,i.length||a.length?l.length?L("div",{key:"default-templates"},L("div",{class:R.templateSelectFlowItemListHeading},e.defaultTemplates),this._renderLayoutTemplates(l,!0)):null:this._renderLayoutTemplates(l,!0),i.length||a.length?o.length?L("div",{key:"service-templates"},L("div",{class:R.templateSelectFlowItemListHeading},e.defaultTemplates),this._renderLayoutTemplates(o)):null:this._renderLayoutTemplates(o))),L("div",{class:R.templateButtonContainer},L("calcite-button",{class:R.templateDoneButton,onclick:()=>this._showTemplates=!1},this.messagesCommon.done))))}_renderCustomTextElementSection(){const{customTextElements:e}=this.templateOptions;return e?L("div",{class:R.formSectionContainer,key:"custom-text-elements"},e.map((e,t)=>{const[i,a]=Object.entries(e)[0];return"date"===i?null:L("calcite-label",{key:`custom-text-elements-${i}-${t}`},i,L("calcite-input",{bind:this,"data-input-custom":!0,"data-input-name":i,value:a??"",onCalciteInputInput:this._updateInputValue}))})):null}_renderTitleOrFileNameSection(){const{title:e,fileName:t,titlePlaceHolder:i,fileNamePlaceHolder:a}=this.messages,l="layoutTab"===this._selectedTab?e:t,o="layoutTab"===this._selectedTab?i:a,n="layoutTab"===this._selectedTab?this.templateOptions.title:this.templateOptions.fileName;return L("div",{class:R.formSectionContainer,key:l},L("calcite-label",null,l,L("calcite-input",{placeholder:o,value:n??"",onCalciteInputInput:this._onInput})))}_focusOnTabChange(e){if(!this._activeTabFocusRequested)return;const t=e.getAttribute("data-tab-id");("layoutTab"===t&&"layoutTab"===this._selectedTab||"mapOnlyTab"===t&&"mapOnlyTab"===this._selectedTab||"exportTab"===t&&"exportTab"===this._selectedTab)&&(e.focus(),this._activeTabFocusRequested=!1)}_renderLoader(){const e={[R.loader]:this._awaitingServerResponse};return L("div",{class:this.classes(e),key:"loader"})}_resetToCurrentScale(){this.templateOptions.scale=this.viewModel.view?.scale}_updateCustomTextElementValue(e,t,i){e.find(e=>{const[i]=Object.entries(e)[0];return i===t})[t]=i}_updateInputValue(e){const t=e.currentTarget,i=t.getAttribute("data-input-name"),a=!!t["data-input-custom"],{templateOptions:l}=this;a?this._updateCustomTextElementValue(l.customTextElements,i,t.value):l[i]=t.value}_updateNumberInputValue(e){const t=e.currentTarget,i=t.getAttribute("data-input-name"),{templateOptions:a}=this,l=Number(t.value);if(!B(l)){const e=a[i];return void(t.value=`${e}`)}a[i]=l}_handlePrintMap(){this._pendingExportScroll=!0;const{templateOptions:e}=this,t="layoutTab"===this._selectedTab?e.title:e.fileName,{promise:i}=this.viewModel.export(t||this.messages.untitled);this._selectedTab="exportTab",i.then(()=>this.scheduleRender())}_switchInput(){[this.templateOptions.width,this.templateOptions.height]=[this.templateOptions.height,this.templateOptions.width]}_scrollExportIntoView(){if(!this._pendingExportScroll)return;this._pendingExportScroll=!1;const e=this._rootNode;if(!e)return;const{clientHeight:t,scrollHeight:i}=e,a=i-t;a>0&&(e.scrollTop=a)}_toggleInputValue(e){const t=e.target,i=t.getAttribute("data-option-name");this.templateOptions[i]=t.checked,"scaleEnabled"===i&&this._resetToCurrentScale()}_renderExportedLinkItemPopover(e){const t=this.messages,i=e.formattedName??"",{state:a}=e,l=this.saveAsButtonCallback&&"error"!==a&&this._isFormatAllowedForSaving(e.extension);return"pending"!==a&&l?L("calcite-popover",{autoClose:!0,key:`${i}-popover`,label:"Popover",offsetDistance:1,overlayPositioning:"fixed",pointerDisabled:!0,referenceElement:`${i}-popover-button`,scale:"s"},L("calcite-list",{label:""},e.portalItem?L("calcite-list-item",{label:t.openItem,onCalciteListItemSelect:()=>{const t=e.portalItem;if(!t||!t.itemPageUrl)return;const i=document.createElement("a");i.target="_blank",i.href=t.itemPageUrl,i.rel="noreferrer",i.click()}},L("calcite-icon",{icon:"launch2",key:`${i}-launch-icon`,scale:"s",slot:"content-start"})):L("calcite-list-item",{label:t.saveAs,onCalciteListItemSelect:async()=>{this.saveAsButtonCallback&&(r(()=>e.portalItem).then(e=>{e.itemPageUrl&&this.scheduleRender()}),await this.saveAsButtonCallback(e))}},L("calcite-icon",{icon:"save",key:`${i}-save-icon`,scale:"s",slot:"content-start"})),L("calcite-list-item",{label:this.messagesCommon.delete,onCalciteListItemSelect:()=>this.exportedLinks.remove(e)},L("calcite-icon",{icon:"trash",key:`${i}-delete-icon`,scale:"s",slot:"content-start"})))):null}_renderExportedLinkItemContent(e){const t=this.messages,{url:i,state:a,error:l}=e,o=e.formattedName??"";let n=i||null;n&&(n=p(n));const s=d(n,location.href),r="error"===a?"print-task:cim-symbol-unsupported"===l?.name?t.exportWebMapCIMError:t.exportWebMapError:null;return L("div",{class:R.exportedFile,"data-item":e,onclick:this._handleLinkClick,slot:"content"},L("div",null,L("div",{class:R.exportedFileLinkTitle},o),L("div",{class:R.exportedFileLinkDescription},"pending"===a?t.generatingExport:r||(s?t.ready:t.linkReady))),"ready"===a?L("calcite-icon",{"aria-label":`${o}. ${t.linkReady}`,icon:s?"download-to":"launch",key:`${o}-end-icon`,scale:"s",slot:"content-end"}):null)}_renderExportedLinkItemIcon(e){const t=e.formattedName??"";return"pending"===e.state?L("calcite-loader",{class:R.exportedFileLoader,inline:!0,key:`${t}-loader`,label:this.messages.generatingExport,scale:"m",slot:"content-start"}):L("calcite-icon",{icon:V(e),key:`${t}-start-icon`,scale:"s",slot:"content-start"})}_renderExportedLinkItemAction(e){const{state:t}=e,i=e.formattedName??"",a=this.saveAsButtonCallback&&"error"!==t&&this._isFormatAllowedForSaving(e.extension);return"pending"!==t?L("calcite-action",{icon:a?"ellipsis":"x",id:a?`${i}-popover-button`:void 0,key:a?`${i}-saveAs-action`:`${i}-action`,onclick:a?void 0:()=>{this.exportedLinks.remove(e)},slot:"actions-end",text:a?this.messagesCommon.options:this.messagesCommon.remove}):null}_renderExportedLinkItem(e){const t=e.formattedName??"";return L(M,null,L("calcite-list-item",{key:t,label:t},this._renderExportedLinkItemContent(e),this._renderExportedLinkItemIcon(e),this._renderExportedLinkItemAction(e)),this._renderExportedLinkItemPopover(e))}_renderExportedLinkItems(e){return L("calcite-list",{filterEnabled:e?.length>10,label:this.messages.exportedLinksList,selectionMode:"none"},e.map(this._renderExportedLinkItem.bind(this)))}_isFormatAllowedForSaving(e){return!this.allowedFormatsForSaving||"all"===this.allowedFormatsForSaving||!(!e||!this.allowedFormatsForSaving.includes(e))}_toggleLayoutPanel(e){const t=e.target;this._toggleTab(t.getAttribute("data-tab-id"))}_toggleTab(e,t=!0){if(this._selectedTab=e,"mapOnlyTab"===this._selectedTab)this.viewModel.applyTemplate(P);else if("layoutTab"===this._selectedTab){const e=this._selectedTemplate??this.viewModel.defaultTemplate;this.viewModel.applyTemplate(e)}t&&(this._activeTabFocusRequested=!0)}_handleLayoutPanelKeyDown(e){const{key:t}=e,i=e.target.getAttribute("data-tab-id");if(F(t))return this._toggleTab(i),e.preventDefault(),void e.stopPropagation();if("ArrowLeft"===t||"ArrowRight"===t){switch(i){case"layoutTab":this._toggleTab("ArrowLeft"===t?"exportTab":"mapOnlyTab");break;case"mapOnlyTab":this._toggleTab("ArrowLeft"===t?"layoutTab":"exportTab");break;case"exportTab":this._toggleTab("ArrowLeft"===t?"mapOnlyTab":"layoutTab")}e.preventDefault(),e.stopPropagation()}}};e([m()],U.prototype,"_showTemplates",void 0),e([m()],U.prototype,"_isValidSpatialReference",void 0),e([m()],U.prototype,"allowedFormats",null),e([m()],U.prototype,"allowedFormatsForSaving",void 0),e([m()],U.prototype,"allowedLayouts",null),e([m()],U.prototype,"browseTemplateButtonOnClick",void 0),e([m()],U.prototype,"error",null),e([m({type:i.ofType(w)})],U.prototype,"exportedLinks",null),e([m()],U.prototype,"extraParameters",null),e([m()],U.prototype,"headerVisible",void 0),e([m()],U.prototype,"headingLevel",void 0),e([m()],U.prototype,"icon",null),e([m()],U.prototype,"includeDefaultTemplates",null),e([m()],U.prototype,"includeOrganizationTemplates",void 0),e([m()],U.prototype,"label",null),e([m(),E("esri/widgets/Print/t9n/Print")],U.prototype,"messages",void 0),e([m(),E("esri/t9n/common")],U.prototype,"messagesCommon",void 0),e([m(),E("esri/core/t9n/Units")],U.prototype,"messagesUnits",void 0),e([m({type:b})],U.prototype,"outSpatialReference",null),e([m({type:v})],U.prototype,"portal",null),e([m()],U.prototype,"saveExportEnabled",null),e([m()],U.prototype,"saveExportHidden",void 0),e([m()],U.prototype,"showPrintAreaEnabled",null),e([m()],U.prototype,"printServiceUrl",null),e([m()],U.prototype,"saveAsButtonCallback",void 0),e([m()],U.prototype,"templateCustomTextElements",null),e([m({type:x})],U.prototype,"templateOptions",null),e([m()],U.prototype,"view",null),e([m({type:k})],U.prototype,"viewModel",void 0),U=e([u("esri.widgets.Print")],U);const H=U;export{H as default};
5
+ import{__decorate as e}from"tslib";import{formatNumber as t}from"../intl.js";import i from"../core/Collection.js";import{deprecateWidget as a}from"../core/deprecate.js";import{JSONMap as l}from"../core/jsonMap.js";import o from"../core/Logger.js";import{watch as n,on as s,whenOnce as r}from"../core/reactiveUtils.js";import{unitName as c}from"../core/unitFormatUtils.js";import{addProxy as p,hasSameOrigin as d}from"../core/urlUtils.js";import{property as m,subclass as u}from"../core/accessorSupport/decorators.js";import{ensureInteger as h}from"../core/accessorSupport/ensureType.js";import b from"../geometry/SpatialReference.js";import{isValid as _}from"../geometry/support/spatialReferenceUtils.js";import v from"../portal/Portal.js";import{reArcGISOnlineDomain as g}from"../portal/support/urlUtils.js";import{findToken as f}from"../rest/utils.js";import{formatJsonMap as y}from"../rest/support/fileFormat.js";import T from"./Widget.js";import w from"./Print/FileLink.js";import k from"./Print/PrintViewModel.js";import x from"./Print/TemplateOptions.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{globalCss as S}from"./support/globalCss.js";import{Heading as I}from"./support/Heading.js";import{legacyIcon as O}from"./support/legacyIcon.js";import{messageBundle as E,tsx as L,isRTL as $,tsxFragment as F,isActivationKey as M}from"./support/widget.js";const P="map-only",A="esri-print",R={base:A,headerTitle:`${A}__header-title`,layoutTabList:`${A}__layout-tab-list`,layoutTab:`${A}__layout-tab`,layoutSection:`${A}__layout-section`,mapOnlySection:`${A}__map-only-section`,panelItemsCentered:`${A}__panel-items--centered`,loader:`${A}__loader`,swapButton:`${A}__swap-button`,printButton:`${A}__export-button`,printButtonSection:`${A}__export-button-section`,printButtonSectionDivider:`${A}__export-button-section--divider`,templateSelectContainer:`${A}__template-select-container`,templateSelectIcon:`${A}__template-select-icon`,templateSelectError:`${A}__template-select-error`,templateSelectArrow:`${A}__template-select-arrow`,formSectionContainer:`${A}__form-section-container`,advancedOptionsSection:`${A}__advanced-options-section`,advancedOptionsContainer:`${A}__advanced-options-container`,browseTemplateButtonContainer:`${A}__browse-template-button-container`,browseTemplateButtonContainerFilter:`${A}__browse-template-button-container-filter`,exportedFilesContainer:`${A}__export-panel-container`,exportedFilesTitle:`${A}__export-title`,exportedFile:`${A}__exported-file`,exportedFileLinkTitle:`${A}__exported-file-link-title`,exportedFileLinkDescription:`${A}__exported-file-link-description`,exportedFilesEmpty:`${A}__exported-files-empty`,printWidgetContainer:`${A}__container`,content:`${A}__content`,panelContainer:`${A}__panel-container`,scaleInfoContainer:`${A}__scale-info-container`,scaleInputContainer:`${A}__scale-input-container`,scaleInput:`${A}__scale-input`,sizeContainer:`${A}__size-container`,panelError:`${A}__panel--error`,exportedFileLoader:`${A}__exported-file--loader`,exportSection:`${A}__export-section`,exportSectionCentered:`${A}__export-section--centered`,templateButtonContainer:`${A}__template-button-container`,templateDoneButton:`${A}__template-done-button`,templateSelectFlowItemContainer:`${A}__template-select-flow-item-container`,templateSelectFlowItemContent:`${A}__template-select-flow-item-content`,templateSelectFlowItemListHeading:`${A}__template-select-flow-item-list-heading`,srLabel:`${A}__sr-label`,invalidWkidText:`${A}__invalid-wkid-text`};function B(e){return!isNaN(e)&&e>0&&Number.isFinite(e)}function N(e){return e?.toLowerCase()===P}function V(e){const{state:t,extension:i}=e;switch(t){case"pending":return"spinner";case"error":return"exclamation-mark-circle";default:return i?.toLowerCase()?.includes("pdf")?"file-pdf":"file"}}const D=new l({inch:"inches",foot:"feet",yard:"yards",mile:"miles","nautical-mile":"nautical-miles",millimeter:"millimeters",centimeter:"centimeters",decimeter:"decimeters",meter:"meters",kilometer:"kilometers"}),j=new Map([["a3-landscape","a3-landscape"],["a3-portrait","a3-portrait"],["a4-landscape","a4-landscape"],["a4-portrait","a4-portrait"],["letter-ansi-a-landscape","ansi-a-landscape"],["letter-ansi-a-portrait","ansi-a-portrait"],["tabloid-ansi-b-landscape","ansi-b-landscape"],["tabloid-ansi-b-portrait","ansi-b-portrait"]]);let U=class extends T{constructor(e,t){super(e,t),this._activeTabFocusRequested=!1,this._awaitingServerResponse=!1,this._selectedTab="layoutTab",this._pendingExportScroll=!1,this._rootNode=null,this._selectedTemplate=null,this._formats=[],this._showTemplates=!1,this._isValidSpatialReference=!0,this.allowedFormatsForSaving=null,this.browseTemplateButtonOnClick=null,this.headerVisible=!0,this.headingLevel=3,this.includeOrganizationTemplates=!0,this.messagesCommon=null,this.messagesUnits=null,this.saveExportHidden=!0,this.saveAsButtonCallback=null,this.viewModel=new k,this._onInput=e=>{"layoutTab"===this._selectedTab?this.templateOptions.title=e.currentTarget.value:"mapOnlyTab"===this._selectedTab&&(this.templateOptions.fileName=e.currentTarget.value)},this._handleLinkClick=e=>{const t=e.currentTarget["data-item"];if(!t||"ready"!==t.state||!t.url)return;const i=f(this.viewModel.effectivePrintServiceUrl),a=t.url,l=document.createElement("a");if(l.target="_blank",l.href=a,l.rel="noreferrer",l.download=t.formattedName??"",!i)return l.click(),void e.stopPropagation();e.preventDefault();const o=new URL(a);o.searchParams.set("token",i),l.href=o.href,l.click(),l.href=a},a(o.getLogger(this),"Print","arcgis-print",{version:"4.33"}),this._focusOnTabChange=this._focusOnTabChange.bind(this)}initialize(){this.addHandles([n(()=>[this.templateOptions.format,this.viewModel.templatesInfo?.format],()=>{const{templatesInfo:e}=this.viewModel;if(!e)return;if(this._formats.length!==e.format.choiceList.length){const t=y.apiValues;this._formats=e.format.choiceList.map(e=>{const i=t.find(t=>new RegExp(`\\b${t}\\b`,"i").test(e))??e;return{value:i,label:e===i?e.toUpperCase():e}}).sort((e,t)=>e.label.localeCompare(t.label))}const t=this._formats.some(({value:e})=>new RegExp(`\\b${e}\\b`,"i").test(this.templateOptions.format));if(e.format.defaultValue&&!t){const t=this._formats.find(({value:t})=>new RegExp(`\\b${t}\\b`,"i").test(e.format.defaultValue))?.value;return void(t&&(this.templateOptions.format=t))}}),n(()=>[this.templateOptions.id,this.viewModel.loaded],()=>{const{layout:e}=this.templateOptions;this._selectedTab=N(e)?"mapOnlyTab":"layoutTab","layoutTab"===this._selectedTab&&this.viewModel.loaded&&(this._selectedTemplate=this.viewModel.getLayoutTemplateById(this.templateOptions.id))}),n(()=>this.templateOptions.dpi,e=>{e<=0&&(this.templateOptions.dpi=1)}),n(()=>this.viewModel.view?.scale,e=>{!e||this.templateOptions.scaleEnabled&&this.templateOptions.scale||(this.templateOptions.scale=e)}),s(()=>this.viewModel,"submit",e=>this.emit("submit",e)),s(()=>this.viewModel,"complete",e=>this.emit("complete",e))]);const{height:e,width:t}=this.templateOptions;this.templateOptions.width=t||800,this.templateOptions.height=e||1100;const i=setTimeout(()=>{this._awaitingServerResponse=!0,this.scheduleRender()},500);this.viewModel.load().then(()=>{clearTimeout(i),this._awaitingServerResponse=!1})}loadDependencies(){return C({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),block:()=>import("@esri/calcite-components/dist/components/calcite-block"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),checkbox:()=>import("@esri/calcite-components/dist/components/calcite-checkbox"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch"),chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),popover:()=>import("@esri/calcite-components/dist/components/calcite-popover"),link:()=>import("@esri/calcite-components/dist/components/calcite-link")})}destroy(){this.viewModel.destroy()}get allowedFormats(){return this.viewModel.allowedFormats}set allowedFormats(e){this.viewModel.allowedFormats=e}get allowedLayouts(){return this.viewModel.allowedLayouts}set allowedLayouts(e){this.viewModel.allowedLayouts=e}get error(){return this.viewModel.error}get exportedLinks(){return this.viewModel.exportedLinks}set exportedLinks(e){this.viewModel.exportedLinks=e}get extraParameters(){return this.viewModel.extraParameters}set extraParameters(e){this.viewModel.extraParameters=e}get icon(){return"print"}set icon(e){this._overrideIfSome("icon",e)}get includeDefaultTemplates(){return this.viewModel.includeDefaultTemplates}set includeDefaultTemplates(e){this.viewModel.includeDefaultTemplates=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get outSpatialReference(){return this.viewModel.outSpatialReference}set outSpatialReference(e){this.viewModel.outSpatialReference=e}get portal(){return this.viewModel.portal}set portal(e){this.viewModel.portal=e}get saveExportEnabled(){return this.viewModel.saveExportEnabled}set saveExportEnabled(e){this.viewModel.saveExportEnabled=e}get showPrintAreaEnabled(){return this.viewModel.showPrintAreaEnabled}set showPrintAreaEnabled(e){this.viewModel.showPrintAreaEnabled=e}get printServiceUrl(){return this.viewModel.printServiceUrl}set printServiceUrl(e){this.viewModel.printServiceUrl=e}get templateCustomTextElements(){return this.viewModel.templateCustomTextElements}set templateCustomTextElements(e){this.viewModel.templateCustomTextElements=e}get templateOptions(){return this.viewModel.templateOptions}set templateOptions(e){this.viewModel.templateOptions=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}render(){const{messages:e,templateOptions:t,viewModel:i,view:a}=this,{attributionEnabled:l,author:o,copyright:n,dpi:s,format:r,height:c,layout:p,layoutItem:d,legendEnabled:m,northArrowEnabled:u,scaleBarEnabled:v,scaleEnabled:g,scale:f,width:y}=t,T="ready"!==i.state||this._awaitingServerResponse||!(p||d),w=this._renderTitleOrFileNameSection(),k=L("div",{class:R.formSectionContainer},L("calcite-label",null,e.fileFormatTitle,L("calcite-combobox",{clearDisabled:!0,label:e.formatDefaultOption,maxItems:6,placeholder:e.formatDefaultOption,selectionMode:"single-persist",onCalciteComboboxChange:({currentTarget:e})=>{this.templateOptions.format=e.selectedItems[0]?.value??"pdf"}},this._formats.map(({value:e,label:t},i)=>L("calcite-combobox-item",{key:`file-format-${i}`,selected:e===this.templateOptions.format,textLabel:t,value:e}))))),x=L("calcite-label",{layout:"inline"},L("calcite-switch",{checked:this.showPrintAreaEnabled,onCalciteSwitchChange:e=>{this.showPrintAreaEnabled=!!e.currentTarget.checked}}),e.printPreview),C=L("div",null,L("div",{class:R.formSectionContainer},L("calcite-label",null,e.template,L("calcite-block",{class:R.templateSelectContainer,collapsible:!1,description:this._getPageSizeLabel(this._selectedTemplate),heading:this._getTemplateLabel(this._selectedTemplate,!0),key:"template-select-block",label:e.template,loading:"loading"===this._selectedTemplate?.state,onclick:()=>this._showTemplates=!0,onkeydown:e=>{"Enter"!==e.key&&" "!==e.key||(this._showTemplates=!0)},tabIndex:0},L("calcite-icon",{class:R.templateSelectIcon,icon:(this._selectedTemplate?.layout?j.get(this._selectedTemplate.layout):null)||"custom-print",key:"template-select-icon",scale:"l",slot:"content-start"}),"error"===this._selectedTemplate?.state?L("calcite-icon",{class:R.templateSelectError,icon:"exclamation-mark-circle",key:"template-select-error",scale:"s",slot:"actions-end"}):null,L("calcite-icon",{class:R.templateSelectArrow,icon:$()?"chevron-left":"chevron-right",key:"template-select-arrow",scale:"s",slot:"actions-end"})))),x),E=L("div",{class:R.formSectionContainer},L("calcite-label",null,e.dpi,L("calcite-input-number",{bind:this,"data-input-name":"dpi",min:1,value:`${s}`,onCalciteInputNumberInput:this._updateNumberInputValue}))),F=L("div",{class:R.formSectionContainer},L("calcite-label",null,L("div",{class:R.srLabel},e.outSpatialReference,L("calcite-link",{href:"https://developers.arcgis.com/rest/services-reference/enterprise/using-spatial-references/",target:"_blank"},"(WKID)")),L("calcite-input-number",{bind:this,"data-input-name":"outSpatialReference",integer:!0,numberButtonType:"none",value:i.outSpatialReference?.wkid?.toString()??"",onCalciteInputNumberInput:({currentTarget:e})=>{const t=h(e.value);i.outSpatialReference=Number.isNaN(t)||null==t?null:new b({wkid:t}),this._isValidSpatialReference=!i.outSpatialReference||_(i.outSpatialReference)}}),this._isValidSpatialReference?null:L("div",{class:R.invalidWkidText,key:`out-sr-${i.outSpatialReference?.wkid}`},e.invalidWkid))),M=L("div",{class:this.classes(R.scaleInfoContainer,R.formSectionContainer)},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:g,"data-option-name":"scaleEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.scale),L("div",{class:R.scaleInputContainer},L("calcite-input-number",{"aria-label":e.scaleLabel,"aria-valuenow":`${f}`,bind:this,class:R.scaleInput,"data-input-name":"scale",disabled:!g,value:`${f}`,onCalciteInputNumberInput:this._updateNumberInputValue}),L("calcite-button",{appearance:"outline","aria-label":e.reset,bind:this,disabled:!g,iconStart:"refresh",kind:"neutral",onclick:this._resetToCurrentScale}))),P=L("div",{"aria-labelledby":`${this.id}__advancedOptionsForLayout`,class:R.advancedOptionsContainer,key:"advanced-section-for-layout"},M,this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasAuthorText??1?L("div",{class:R.formSectionContainer,key:"author-info"},L("calcite-label",null,e.author,L("calcite-input",{bind:this,"data-input-name":"author",value:o??"",onCalciteInputInput:this._updateInputValue}))):null,this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasCopyrightText??1?L("div",{class:R.formSectionContainer,key:"copyright-text"},L("calcite-label",null,e.copyright,L("calcite-input",{bind:this,"data-input-name":"copyright",value:n??"",onCalciteInputInput:this._updateInputValue}))):null,E,F,this._renderCustomTextElementSection(),this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasLegend??1?L("div",{class:R.formSectionContainer,key:"legend-info"},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:!!m,"data-option-name":"legendEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.legend)):null,this._selectedTemplate?.mapSurroundInfoOptions?.northArrow.length?L("div",{class:R.formSectionContainer,key:"north-arrow"},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:!!u,"data-option-name":"northArrowEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.northArrow)):null,this._selectedTemplate?.mapSurroundInfoOptions?.scaleBar.length?L("div",{class:R.formSectionContainer,key:"scale-bar"},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:!!v,"data-option-name":"scaleBarEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.scaleBar)):null),A=L("div",{"aria-labelledby":`${this.id}__advancedOptionsForMapOnly`,class:R.advancedOptionsContainer},M,E,F,L("div",{class:R.formSectionContainer},L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:l,"data-option-name":"attributionEnabled",onCalciteCheckboxChange:this._toggleInputValue}),e.attribution)),this._renderCustomTextElementSection()),B=this.exportedLinks.toArray(),N=this._renderExportedLinkItems(B),V={[R.exportSectionCentered]:!B.length},D="layoutTab"===this._selectedTab?L("section",{"aria-labelledby":`${this.id}__layoutTab`,class:R.layoutSection,id:`${this.id}__layoutContent`,key:"esri-print__layoutContent",role:"tabpanel"},L("div",{class:R.panelContainer},this._selectedTemplate?.layoutTemplateInfo?.layoutOptions?.hasTitleText??1?w:null,C,"layoutTab"===this._selectedTab?k:null,L("calcite-block",{"aria-label":e.advancedOptions,class:this.classes(R.panelContainer,R.advancedOptionsSection),collapsible:!0,disabled:!(p||d?.id),heading:e.advancedOptions,id:"advancedOptionsForLayout",key:"advanced-options-for-layout"},P))):"mapOnlyTab"===this._selectedTab?L("section",{"aria-labelledby":`${this.id}__mapOnlyTab`,class:R.mapOnlySection,id:`${this.id}__mapOnlyContent`,key:"esri-print__mapOnlyContent",role:"tabpanel"},L("div",{class:R.panelContainer},w,k,L("div",null,L("div",{class:this.classes(R.sizeContainer,R.formSectionContainer)},L("calcite-label",null,e.width,L("calcite-input-number",{bind:this,"data-input-name":"width",value:`${y}`,onCalciteInputNumberInput:this._updateNumberInputValue})),L("calcite-label",null,e.height,L("calcite-input-number",{bind:this,"data-input-name":"height",value:`${c}`,onCalciteInputNumberInput:this._updateNumberInputValue})),L("button",{"aria-label":e.swap,bind:this,class:this.classes(S.widgetButton,R.swapButton,O.swap),onclick:this._switchInput,type:"button"})),x),L("calcite-block",{"aria-label":e.advancedOptions,class:this.classes(R.panelContainer,R.advancedOptionsSection),collapsible:!0,heading:e.advancedOptions,id:"advancedOptionsForMapOnly",key:"advanced-options-for-map-only"},A))):L("section",{"aria-labelledby":`${this.id}__exportTab`,class:this.classes(R.exportSection,V),id:`${this.id}__exportContent`,key:"esri-print__exportContent",role:"tabpanel"},L("div",{class:R.panelContainer},L("div",{afterUpdate:this._scrollExportIntoView,bind:this,class:R.exportedFilesContainer},0===B.length?L("div",{class:R.exportedFilesEmpty},L("calcite-icon",{icon:"file",scale:"l"}),L("div",null,L(I,{class:R.exportedFilesTitle,level:this.headingLevel},e.noExportedFiles),L("div",null,e.exportHint))):N))),U="2d"!==a?.type,H=L("div",{class:R.panelError},a?U?e.sceneViewError:e.serviceError:e.noViewError),z=B.some(({state:e})=>"pending"===e),W=L("div",{class:R.content,key:"panel"},L("div",null,L("ul",{bind:this,class:R.layoutTabList,onclick:this._toggleLayoutPanel,onkeydown:this._handleLayoutPanelKeyDown,role:"tablist"},L("li",{afterCreate:this._focusOnTabChange,afterUpdate:this._focusOnTabChange,"aria-selected":`${"layoutTab"===this._selectedTab}`,class:R.layoutTab,"data-tab-id":"layoutTab",id:`${this.id}__layoutTab`,role:"tab",tabIndex:0},e.layoutTab),L("li",{afterCreate:this._focusOnTabChange,afterUpdate:this._focusOnTabChange,"aria-selected":`${"mapOnlyTab"===this._selectedTab}`,class:R.layoutTab,"data-tab-id":"mapOnlyTab",id:`${this.id}__mapOnlyTab`,role:"tab",tabIndex:0},e.mapOnlyTab),L("li",{afterCreate:this._focusOnTabChange,afterUpdate:this._focusOnTabChange,"aria-selected":`${"exportTab"===this._selectedTab}`,class:R.layoutTab,"data-tab-id":"exportTab",id:`${this.id}__exportedFilesTab`,role:"tab",tabIndex:0},z?L("calcite-loader",{inline:!0,label:"loading",scale:"s"}):null,e.exportsTab)),D),"exportTab"!==this._selectedTab?L("div",{class:this.classes(R.printButtonSection,!this.saveExportHidden&&this.portal?R.printButtonSectionDivider:null),key:"export-button-section"},!this.saveExportHidden&&this.portal?L("calcite-label",{layout:"inline"},L("calcite-checkbox",{bind:this,checked:this.saveExportEnabled,onCalciteCheckboxChange:e=>{this.saveExportEnabled=!!e.currentTarget.checked}}),e.saveExportToMyContent):null,L("calcite-button",{"aria-label":e.exportDescription,bind:this,class:this.classes(R.printButton),disabled:T||!(p||d?.id)&&!r,onclick:this._handlePrintMap,scale:"l",width:"full"},e.export)):null),q=L("calcite-flow",{key:"root-flow"},L("calcite-flow-item",{bind:this,key:"root-flow-item",selected:!this._showTemplates},L("div",{class:R.printWidgetContainer},this.headerVisible?L("header",{class:R.headerTitle},e.export):null,this.error||U||!a?H:W)),this._renderChooseTemplateFlowItem()),K="initializing"===i.state,J=K?this._renderLoader():q,G={[R.panelItemsCentered]:K};return L("div",{bind:this,class:this.classes(R.base,S.widget,S.panel,G)},J)}_getPageSizeLabel(e){if(!e)return;const i=e.layoutTemplateInfo;if(!i)return;const a=D.fromJSON(i.pageUnits.toLowerCase());return`${t(i.pageSize[0])} × ${t(i.pageSize[1])} ${c(this.messagesUnits,a,"abbr")}`}_getTemplateLabel(e,t=!1){if(!e)return t?this.messages.selectTemplate:this.messages.untitled;const{label:i,layout:a,layoutItem:l}=e,o=a&&!l&&this.messages[a]?this.messages[a]:null;if(o)return o;const n=i??a??l?.id;return n?.replaceAll("_"," ")??this.messages.untitled}_getPortalTemplates(){return this.includeDefaultTemplates&&this.includeOrganizationTemplates?this.viewModel.defaultTemplates.toArray().filter(({layout:e,layoutItem:t})=>!N(e)&&!!t?.id):[]}_getDefaultTemplates(){return this.includeDefaultTemplates?this.viewModel.defaultTemplates.toArray().filter(({layout:e,layoutItem:t})=>!N(e)&&!t?.id):[]}_getPrintServiceTemplates(){return this.includeDefaultTemplates&&this._getDefaultTemplates().length?[]:this.viewModel.printServiceTemplates.toArray().filter(({layout:e})=>!N(e))}_renderLayoutTemplates(e,t=!1,i=!1){return t&&e.sort((e,t)=>(e.label??"")>(t.label??"")?1:-1),e.map(e=>L("calcite-list-item",{description:this._getPageSizeLabel(e),key:`template-${e.id}-${e.id===this.templateOptions.id}`,label:this._getTemplateLabel(e),selected:e.id===this.templateOptions.id,title:e.description??"",value:e},L("calcite-icon",{icon:(e.layout?j.get(e.layout):null)||"custom-print",slot:"content-start"}),"loading"===e.state?L("calcite-loader",{inline:!0,key:`template-loader-${e.id}`,label:"loading",scale:"s",slot:"content-end"}):null,"error"===e?.state?L("calcite-icon",{class:R.templateSelectError,icon:"exclamation-mark-circle",key:`template-error-${e.id}`,scale:"s",slot:"content-end"}):null,i?L("calcite-action",{icon:"trash",onclick:()=>this.viewModel.removePortalTemplate(e),slot:"actions-end",text:"delete"}):null))}_renderChooseTemplateFlowItem(){if(!this._showTemplates)return null;const{messages:e}=this,t=g.test(this.portal?.url),i=this.viewModel.browseTemplates.toArray(),a=this._getPortalTemplates(),l=this._getDefaultTemplates(),o=this._getPrintServiceTemplates(),n=i.length+a.length+l.length+o.length>15,s=this.browseTemplateButtonOnClick?L("calcite-button",{appearance:"outline",class:n?R.browseTemplateButtonContainerFilter:R.browseTemplateButtonContainer,iconStart:"folder",key:"browse-template-button",onclick:this.browseTemplateButtonOnClick,slot:n?"filter-actions-end":"default"},n?null:e.browseTemplates):null;return L("calcite-flow-item",{bind:this,closable:!1,heading:e.chooseTemplate,key:"template-flow-item",selected:this._showTemplates,onCalciteFlowItemBack:e=>{e.preventDefault(),this._showTemplates=!1}},L("div",{class:R.templateSelectFlowItemContainer},L("div",{class:R.templateSelectFlowItemContent},n?null:s,L("calcite-list",{filterEnabled:n,filterProps:["label"],key:"template-list",label:e.templateList,selectionMode:"single-persist",onCalciteListChange:({currentTarget:e})=>this.viewModel.applyTemplate(e.selectedItems[0]?.value)},n?s:null,i.length?L("div",{key:"my-templates"},L("div",{class:R.templateSelectFlowItemListHeading},e.myTemplates,t?L("calcite-chip",{appearance:"outline",kind:"neutral",label:e.beta,scale:"s"},e.beta):null),this._renderLayoutTemplates(i,!0,!0)):null,a.length?L("div",{key:"org-templates"},L("div",{class:R.templateSelectFlowItemListHeading},e.organizationTemplates,t?L("calcite-chip",{appearance:"outline",kind:"neutral",label:e.beta,scale:"s"},e.beta):null),this._renderLayoutTemplates(a)):null,i.length||a.length?l.length?L("div",{key:"default-templates"},L("div",{class:R.templateSelectFlowItemListHeading},e.defaultTemplates),this._renderLayoutTemplates(l,!0)):null:this._renderLayoutTemplates(l,!0),i.length||a.length?o.length?L("div",{key:"service-templates"},L("div",{class:R.templateSelectFlowItemListHeading},e.defaultTemplates),this._renderLayoutTemplates(o)):null:this._renderLayoutTemplates(o))),L("div",{class:R.templateButtonContainer},L("calcite-button",{class:R.templateDoneButton,onclick:()=>this._showTemplates=!1},this.messagesCommon.done))))}_renderCustomTextElementSection(){const{customTextElements:e}=this.templateOptions;return e?L("div",{class:R.formSectionContainer,key:"custom-text-elements"},e.map((e,t)=>{const[i,a]=Object.entries(e)[0];return"date"===i?null:L("calcite-label",{key:`custom-text-elements-${i}-${t}`},i,L("calcite-input",{bind:this,"data-input-custom":!0,"data-input-name":i,value:a??"",onCalciteInputInput:this._updateInputValue}))})):null}_renderTitleOrFileNameSection(){const{title:e,fileName:t,titlePlaceHolder:i,fileNamePlaceHolder:a}=this.messages,l="layoutTab"===this._selectedTab?e:t,o="layoutTab"===this._selectedTab?i:a,n="layoutTab"===this._selectedTab?this.templateOptions.title:this.templateOptions.fileName;return L("div",{class:R.formSectionContainer,key:l},L("calcite-label",null,l,L("calcite-input",{placeholder:o,value:n??"",onCalciteInputInput:this._onInput})))}_focusOnTabChange(e){if(!this._activeTabFocusRequested)return;const t=e.getAttribute("data-tab-id");("layoutTab"===t&&"layoutTab"===this._selectedTab||"mapOnlyTab"===t&&"mapOnlyTab"===this._selectedTab||"exportTab"===t&&"exportTab"===this._selectedTab)&&(e.focus(),this._activeTabFocusRequested=!1)}_renderLoader(){const e={[R.loader]:this._awaitingServerResponse};return L("div",{class:this.classes(e),key:"loader"})}_resetToCurrentScale(){this.templateOptions.scale=this.viewModel.view?.scale}_updateCustomTextElementValue(e,t,i){e.find(e=>{const[i]=Object.entries(e)[0];return i===t})[t]=i}_updateInputValue(e){const t=e.currentTarget,i=t.getAttribute("data-input-name"),a=!!t["data-input-custom"],{templateOptions:l}=this;a?this._updateCustomTextElementValue(l.customTextElements,i,t.value):l[i]=t.value}_updateNumberInputValue(e){const t=e.currentTarget,i=t.getAttribute("data-input-name"),{templateOptions:a}=this,l=Number(t.value);if(!B(l)){const e=a[i];return void(t.value=`${e}`)}a[i]=l}_handlePrintMap(){this._pendingExportScroll=!0;const{templateOptions:e}=this,t="layoutTab"===this._selectedTab?e.title:e.fileName,{promise:i}=this.viewModel.export(t||this.messages.untitled);this._selectedTab="exportTab",i.then(()=>this.scheduleRender())}_switchInput(){[this.templateOptions.width,this.templateOptions.height]=[this.templateOptions.height,this.templateOptions.width]}_scrollExportIntoView(){if(!this._pendingExportScroll)return;this._pendingExportScroll=!1;const e=this._rootNode;if(!e)return;const{clientHeight:t,scrollHeight:i}=e,a=i-t;a>0&&(e.scrollTop=a)}_toggleInputValue(e){const t=e.target,i=t.getAttribute("data-option-name");this.templateOptions[i]=t.checked,"scaleEnabled"===i&&this._resetToCurrentScale()}_renderExportedLinkItemPopover(e){const t=this.messages,i=e.formattedName??"",{state:a}=e,l=this.saveAsButtonCallback&&"error"!==a&&this._isFormatAllowedForSaving(e.extension);return"pending"!==a&&l?L("calcite-popover",{autoClose:!0,key:`${i}-popover`,label:"Popover",offsetDistance:1,overlayPositioning:"fixed",pointerDisabled:!0,referenceElement:`${i}-popover-button`,scale:"s"},L("calcite-list",{label:""},e.portalItem?L("calcite-list-item",{label:t.openItem,onCalciteListItemSelect:()=>{const t=e.portalItem;if(!t||!t.itemPageUrl)return;const i=document.createElement("a");i.target="_blank",i.href=t.itemPageUrl,i.rel="noreferrer",i.click()}},L("calcite-icon",{icon:"launch2",key:`${i}-launch-icon`,scale:"s",slot:"content-start"})):L("calcite-list-item",{label:t.saveAs,onCalciteListItemSelect:async()=>{this.saveAsButtonCallback&&(r(()=>e.portalItem).then(e=>{e.itemPageUrl&&this.scheduleRender()}),await this.saveAsButtonCallback(e))}},L("calcite-icon",{icon:"save",key:`${i}-save-icon`,scale:"s",slot:"content-start"})),L("calcite-list-item",{label:this.messagesCommon.delete,onCalciteListItemSelect:()=>this.exportedLinks.remove(e)},L("calcite-icon",{icon:"trash",key:`${i}-delete-icon`,scale:"s",slot:"content-start"})))):null}_renderExportedLinkItemContent(e){const t=this.messages,{url:i,state:a,error:l}=e,o=e.formattedName??"";let n=i||null;n&&(n=p(n));const s=d(n,location.href),r="error"===a?"print-task:cim-symbol-unsupported"===l?.name?t.exportWebMapCIMError:t.exportWebMapError:null;return L("div",{class:R.exportedFile,"data-item":e,onclick:this._handleLinkClick,slot:"content"},L("div",null,L("div",{class:R.exportedFileLinkTitle},o),L("div",{class:R.exportedFileLinkDescription},"pending"===a?t.generatingExport:r||(s?t.ready:t.linkReady))),"ready"===a?L("calcite-icon",{"aria-label":`${o}. ${t.linkReady}`,icon:s?"download-to":"launch",key:`${o}-end-icon`,scale:"s",slot:"content-end"}):null)}_renderExportedLinkItemIcon(e){const t=e.formattedName??"";return"pending"===e.state?L("calcite-loader",{class:R.exportedFileLoader,inline:!0,key:`${t}-loader`,label:this.messages.generatingExport,scale:"m",slot:"content-start"}):L("calcite-icon",{icon:V(e),key:`${t}-start-icon`,scale:"s",slot:"content-start"})}_renderExportedLinkItemAction(e){const{state:t}=e,i=e.formattedName??"",a=this.saveAsButtonCallback&&"error"!==t&&this._isFormatAllowedForSaving(e.extension);return"pending"!==t?L("calcite-action",{icon:a?"ellipsis":"x",id:a?`${i}-popover-button`:void 0,key:a?`${i}-saveAs-action`:`${i}-action`,onclick:a?void 0:()=>{this.exportedLinks.remove(e)},slot:"actions-end",text:a?this.messagesCommon.options:this.messagesCommon.remove}):null}_renderExportedLinkItem(e){const t=e.formattedName??"";return L(F,null,L("calcite-list-item",{key:t,label:t},this._renderExportedLinkItemContent(e),this._renderExportedLinkItemIcon(e),this._renderExportedLinkItemAction(e)),this._renderExportedLinkItemPopover(e))}_renderExportedLinkItems(e){return L("calcite-list",{filterEnabled:e?.length>10,label:this.messages.exportedLinksList,selectionMode:"none"},e.map(this._renderExportedLinkItem.bind(this)))}_isFormatAllowedForSaving(e){return!this.allowedFormatsForSaving||"all"===this.allowedFormatsForSaving||!(!e||!this.allowedFormatsForSaving.includes(e))}_toggleLayoutPanel(e){const t=e.target;this._toggleTab(t.getAttribute("data-tab-id"))}_toggleTab(e,t=!0){if(this._selectedTab=e,"mapOnlyTab"===this._selectedTab)this.viewModel.applyTemplate(P);else if("layoutTab"===this._selectedTab){const e=this._selectedTemplate??this.viewModel.defaultTemplate;this.viewModel.applyTemplate(e)}t&&(this._activeTabFocusRequested=!0)}_handleLayoutPanelKeyDown(e){const{key:t}=e,i=e.target.getAttribute("data-tab-id");if(M(t))return this._toggleTab(i),e.preventDefault(),void e.stopPropagation();if("ArrowLeft"===t||"ArrowRight"===t){switch(i){case"layoutTab":this._toggleTab("ArrowLeft"===t?"exportTab":"mapOnlyTab");break;case"mapOnlyTab":this._toggleTab("ArrowLeft"===t?"layoutTab":"exportTab");break;case"exportTab":this._toggleTab("ArrowLeft"===t?"mapOnlyTab":"layoutTab")}e.preventDefault(),e.stopPropagation()}}};e([m()],U.prototype,"_showTemplates",void 0),e([m()],U.prototype,"_isValidSpatialReference",void 0),e([m()],U.prototype,"allowedFormats",null),e([m()],U.prototype,"allowedFormatsForSaving",void 0),e([m()],U.prototype,"allowedLayouts",null),e([m()],U.prototype,"browseTemplateButtonOnClick",void 0),e([m()],U.prototype,"error",null),e([m({type:i.ofType(w)})],U.prototype,"exportedLinks",null),e([m()],U.prototype,"extraParameters",null),e([m()],U.prototype,"headerVisible",void 0),e([m()],U.prototype,"headingLevel",void 0),e([m()],U.prototype,"icon",null),e([m()],U.prototype,"includeDefaultTemplates",null),e([m()],U.prototype,"includeOrganizationTemplates",void 0),e([m()],U.prototype,"label",null),e([m(),E("esri/widgets/Print/t9n/Print")],U.prototype,"messages",void 0),e([m(),E("esri/t9n/common")],U.prototype,"messagesCommon",void 0),e([m(),E("esri/core/t9n/Units")],U.prototype,"messagesUnits",void 0),e([m({type:b})],U.prototype,"outSpatialReference",null),e([m({type:v})],U.prototype,"portal",null),e([m()],U.prototype,"saveExportEnabled",null),e([m()],U.prototype,"saveExportHidden",void 0),e([m()],U.prototype,"showPrintAreaEnabled",null),e([m()],U.prototype,"printServiceUrl",null),e([m()],U.prototype,"saveAsButtonCallback",void 0),e([m()],U.prototype,"templateCustomTextElements",null),e([m({type:x})],U.prototype,"templateOptions",null),e([m()],U.prototype,"view",null),e([m({type:k})],U.prototype,"viewModel",void 0),U=e([u("esri.widgets.Print")],U);const H=U;export{H as default};