New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@netless/app-docs-viewer

Package Overview
Dependencies
Maintainers
12
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netless/app-docs-viewer - npm Package Compare versions

Comparing version 1.0.0-canary.2 to 1.0.0-canary.3

4

dist/main.iife.js

@@ -1,3 +0,3 @@

const NetlessAppDocsViewer=function(b,$,w,A,z){"use strict";const M=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(A),Q="",R=`.netless-app-docs-viewer-footer{box-sizing:border-box;height:26px;display:flex;align-items:center;padding:0 16px;border-top:1px solid #eeeef7;font-family:PingFang SC,Source Han Sans SC,Microsoft YaHei,Helvetica Neue,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif}.netless-app-docs-viewer-footer-btn{box-sizing:border-box;width:26px;height:26px;font-size:0;margin:0;padding:3px;border:none;border-radius:1px;outline:none;color:currentColor;background:transparent;transition:background .4s;cursor:pointer;user-select:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-docs-viewer-footer-btn:hover{background:rgba(237,237,240,.9)}@media (hover: none){.netless-app-docs-viewer-footer-btn:hover{background:transparent!important}}.netless-app-docs-viewer-footer-btn>svg{width:100%;height:100%}.netless-app-docs-viewer-footer-btn>svg:nth-of-type(2){display:none}.netless-app-docs-viewer-footer-btn.netless-app-docs-viewer-footer-btn-playing>svg:nth-of-type(1){display:none}.netless-app-docs-viewer-footer-btn.netless-app-docs-viewer-footer-btn-playing>svg:nth-of-type(2){display:initial}.netless-app-docs-viewer-footer-btn~.netless-app-docs-viewer-footer-btn{margin-left:15px}.netless-app-docs-viewer-page-jumps{flex:1;display:flex;justify-content:center;align-items:center}.netless-app-docs-viewer-page-number{display:flex;align-items:center;height:26px;margin-left:auto;font-size:13px;white-space:nowrap;word-break:keep-all;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-page-number-input{border:none;outline:none;width:3em;margin:0;padding:0 .5em 0 2px;text-align:right;font-size:13px;line-height:1;font-weight:400;font-family:inherit;border-radius:2px;color:currentColor;font-family:PingFang SC,Source Han Sans SC,Microsoft YaHei,Helvetica Neue,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif;background:transparent;transition:background .4s;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-docs-viewer-page-number-input:hover,.netless-app-docs-viewer-page-number-input:focus,.netless-app-docs-viewer-page-number-input:active{user-select:text;background:#fff;box-shadow:#63636333 0 2px 8px}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-footer-btn{cursor:not-allowed}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-footer-btn:hover{background:transparent}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input{cursor:not-allowed}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:hover,.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:focus,.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:active{background:transparent;box-shadow:none}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:disabled{color:inherit}.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:active,.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:focus,.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:hover{color:currentColor;background:#25282e}.telebox-color-scheme-dark .netless-app-docs-viewer-footer{border-top:none}.telebox-color-scheme-dark .netless-app-docs-viewer-footer-btn:hover{background:#212126}.netless-app-docs-viewer-preview-mask{position:absolute;z-index:10200;top:0;left:0;width:100%;height:100%}.netless-app-docs-viewer-preview{box-sizing:border-box;display:flex;flex-direction:column;align-items:center;position:absolute;z-index:10300;top:0;left:0;width:33%;max-width:200px;height:100%;padding-top:10px;transform:translate(-100%);background:rgba(237,237,240,.9);box-shadow:inset -1px 0 #0000001c;transition:transform .4s;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-preview.netless-app-docs-viewer-preview-active{transform:translate(0)}.netless-app-docs-viewer-preview-page{position:relative;display:block;width:55%;margin-bottom:10px;font-size:0;color:transparent;outline:none;border:7px solid transparent;border-radius:4px;transition:border-color .3s;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-preview-page:hover,.netless-app-docs-viewer-preview-page.netless-app-docs-viewer-preview-page-active{border-color:#444e601a}.netless-app-docs-viewer-preview-page>img{width:100%;height:auto;box-sizing:border-box;border:1px solid rgba(0,0,0,.5);border-radius:1px;background-color:#fff;box-shadow:0 2px 8px #0000004d}.netless-app-docs-viewer-preview-page-name{position:absolute;top:1px;left:-10px;transform:translate(-100%);text-align:right;font-size:12px;color:#5f5f5f;user-select:none}.telebox-color-scheme-dark .netless-app-docs-viewer-preview{background:rgba(50,50,50,.9)}.netless-app-docs-viewer-content{position:relative;height:100%;overflow:hidden}.netless-app-docs-viewer-static-scrollbar{box-sizing:border-box;position:absolute;top:0;right:0;z-index:2147483647;width:16px;min-height:30px;margin:0;padding:0 0 0 8px;border:none;outline:none;opacity:0;background:transparent;transition:opacity .4s 3s,transform .1s;user-select:none;touch-action:none}.netless-app-docs-viewer-static-scrollbar:after{content:"";display:block;width:8px;height:100%;border-radius:4px;background:rgba(68,78,96,.4);box-shadow:1px 1px 8px #ffffffb3;transition:background .4s}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrolling{opacity:1;transition:opacity .4s,transform .1s}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrollbar-dragging{opacity:1;transition:opacity .4s 3s!important}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrollbar-dragging:after{background:rgba(68,78,96,.6)}.netless-app-docs-viewer-static-scrollbar:hover:after,.netless-app-docs-viewer-static-scrollbar:focus:after{background:rgba(68,78,96,.5)}.netless-app-docs-viewer-static-scrollbar:active:after{background:rgba(68,78,96,.6)}.telebox-body-wrap:hover .netless-app-docs-viewer-static-scrollbar{opacity:1;transition:opacity .4s,transform .1s}.telebox-readonly .netless-app-docs-viewer-static-scrollbar{display:none}.page-renderer-pages-container{position:relative;width:100%;height:100%}.page-renderer-page{position:absolute;top:0;left:0;background-position:center;background-size:cover;background-repeat:no-repeat}.page-renderer-pages-container.is-hwa .page-renderer-page{will-change:transform}.page-renderer-page-img{display:block;width:100%;height:auto;user-select:none}.netless-app-docs-viewer-static-pages{overflow:hidden;position:relative;height:100%;user-select:none}.netless-app-docs-viewer-static-page{display:block;width:100%;height:auto;user-select:none}.netless-app-docs-viewer-dynamic-wb-view{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;overflow:hidden}.netless-app-docs-viewer-dynamic-wb-view .cursor-clicker .ppt-event-source{cursor:pointer}
`;class _{constructor({namespace:e,pages$:t,sideEffect:s,readonly$:r,events:l,wrapClassName:o,root:a,pagesIndex$:c}){this.showPreview$=new w.Val(!1),this.namespace=e,this.pages$=t,this.sideEffect=s,this.readonly$=r,this.events=l,this.wrapClassName=o,this.sideEffect.addDisposer(this.events.on("togglePreview",()=>{this.showPreview$.setValue(!this.showPreview$.value)})),this.sideEffect.addDisposer(this.showPreview$.subscribe(i=>{this.sideEffect.add(()=>{const h=this.renderPreview(),d=this.renderPreviewMask();if(i){a.appendChild(h),a.appendChild(d),h.scrollTop;const g=h.querySelector("."+this.wrapClassName(`preview-page-${c.value}`));return g&&h.scrollTo({top:g.offsetTop-16}),h.classList.toggle(this.wrapClassName("preview-active"),!0),this.previewLazyLoad=new M.default({container:this.$preview,elements_selector:"."+this.wrapClassName("preview-page>img")}),()=>{var p;return(p=this.previewLazyLoad)==null?void 0:p.destroy()}}else return h.classList.toggle(this.wrapClassName("preview-active"),!1),this.sideEffect.setTimeout(()=>{h.remove(),d.remove()},500,"preview-remove"),null},"preview-lazyload")}))}destroy(){var e,t;(e=this.$preview)==null||e.remove(),(t=this.$previewMask)==null||t.remove()}renderPreview(){if(this.$preview)return this.$preview;const e=document.createElement("div");return e.className=this.wrapClassName("preview")+" tele-fancy-scrollbar",this.$preview=e,this.sideEffect.addEventListener(e,"wheel",t=>t.stopPropagation(),{passive:!1}),this.sideEffect.addDisposer(this.pages$.subscribe(t=>{var s;this.sideEffect.add(()=>{const r=t.map((l,o)=>{var g;const a=(g=l.thumbnail)!=null?g:l.src.startsWith("ppt")?void 0:l.src;if(!a)return;const c=String(o),i=document.createElement("a");i.className=this.wrapClassName("preview-page")+" "+this.wrapClassName(`preview-page-${o}`),i.setAttribute("href","#"),i.dataset.pageIndex=c;const h=document.createElement("span");h.className=this.wrapClassName("preview-page-name"),h.textContent=String(o+1),h.dataset.pageIndex=c;const d=document.createElement("img");return d.width=l.width,d.height=l.height,d.dataset.src=a,d.dataset.pageIndex=c,i.appendChild(d),i.appendChild(h),e.appendChild(i),i});return()=>r.forEach(l=>l==null?void 0:l.remove())},"render-preview-pages"),(s=this.previewLazyLoad)==null||s.update()})),this.sideEffect.addEventListener(e,"click",t=>{var r;if(this.readonly$.value)return;const s=(r=t.target.dataset)==null?void 0:r.pageIndex;s&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),this.events.emit("jumpPage",Number(s)),this.showPreview$.setValue(!1))}),e}renderPreviewMask(){if(this.$previewMask)return this.$previewMask;const e=document.createElement("div");return e.className=this.wrapClassName("preview-mask"),this.$previewMask=e,this.sideEffect.addEventListener(e,"click",t=>{this.readonly$.value||t.target===e&&this.showPreview$.setValue(!1)}),e}}function I(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-sidebar`),t.setAttribute("viewBox","0 0 64 64");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M50 8H14c-3.309 0-6 2.691-6 6v36c0 3.309 2.691 6 6 6h36c3.309 0 6-2.691 6-6V14c0-3.309-2.691-6-6-6zM12 50V14c0-1.103.897-2 2-2h8v40h-8c-1.103 0-2-.897-2-2zm40 0c0 1.103-.897 2-2 2H26V12h24c1.103 0 2 .897 2 2z"),t.appendChild(s),t}function B(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-arrow-left`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M177.81 249.959L337.473 90.295c2.722-2.865 2.651-7.378-.143-10.1-2.793-2.65-7.163-2.65-9.956 0l-164.75 164.75c-2.793 2.793-2.793 7.306 0 10.1l164.75 164.75c2.865 2.722 7.378 2.65 10.099-.143 2.651-2.794 2.651-7.163 0-9.957L177.809 249.959z"),t.appendChild(s),t}function H(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-arrow-right`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M322.19 250.041L162.527 409.705c-2.722 2.865-2.651 7.378.143 10.1 2.793 2.65 7.163 2.65 9.956 0l164.75-164.75c2.793-2.793 2.793-7.306 0-10.1l-164.75-164.75c-2.865-2.722-7.378-2.65-10.099.143-2.651 2.794-2.651 7.163 0 9.957l159.664 159.736z"),t.appendChild(s),t}function U(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-play`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M418.158 257.419L174.663 413.33c-6.017 3.919-15.708 3.772-21.291-.29-2.791-2.018-4.295-4.483-4.295-7.084V94.109c0-5.65 6.883-10.289 15.271-10.289 4.298 0 8.391 1.307 11.181 3.332l242.629 155.484c6.016 3.917 6.451 10.292.649 14.491-.216.154-.432.154-.649.292zM170.621 391.288l223.116-141.301L170.71 107.753l-.089 283.535z"),t.appendChild(s),t}function F(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-pause`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M312.491 78.261c0-6.159 4.893-11.213 11.04-11.213 6.158 0 11.211 5.054 11.211 11.213v343.478c0 6.159-5.053 11.213-11.211 11.213-6.147 0-11.04-5.054-11.04-11.213V78.261zM165.257 78.261c0-6.159 4.893-11.213 11.04-11.213 6.158 0 11.211 5.054 11.211 11.213v343.478c0 6.159-5.053 11.213-11.211 11.213-6.147 0-11.04-5.054-11.04-11.213V78.261z"),t.appendChild(s),t}class W{constructor({namespace:e,pages$:t,sideEffect:s,readonly$:r,events:l,playable:o,wrapClassName:a,pagesIndex$:c,root:i}){this.namespace=e,this.pages$=t,this.sideEffect=s,this.readonly$=r,this.events=l,this.wrapClassName=a,this.pagesIndex$=c,this.playable=o,this.$footer=this.render(),i.appendChild(this.$footer)}destroy(){this.$footer.remove()}render(){const e=document.createElement("div");e.className=this.wrapClassName("footer"),this.sideEffect.addDisposer(this.readonly$.subscribe(i=>e.classList.toggle(this.wrapClassName("readonly"),i)));const t=this.renderFooterBtn("btn-sidebar",I(this.namespace));this.sideEffect.addEventListener(t,"click",()=>{this.readonly$.value||this.events.emit("togglePreview")}),e.appendChild(t),this.sideEffect.addDisposer(this.pages$.subscribe(i=>{const h=i.some(d=>d.thumbnail||!d.src.startsWith("ppt"));t.style.display=h?"":"none"}));const s=document.createElement("div");s.className=this.wrapClassName("page-jumps");const r=this.renderFooterBtn("btn-page-back",B(this.namespace));if(this.sideEffect.addEventListener(r,"click",()=>{this.readonly$.value||this.events.emit("back")}),s.appendChild(r),this.playable){const i=this.renderFooterBtn("btn-page-play",U(this.namespace),F(this.namespace));this.sideEffect.addEventListener(i,"click",()=>{this.readonly$.value||(i.classList.toggle(this.wrapClassName("footer-btn-playing"),!0),this.events.emit("play"),this.sideEffect.setTimeout(()=>i.classList.toggle(this.wrapClassName("footer-btn-playing"),!1),500,"returnPlay"))}),s.appendChild(i)}const l=this.renderFooterBtn("btn-page-next",H(this.namespace));this.sideEffect.addEventListener(l,"click",()=>{this.readonly$.value||this.events.emit("next")}),s.appendChild(l);const o=document.createElement("div");o.className=this.wrapClassName("page-number");const a=document.createElement("input");a.className=this.wrapClassName("page-number-input"),this.sideEffect.addDisposer(this.readonly$.subscribe(i=>a.disabled=i)),this.sideEffect.addDisposer(this.pagesIndex$.subscribe(i=>a.value=String(i+1))),this.sideEffect.addEventListener(a,"blur",()=>{a.value=String(this.pagesIndex$.value+1)}),this.sideEffect.addEventListener(a,"change",()=>{if(this.readonly$.value)return;const i=a.value?Number(a.value)-1:NaN;i>=0?this.events.emit("jumpPage",i):a.value=String(this.pagesIndex$.value+1)});const c=document.createElement("span");return this.sideEffect.addDisposer(this.pages$.subscribe(i=>{c.textContent=" / "+i.length})),o.appendChild(a),o.appendChild(c),e.appendChild(s),e.appendChild(o),e}renderFooterBtn(e,t,s){const r=document.createElement("button");return r.className=this.wrapClassName("footer-btn")+" "+this.wrapClassName(e),r.appendChild(t),s&&r.appendChild(s),r}}class x{constructor({readonly$:e,pagesIndex$:t,previewRoot:s,footerRoot:r,pages$:l,playable:o}){this.wrapClassName=a=>`${this.namespace}-${a}`,this.namespace="netless-app-docs-viewer",this.sideEffect=new $.SideEffectManager,this.events=new z.Remitter,this.preview=new _({pages$:l,readonly$:e,pagesIndex$:t,root:s,sideEffect:this.sideEffect,events:this.events,namespace:this.namespace,wrapClassName:this.wrapClassName}),this.footer=new W({pages$:l,readonly$:e,playable:o,pagesIndex$:t,root:r,namespace:this.namespace,sideEffect:this.sideEffect,events:this.events,wrapClassName:this.wrapClassName})}destroy(){this.preview.destroy(),this.footer.destroy(),this.sideEffect.flushAll(),this.events.destroy()}}function v(n,e,t){return Math.min(Math.max(n,e),t)}function E(n){return n.touches?n.touches[0]:n}function C(n){n.stopPropagation(),n.cancelable&&n.preventDefault()}function k(n,e){return n.width===e.width&&n.height===e.height}class N{constructor(e){var t,s,r;this.velocity=0,this._paused=!0,this._animationFrameID=null,this._loopTimestamp=0,this.looper=l=>{var a;if(this._paused)return;let o=Math.floor((l-this._loopTimestamp)/1e3*60)+1;for(this._loopTimestamp=l;o-- >0;)this.stepper();(a=this.onStep)==null||a.call(this,this.current),this._paused?this._animationFrameID=null:this._animationFrameID=window.requestAnimationFrame(this.looper)},this.current=(t=e.start)!=null?t:0,this.target=this.current,this.stiffness=(s=e.stiffness)!=null?s:170,this.damping=(r=e.damping)!=null?r:26,this.onStep=e.onStep}get paused(){return this._paused}stepTo(e,t){var s;this._paused&&t!=null&&(this.current=t),this._paused=!1,this.target=e,(s=this.onStep)==null||s.call(this,this.current),this._loopTimestamp=Date.now(),this._animationFrameID=window.requestAnimationFrame(this.looper)}pause(){this._paused=!0,this._animationFrameID!=null&&window.cancelAnimationFrame(this._animationFrameID)}destroy(){this.pause(),this.onStep=void 0}stepper(){const e=-this.stiffness*(this.current-this.target),t=-this.damping*this.velocity,s=this.velocity+(e+t)/60,r=this.current+s/60;Math.abs(s-0)<.01&&Math.abs(r-this.target)<.01?(this.current=this.target,this.velocity=0,this._paused=!0):(this.current=r,this.velocity=s)}}class Y{constructor(e,t,s,r,l,o){this.index=e,this.lastVisit=Date.now(),this.sideEffect=new $.SideEffectManager;const a=w.derive(t,g=>g[e]||{width:0,height:0}),c=w.combine([a,s],([g,p])=>(p.width-g.width)/2),i=w.combine([l,o],([g,p])=>(g[e]||0)-p),h=document.createElement("div");h.className="page-renderer-page",h.dataset.index=`${e}`;const d=document.createElement("img");d.className="page-renderer-page-img",h.appendChild(d),this.sideEffect.addDisposer([w.combine([a,r]).subscribe(([g,p])=>{h.style.width=`${g.width*p}px`,h.style.height=`${g.height*p}px`}),a.subscribe(g=>{g.thumbnail&&(h.style.backgroundImage=`url("${g.thumbnail}")`),d.width=g.width,d.height=g.height,d.src=g.src}),w.combine([c,i,r]).subscribe(([g,p,u])=>{h.style.transform=`translate(${g*u}px, ${p*u}px)`})]),this.$page=h}destroy(){this.sideEffect.flushAll(),this.$page.remove()}}class j{constructor(e,t,s,r,l){this.pages$=e,this.pagesSize$=t,this.scale$=s,this.pagesYs$=r,this.pagesScrollTop$=l,this.els=new Map,this.maxElCount=200,this.gcTimer=null,this.gc=()=>{var o;if(this.gcTimer=null,this.els.size>this.maxElCount){const a=[...this.els.values()].sort((c,i)=>i.lastVisit-c.lastVisit);for(let c=Math.floor(this.maxElCount/4);c<a.length;c++)(o=this.els.get(a[c].index))==null||o.destroy(),this.els.delete(a[c].index)}},this.schedule=window.requestIdleCallback||(o=>window.setTimeout(o,5e3)),this.cancelSchedule=window.cancelIdleCallback||window.clearTimeout}getEl(e){let t=this.els.get(e);return t||(t=new Y(e,this.pages$,this.pagesSize$,this.scale$,this.pagesYs$,this.pagesScrollTop$),this.els.set(e,t)),t.lastVisit=Date.now(),this.els.size>this.maxElCount&&this.gcTimer===null&&(this.gcTimer=this.schedule(this.gc)),t}destroy(){this.els.forEach(e=>e.destroy()),this.els.clear(),this.gcTimer!==null&&(this.cancelSchedule(this.gcTimer),this.gcTimer=null)}}class P{constructor({pagesScrollTop$:e,containerRect$:t,pages$:s,pagesSize$:r}){this.sideEffect=new $.SideEffectManager,s=w.derive(s,p=>p.map(u=>{if(u.thumbnail)return u;try{const f=new URL(u.src);return f.searchParams.set("x-oss-process","image/resize,l_50"),{...u,thumbnail:f.toString()}}catch(f){return console.error(f),u}}));const l=w.derive(s,p=>{const u=Array(p.length);for(let f=0;f<p.length;f++)u[f]=f>0?u[f-1]+p[f-1].height:0;return u}),o=w.derive(s,p=>{let u=1/0;for(let f=p.length-1;f>=0;f--)p[f].height<=u&&(u=p[f].height);return u}),a=w.combine([e,l,s],([p,u,f])=>{if(u.length!==f.length)return a.value;for(let m=0;m<u.length;m++)if(u[m]+f[m].height-p>=.001)return m;return u.length-1}),c=w.combine([t,r],([p,u])=>p.width/u.width||1),i=w.combine([s,t,o,c],([p,u,f,m])=>v(Math.ceil(u.height/m/f/2),1,p.length));w.withReadonlyValueEnhancer(this,{pagesScrollTop:e,containerRect:t,pages:s,pagesSize:r,pagesIndex:a,pagesYs:l,pagesMinHeight:o,scale:c}),this.pageElManager=new j(s,r,c,l,e),this.$pages=this.renderPages();const h=new w.Val(!1);this.sideEffect.addDisposer(h.subscribe(p=>this.$pages.classList.toggle("is-hwa",p)));const d=()=>h.setValue(!1),g=()=>{this.sideEffect.setTimeout(d,1e3,"turn-off-hwa"),h.setValue(!0)};this.sideEffect.addDisposer(w.combine([a,i,s]).subscribe(([p,u,f])=>{g();const m=Math.max(p-u,0),L=Math.min(p+u,f.length-1);for(let S=0;S<this.$pages.children.length;S++){const y=this.$pages.children[S],V=Number(y.dataset.index);V>=m&&V<=L||(y.remove(),S--)}for(let S=m;S<=L;S++){const y=this.pageElManager.getEl(S);y.$page.parentElement!==this.$pages&&this.$pages.appendChild(y.$page)}}))}renderPages(){const e=document.createElement("div");return e.className="page-renderer-pages-container",this.sideEffect.addDisposer(this._containerRect$.subscribe(t=>{e.style.width=`${t.width}px`,e.style.height=`${t.height}px`}),"render-pages-size"),e}destroy(){this.sideEffect.flushAll(),this.$pages.remove(),this.pageElManager.destroy()}}const O=30;class T{constructor({pagesScrollTop$:e,containerRect$:t,stageRect$:s,pagesSize$:r,readonly$:l,scrollbarMinHeight:o=O,wrapClassName:a,onDragScroll:c}){this.sideEffect=new $.SideEffectManager,this.scrolling$=new w.Val(!1),this.pagesScrollTop$=e,this.containerRect$=t,this.stageRect$=s,this.pagesSize$=r,this.scrollbarMinHeight=o,this.readonly$=l,this.wrapClassName=a,this.onDragScroll=c,this.scrollbarHeight$=w.combine([t,s,r],([i,h,d])=>v(h.height/(h.width/d.width*d.height)*i.height,o,i.height)),this.scrollTop$=w.combine([t,s,r,this.scrollbarHeight$,this.pagesScrollTop$],([i,h,d,g,p])=>v(p/(d.height-d.width/h.width*h.height)*(i.height-g),0,i.height-g)),this.$scrollbar=this.renderScrollbar()}mount(e){e.appendChild(this.$scrollbar)}destroy(){this.$scrollbar.remove(),this.onDragScroll=void 0,this.sideEffect.flushAll()}renderScrollbar(){const e=document.createElement("button");e.className=this.wrapClassName("scrollbar"),e.style.minHeight=`${this.scrollbarMinHeight}px`,this.sideEffect.addDisposer([this.scrollbarHeight$.subscribe(s=>{e.style.height=`${s}px`}),this.scrollTop$.subscribe(s=>{this.scrolling$.setValue(!0),this.sideEffect.setTimeout(()=>this.scrolling$.setValue(!1),100,"reset-scrolling");const r=()=>e.style.transform=`translateY(${s}px)`;window.requestAnimationFrame?window.requestAnimationFrame(r):r()}),this.scrolling$.subscribe(s=>{e.classList.toggle(this.wrapClassName("scrolling"),s)})]);const t=s=>{if(!s.isPrimary||this.readonly$.value||s.button!=null&&s.button!==0)return;C(s);const r=this.wrapClassName("scrollbar-dragging");e.classList.toggle(r,!0);const l=this.pagesScrollTop$.value,{clientY:o}=E(s),a=i=>{if(!i.isPrimary||this.readonly$.value)return;const{clientY:h}=E(i),d=h-o;Math.abs(d)>0&&this.onDragScroll&&this.onDragScroll(l+d/this.containerRect$.value.height*this.pagesSize$.value.height)},c=i=>{!i.isPrimary||(e.classList.toggle(r,!1),window.removeEventListener("pointermove",a,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("pointercancel",c,!0))};window.addEventListener("pointermove",a,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("pointercancel",c,!0)};return this.sideEffect.addEventListener(e,"pointerdown",t),e}}class G{constructor({whiteboard:e,readonly$:t,box:s,pages:r,pagesScrollTop:l=0,onUserScroll:o}){this.sideEffect=new $.SideEffectManager,this.userScrolling=!1,this.whiteboard=e,this.readonly$=t,this.box=s,this.pages=r,this.onUserScroll=o;const a=()=>{var i;this.userScrolling=!1,(i=this.onUserScroll)==null||i.call(this,this.pagesScrollTop$.value)};this.debounceOnUserScroll=()=>{this.userScrolling=!0,this.sideEffect.setTimeout(a,80,"debounceOnUserScroll")};const c=new w.Val([]);this.pagesScrollTop$=new w.Val(l),this.pagesSize$=w.derive(c,i=>{let h=0,d=0;for(let g=i.length-1;g>=0;g--){const p=i[g];p.width>h&&(h=p.width),d+=p.height}return{width:Math.max(1,h),height:Math.max(1,d)}},{compare:k}),this.pageRenderer=new P({pagesScrollTop$:this.pagesScrollTop$,containerRect$:s._stageRect$,pages$:c,pagesSize$:this.pagesSize$}),this.viewer=new x({readonly$:t,pagesIndex$:this.pageRenderer._pagesIndex$,previewRoot:s.$body,footerRoot:s.$footer,pages$:c,playable:!1}),this.sideEffect.addDisposer([this.viewer.events.on("next",()=>{this.userScrollByPercent(.8)}),this.viewer.events.on("back",()=>{this.userScrollByPercent(-.8)})]),this.scrollbar=new T({pagesScrollTop$:this.pagesScrollTop$,containerRect$:s._bodyRect$,stageRect$:s._stageRect$,pagesSize$:this.pagesSize$,readonly$:t,wrapClassName:this.wrapClassName.bind(this),onDragScroll:i=>{this.pageScrollTo(i),this.debounceOnUserScroll()}}),this.pageScrollStepper=new N({start:this.pagesScrollTop$.value,onStep:i=>{this.pageScrollTo(i)}}),this.sideEffect.addDisposer(this.viewer.events.on("jumpPage",i=>this.userScrollToPageIndex(i))),this.render(),this.setupScrollListener(),this.sideEffect.setTimeout(()=>{this.userScrolling||this.pageScrollTo(this.pageRenderer.pagesScrollTop)},100),c.setValue(r)}get pagesScrollTop(){return this.pagesScrollTop$.value}destroy(){this.sideEffect.flushAll(),this.pageScrollStepper.destroy(),this.onUserScroll=void 0,this.viewer.destroy(),this.pageRenderer.destroy(),this.scrollbar.destroy()}syncPageScrollTop(e){!this.userScrolling&&e>=0&&Math.abs(this.pagesScrollTop$.value-e)>.01&&this.pageScrollStepper.stepTo(e,this.pagesScrollTop$.value)}render(){this.box.$content.style.overflow="hidden",this.box.mountStage(this.pageRenderer.$pages),this.scrollbar.mount(this.box.$body)}pageScrollTo(e){const t=this.whiteboard.view.size.height/2/this.pageRenderer.scale;this.whiteboard.view.moveCamera({centerY:v(e+t,t,this.pagesSize$.value.height-t),animationMode:"immediately"})}userScrollToPageIndex(e){var t;if(e=v(e,0,this.pages.length-1),!this.readonly$.value&&!Number.isNaN(e)){const s=this.pageRenderer.pagesYs[e];s>=0&&((t=this.onUserScroll)==null||t.call(this,s+5/this.pageRenderer.scale))}}userScrollByPercent(e){var t;this.readonly$.value||(t=this.onUserScroll)==null||t.call(this,v(this.pageRenderer.pagesScrollTop+this.pageRenderer.containerRect.height/this.pageRenderer.scale*v(e,-1,1),0,this.pageRenderer.pagesSize.height-this.pageRenderer.containerRect.height/this.pageRenderer.scale))}setupScrollListener(){this.sideEffect.addEventListener(this.box.$main,"wheel",e=>{C(e),!this.readonly$.value&&this.pageScrollStepper.paused&&(this.pageScrollTo(this.pagesScrollTop+e.deltaY),this.debounceOnUserScroll())},{passive:!1}),this.sideEffect.addEventListener(this.box.$main,"touchmove",e=>{!this.readonly$.value&&e.touches.length>1&&this.debounceOnUserScroll()},{passive:!0,capture:!0}),this.sideEffect.add(()=>{const e=t=>{const{width:s,height:r}=this.whiteboard.view.size;if(s<=0||r<=0)return;const l=t.centerY-this.pageRenderer.containerRect.height/this.pageRenderer.scale/2;this.pagesScrollTop$.setValue(l)};return this.whiteboard.view.callbacks.on("onCameraUpdated",e),()=>this.whiteboard.view.callbacks.off("onCameraUpdated",e)}),this.sideEffect.addDisposer(this.box._stageRect$.subscribe(e=>{const{width:t,height:s}=this.pagesSize$.value;this.whiteboard.view.moveCameraToContain({originX:0,originY:this.pageRenderer.pagesScrollTop,width:t,height:e.height/this.pageRenderer.scale,animationMode:"immediately"}),this.whiteboard.view.setCameraBound({damping:1,maxContentMode:()=>this.pageRenderer.scale,minContentMode:()=>this.pageRenderer.scale,centerX:t/2,centerY:s/2,width:t,height:s})}),"whiteboard-size-update"),this.sideEffect.addEventListener(window,"keyup",e=>{if(!(this.readonly$.value||!this.box.focus||this.box.minimized))switch(e.key){case"PageDown":{this.userScrollByPercent(.8);break}case"PageUp":{this.userScrollByPercent(-.8);break}case"ArrowLeft":{this.userScrollByPercent(-.25);break}case"ArrowRight":{this.userScrollByPercent(.25);break}case"ArrowDown":{this.userScrollByPercent(.5);break}case"ArrowUp":{this.userScrollByPercent(-.5);break}}},{capture:!0})}wrapClassName(e){return"netless-app-docs-viewer-static-"+e}}class q{constructor({readonly$:e,context:t,whiteboard:s,box:r,pages:l}){this.sideEffect=new $.SideEffectManager,this.context=t,this.whiteboard=s,this.box=r,this.pages=l;const o=new w.Val(t.displayer.state.sceneState.index||0);this.pagesIndex$=o,this.sideEffect.add(()=>{const a=c=>{this.jumpToPage(c.index)};return this.context.emitter.on("sceneStateChange",a),()=>this.context.emitter.off("sceneStateChange",a)}),this.viewer=new x({readonly$:e,pagesIndex$:o,previewRoot:r.$body,footerRoot:r.$footer,pages$:new w.Val(l),playable:!0}),this.sideEffect.addDisposer([this.viewer.events.on("jumpPage",a=>this.jumpToPage(a,!0)),this.viewer.events.on("play",()=>{var a;return(a=this.context.room)==null?void 0:a.pptNextStep()}),this.viewer.events.on("back",()=>this.prevPage()),this.viewer.events.on("next",()=>this.nextPage())]),this.render(),this.sideEffect.addDisposer(o.subscribe((a,c)=>{var d,g;if(e.value)return;const i=this.context.getInitScenePath(),h=(g=(d=this.context.getScenes())==null?void 0:d[a])==null?void 0:g.name;if(i&&h&&this.context.setScenePath(`${i}/${h}`),c){const p=this.context.room;if(p){const u=p.state.globalState.__pptState;p.setGlobalState({__pptState:u&&{uuid:u.uuid,pageIndex:a,disableAutoPlay:u.disableAutoPlay}})}}}))}destroy(){this.sideEffect.flushAll(),this.viewer.destroy()}nextPage(){this.jumpToPage(this.pagesIndex$.value+1,!0)}prevPage(){this.jumpToPage(this.pagesIndex$.value-1,!0)}jumpToPage(e,t=!1){this.pagesIndex$.setValue(v(e,0,this.pages.length-1),t)}render(){var t;this.box.mountStage(document.createElement("div")),this.sideEffect.addEventListener(window,"keydown",s=>{var r;if(this.box.focus)switch(s.key){case"ArrowUp":case"ArrowLeft":{this.prevPage();break}case"ArrowRight":case"ArrowDown":{(r=this.context.room)==null||r.pptNextStep();break}}});const e=(t=this.whiteboard.view.divElement)==null?void 0:t.parentElement;e&&this.sideEffect.addEventListener(e,"click",s=>{var l;const r=this.context.room;if(r&&r.state.memberState.currentApplianceName==="clicker"){for(let o=s.target;o;o=o.parentElement)if((l=o.classList)!=null&&l.contains("ppt-event-source"))return;r.pptNextStep()}})}wrapClassName(e){return"netless-app-docs-viewer-dynamic-"+e}}const D={kind:"DocsViewer",setup(n){const e=n.box,t=n.getScenes();if(!t)throw new Error("[Docs Viewer]: scenes not found.");const s=new $.SideEffectManager,r=t.map(({ppt:o})=>o?{width:o.width,height:o.height,src:o.src,thumbnail:o.previewURL}:null).filter(o=>Boolean(o));if(r.length<=0)throw new Error("[Docs Viewer]: empty scenes.");e.mountStyles(R);const l=new w.Val(!n.isWritable);s.addDisposer(n.emitter.on("writableChange",o=>{l.setValue(!o)})),r[0].src.startsWith("ppt")?X(s,n,e,r,l):J(s,n,e,r,l),s.addDisposer(n.emitter.on("destroy",()=>{s.flushAll()}))}};function J(n,e,t,s,r){const l=e.createWhiteBoardView({syncCamera:!1});n.addDisposer(r.subscribe(c=>{l.view.disableCameraTransform=c}));const o=e.createStorage("static-docs-viewer",{pagesScrollTop:0}),a=new G({whiteboard:l,readonly$:r,box:t,pages:s,pagesScrollTop:o.state.pagesScrollTop,onUserScroll:c=>{e.isWritable&&o.setState({pagesScrollTop:c})}});n.addDisposer(()=>a.destroy()),n.addDisposer(o.addStateChangedListener(c=>{c.pagesScrollTop&&a.syncPageScrollTop(c.pagesScrollTop.newValue||0)})),n.addDisposer(w.combine([t._maximized$,t._managerStageRect$,t._intrinsicSize$,a.pagesSize$,a.pageRenderer._pagesMinHeight$],([c,i,h,d,g])=>c?Math.max(g/d.width*.4,i.height/i.width):h.height/h.width*(i.height/i.width)).subscribe(c=>{t.setStageRatio(c)}))}function X(n,e,t,s,r){const l=e.createWhiteBoardView();l.view.disableCameraTransform=!0;const o=new q({context:e,whiteboard:l,box:t,pages:s,readonly$:r});n.addDisposer(()=>o.destroy());const a=new w.Val({width:s[0].width,height:s[0].height},{compare:k});if(n.addDisposer(o.pagesIndex$.subscribe(c=>{const i=s[c];i&&a.setValue({width:i.width,height:i.height})})),n.addDisposer(a.subscribe(c=>{r.value||l.setBaseRect(c)})),e.isAddApp){const c=n.add(()=>{const i=({width:h,height:d})=>{if(s.length>0&&t.state!=="maximized"){const{width:g,height:p}=s[0],f=p/g*h-d;f!==0&&e.isWritable&&e.emitter.emit("setBoxSize",{width:t.intrinsicWidth,height:t.intrinsicHeight+f/t.rootRect.height})}n.remove(c)};return l.view.callbacks.once("onSizeUpdated",i),()=>l.view.callbacks.off("onSizeUpdated",i)})}}return b.DocsViewer=x,b.NetlessAppDocsViewer=D,b.PageRenderer=P,b.ScrollBar=T,b.Stepper=N,b.default=D,Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),b}({},sideEffectManager,valueEnhancer,LazyLoad,remitter);
var NetlessAppDocsViewer=function(v,b,f,A,V){"use strict";var Q=Object.defineProperty;var Z=(v,b,f)=>b in v?Q(v,b,{enumerable:!0,configurable:!0,writable:!0,value:f}):v[b]=f;var i=(v,b,f)=>(Z(v,typeof b!="symbol"?b+"":b,f),f);const R=(o=>o&&typeof o=="object"&&"default"in o?o:{default:o})(A),te="",_=`.netless-app-docs-viewer-footer{box-sizing:border-box;height:26px;display:flex;align-items:center;padding:0 16px;border-top:1px solid #eeeef7;font-family:PingFang SC,Source Han Sans SC,Microsoft YaHei,Helvetica Neue,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif}.netless-app-docs-viewer-footer-btn{box-sizing:border-box;width:26px;height:26px;font-size:0;margin:0;padding:3px;border:none;border-radius:1px;outline:none;color:currentColor;background:transparent;transition:background .4s;cursor:pointer;user-select:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-docs-viewer-footer-btn:hover{background:rgba(237,237,240,.9)}@media (hover: none){.netless-app-docs-viewer-footer-btn:hover{background:transparent!important}}.netless-app-docs-viewer-footer-btn>svg{width:100%;height:100%}.netless-app-docs-viewer-footer-btn>svg:nth-of-type(2){display:none}.netless-app-docs-viewer-footer-btn.netless-app-docs-viewer-footer-btn-playing>svg:nth-of-type(1){display:none}.netless-app-docs-viewer-footer-btn.netless-app-docs-viewer-footer-btn-playing>svg:nth-of-type(2){display:initial}.netless-app-docs-viewer-footer-btn~.netless-app-docs-viewer-footer-btn{margin-left:15px}.netless-app-docs-viewer-page-jumps{flex:1;display:flex;justify-content:center;align-items:center}.netless-app-docs-viewer-page-number{display:flex;align-items:center;height:26px;margin-left:auto;font-size:13px;white-space:nowrap;word-break:keep-all;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-page-number-input{border:none;outline:none;width:3em;margin:0;padding:0 .5em 0 2px;text-align:right;font-size:13px;line-height:1;font-weight:400;font-family:inherit;border-radius:2px;color:currentColor;font-family:PingFang SC,Source Han Sans SC,Microsoft YaHei,Helvetica Neue,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif;background:transparent;transition:background .4s;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-docs-viewer-page-number-input:hover,.netless-app-docs-viewer-page-number-input:focus,.netless-app-docs-viewer-page-number-input:active{user-select:text;background:#fff;box-shadow:#63636333 0 2px 8px}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-footer-btn{cursor:not-allowed}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-footer-btn:hover{background:transparent}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input{cursor:not-allowed}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:hover,.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:focus,.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:active{background:transparent;box-shadow:none}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:disabled{color:inherit}.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:active,.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:focus,.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:hover{color:currentColor;background:#25282e}.telebox-color-scheme-dark .netless-app-docs-viewer-footer{border-top:none}.telebox-color-scheme-dark .netless-app-docs-viewer-footer-btn:hover{background:#212126}.netless-app-docs-viewer-preview-mask{position:absolute;z-index:10200;top:0;left:0;width:100%;height:100%}.netless-app-docs-viewer-preview{box-sizing:border-box;display:flex;flex-direction:column;align-items:center;position:absolute;z-index:10300;top:0;left:0;width:33%;max-width:200px;height:100%;padding-top:10px;transform:translate(-100%);background:rgba(237,237,240,.9);box-shadow:inset -1px 0 #0000001c;transition:transform .4s;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-preview.netless-app-docs-viewer-preview-active{transform:translate(0)}.netless-app-docs-viewer-preview-page{position:relative;display:block;width:55%;margin-bottom:10px;font-size:0;color:transparent;outline:none;border:7px solid transparent;border-radius:4px;transition:border-color .3s;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-preview-page:hover,.netless-app-docs-viewer-preview-page.netless-app-docs-viewer-preview-page-active{border-color:#444e601a}.netless-app-docs-viewer-preview-page>img{width:100%;height:auto;box-sizing:border-box;border:1px solid rgba(0,0,0,.5);border-radius:1px;background-color:#fff;box-shadow:0 2px 8px #0000004d}.netless-app-docs-viewer-preview-page-name{position:absolute;top:1px;left:-10px;transform:translate(-100%);text-align:right;font-size:12px;color:#5f5f5f;user-select:none}.telebox-color-scheme-dark .netless-app-docs-viewer-preview{background:rgba(50,50,50,.9)}.netless-app-docs-viewer-content{position:relative;height:100%;overflow:hidden}.netless-app-docs-viewer-static-scrollbar{box-sizing:border-box;position:absolute;top:0;right:0;z-index:2147483647;width:16px;min-height:30px;margin:0;padding:0 0 0 8px;border:none;outline:none;opacity:0;background:transparent;transition:opacity .4s 3s,transform .1s;user-select:none;touch-action:none}.netless-app-docs-viewer-static-scrollbar:after{content:"";display:block;width:8px;height:100%;border-radius:4px;background:rgba(68,78,96,.4);box-shadow:1px 1px 8px #ffffffb3;transition:background .4s}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrolling{opacity:1;transition:opacity .4s,transform .1s}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrollbar-dragging{opacity:1;transition:opacity .4s 3s!important}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrollbar-dragging:after{background:rgba(68,78,96,.6)}.netless-app-docs-viewer-static-scrollbar:hover:after,.netless-app-docs-viewer-static-scrollbar:focus:after{background:rgba(68,78,96,.5)}.netless-app-docs-viewer-static-scrollbar:active:after{background:rgba(68,78,96,.6)}.telebox-body-wrap:hover .netless-app-docs-viewer-static-scrollbar{opacity:1;transition:opacity .4s,transform .1s}.telebox-readonly .netless-app-docs-viewer-static-scrollbar{display:none}.page-renderer-pages-container{position:relative;width:100%;height:100%}.page-renderer-page{position:absolute;top:0;left:0;background-position:center;background-size:cover;background-repeat:no-repeat}.page-renderer-pages-container.is-hwa .page-renderer-page{will-change:transform}.page-renderer-page-img{display:block;width:100%;height:auto;user-select:none}.netless-app-docs-viewer-static-pages{overflow:hidden;position:relative;height:100%;user-select:none}.netless-app-docs-viewer-static-page{display:block;width:100%;height:auto;user-select:none}.netless-app-docs-viewer-dynamic-wb-view{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;overflow:hidden}.netless-app-docs-viewer-dynamic-wb-view .cursor-clicker .ppt-event-source{cursor:pointer}
`;class I{constructor({namespace:e,pages$:t,sideEffect:s,readonly$:r,events:n,wrapClassName:l,root:c,pagesIndex$:p}){i(this,"namespace");i(this,"pages$");i(this,"sideEffect");i(this,"readonly$");i(this,"events");i(this,"wrapClassName");i(this,"showPreview$",new f.Val(!1));i(this,"$preview");i(this,"$previewMask");i(this,"previewLazyLoad");this.namespace=e,this.pages$=t,this.sideEffect=s,this.readonly$=r,this.events=n,this.wrapClassName=l,this.sideEffect.addDisposer(this.events.on("togglePreview",()=>{this.showPreview$.setValue(!this.showPreview$.value)})),this.sideEffect.addDisposer(this.showPreview$.subscribe(a=>{this.sideEffect.add(()=>{const h=this.renderPreview(),g=this.renderPreviewMask();if(a){c.appendChild(h),c.appendChild(g),h.scrollTop;const u=h.querySelector("."+this.wrapClassName(`preview-page-${p.value}`));return u&&h.scrollTo({top:u.offsetTop-16}),h.classList.toggle(this.wrapClassName("preview-active"),!0),this.previewLazyLoad=new R.default({container:this.$preview,elements_selector:"."+this.wrapClassName("preview-page>img")}),()=>{var d;return(d=this.previewLazyLoad)==null?void 0:d.destroy()}}else return h.classList.toggle(this.wrapClassName("preview-active"),!1),this.sideEffect.setTimeout(()=>{h.remove(),g.remove()},500,"preview-remove"),null},"preview-lazyload")}))}destroy(){var e,t;(e=this.$preview)==null||e.remove(),(t=this.$previewMask)==null||t.remove()}renderPreview(){if(this.$preview)return this.$preview;const e=document.createElement("div");return e.className=this.wrapClassName("preview")+" tele-fancy-scrollbar",this.$preview=e,this.sideEffect.addEventListener(e,"wheel",t=>t.stopPropagation(),{passive:!1}),this.sideEffect.addDisposer(this.pages$.subscribe(t=>{var s;this.sideEffect.add(()=>{const r=t.map((n,l)=>{var u;const c=(u=n.thumbnail)!=null?u:n.src.startsWith("ppt")?void 0:n.src;if(!c)return;const p=String(l),a=document.createElement("a");a.className=this.wrapClassName("preview-page")+" "+this.wrapClassName(`preview-page-${l}`),a.setAttribute("href","#"),a.dataset.pageIndex=p;const h=document.createElement("span");h.className=this.wrapClassName("preview-page-name"),h.textContent=String(l+1),h.dataset.pageIndex=p;const g=document.createElement("img");return g.width=n.width,g.height=n.height,g.dataset.src=c,g.dataset.pageIndex=p,a.appendChild(g),a.appendChild(h),e.appendChild(a),a});return()=>r.forEach(n=>n==null?void 0:n.remove())},"render-preview-pages"),(s=this.previewLazyLoad)==null||s.update()})),this.sideEffect.addEventListener(e,"click",t=>{var r;if(this.readonly$.value)return;const s=(r=t.target.dataset)==null?void 0:r.pageIndex;s&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),this.events.emit("jumpPage",Number(s)),this.showPreview$.setValue(!1))}),e}renderPreviewMask(){if(this.$previewMask)return this.$previewMask;const e=document.createElement("div");return e.className=this.wrapClassName("preview-mask"),this.$previewMask=e,this.sideEffect.addEventListener(e,"click",t=>{this.readonly$.value||t.target===e&&this.showPreview$.setValue(!1)}),e}}function H(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-sidebar`),t.setAttribute("viewBox","0 0 64 64");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M50 8H14c-3.309 0-6 2.691-6 6v36c0 3.309 2.691 6 6 6h36c3.309 0 6-2.691 6-6V14c0-3.309-2.691-6-6-6zM12 50V14c0-1.103.897-2 2-2h8v40h-8c-1.103 0-2-.897-2-2zm40 0c0 1.103-.897 2-2 2H26V12h24c1.103 0 2 .897 2 2z"),t.appendChild(s),t}function B(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-arrow-left`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M177.81 249.959L337.473 90.295c2.722-2.865 2.651-7.378-.143-10.1-2.793-2.65-7.163-2.65-9.956 0l-164.75 164.75c-2.793 2.793-2.793 7.306 0 10.1l164.75 164.75c2.865 2.722 7.378 2.65 10.099-.143 2.651-2.794 2.651-7.163 0-9.957L177.809 249.959z"),t.appendChild(s),t}function U(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-arrow-right`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M322.19 250.041L162.527 409.705c-2.722 2.865-2.651 7.378.143 10.1 2.793 2.65 7.163 2.65 9.956 0l164.75-164.75c2.793-2.793 2.793-7.306 0-10.1l-164.75-164.75c-2.865-2.722-7.378-2.65-10.099.143-2.651 2.794-2.651 7.163 0 9.957l159.664 159.736z"),t.appendChild(s),t}function F(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-play`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M418.158 257.419L174.663 413.33c-6.017 3.919-15.708 3.772-21.291-.29-2.791-2.018-4.295-4.483-4.295-7.084V94.109c0-5.65 6.883-10.289 15.271-10.289 4.298 0 8.391 1.307 11.181 3.332l242.629 155.484c6.016 3.917 6.451 10.292.649 14.491-.216.154-.432.154-.649.292zM170.621 391.288l223.116-141.301L170.71 107.753l-.089 283.535z"),t.appendChild(s),t}function W(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-pause`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M312.491 78.261c0-6.159 4.893-11.213 11.04-11.213 6.158 0 11.211 5.054 11.211 11.213v343.478c0 6.159-5.053 11.213-11.211 11.213-6.147 0-11.04-5.054-11.04-11.213V78.261zM165.257 78.261c0-6.159 4.893-11.213 11.04-11.213 6.158 0 11.211 5.054 11.211 11.213v343.478c0 6.159-5.053 11.213-11.211 11.213-6.147 0-11.04-5.054-11.04-11.213V78.261z"),t.appendChild(s),t}class Y{constructor({namespace:e,pages$:t,sideEffect:s,readonly$:r,events:n,playable:l,wrapClassName:c,pagesIndex$:p,root:a}){i(this,"namespace");i(this,"pages$");i(this,"sideEffect");i(this,"readonly$");i(this,"events");i(this,"playable");i(this,"wrapClassName");i(this,"pagesIndex$");i(this,"$footer");this.namespace=e,this.pages$=t,this.sideEffect=s,this.readonly$=r,this.events=n,this.wrapClassName=c,this.pagesIndex$=p,this.playable=l,this.$footer=this.render(),a.appendChild(this.$footer)}destroy(){this.$footer.remove()}render(){const e=document.createElement("div");e.className=this.wrapClassName("footer"),this.sideEffect.addDisposer(this.readonly$.subscribe(a=>e.classList.toggle(this.wrapClassName("readonly"),a)));const t=this.renderFooterBtn("btn-sidebar",H(this.namespace));this.sideEffect.addEventListener(t,"click",()=>{this.readonly$.value||this.events.emit("togglePreview")}),e.appendChild(t),this.sideEffect.addDisposer(this.pages$.subscribe(a=>{const h=a.some(g=>g.thumbnail||!g.src.startsWith("ppt"));t.style.display=h?"":"none"}));const s=document.createElement("div");s.className=this.wrapClassName("page-jumps");const r=this.renderFooterBtn("btn-page-back",B(this.namespace));if(this.sideEffect.addEventListener(r,"click",()=>{this.readonly$.value||this.events.emit("back")}),s.appendChild(r),this.playable){const a=this.renderFooterBtn("btn-page-play",F(this.namespace),W(this.namespace));this.sideEffect.addEventListener(a,"click",()=>{this.readonly$.value||(a.classList.toggle(this.wrapClassName("footer-btn-playing"),!0),this.events.emit("play"),this.sideEffect.setTimeout(()=>a.classList.toggle(this.wrapClassName("footer-btn-playing"),!1),500,"returnPlay"))}),s.appendChild(a)}const n=this.renderFooterBtn("btn-page-next",U(this.namespace));this.sideEffect.addEventListener(n,"click",()=>{this.readonly$.value||this.events.emit("next")}),s.appendChild(n);const l=document.createElement("div");l.className=this.wrapClassName("page-number");const c=document.createElement("input");c.className=this.wrapClassName("page-number-input"),this.sideEffect.addDisposer(this.readonly$.subscribe(a=>c.disabled=a)),this.sideEffect.addDisposer(this.pagesIndex$.subscribe(a=>c.value=String(a+1))),this.sideEffect.addEventListener(c,"blur",()=>{c.value=String(this.pagesIndex$.value+1)}),this.sideEffect.addEventListener(c,"change",()=>{if(this.readonly$.value)return;const a=c.value?Number(c.value)-1:NaN;a>=0?this.events.emit("jumpPage",a):c.value=String(this.pagesIndex$.value+1)});const p=document.createElement("span");return this.sideEffect.addDisposer(this.pages$.subscribe(a=>{p.textContent=" / "+a.length})),l.appendChild(c),l.appendChild(p),e.appendChild(s),e.appendChild(l),e}renderFooterBtn(e,t,s){const r=document.createElement("button");return r.className=this.wrapClassName("footer-btn")+" "+this.wrapClassName(e),r.appendChild(t),s&&r.appendChild(s),r}}class E{constructor({readonly$:e,pagesIndex$:t,previewRoot:s,footerRoot:r,pages$:n,playable:l}){i(this,"preview");i(this,"footer");i(this,"wrapClassName",e=>`${this.namespace}-${e}`);i(this,"namespace","netless-app-docs-viewer");i(this,"sideEffect",new b.SideEffectManager);i(this,"events",new V.Remitter);this.preview=new I({pages$:n,readonly$:e,pagesIndex$:t,root:s,sideEffect:this.sideEffect,events:this.events,namespace:this.namespace,wrapClassName:this.wrapClassName}),this.footer=new Y({pages$:n,readonly$:e,playable:l,pagesIndex$:t,root:r,namespace:this.namespace,sideEffect:this.sideEffect,events:this.events,wrapClassName:this.wrapClassName})}destroy(){this.preview.destroy(),this.footer.destroy(),this.sideEffect.flushAll(),this.events.destroy()}}function S(o,e,t){return Math.min(Math.max(o,e),t)}function C(o){return o.touches?o.touches[0]:o}function k(o){o.stopPropagation(),o.cancelable&&o.preventDefault()}function N(o,e){return o.width===e.width&&o.height===e.height}class T{constructor(e){i(this,"stiffness");i(this,"damping");i(this,"current");i(this,"target");i(this,"velocity",0);i(this,"onStep");i(this,"_paused",!0);i(this,"_animationFrameID",null);i(this,"_loopTimestamp",0);i(this,"looper",e=>{var s;if(this._paused)return;let t=Math.floor((e-this._loopTimestamp)/1e3*60)+1;for(this._loopTimestamp=e;t-- >0;)this.stepper();(s=this.onStep)==null||s.call(this,this.current),this._paused?this._animationFrameID=null:this._animationFrameID=window.requestAnimationFrame(this.looper)});var t,s,r;this.current=(t=e.start)!=null?t:0,this.target=this.current,this.stiffness=(s=e.stiffness)!=null?s:170,this.damping=(r=e.damping)!=null?r:26,this.onStep=e.onStep}get paused(){return this._paused}stepTo(e,t){var s;this._paused&&t!=null&&(this.current=t),this._paused=!1,this.target=e,(s=this.onStep)==null||s.call(this,this.current),this._loopTimestamp=Date.now(),this._animationFrameID=window.requestAnimationFrame(this.looper)}pause(){this._paused=!0,this._animationFrameID!=null&&window.cancelAnimationFrame(this._animationFrameID)}destroy(){this.pause(),this.onStep=void 0}stepper(){const e=-this.stiffness*(this.current-this.target),t=-this.damping*this.velocity,s=this.velocity+(e+t)/60,r=this.current+s/60;Math.abs(s-0)<.01&&Math.abs(r-this.target)<.01?(this.current=this.target,this.velocity=0,this._paused=!0):(this.current=r,this.velocity=s)}}class j{constructor(e,t,s,r,n,l){i(this,"lastVisit",Date.now());i(this,"$page");i(this,"sideEffect",new b.SideEffectManager);this.index=e;const c=f.derive(t,u=>u[e]||{width:0,height:0}),p=f.combine([c,s],([u,d])=>(d.width-u.width)/2),a=f.combine([n,l],([u,d])=>(u[e]||0)-d),h=document.createElement("div");h.className="page-renderer-page",h.dataset.index=`${e}`;const g=document.createElement("img");g.className="page-renderer-page-img",h.appendChild(g),this.sideEffect.addDisposer([f.combine([c,r]).subscribe(([u,d])=>{h.style.width=`${u.width*d}px`,h.style.height=`${u.height*d}px`}),c.subscribe(u=>{u.thumbnail&&(h.style.backgroundImage=`url("${u.thumbnail}")`),g.width=u.width,g.height=u.height,g.src=u.src}),f.combine([p,a,r]).subscribe(([u,d,w])=>{h.style.transform=`translate(${u*w}px, ${d*w}px)`})]),this.$page=h}destroy(){this.sideEffect.flushAll(),this.$page.remove()}}class O{constructor(e,t,s,r,n){i(this,"els",new Map);i(this,"maxElCount",200);i(this,"gcTimer",null);i(this,"schedule");i(this,"cancelSchedule");i(this,"gc",()=>{var e;if(this.gcTimer=null,this.els.size>this.maxElCount){const t=[...this.els.values()].sort((s,r)=>r.lastVisit-s.lastVisit);for(let s=Math.floor(this.maxElCount/4);s<t.length;s++)(e=this.els.get(t[s].index))==null||e.destroy(),this.els.delete(t[s].index)}});this.pages$=e,this.pagesSize$=t,this.scale$=s,this.pagesYs$=r,this.pagesScrollTop$=n,this.schedule=window.requestIdleCallback||(l=>window.setTimeout(l,5e3)),this.cancelSchedule=window.cancelIdleCallback||window.clearTimeout}getEl(e){let t=this.els.get(e);return t||(t=new j(e,this.pages$,this.pagesSize$,this.scale$,this.pagesYs$,this.pagesScrollTop$),this.els.set(e,t)),t.lastVisit=Date.now(),this.els.size>this.maxElCount&&this.gcTimer===null&&(this.gcTimer=this.schedule(this.gc)),t}destroy(){this.els.forEach(e=>e.destroy()),this.els.clear(),this.gcTimer!==null&&(this.cancelSchedule(this.gcTimer),this.gcTimer=null)}}class P{constructor({pagesScrollTop$:e,containerRect$:t,pages$:s,pagesSize$:r}){i(this,"$pages");i(this,"sideEffect",new b.SideEffectManager);i(this,"pageElManager");s=f.derive(s,d=>d.map(w=>{if(w.thumbnail)return w;try{const m=new URL(w.src);return m.searchParams.set("x-oss-process","image/resize,l_50"),{...w,thumbnail:m.toString()}}catch(m){return console.error(m),w}}));const n=f.derive(s,d=>{const w=Array(d.length);for(let m=0;m<d.length;m++)w[m]=m>0?w[m-1]+d[m-1].height:0;return w}),l=f.derive(s,d=>{let w=1/0;for(let m=d.length-1;m>=0;m--)d[m].height<=w&&(w=d[m].height);return w}),c=f.combine([e,n,s],([d,w,m])=>{if(w.length!==m.length)return c.value;for(let $=0;$<w.length;$++)if(w[$]+m[$].height-d>=.001)return $;return w.length-1}),p=f.combine([t,r],([d,w])=>d.width/w.width||1),a=f.combine([s,t,l,p],([d,w,m,$])=>S(Math.ceil(w.height/$/m/2),1,d.length));f.withReadonlyValueEnhancer(this,{pagesScrollTop:e,containerRect:t,pages:s,pagesSize:r,pagesIndex:c,pagesYs:n,pagesMinHeight:l,scale:p}),this.pageElManager=new O(s,r,p,n,e),this.$pages=this.renderPages();const h=new f.Val(!1);this.sideEffect.addDisposer(h.subscribe(d=>this.$pages.classList.toggle("is-hwa",d)));const g=()=>h.setValue(!1),u=()=>{this.sideEffect.setTimeout(g,1e3,"turn-off-hwa"),h.setValue(!0)};this.sideEffect.addDisposer(f.combine([c,a,s]).subscribe(([d,w,m])=>{u();const $=Math.max(d-w,0),M=Math.min(d+w,m.length-1);for(let y=0;y<this.$pages.children.length;y++){const x=this.$pages.children[y],z=Number(x.dataset.index);z>=$&&z<=M||(x.remove(),y--)}for(let y=$;y<=M;y++){const x=this.pageElManager.getEl(y);x.$page.parentElement!==this.$pages&&this.$pages.appendChild(x.$page)}}))}renderPages(){const e=document.createElement("div");return e.className="page-renderer-pages-container",this.sideEffect.addDisposer(this._containerRect$.subscribe(t=>{e.style.width=`${t.width}px`,e.style.height=`${t.height}px`}),"render-pages-size"),e}destroy(){this.sideEffect.flushAll(),this.$pages.remove(),this.pageElManager.destroy()}}const G=30;class D{constructor({pagesScrollTop$:e,containerRect$:t,stageRect$:s,pagesSize$:r,readonly$:n,scrollbarMinHeight:l=G,wrapClassName:c,onDragScroll:p}){i(this,"sideEffect",new b.SideEffectManager);i(this,"scrollbarMinHeight");i(this,"readonly$");i(this,"wrapClassName");i(this,"onDragScroll");i(this,"$scrollbar");i(this,"pagesScrollTop$");i(this,"containerRect$");i(this,"stageRect$");i(this,"pagesSize$");i(this,"scrolling$",new f.Val(!1));i(this,"scrollbarHeight$");i(this,"scrollTop$");this.pagesScrollTop$=e,this.containerRect$=t,this.stageRect$=s,this.pagesSize$=r,this.scrollbarMinHeight=l,this.readonly$=n,this.wrapClassName=c,this.onDragScroll=p,this.scrollbarHeight$=f.combine([t,s,r],([a,h,g])=>S(h.height/(h.width/g.width*g.height)*a.height,l,a.height)),this.scrollTop$=f.combine([t,s,r,this.scrollbarHeight$,this.pagesScrollTop$],([a,h,g,u,d])=>S(d/(g.height-g.width/h.width*h.height)*(a.height-u),0,a.height-u)),this.$scrollbar=this.renderScrollbar()}mount(e){e.appendChild(this.$scrollbar)}destroy(){this.$scrollbar.remove(),this.onDragScroll=void 0,this.sideEffect.flushAll()}renderScrollbar(){const e=document.createElement("button");e.className=this.wrapClassName("scrollbar"),e.style.minHeight=`${this.scrollbarMinHeight}px`,this.sideEffect.addDisposer([this.scrollbarHeight$.subscribe(s=>{e.style.height=`${s}px`}),this.scrollTop$.subscribe(s=>{this.scrolling$.setValue(!0),this.sideEffect.setTimeout(()=>this.scrolling$.setValue(!1),100,"reset-scrolling");const r=()=>e.style.transform=`translateY(${s}px)`;window.requestAnimationFrame?window.requestAnimationFrame(r):r()}),this.scrolling$.subscribe(s=>{e.classList.toggle(this.wrapClassName("scrolling"),s)})]);const t=s=>{if(!s.isPrimary||this.readonly$.value||s.button!=null&&s.button!==0)return;k(s);const r=this.wrapClassName("scrollbar-dragging");e.classList.toggle(r,!0);const n=this.pagesScrollTop$.value,{clientY:l}=C(s),c=a=>{if(!a.isPrimary||this.readonly$.value)return;const{clientY:h}=C(a),g=h-l;Math.abs(g)>0&&this.onDragScroll&&this.onDragScroll(n+g/this.containerRect$.value.height*this.pagesSize$.value.height)},p=a=>{!a.isPrimary||(e.classList.toggle(r,!1),window.removeEventListener("pointermove",c,!0),window.removeEventListener("pointerup",p,!0),window.removeEventListener("pointercancel",p,!0))};window.addEventListener("pointermove",c,!0),window.addEventListener("pointerup",p,!0),window.addEventListener("pointercancel",p,!0)};return this.sideEffect.addEventListener(e,"pointerdown",t),e}}class q{constructor({whiteboard:e,readonly$:t,box:s,pages:r,pagesScrollTop:n=0,onUserScroll:l}){i(this,"readonly$");i(this,"pagesScrollTop$");i(this,"pagesSize$");i(this,"pageRenderer");i(this,"scrollbar");i(this,"sideEffect",new b.SideEffectManager);i(this,"pageScrollStepper");i(this,"userScrolling",!1);i(this,"pages");i(this,"box");i(this,"whiteboard");i(this,"onUserScroll");i(this,"debounceOnUserScroll");i(this,"viewer");this.whiteboard=e,this.readonly$=t,this.box=s,this.pages=r,this.onUserScroll=l;const c=()=>{var a;this.userScrolling=!1,(a=this.onUserScroll)==null||a.call(this,this.pagesScrollTop$.value)};this.debounceOnUserScroll=()=>{this.userScrolling=!0,this.sideEffect.setTimeout(c,80,"debounceOnUserScroll")};const p=new f.Val(r);this.pagesScrollTop$=new f.Val(n),this.pagesSize$=f.derive(p,a=>{let h=0,g=0;for(let u=a.length-1;u>=0;u--){const d=a[u];d.width>h&&(h=d.width),g+=d.height}return{width:Math.max(1,h),height:Math.max(1,g)}},{compare:N}),this.pageRenderer=new P({pagesScrollTop$:this.pagesScrollTop$,containerRect$:s._stageRect$,pages$:p,pagesSize$:this.pagesSize$}),this.viewer=new E({readonly$:t,pagesIndex$:this.pageRenderer._pagesIndex$,previewRoot:s.$body,footerRoot:s.$footer,pages$:p,playable:!1}),this.sideEffect.addDisposer([this.viewer.events.on("next",()=>{this.userScrollByPercent(.8)}),this.viewer.events.on("back",()=>{this.userScrollByPercent(-.8)})]),this.scrollbar=new D({pagesScrollTop$:this.pagesScrollTop$,containerRect$:s._bodyRect$,stageRect$:s._stageRect$,pagesSize$:this.pagesSize$,readonly$:t,wrapClassName:this.wrapClassName.bind(this),onDragScroll:a=>{this.pageScrollTo(a),this.debounceOnUserScroll()}}),this.pageScrollStepper=new T({start:this.pagesScrollTop$.value,onStep:a=>{this.pageScrollTo(a)}}),this.sideEffect.addDisposer(this.viewer.events.on("jumpPage",a=>this.userScrollToPageIndex(a))),this.render(),this.setupScrollListener(),this.sideEffect.setTimeout(()=>{this.userScrolling||this.pageScrollTo(this.pageRenderer.pagesScrollTop)},100)}get pagesScrollTop(){return this.pagesScrollTop$.value}destroy(){this.sideEffect.flushAll(),this.pageScrollStepper.destroy(),this.onUserScroll=void 0,this.viewer.destroy(),this.pageRenderer.destroy(),this.scrollbar.destroy()}syncPageScrollTop(e){!this.userScrolling&&e>=0&&Math.abs(this.pagesScrollTop$.value-e)>.01&&this.pageScrollStepper.stepTo(e,this.pagesScrollTop$.value)}render(){this.box.$content.style.overflow="hidden",this.box.mountStage(this.pageRenderer.$pages),this.scrollbar.mount(this.box.$body)}pageScrollTo(e){const t=this.whiteboard.view.size.height/2/this.pageRenderer.scale;this.whiteboard.view.moveCamera({centerY:S(e+t,t,this.pagesSize$.value.height-t),animationMode:"immediately"})}userScrollToPageIndex(e){var t;if(e=S(e,0,this.pages.length-1),!this.readonly$.value&&!Number.isNaN(e)){const s=this.pageRenderer.pagesYs[e];s>=0&&((t=this.onUserScroll)==null||t.call(this,s+5/this.pageRenderer.scale))}}userScrollByPercent(e){var t;this.readonly$.value||(t=this.onUserScroll)==null||t.call(this,S(this.pageRenderer.pagesScrollTop+this.pageRenderer.containerRect.height/this.pageRenderer.scale*S(e,-1,1),0,this.pageRenderer.pagesSize.height-this.pageRenderer.containerRect.height/this.pageRenderer.scale))}setupScrollListener(){this.sideEffect.addEventListener(this.box.$main,"wheel",e=>{k(e),!this.readonly$.value&&this.pageScrollStepper.paused&&(this.pageScrollTo(this.pagesScrollTop+e.deltaY),this.debounceOnUserScroll())},{passive:!1}),this.sideEffect.addEventListener(this.box.$main,"touchmove",e=>{!this.readonly$.value&&e.touches.length>1&&this.debounceOnUserScroll()},{passive:!0,capture:!0}),this.sideEffect.add(()=>{const e=t=>{const{width:s,height:r}=this.whiteboard.view.size;if(s<=0||r<=0)return;const n=t.centerY-this.pageRenderer.containerRect.height/this.pageRenderer.scale/2;this.pagesScrollTop$.setValue(Math.max(0,n))};return this.whiteboard.view.callbacks.on("onCameraUpdated",e),()=>this.whiteboard.view.callbacks.off("onCameraUpdated",e)}),this.sideEffect.addDisposer(this.box._stageRect$.subscribe(e=>{const{width:t,height:s}=this.pagesSize$.value;this.whiteboard.view.moveCameraToContain({originX:0,originY:this.pageRenderer.pagesScrollTop,width:t,height:e.height/this.pageRenderer.scale,animationMode:"immediately"}),this.whiteboard.view.setCameraBound({damping:1,maxContentMode:()=>this.pageRenderer.scale,minContentMode:()=>this.pageRenderer.scale,centerX:t/2,centerY:s/2,width:t,height:s})}),"whiteboard-size-update"),this.sideEffect.addEventListener(window,"keyup",e=>{if(!(this.readonly$.value||!this.box.focus||this.box.minimized))switch(e.key){case"PageDown":{this.userScrollByPercent(.8);break}case"PageUp":{this.userScrollByPercent(-.8);break}case"ArrowLeft":{this.userScrollByPercent(-.25);break}case"ArrowRight":{this.userScrollByPercent(.25);break}case"ArrowDown":{this.userScrollByPercent(.5);break}case"ArrowUp":{this.userScrollByPercent(-.5);break}}},{capture:!0})}wrapClassName(e){return"netless-app-docs-viewer-static-"+e}}class J{constructor({readonly$:e,context:t,whiteboard:s,box:r,pages:n}){i(this,"pagesIndex$");i(this,"sideEffect",new b.SideEffectManager);i(this,"context");i(this,"pages");i(this,"box");i(this,"whiteboard");i(this,"viewer");this.context=t,this.whiteboard=s,this.box=r,this.pages=n;const l=new f.Val(t.displayer.state.sceneState.index||0);this.pagesIndex$=l,this.sideEffect.add(()=>{const c=p=>{this.jumpToPage(p.index)};return this.context.emitter.on("sceneStateChange",c),()=>this.context.emitter.off("sceneStateChange",c)}),this.viewer=new E({readonly$:e,pagesIndex$:l,previewRoot:r.$body,footerRoot:r.$footer,pages$:new f.Val(n),playable:!0}),this.sideEffect.addDisposer([this.viewer.events.on("jumpPage",c=>this.jumpToPage(c,!0)),this.viewer.events.on("play",()=>{var c;return(c=this.context.room)==null?void 0:c.pptNextStep()}),this.viewer.events.on("back",()=>this.prevPage()),this.viewer.events.on("next",()=>this.nextPage())]),this.render(),this.sideEffect.addDisposer(l.subscribe((c,p)=>{var g,u;if(e.value)return;const a=this.context.getInitScenePath(),h=(u=(g=this.context.getScenes())==null?void 0:g[c])==null?void 0:u.name;if(a&&h&&this.context.setScenePath(`${a}/${h}`),p){const d=this.context.room;if(d){const w=d.state.globalState.__pptState;d.setGlobalState({__pptState:w&&{uuid:w.uuid,pageIndex:c,disableAutoPlay:w.disableAutoPlay}})}}}))}destroy(){this.sideEffect.flushAll(),this.viewer.destroy()}nextPage(){this.jumpToPage(this.pagesIndex$.value+1,!0)}prevPage(){this.jumpToPage(this.pagesIndex$.value-1,!0)}jumpToPage(e,t=!1){this.pagesIndex$.setValue(S(e,0,this.pages.length-1),t)}render(){var t;this.box.mountStage(document.createElement("div")),this.sideEffect.addEventListener(window,"keydown",s=>{var r;if(this.box.focus)switch(s.key){case"ArrowUp":case"ArrowLeft":{this.prevPage();break}case"ArrowRight":case"ArrowDown":{(r=this.context.room)==null||r.pptNextStep();break}}});const e=(t=this.whiteboard.view.divElement)==null?void 0:t.parentElement;e&&this.sideEffect.addEventListener(e,"click",s=>{var n;const r=this.context.room;if(r&&r.state.memberState.currentApplianceName==="clicker"){for(let l=s.target;l;l=l.parentElement)if((n=l.classList)!=null&&n.contains("ppt-event-source"))return;r.pptNextStep()}})}wrapClassName(e){return"netless-app-docs-viewer-dynamic-"+e}}const L={kind:"DocsViewer",setup(o){const e=o.box,t=o.getScenes();if(!t)throw new Error("[Docs Viewer]: scenes not found.");const s=new b.SideEffectManager,r=t.map(({ppt:l})=>l?{width:l.width,height:l.height,src:l.src,thumbnail:l.previewURL}:null).filter(l=>Boolean(l));if(r.length<=0)throw new Error("[Docs Viewer]: empty scenes.");e.mountStyles(_);const n=new f.Val(!o.isWritable);s.addDisposer(o.emitter.on("writableChange",l=>{n.setValue(!l)})),r[0].src.startsWith("ppt")?K(s,o,e,r,n):X(s,o,e,r,n),s.addDisposer(o.emitter.on("destroy",()=>{s.flushAll()}))}};function X(o,e,t,s,r){const n=e.createWhiteBoardView({syncCamera:!1});o.addDisposer(r.subscribe(p=>{n.view.disableCameraTransform=p}));const l=e.createStorage("static-docs-viewer",{pagesScrollTop:0}),c=new q({whiteboard:n,readonly$:r,box:t,pages:s,pagesScrollTop:l.state.pagesScrollTop,onUserScroll:p=>{e.isWritable&&l.setState({pagesScrollTop:p})}});o.addDisposer(()=>c.destroy()),o.addDisposer(l.on("stateChanged",p=>{p.pagesScrollTop&&c.syncPageScrollTop(p.pagesScrollTop.newValue||0)})),o.addDisposer(f.combine([t._maximized$,t._managerStageRect$,t._intrinsicSize$,c.pagesSize$,c.pageRenderer._pagesMinHeight$],([p,a,h,g,u])=>p?Math.max(u/g.width*.4,a.height/a.width):h.height/h.width*(a.height/a.width)).subscribe(p=>{t.setStageRatio(p)}))}function K(o,e,t,s,r){const n=e.createWhiteBoardView();n.view.disableCameraTransform=!0;const l=new J({context:e,whiteboard:n,box:t,pages:s,readonly$:r});o.addDisposer(()=>l.destroy());const c=new f.Val({width:s[0].width,height:s[0].height},{compare:N});if(o.addDisposer(l.pagesIndex$.subscribe(p=>{const a=s[p];a&&c.setValue({width:a.width,height:a.height})})),o.addDisposer(c.subscribe(p=>{r.value||n.setBaseRect(p)})),e.isAddApp){const p=o.add(()=>{const a=({width:h,height:g})=>{if(s.length>0&&t.state!=="maximized"){const{width:u,height:d}=s[0],m=d/u*h-g;m!==0&&e.isWritable&&e.emitter.emit("setBoxSize",{width:t.intrinsicWidth,height:t.intrinsicHeight+m/t.rootRect.height})}o.remove(p)};return n.view.callbacks.once("onSizeUpdated",a),()=>n.view.callbacks.off("onSizeUpdated",a)})}}return v.DocsViewer=E,v.NetlessAppDocsViewer=L,v.PageRenderer=P,v.ScrollBar=D,v.Stepper=T,v.default=L,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),v}({},sideEffectManager,valueEnhancer,LazyLoad,remitter);
//# sourceMappingURL=main.iife.js.map

@@ -1,3 +0,3 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=require("side-effect-manager"),f=require("value-enhancer"),L=require("vanilla-lazyload"),z=require("remitter"),V=o=>o&&typeof o=="object"&&"default"in o?o:{default:o},A=V(L);const R=`.netless-app-docs-viewer-footer{box-sizing:border-box;height:26px;display:flex;align-items:center;padding:0 16px;border-top:1px solid #eeeef7;font-family:PingFang SC,Source Han Sans SC,Microsoft YaHei,Helvetica Neue,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif}.netless-app-docs-viewer-footer-btn{box-sizing:border-box;width:26px;height:26px;font-size:0;margin:0;padding:3px;border:none;border-radius:1px;outline:none;color:currentColor;background:transparent;transition:background .4s;cursor:pointer;user-select:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-docs-viewer-footer-btn:hover{background:rgba(237,237,240,.9)}@media (hover: none){.netless-app-docs-viewer-footer-btn:hover{background:transparent!important}}.netless-app-docs-viewer-footer-btn>svg{width:100%;height:100%}.netless-app-docs-viewer-footer-btn>svg:nth-of-type(2){display:none}.netless-app-docs-viewer-footer-btn.netless-app-docs-viewer-footer-btn-playing>svg:nth-of-type(1){display:none}.netless-app-docs-viewer-footer-btn.netless-app-docs-viewer-footer-btn-playing>svg:nth-of-type(2){display:initial}.netless-app-docs-viewer-footer-btn~.netless-app-docs-viewer-footer-btn{margin-left:15px}.netless-app-docs-viewer-page-jumps{flex:1;display:flex;justify-content:center;align-items:center}.netless-app-docs-viewer-page-number{display:flex;align-items:center;height:26px;margin-left:auto;font-size:13px;white-space:nowrap;word-break:keep-all;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-page-number-input{border:none;outline:none;width:3em;margin:0;padding:0 .5em 0 2px;text-align:right;font-size:13px;line-height:1;font-weight:400;font-family:inherit;border-radius:2px;color:currentColor;font-family:PingFang SC,Source Han Sans SC,Microsoft YaHei,Helvetica Neue,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif;background:transparent;transition:background .4s;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-docs-viewer-page-number-input:hover,.netless-app-docs-viewer-page-number-input:focus,.netless-app-docs-viewer-page-number-input:active{user-select:text;background:#fff;box-shadow:#63636333 0 2px 8px}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-footer-btn{cursor:not-allowed}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-footer-btn:hover{background:transparent}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input{cursor:not-allowed}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:hover,.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:focus,.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:active{background:transparent;box-shadow:none}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:disabled{color:inherit}.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:active,.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:focus,.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:hover{color:currentColor;background:#25282e}.telebox-color-scheme-dark .netless-app-docs-viewer-footer{border-top:none}.telebox-color-scheme-dark .netless-app-docs-viewer-footer-btn:hover{background:#212126}.netless-app-docs-viewer-preview-mask{position:absolute;z-index:10200;top:0;left:0;width:100%;height:100%}.netless-app-docs-viewer-preview{box-sizing:border-box;display:flex;flex-direction:column;align-items:center;position:absolute;z-index:10300;top:0;left:0;width:33%;max-width:200px;height:100%;padding-top:10px;transform:translate(-100%);background:rgba(237,237,240,.9);box-shadow:inset -1px 0 #0000001c;transition:transform .4s;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-preview.netless-app-docs-viewer-preview-active{transform:translate(0)}.netless-app-docs-viewer-preview-page{position:relative;display:block;width:55%;margin-bottom:10px;font-size:0;color:transparent;outline:none;border:7px solid transparent;border-radius:4px;transition:border-color .3s;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-preview-page:hover,.netless-app-docs-viewer-preview-page.netless-app-docs-viewer-preview-page-active{border-color:#444e601a}.netless-app-docs-viewer-preview-page>img{width:100%;height:auto;box-sizing:border-box;border:1px solid rgba(0,0,0,.5);border-radius:1px;background-color:#fff;box-shadow:0 2px 8px #0000004d}.netless-app-docs-viewer-preview-page-name{position:absolute;top:1px;left:-10px;transform:translate(-100%);text-align:right;font-size:12px;color:#5f5f5f;user-select:none}.telebox-color-scheme-dark .netless-app-docs-viewer-preview{background:rgba(50,50,50,.9)}.netless-app-docs-viewer-content{position:relative;height:100%;overflow:hidden}.netless-app-docs-viewer-static-scrollbar{box-sizing:border-box;position:absolute;top:0;right:0;z-index:2147483647;width:16px;min-height:30px;margin:0;padding:0 0 0 8px;border:none;outline:none;opacity:0;background:transparent;transition:opacity .4s 3s,transform .1s;user-select:none;touch-action:none}.netless-app-docs-viewer-static-scrollbar:after{content:"";display:block;width:8px;height:100%;border-radius:4px;background:rgba(68,78,96,.4);box-shadow:1px 1px 8px #ffffffb3;transition:background .4s}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrolling{opacity:1;transition:opacity .4s,transform .1s}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrollbar-dragging{opacity:1;transition:opacity .4s 3s!important}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrollbar-dragging:after{background:rgba(68,78,96,.6)}.netless-app-docs-viewer-static-scrollbar:hover:after,.netless-app-docs-viewer-static-scrollbar:focus:after{background:rgba(68,78,96,.5)}.netless-app-docs-viewer-static-scrollbar:active:after{background:rgba(68,78,96,.6)}.telebox-body-wrap:hover .netless-app-docs-viewer-static-scrollbar{opacity:1;transition:opacity .4s,transform .1s}.telebox-readonly .netless-app-docs-viewer-static-scrollbar{display:none}.page-renderer-pages-container{position:relative;width:100%;height:100%}.page-renderer-page{position:absolute;top:0;left:0;background-position:center;background-size:cover;background-repeat:no-repeat}.page-renderer-pages-container.is-hwa .page-renderer-page{will-change:transform}.page-renderer-page-img{display:block;width:100%;height:auto;user-select:none}.netless-app-docs-viewer-static-pages{overflow:hidden;position:relative;height:100%;user-select:none}.netless-app-docs-viewer-static-page{display:block;width:100%;height:auto;user-select:none}.netless-app-docs-viewer-dynamic-wb-view{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;overflow:hidden}.netless-app-docs-viewer-dynamic-wb-view .cursor-clicker .ppt-event-source{cursor:pointer}
`;class _{constructor({namespace:e,pages$:t,sideEffect:s,readonly$:r,events:l,wrapClassName:n,root:a,pagesIndex$:c}){this.showPreview$=new f.Val(!1),this.namespace=e,this.pages$=t,this.sideEffect=s,this.readonly$=r,this.events=l,this.wrapClassName=n,this.sideEffect.addDisposer(this.events.on("togglePreview",()=>{this.showPreview$.setValue(!this.showPreview$.value)})),this.sideEffect.addDisposer(this.showPreview$.subscribe(i=>{this.sideEffect.add(()=>{const h=this.renderPreview(),d=this.renderPreviewMask();if(i){a.appendChild(h),a.appendChild(d),h.scrollTop;const u=h.querySelector("."+this.wrapClassName(`preview-page-${c.value}`));return u&&h.scrollTo({top:u.offsetTop-16}),h.classList.toggle(this.wrapClassName("preview-active"),!0),this.previewLazyLoad=new A.default({container:this.$preview,elements_selector:"."+this.wrapClassName("preview-page>img")}),()=>{var p;return(p=this.previewLazyLoad)==null?void 0:p.destroy()}}else return h.classList.toggle(this.wrapClassName("preview-active"),!1),this.sideEffect.setTimeout(()=>{h.remove(),d.remove()},500,"preview-remove"),null},"preview-lazyload")}))}destroy(){var e,t;(e=this.$preview)==null||e.remove(),(t=this.$previewMask)==null||t.remove()}renderPreview(){if(this.$preview)return this.$preview;const e=document.createElement("div");return e.className=this.wrapClassName("preview")+" tele-fancy-scrollbar",this.$preview=e,this.sideEffect.addEventListener(e,"wheel",t=>t.stopPropagation(),{passive:!1}),this.sideEffect.addDisposer(this.pages$.subscribe(t=>{var s;this.sideEffect.add(()=>{const r=t.map((l,n)=>{var u;const a=(u=l.thumbnail)!=null?u:l.src.startsWith("ppt")?void 0:l.src;if(!a)return;const c=String(n),i=document.createElement("a");i.className=this.wrapClassName("preview-page")+" "+this.wrapClassName(`preview-page-${n}`),i.setAttribute("href","#"),i.dataset.pageIndex=c;const h=document.createElement("span");h.className=this.wrapClassName("preview-page-name"),h.textContent=String(n+1),h.dataset.pageIndex=c;const d=document.createElement("img");return d.width=l.width,d.height=l.height,d.dataset.src=a,d.dataset.pageIndex=c,i.appendChild(d),i.appendChild(h),e.appendChild(i),i});return()=>r.forEach(l=>l==null?void 0:l.remove())},"render-preview-pages"),(s=this.previewLazyLoad)==null||s.update()})),this.sideEffect.addEventListener(e,"click",t=>{var r;if(this.readonly$.value)return;const s=(r=t.target.dataset)==null?void 0:r.pageIndex;s&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),this.events.emit("jumpPage",Number(s)),this.showPreview$.setValue(!1))}),e}renderPreviewMask(){if(this.$previewMask)return this.$previewMask;const e=document.createElement("div");return e.className=this.wrapClassName("preview-mask"),this.$previewMask=e,this.sideEffect.addEventListener(e,"click",t=>{this.readonly$.value||t.target===e&&this.showPreview$.setValue(!1)}),e}}function I(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-sidebar`),t.setAttribute("viewBox","0 0 64 64");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M50 8H14c-3.309 0-6 2.691-6 6v36c0 3.309 2.691 6 6 6h36c3.309 0 6-2.691 6-6V14c0-3.309-2.691-6-6-6zM12 50V14c0-1.103.897-2 2-2h8v40h-8c-1.103 0-2-.897-2-2zm40 0c0 1.103-.897 2-2 2H26V12h24c1.103 0 2 .897 2 2z"),t.appendChild(s),t}function B(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-arrow-left`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M177.81 249.959L337.473 90.295c2.722-2.865 2.651-7.378-.143-10.1-2.793-2.65-7.163-2.65-9.956 0l-164.75 164.75c-2.793 2.793-2.793 7.306 0 10.1l164.75 164.75c2.865 2.722 7.378 2.65 10.099-.143 2.651-2.794 2.651-7.163 0-9.957L177.809 249.959z"),t.appendChild(s),t}function H(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-arrow-right`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M322.19 250.041L162.527 409.705c-2.722 2.865-2.651 7.378.143 10.1 2.793 2.65 7.163 2.65 9.956 0l164.75-164.75c2.793-2.793 2.793-7.306 0-10.1l-164.75-164.75c-2.865-2.722-7.378-2.65-10.099.143-2.651 2.794-2.651 7.163 0 9.957l159.664 159.736z"),t.appendChild(s),t}function U(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-play`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M418.158 257.419L174.663 413.33c-6.017 3.919-15.708 3.772-21.291-.29-2.791-2.018-4.295-4.483-4.295-7.084V94.109c0-5.65 6.883-10.289 15.271-10.289 4.298 0 8.391 1.307 11.181 3.332l242.629 155.484c6.016 3.917 6.451 10.292.649 14.491-.216.154-.432.154-.649.292zM170.621 391.288l223.116-141.301L170.71 107.753l-.089 283.535z"),t.appendChild(s),t}function F(o){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${o}-footer-icon-pause`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M312.491 78.261c0-6.159 4.893-11.213 11.04-11.213 6.158 0 11.211 5.054 11.211 11.213v343.478c0 6.159-5.053 11.213-11.211 11.213-6.147 0-11.04-5.054-11.04-11.213V78.261zM165.257 78.261c0-6.159 4.893-11.213 11.04-11.213 6.158 0 11.211 5.054 11.211 11.213v343.478c0 6.159-5.053 11.213-11.211 11.213-6.147 0-11.04-5.054-11.04-11.213V78.261z"),t.appendChild(s),t}class W{constructor({namespace:e,pages$:t,sideEffect:s,readonly$:r,events:l,playable:n,wrapClassName:a,pagesIndex$:c,root:i}){this.namespace=e,this.pages$=t,this.sideEffect=s,this.readonly$=r,this.events=l,this.wrapClassName=a,this.pagesIndex$=c,this.playable=n,this.$footer=this.render(),i.appendChild(this.$footer)}destroy(){this.$footer.remove()}render(){const e=document.createElement("div");e.className=this.wrapClassName("footer"),this.sideEffect.addDisposer(this.readonly$.subscribe(i=>e.classList.toggle(this.wrapClassName("readonly"),i)));const t=this.renderFooterBtn("btn-sidebar",I(this.namespace));this.sideEffect.addEventListener(t,"click",()=>{this.readonly$.value||this.events.emit("togglePreview")}),e.appendChild(t),this.sideEffect.addDisposer(this.pages$.subscribe(i=>{const h=i.some(d=>d.thumbnail||!d.src.startsWith("ppt"));t.style.display=h?"":"none"}));const s=document.createElement("div");s.className=this.wrapClassName("page-jumps");const r=this.renderFooterBtn("btn-page-back",B(this.namespace));if(this.sideEffect.addEventListener(r,"click",()=>{this.readonly$.value||this.events.emit("back")}),s.appendChild(r),this.playable){const i=this.renderFooterBtn("btn-page-play",U(this.namespace),F(this.namespace));this.sideEffect.addEventListener(i,"click",()=>{this.readonly$.value||(i.classList.toggle(this.wrapClassName("footer-btn-playing"),!0),this.events.emit("play"),this.sideEffect.setTimeout(()=>i.classList.toggle(this.wrapClassName("footer-btn-playing"),!1),500,"returnPlay"))}),s.appendChild(i)}const l=this.renderFooterBtn("btn-page-next",H(this.namespace));this.sideEffect.addEventListener(l,"click",()=>{this.readonly$.value||this.events.emit("next")}),s.appendChild(l);const n=document.createElement("div");n.className=this.wrapClassName("page-number");const a=document.createElement("input");a.className=this.wrapClassName("page-number-input"),this.sideEffect.addDisposer(this.readonly$.subscribe(i=>a.disabled=i)),this.sideEffect.addDisposer(this.pagesIndex$.subscribe(i=>a.value=String(i+1))),this.sideEffect.addEventListener(a,"blur",()=>{a.value=String(this.pagesIndex$.value+1)}),this.sideEffect.addEventListener(a,"change",()=>{if(this.readonly$.value)return;const i=a.value?Number(a.value)-1:NaN;i>=0?this.events.emit("jumpPage",i):a.value=String(this.pagesIndex$.value+1)});const c=document.createElement("span");return this.sideEffect.addDisposer(this.pages$.subscribe(i=>{c.textContent=" / "+i.length})),n.appendChild(a),n.appendChild(c),e.appendChild(s),e.appendChild(n),e}renderFooterBtn(e,t,s){const r=document.createElement("button");return r.className=this.wrapClassName("footer-btn")+" "+this.wrapClassName(e),r.appendChild(t),s&&r.appendChild(s),r}}class y{constructor({readonly$:e,pagesIndex$:t,previewRoot:s,footerRoot:r,pages$:l,playable:n}){this.wrapClassName=a=>`${this.namespace}-${a}`,this.namespace="netless-app-docs-viewer",this.sideEffect=new S.SideEffectManager,this.events=new z.Remitter,this.preview=new _({pages$:l,readonly$:e,pagesIndex$:t,root:s,sideEffect:this.sideEffect,events:this.events,namespace:this.namespace,wrapClassName:this.wrapClassName}),this.footer=new W({pages$:l,readonly$:e,playable:n,pagesIndex$:t,root:r,namespace:this.namespace,sideEffect:this.sideEffect,events:this.events,wrapClassName:this.wrapClassName})}destroy(){this.preview.destroy(),this.footer.destroy(),this.sideEffect.flushAll(),this.events.destroy()}}function b(o,e,t){return Math.min(Math.max(o,e),t)}function C(o){return o.touches?o.touches[0]:o}function k(o){o.stopPropagation(),o.cancelable&&o.preventDefault()}function N(o,e){return o.width===e.width&&o.height===e.height}class P{constructor(e){var t,s,r;this.velocity=0,this._paused=!0,this._animationFrameID=null,this._loopTimestamp=0,this.looper=l=>{var a;if(this._paused)return;let n=Math.floor((l-this._loopTimestamp)/1e3*60)+1;for(this._loopTimestamp=l;n-- >0;)this.stepper();(a=this.onStep)==null||a.call(this,this.current),this._paused?this._animationFrameID=null:this._animationFrameID=window.requestAnimationFrame(this.looper)},this.current=(t=e.start)!=null?t:0,this.target=this.current,this.stiffness=(s=e.stiffness)!=null?s:170,this.damping=(r=e.damping)!=null?r:26,this.onStep=e.onStep}get paused(){return this._paused}stepTo(e,t){var s;this._paused&&t!=null&&(this.current=t),this._paused=!1,this.target=e,(s=this.onStep)==null||s.call(this,this.current),this._loopTimestamp=Date.now(),this._animationFrameID=window.requestAnimationFrame(this.looper)}pause(){this._paused=!0,this._animationFrameID!=null&&window.cancelAnimationFrame(this._animationFrameID)}destroy(){this.pause(),this.onStep=void 0}stepper(){const e=-this.stiffness*(this.current-this.target),t=-this.damping*this.velocity,s=this.velocity+(e+t)/60,r=this.current+s/60;Math.abs(s-0)<.01&&Math.abs(r-this.target)<.01?(this.current=this.target,this.velocity=0,this._paused=!0):(this.current=r,this.velocity=s)}}class Y{constructor(e,t,s,r,l,n){this.index=e,this.lastVisit=Date.now(),this.sideEffect=new S.SideEffectManager;const a=f.derive(t,u=>u[e]||{width:0,height:0}),c=f.combine([a,s],([u,p])=>(p.width-u.width)/2),i=f.combine([l,n],([u,p])=>(u[e]||0)-p),h=document.createElement("div");h.className="page-renderer-page",h.dataset.index=`${e}`;const d=document.createElement("img");d.className="page-renderer-page-img",h.appendChild(d),this.sideEffect.addDisposer([f.combine([a,r]).subscribe(([u,p])=>{h.style.width=`${u.width*p}px`,h.style.height=`${u.height*p}px`}),a.subscribe(u=>{u.thumbnail&&(h.style.backgroundImage=`url("${u.thumbnail}")`),d.width=u.width,d.height=u.height,d.src=u.src}),f.combine([c,i,r]).subscribe(([u,p,g])=>{h.style.transform=`translate(${u*g}px, ${p*g}px)`})]),this.$page=h}destroy(){this.sideEffect.flushAll(),this.$page.remove()}}class j{constructor(e,t,s,r,l){this.pages$=e,this.pagesSize$=t,this.scale$=s,this.pagesYs$=r,this.pagesScrollTop$=l,this.els=new Map,this.maxElCount=200,this.gcTimer=null,this.gc=()=>{var n;if(this.gcTimer=null,this.els.size>this.maxElCount){const a=[...this.els.values()].sort((c,i)=>i.lastVisit-c.lastVisit);for(let c=Math.floor(this.maxElCount/4);c<a.length;c++)(n=this.els.get(a[c].index))==null||n.destroy(),this.els.delete(a[c].index)}},this.schedule=window.requestIdleCallback||(n=>window.setTimeout(n,5e3)),this.cancelSchedule=window.cancelIdleCallback||window.clearTimeout}getEl(e){let t=this.els.get(e);return t||(t=new Y(e,this.pages$,this.pagesSize$,this.scale$,this.pagesYs$,this.pagesScrollTop$),this.els.set(e,t)),t.lastVisit=Date.now(),this.els.size>this.maxElCount&&this.gcTimer===null&&(this.gcTimer=this.schedule(this.gc)),t}destroy(){this.els.forEach(e=>e.destroy()),this.els.clear(),this.gcTimer!==null&&(this.cancelSchedule(this.gcTimer),this.gcTimer=null)}}class T{constructor({pagesScrollTop$:e,containerRect$:t,pages$:s,pagesSize$:r}){this.sideEffect=new S.SideEffectManager,s=f.derive(s,p=>p.map(g=>{if(g.thumbnail)return g;try{const w=new URL(g.src);return w.searchParams.set("x-oss-process","image/resize,l_50"),{...g,thumbnail:w.toString()}}catch(w){return console.error(w),g}}));const l=f.derive(s,p=>{const g=Array(p.length);for(let w=0;w<p.length;w++)g[w]=w>0?g[w-1]+p[w-1].height:0;return g}),n=f.derive(s,p=>{let g=1/0;for(let w=p.length-1;w>=0;w--)p[w].height<=g&&(g=p[w].height);return g}),a=f.combine([e,l,s],([p,g,w])=>{if(g.length!==w.length)return a.value;for(let m=0;m<g.length;m++)if(g[m]+w[m].height-p>=.001)return m;return g.length-1}),c=f.combine([t,r],([p,g])=>p.width/g.width||1),i=f.combine([s,t,n,c],([p,g,w,m])=>b(Math.ceil(g.height/m/w/2),1,p.length));f.withReadonlyValueEnhancer(this,{pagesScrollTop:e,containerRect:t,pages:s,pagesSize:r,pagesIndex:a,pagesYs:l,pagesMinHeight:n,scale:c}),this.pageElManager=new j(s,r,c,l,e),this.$pages=this.renderPages();const h=new f.Val(!1);this.sideEffect.addDisposer(h.subscribe(p=>this.$pages.classList.toggle("is-hwa",p)));const d=()=>h.setValue(!1),u=()=>{this.sideEffect.setTimeout(d,1e3,"turn-off-hwa"),h.setValue(!0)};this.sideEffect.addDisposer(f.combine([a,i,s]).subscribe(([p,g,w])=>{u();const m=Math.max(p-g,0),E=Math.min(p+g,w.length-1);for(let v=0;v<this.$pages.children.length;v++){const $=this.$pages.children[v],x=Number($.dataset.index);x>=m&&x<=E||($.remove(),v--)}for(let v=m;v<=E;v++){const $=this.pageElManager.getEl(v);$.$page.parentElement!==this.$pages&&this.$pages.appendChild($.$page)}}))}renderPages(){const e=document.createElement("div");return e.className="page-renderer-pages-container",this.sideEffect.addDisposer(this._containerRect$.subscribe(t=>{e.style.width=`${t.width}px`,e.style.height=`${t.height}px`}),"render-pages-size"),e}destroy(){this.sideEffect.flushAll(),this.$pages.remove(),this.pageElManager.destroy()}}const O=30;class D{constructor({pagesScrollTop$:e,containerRect$:t,stageRect$:s,pagesSize$:r,readonly$:l,scrollbarMinHeight:n=O,wrapClassName:a,onDragScroll:c}){this.sideEffect=new S.SideEffectManager,this.scrolling$=new f.Val(!1),this.pagesScrollTop$=e,this.containerRect$=t,this.stageRect$=s,this.pagesSize$=r,this.scrollbarMinHeight=n,this.readonly$=l,this.wrapClassName=a,this.onDragScroll=c,this.scrollbarHeight$=f.combine([t,s,r],([i,h,d])=>b(h.height/(h.width/d.width*d.height)*i.height,n,i.height)),this.scrollTop$=f.combine([t,s,r,this.scrollbarHeight$,this.pagesScrollTop$],([i,h,d,u,p])=>b(p/(d.height-d.width/h.width*h.height)*(i.height-u),0,i.height-u)),this.$scrollbar=this.renderScrollbar()}mount(e){e.appendChild(this.$scrollbar)}destroy(){this.$scrollbar.remove(),this.onDragScroll=void 0,this.sideEffect.flushAll()}renderScrollbar(){const e=document.createElement("button");e.className=this.wrapClassName("scrollbar"),e.style.minHeight=`${this.scrollbarMinHeight}px`,this.sideEffect.addDisposer([this.scrollbarHeight$.subscribe(s=>{e.style.height=`${s}px`}),this.scrollTop$.subscribe(s=>{this.scrolling$.setValue(!0),this.sideEffect.setTimeout(()=>this.scrolling$.setValue(!1),100,"reset-scrolling");const r=()=>e.style.transform=`translateY(${s}px)`;window.requestAnimationFrame?window.requestAnimationFrame(r):r()}),this.scrolling$.subscribe(s=>{e.classList.toggle(this.wrapClassName("scrolling"),s)})]);const t=s=>{if(!s.isPrimary||this.readonly$.value||s.button!=null&&s.button!==0)return;k(s);const r=this.wrapClassName("scrollbar-dragging");e.classList.toggle(r,!0);const l=this.pagesScrollTop$.value,{clientY:n}=C(s),a=i=>{if(!i.isPrimary||this.readonly$.value)return;const{clientY:h}=C(i),d=h-n;Math.abs(d)>0&&this.onDragScroll&&this.onDragScroll(l+d/this.containerRect$.value.height*this.pagesSize$.value.height)},c=i=>{!i.isPrimary||(e.classList.toggle(r,!1),window.removeEventListener("pointermove",a,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("pointercancel",c,!0))};window.addEventListener("pointermove",a,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("pointercancel",c,!0)};return this.sideEffect.addEventListener(e,"pointerdown",t),e}}class q{constructor({whiteboard:e,readonly$:t,box:s,pages:r,pagesScrollTop:l=0,onUserScroll:n}){this.sideEffect=new S.SideEffectManager,this.userScrolling=!1,this.whiteboard=e,this.readonly$=t,this.box=s,this.pages=r,this.onUserScroll=n;const a=()=>{var i;this.userScrolling=!1,(i=this.onUserScroll)==null||i.call(this,this.pagesScrollTop$.value)};this.debounceOnUserScroll=()=>{this.userScrolling=!0,this.sideEffect.setTimeout(a,80,"debounceOnUserScroll")};const c=new f.Val([]);this.pagesScrollTop$=new f.Val(l),this.pagesSize$=f.derive(c,i=>{let h=0,d=0;for(let u=i.length-1;u>=0;u--){const p=i[u];p.width>h&&(h=p.width),d+=p.height}return{width:Math.max(1,h),height:Math.max(1,d)}},{compare:N}),this.pageRenderer=new T({pagesScrollTop$:this.pagesScrollTop$,containerRect$:s._stageRect$,pages$:c,pagesSize$:this.pagesSize$}),this.viewer=new y({readonly$:t,pagesIndex$:this.pageRenderer._pagesIndex$,previewRoot:s.$body,footerRoot:s.$footer,pages$:c,playable:!1}),this.sideEffect.addDisposer([this.viewer.events.on("next",()=>{this.userScrollByPercent(.8)}),this.viewer.events.on("back",()=>{this.userScrollByPercent(-.8)})]),this.scrollbar=new D({pagesScrollTop$:this.pagesScrollTop$,containerRect$:s._bodyRect$,stageRect$:s._stageRect$,pagesSize$:this.pagesSize$,readonly$:t,wrapClassName:this.wrapClassName.bind(this),onDragScroll:i=>{this.pageScrollTo(i),this.debounceOnUserScroll()}}),this.pageScrollStepper=new P({start:this.pagesScrollTop$.value,onStep:i=>{this.pageScrollTo(i)}}),this.sideEffect.addDisposer(this.viewer.events.on("jumpPage",i=>this.userScrollToPageIndex(i))),this.render(),this.setupScrollListener(),this.sideEffect.setTimeout(()=>{this.userScrolling||this.pageScrollTo(this.pageRenderer.pagesScrollTop)},100),c.setValue(r)}get pagesScrollTop(){return this.pagesScrollTop$.value}destroy(){this.sideEffect.flushAll(),this.pageScrollStepper.destroy(),this.onUserScroll=void 0,this.viewer.destroy(),this.pageRenderer.destroy(),this.scrollbar.destroy()}syncPageScrollTop(e){!this.userScrolling&&e>=0&&Math.abs(this.pagesScrollTop$.value-e)>.01&&this.pageScrollStepper.stepTo(e,this.pagesScrollTop$.value)}render(){this.box.$content.style.overflow="hidden",this.box.mountStage(this.pageRenderer.$pages),this.scrollbar.mount(this.box.$body)}pageScrollTo(e){const t=this.whiteboard.view.size.height/2/this.pageRenderer.scale;this.whiteboard.view.moveCamera({centerY:b(e+t,t,this.pagesSize$.value.height-t),animationMode:"immediately"})}userScrollToPageIndex(e){var t;if(e=b(e,0,this.pages.length-1),!this.readonly$.value&&!Number.isNaN(e)){const s=this.pageRenderer.pagesYs[e];s>=0&&((t=this.onUserScroll)==null||t.call(this,s+5/this.pageRenderer.scale))}}userScrollByPercent(e){var t;this.readonly$.value||(t=this.onUserScroll)==null||t.call(this,b(this.pageRenderer.pagesScrollTop+this.pageRenderer.containerRect.height/this.pageRenderer.scale*b(e,-1,1),0,this.pageRenderer.pagesSize.height-this.pageRenderer.containerRect.height/this.pageRenderer.scale))}setupScrollListener(){this.sideEffect.addEventListener(this.box.$main,"wheel",e=>{k(e),!this.readonly$.value&&this.pageScrollStepper.paused&&(this.pageScrollTo(this.pagesScrollTop+e.deltaY),this.debounceOnUserScroll())},{passive:!1}),this.sideEffect.addEventListener(this.box.$main,"touchmove",e=>{!this.readonly$.value&&e.touches.length>1&&this.debounceOnUserScroll()},{passive:!0,capture:!0}),this.sideEffect.add(()=>{const e=t=>{const{width:s,height:r}=this.whiteboard.view.size;if(s<=0||r<=0)return;const l=t.centerY-this.pageRenderer.containerRect.height/this.pageRenderer.scale/2;this.pagesScrollTop$.setValue(l)};return this.whiteboard.view.callbacks.on("onCameraUpdated",e),()=>this.whiteboard.view.callbacks.off("onCameraUpdated",e)}),this.sideEffect.addDisposer(this.box._stageRect$.subscribe(e=>{const{width:t,height:s}=this.pagesSize$.value;this.whiteboard.view.moveCameraToContain({originX:0,originY:this.pageRenderer.pagesScrollTop,width:t,height:e.height/this.pageRenderer.scale,animationMode:"immediately"}),this.whiteboard.view.setCameraBound({damping:1,maxContentMode:()=>this.pageRenderer.scale,minContentMode:()=>this.pageRenderer.scale,centerX:t/2,centerY:s/2,width:t,height:s})}),"whiteboard-size-update"),this.sideEffect.addEventListener(window,"keyup",e=>{if(!(this.readonly$.value||!this.box.focus||this.box.minimized))switch(e.key){case"PageDown":{this.userScrollByPercent(.8);break}case"PageUp":{this.userScrollByPercent(-.8);break}case"ArrowLeft":{this.userScrollByPercent(-.25);break}case"ArrowRight":{this.userScrollByPercent(.25);break}case"ArrowDown":{this.userScrollByPercent(.5);break}case"ArrowUp":{this.userScrollByPercent(-.5);break}}},{capture:!0})}wrapClassName(e){return"netless-app-docs-viewer-static-"+e}}class G{constructor({readonly$:e,context:t,whiteboard:s,box:r,pages:l}){this.sideEffect=new S.SideEffectManager,this.context=t,this.whiteboard=s,this.box=r,this.pages=l;const n=new f.Val(t.displayer.state.sceneState.index||0);this.pagesIndex$=n,this.sideEffect.add(()=>{const a=c=>{this.jumpToPage(c.index)};return this.context.emitter.on("sceneStateChange",a),()=>this.context.emitter.off("sceneStateChange",a)}),this.viewer=new y({readonly$:e,pagesIndex$:n,previewRoot:r.$body,footerRoot:r.$footer,pages$:new f.Val(l),playable:!0}),this.sideEffect.addDisposer([this.viewer.events.on("jumpPage",a=>this.jumpToPage(a,!0)),this.viewer.events.on("play",()=>{var a;return(a=this.context.room)==null?void 0:a.pptNextStep()}),this.viewer.events.on("back",()=>this.prevPage()),this.viewer.events.on("next",()=>this.nextPage())]),this.render(),this.sideEffect.addDisposer(n.subscribe((a,c)=>{var d,u;if(e.value)return;const i=this.context.getInitScenePath(),h=(u=(d=this.context.getScenes())==null?void 0:d[a])==null?void 0:u.name;if(i&&h&&this.context.setScenePath(`${i}/${h}`),c){const p=this.context.room;if(p){const g=p.state.globalState.__pptState;p.setGlobalState({__pptState:g&&{uuid:g.uuid,pageIndex:a,disableAutoPlay:g.disableAutoPlay}})}}}))}destroy(){this.sideEffect.flushAll(),this.viewer.destroy()}nextPage(){this.jumpToPage(this.pagesIndex$.value+1,!0)}prevPage(){this.jumpToPage(this.pagesIndex$.value-1,!0)}jumpToPage(e,t=!1){this.pagesIndex$.setValue(b(e,0,this.pages.length-1),t)}render(){var t;this.box.mountStage(document.createElement("div")),this.sideEffect.addEventListener(window,"keydown",s=>{var r;if(this.box.focus)switch(s.key){case"ArrowUp":case"ArrowLeft":{this.prevPage();break}case"ArrowRight":case"ArrowDown":{(r=this.context.room)==null||r.pptNextStep();break}}});const e=(t=this.whiteboard.view.divElement)==null?void 0:t.parentElement;e&&this.sideEffect.addEventListener(e,"click",s=>{var l;const r=this.context.room;if(r&&r.state.memberState.currentApplianceName==="clicker"){for(let n=s.target;n;n=n.parentElement)if((l=n.classList)!=null&&l.contains("ppt-event-source"))return;r.pptNextStep()}})}wrapClassName(e){return"netless-app-docs-viewer-dynamic-"+e}}const J="DocsViewer",M={kind:J,setup(o){const e=o.box,t=o.getScenes();if(!t)throw new Error("[Docs Viewer]: scenes not found.");const s=new S.SideEffectManager,r=t.map(({ppt:n})=>n?{width:n.width,height:n.height,src:n.src,thumbnail:n.previewURL}:null).filter(n=>Boolean(n));if(r.length<=0)throw new Error("[Docs Viewer]: empty scenes.");e.mountStyles(R);const l=new f.Val(!o.isWritable);s.addDisposer(o.emitter.on("writableChange",n=>{l.setValue(!n)})),r[0].src.startsWith("ppt")?K(s,o,e,r,l):X(s,o,e,r,l),s.addDisposer(o.emitter.on("destroy",()=>{s.flushAll()}))}};function X(o,e,t,s,r){const l=e.createWhiteBoardView({syncCamera:!1});o.addDisposer(r.subscribe(c=>{l.view.disableCameraTransform=c}));const n=e.createStorage("static-docs-viewer",{pagesScrollTop:0}),a=new q({whiteboard:l,readonly$:r,box:t,pages:s,pagesScrollTop:n.state.pagesScrollTop,onUserScroll:c=>{e.isWritable&&n.setState({pagesScrollTop:c})}});o.addDisposer(()=>a.destroy()),o.addDisposer(n.addStateChangedListener(c=>{c.pagesScrollTop&&a.syncPageScrollTop(c.pagesScrollTop.newValue||0)})),o.addDisposer(f.combine([t._maximized$,t._managerStageRect$,t._intrinsicSize$,a.pagesSize$,a.pageRenderer._pagesMinHeight$],([c,i,h,d,u])=>c?Math.max(u/d.width*(2/5),i.height/i.width):h.height/h.width*(i.height/i.width)).subscribe(c=>{t.setStageRatio(c)}))}function K(o,e,t,s,r){const l=e.createWhiteBoardView();l.view.disableCameraTransform=!0;const n=new G({context:e,whiteboard:l,box:t,pages:s,readonly$:r});o.addDisposer(()=>n.destroy());const a=new f.Val({width:s[0].width,height:s[0].height},{compare:N});if(o.addDisposer(n.pagesIndex$.subscribe(c=>{const i=s[c];i&&a.setValue({width:i.width,height:i.height})})),o.addDisposer(a.subscribe(c=>{r.value||l.setBaseRect(c)})),e.isAddApp){const c=o.add(()=>{const i=({width:h,height:d})=>{if(s.length>0&&t.state!=="maximized"){const{width:u,height:p}=s[0],w=p/u*h-d;w!==0&&e.isWritable&&e.emitter.emit("setBoxSize",{width:t.intrinsicWidth,height:t.intrinsicHeight+w/t.rootRect.height})}o.remove(c)};return l.view.callbacks.once("onSizeUpdated",i),()=>l.view.callbacks.off("onSizeUpdated",i)})}}exports.DocsViewer=y;exports.NetlessAppDocsViewer=M;exports.PageRenderer=T;exports.ScrollBar=D;exports.Stepper=P;exports.default=M;
"use strict";var z=Object.defineProperty;var A=(n,e,t)=>e in n?z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var i=(n,e,t)=>(A(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=require("side-effect-manager"),m=require("value-enhancer"),V=require("vanilla-lazyload"),R=require("remitter"),I=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},_=I(V);const H=`.netless-app-docs-viewer-footer{box-sizing:border-box;height:26px;display:flex;align-items:center;padding:0 16px;border-top:1px solid #eeeef7;font-family:PingFang SC,Source Han Sans SC,Microsoft YaHei,Helvetica Neue,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif}.netless-app-docs-viewer-footer-btn{box-sizing:border-box;width:26px;height:26px;font-size:0;margin:0;padding:3px;border:none;border-radius:1px;outline:none;color:currentColor;background:transparent;transition:background .4s;cursor:pointer;user-select:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-docs-viewer-footer-btn:hover{background:rgba(237,237,240,.9)}@media (hover: none){.netless-app-docs-viewer-footer-btn:hover{background:transparent!important}}.netless-app-docs-viewer-footer-btn>svg{width:100%;height:100%}.netless-app-docs-viewer-footer-btn>svg:nth-of-type(2){display:none}.netless-app-docs-viewer-footer-btn.netless-app-docs-viewer-footer-btn-playing>svg:nth-of-type(1){display:none}.netless-app-docs-viewer-footer-btn.netless-app-docs-viewer-footer-btn-playing>svg:nth-of-type(2){display:initial}.netless-app-docs-viewer-footer-btn~.netless-app-docs-viewer-footer-btn{margin-left:15px}.netless-app-docs-viewer-page-jumps{flex:1;display:flex;justify-content:center;align-items:center}.netless-app-docs-viewer-page-number{display:flex;align-items:center;height:26px;margin-left:auto;font-size:13px;white-space:nowrap;word-break:keep-all;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-page-number-input{border:none;outline:none;width:3em;margin:0;padding:0 .5em 0 2px;text-align:right;font-size:13px;line-height:1;font-weight:400;font-family:inherit;border-radius:2px;color:currentColor;font-family:PingFang SC,Source Han Sans SC,Microsoft YaHei,Helvetica Neue,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif;background:transparent;transition:background .4s;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-docs-viewer-page-number-input:hover,.netless-app-docs-viewer-page-number-input:focus,.netless-app-docs-viewer-page-number-input:active{user-select:text;background:#fff;box-shadow:#63636333 0 2px 8px}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-footer-btn{cursor:not-allowed}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-footer-btn:hover{background:transparent}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input{cursor:not-allowed}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:hover,.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:focus,.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:active{background:transparent;box-shadow:none}.netless-app-docs-viewer-readonly .netless-app-docs-viewer-page-number-input:disabled{color:inherit}.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:active,.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:focus,.telebox-color-scheme-dark .netless-app-docs-viewer-page-number-input:hover{color:currentColor;background:#25282e}.telebox-color-scheme-dark .netless-app-docs-viewer-footer{border-top:none}.telebox-color-scheme-dark .netless-app-docs-viewer-footer-btn:hover{background:#212126}.netless-app-docs-viewer-preview-mask{position:absolute;z-index:10200;top:0;left:0;width:100%;height:100%}.netless-app-docs-viewer-preview{box-sizing:border-box;display:flex;flex-direction:column;align-items:center;position:absolute;z-index:10300;top:0;left:0;width:33%;max-width:200px;height:100%;padding-top:10px;transform:translate(-100%);background:rgba(237,237,240,.9);box-shadow:inset -1px 0 #0000001c;transition:transform .4s;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-preview.netless-app-docs-viewer-preview-active{transform:translate(0)}.netless-app-docs-viewer-preview-page{position:relative;display:block;width:55%;margin-bottom:10px;font-size:0;color:transparent;outline:none;border:7px solid transparent;border-radius:4px;transition:border-color .3s;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.netless-app-docs-viewer-preview-page:hover,.netless-app-docs-viewer-preview-page.netless-app-docs-viewer-preview-page-active{border-color:#444e601a}.netless-app-docs-viewer-preview-page>img{width:100%;height:auto;box-sizing:border-box;border:1px solid rgba(0,0,0,.5);border-radius:1px;background-color:#fff;box-shadow:0 2px 8px #0000004d}.netless-app-docs-viewer-preview-page-name{position:absolute;top:1px;left:-10px;transform:translate(-100%);text-align:right;font-size:12px;color:#5f5f5f;user-select:none}.telebox-color-scheme-dark .netless-app-docs-viewer-preview{background:rgba(50,50,50,.9)}.netless-app-docs-viewer-content{position:relative;height:100%;overflow:hidden}.netless-app-docs-viewer-static-scrollbar{box-sizing:border-box;position:absolute;top:0;right:0;z-index:2147483647;width:16px;min-height:30px;margin:0;padding:0 0 0 8px;border:none;outline:none;opacity:0;background:transparent;transition:opacity .4s 3s,transform .1s;user-select:none;touch-action:none}.netless-app-docs-viewer-static-scrollbar:after{content:"";display:block;width:8px;height:100%;border-radius:4px;background:rgba(68,78,96,.4);box-shadow:1px 1px 8px #ffffffb3;transition:background .4s}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrolling{opacity:1;transition:opacity .4s,transform .1s}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrollbar-dragging{opacity:1;transition:opacity .4s 3s!important}.netless-app-docs-viewer-static-scrollbar.netless-app-docs-viewer-static-scrollbar-dragging:after{background:rgba(68,78,96,.6)}.netless-app-docs-viewer-static-scrollbar:hover:after,.netless-app-docs-viewer-static-scrollbar:focus:after{background:rgba(68,78,96,.5)}.netless-app-docs-viewer-static-scrollbar:active:after{background:rgba(68,78,96,.6)}.telebox-body-wrap:hover .netless-app-docs-viewer-static-scrollbar{opacity:1;transition:opacity .4s,transform .1s}.telebox-readonly .netless-app-docs-viewer-static-scrollbar{display:none}.page-renderer-pages-container{position:relative;width:100%;height:100%}.page-renderer-page{position:absolute;top:0;left:0;background-position:center;background-size:cover;background-repeat:no-repeat}.page-renderer-pages-container.is-hwa .page-renderer-page{will-change:transform}.page-renderer-page-img{display:block;width:100%;height:auto;user-select:none}.netless-app-docs-viewer-static-pages{overflow:hidden;position:relative;height:100%;user-select:none}.netless-app-docs-viewer-static-page{display:block;width:100%;height:auto;user-select:none}.netless-app-docs-viewer-dynamic-wb-view{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;overflow:hidden}.netless-app-docs-viewer-dynamic-wb-view .cursor-clicker .ppt-event-source{cursor:pointer}
`;class B{constructor({namespace:e,pages$:t,sideEffect:s,readonly$:r,events:o,wrapClassName:l,root:c,pagesIndex$:h}){i(this,"namespace");i(this,"pages$");i(this,"sideEffect");i(this,"readonly$");i(this,"events");i(this,"wrapClassName");i(this,"showPreview$",new m.Val(!1));i(this,"$preview");i(this,"$previewMask");i(this,"previewLazyLoad");this.namespace=e,this.pages$=t,this.sideEffect=s,this.readonly$=r,this.events=o,this.wrapClassName=l,this.sideEffect.addDisposer(this.events.on("togglePreview",()=>{this.showPreview$.setValue(!this.showPreview$.value)})),this.sideEffect.addDisposer(this.showPreview$.subscribe(a=>{this.sideEffect.add(()=>{const p=this.renderPreview(),g=this.renderPreviewMask();if(a){c.appendChild(p),c.appendChild(g),p.scrollTop;const u=p.querySelector("."+this.wrapClassName(`preview-page-${h.value}`));return u&&p.scrollTo({top:u.offsetTop-16}),p.classList.toggle(this.wrapClassName("preview-active"),!0),this.previewLazyLoad=new _.default({container:this.$preview,elements_selector:"."+this.wrapClassName("preview-page>img")}),()=>{var d;return(d=this.previewLazyLoad)==null?void 0:d.destroy()}}else return p.classList.toggle(this.wrapClassName("preview-active"),!1),this.sideEffect.setTimeout(()=>{p.remove(),g.remove()},500,"preview-remove"),null},"preview-lazyload")}))}destroy(){var e,t;(e=this.$preview)==null||e.remove(),(t=this.$previewMask)==null||t.remove()}renderPreview(){if(this.$preview)return this.$preview;const e=document.createElement("div");return e.className=this.wrapClassName("preview")+" tele-fancy-scrollbar",this.$preview=e,this.sideEffect.addEventListener(e,"wheel",t=>t.stopPropagation(),{passive:!1}),this.sideEffect.addDisposer(this.pages$.subscribe(t=>{var s;this.sideEffect.add(()=>{const r=t.map((o,l)=>{var u;const c=(u=o.thumbnail)!=null?u:o.src.startsWith("ppt")?void 0:o.src;if(!c)return;const h=String(l),a=document.createElement("a");a.className=this.wrapClassName("preview-page")+" "+this.wrapClassName(`preview-page-${l}`),a.setAttribute("href","#"),a.dataset.pageIndex=h;const p=document.createElement("span");p.className=this.wrapClassName("preview-page-name"),p.textContent=String(l+1),p.dataset.pageIndex=h;const g=document.createElement("img");return g.width=o.width,g.height=o.height,g.dataset.src=c,g.dataset.pageIndex=h,a.appendChild(g),a.appendChild(p),e.appendChild(a),a});return()=>r.forEach(o=>o==null?void 0:o.remove())},"render-preview-pages"),(s=this.previewLazyLoad)==null||s.update()})),this.sideEffect.addEventListener(e,"click",t=>{var r;if(this.readonly$.value)return;const s=(r=t.target.dataset)==null?void 0:r.pageIndex;s&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),this.events.emit("jumpPage",Number(s)),this.showPreview$.setValue(!1))}),e}renderPreviewMask(){if(this.$previewMask)return this.$previewMask;const e=document.createElement("div");return e.className=this.wrapClassName("preview-mask"),this.$previewMask=e,this.sideEffect.addEventListener(e,"click",t=>{this.readonly$.value||t.target===e&&this.showPreview$.setValue(!1)}),e}}function U(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-sidebar`),t.setAttribute("viewBox","0 0 64 64");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M50 8H14c-3.309 0-6 2.691-6 6v36c0 3.309 2.691 6 6 6h36c3.309 0 6-2.691 6-6V14c0-3.309-2.691-6-6-6zM12 50V14c0-1.103.897-2 2-2h8v40h-8c-1.103 0-2-.897-2-2zm40 0c0 1.103-.897 2-2 2H26V12h24c1.103 0 2 .897 2 2z"),t.appendChild(s),t}function F(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-arrow-left`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M177.81 249.959L337.473 90.295c2.722-2.865 2.651-7.378-.143-10.1-2.793-2.65-7.163-2.65-9.956 0l-164.75 164.75c-2.793 2.793-2.793 7.306 0 10.1l164.75 164.75c2.865 2.722 7.378 2.65 10.099-.143 2.651-2.794 2.651-7.163 0-9.957L177.809 249.959z"),t.appendChild(s),t}function W(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-arrow-right`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M322.19 250.041L162.527 409.705c-2.722 2.865-2.651 7.378.143 10.1 2.793 2.65 7.163 2.65 9.956 0l164.75-164.75c2.793-2.793 2.793-7.306 0-10.1l-164.75-164.75c-2.865-2.722-7.378-2.65-10.099.143-2.651 2.794-2.651 7.163 0 9.957l159.664 159.736z"),t.appendChild(s),t}function Y(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-play`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M418.158 257.419L174.663 413.33c-6.017 3.919-15.708 3.772-21.291-.29-2.791-2.018-4.295-4.483-4.295-7.084V94.109c0-5.65 6.883-10.289 15.271-10.289 4.298 0 8.391 1.307 11.181 3.332l242.629 155.484c6.016 3.917 6.451 10.292.649 14.491-.216.154-.432.154-.649.292zM170.621 391.288l223.116-141.301L170.71 107.753l-.089 283.535z"),t.appendChild(s),t}function j(n){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("class",`${n}-footer-icon-pause`),t.setAttribute("viewBox","0 0 500 500");const s=document.createElementNS(e,"path");return s.setAttribute("fill","currentColor"),s.setAttribute("d","M312.491 78.261c0-6.159 4.893-11.213 11.04-11.213 6.158 0 11.211 5.054 11.211 11.213v343.478c0 6.159-5.053 11.213-11.211 11.213-6.147 0-11.04-5.054-11.04-11.213V78.261zM165.257 78.261c0-6.159 4.893-11.213 11.04-11.213 6.158 0 11.211 5.054 11.211 11.213v343.478c0 6.159-5.053 11.213-11.211 11.213-6.147 0-11.04-5.054-11.04-11.213V78.261z"),t.appendChild(s),t}class O{constructor({namespace:e,pages$:t,sideEffect:s,readonly$:r,events:o,playable:l,wrapClassName:c,pagesIndex$:h,root:a}){i(this,"namespace");i(this,"pages$");i(this,"sideEffect");i(this,"readonly$");i(this,"events");i(this,"playable");i(this,"wrapClassName");i(this,"pagesIndex$");i(this,"$footer");this.namespace=e,this.pages$=t,this.sideEffect=s,this.readonly$=r,this.events=o,this.wrapClassName=c,this.pagesIndex$=h,this.playable=l,this.$footer=this.render(),a.appendChild(this.$footer)}destroy(){this.$footer.remove()}render(){const e=document.createElement("div");e.className=this.wrapClassName("footer"),this.sideEffect.addDisposer(this.readonly$.subscribe(a=>e.classList.toggle(this.wrapClassName("readonly"),a)));const t=this.renderFooterBtn("btn-sidebar",U(this.namespace));this.sideEffect.addEventListener(t,"click",()=>{this.readonly$.value||this.events.emit("togglePreview")}),e.appendChild(t),this.sideEffect.addDisposer(this.pages$.subscribe(a=>{const p=a.some(g=>g.thumbnail||!g.src.startsWith("ppt"));t.style.display=p?"":"none"}));const s=document.createElement("div");s.className=this.wrapClassName("page-jumps");const r=this.renderFooterBtn("btn-page-back",F(this.namespace));if(this.sideEffect.addEventListener(r,"click",()=>{this.readonly$.value||this.events.emit("back")}),s.appendChild(r),this.playable){const a=this.renderFooterBtn("btn-page-play",Y(this.namespace),j(this.namespace));this.sideEffect.addEventListener(a,"click",()=>{this.readonly$.value||(a.classList.toggle(this.wrapClassName("footer-btn-playing"),!0),this.events.emit("play"),this.sideEffect.setTimeout(()=>a.classList.toggle(this.wrapClassName("footer-btn-playing"),!1),500,"returnPlay"))}),s.appendChild(a)}const o=this.renderFooterBtn("btn-page-next",W(this.namespace));this.sideEffect.addEventListener(o,"click",()=>{this.readonly$.value||this.events.emit("next")}),s.appendChild(o);const l=document.createElement("div");l.className=this.wrapClassName("page-number");const c=document.createElement("input");c.className=this.wrapClassName("page-number-input"),this.sideEffect.addDisposer(this.readonly$.subscribe(a=>c.disabled=a)),this.sideEffect.addDisposer(this.pagesIndex$.subscribe(a=>c.value=String(a+1))),this.sideEffect.addEventListener(c,"blur",()=>{c.value=String(this.pagesIndex$.value+1)}),this.sideEffect.addEventListener(c,"change",()=>{if(this.readonly$.value)return;const a=c.value?Number(c.value)-1:NaN;a>=0?this.events.emit("jumpPage",a):c.value=String(this.pagesIndex$.value+1)});const h=document.createElement("span");return this.sideEffect.addDisposer(this.pages$.subscribe(a=>{h.textContent=" / "+a.length})),l.appendChild(c),l.appendChild(h),e.appendChild(s),e.appendChild(l),e}renderFooterBtn(e,t,s){const r=document.createElement("button");return r.className=this.wrapClassName("footer-btn")+" "+this.wrapClassName(e),r.appendChild(t),s&&r.appendChild(s),r}}class E{constructor({readonly$:e,pagesIndex$:t,previewRoot:s,footerRoot:r,pages$:o,playable:l}){i(this,"preview");i(this,"footer");i(this,"wrapClassName",e=>`${this.namespace}-${e}`);i(this,"namespace","netless-app-docs-viewer");i(this,"sideEffect",new S.SideEffectManager);i(this,"events",new R.Remitter);this.preview=new B({pages$:o,readonly$:e,pagesIndex$:t,root:s,sideEffect:this.sideEffect,events:this.events,namespace:this.namespace,wrapClassName:this.wrapClassName}),this.footer=new O({pages$:o,readonly$:e,playable:l,pagesIndex$:t,root:r,namespace:this.namespace,sideEffect:this.sideEffect,events:this.events,wrapClassName:this.wrapClassName})}destroy(){this.preview.destroy(),this.footer.destroy(),this.sideEffect.flushAll(),this.events.destroy()}}function $(n,e,t){return Math.min(Math.max(n,e),t)}function k(n){return n.touches?n.touches[0]:n}function N(n){n.stopPropagation(),n.cancelable&&n.preventDefault()}function T(n,e){return n.width===e.width&&n.height===e.height}class P{constructor(e){i(this,"stiffness");i(this,"damping");i(this,"current");i(this,"target");i(this,"velocity",0);i(this,"onStep");i(this,"_paused",!0);i(this,"_animationFrameID",null);i(this,"_loopTimestamp",0);i(this,"looper",e=>{var s;if(this._paused)return;let t=Math.floor((e-this._loopTimestamp)/1e3*60)+1;for(this._loopTimestamp=e;t-- >0;)this.stepper();(s=this.onStep)==null||s.call(this,this.current),this._paused?this._animationFrameID=null:this._animationFrameID=window.requestAnimationFrame(this.looper)});var t,s,r;this.current=(t=e.start)!=null?t:0,this.target=this.current,this.stiffness=(s=e.stiffness)!=null?s:170,this.damping=(r=e.damping)!=null?r:26,this.onStep=e.onStep}get paused(){return this._paused}stepTo(e,t){var s;this._paused&&t!=null&&(this.current=t),this._paused=!1,this.target=e,(s=this.onStep)==null||s.call(this,this.current),this._loopTimestamp=Date.now(),this._animationFrameID=window.requestAnimationFrame(this.looper)}pause(){this._paused=!0,this._animationFrameID!=null&&window.cancelAnimationFrame(this._animationFrameID)}destroy(){this.pause(),this.onStep=void 0}stepper(){const e=-this.stiffness*(this.current-this.target),t=-this.damping*this.velocity,s=this.velocity+(e+t)/60,r=this.current+s/60;Math.abs(s-0)<.01&&Math.abs(r-this.target)<.01?(this.current=this.target,this.velocity=0,this._paused=!0):(this.current=r,this.velocity=s)}}class q{constructor(e,t,s,r,o,l){i(this,"lastVisit",Date.now());i(this,"$page");i(this,"sideEffect",new S.SideEffectManager);this.index=e;const c=m.derive(t,u=>u[e]||{width:0,height:0}),h=m.combine([c,s],([u,d])=>(d.width-u.width)/2),a=m.combine([o,l],([u,d])=>(u[e]||0)-d),p=document.createElement("div");p.className="page-renderer-page",p.dataset.index=`${e}`;const g=document.createElement("img");g.className="page-renderer-page-img",p.appendChild(g),this.sideEffect.addDisposer([m.combine([c,r]).subscribe(([u,d])=>{p.style.width=`${u.width*d}px`,p.style.height=`${u.height*d}px`}),c.subscribe(u=>{u.thumbnail&&(p.style.backgroundImage=`url("${u.thumbnail}")`),g.width=u.width,g.height=u.height,g.src=u.src}),m.combine([h,a,r]).subscribe(([u,d,w])=>{p.style.transform=`translate(${u*w}px, ${d*w}px)`})]),this.$page=p}destroy(){this.sideEffect.flushAll(),this.$page.remove()}}class G{constructor(e,t,s,r,o){i(this,"els",new Map);i(this,"maxElCount",200);i(this,"gcTimer",null);i(this,"schedule");i(this,"cancelSchedule");i(this,"gc",()=>{var e;if(this.gcTimer=null,this.els.size>this.maxElCount){const t=[...this.els.values()].sort((s,r)=>r.lastVisit-s.lastVisit);for(let s=Math.floor(this.maxElCount/4);s<t.length;s++)(e=this.els.get(t[s].index))==null||e.destroy(),this.els.delete(t[s].index)}});this.pages$=e,this.pagesSize$=t,this.scale$=s,this.pagesYs$=r,this.pagesScrollTop$=o,this.schedule=window.requestIdleCallback||(l=>window.setTimeout(l,5e3)),this.cancelSchedule=window.cancelIdleCallback||window.clearTimeout}getEl(e){let t=this.els.get(e);return t||(t=new q(e,this.pages$,this.pagesSize$,this.scale$,this.pagesYs$,this.pagesScrollTop$),this.els.set(e,t)),t.lastVisit=Date.now(),this.els.size>this.maxElCount&&this.gcTimer===null&&(this.gcTimer=this.schedule(this.gc)),t}destroy(){this.els.forEach(e=>e.destroy()),this.els.clear(),this.gcTimer!==null&&(this.cancelSchedule(this.gcTimer),this.gcTimer=null)}}class D{constructor({pagesScrollTop$:e,containerRect$:t,pages$:s,pagesSize$:r}){i(this,"$pages");i(this,"sideEffect",new S.SideEffectManager);i(this,"pageElManager");s=m.derive(s,d=>d.map(w=>{if(w.thumbnail)return w;try{const f=new URL(w.src);return f.searchParams.set("x-oss-process","image/resize,l_50"),{...w,thumbnail:f.toString()}}catch(f){return console.error(f),w}}));const o=m.derive(s,d=>{const w=Array(d.length);for(let f=0;f<d.length;f++)w[f]=f>0?w[f-1]+d[f-1].height:0;return w}),l=m.derive(s,d=>{let w=1/0;for(let f=d.length-1;f>=0;f--)d[f].height<=w&&(w=d[f].height);return w}),c=m.combine([e,o,s],([d,w,f])=>{if(w.length!==f.length)return c.value;for(let v=0;v<w.length;v++)if(w[v]+f[v].height-d>=.001)return v;return w.length-1}),h=m.combine([t,r],([d,w])=>d.width/w.width||1),a=m.combine([s,t,l,h],([d,w,f,v])=>$(Math.ceil(w.height/v/f/2),1,d.length));m.withReadonlyValueEnhancer(this,{pagesScrollTop:e,containerRect:t,pages:s,pagesSize:r,pagesIndex:c,pagesYs:o,pagesMinHeight:l,scale:h}),this.pageElManager=new G(s,r,h,o,e),this.$pages=this.renderPages();const p=new m.Val(!1);this.sideEffect.addDisposer(p.subscribe(d=>this.$pages.classList.toggle("is-hwa",d)));const g=()=>p.setValue(!1),u=()=>{this.sideEffect.setTimeout(g,1e3,"turn-off-hwa"),p.setValue(!0)};this.sideEffect.addDisposer(m.combine([c,a,s]).subscribe(([d,w,f])=>{u();const v=Math.max(d-w,0),x=Math.min(d+w,f.length-1);for(let b=0;b<this.$pages.children.length;b++){const y=this.$pages.children[b],C=Number(y.dataset.index);C>=v&&C<=x||(y.remove(),b--)}for(let b=v;b<=x;b++){const y=this.pageElManager.getEl(b);y.$page.parentElement!==this.$pages&&this.$pages.appendChild(y.$page)}}))}renderPages(){const e=document.createElement("div");return e.className="page-renderer-pages-container",this.sideEffect.addDisposer(this._containerRect$.subscribe(t=>{e.style.width=`${t.width}px`,e.style.height=`${t.height}px`}),"render-pages-size"),e}destroy(){this.sideEffect.flushAll(),this.$pages.remove(),this.pageElManager.destroy()}}const J=30;class M{constructor({pagesScrollTop$:e,containerRect$:t,stageRect$:s,pagesSize$:r,readonly$:o,scrollbarMinHeight:l=J,wrapClassName:c,onDragScroll:h}){i(this,"sideEffect",new S.SideEffectManager);i(this,"scrollbarMinHeight");i(this,"readonly$");i(this,"wrapClassName");i(this,"onDragScroll");i(this,"$scrollbar");i(this,"pagesScrollTop$");i(this,"containerRect$");i(this,"stageRect$");i(this,"pagesSize$");i(this,"scrolling$",new m.Val(!1));i(this,"scrollbarHeight$");i(this,"scrollTop$");this.pagesScrollTop$=e,this.containerRect$=t,this.stageRect$=s,this.pagesSize$=r,this.scrollbarMinHeight=l,this.readonly$=o,this.wrapClassName=c,this.onDragScroll=h,this.scrollbarHeight$=m.combine([t,s,r],([a,p,g])=>$(p.height/(p.width/g.width*g.height)*a.height,l,a.height)),this.scrollTop$=m.combine([t,s,r,this.scrollbarHeight$,this.pagesScrollTop$],([a,p,g,u,d])=>$(d/(g.height-g.width/p.width*p.height)*(a.height-u),0,a.height-u)),this.$scrollbar=this.renderScrollbar()}mount(e){e.appendChild(this.$scrollbar)}destroy(){this.$scrollbar.remove(),this.onDragScroll=void 0,this.sideEffect.flushAll()}renderScrollbar(){const e=document.createElement("button");e.className=this.wrapClassName("scrollbar"),e.style.minHeight=`${this.scrollbarMinHeight}px`,this.sideEffect.addDisposer([this.scrollbarHeight$.subscribe(s=>{e.style.height=`${s}px`}),this.scrollTop$.subscribe(s=>{this.scrolling$.setValue(!0),this.sideEffect.setTimeout(()=>this.scrolling$.setValue(!1),100,"reset-scrolling");const r=()=>e.style.transform=`translateY(${s}px)`;window.requestAnimationFrame?window.requestAnimationFrame(r):r()}),this.scrolling$.subscribe(s=>{e.classList.toggle(this.wrapClassName("scrolling"),s)})]);const t=s=>{if(!s.isPrimary||this.readonly$.value||s.button!=null&&s.button!==0)return;N(s);const r=this.wrapClassName("scrollbar-dragging");e.classList.toggle(r,!0);const o=this.pagesScrollTop$.value,{clientY:l}=k(s),c=a=>{if(!a.isPrimary||this.readonly$.value)return;const{clientY:p}=k(a),g=p-l;Math.abs(g)>0&&this.onDragScroll&&this.onDragScroll(o+g/this.containerRect$.value.height*this.pagesSize$.value.height)},h=a=>{!a.isPrimary||(e.classList.toggle(r,!1),window.removeEventListener("pointermove",c,!0),window.removeEventListener("pointerup",h,!0),window.removeEventListener("pointercancel",h,!0))};window.addEventListener("pointermove",c,!0),window.addEventListener("pointerup",h,!0),window.addEventListener("pointercancel",h,!0)};return this.sideEffect.addEventListener(e,"pointerdown",t),e}}class X{constructor({whiteboard:e,readonly$:t,box:s,pages:r,pagesScrollTop:o=0,onUserScroll:l}){i(this,"readonly$");i(this,"pagesScrollTop$");i(this,"pagesSize$");i(this,"pageRenderer");i(this,"scrollbar");i(this,"sideEffect",new S.SideEffectManager);i(this,"pageScrollStepper");i(this,"userScrolling",!1);i(this,"pages");i(this,"box");i(this,"whiteboard");i(this,"onUserScroll");i(this,"debounceOnUserScroll");i(this,"viewer");this.whiteboard=e,this.readonly$=t,this.box=s,this.pages=r,this.onUserScroll=l;const c=()=>{var a;this.userScrolling=!1,(a=this.onUserScroll)==null||a.call(this,this.pagesScrollTop$.value)};this.debounceOnUserScroll=()=>{this.userScrolling=!0,this.sideEffect.setTimeout(c,80,"debounceOnUserScroll")};const h=new m.Val(r);this.pagesScrollTop$=new m.Val(o),this.pagesSize$=m.derive(h,a=>{let p=0,g=0;for(let u=a.length-1;u>=0;u--){const d=a[u];d.width>p&&(p=d.width),g+=d.height}return{width:Math.max(1,p),height:Math.max(1,g)}},{compare:T}),this.pageRenderer=new D({pagesScrollTop$:this.pagesScrollTop$,containerRect$:s._stageRect$,pages$:h,pagesSize$:this.pagesSize$}),this.viewer=new E({readonly$:t,pagesIndex$:this.pageRenderer._pagesIndex$,previewRoot:s.$body,footerRoot:s.$footer,pages$:h,playable:!1}),this.sideEffect.addDisposer([this.viewer.events.on("next",()=>{this.userScrollByPercent(.8)}),this.viewer.events.on("back",()=>{this.userScrollByPercent(-.8)})]),this.scrollbar=new M({pagesScrollTop$:this.pagesScrollTop$,containerRect$:s._bodyRect$,stageRect$:s._stageRect$,pagesSize$:this.pagesSize$,readonly$:t,wrapClassName:this.wrapClassName.bind(this),onDragScroll:a=>{this.pageScrollTo(a),this.debounceOnUserScroll()}}),this.pageScrollStepper=new P({start:this.pagesScrollTop$.value,onStep:a=>{this.pageScrollTo(a)}}),this.sideEffect.addDisposer(this.viewer.events.on("jumpPage",a=>this.userScrollToPageIndex(a))),this.render(),this.setupScrollListener(),this.sideEffect.setTimeout(()=>{this.userScrolling||this.pageScrollTo(this.pageRenderer.pagesScrollTop)},100)}get pagesScrollTop(){return this.pagesScrollTop$.value}destroy(){this.sideEffect.flushAll(),this.pageScrollStepper.destroy(),this.onUserScroll=void 0,this.viewer.destroy(),this.pageRenderer.destroy(),this.scrollbar.destroy()}syncPageScrollTop(e){!this.userScrolling&&e>=0&&Math.abs(this.pagesScrollTop$.value-e)>.01&&this.pageScrollStepper.stepTo(e,this.pagesScrollTop$.value)}render(){this.box.$content.style.overflow="hidden",this.box.mountStage(this.pageRenderer.$pages),this.scrollbar.mount(this.box.$body)}pageScrollTo(e){const t=this.whiteboard.view.size.height/2/this.pageRenderer.scale;this.whiteboard.view.moveCamera({centerY:$(e+t,t,this.pagesSize$.value.height-t),animationMode:"immediately"})}userScrollToPageIndex(e){var t;if(e=$(e,0,this.pages.length-1),!this.readonly$.value&&!Number.isNaN(e)){const s=this.pageRenderer.pagesYs[e];s>=0&&((t=this.onUserScroll)==null||t.call(this,s+5/this.pageRenderer.scale))}}userScrollByPercent(e){var t;this.readonly$.value||(t=this.onUserScroll)==null||t.call(this,$(this.pageRenderer.pagesScrollTop+this.pageRenderer.containerRect.height/this.pageRenderer.scale*$(e,-1,1),0,this.pageRenderer.pagesSize.height-this.pageRenderer.containerRect.height/this.pageRenderer.scale))}setupScrollListener(){this.sideEffect.addEventListener(this.box.$main,"wheel",e=>{N(e),!this.readonly$.value&&this.pageScrollStepper.paused&&(this.pageScrollTo(this.pagesScrollTop+e.deltaY),this.debounceOnUserScroll())},{passive:!1}),this.sideEffect.addEventListener(this.box.$main,"touchmove",e=>{!this.readonly$.value&&e.touches.length>1&&this.debounceOnUserScroll()},{passive:!0,capture:!0}),this.sideEffect.add(()=>{const e=t=>{const{width:s,height:r}=this.whiteboard.view.size;if(s<=0||r<=0)return;const o=t.centerY-this.pageRenderer.containerRect.height/this.pageRenderer.scale/2;this.pagesScrollTop$.setValue(Math.max(0,o))};return this.whiteboard.view.callbacks.on("onCameraUpdated",e),()=>this.whiteboard.view.callbacks.off("onCameraUpdated",e)}),this.sideEffect.addDisposer(this.box._stageRect$.subscribe(e=>{const{width:t,height:s}=this.pagesSize$.value;this.whiteboard.view.moveCameraToContain({originX:0,originY:this.pageRenderer.pagesScrollTop,width:t,height:e.height/this.pageRenderer.scale,animationMode:"immediately"}),this.whiteboard.view.setCameraBound({damping:1,maxContentMode:()=>this.pageRenderer.scale,minContentMode:()=>this.pageRenderer.scale,centerX:t/2,centerY:s/2,width:t,height:s})}),"whiteboard-size-update"),this.sideEffect.addEventListener(window,"keyup",e=>{if(!(this.readonly$.value||!this.box.focus||this.box.minimized))switch(e.key){case"PageDown":{this.userScrollByPercent(.8);break}case"PageUp":{this.userScrollByPercent(-.8);break}case"ArrowLeft":{this.userScrollByPercent(-.25);break}case"ArrowRight":{this.userScrollByPercent(.25);break}case"ArrowDown":{this.userScrollByPercent(.5);break}case"ArrowUp":{this.userScrollByPercent(-.5);break}}},{capture:!0})}wrapClassName(e){return"netless-app-docs-viewer-static-"+e}}class K{constructor({readonly$:e,context:t,whiteboard:s,box:r,pages:o}){i(this,"pagesIndex$");i(this,"sideEffect",new S.SideEffectManager);i(this,"context");i(this,"pages");i(this,"box");i(this,"whiteboard");i(this,"viewer");this.context=t,this.whiteboard=s,this.box=r,this.pages=o;const l=new m.Val(t.displayer.state.sceneState.index||0);this.pagesIndex$=l,this.sideEffect.add(()=>{const c=h=>{this.jumpToPage(h.index)};return this.context.emitter.on("sceneStateChange",c),()=>this.context.emitter.off("sceneStateChange",c)}),this.viewer=new E({readonly$:e,pagesIndex$:l,previewRoot:r.$body,footerRoot:r.$footer,pages$:new m.Val(o),playable:!0}),this.sideEffect.addDisposer([this.viewer.events.on("jumpPage",c=>this.jumpToPage(c,!0)),this.viewer.events.on("play",()=>{var c;return(c=this.context.room)==null?void 0:c.pptNextStep()}),this.viewer.events.on("back",()=>this.prevPage()),this.viewer.events.on("next",()=>this.nextPage())]),this.render(),this.sideEffect.addDisposer(l.subscribe((c,h)=>{var g,u;if(e.value)return;const a=this.context.getInitScenePath(),p=(u=(g=this.context.getScenes())==null?void 0:g[c])==null?void 0:u.name;if(a&&p&&this.context.setScenePath(`${a}/${p}`),h){const d=this.context.room;if(d){const w=d.state.globalState.__pptState;d.setGlobalState({__pptState:w&&{uuid:w.uuid,pageIndex:c,disableAutoPlay:w.disableAutoPlay}})}}}))}destroy(){this.sideEffect.flushAll(),this.viewer.destroy()}nextPage(){this.jumpToPage(this.pagesIndex$.value+1,!0)}prevPage(){this.jumpToPage(this.pagesIndex$.value-1,!0)}jumpToPage(e,t=!1){this.pagesIndex$.setValue($(e,0,this.pages.length-1),t)}render(){var t;this.box.mountStage(document.createElement("div")),this.sideEffect.addEventListener(window,"keydown",s=>{var r;if(this.box.focus)switch(s.key){case"ArrowUp":case"ArrowLeft":{this.prevPage();break}case"ArrowRight":case"ArrowDown":{(r=this.context.room)==null||r.pptNextStep();break}}});const e=(t=this.whiteboard.view.divElement)==null?void 0:t.parentElement;e&&this.sideEffect.addEventListener(e,"click",s=>{var o;const r=this.context.room;if(r&&r.state.memberState.currentApplianceName==="clicker"){for(let l=s.target;l;l=l.parentElement)if((o=l.classList)!=null&&o.contains("ppt-event-source"))return;r.pptNextStep()}})}wrapClassName(e){return"netless-app-docs-viewer-dynamic-"+e}}const Q="DocsViewer",L={kind:Q,setup(n){const e=n.box,t=n.getScenes();if(!t)throw new Error("[Docs Viewer]: scenes not found.");const s=new S.SideEffectManager,r=t.map(({ppt:l})=>l?{width:l.width,height:l.height,src:l.src,thumbnail:l.previewURL}:null).filter(l=>Boolean(l));if(r.length<=0)throw new Error("[Docs Viewer]: empty scenes.");e.mountStyles(H);const o=new m.Val(!n.isWritable);s.addDisposer(n.emitter.on("writableChange",l=>{o.setValue(!l)})),r[0].src.startsWith("ppt")?ee(s,n,e,r,o):Z(s,n,e,r,o),s.addDisposer(n.emitter.on("destroy",()=>{s.flushAll()}))}};function Z(n,e,t,s,r){const o=e.createWhiteBoardView({syncCamera:!1});n.addDisposer(r.subscribe(h=>{o.view.disableCameraTransform=h}));const l=e.createStorage("static-docs-viewer",{pagesScrollTop:0}),c=new X({whiteboard:o,readonly$:r,box:t,pages:s,pagesScrollTop:l.state.pagesScrollTop,onUserScroll:h=>{e.isWritable&&l.setState({pagesScrollTop:h})}});n.addDisposer(()=>c.destroy()),n.addDisposer(l.on("stateChanged",h=>{h.pagesScrollTop&&c.syncPageScrollTop(h.pagesScrollTop.newValue||0)})),n.addDisposer(m.combine([t._maximized$,t._managerStageRect$,t._intrinsicSize$,c.pagesSize$,c.pageRenderer._pagesMinHeight$],([h,a,p,g,u])=>h?Math.max(u/g.width*(2/5),a.height/a.width):p.height/p.width*(a.height/a.width)).subscribe(h=>{t.setStageRatio(h)}))}function ee(n,e,t,s,r){const o=e.createWhiteBoardView();o.view.disableCameraTransform=!0;const l=new K({context:e,whiteboard:o,box:t,pages:s,readonly$:r});n.addDisposer(()=>l.destroy());const c=new m.Val({width:s[0].width,height:s[0].height},{compare:T});if(n.addDisposer(l.pagesIndex$.subscribe(h=>{const a=s[h];a&&c.setValue({width:a.width,height:a.height})})),n.addDisposer(c.subscribe(h=>{r.value||o.setBaseRect(h)})),e.isAddApp){const h=n.add(()=>{const a=({width:p,height:g})=>{if(s.length>0&&t.state!=="maximized"){const{width:u,height:d}=s[0],f=d/u*p-g;f!==0&&e.isWritable&&e.emitter.emit("setBoxSize",{width:t.intrinsicWidth,height:t.intrinsicHeight+f/t.rootRect.height})}n.remove(h)};return o.view.callbacks.once("onSizeUpdated",a),()=>o.view.callbacks.off("onSizeUpdated",a)})}}exports.DocsViewer=E;exports.NetlessAppDocsViewer=L;exports.PageRenderer=D;exports.ScrollBar=M;exports.Stepper=P;exports.default=L;
//# sourceMappingURL=main.js.map
{
"name": "@netless/app-docs-viewer",
"version": "1.0.0-canary.2",
"version": "1.0.0-canary.3",
"description": "Netless App Docs Viewer",

@@ -19,6 +19,6 @@ "repository": "netless-io/netless-app",

"dependencies": {
"remitter": "^0.2.7",
"side-effect-manager": "^1.1.3",
"remitter": "^0.2.9",
"side-effect-manager": "^1.2.1",
"value-enhancer": "^1.3.2",
"vanilla-lazyload": "^17.8.2"
"vanilla-lazyload": "^17.8.3"
},

@@ -25,0 +25,0 @@ "scripts": {

@@ -119,3 +119,3 @@ import styles from "./style.scss?inline";

sideEffect.addDisposer(
storage.addStateChangedListener(diff => {
storage.on("stateChanged", diff => {
if (diff.pagesScrollTop) {

@@ -122,0 +122,0 @@ staticDocsViewer.syncPageScrollTop(diff.pagesScrollTop.newValue || 0);

@@ -249,3 +249,3 @@ import type { AnimationMode, ReadonlyTeleBox, WhiteBoardView } from "@netless/window-manager";

camera.centerY - this.pageRenderer.containerRect.height / this.pageRenderer.scale / 2;
this.pagesScrollTop$.setValue(pagesScrollTop);
this.pagesScrollTop$.setValue(Math.max(0, pagesScrollTop));
};

@@ -252,0 +252,0 @@ this.whiteboard.view.callbacks.on("onCameraUpdated", handleCameraUpdate);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc