"use strict";(self.webpackChunk_JUPYTERLAB_CORE_OUTPUT=self.webpackChunk_JUPYTERLAB_CORE_OUTPUT||[]).push([[5325,377],{35325:(t,e,n)=>{n.r(e),n.d(e,{HTMLViewer:()=>d,HTMLViewerFactory:()=>m,IHTMLViewerTracker:()=>r,ToolbarItems:()=>s});const r=new(n(49501).Token)("@jupyterlab/htmlviewer:IHTMLViewerTracker","A widget tracker for rendered HTML documents.\n  Use this if you want to be able to iterate over and interact with HTML documents\n  viewed by the application.");var s,o,i=n(57174),a=n(87761),l=n(77952),c=n(71037),u=n(47479),h=n(78156);class d extends a.DocumentWidget{constructor(t){super({...t,content:new c.IFrame({sandbox:["allow-same-origin"]})}),this._renderPending=!1,this._parser=new DOMParser,this._monitor=null,this._objectUrl="",this._trustedChanged=new u.Signal(this),this.translator=t.translator||l.nullTranslator,this.content.addClass("jp-HTMLViewer"),this.context.ready.then((()=>{this.update(),this._monitor=new i.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?o.trusted:o.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"}),n=this._objectUrl;if(this._objectUrl=URL.createObjectURL(e),this.content.url=this._objectUrl,n)try{URL.revokeObjectURL(n)}catch(t){}}async _setBase(t){const e=this._parser.parseFromString(t,"text/html");let n=e.querySelector("base");n||(n=e.createElement("base"),e.head.insertBefore(n,e.head.firstChild));const r=this.context.path,s=await this.context.urlResolver.getDownloadUrl(r);return n.href=s,n.target="_self",e.documentElement.innerHTML}}class m extends a.ABCWidgetFactory{createNewWidget(t){return new d({context:t})}defaultToolbarFactory(t){return[{name:"refresh",widget:s.createRefreshButton(t,this.translator)},{name:"trust",widget:s.createTrustButton(t,this.translator)}]}}!function(t){t.createRefreshButton=function(t,e){const n=(null!=e?e:l.nullTranslator).load("jupyterlab");return new c.ToolbarButton({icon:c.refreshIcon,onClick:async()=>{t.context.model.dirty||(await t.context.revert(),t.update())},tooltip:n.__("Rerender HTML Document")})},t.createTrustButton=function(t,e){return c.ReactWidget.create(h.createElement(o.TrustButtonComponent,{htmlDocument:t,translator:e}))}}(s||(s={})),function(t){t.untrusted=[],t.trusted=["allow-scripts"],t.TrustButtonComponent=function(t){const e=(t.translator||l.nullTranslator).load("jupyterlab");return h.createElement(c.UseSignal,{signal:t.htmlDocument.trustedChanged,initialSender:t.htmlDocument},(()=>h.createElement(c.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")})))}}(o||(o={}))}}]);