@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.78 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Accessor.js";import{deprecatedModule as r}from"../../core/deprecate.js";import s from"../../core/Logger.js";import{property as n}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";let o=class extends t{constructor(e){super(e),this._vendorInfo=null,this._fullscreenStyle="width: 100%; height: 100%;",this.view=null,this._errorHandler=this._errorHandler.bind(this),this._stateHandler=this._stateHandler.bind(this),e?.isDefaultViewModel||r(s.getLogger("esri.widgets.Fullscreen.FullscreenViewModel"),"esri.widgets.Fullscreen.FullscreenViewModel",{replacement:"Fullscreen API",version:"4.33",see:"https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API",warnOnce:!0})}normalizeCtorArgs(e={}){const{isDefaultViewModel:t,...r}=e;return r}destroy(){this._removeFullscreenListeners(),this.view=null}get element(){return this.view?.container??null}set element(e){this._override("element",e)}get state(){return this.element?this._isSupported()?this._isActive()?"active":"ready":"feature-unsupported":"disabled"}enter(){this._enterFullscreen()}exit(){this._exitFullscreen()}toggle(){this._isActive()?this._exitFullscreen():this._enterFullscreen()}_isSupported(){this._removeFullscreenListeners();const e=this._getVendorInfo(this.element);return this._addFullscreenListeners(e),this._vendorInfo=e,!!e}_isActive(){return!!this._vendorInfo&&!!document[this._vendorInfo.propertyName]}_stateHandler(){this.notifyChange("state"),"active"===this.state?this._addStyle():this._removeStyle()}_errorHandler(e){s.getLogger(this).error("fullscreen request failed",e)}_getVendorInfo(e){if(e)return e.requestFullscreen?{enterName:"requestFullscreen",exitName:"exitFullscreen",errorEventName:"fullscreenerror",changeEventName:"fullscreenchange",propertyName:"fullscreen"}:e.webkitRequestFullScreen?{enterName:"webkitRequestFullscreen",exitName:"webkitCancelFullScreen",errorEventName:"webkitfullscreenerror",changeEventName:"webkitfullscreenchange",propertyName:"webkitIsFullScreen"}:e.mozRequestFullScreen?{enterName:"mozRequestFullScreen",exitName:"mozCancelFullScreen",errorEventName:"mozfullscreenerror",changeEventName:"mozfullscreenchange",propertyName:"mozFullScreen"}:void 0}_enterFullscreen(){if("feature-unsupported"===this.state)return void s.getLogger(this).warn("The fullscreen API is not supported in this browser.");const{element:e}=this;e&&(this._vendorInfo&&e[this._vendorInfo.enterName].call(e),this.notifyChange("state"))}_addStyle(){const{element:e}=this;e&&e.setAttribute("style",this._fullscreenStyle)}_removeStyle(){const{element:e}=this;e&&e.removeAttribute("style")}_exitFullscreen(){if("feature-unsupported"===this.state)return;const{element:e}=this;e&&(this._vendorInfo&&document[this._vendorInfo.exitName].call(document),this.notifyChange("state"))}_addFullscreenListeners(e){e&&(document.addEventListener(e.changeEventName,this._stateHandler),document.addEventListener(e.errorEventName,this._errorHandler))}_removeFullscreenListeners(){const{_vendorInfo:e}=this;e&&(document.removeEventListener(e.changeEventName,this._stateHandler),document.removeEventListener(e.errorEventName,this._errorHandler))}};e([n()],o.prototype,"element",null),e([n({readOnly:!0})],o.prototype,"state",null),e([n()],o.prototype,"view",void 0),e([n()],o.prototype,"enter",null),e([n()],o.prototype,"exit",null),e([n()],o.prototype,"toggle",null),o=e([l("esri.widgets.Fullscreen.FullscreenViewModel")],o);const i=o;export{i as default};