@netless/app-docs-viewer
Advanced tools
Comparing version 0.3.3 to 1.0.0-canary.0
@@ -1,2 +0,1 @@ | ||
import type { ReadonlyTeleBox } from "@netless/window-manager"; | ||
import { type ReadonlyVal, Val, type ValEnhancedResult } from "value-enhancer"; | ||
@@ -17,7 +16,8 @@ import type { DocsViewerEventData, DocsViewerPage } from "./typings"; | ||
pages?: DocsViewerPage[]; | ||
box: ReadonlyTeleBox; | ||
previewRoot: HTMLElement; | ||
footerRoot: HTMLElement; | ||
playable: boolean; | ||
} | ||
export declare class DocsViewer { | ||
constructor({ readonly$, pagesIndex$, box, pages, playable }: DocsViewerConfig); | ||
constructor({ readonly$, pagesIndex$, previewRoot, footerRoot, pages, playable, }: DocsViewerConfig); | ||
preview: Preview; | ||
@@ -24,0 +24,0 @@ footer: Footer; |
@@ -1,10 +0,6 @@ | ||
import type { NetlessApp } from "@netless/window-manager"; | ||
export type { DocsViewerPage } from "./DocsViewer"; | ||
export interface NetlessAppStaticDocsViewerAttributes { | ||
/** ScrollTop base on the real page size */ | ||
pageScrollTop?: number; | ||
} | ||
export interface NetlessAppDynamicDocsViewerAttributes { | ||
} | ||
declare const NetlessAppDocsViewer: NetlessApp<NetlessAppStaticDocsViewerAttributes | NetlessAppDynamicDocsViewerAttributes>; | ||
export default NetlessAppDocsViewer; | ||
import "./style.scss"; | ||
export * from "./app-docs-viewer"; | ||
export * from "./DocsViewer"; | ||
export * from "./PageRenderer"; | ||
export * from "./ScrollBar"; | ||
export { NetlessAppDocsViewer as default } from "./app-docs-viewer"; |
@@ -1,3 +0,3 @@ | ||
const NetlessAppDocsViewer=function(j){"use strict";const Qe=`.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} | ||
`,ae="!#%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",Ze=ae.length,ne=Array(20),et=()=>{for(let t=0;t<20;t++)ne[t]=ae.charAt(Math.random()*Ze);return ne.join("")};function ce(t){try{return t()}catch(e){console.error(e)}}class k{constructor(){this.disposers=new Map}addDisposer(e,s=this.genUID()){return this.flush(s),this.disposers.set(s,Array.isArray(e)?()=>e.forEach(ce):e),s}add(e,s=this.genUID()){const r=e();return r?this.addDisposer(r,s):s}addEventListener(e,s,r,i,o=this.genUID()){return e.addEventListener(s,r,i),this.addDisposer(()=>e.removeEventListener(s,r,i),o),o}setTimeout(e,s,r=this.genUID()){const i=window.setTimeout(()=>{this.remove(r),e()},s);return this.addDisposer(()=>window.clearTimeout(i),r)}setInterval(e,s,r=this.genUID()){const i=window.setInterval(e,s);return this.addDisposer(()=>window.clearInterval(i),r)}remove(e){const s=this.disposers.get(e);return this.disposers.delete(e),s}flush(e){const s=this.remove(e);if(s)try{s()}catch(r){console.error(r)}}flushAll(){this.disposers.forEach(ce),this.disposers.clear()}genUID(){let e;do e=et();while(this.disposers.has(e));return e}}var tt=Object.defineProperty,st=Object.defineProperties,rt=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,W=(t,e,s)=>e in t?tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,he=(t,e)=>{for(var s in e||(e={}))it.call(e,s)&&W(t,s,e[s]);if(le)for(var s of le(e))ot.call(e,s)&&W(t,s,e[s]);return t},de=(t,e)=>st(t,rt(e)),E=(t,e,s)=>(W(t,typeof e!="symbol"?e+"":e,s),s);class at{constructor(e){E(this,"_subscribers"),E(this,"_bSub"),E(this,"_bSubDisposer"),this._bSub=e}get size(){return this._subscribers?this._subscribers.size:0}invoke(e,s){this._subscribers&&this._subscribers.forEach(r=>r(e,s))}add(e){this._bSub&&(!this._subscribers||this._subscribers.size<=0)&&(this._bSubDisposer=this._bSub()),this._subscribers||(this._subscribers=new Set),this._subscribers.add(e)}remove(e){if(this._subscribers&&this._subscribers.delete(e),this._subscribers&&this._subscribers.size<=0&&this._bSubDisposer){const s=this._bSubDisposer;this._bSubDisposer=null,s()}}clear(){if(this._subscribers&&this._subscribers.clear(),this._bSubDisposer){const e=this._bSubDisposer;this._bSubDisposer=null,e()}}destroy(){this.clear()}}class Y{constructor(e,s){E(this,"_subscribers"),E(this,"_value"),this._value=e;let r;if(s&&(s.compare&&(this.compare=s.compare),s.beforeSubscribe)){const i=s.beforeSubscribe,o=this._setValue.bind(this);r=()=>i(o)}this._subscribers=new at(r)}_setValue(e,s){this.compare(e,this._value)||(this._value=e,this._subscribers.invoke(e,s))}get value(){return this._value}reaction(e){return this._subscribers.add(e),()=>{this._subscribers.remove(e)}}subscribe(e,s){const r=this.reaction(e);return e(this._value,s),r}destroy(){this._subscribers.destroy()}unsubscribe(e){this._subscribers.remove(e)}get size(){return this._subscribers.size}compare(e,s){return e===s}}class S extends Y{constructor(){super(...arguments),E(this,"setValue",this._setValue)}}class nt extends Y{constructor(e,s,r={}){super(s(e.value),de(he({},r),{beforeSubscribe:i=>{const o=e.subscribe((n,c)=>i(s(n),c));if(r.beforeSubscribe){const n=r.beforeSubscribe(i);if(n)return()=>{o(),n()}}return o}})),E(this,"_srcValue"),this._srcValue=()=>s(e.value)}get value(){if(this.size<=0){const e=this._srcValue();return this.compare(e,this._value)?this._value:e}return this._value}}function A(t,e=r=>r,s={}){return new nt(t,e,s)}class ct extends Y{constructor(e,s,r={}){super(s(G(e)),de(he({},r),{beforeSubscribe:i=>{let o=G(e);i(s(o));const n=e.map((l,a)=>l.reaction((h,p)=>{o=o.slice(),o[a]=h,i(s(o),p)})),c=()=>n.forEach(l=>l());if(r.beforeSubscribe){const l=r.beforeSubscribe(i);if(l)return()=>{c(),l()}}return c}})),E(this,"_srcValue"),this._srcValue=()=>s(G(e))}get value(){if(this.size<=0){const e=this._srcValue();return this.compare(e,this._value)?this._value:e}return this._value}}function G(t){return t.map(lt)}function lt(t){return t.value}function w(t,e=r=>r,s={}){return new ct(t,e,s)}function pe(t){t.onValChanged||(t.onValChanged=ht)}function ht(t,e){const s=this[`_${t}$`]||this[t];if(!(s!=null&&s.reaction))throw new TypeError(`"${t}" is not related to a Val in this instance`);return s.reaction(e)}function dt(t,e,s){Object.keys(e).forEach(r=>{pt(t,r,e[r]),s&&s.attach(e[r])}),pe(t)}function pt(t,e,s){return Object.defineProperties(t,{[e]:{get(){return s.value}},[`_${e}$`]:{value:s}}),t}function ut(t,e,s){Object.keys(e).forEach(r=>{gt(t,r,e[r]),s&&s.attach(e[r])}),pe(t)}function gt(t,e,s){return Object.defineProperties(t,{[e]:{get(){return s.value},set(r){s.setValue(r)}},[`_${e}$`]:{value:s},[`set${ft(e)}`]:{value:(r,i)=>s.setValue(r,i)}}),t}function ft(t){return t[0].toUpperCase()+t.slice(1)}const y=typeof window<"u",ue=y&&!("onscroll"in window)||typeof navigator<"u"&&/(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent),ge=y&&"IntersectionObserver"in window,fe=y&&"classList"in document.createElement("p"),be=y&&window.devicePixelRatio>1,bt={elements_selector:".lazy",container:ue||y?document:null,threshold:300,thresholds:null,data_src:"src",data_srcset:"srcset",data_sizes:"sizes",data_bg:"bg",data_bg_hidpi:"bg-hidpi",data_bg_multi:"bg-multi",data_bg_multi_hidpi:"bg-multi-hidpi",data_bg_set:"bg-set",data_poster:"poster",class_applied:"applied",class_loading:"loading",class_loaded:"loaded",class_error:"error",class_entered:"entered",class_exited:"exited",unobserve_completed:!0,unobserve_entered:!1,cancel_on_exit:!0,callback_enter:null,callback_exit:null,callback_applied:null,callback_loading:null,callback_loaded:null,callback_error:null,callback_finish:null,callback_cancel:null,use_native:!1,restore_on_error:!1},we=t=>Object.assign({},bt,t),ve=function(t,e){let s;const r="LazyLoad::Initialized",i=new t(e);try{s=new CustomEvent(r,{detail:{instance:i}})}catch{s=document.createEvent("CustomEvent"),s.initCustomEvent(r,!1,!1,{instance:i})}window.dispatchEvent(s)},wt=(t,e)=>{if(!!e)if(!e.length)ve(t,e);else for(let s=0,r;r=e[s];s+=1)ve(t,r)},_="src",q="srcset",J="sizes",me="poster",P="llOriginalAttrs",Se="data",X="loading",_e="loaded",Ee="applied",vt="entered",K="error",ye="native",$e="data-",xe="ll-status",b=(t,e)=>t.getAttribute($e+e),mt=(t,e,s)=>{var r=$e+e;if(s===null){t.removeAttribute(r);return}t.setAttribute(r,s)},V=t=>b(t,xe),I=(t,e)=>mt(t,xe,e),R=t=>I(t,null),Q=t=>V(t)===null,St=t=>V(t)===X,_t=t=>V(t)===K,Z=t=>V(t)===ye,Et=[X,_e,Ee,K],yt=t=>Et.indexOf(V(t))>=0,$=(t,e,s,r)=>{if(!!t){if(r!==void 0){t(e,s,r);return}if(s!==void 0){t(e,s);return}t(e)}},T=(t,e)=>{if(fe){t.classList.add(e);return}t.className+=(t.className?" ":"")+e},v=(t,e)=>{if(fe){t.classList.remove(e);return}t.className=t.className.replace(new RegExp("(^|\\s+)"+e+"(\\s+|$)")," ").replace(/^\s+/,"").replace(/\s+$/,"")},$t=t=>{t.llTempImage=document.createElement("IMG")},xt=t=>{delete t.llTempImage},Ce=t=>t.llTempImage,H=(t,e)=>{if(!e)return;const s=e._observer;!s||s.unobserve(t)},Ct=t=>{t.disconnect()},Lt=(t,e,s)=>{e.unobserve_entered&&H(t,s)},ee=(t,e)=>{!t||(t.loadingCount+=e)},kt=t=>{!t||(t.toLoadCount-=1)},Le=(t,e)=>{!t||(t.toLoadCount=e)},It=t=>t.loadingCount>0,Dt=t=>t.toLoadCount>0,ke=t=>{let e=[];for(let s=0,r;r=t.children[s];s+=1)r.tagName==="SOURCE"&&e.push(r);return e},te=(t,e)=>{const s=t.parentNode;if(!s||s.tagName!=="PICTURE")return;ke(s).forEach(e)},Ie=(t,e)=>{ke(t).forEach(e)},B=[_],De=[_,me],z=[_,q,J],Te=[Se],U=t=>!!t[P],Ne=t=>t[P],Ae=t=>delete t[P],N=(t,e)=>{if(U(t))return;const s={};e.forEach(r=>{s[r]=t.getAttribute(r)}),t[P]=s},Tt=t=>{U(t)||(t[P]={backgroundImage:t.style.backgroundImage})},Nt=(t,e,s)=>{if(!s){t.removeAttribute(e);return}t.setAttribute(e,s)},D=(t,e)=>{if(!U(t))return;const s=Ne(t);e.forEach(r=>{Nt(t,r,s[r])})},At=t=>{if(!U(t))return;const e=Ne(t);t.style.backgroundImage=e.backgroundImage},Pe=(t,e,s)=>{T(t,e.class_applied),I(t,Ee),s&&(e.unobserve_completed&&H(t,e),$(e.callback_applied,t,s))},Ve=(t,e,s)=>{T(t,e.class_loading),I(t,X),s&&(ee(s,1),$(e.callback_loading,t,s))},x=(t,e,s)=>{!s||t.setAttribute(e,s)},ze=(t,e)=>{x(t,J,b(t,e.data_sizes)),x(t,q,b(t,e.data_srcset)),x(t,_,b(t,e.data_src))},Pt=(t,e)=>{te(t,s=>{N(s,z),ze(s,e)}),N(t,z),ze(t,e)},Vt=(t,e)=>{N(t,B),x(t,_,b(t,e.data_src))},zt=(t,e)=>{Ie(t,s=>{N(s,B),x(s,_,b(s,e.data_src))}),N(t,De),x(t,me,b(t,e.data_poster)),x(t,_,b(t,e.data_src)),t.load()},Ot=(t,e)=>{N(t,Te),x(t,Se,b(t,e.data_src))},Mt=(t,e,s)=>{const r=b(t,e.data_bg),i=b(t,e.data_bg_hidpi),o=be&&i?i:r;!o||(t.style.backgroundImage=`url("${o}")`,Ce(t).setAttribute(_,o),Ve(t,e,s))},Rt=(t,e,s)=>{const r=b(t,e.data_bg_multi),i=b(t,e.data_bg_multi_hidpi),o=be&&i?i:r;!o||(t.style.backgroundImage=o,Pe(t,e,s))},Ht=(t,e,s)=>{const r=b(t,e.data_bg_set);if(!r)return;const i=r.split("|");let o=i.map(n=>`image-set(${n})`);t.style.backgroundImage=o.join(),t.style.backgroundImage===""&&(o=i.map(n=>`-webkit-image-set(${n})`),t.style.backgroundImage=o.join()),Pe(t,e,s)},Oe={IMG:Pt,IFRAME:Vt,VIDEO:zt,OBJECT:Ot},Bt=(t,e)=>{const s=Oe[t.tagName];!s||s(t,e)},Ut=(t,e,s)=>{const r=Oe[t.tagName];!r||(r(t,e),Ve(t,e,s))},Ft=["IMG","IFRAME","VIDEO","OBJECT"],jt=t=>Ft.indexOf(t.tagName)>-1,Me=(t,e)=>{e&&!It(e)&&!Dt(e)&&$(t.callback_finish,e)},Re=(t,e,s)=>{t.addEventListener(e,s),t.llEvLisnrs[e]=s},Wt=(t,e,s)=>{t.removeEventListener(e,s)},se=t=>!!t.llEvLisnrs,Yt=(t,e,s)=>{se(t)||(t.llEvLisnrs={});const r=t.tagName==="VIDEO"?"loadeddata":"load";Re(t,r,e),Re(t,"error",s)},re=t=>{if(!se(t))return;const e=t.llEvLisnrs;for(let s in e){const r=e[s];Wt(t,s,r)}delete t.llEvLisnrs},He=(t,e,s)=>{xt(t),ee(s,-1),kt(s),v(t,e.class_loading),e.unobserve_completed&&H(t,s)},Gt=(t,e,s,r)=>{const i=Z(e);He(e,s,r),T(e,s.class_loaded),I(e,_e),$(s.callback_loaded,e,r),i||Me(s,r)},qt=(t,e,s,r)=>{const i=Z(e);He(e,s,r),T(e,s.class_error),I(e,K),$(s.callback_error,e,r),s.restore_on_error&&D(e,z),i||Me(s,r)},ie=(t,e,s)=>{const r=Ce(t)||t;if(se(r))return;Yt(r,n=>{Gt(n,t,e,s),re(r)},n=>{qt(n,t,e,s),re(r)})},Jt=(t,e,s)=>{$t(t),ie(t,e,s),Tt(t),Mt(t,e,s),Rt(t,e,s),Ht(t,e,s)},Xt=(t,e,s)=>{ie(t,e,s),Ut(t,e,s)},oe=(t,e,s)=>{jt(t)?Xt(t,e,s):Jt(t,e,s)},Kt=(t,e,s)=>{t.setAttribute("loading","lazy"),ie(t,e,s),Bt(t,e),I(t,ye)},Be=t=>{t.removeAttribute(_),t.removeAttribute(q),t.removeAttribute(J)},Qt=t=>{te(t,e=>{Be(e)}),Be(t)},Ue=t=>{te(t,e=>{D(e,z)}),D(t,z)},Zt={IMG:Ue,IFRAME:t=>{D(t,B)},VIDEO:t=>{Ie(t,e=>{D(e,B)}),D(t,De),t.load()},OBJECT:t=>{D(t,Te)}},es=t=>{const e=Zt[t.tagName];if(!e){At(t);return}e(t)},ts=(t,e)=>{Q(t)||Z(t)||(v(t,e.class_entered),v(t,e.class_exited),v(t,e.class_applied),v(t,e.class_loading),v(t,e.class_loaded),v(t,e.class_error))},ss=(t,e)=>{es(t),ts(t,e),R(t),Ae(t)},rs=(t,e,s,r)=>{!s.cancel_on_exit||!St(t)||t.tagName==="IMG"&&(re(t),Qt(t),Ue(t),v(t,s.class_loading),ee(r,-1),R(t),$(s.callback_cancel,t,e,r))},is=(t,e,s,r)=>{const i=yt(t);I(t,vt),T(t,s.class_entered),v(t,s.class_exited),Lt(t,s,r),$(s.callback_enter,t,e,r),!i&&oe(t,s,r)},os=(t,e,s,r)=>{Q(t)||(T(t,s.class_exited),rs(t,e,s,r),$(s.callback_exit,t,e,r))},as=["IMG","IFRAME","VIDEO"],Fe=t=>t.use_native&&"loading"in HTMLImageElement.prototype,ns=(t,e,s)=>{t.forEach(r=>{as.indexOf(r.tagName)!==-1&&Kt(r,e,s)}),Le(s,0)},cs=t=>t.isIntersecting||t.intersectionRatio>0,ls=t=>({root:t.container===document?null:t.container,rootMargin:t.thresholds||t.threshold+"px"}),hs=(t,e,s)=>{t.forEach(r=>cs(r)?is(r.target,r,e,s):os(r.target,r,e,s))},ds=(t,e)=>{e.forEach(s=>{t.observe(s)})},ps=(t,e)=>{Ct(t),ds(t,e)},us=(t,e)=>{!ge||Fe(t)||(e._observer=new IntersectionObserver(s=>{hs(s,t,e)},ls(t)))},je=t=>Array.prototype.slice.call(t),F=t=>t.container.querySelectorAll(t.elements_selector),gs=t=>je(t).filter(Q),fs=t=>_t(t),bs=t=>je(t).filter(fs),We=(t,e)=>gs(t||F(e)),ws=(t,e)=>{bs(F(t)).forEach(r=>{v(r,t.class_error),R(r)}),e.update()},vs=(t,e)=>{!y||(e._onlineHandler=()=>{ws(t,e)},window.addEventListener("online",e._onlineHandler))},ms=t=>{!y||window.removeEventListener("online",t._onlineHandler)},O=function(t,e){const s=we(t);this._settings=s,this.loadingCount=0,us(s,this),vs(s,this),this.update(e)};O.prototype={update:function(t){const e=this._settings,s=We(t,e);if(Le(this,s.length),ue||!ge){this.loadAll(s);return}if(Fe(e)){ns(s,e,this);return}ps(this._observer,s)},destroy:function(){this._observer&&this._observer.disconnect(),ms(this),F(this._settings).forEach(t=>{Ae(t)}),delete this._observer,delete this._settings,delete this._onlineHandler,delete this.loadingCount,delete this.toLoadCount},loadAll:function(t){const e=this._settings;We(t,e).forEach(r=>{H(r,this),oe(r,e,this)})},restoreAll:function(){const t=this._settings;F(t).forEach(e=>{ss(e,t)})}},O.load=(t,e)=>{const s=we(e);oe(t,s)},O.resetStatus=t=>{R(t)},y&&wt(O,window.lazyLoadOptions);class Ss{constructor({namespace:e,pages$:s,sideEffect:r,readonly$:i,events:o,wrapClassName:n,root:c,pagesIndex$:l}){this.showPreview$=new S(!1),this.namespace=e,this.pages$=s,this.sideEffect=r,this.readonly$=i,this.events=o,this.wrapClassName=n,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(),p=this.renderPreviewMask();if(a){c.appendChild(h),c.appendChild(p),h.scrollTop;const u=h.querySelector("."+this.wrapClassName(`preview-page-${l.value}`));return u&&h.scrollTo({top:u.offsetTop-16}),h.classList.toggle(this.wrapClassName("preview-active"),!0),this.previewLazyLoad=new O({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(),p.remove()},500,"preview-remove"),null},"preview-lazyload")}))}destroy(){var e,s;(e=this.$preview)==null||e.remove(),(s=this.$previewMask)==null||s.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",s=>s.stopPropagation(),{passive:!1}),this.sideEffect.addDisposer(this.pages$.subscribe(s=>{var r;this.sideEffect.add(()=>{const i=s.map((o,n)=>{var u;const c=(u=o.thumbnail)!=null?u:o.src.startsWith("ppt")?void 0:o.src;if(!c)return;const l=String(n),a=document.createElement("a");a.className=this.wrapClassName("preview-page")+" "+this.wrapClassName(`preview-page-${n}`),a.setAttribute("href","#"),a.dataset.pageIndex=l;const h=document.createElement("span");h.className=this.wrapClassName("preview-page-name"),h.textContent=String(n+1),h.dataset.pageIndex=l;const p=document.createElement("img");return p.width=o.width,p.height=o.height,p.dataset.src=c,p.dataset.pageIndex=l,a.appendChild(p),a.appendChild(h),e.appendChild(a),a});return()=>i.forEach(o=>o==null?void 0:o.remove())},"render-preview-pages"),(r=this.previewLazyLoad)==null||r.update()})),this.sideEffect.addEventListener(e,"click",s=>{var i;if(this.readonly$.value)return;const r=(i=s.target.dataset)==null?void 0:i.pageIndex;r&&(s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation(),this.events.emit("jumpPage",Number(r)),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",s=>{this.readonly$.value||s.target===e&&this.showPreview$.setValue(!1)}),e}}function _s(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-sidebar`),s.setAttribute("viewBox","0 0 64 64");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}function Es(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-arrow-left`),s.setAttribute("viewBox","0 0 500 500");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}function ys(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-arrow-right`),s.setAttribute("viewBox","0 0 500 500");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}function $s(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-play`),s.setAttribute("viewBox","0 0 500 500");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}function xs(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-pause`),s.setAttribute("viewBox","0 0 500 500");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}class Cs{constructor({namespace:e,pages$:s,sideEffect:r,readonly$:i,events:o,playable:n,wrapClassName:c,pagesIndex$:l,root:a}){this.namespace=e,this.pages$=s,this.sideEffect=r,this.readonly$=i,this.events=o,this.wrapClassName=c,this.pagesIndex$=l,this.playable=n,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 s=this.renderFooterBtn("btn-sidebar",_s(this.namespace));this.sideEffect.addEventListener(s,"click",()=>{this.readonly$.value||this.events.emit("togglePreview")}),e.appendChild(s),this.sideEffect.addDisposer(this.pages$.subscribe(a=>{const h=a.some(p=>p.thumbnail||!p.src.startsWith("ppt"));s.style.display=h?"":"none"}));const r=document.createElement("div");r.className=this.wrapClassName("page-jumps");const i=this.renderFooterBtn("btn-page-back",Es(this.namespace));if(this.sideEffect.addEventListener(i,"click",()=>{this.readonly$.value||this.events.emit("back")}),r.appendChild(i),this.playable){const a=this.renderFooterBtn("btn-page-play",$s(this.namespace),xs(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"))}),r.appendChild(a)}const o=this.renderFooterBtn("btn-page-next",ys(this.namespace));this.sideEffect.addEventListener(o,"click",()=>{this.readonly$.value||this.events.emit("next")}),r.appendChild(o);const n=document.createElement("div");n.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 l=document.createElement("span");return this.sideEffect.addDisposer(this.pages$.subscribe(a=>{l.textContent=" / "+a.length})),n.appendChild(c),n.appendChild(l),e.appendChild(r),e.appendChild(n),e}renderFooterBtn(e,s,r){const i=document.createElement("button");return i.className=this.wrapClassName("footer-btn")+" "+this.wrapClassName(e),i.appendChild(s),r&&i.appendChild(r),i}}class Ls{constructor(){this.listeners=new Map,this.relayListeners=new Set}emit(e,s){var r;(r=this.listeners.get(e))==null||r.forEach(i=>i(s))}on(e,s){let r=this.listeners.get(e);return r||(r=new Set,this.listeners.set(e,r)),r.add(s),r.size===1&&this.relayListeners.forEach(i=>i.start(e)),()=>{this.off(e,s)}}off(e,s){const r=this.listeners.get(e);if(r){const i=r.delete(s);return r.size<=0&&(this.listeners.delete(e),this.relayListeners.forEach(o=>o.dispose(e))),i}return!1}clear(e){var s;e?(s=this.listeners.get(e))==null||s.clear():this.listeners.clear()}count(e){var s;if(e)return((s=this.listeners.get(e))==null?void 0:s.size)||0;{let r=0;return this.listeners.forEach(i=>{r+=i.size}),r}}remit(e,s){let r;const i={start:o=>{o===e&&(r=s(this))},dispose:o=>{r&&(!o||o===e)&&r()}};return this.relayListeners.add(i),()=>{this.relayListeners.delete(i),r&&r()}}destroy(){this.clear(),this.relayListeners.forEach(e=>e.dispose()),this.relayListeners.clear()}}class Ye{constructor({readonly$:e,pagesIndex$:s,box:r,pages:i=[],playable:o}){this.wrapClassName=c=>`${this.namespace}-${c}`,this.namespace="netless-app-docs-viewer",this.sideEffect=new k,this.events=new Ls;const n=new S(i);ut(this,{pages:n}),this.preview=new Ss({pages$:n,readonly$:e,pagesIndex$:s,root:r.$body,sideEffect:this.sideEffect,events:this.events,namespace:this.namespace,wrapClassName:this.wrapClassName}),this.footer=new Cs({pages$:n,readonly$:e,playable:o,pagesIndex$:s,root:r.$footer,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 C(t,e,s){return Math.min(Math.max(t,e),s)}function Ge(t){return t.touches?t.touches[0]:t}function qe(t){t.stopPropagation(),t.cancelable&&t.preventDefault()}function Je(t,e){return t.width===e.width&&t.height===e.height}class ks{constructor(e){var s,r,i;this.velocity=0,this._paused=!0,this._animationFrameID=null,this._loopTimestamp=0,this.looper=o=>{var c;if(this._paused)return;let n=Math.floor((o-this._loopTimestamp)/1e3*60)+1;for(this._loopTimestamp=o;n-- >0;)this.stepper();(c=this.onStep)==null||c.call(this,this.current),this._paused?this._animationFrameID=null:this._animationFrameID=window.requestAnimationFrame(this.looper)},this.current=(s=e.start)!=null?s:0,this.target=this.current,this.stiffness=(r=e.stiffness)!=null?r:170,this.damping=(i=e.damping)!=null?i:26,this.onStep=e.onStep}get paused(){return this._paused}stepTo(e,s){var r;this._paused&&s!=null&&(this.current=s),this._paused=!1,this.target=e,(r=this.onStep)==null||r.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),s=-this.damping*this.velocity,r=this.velocity+(e+s)/60,i=this.current+r/60;Math.abs(r-0)<.01&&Math.abs(i-this.target)<.01?(this.current=this.target,this.velocity=0,this._paused=!0):(this.current=i,this.velocity=r)}}class Is{constructor(e,s,r,i,o,n){this.index=e,this.lastVisit=Date.now(),this.sideEffect=new k;const c=A(s,u=>u[e]||{width:0,height:0}),l=w([c,r],([u,d])=>(d.width-u.width)/2),a=w([o,n],([u,d])=>(u[e]||0)-d),h=document.createElement("div");h.className="page-renderer-page",h.dataset.index=`${e}`;const p=document.createElement("img");p.className="page-renderer-page-img",h.appendChild(p),this.sideEffect.addDisposer([w([c,i]).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}")`),p.width=u.width,p.height=u.height,p.src=u.src}),w([l,a,i]).subscribe(([u,d,g])=>{h.style.transform=`translate(${u*g}px, ${d*g}px)`})]),this.$page=h}destroy(){this.sideEffect.flushAll(),this.$page.remove()}}const Ds=window.requestIdleCallback||(t=>window.setTimeout(t,5e3)),Ts=window.cancelIdleCallback||window.clearTimeout;class Ns{constructor(e,s,r,i,o){this.pages$=e,this.pagesSize$=s,this.scale$=r,this.pagesYs$=i,this.pagesScrollTop$=o,this.els=new Map,this.maxElCount=200,this.gcTimer=null,this.gc=()=>{var n;if(this.gcTimer=null,this.els.size>this.maxElCount){const c=[...this.els.values()].sort((l,a)=>a.lastVisit-l.lastVisit);for(let l=Math.floor(this.maxElCount/4);l<c.length;l++)(n=this.els.get(c[l].index))==null||n.destroy(),this.els.delete(c[l].index)}}}getEl(e){let s=this.els.get(e);return s||(s=new Is(e,this.pages$,this.pagesSize$,this.scale$,this.pagesYs$,this.pagesScrollTop$),this.els.set(e,s)),s.lastVisit=Date.now(),this.els.size>this.maxElCount&&this.gcTimer===null&&(this.gcTimer=Ds(this.gc)),s}destroy(){this.els.forEach(e=>e.destroy()),this.els.clear(),this.gcTimer!==null&&(Ts(this.gcTimer),this.gcTimer=null)}}class As{constructor({pagesScrollTop$:e,containerRect$:s,pages$:r,pagesSize$:i}){this.sideEffect=new k,r=A(r,d=>d.map(g=>{if(g.thumbnail)return g;try{const f=new URL(g.src);return f.searchParams.set("x-oss-process","image/resize,l_50"),{...g,thumbnail:f.toString()}}catch(f){return console.error(f),g}}));const o=A(r,d=>{const g=Array(d.length);for(let f=0;f<d.length;f++)g[f]=f>0?g[f-1]+d[f-1].height:0;return g}),n=A(r,d=>{let g=1/0;for(let f=d.length-1;f>=0;f--)d[f].height<=g&&(g=d[f].height);return g}),c=w([e,o,r],([d,g,f])=>{for(let m=0;m<g.length;m++)if(g[m]+f[m].height-d>=.001)return m;return g.length-1}),l=w([s,i],([d,g])=>d.width/g.width||1),a=w([r,s,n,l],([d,g,f,m])=>C(Math.ceil(g.height/m/f/2),1,d.length));dt(this,{pagesScrollTop:e,containerRect:s,pages:r,pagesSize:i,pagesIndex:c,pagesYs:o,pagesMinHeight:n,scale:l}),this.pageElManager=new Ns(r,i,l,o,e),this.$pages=this.renderPages();const h=new S(!1);this.sideEffect.addDisposer(h.subscribe(d=>this.$pages.classList.toggle("is-hwa",d)));const p=()=>h.setValue(!1),u=()=>{this.sideEffect.setTimeout(p,1e3,"turn-off-hwa"),h.setValue(!0)};this.sideEffect.addDisposer(w([c,a,r]).subscribe(([d,g,f])=>{u();const m=Math.max(d-g,0),Xe=Math.min(d+g,f.length-1);for(let L=0;L<this.$pages.children.length;L++){const M=this.$pages.children[L],Ke=Number(M.dataset.index);Ke>=m&&Ke<=Xe||(M.remove(),L--)}for(let L=m;L<=Xe;L++){const M=this.pageElManager.getEl(L);M.$page.parentElement!==this.$pages&&this.$pages.appendChild(M.$page)}}))}renderPages(){const e=document.createElement("div");return e.className="page-renderer-pages-container",this.sideEffect.addDisposer(this._containerRect$.subscribe(s=>{e.style.width=`${s.width}px`,e.style.height=`${s.height}px`}),"render-pages-size"),e}destroy(){this.sideEffect.flushAll(),this.$pages.remove(),this.pageElManager.destroy()}}const Ps=30;class Vs{constructor({pagesScrollTop$:e,containerRect$:s,stageRect$:r,pagesSize$:i,readonly$:o,scrollbarMinHeight:n=Ps,wrapClassName:c,onDragScroll:l}){this.sideEffect=new k,this.scrolling$=new S(!1),this.pagesScrollTop$=e,this.containerRect$=s,this.stageRect$=r,this.pagesSize$=i,this.scrollbarMinHeight=n,this.readonly$=o,this.wrapClassName=c,this.onDragScroll=l,this.scrollbarHeight$=w([s,r,i],([a,h,p])=>C(h.height/(h.width/p.width*p.height)*a.height,n,a.height)),this.scrollTop$=w([s,r,i,this.scrollbarHeight$,this.pagesScrollTop$],([a,h,p,u,d])=>C(d/(p.height-p.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(r=>{e.style.height=`${r}px`}),this.scrollTop$.subscribe(r=>{this.scrolling$.setValue(!0),this.sideEffect.setTimeout(()=>this.scrolling$.setValue(!1),100,"reset-scrolling");const i=()=>e.style.transform=`translateY(${r}px)`;window.requestAnimationFrame?window.requestAnimationFrame(i):i()}),this.scrolling$.subscribe(r=>{e.classList.toggle(this.wrapClassName("scrolling"),r)})]);const s=r=>{if(!r.isPrimary||this.readonly$.value||r.button!=null&&r.button!==0)return;qe(r);const i=this.wrapClassName("scrollbar-dragging");e.classList.toggle(i,!0);const o=this.pagesScrollTop$.value,{clientY:n}=Ge(r),c=a=>{if(!a.isPrimary||this.readonly$.value)return;const{clientY:h}=Ge(a),p=h-n;Math.abs(p)>0&&this.onDragScroll&&this.onDragScroll(o+p/this.containerRect$.value.height*this.pagesSize$.value.height)},l=a=>{!a.isPrimary||(e.classList.toggle(i,!1),window.removeEventListener("pointermove",c,!0),window.removeEventListener("pointerup",l,!0),window.removeEventListener("pointercancel",l,!0))};window.addEventListener("pointermove",c,!0),window.addEventListener("pointerup",l,!0),window.addEventListener("pointercancel",l,!0)};return this.sideEffect.addEventListener(e,"pointerdown",s),e}}class zs{constructor({whiteboard:e,readonly$:s,box:r,pages:i,pagesScrollTop:o=0,onUserScroll:n}){this.sideEffect=new k,this.userScrolling=!1,this.whiteboard=e,this.readonly$=s,this.box=r,this.pages=i,this.onUserScroll=n;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 l=new S(i);this.pagesScrollTop$=new S(o),this.pagesSize$=A(l,a=>{let h=0,p=0;for(let u=a.length-1;u>=0;u--){const d=a[u];d.width>h&&(h=d.width),p+=d.height}return{width:Math.max(1,h),height:Math.max(1,p)}},{compare:Je}),this.pageRenderer=new As({pagesScrollTop$:this.pagesScrollTop$,containerRect$:r._stageRect$,pages$:l,pagesSize$:this.pagesSize$}),this.viewer=new Ye({readonly$:s,pagesIndex$:this.pageRenderer._pagesIndex$,box:r,pages:i,playable:!1}),this.sideEffect.addDisposer([this.viewer.events.on("next",()=>{this.userScrollByPercent(.8)}),this.viewer.events.on("back",()=>{this.userScrollByPercent(-.8)})]),this.scrollbar=new Vs({pagesScrollTop$:this.pagesScrollTop$,containerRect$:r._bodyRect$,stageRect$:r._stageRect$,pagesSize$:this.pagesSize$,readonly$:s,wrapClassName:this.wrapClassName.bind(this),onDragScroll:a=>{this.pageScrollTo(a),this.debounceOnUserScroll()}}),this.pageScrollStepper=new ks({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 s=this.whiteboard.view.size.height/2/this.pageRenderer.scale;this.whiteboard.view.moveCamera({centerY:C(e+s,s,this.pagesSize$.value.height-s),animationMode:"immediately"})}userScrollToPageIndex(e){var s;if(e=C(e,0,this.pages.length-1),!this.readonly$.value&&!Number.isNaN(e)){const r=this.pageRenderer.pagesYs[e];r>=0&&((s=this.onUserScroll)==null||s.call(this,r+5/this.pageRenderer.scale))}}userScrollByPercent(e){var s;this.readonly$.value||(s=this.onUserScroll)==null||s.call(this,C(this.pageRenderer.pagesScrollTop+this.pageRenderer.containerRect.height/this.pageRenderer.scale*C(e,-1,1),0,this.pageRenderer.pagesSize.height-this.pageRenderer.containerRect.height/this.pageRenderer.scale))}setupScrollListener(){this.sideEffect.addEventListener(this.box.$main,"wheel",e=>{qe(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=s=>{const{width:r,height:i}=this.whiteboard.view.size;if(r<=0||i<=0)return;const o=s.centerY-this.pageRenderer.containerRect.height/this.pageRenderer.scale/2;this.pagesScrollTop$.setValue(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:s,height:r}=this.pagesSize$.value;this.whiteboard.view.moveCameraToContain({originX:0,originY:this.pageRenderer.pagesScrollTop,width:s,height:e.height/this.pageRenderer.scale,animationMode:"immediately"}),this.whiteboard.view.setCameraBound({damping:1,maxContentMode:()=>this.pageRenderer.scale,minContentMode:()=>this.pageRenderer.scale,centerX:s/2,centerY:r/2,width:s,height:r})}),"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 Os{constructor({readonly$:e,context:s,whiteboard:r,box:i,pages:o}){this.sideEffect=new k,this.context=s,this.whiteboard=r,this.box=i,this.pages=o;const n=new S(s.displayer.state.sceneState.index||0);this.pagesIndex$=n,this.sideEffect.add(()=>{const c=l=>{this.jumpToPage(l.index)};return this.context.emitter.on("sceneStateChange",c),()=>this.context.emitter.off("sceneStateChange",c)}),this.viewer=new Ye({readonly$:e,pagesIndex$:n,box:i,pages: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(n.subscribe((c,l)=>{var p,u;if(e.value)return;const a=this.context.getInitScenePath(),h=(u=(p=this.context.getScenes())==null?void 0:p[c])==null?void 0:u.name;if(a&&h&&this.context.setScenePath(`${a}/${h}`),l){const d=this.context.room;if(d){const g=d.state.globalState.__pptState;d.setGlobalState({__pptState:g&&{uuid:g.uuid,pageIndex:c,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,s=!1){this.pagesIndex$.setValue(C(e,0,this.pages.length-1),s)}render(){var s;this.box.mountStage(document.createElement("div")),this.sideEffect.addEventListener(window,"keydown",r=>{var i;if(this.box.focus)switch(r.key){case"ArrowUp":case"ArrowLeft":{this.prevPage();break}case"ArrowRight":case"ArrowDown":{(i=this.context.room)==null||i.pptNextStep();break}}});const e=(s=this.whiteboard.view.divElement)==null?void 0:s.parentElement;e&&this.sideEffect.addEventListener(e,"click",r=>{var o;const i=this.context.room;if(i&&i.state.memberState.currentApplianceName==="clicker"){for(let n=r.target;n;n=n.parentElement)if((o=n.classList)!=null&&o.contains("ppt-event-source"))return;i.pptNextStep()}})}wrapClassName(e){return"netless-app-docs-viewer-dynamic-"+e}}const Ms={kind:"DocsViewer",setup(t){const e=t.box,s=t.getScenes();if(!s)throw new Error("[Docs Viewer]: scenes not found.");const r=new k,i=s.map(({ppt:n})=>n?{width:n.width,height:n.height,src:n.src,thumbnail:n.previewURL}:null).filter(n=>Boolean(n));if(i.length<=0)throw new Error("[Docs Viewer]: empty scenes.");e.mountStyles(Qe);const o=new S(!t.isWritable);r.addDisposer(t.emitter.on("writableChange",n=>{o.setValue(!n)})),i[0].src.startsWith("ppt")?Hs(r,t,e,i,o):Rs(r,t,e,i,o),r.addDisposer(t.emitter.on("destroy",()=>{r.flushAll()}))}};function Rs(t,e,s,r,i){const o=e.createWhiteBoardView({syncCamera:!1});t.addDisposer(i.subscribe(l=>{o.view.disableCameraTransform=l}));const n=e.createStorage("static-docs-viewer",{pagesScrollTop:0}),c=new zs({whiteboard:o,readonly$:i,box:s,pages:r,pagesScrollTop:n.state.pagesScrollTop,onUserScroll:l=>{e.isWritable&&n.setState({pagesScrollTop:l})}});t.addDisposer(()=>c.destroy()),t.addDisposer(n.addStateChangedListener(l=>{l.pagesScrollTop&&c.syncPageScrollTop(l.pagesScrollTop.newValue||0)})),t.addDisposer(w([s._maximized$,s._managerStageRect$,s._intrinsicSize$,c.pagesSize$,c.pageRenderer._pagesMinHeight$],([l,a,h,p,u])=>l?Math.max(u/p.width*.4,a.height/a.width):h.height/h.width*(a.height/a.width)).subscribe(l=>{s.setStageRatio(l)}))}function Hs(t,e,s,r,i){const o=e.createWhiteBoardView();o.view.disableCameraTransform=!0;const n=new Os({context:e,whiteboard:o,box:s,pages:r,readonly$:i});t.addDisposer(()=>n.destroy());const c=new S({width:r[0].width,height:r[0].height},{compare:Je});if(t.addDisposer(n.pagesIndex$.subscribe(l=>{const a=r[l];a&&c.setValue({width:a.width,height:a.height})})),t.addDisposer(c.subscribe(l=>{i.value||o.setBaseRect(l)})),e.isAddApp){const l=t.add(()=>{const a=({width:h,height:p})=>{if(r.length>0&&s.state!=="maximized"){const{width:u,height:d}=r[0],f=d/u*h-p;f!==0&&e.isWritable&&e.emitter.emit("setBoxSize",{width:s.intrinsicWidth,height:s.intrinsicHeight+f/s.rootRect.height})}t.remove(l)};return o.view.callbacks.once("onSizeUpdated",a),()=>o.view.callbacks.off("onSizeUpdated",a)})}}return j.default=Ms,Object.defineProperties(j,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),j}({}); | ||
const NetlessAppDocsViewer=function(S,$,w,V,A){"use strict";const z=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(V),Q="",M=`.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 R{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 z.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 _(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 I(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 B(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 H(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 U(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 F{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",_(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",I(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",H(this.namespace),U(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",B(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=c=>`${this.namespace}-${c}`,this.namespace="netless-app-docs-viewer",this.sideEffect=new $.SideEffectManager,this.events=new A.Remitter;const a=new w.Val(l);w.withValueEnhancer(this,{pages:a}),this.preview=new R({pages$:a,readonly$:e,pagesIndex$:t,root:s,sideEffect:this.sideEffect,events:this.events,namespace:this.namespace,wrapClassName:this.wrapClassName}),this.footer=new F({pages$:a,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 b(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 Y{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 W{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 W(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 N{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])=>{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])=>b(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),D=Math.min(p+u,f.length-1);for(let v=0;v<this.$pages.children.length;v++){const y=this.$pages.children[v],L=Number(y.dataset.index);L>=m&&L<=D||(y.remove(),v--)}for(let v=m;v<=D;v++){const y=this.pageElManager.getEl(v);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 P{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])=>b(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])=>b(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(r);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 N({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:r,playable:!1}),this.sideEffect.addDisposer([this.viewer.events.on("next",()=>{this.userScrollByPercent(.8)}),this.viewer.events.on("back",()=>{this.userScrollByPercent(-.8)})]),this.scrollbar=new P({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 Y({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)}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=>{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: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(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 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 T={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(M);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 S.DocsViewer=x,S.NetlessAppDocsViewer=T,S.PageRenderer=N,S.ScrollBar=P,S.default=T,Object.defineProperties(S,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),S}({},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 Ke=`.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} | ||
`,be="!#%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",Qe=be.length,ne=Array(20),Ze=()=>{for(let t=0;t<20;t++)ne[t]=be.charAt(Math.random()*Qe);return ne.join("")};function ce(t){try{return t()}catch(e){console.error(e)}}class I{constructor(){this.disposers=new Map}addDisposer(e,s=this.genUID()){return this.flush(s),this.disposers.set(s,Array.isArray(e)?()=>e.forEach(ce):e),s}add(e,s=this.genUID()){const r=e();return r?this.addDisposer(r,s):s}addEventListener(e,s,r,i,o=this.genUID()){return e.addEventListener(s,r,i),this.addDisposer(()=>e.removeEventListener(s,r,i),o),o}setTimeout(e,s,r=this.genUID()){const i=window.setTimeout(()=>{this.remove(r),e()},s);return this.addDisposer(()=>window.clearTimeout(i),r)}setInterval(e,s,r=this.genUID()){const i=window.setInterval(e,s);return this.addDisposer(()=>window.clearInterval(i),r)}remove(e){const s=this.disposers.get(e);return this.disposers.delete(e),s}flush(e){const s=this.remove(e);if(s)try{s()}catch(r){console.error(r)}}flushAll(){this.disposers.forEach(ce),this.disposers.clear()}genUID(){let e;do e=Ze();while(this.disposers.has(e));return e}}var et=Object.defineProperty,tt=Object.defineProperties,st=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertySymbols,rt=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,W=(t,e,s)=>e in t?et(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,we=(t,e)=>{for(var s in e||(e={}))rt.call(e,s)&&W(t,s,e[s]);if(le)for(var s of le(e))it.call(e,s)&&W(t,s,e[s]);return t},ve=(t,e)=>tt(t,st(e)),$=(t,e,s)=>(W(t,typeof e!="symbol"?e+"":e,s),s);class ot{constructor(e){$(this,"_subscribers"),$(this,"_bSub"),$(this,"_bSubDisposer"),this._bSub=e}get size(){return this._subscribers?this._subscribers.size:0}invoke(e,s){this._subscribers&&this._subscribers.forEach(r=>r(e,s))}add(e){this._bSub&&(!this._subscribers||this._subscribers.size<=0)&&(this._bSubDisposer=this._bSub()),this._subscribers||(this._subscribers=new Set),this._subscribers.add(e)}remove(e){if(this._subscribers&&this._subscribers.delete(e),this._subscribers&&this._subscribers.size<=0&&this._bSubDisposer){const s=this._bSubDisposer;this._bSubDisposer=null,s()}}clear(){if(this._subscribers&&this._subscribers.clear(),this._bSubDisposer){const e=this._bSubDisposer;this._bSubDisposer=null,e()}}destroy(){this.clear()}}class G{constructor(e,s){$(this,"_subscribers"),$(this,"_value"),this._value=e;let r;if(s&&(s.compare&&(this.compare=s.compare),s.beforeSubscribe)){const i=s.beforeSubscribe,o=this._setValue.bind(this);r=()=>i(o)}this._subscribers=new ot(r)}_setValue(e,s){this.compare(e,this._value)||(this._value=e,this._subscribers.invoke(e,s))}get value(){return this._value}reaction(e){return this._subscribers.add(e),()=>{this._subscribers.remove(e)}}subscribe(e,s){const r=this.reaction(e);return e(this._value,s),r}destroy(){this._subscribers.destroy()}unsubscribe(e){this._subscribers.remove(e)}get size(){return this._subscribers.size}compare(e,s){return e===s}}class S extends G{constructor(){super(...arguments),$(this,"setValue",this._setValue)}}class at extends G{constructor(e,s,r={}){super(s(e.value),ve(we({},r),{beforeSubscribe:i=>{const o=e.subscribe((n,c)=>i(s(n),c));if(r.beforeSubscribe){const n=r.beforeSubscribe(i);if(n)return()=>{o(),n()}}return o}})),$(this,"_srcValue"),this._srcValue=()=>s(e.value)}get value(){if(this.size<=0){const e=this._srcValue();return this.compare(e,this._value)?this._value:e}return this._value}}function P(t,e=r=>r,s={}){return new at(t,e,s)}class nt extends G{constructor(e,s,r={}){super(s(j(e)),ve(we({},r),{beforeSubscribe:i=>{let o=j(e);i(s(o));const n=e.map((l,a)=>l.reaction((h,p)=>{o=o.slice(),o[a]=h,i(s(o),p)})),c=()=>n.forEach(l=>l());if(r.beforeSubscribe){const l=r.beforeSubscribe(i);if(l)return()=>{c(),l()}}return c}})),$(this,"_srcValue"),this._srcValue=()=>s(j(e))}get value(){if(this.size<=0){const e=this._srcValue();return this.compare(e,this._value)?this._value:e}return this._value}}function j(t){return t.map(ct)}function ct(t){return t.value}function w(t,e=r=>r,s={}){return new nt(t,e,s)}function me(t){t.onValChanged||(t.onValChanged=lt)}function lt(t,e){const s=this[`_${t}$`]||this[t];if(!(s!=null&&s.reaction))throw new TypeError(`"${t}" is not related to a Val in this instance`);return s.reaction(e)}function ht(t,e,s){Object.keys(e).forEach(r=>{dt(t,r,e[r]),s&&s.attach(e[r])}),me(t)}function dt(t,e,s){return Object.defineProperties(t,{[e]:{get(){return s.value}},[`_${e}$`]:{value:s}}),t}function pt(t,e,s){Object.keys(e).forEach(r=>{ut(t,r,e[r]),s&&s.attach(e[r])}),me(t)}function ut(t,e,s){return Object.defineProperties(t,{[e]:{get(){return s.value},set(r){s.setValue(r)}},[`_${e}$`]:{value:s},[`set${gt(e)}`]:{value:(r,i)=>s.setValue(r,i)}}),t}function gt(t){return t[0].toUpperCase()+t.slice(1)}const C=typeof window<"u",Se=C&&!("onscroll"in window)||typeof navigator<"u"&&/(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent),_e=C&&"IntersectionObserver"in window,Ee=C&&"classList"in document.createElement("p"),ye=C&&window.devicePixelRatio>1,ft={elements_selector:".lazy",container:Se||C?document:null,threshold:300,thresholds:null,data_src:"src",data_srcset:"srcset",data_sizes:"sizes",data_bg:"bg",data_bg_hidpi:"bg-hidpi",data_bg_multi:"bg-multi",data_bg_multi_hidpi:"bg-multi-hidpi",data_bg_set:"bg-set",data_poster:"poster",class_applied:"applied",class_loading:"loading",class_loaded:"loaded",class_error:"error",class_entered:"entered",class_exited:"exited",unobserve_completed:!0,unobserve_entered:!1,cancel_on_exit:!0,callback_enter:null,callback_exit:null,callback_applied:null,callback_loading:null,callback_loaded:null,callback_error:null,callback_finish:null,callback_cancel:null,use_native:!1,restore_on_error:!1},$e=t=>Object.assign({},ft,t),he=function(t,e){let s;const r="LazyLoad::Initialized",i=new t(e);try{s=new CustomEvent(r,{detail:{instance:i}})}catch{s=document.createEvent("CustomEvent"),s.initCustomEvent(r,!1,!1,{instance:i})}window.dispatchEvent(s)},bt=(t,e)=>{if(!!e)if(!e.length)he(t,e);else for(let s=0,r;r=e[s];s+=1)he(t,r)},_="src",q="srcset",J="sizes",xe="poster",z="llOriginalAttrs",Ce="data",X="loading",Le="loaded",ke="applied",wt="entered",K="error",Ie="native",De="data-",Te="ll-status",b=(t,e)=>t.getAttribute(De+e),vt=(t,e,s)=>{var r=De+e;if(s===null){t.removeAttribute(r);return}t.setAttribute(r,s)},O=t=>b(t,Te),D=(t,e)=>vt(t,Te,e),H=t=>D(t,null),Q=t=>O(t)===null,mt=t=>O(t)===X,St=t=>O(t)===K,Z=t=>O(t)===Ie,_t=[X,Le,ke,K],Et=t=>_t.indexOf(O(t))>=0,L=(t,e,s,r)=>{if(!!t){if(r!==void 0){t(e,s,r);return}if(s!==void 0){t(e,s);return}t(e)}},N=(t,e)=>{if(Ee){t.classList.add(e);return}t.className+=(t.className?" ":"")+e},m=(t,e)=>{if(Ee){t.classList.remove(e);return}t.className=t.className.replace(new RegExp("(^|\\s+)"+e+"(\\s+|$)")," ").replace(/^\s+/,"").replace(/\s+$/,"")},yt=t=>{t.llTempImage=document.createElement("IMG")},$t=t=>{delete t.llTempImage},Ne=t=>t.llTempImage,B=(t,e)=>{if(!e)return;const s=e._observer;!s||s.unobserve(t)},xt=t=>{t.disconnect()},Ct=(t,e,s)=>{e.unobserve_entered&&B(t,s)},ee=(t,e)=>{!t||(t.loadingCount+=e)},Lt=t=>{!t||(t.toLoadCount-=1)},Ae=(t,e)=>{!t||(t.toLoadCount=e)},kt=t=>t.loadingCount>0,It=t=>t.toLoadCount>0,Pe=t=>{let e=[];for(let s=0,r;r=t.children[s];s+=1)r.tagName==="SOURCE"&&e.push(r);return e},te=(t,e)=>{const s=t.parentNode;if(!s||s.tagName!=="PICTURE")return;Pe(s).forEach(e)},Ve=(t,e)=>{Pe(t).forEach(e)},U=[_],ze=[_,xe],V=[_,q,J],Oe=[Ce],F=t=>!!t[z],Me=t=>t[z],Re=t=>delete t[z],T=(t,e)=>{if(F(t))return;const s={};e.forEach(r=>{s[r]=t.getAttribute(r)}),t[z]=s},Dt=t=>{F(t)||(t[z]={backgroundImage:t.style.backgroundImage})},Tt=(t,e,s)=>{if(!s){t.removeAttribute(e);return}t.setAttribute(e,s)},k=(t,e)=>{if(!F(t))return;const s=Me(t);e.forEach(r=>{Tt(t,r,s[r])})},Nt=t=>{if(!F(t))return;const e=Me(t);t.style.backgroundImage=e.backgroundImage},He=(t,e,s)=>{N(t,e.class_applied),D(t,ke),s&&(e.unobserve_completed&&B(t,e),L(e.callback_applied,t,s))},Be=(t,e,s)=>{N(t,e.class_loading),D(t,X),s&&(ee(s,1),L(e.callback_loading,t,s))},x=(t,e,s)=>{!s||t.setAttribute(e,s)},de=(t,e)=>{x(t,J,b(t,e.data_sizes)),x(t,q,b(t,e.data_srcset)),x(t,_,b(t,e.data_src))},At=(t,e)=>{te(t,s=>{T(s,V),de(s,e)}),T(t,V),de(t,e)},Pt=(t,e)=>{T(t,U),x(t,_,b(t,e.data_src))},Vt=(t,e)=>{Ve(t,s=>{T(s,U),x(s,_,b(s,e.data_src))}),T(t,ze),x(t,xe,b(t,e.data_poster)),x(t,_,b(t,e.data_src)),t.load()},zt=(t,e)=>{T(t,Oe),x(t,Ce,b(t,e.data_src))},Ot=(t,e,s)=>{const r=b(t,e.data_bg),i=b(t,e.data_bg_hidpi),o=ye&&i?i:r;!o||(t.style.backgroundImage=`url("${o}")`,Ne(t).setAttribute(_,o),Be(t,e,s))},Mt=(t,e,s)=>{const r=b(t,e.data_bg_multi),i=b(t,e.data_bg_multi_hidpi),o=ye&&i?i:r;!o||(t.style.backgroundImage=o,He(t,e,s))},Rt=(t,e,s)=>{const r=b(t,e.data_bg_set);if(!r)return;const i=r.split("|");let o=i.map(n=>`image-set(${n})`);t.style.backgroundImage=o.join(),t.style.backgroundImage===""&&(o=i.map(n=>`-webkit-image-set(${n})`),t.style.backgroundImage=o.join()),He(t,e,s)},Ue={IMG:At,IFRAME:Pt,VIDEO:Vt,OBJECT:zt},Ht=(t,e)=>{const s=Ue[t.tagName];!s||s(t,e)},Bt=(t,e,s)=>{const r=Ue[t.tagName];!r||(r(t,e),Be(t,e,s))},Ut=["IMG","IFRAME","VIDEO","OBJECT"],Ft=t=>Ut.indexOf(t.tagName)>-1,Fe=(t,e)=>{e&&!kt(e)&&!It(e)&&L(t.callback_finish,e)},pe=(t,e,s)=>{t.addEventListener(e,s),t.llEvLisnrs[e]=s},jt=(t,e,s)=>{t.removeEventListener(e,s)},se=t=>!!t.llEvLisnrs,Wt=(t,e,s)=>{se(t)||(t.llEvLisnrs={});const r=t.tagName==="VIDEO"?"loadeddata":"load";pe(t,r,e),pe(t,"error",s)},Y=t=>{if(!se(t))return;const e=t.llEvLisnrs;for(let s in e){const r=e[s];jt(t,s,r)}delete t.llEvLisnrs},je=(t,e,s)=>{$t(t),ee(s,-1),Lt(s),m(t,e.class_loading),e.unobserve_completed&&B(t,s)},Yt=(t,e,s,r)=>{const i=Z(e);je(e,s,r),N(e,s.class_loaded),D(e,Le),L(s.callback_loaded,e,r),i||Fe(s,r)},Gt=(t,e,s,r)=>{const i=Z(e);je(e,s,r),N(e,s.class_error),D(e,K),L(s.callback_error,e,r),s.restore_on_error&&k(e,V),i||Fe(s,r)},re=(t,e,s)=>{const r=Ne(t)||t;if(se(r))return;Wt(r,n=>{Yt(n,t,e,s),Y(r)},n=>{Gt(n,t,e,s),Y(r)})},qt=(t,e,s)=>{yt(t),re(t,e,s),Dt(t),Ot(t,e,s),Mt(t,e,s),Rt(t,e,s)},Jt=(t,e,s)=>{re(t,e,s),Bt(t,e,s)},ie=(t,e,s)=>{Ft(t)?Jt(t,e,s):qt(t,e,s)},Xt=(t,e,s)=>{t.setAttribute("loading","lazy"),re(t,e,s),Ht(t,e),D(t,Ie)},ue=t=>{t.removeAttribute(_),t.removeAttribute(q),t.removeAttribute(J)},Kt=t=>{te(t,e=>{ue(e)}),ue(t)},We=t=>{te(t,e=>{k(e,V)}),k(t,V)},Qt=t=>{Ve(t,e=>{k(e,U)}),k(t,ze),t.load()},Zt=t=>{k(t,U)},es=t=>{k(t,Oe)},ts={IMG:We,IFRAME:Zt,VIDEO:Qt,OBJECT:es},ss=t=>{const e=ts[t.tagName];if(!e){Nt(t);return}e(t)},rs=(t,e)=>{Q(t)||Z(t)||(m(t,e.class_entered),m(t,e.class_exited),m(t,e.class_applied),m(t,e.class_loading),m(t,e.class_loaded),m(t,e.class_error))},is=(t,e)=>{ss(t),rs(t,e),H(t),Re(t)},os=(t,e,s,r)=>{!s.cancel_on_exit||!mt(t)||t.tagName==="IMG"&&(Y(t),Kt(t),We(t),m(t,s.class_loading),ee(r,-1),H(t),L(s.callback_cancel,t,e,r))},as=(t,e,s,r)=>{const i=Et(t);D(t,wt),N(t,s.class_entered),m(t,s.class_exited),Ct(t,s,r),L(s.callback_enter,t,e,r),!i&&ie(t,s,r)},ns=(t,e,s,r)=>{Q(t)||(N(t,s.class_exited),os(t,e,s,r),L(s.callback_exit,t,e,r))},cs=["IMG","IFRAME","VIDEO"],Ye=t=>t.use_native&&"loading"in HTMLImageElement.prototype,ls=(t,e,s)=>{t.forEach(r=>{cs.indexOf(r.tagName)!==-1&&Xt(r,e,s)}),Ae(s,0)},hs=t=>t.isIntersecting||t.intersectionRatio>0,ds=t=>({root:t.container===document?null:t.container,rootMargin:t.thresholds||t.threshold+"px"}),ps=(t,e,s)=>{t.forEach(r=>hs(r)?as(r.target,r,e,s):ns(r.target,r,e,s))},us=(t,e)=>{e.forEach(s=>{t.observe(s)})},gs=(t,e)=>{xt(t),us(t,e)},fs=(t,e)=>{!_e||Ye(t)||(e._observer=new IntersectionObserver(s=>{ps(s,t,e)},ds(t)))},Ge=t=>Array.prototype.slice.call(t),R=t=>t.container.querySelectorAll(t.elements_selector),bs=t=>Ge(t).filter(Q),ws=t=>St(t),vs=t=>Ge(t).filter(ws),ge=(t,e)=>bs(t||R(e)),ms=(t,e)=>{vs(R(t)).forEach(r=>{m(r,t.class_error),H(r)}),e.update()},Ss=(t,e)=>{!C||(e._onlineHandler=()=>{ms(t,e)},window.addEventListener("online",e._onlineHandler))},_s=t=>{!C||window.removeEventListener("online",t._onlineHandler)},M=function(t,e){const s=$e(t);this._settings=s,this.loadingCount=0,fs(s,this),Ss(s,this),this.update(e)};M.prototype={update:function(t){const e=this._settings,s=ge(t,e);if(Ae(this,s.length),Se||!_e){this.loadAll(s);return}if(Ye(e)){ls(s,e,this);return}gs(this._observer,s)},destroy:function(){this._observer&&this._observer.disconnect(),_s(this),R(this._settings).forEach(t=>{Re(t)}),delete this._observer,delete this._settings,delete this._onlineHandler,delete this.loadingCount,delete this.toLoadCount},loadAll:function(t){const e=this._settings;ge(t,e).forEach(r=>{B(r,this),ie(r,e,this)})},restoreAll:function(){const t=this._settings;R(t).forEach(e=>{is(e,t)})}};M.load=(t,e)=>{const s=$e(e);ie(t,s)};M.resetStatus=t=>{H(t)};C&&bt(M,window.lazyLoadOptions);class Es{constructor({namespace:e,pages$:s,sideEffect:r,readonly$:i,events:o,wrapClassName:n,root:c,pagesIndex$:l}){this.showPreview$=new S(!1),this.namespace=e,this.pages$=s,this.sideEffect=r,this.readonly$=i,this.events=o,this.wrapClassName=n,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(),p=this.renderPreviewMask();if(a){c.appendChild(h),c.appendChild(p),h.scrollTop;const u=h.querySelector("."+this.wrapClassName(`preview-page-${l.value}`));return u&&h.scrollTo({top:u.offsetTop-16}),h.classList.toggle(this.wrapClassName("preview-active"),!0),this.previewLazyLoad=new M({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(),p.remove()},500,"preview-remove"),null},"preview-lazyload")}))}destroy(){var e,s;(e=this.$preview)==null||e.remove(),(s=this.$previewMask)==null||s.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",s=>s.stopPropagation(),{passive:!1}),this.sideEffect.addDisposer(this.pages$.subscribe(s=>{var r;this.sideEffect.add(()=>{const i=s.map((o,n)=>{var u;const c=(u=o.thumbnail)!=null?u:o.src.startsWith("ppt")?void 0:o.src;if(!c)return;const l=String(n),a=document.createElement("a");a.className=this.wrapClassName("preview-page")+" "+this.wrapClassName(`preview-page-${n}`),a.setAttribute("href","#"),a.dataset.pageIndex=l;const h=document.createElement("span");h.className=this.wrapClassName("preview-page-name"),h.textContent=String(n+1),h.dataset.pageIndex=l;const p=document.createElement("img");return p.width=o.width,p.height=o.height,p.dataset.src=c,p.dataset.pageIndex=l,a.appendChild(p),a.appendChild(h),e.appendChild(a),a});return()=>i.forEach(o=>o==null?void 0:o.remove())},"render-preview-pages"),(r=this.previewLazyLoad)==null||r.update()})),this.sideEffect.addEventListener(e,"click",s=>{var i;if(this.readonly$.value)return;const r=(i=s.target.dataset)==null?void 0:i.pageIndex;r&&(s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation(),this.events.emit("jumpPage",Number(r)),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",s=>{this.readonly$.value||s.target===e&&this.showPreview$.setValue(!1)}),e}}function ys(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-sidebar`),s.setAttribute("viewBox","0 0 64 64");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}function $s(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-arrow-left`),s.setAttribute("viewBox","0 0 500 500");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}function xs(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-arrow-right`),s.setAttribute("viewBox","0 0 500 500");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}function Cs(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-play`),s.setAttribute("viewBox","0 0 500 500");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}function Ls(t){const e="http://www.w3.org/2000/svg",s=document.createElementNS(e,"svg");s.setAttribute("class",`${t}-footer-icon-pause`),s.setAttribute("viewBox","0 0 500 500");const r=document.createElementNS(e,"path");return r.setAttribute("fill","currentColor"),r.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"),s.appendChild(r),s}class ks{constructor({namespace:e,pages$:s,sideEffect:r,readonly$:i,events:o,playable:n,wrapClassName:c,pagesIndex$:l,root:a}){this.namespace=e,this.pages$=s,this.sideEffect=r,this.readonly$=i,this.events=o,this.wrapClassName=c,this.pagesIndex$=l,this.playable=n,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 s=this.renderFooterBtn("btn-sidebar",ys(this.namespace));this.sideEffect.addEventListener(s,"click",()=>{this.readonly$.value||this.events.emit("togglePreview")}),e.appendChild(s),this.sideEffect.addDisposer(this.pages$.subscribe(a=>{const h=a.some(p=>p.thumbnail||!p.src.startsWith("ppt"));s.style.display=h?"":"none"}));const r=document.createElement("div");r.className=this.wrapClassName("page-jumps");const i=this.renderFooterBtn("btn-page-back",$s(this.namespace));if(this.sideEffect.addEventListener(i,"click",()=>{this.readonly$.value||this.events.emit("back")}),r.appendChild(i),this.playable){const a=this.renderFooterBtn("btn-page-play",Cs(this.namespace),Ls(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"))}),r.appendChild(a)}const o=this.renderFooterBtn("btn-page-next",xs(this.namespace));this.sideEffect.addEventListener(o,"click",()=>{this.readonly$.value||this.events.emit("next")}),r.appendChild(o);const n=document.createElement("div");n.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 l=document.createElement("span");return this.sideEffect.addDisposer(this.pages$.subscribe(a=>{l.textContent=" / "+a.length})),n.appendChild(c),n.appendChild(l),e.appendChild(r),e.appendChild(n),e}renderFooterBtn(e,s,r){const i=document.createElement("button");return i.className=this.wrapClassName("footer-btn")+" "+this.wrapClassName(e),i.appendChild(s),r&&i.appendChild(r),i}}class Is{constructor(){this.listeners=new Map,this.relayListeners=new Set}emit(e,s){var r;(r=this.listeners.get(e))==null||r.forEach(i=>i(s))}on(e,s){let r=this.listeners.get(e);return r||(r=new Set,this.listeners.set(e,r)),r.add(s),r.size===1&&this.relayListeners.forEach(i=>i.start(e)),()=>{this.off(e,s)}}off(e,s){const r=this.listeners.get(e);if(r){const i=r.delete(s);return r.size<=0&&(this.listeners.delete(e),this.relayListeners.forEach(o=>o.dispose(e))),i}return!1}clear(e){var s;e?(s=this.listeners.get(e))==null||s.clear():this.listeners.clear()}count(e){var s;if(e)return((s=this.listeners.get(e))==null?void 0:s.size)||0;{let r=0;return this.listeners.forEach(i=>{r+=i.size}),r}}remit(e,s){let r;const i={start:o=>{o===e&&(r=s(this))},dispose:o=>{r&&(!o||o===e)&&r()}};return this.relayListeners.add(i),()=>{this.relayListeners.delete(i),r&&r()}}destroy(){this.clear(),this.relayListeners.forEach(e=>e.dispose()),this.relayListeners.clear()}}class qe{constructor({readonly$:e,pagesIndex$:s,box:r,pages:i=[],playable:o}){this.wrapClassName=c=>`${this.namespace}-${c}`,this.namespace="netless-app-docs-viewer",this.sideEffect=new I,this.events=new Is;const n=new S(i);pt(this,{pages:n}),this.preview=new Es({pages$:n,readonly$:e,pagesIndex$:s,root:r.$body,sideEffect:this.sideEffect,events:this.events,namespace:this.namespace,wrapClassName:this.wrapClassName}),this.footer=new ks({pages$:n,readonly$:e,playable:o,pagesIndex$:s,root:r.$footer,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 y(t,e,s){return Math.min(Math.max(t,e),s)}function fe(t){return t.touches?t.touches[0]:t}function Je(t){t.stopPropagation(),t.cancelable&&t.preventDefault()}function Xe(t,e){return t.width===e.width&&t.height===e.height}class Ds{constructor(e){var s,r,i;this.velocity=0,this._paused=!0,this._animationFrameID=null,this._loopTimestamp=0,this.looper=o=>{var c;if(this._paused)return;let n=Math.floor((o-this._loopTimestamp)/1e3*60)+1;for(this._loopTimestamp=o;n-- >0;)this.stepper();(c=this.onStep)==null||c.call(this,this.current),this._paused?this._animationFrameID=null:this._animationFrameID=window.requestAnimationFrame(this.looper)},this.current=(s=e.start)!=null?s:0,this.target=this.current,this.stiffness=(r=e.stiffness)!=null?r:170,this.damping=(i=e.damping)!=null?i:26,this.onStep=e.onStep}get paused(){return this._paused}stepTo(e,s){var r;this._paused&&s!=null&&(this.current=s),this._paused=!1,this.target=e,(r=this.onStep)==null||r.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),s=-this.damping*this.velocity,r=this.velocity+(e+s)/60,i=this.current+r/60;Math.abs(r-0)<.01&&Math.abs(i-this.target)<.01?(this.current=this.target,this.velocity=0,this._paused=!0):(this.current=i,this.velocity=r)}}class Ts{constructor(e,s,r,i,o,n){this.index=e,this.lastVisit=Date.now(),this.sideEffect=new I;const c=P(s,u=>u[e]||{width:0,height:0}),l=w([c,r],([u,d])=>(d.width-u.width)/2),a=w([o,n],([u,d])=>(u[e]||0)-d),h=document.createElement("div");h.className="page-renderer-page",h.dataset.index=`${e}`;const p=document.createElement("img");p.className="page-renderer-page-img",h.appendChild(p),this.sideEffect.addDisposer([w([c,i]).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}")`),p.width=u.width,p.height=u.height,p.src=u.src}),w([l,a,i]).subscribe(([u,d,g])=>{h.style.transform=`translate(${u*g}px, ${d*g}px)`})]),this.$page=h}destroy(){this.sideEffect.flushAll(),this.$page.remove()}}const Ns=window.requestIdleCallback||(t=>window.setTimeout(t,5e3)),As=window.cancelIdleCallback||window.clearTimeout;class Ps{constructor(e,s,r,i,o){this.pages$=e,this.pagesSize$=s,this.scale$=r,this.pagesYs$=i,this.pagesScrollTop$=o,this.els=new Map,this.maxElCount=200,this.gcTimer=null,this.gc=()=>{var n;if(this.gcTimer=null,this.els.size>this.maxElCount){const c=[...this.els.values()].sort((l,a)=>a.lastVisit-l.lastVisit);for(let l=Math.floor(this.maxElCount/4);l<c.length;l++)(n=this.els.get(c[l].index))==null||n.destroy(),this.els.delete(c[l].index)}}}getEl(e){let s=this.els.get(e);return s||(s=new Ts(e,this.pages$,this.pagesSize$,this.scale$,this.pagesYs$,this.pagesScrollTop$),this.els.set(e,s)),s.lastVisit=Date.now(),this.els.size>this.maxElCount&&this.gcTimer===null&&(this.gcTimer=Ns(this.gc)),s}destroy(){this.els.forEach(e=>e.destroy()),this.els.clear(),this.gcTimer!==null&&(As(this.gcTimer),this.gcTimer=null)}}class Vs{constructor({pagesScrollTop$:e,containerRect$:s,pages$:r,pagesSize$:i}){this.sideEffect=new I,r=P(r,d=>d.map(g=>{if(g.thumbnail)return g;try{const f=new URL(g.src);return f.searchParams.set("x-oss-process","image/resize,l_50"),{...g,thumbnail:f.toString()}}catch(f){return console.error(f),g}}));const o=P(r,d=>{const g=Array(d.length);for(let f=0;f<d.length;f++)g[f]=f>0?g[f-1]+d[f-1].height:0;return g}),n=P(r,d=>{let g=1/0;for(let f=d.length-1;f>=0;f--)d[f].height<=g&&(g=d[f].height);return g}),c=w([e,o,r],([d,g,f])=>{for(let v=0;v<g.length;v++)if(g[v]+f[v].height-d>=.001)return v;return g.length-1}),l=w([s,i],([d,g])=>d.width/g.width||1),a=w([r,s,n,l],([d,g,f,v])=>y(Math.ceil(g.height/v/f/2),1,d.length));ht(this,{pagesScrollTop:e,containerRect:s,pages:r,pagesSize:i,pagesIndex:c,pagesYs:o,pagesMinHeight:n,scale:l}),this.pageElManager=new Ps(r,i,l,o,e),this.$pages=this.renderPages();const h=new S(!1);this.sideEffect.addDisposer(h.subscribe(d=>this.$pages.classList.toggle("is-hwa",d)));const p=()=>h.setValue(!1),u=()=>{this.sideEffect.setTimeout(p,1e3,"turn-off-hwa"),h.setValue(!0)};this.sideEffect.addDisposer(w([c,a,r]).subscribe(([d,g,f])=>{u();const v=Math.max(d-g,0),oe=Math.min(d+g,f.length-1);for(let E=0;E<this.$pages.children.length;E++){const A=this.$pages.children[E],ae=Number(A.dataset.index);ae>=v&&ae<=oe||(A.remove(),E--)}for(let E=v;E<=oe;E++){const A=this.pageElManager.getEl(E);A.$page.parentElement!==this.$pages&&this.$pages.appendChild(A.$page)}}))}renderPages(){const e=document.createElement("div");return e.className="page-renderer-pages-container",this.sideEffect.addDisposer(this._containerRect$.subscribe(s=>{e.style.width=`${s.width}px`,e.style.height=`${s.height}px`}),"render-pages-size"),e}destroy(){this.sideEffect.flushAll(),this.$pages.remove(),this.pageElManager.destroy()}}const zs=30;class Os{constructor({pagesScrollTop$:e,containerRect$:s,stageRect$:r,pagesSize$:i,readonly$:o,scrollbarMinHeight:n=zs,wrapClassName:c,onDragScroll:l}){this.sideEffect=new I,this.scrolling$=new S(!1),this.pagesScrollTop$=e,this.containerRect$=s,this.stageRect$=r,this.pagesSize$=i,this.scrollbarMinHeight=n,this.readonly$=o,this.wrapClassName=c,this.onDragScroll=l,this.scrollbarHeight$=w([s,r,i],([a,h,p])=>y(h.height/(h.width/p.width*p.height)*a.height,n,a.height)),this.scrollTop$=w([s,r,i,this.scrollbarHeight$,this.pagesScrollTop$],([a,h,p,u,d])=>y(d/(p.height-p.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(r=>{e.style.height=`${r}px`}),this.scrollTop$.subscribe(r=>{this.scrolling$.setValue(!0),this.sideEffect.setTimeout(()=>this.scrolling$.setValue(!1),100,"reset-scrolling");const i=()=>e.style.transform=`translateY(${r}px)`;window.requestAnimationFrame?window.requestAnimationFrame(i):i()}),this.scrolling$.subscribe(r=>{e.classList.toggle(this.wrapClassName("scrolling"),r)})]);const s=r=>{if(!r.isPrimary||this.readonly$.value||r.button!=null&&r.button!==0)return;Je(r);const i=this.wrapClassName("scrollbar-dragging");e.classList.toggle(i,!0);const o=this.pagesScrollTop$.value,{clientY:n}=fe(r),c=a=>{if(!a.isPrimary||this.readonly$.value)return;const{clientY:h}=fe(a),p=h-n;Math.abs(p)>0&&this.onDragScroll&&this.onDragScroll(o+p/this.containerRect$.value.height*this.pagesSize$.value.height)},l=a=>{!a.isPrimary||(e.classList.toggle(i,!1),window.removeEventListener("pointermove",c,!0),window.removeEventListener("pointerup",l,!0),window.removeEventListener("pointercancel",l,!0))};window.addEventListener("pointermove",c,!0),window.addEventListener("pointerup",l,!0),window.addEventListener("pointercancel",l,!0)};return this.sideEffect.addEventListener(e,"pointerdown",s),e}}class Ms{constructor({whiteboard:e,readonly$:s,box:r,pages:i,pagesScrollTop:o=0,onUserScroll:n}){this.sideEffect=new I,this.userScrolling=!1,this.whiteboard=e,this.readonly$=s,this.box=r,this.pages=i,this.onUserScroll=n;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 l=new S(i);this.pagesScrollTop$=new S(o),this.pagesSize$=P(l,a=>{let h=0,p=0;for(let u=a.length-1;u>=0;u--){const d=a[u];d.width>h&&(h=d.width),p+=d.height}return{width:Math.max(1,h),height:Math.max(1,p)}},{compare:Xe}),this.pageRenderer=new Vs({pagesScrollTop$:this.pagesScrollTop$,containerRect$:r._stageRect$,pages$:l,pagesSize$:this.pagesSize$}),this.viewer=new qe({readonly$:s,pagesIndex$:this.pageRenderer._pagesIndex$,box:r,pages:i,playable:!1}),this.sideEffect.addDisposer([this.viewer.events.on("next",()=>{this.userScrollByPercent(.8)}),this.viewer.events.on("back",()=>{this.userScrollByPercent(-.8)})]),this.scrollbar=new Os({pagesScrollTop$:this.pagesScrollTop$,containerRect$:r._bodyRect$,stageRect$:r._stageRect$,pagesSize$:this.pagesSize$,readonly$:s,wrapClassName:this.wrapClassName.bind(this),onDragScroll:a=>{this.pageScrollTo(a),this.debounceOnUserScroll()}}),this.pageScrollStepper=new Ds({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 s=this.whiteboard.view.size.height/2/this.pageRenderer.scale;this.whiteboard.view.moveCamera({centerY:y(e+s,s,this.pagesSize$.value.height-s),animationMode:"immediately"})}userScrollToPageIndex(e){var s;if(e=y(e,0,this.pages.length-1),!this.readonly$.value&&!Number.isNaN(e)){const r=this.pageRenderer.pagesYs[e];r>=0&&((s=this.onUserScroll)==null||s.call(this,r+5/this.pageRenderer.scale))}}userScrollByPercent(e){var s;this.readonly$.value||(s=this.onUserScroll)==null||s.call(this,y(this.pageRenderer.pagesScrollTop+this.pageRenderer.containerRect.height/this.pageRenderer.scale*y(e,-1,1),0,this.pageRenderer.pagesSize.height-this.pageRenderer.containerRect.height/this.pageRenderer.scale))}setupScrollListener(){this.sideEffect.addEventListener(this.box.$main,"wheel",e=>{Je(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=s=>{const{width:r,height:i}=this.whiteboard.view.size;if(r<=0||i<=0)return;const o=s.centerY-this.pageRenderer.containerRect.height/this.pageRenderer.scale/2;this.pagesScrollTop$.setValue(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:s,height:r}=this.pagesSize$.value;this.whiteboard.view.moveCameraToContain({originX:0,originY:this.pageRenderer.pagesScrollTop,width:s,height:e.height/this.pageRenderer.scale,animationMode:"immediately"}),this.whiteboard.view.setCameraBound({damping:1,maxContentMode:()=>this.pageRenderer.scale,minContentMode:()=>this.pageRenderer.scale,centerX:s/2,centerY:r/2,width:s,height:r})}),"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 Rs{constructor({readonly$:e,context:s,whiteboard:r,box:i,pages:o}){this.sideEffect=new I,this.context=s,this.whiteboard=r,this.box=i,this.pages=o;const n=new S(s.displayer.state.sceneState.index||0);this.pagesIndex$=n,this.sideEffect.add(()=>{const c=l=>{this.jumpToPage(l.index)};return this.context.emitter.on("sceneStateChange",c),()=>this.context.emitter.off("sceneStateChange",c)}),this.viewer=new qe({readonly$:e,pagesIndex$:n,box:i,pages: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(n.subscribe((c,l)=>{var p,u;if(e.value)return;const a=this.context.getInitScenePath(),h=(u=(p=this.context.getScenes())==null?void 0:p[c])==null?void 0:u.name;if(a&&h&&this.context.setScenePath(`${a}/${h}`),l){const d=this.context.room;if(d){const g=d.state.globalState.__pptState;d.setGlobalState({__pptState:g&&{uuid:g.uuid,pageIndex:c,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,s=!1){this.pagesIndex$.setValue(y(e,0,this.pages.length-1),s)}render(){var s;this.box.mountStage(document.createElement("div")),this.sideEffect.addEventListener(window,"keydown",r=>{var i;if(this.box.focus)switch(r.key){case"ArrowUp":case"ArrowLeft":{this.prevPage();break}case"ArrowRight":case"ArrowDown":{(i=this.context.room)==null||i.pptNextStep();break}}});const e=(s=this.whiteboard.view.divElement)==null?void 0:s.parentElement;e&&this.sideEffect.addEventListener(e,"click",r=>{var o;const i=this.context.room;if(i&&i.state.memberState.currentApplianceName==="clicker"){for(let n=r.target;n;n=n.parentElement)if((o=n.classList)!=null&&o.contains("ppt-event-source"))return;i.pptNextStep()}})}wrapClassName(e){return"netless-app-docs-viewer-dynamic-"+e}}const Hs="DocsViewer",Bs={kind:Hs,setup(t){const e=t.box,s=t.getScenes();if(!s)throw new Error("[Docs Viewer]: scenes not found.");const r=new I,i=s.map(({ppt:n})=>n?{width:n.width,height:n.height,src:n.src,thumbnail:n.previewURL}:null).filter(n=>Boolean(n));if(i.length<=0)throw new Error("[Docs Viewer]: empty scenes.");e.mountStyles(Ke);const o=new S(!t.isWritable);r.addDisposer(t.emitter.on("writableChange",n=>{o.setValue(!n)})),i[0].src.startsWith("ppt")?Fs(r,t,e,i,o):Us(r,t,e,i,o),r.addDisposer(t.emitter.on("destroy",()=>{r.flushAll()}))}};function Us(t,e,s,r,i){const o=e.createWhiteBoardView({syncCamera:!1});t.addDisposer(i.subscribe(l=>{o.view.disableCameraTransform=l}));const n=e.createStorage("static-docs-viewer",{pagesScrollTop:0}),c=new Ms({whiteboard:o,readonly$:i,box:s,pages:r,pagesScrollTop:n.state.pagesScrollTop,onUserScroll:l=>{e.isWritable&&n.setState({pagesScrollTop:l})}});t.addDisposer(()=>c.destroy()),t.addDisposer(n.addStateChangedListener(l=>{l.pagesScrollTop&&c.syncPageScrollTop(l.pagesScrollTop.newValue||0)})),t.addDisposer(w([s._maximized$,s._managerStageRect$,s._intrinsicSize$,c.pagesSize$,c.pageRenderer._pagesMinHeight$],([l,a,h,p,u])=>l?Math.max(u/p.width*(2/5),a.height/a.width):h.height/h.width*(a.height/a.width)).subscribe(l=>{s.setStageRatio(l)}))}function Fs(t,e,s,r,i){const o=e.createWhiteBoardView();o.view.disableCameraTransform=!0;const n=new Rs({context:e,whiteboard:o,box:s,pages:r,readonly$:i});t.addDisposer(()=>n.destroy());const c=new S({width:r[0].width,height:r[0].height},{compare:Xe});if(t.addDisposer(n.pagesIndex$.subscribe(l=>{const a=r[l];a&&c.setValue({width:a.width,height:a.height})})),t.addDisposer(c.subscribe(l=>{i.value||o.setBaseRect(l)})),e.isAddApp){const l=t.add(()=>{const a=({width:h,height:p})=>{if(r.length>0&&s.state!=="maximized"){const{width:u,height:d}=r[0],f=d/u*h-p;f!==0&&e.isWritable&&e.emitter.emit("setBoxSize",{width:s.intrinsicWidth,height:s.intrinsicHeight+f/s.rootRect.height})}t.remove(l)};return o.view.callbacks.once("onSizeUpdated",a),()=>o.view.callbacks.off("onSizeUpdated",a)})}}exports.default=Bs; | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=require("side-effect-manager"),w=require("value-enhancer"),M=require("vanilla-lazyload"),L=require("remitter"),z=o=>o&&typeof o=="object"&&"default"in o?o:{default:o},V=z(M);const A=`.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 R{constructor({namespace:e,pages$:t,sideEffect:s,readonly$:r,events:l,wrapClassName:n,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=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 V.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 _(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 I(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 B(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 H(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 U(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 F{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",_(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",I(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",H(this.namespace),U(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",B(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=c=>`${this.namespace}-${c}`,this.namespace="netless-app-docs-viewer",this.sideEffect=new S.SideEffectManager,this.events=new L.Remitter;const a=new w.Val(l);w.withValueEnhancer(this,{pages:a}),this.preview=new R({pages$:a,readonly$:e,pagesIndex$:t,root:s,sideEffect:this.sideEffect,events:this.events,namespace:this.namespace,wrapClassName:this.wrapClassName}),this.footer=new F({pages$:a,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 Y{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 W{constructor(e,t,s,r,l,n){this.index=e,this.lastVisit=Date.now(),this.sideEffect=new S.SideEffectManager;const a=w.derive(t,u=>u[e]||{width:0,height:0}),c=w.combine([a,s],([u,p])=>(p.width-u.width)/2),i=w.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([w.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}),w.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 W(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 S.SideEffectManager,s=w.derive(s,p=>p.map(g=>{if(g.thumbnail)return g;try{const f=new URL(g.src);return f.searchParams.set("x-oss-process","image/resize,l_50"),{...g,thumbnail:f.toString()}}catch(f){return console.error(f),g}}));const l=w.derive(s,p=>{const g=Array(p.length);for(let f=0;f<p.length;f++)g[f]=f>0?g[f-1]+p[f-1].height:0;return g}),n=w.derive(s,p=>{let g=1/0;for(let f=p.length-1;f>=0;f--)p[f].height<=g&&(g=p[f].height);return g}),a=w.combine([e,l,s],([p,g,f])=>{for(let m=0;m<g.length;m++)if(g[m]+f[m].height-p>=.001)return m;return g.length-1}),c=w.combine([t,r],([p,g])=>p.width/g.width||1),i=w.combine([s,t,n,c],([p,g,f,m])=>b(Math.ceil(g.height/m/f/2),1,p.length));w.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 w.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(w.combine([a,i,s]).subscribe(([p,g,f])=>{u();const m=Math.max(p-g,0),E=Math.min(p+g,f.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 T{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 w.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$=w.combine([t,s,r],([i,h,d])=>b(h.height/(h.width/d.width*d.height)*i.height,n,i.height)),this.scrollTop$=w.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 w.Val(r);this.pagesScrollTop$=new w.Val(l),this.pagesSize$=w.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 P({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:r,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 Y({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)}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 w.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: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",D={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(A);const l=new w.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(w.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 w.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],f=p/u*h-d;f!==0&&e.isWritable&&e.emitter.emit("setBoxSize",{width:t.intrinsicWidth,height:t.intrinsicHeight+f/t.rootRect.height})}o.remove(c)};return l.view.callbacks.once("onSizeUpdated",i),()=>l.view.callbacks.off("onSizeUpdated",i)})}}exports.DocsViewer=y;exports.NetlessAppDocsViewer=D;exports.PageRenderer=P;exports.ScrollBar=T;exports.default=D; | ||
//# sourceMappingURL=main.js.map |
@@ -19,3 +19,5 @@ import type { ReadonlyVal } from "value-enhancer"; | ||
destroy(): void; | ||
private schedule; | ||
private cancelSchedule; | ||
private gc; | ||
} |
{ | ||
"name": "@netless/app-docs-viewer", | ||
"version": "0.3.3", | ||
"version": "1.0.0-canary.0", | ||
"description": "Netless App Docs Viewer", | ||
@@ -19,10 +19,7 @@ "repository": "netless-io/netless-app", | ||
"dependencies": { | ||
"remitter": "^0.2.3", | ||
"remitter": "^0.2.7", | ||
"side-effect-manager": "^1.1.3", | ||
"value-enhancer": "^1.3.2", | ||
"vanilla-lazyload": "^17.8.2" | ||
}, | ||
"devDependencies": { | ||
"@netless/app-shared": "0.1.2", | ||
"side-effect-manager": "^1.1.1" | ||
}, | ||
"scripts": { | ||
@@ -29,0 +26,0 @@ "types": "cross-env NODE_ENV=production tsc --declaration --emitDeclarationOnly --outDir dist", |
@@ -9,4 +9,4 @@ ## @netless/app-docs-viewer | ||
### Licence | ||
### License | ||
MIT @ [netless](https://github.com/netless-io) |
@@ -1,3 +0,1 @@ | ||
import type { ReadonlyTeleBox } from "@netless/window-manager"; | ||
import { SideEffectManager } from "side-effect-manager"; | ||
@@ -22,3 +20,4 @@ import { withValueEnhancer, type ReadonlyVal, Val, type ValEnhancedResult } from "value-enhancer"; | ||
pages?: DocsViewerPage[]; | ||
box: ReadonlyTeleBox; | ||
previewRoot: HTMLElement; | ||
footerRoot: HTMLElement; | ||
playable: boolean; | ||
@@ -28,3 +27,10 @@ } | ||
export class DocsViewer { | ||
public constructor({ readonly$, pagesIndex$, box, pages = [], playable }: DocsViewerConfig) { | ||
public constructor({ | ||
readonly$, | ||
pagesIndex$, | ||
previewRoot, | ||
footerRoot, | ||
pages = [], | ||
playable, | ||
}: DocsViewerConfig) { | ||
const pages$ = new Val(pages); | ||
@@ -40,3 +46,3 @@ | ||
pagesIndex$, | ||
root: box.$body, | ||
root: previewRoot, | ||
sideEffect: this.sideEffect, | ||
@@ -53,3 +59,3 @@ events: this.events, | ||
pagesIndex$, | ||
root: box.$footer, | ||
root: footerRoot, | ||
namespace: this.namespace, | ||
@@ -56,0 +62,0 @@ sideEffect: this.sideEffect, |
@@ -45,3 +45,4 @@ import type { | ||
pagesIndex$, | ||
box, | ||
previewRoot: box.$body, | ||
footerRoot: box.$footer, | ||
pages, | ||
@@ -48,0 +49,0 @@ playable: true, |
229
src/index.ts
@@ -1,225 +0,8 @@ | ||
import styles from "./style.scss?inline"; | ||
import "./style.scss"; | ||
import type { NetlessApp, AppContext, ReadonlyTeleBox } from "@netless/window-manager"; | ||
import type { Size } from "white-web-sdk"; | ||
import { StaticDocsViewer } from "./StaticDocsViewer"; | ||
import type { DocsViewerPage } from "./DocsViewer"; | ||
import { DynamicDocsViewer } from "./DynamicDocsViewer"; | ||
import { kind } from "./constants"; | ||
import { SideEffectManager } from "side-effect-manager"; | ||
import type { ReadonlyVal } from "value-enhancer"; | ||
import { combine, Val } from "value-enhancer"; | ||
import { sameSize } from "./utils/helpers"; | ||
export * from "./app-docs-viewer"; | ||
export * from "./DocsViewer"; | ||
export * from "./PageRenderer"; | ||
export * from "./ScrollBar"; | ||
export type { DocsViewerPage } from "./DocsViewer"; | ||
export interface NetlessAppStaticDocsViewerAttributes { | ||
/** ScrollTop base on the real page size */ | ||
pageScrollTop?: number; | ||
} | ||
export interface NetlessAppDynamicDocsViewerAttributes {} | ||
const NetlessAppDocsViewer: NetlessApp< | ||
NetlessAppStaticDocsViewerAttributes | NetlessAppDynamicDocsViewerAttributes | ||
> = { | ||
kind, | ||
setup(context) { | ||
const box = context.box; | ||
const scenes = context.getScenes(); | ||
if (!scenes) { | ||
throw new Error("[Docs Viewer]: scenes not found."); | ||
} | ||
const sideEffect = new SideEffectManager(); | ||
const pages = scenes | ||
.map(({ ppt }): DocsViewerPage | null => | ||
ppt | ||
? { | ||
width: ppt.width, | ||
height: ppt.height, | ||
src: ppt.src, | ||
thumbnail: ppt.previewURL, | ||
} | ||
: null | ||
) | ||
.filter((page): page is DocsViewerPage => Boolean(page)); | ||
if (pages.length <= 0) { | ||
throw new Error("[Docs Viewer]: empty scenes."); | ||
} | ||
box.mountStyles(styles); | ||
const readonly$ = new Val(!context.isWritable); | ||
sideEffect.addDisposer( | ||
context.emitter.on("writableChange", isWritable => { | ||
readonly$.setValue(!isWritable); | ||
}) | ||
); | ||
if (pages[0].src.startsWith("ppt")) { | ||
setupDynamicDocsViewer( | ||
sideEffect, | ||
context as AppContext<NetlessAppDynamicDocsViewerAttributes>, | ||
box, | ||
pages, | ||
readonly$ | ||
); | ||
} else { | ||
setupStaticDocsViewer( | ||
sideEffect, | ||
context as AppContext<NetlessAppStaticDocsViewerAttributes>, | ||
box, | ||
pages, | ||
readonly$ | ||
); | ||
} | ||
sideEffect.addDisposer( | ||
context.emitter.on("destroy", () => { | ||
sideEffect.flushAll(); | ||
}) | ||
); | ||
}, | ||
}; | ||
export default NetlessAppDocsViewer; | ||
function setupStaticDocsViewer( | ||
sideEffect: SideEffectManager, | ||
context: AppContext<NetlessAppStaticDocsViewerAttributes>, | ||
box: ReadonlyTeleBox, | ||
pages: DocsViewerPage[], | ||
readonly$: Val<boolean> | ||
): void { | ||
const whiteboard = context.createWhiteBoardView({ syncCamera: false }); | ||
sideEffect.addDisposer( | ||
readonly$.subscribe(readonly => { | ||
whiteboard.view.disableCameraTransform = readonly; | ||
}) | ||
); | ||
const storage = context.createStorage("static-docs-viewer", { pagesScrollTop: 0 }); | ||
const staticDocsViewer = new StaticDocsViewer({ | ||
whiteboard, | ||
readonly$, | ||
box, | ||
pages, | ||
pagesScrollTop: storage.state.pagesScrollTop, | ||
onUserScroll: pagesScrollTop => { | ||
if (context.isWritable) { | ||
storage.setState({ pagesScrollTop }); | ||
} | ||
}, | ||
}); | ||
sideEffect.addDisposer(() => staticDocsViewer.destroy()); | ||
sideEffect.addDisposer( | ||
storage.addStateChangedListener(diff => { | ||
if (diff.pagesScrollTop) { | ||
staticDocsViewer.syncPageScrollTop(diff.pagesScrollTop.newValue || 0); | ||
} | ||
}) | ||
); | ||
// ensure stage top-bottom will always touch box content area | ||
sideEffect.addDisposer( | ||
combine( | ||
[ | ||
box._maximized$, | ||
box._managerStageRect$, | ||
box._intrinsicSize$, | ||
staticDocsViewer.pagesSize$, | ||
staticDocsViewer.pageRenderer._pagesMinHeight$, | ||
], | ||
([maximized, managerStageRect, size, pagesSize, pagesMinHeight]) => | ||
maximized | ||
? Math.max( | ||
(pagesMinHeight / pagesSize.width) * (2 / 5), | ||
managerStageRect.height / managerStageRect.width | ||
) | ||
: (size.height / size.width) * (managerStageRect.height / managerStageRect.width) | ||
).subscribe(ratio => { | ||
box.setStageRatio(ratio); | ||
}) | ||
); | ||
if (import.meta.env.DEV) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any).staticDocsViewer = staticDocsViewer; | ||
} | ||
} | ||
function setupDynamicDocsViewer( | ||
sideEffect: SideEffectManager, | ||
context: AppContext<NetlessAppDynamicDocsViewerAttributes>, | ||
box: ReadonlyTeleBox, | ||
pages: DocsViewerPage[], | ||
readonly$: ReadonlyVal<boolean> | ||
): void { | ||
const whiteboard = context.createWhiteBoardView(); | ||
whiteboard.view.disableCameraTransform = true; | ||
const dynamicDocsViewer = new DynamicDocsViewer({ | ||
context, | ||
whiteboard, | ||
box, | ||
pages, | ||
readonly$, | ||
}); | ||
sideEffect.addDisposer(() => dynamicDocsViewer.destroy()); | ||
const whiteboardBaseRect$ = new Val( | ||
{ width: pages[0].width, height: pages[0].height }, | ||
{ compare: sameSize } | ||
); | ||
sideEffect.addDisposer( | ||
dynamicDocsViewer.pagesIndex$.subscribe(pageIndex => { | ||
const page = pages[pageIndex]; | ||
if (page) { | ||
whiteboardBaseRect$.setValue({ width: page.width, height: page.height }); | ||
} | ||
}) | ||
); | ||
sideEffect.addDisposer( | ||
whiteboardBaseRect$.subscribe(rect => { | ||
if (!readonly$.value) { | ||
whiteboard.setBaseRect(rect); | ||
} | ||
}) | ||
); | ||
if (context.isAddApp) { | ||
const disposerID = sideEffect.add(() => { | ||
const handler = ({ width: contentWidth, height: contentHeight }: Size) => { | ||
if (pages.length > 0 && box.state !== "maximized") { | ||
const { width: pageWidth, height: pageHeight } = pages[0]; | ||
const preferHeight = (pageHeight / pageWidth) * contentWidth; | ||
const diff = preferHeight - contentHeight; | ||
if (diff !== 0 && context.isWritable) { | ||
context.emitter.emit("setBoxSize", { | ||
width: box.intrinsicWidth, | ||
height: box.intrinsicHeight + diff / box.rootRect.height, | ||
}); | ||
} | ||
} | ||
sideEffect.remove(disposerID); | ||
}; | ||
whiteboard.view.callbacks.once("onSizeUpdated", handler); | ||
return () => whiteboard.view.callbacks.off("onSizeUpdated", handler); | ||
}); | ||
} | ||
if (import.meta.env.DEV) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any).dynamicDocsViewer = dynamicDocsViewer; | ||
} | ||
} | ||
export { NetlessAppDocsViewer as default } from "./app-docs-viewer"; |
@@ -5,7 +5,2 @@ import type { ReadonlyVal } from "value-enhancer"; | ||
const schedule: (handler: () => void) => number = | ||
window.requestIdleCallback || ((handler: () => void) => window.setTimeout(handler, 5000)); | ||
const cancelSchedule = window.cancelIdleCallback || window.clearTimeout; | ||
export class PageElManager { | ||
@@ -23,4 +18,9 @@ els = new Map<number, PageEl>(); | ||
private pagesScrollTop$: ReadonlyVal<number> | ||
) {} | ||
) { | ||
this.schedule = | ||
window.requestIdleCallback || ((handler: () => void) => window.setTimeout(handler, 5000)); | ||
this.cancelSchedule = window.cancelIdleCallback || window.clearTimeout; | ||
} | ||
getEl(index: number): PageEl { | ||
@@ -42,3 +42,3 @@ let el = this.els.get(index); | ||
if (this.els.size > this.maxElCount && this.gcTimer === null) { | ||
this.gcTimer = schedule(this.gc); | ||
this.gcTimer = this.schedule(this.gc); | ||
} | ||
@@ -53,3 +53,3 @@ | ||
if (this.gcTimer !== null) { | ||
cancelSchedule(this.gcTimer); | ||
this.cancelSchedule(this.gcTimer); | ||
this.gcTimer = null; | ||
@@ -59,2 +59,5 @@ } | ||
private schedule: (handler: () => void) => number; | ||
private cancelSchedule: (handle: number) => void; | ||
private gc = () => { | ||
@@ -61,0 +64,0 @@ this.gcTimer = null; |
@@ -84,3 +84,4 @@ import type { AnimationMode, ReadonlyTeleBox, WhiteBoardView } from "@netless/window-manager"; | ||
pagesIndex$: this.pageRenderer._pagesIndex$, | ||
box, | ||
previewRoot: box.$body, | ||
footerRoot: box.$footer, | ||
pages, | ||
@@ -87,0 +88,0 @@ playable: false, |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
64
441925
4
3017
3
+ Addedside-effect-manager@^1.1.3
+ Addedside-effect-manager@1.2.2(transitive)
Updatedremitter@^0.2.7