"use strict";(self.webpackChunk_JUPYTERLAB_CORE_OUTPUT=self.webpackChunk_JUPYTERLAB_CORE_OUTPUT||[]).push([[3904,2526],{13904:(t,e,r)=>{r.r(e),r.d(e,{HTMLViewer:()=>h,HTMLViewerFactory:()=>d,IHTMLViewerTracker:()=>u,ToolbarItems:()=>m});var n=r(10806),s=r(82776),o=r(98836),i=r(14039),a=r(17176),l=r(38684),c=r(78156);const u=new a.Token("@jupyterlab/htmlviewer:IHTMLViewerTracker");class h extends s.DocumentWidget{constructor(t){super({...t,content:new i.IFrame({sandbox:["allow-same-origin"]})}),this._renderPending=!1,this._parser=new DOMParser,this._monitor=null,this._objectUrl="",this._trustedChanged=new l.Signal(this),this.translator=t.translator||o.nullTranslator,this.content.addClass("jp-HTMLViewer"),this.context.ready.then((()=>{this.update(),this._monitor=new n.ActivityMonitor({signal:this.context.model.contentChanged,timeout:1e3}),this._monitor.activityStopped.connect(this.update,this)}))}get trusted(){return-1!==this.content.sandbox.indexOf("allow-scripts")}set trusted(t){this.trusted!==t&&(this.content.sandbox=t?_.trusted:_.untrusted,this.content.url=this.content.url,this._trustedChanged.emit(t))}get trustedChanged(){return this._trustedChanged}dispose(){if(this._objectUrl)try{URL.revokeObjectURL(this._objectUrl)}catch(t){}super.dispose()}onUpdateRequest(){this._renderPending||(this._renderPending=!0,this._renderModel().then((()=>this._renderPending=!1)))}async _renderModel(){let t=this.context.model.toString();t=await this._setBase(t);const e=new Blob([t],{type:"text/html"}),r=this._objectUrl;if(this._objectUrl=URL.createObjectURL(e),this.content.url=this._objectUrl,r)try{URL.revokeObjectURL(r)}catch(t){}}async _setBase(t){const e=this._parser.parseFromString(t,"text/html");let r=e.querySelector("base");r||(r=e.createElement("base"),e.head.insertBefore(r,e.head.firstChild));const n=this.context.path,s=await this.context.urlResolver.getDownloadUrl(n);return r.href=s,r.target="_self",e.documentElement.innerHTML}}class d extends s.ABCWidgetFactory{createNewWidget(t){return new h({context:t})}defaultToolbarFactory(t){return[{name:"refresh",widget:m.createRefreshButton(t,this.translator)},{name:"trust",widget:m.createTrustButton(t,this.translator)}]}}var m,_;!function(t){t.createRefreshButton=function(t,e){const r=(null!=e?e:o.nullTranslator).load("jupyterlab");return new i.ToolbarButton({icon:i.refreshIcon,onClick:async()=>{t.context.model.dirty||(await t.context.revert(),t.update())},tooltip:r.__("Rerender HTML Document")})},t.createTrustButton=function(t,e){return i.ReactWidget.create(c.createElement(_.TrustButtonComponent,{htmlDocument:t,translator:e}))}}(m||(m={})),function(t){t.untrusted=[],t.trusted=["allow-scripts"],t.TrustButtonComponent=function(t){const e=(t.translator||o.nullTranslator).load("jupyterlab");return c.createElement(i.UseSignal,{signal:t.htmlDocument.trustedChanged,initialSender:t.htmlDocument},(()=>c.createElement(i.ToolbarButtonComponent,{className:"",onClick:()=>t.htmlDocument.trusted=!t.htmlDocument.trusted,tooltip:e.__("Whether the HTML file is trusted.\nTrusting the file allows scripts to run in it,\nwhich may result in security risks.\nOnly enable for files you trust."),label:t.htmlDocument.trusted?e.__("Distrust HTML"):e.__("Trust HTML")})))}}(_||(_={}))}}]);