filens-preview 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/all-in-one/filens.js +306 -306
- package/dist/split/chunks/{archive-DMapcEqq.js → archive-haip2eOP.js} +1 -1
- package/dist/split/chunks/{browser-video-session-CGI8FpX_.js → browser-video-session-C_14e_mG.js} +1 -1
- package/dist/split/chunks/{cad-BvXJNqHR.js → cad-5oTkbaDV.js} +1 -1
- package/dist/split/chunks/{core-BLayEJn5.js → core-EjELrtsP.js} +2 -2
- package/dist/split/chunks/{diagram-DlpgioZ9.js → diagram-BRcdlitF.js} +1 -1
- package/dist/split/chunks/{docx-Sii3GNtE.js → docx-I39iDYpR.js} +1 -1
- package/dist/split/chunks/{ebook-CLCQfska.js → ebook-BRfadCGl.js} +1 -1
- package/dist/split/chunks/{index-DI_GyFX1.js → index-C4jdVbDq.js} +1 -1
- package/dist/split/chunks/{index-BPK_cNTp.js → index-DkF8PBGR.js} +1 -1
- package/dist/split/chunks/{iwork-Datv3D5d.js → iwork-DXq9Adf7.js} +1 -1
- package/dist/split/chunks/{media-runtime-tb-Q4Sah.js → media-runtime-B6322raw.js} +1 -1
- package/dist/split/chunks/{mindmap-B_GYpiFO.js → mindmap-CyR3TRfx.js} +1 -1
- package/dist/split/chunks/model3d-BEt6INTt.js +55 -0
- package/dist/split/chunks/{panorama-CIdiLIwD.js → panorama-ChsqnvWC.js} +1 -1
- package/dist/split/chunks/vendor-C1aIdQ-w.js +4115 -0
- package/dist/split/chunks/{xlsx-D2NFYc3n.js → xlsx-CITQo0Od.js} +1 -1
- package/dist/split/filens.js +1 -1
- package/package.json +1 -1
- package/dist/split/chunks/model3d-BsIQNF2D.js +0 -55
- package/dist/split/chunks/vendor-CBCxJuSg.js +0 -4115
|
@@ -1 +1 @@
|
|
|
1
|
-
var _=Object.defineProperty;var R=(e,t,r)=>t in e?_(e,t,{enumerable:true,configurable:true,writable:true,value:r}):e[t]=r;var f=(e,t,r)=>R(e,typeof t!="symbol"?t+"":t,r);import{c as G,b as Y}from"./core-BLayEJn5.js";import{J as W,i as H,a as j,s as q}from"./vendor-CBCxJuSg.js";const J=[{extensions:["drawio","dio","vdx","vsdx"],family:"diagram",driverId:"diagram",targetFormat:"diagram",contentTypes:["application/vnd.jgraph.mxfile","application/vnd.visio"]}],F=new Set(["drawio","dio","vdx","vsdx"]),w=96,p="http://www.w3.org/2000/svg",S=36,Z=120,K=60,Q="#ffffff",tt="#9db3d1",V="#1f2937",et="#6b7f99",rt={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"};class it{constructor(t,r={}){f(this,"listeners",{loading:new Set,rendered:new Set,error:new Set,statechange:new Set,warnings:new Set});f(this,"root");f(this,"scale");f(this,"fitMode");f(this,"canvasSize");f(this,"resizeObserver");f(this,"document",null);f(this,"loadGeneration",0);f(this,"loadController");f(this,"removeAbortListener");f(this,"pageIndex",0);f(this,"selectedElementId");f(this,"state");this.host=t,this.scale=r.initialScale??1,this.fitMode=r.fit??"contain",this.root=document.createElement("div"),this.root.className="diagramv-preview",this.host.replaceChildren(this.root),this.state={loading:false,error:null,family:"diagram",warnings:[],capabilities:{zoom:true,fit:true,pan:true,paged:true,search:true,fullscreen:true,metadata:true,download:true},scale:this.scale,pageIndex:0,pageCount:0},typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>{if(this.fitMode==="none")return;const i=this.scale;this.applyScale(),this.scale!==i&&this.emit("statechange",this.state)}))}async load(t,r){var a,c,d;const i=++this.loadGeneration;(a=this.loadController)==null||a.abort(),(c=this.removeAbortListener)==null||c.call(this),this.releaseDocument();const n=new AbortController;this.loadController=n;const s=r.signal,o=()=>{n.abort(),i===this.loadGeneration&&(this.releaseDocument(),this.state.loading=false,this.emit("statechange",this.state))};s==null||s.addEventListener("abort",o,{once:true}),this.removeAbortListener=()=>s==null?void 0:s.removeEventListener("abort",o),this.state={...this.state,loading:true,error:null,title:r.descriptor.name,warnings:[],selectedElementId:void 0},this.emit("loading",this.state),this.emit("statechange",this.state);try{s!=null&&s.aborted&&n.abort(),m(n.signal);const l=O(((d=r.route)==null?void 0:d.sourceFormat)??r.descriptor.extension);if(!F.has(l))throw new Error(`Diagram preview currently supports diagrams.net drawio/dio and Visio VDX/VSDX files, got ${l||"unknown"}.`);const h={...r,signal:n.signal};let u;if(l==="vsdx"){const b=await Tt(t,h);m(n.signal),u=await st(b,h)}else{const b=await It(t,h);m(n.signal),u=l==="vdx"?ct(b):nt(b)}if(i!==this.loadGeneration)return;m(n.signal),this.document=u,this.pageIndex=0,this.selectedElementId=void 0,this.state={...this.state,loading:false,error:null,title:this.document.title??r.descriptor.name,pageIndex:0,pageCount:this.document.pages.length,selectedElementId:void 0,scale:this.scale},this.render(),Y(this.root,{getScale:()=>this.state.scale,setScale:b=>this.setScale(b),signal:n.signal}),this.emit("rendered",this.state),this.emit("statechange",this.state)}catch(l){if(i!==this.loadGeneration)return;this.releaseDocument(),this.state.loading=false,m(n.signal);const h=l instanceof Error?l:new Error(String(l));throw this.state.error=h.message,this.emit("error",h),this.emit("statechange",this.state),h}}destroy(){var t,r;this.loadGeneration++,(t=this.loadController)==null||t.abort(),(r=this.removeAbortListener)==null||r.call(this),this.releaseDocument(),this.state.loading=false,this.root.parentElement===this.host&&this.host.replaceChildren();for(const i of Object.values(this.listeners))i.clear()}getState(){var t;return{...this.state,warnings:[...this.state.warnings],pageIndex:this.pageIndex,pageCount:((t=this.document)==null?void 0:t.pages.length)??0,selectedElementId:this.selectedElementId}}on(t,r){return this.listeners[t].add(r),()=>{this.listeners[t].delete(r)}}setScale(t){Number.isFinite(t)&&(this.scale=Math.max(.25,Math.min(t,3)),this.fitMode="none",this.state.scale=this.scale,this.applyScale(),this.emit("statechange",this.state))}fit(t="contain"){this.fitMode=t,t==="none"&&(this.scale=1),this.applyScale(),this.state.scale=this.scale,this.root.scrollLeft=0,this.root.scrollTop=0,this.emit("statechange",this.state)}pan(t,r){this.root.scrollLeft+=t,this.root.scrollTop+=r}async fullscreen(){var t,r;await((r=(t=this.root).requestFullscreen)==null?void 0:r.call(t))}goToPage(t){if(!this.document||!Number.isInteger(t))return;const r=Math.max(0,Math.min(t,this.document.pages.length-1));r!==this.pageIndex&&(this.pageIndex=r,this.selectedElementId=void 0,this.state.pageIndex=this.pageIndex,this.state.selectedElementId=void 0,this.root.scrollTop=0,this.root.scrollLeft=0,this.render(),this.emit("statechange",this.state))}next(){this.goToPage(this.pageIndex+1)}prev(){this.goToPage(this.pageIndex-1)}render(){var o,a,c,d;const t=(o=this.document)==null?void 0:o.pages[this.pageIndex];if(!t){this.root.replaceChildren();return}const r=St(t);this.canvasSize=r;const i=document.createElement("div");i.className="diagramv-summary",i.textContent=`${t.name} - ${t.nodes.length} node${t.nodes.length===1?"":"s"} - ${t.edges.length} edge${t.edges.length===1?"":"s"}`;const n=document.createElement("div");n.className="diagramv-canvas-wrap",n.style.width=`${r.width}px`,n.style.height=`${r.height}px`;const s=document.createElementNS(p,"svg");s.classList.add("diagramv-canvas"),s.setAttribute("viewBox",`${r.minX} ${r.minY} ${r.width} ${r.height}`),s.setAttribute("role","img"),s.setAttribute("aria-label",t.name),s.appendChild(wt()),s.append(At(t,l=>this.selectElement(l)),yt(t,l=>this.selectElement(l))),n.appendChild(s),(a=this.resizeObserver)==null||a.disconnect(),this.root.replaceChildren(i,n),this.applyScale(),(c=this.resizeObserver)==null||c.observe(this.root),(d=this.resizeObserver)==null||d.observe(i),this.selectedElementId&&this.selectElement(this.selectedElementId,false)}selectElement(t,r=true){this.selectedElementId=t,this.state.selectedElementId=t,this.root.querySelectorAll(".diagramv-node, .diagramv-edge").forEach(i=>{i.classList.toggle("is-selected",i.getAttribute("data-element-id")===t)}),r&&this.emit("statechange",this.state)}applyScale(){const t=this.root.querySelector(".diagramv-canvas-wrap");if(!(!t||!this.canvasSize)){if(this.fitMode!=="none"){const r=this.root.clientWidth,i=this.root.clientHeight-this.root.firstElementChild.offsetHeight;if(r>0&&i>0){const n=r/this.canvasSize.width,s=i/this.canvasSize.height;this.scale=this.fitMode==="width"?n:this.fitMode==="height"?s:Math.min(n,s)}}this.state.scale=this.scale,t.style.width=`${this.canvasSize.width*this.scale}px`,t.style.height=`${this.canvasSize.height*this.scale}px`}}releaseDocument(){var t;(t=this.resizeObserver)==null||t.disconnect(),this.canvasSize=void 0,this.document=null,this.pageIndex=0,this.selectedElementId=void 0,this.state.pageIndex=0,this.state.pageCount=0,this.state.selectedElementId=void 0,this.root.replaceChildren()}emit(t,r){for(const i of this.listeners[t])i(r)}}function Bt(){return{id:"diagram",family:"diagram",supports:e=>F.has(O(e)),createSession:(e,t)=>new it(e,t)}}function $t(e=G()){return[...J,...e.filter(t=>!t.extensions.some(r=>F.has(r)))]}function nt(e){var s;const t=new DOMParser().parseFromString(e,"application/xml");if(t.getElementsByTagName("parsererror")[0])throw new Error("draw.io XML is invalid.");const r={},i=Array.from(t.getElementsByTagName("*")).filter(o=>g(o)==="diagram"),n=i.length?i.map((o,a)=>P(o,a,r)):[P(t.documentElement,0,r)];if(!n.some(o=>o.nodes.length||o.edges.length))throw new Error("draw.io file does not contain supported mxCell geometry.");return{title:t.documentElement.getAttribute("name")??((s=n[0])==null?void 0:s.name),pages:n}}async function st(e,t={}){var o;m(t.signal);const r=await W.loadAsync(e);m(t.signal);const i=await ot(r,t.signal);if(m(t.signal),!i.length)throw new Error("VSDX package is missing visio/pages/page*.xml files.");const n=[],s={};for(let a=0;a<i.length;a+=1){const c=i[a],d=await c.file.async("text");m(t.signal);const l=dt(d,a,s,c.metadata);(l.nodes.length||l.edges.length)&&n.push(l)}if(!n.length)throw new Error("VSDX file does not contain supported shape geometry.");return{title:(o=n[0])==null?void 0:o.name,pages:n}}async function ot(e,t){const r=e.file(/^visio\/pages\/page\d+\.xml$/i).sort((d,l)=>d.name.localeCompare(l.name,void 0,{numeric:true})),i=e.file("visio/pages/pages.xml");if(!i)return r.map(d=>({file:d}));const n=await i.async("text");m(t);const s=new DOMParser().parseFromString(n,"application/xml");if(s.getElementsByTagName("parsererror")[0])return r.map(d=>({file:d}));const o=await at(e,t);m(t);const c=Array.from(s.getElementsByTagName("*")).filter(d=>g(d)==="page").map((d,l)=>{var E;const h=(E=Array.from(d.children).find(I=>g(I)==="rel"))==null?void 0:E.getAttribute("r:id"),u=h?o.get(h):void 0,b=u?e.file(lt(u)):r[l];if(b)return{file:b,metadata:{id:d.getAttribute("ID")??void 0,name:d.getAttribute("NameU")||d.getAttribute("Name")||void 0}}}).filter(Mt);return c.length?c:r.map(d=>({file:d}))}async function at(e,t){const r=new Map,i=e.file("visio/pages/_rels/pages.xml.rels");if(!i)return r;const n=await i.async("text");m(t);const s=new DOMParser().parseFromString(n,"application/xml");if(s.getElementsByTagName("parsererror")[0])return r;for(const o of Array.from(s.getElementsByTagName("*")).filter(a=>g(a)==="relationship")){const a=o.getAttribute("Id"),c=o.getAttribute("Target");a&&c&&r.set(a,c)}return r}function lt(e){const t=e.replace(/\\/g,"/").replace(/^\//,"");return t.toLowerCase().startsWith("visio/pages/")?t:`visio/pages/${t.replace(/^pages\//i,"")}`}function ct(e){var s;const t=new DOMParser().parseFromString(e,"application/xml");if(t.getElementsByTagName("parsererror")[0])throw new Error("VDX XML is invalid.");const r={legacy:true},i=Array.from(t.getElementsByTagName("*")).filter(o=>g(o)==="page"),n=i.length?i.map((o,a)=>M(o,a,r)):[M(t.documentElement,0,r)];if(!n.some(o=>o.nodes.length||o.edges.length))throw new Error("VDX file does not contain supported shape geometry.");return{title:t.documentElement.getAttribute("Name")??((s=n[0])==null?void 0:s.name),pages:n}}function dt(e,t,r,i){const n=new DOMParser().parseFromString(e,"application/xml");if(n.getElementsByTagName("parsererror")[0])throw new Error("Visio page XML is invalid.");return M(n.documentElement,t,r,i)}function M(e,t,r,i){let n;const s=[],o=[];for(const h of Array.from(e.getElementsByTagName("*"))){const u=g(h);u==="pagesheet"&&!n?n=h:u==="shape"?s.push(h):u==="connect"&&o.push(h)}const a=(y(B(n,!!r.legacy),"PageHeight")??8.5)*w,c=gt(o),d=[],l=[];for(const h of s){const u=h.getAttribute("ID")??`shape-${d.length+l.length+1}`,b=h.getAttribute("Type")??"",E=B(h,!!r.legacy),I=y(E,"BeginX"),U=y(E,"EndX"),x=c.get(u),k=L(ut(h),r);if(b==="Shape"&&I==null&&U==null&&!(x!=null&&x.source)&&!(x!=null&&x.target)){const T=ht(E,u,k,a);T.width>0&&T.height>0&&d.push(T);continue}if(b==="Foreign"||b==="Group")continue;const v=mt(E,u,k,a,x);(v.points.length||v.source||v.target)&&l.push(v)}return{id:(i==null?void 0:i.id)??`visio-page-${t+1}`,name:(i==null?void 0:i.name)||e.getAttribute("NameU")||e.getAttribute("Name")||`Page ${t+1}`,nodes:d,edges:l}}function ht(e,t,r,i){const n=(y(e,"PinX")??0)*w,s=(y(e,"PinY")??0)*w,o=Math.max(1,(y(e,"Width")??1)*w),a=Math.max(1,(y(e,"Height")??.5)*w);return{id:t,label:r,x:n-o/2,y:i-s-a/2,width:o,height:a,style:ft(e)}}function mt(e,t,r,i,n={}){const s=y(e,"PinX")??0,o=y(e,"PinY")??0,a=(y(e,"BeginX")??s)*w,c=i-(y(e,"BeginY")??o)*w,d=(y(e,"EndX")??s)*w,l=i-(y(e,"EndY")??o)*w;return{id:t,label:r,source:n.source,target:n.target,points:n.source||n.target?[]:[[a,c],[d,l]],style:"endArrow=block;strokeColor=#6b7f99"}}function gt(e){const t=new Map;for(const r of e){const i=r.getAttribute("FromSheet"),n=r.getAttribute("ToSheet");if(!i||!n)continue;const s=r.getAttribute("FromCell")??"",o=t.get(i)??{};/begin/i.test(s)?o.source=n:/end/i.test(s)&&(o.target=n),t.set(i,o)}return t}function B(e,t){const r=new Map;if(!e)return r;for(const i of Array.from(e.getElementsByTagName("*"))){if(g(i)!=="cell")continue;const n=i.getAttribute("N");n!=null&&!r.has(n)&&r.set(n,i.getAttribute("V"))}if(t){for(const i of Array.from(e.children))if(["xform","xform1d","pageprops","fill","line"].includes(g(i)))for(const n of Array.from(i.children))r.has(n.localName)||r.set(n.localName,n.textContent)}return r}function y(e,t){const r=Number(e.get(t));return Number.isFinite(r)?r:void 0}function ut(e){const t=Array.from(e.children).find(r=>g(r)==="text");return(t==null?void 0:t.textContent)??""}function ft(e){const t=$(e.get("FillForegnd")??void 0),r=$(e.get("LineColor")??void 0);return[t?`fillColor=${t}`:"",r?`strokeColor=${r}`:"","rounded=1"].filter(Boolean).join(";")}function $(e){var i;if(!e||e==="THEMEGUARD(RGB(255,255,255))")return;const t=(i=/^#?[0-9a-f]{6}$/i.exec(e.trim()))==null?void 0:i[0];if(t)return t.startsWith("#")?t:`#${t}`;const r=/RGB\((\d+),\s*(\d+),\s*(\d+)\)/i.exec(e);if(r)return`#${[r[1],r[2],r[3]].map(n=>Number(n).toString(16).padStart(2,"0")).join("")}`}function P(e,t,r){const i=pt(e),n=g(i)==="mxgraphmodel"?i:Array.from(i.getElementsByTagName("*")).find(c=>g(c)==="mxgraphmodel"),s=n?Array.from(n.getElementsByTagName("*")).filter(c=>g(c)==="mxcell"):[],o=[],a=[];for(const c of s){const d=c.getAttribute("id")??`cell-${o.length+a.length+1}`,l=N(c,"mxgeometry")[0];if(c.getAttribute("vertex")==="1"&&l){o.push({id:d,label:L(c.getAttribute("value")??"",r),x:A(l,"x"),y:A(l,"y"),width:A(l,"width",Z),height:A(l,"height",K),style:c.getAttribute("style")??void 0});continue}c.getAttribute("edge")==="1"&&a.push({id:d,label:L(c.getAttribute("value")??"",r),source:c.getAttribute("source")??void 0,target:c.getAttribute("target")??void 0,points:l?vt(l):[],style:c.getAttribute("style")??void 0})}return{id:e.getAttribute("id")??`page-${t+1}`,name:e.getAttribute("name")||`Page ${t+1}`,nodes:o,edges:a}}function pt(e){var r;if(g(e)!=="diagram"||Array.from(e.getElementsByTagName("*")).some(i=>g(i)==="mxgraphmodel"))return e;const t=(r=e.textContent)==null?void 0:r.trim();if(!t)return e;try{const i=bt(t),n=new DOMParser().parseFromString(i,"application/xml");return n.getElementsByTagName("parsererror")[0]?e:n.documentElement}catch{return e}}function bt(e){const t=e.replace(/\s+/g,""),r=typeof atob=="function"?atob(t):Buffer.from(t,"base64").toString("binary"),i=Uint8Array.from(r,o=>o.charCodeAt(0));let n;try{n=H(i)}catch{n=j(i)}const s=q(n).replace(/\+/g,"%20");return decodeURIComponent(s)}function yt(e,t){const r=document.createElementNS(p,"g");r.classList.add("diagramv-nodes");for(const i of e.nodes){const n=document.createElementNS(p,"g");n.classList.add("diagramv-node"),n.setAttribute("data-element-id",i.id),n.setAttribute("tabindex","0"),n.setAttribute("role","button"),n.setAttribute("aria-label",i.label||i.id),n.addEventListener("click",()=>t(i.id)),n.addEventListener("keydown",a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),t(i.id))});const s=X(i.style),o=Et(i,s);if(n.appendChild(o),i.label){const a=document.createElementNS(p,"text");a.setAttribute("x",String(i.x+i.width/2)),a.setAttribute("y",String(i.y+i.height/2+5)),a.setAttribute("fill",s.fontColor??V),a.setAttribute("font-size",s.fontSize??"13"),a.textContent=z(i.label),n.appendChild(a)}r.appendChild(n)}return r}function wt(){const e=document.createElementNS(p,"defs"),t=document.createElementNS(p,"marker");t.setAttribute("id","diagramv-arrow-end"),t.setAttribute("viewBox","0 0 10 10"),t.setAttribute("refX","9"),t.setAttribute("refY","5"),t.setAttribute("markerWidth","7"),t.setAttribute("markerHeight","7"),t.setAttribute("orient","auto-start-reverse");const r=document.createElementNS(p,"path");return r.setAttribute("d","M 0 0 L 10 5 L 0 10 z"),r.setAttribute("fill","context-stroke"),t.appendChild(r),e.appendChild(t),e}function At(e,t){const r=document.createElementNS(p,"g");r.classList.add("diagramv-edges");const i=new Map(e.nodes.map(n=>[n.id,n]));for(const n of e.edges){const s=document.createElementNS(p,"g");s.classList.add("diagramv-edge"),s.setAttribute("data-element-id",n.id),s.setAttribute("tabindex","0"),s.setAttribute("role","button"),s.setAttribute("aria-label",n.label||n.id),s.addEventListener("click",()=>t(n.id)),s.addEventListener("keydown",d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),t(n.id))});const o=xt(n,i),a=X(n.style),c=document.createElementNS(p,"polyline");if(c.setAttribute("points",o.map(([d,l])=>`${d},${l}`).join(" ")),c.setAttribute("stroke",a.strokeColor??et),c.setAttribute("stroke-width",a.strokeWidth??"2"),a.dashed==="1"&&c.setAttribute("stroke-dasharray","8 5"),a.endArrow&&a.endArrow!=="none"&&c.setAttribute("marker-end","url(#diagramv-arrow-end)"),s.appendChild(c),n.label&&o.length){const d=o[Math.floor(o.length/2)],l=document.createElementNS(p,"text");l.setAttribute("x",String(d[0]+8)),l.setAttribute("y",String(d[1]-8)),l.setAttribute("fill",a.fontColor??V),l.setAttribute("font-size",a.fontSize??"13"),l.textContent=z(n.label),s.appendChild(l)}r.appendChild(s)}return r}function Et(e,t){const r=t.shape??"";if(r==="ellipse"||t.ellipse==="1"){const n=document.createElementNS(p,"ellipse");return n.setAttribute("cx",String(e.x+e.width/2)),n.setAttribute("cy",String(e.y+e.height/2)),n.setAttribute("rx",String(e.width/2)),n.setAttribute("ry",String(e.height/2)),C(n,t),n}if(r==="rhombus"||t.rhombus==="1"){const n=document.createElementNS(p,"polygon");return n.setAttribute("points",[[e.x+e.width/2,e.y],[e.x+e.width,e.y+e.height/2],[e.x+e.width/2,e.y+e.height],[e.x,e.y+e.height/2]].map(([s,o])=>`${s},${o}`).join(" ")),C(n,t),n}const i=document.createElementNS(p,"rect");return i.setAttribute("x",String(e.x)),i.setAttribute("y",String(e.y)),i.setAttribute("width",String(e.width)),i.setAttribute("height",String(e.height)),i.setAttribute("rx",t.rounded==="1"?"8":"3"),C(i,t),i}function C(e,t){e.setAttribute("fill",t.fillColor==="none"?"transparent":t.fillColor??Q),e.setAttribute("stroke",t.strokeColor==="none"?"transparent":t.strokeColor??tt),e.setAttribute("stroke-width",t.strokeWidth??"1.4"),t.dashed==="1"&&e.setAttribute("stroke-dasharray","8 5")}function xt(e,t){const r=[],i=e.source?t.get(e.source):void 0,n=e.target?t.get(e.target):void 0;return i&&r.push([i.x+i.width,i.y+i.height/2]),r.push(...e.points),n&&r.push([n.x,n.y+n.height/2]),r.length>=2?r:i&&n?[[i.x+i.width,i.y+i.height/2],[n.x,n.y+n.height/2]]:r}function vt(e){const t=[];for(const i of N(e,"mxpoint"))t.push([A(i,"x"),A(i,"y")]);const r=N(e,"array")[0];if(r)for(const i of N(r,"mxpoint"))t.push([A(i,"x"),A(i,"y")]);return t}function St(e){let t=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const s of e.nodes)t=Math.min(t,s.x),r=Math.min(r,s.y),i=Math.max(i,s.x+s.width),n=Math.max(n,s.y+s.height);for(const s of e.edges)for(const[o,a]of s.points)t=Math.min(t,o),r=Math.min(r,a),i=Math.max(i,o),n=Math.max(n,a);return!Number.isFinite(t)||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(n)?{minX:0,minY:0,width:360,height:260}:(t-=S,r-=S,i+=S,n+=S,{minX:t,minY:r,width:Math.max(360,i-t),height:Math.max(260,n-r)})}function N(e,t){return Array.from(e.children).filter(r=>g(r)===t)}function g(e){return e.localName.toLowerCase()}function A(e,t,r=0){const i=e.getAttribute(t),n=i===null?NaN:Number(i);return Number.isFinite(n)?n:r}function L(e,t){return Nt(e.replace(/<[^>]+>/g," "),t).replace(/\s+/g," ").trim()}function X(e){const t={};for(const r of String(e??"").split(";")){if(!r)continue;const[i,...n]=r.split("="),s=i==null?void 0:i.trim();s&&(t[s]=n.length?n.join("=").trim():"1")}return t}function Nt(e,t){if(!e.includes("&")&&!e.includes("\0"))return e;if(!e.includes("\0")&&!/&(?!amp;|lt;|gt;|quot;|apos;)/.test(e))return e.replace(/&(amp|lt|gt|quot|apos);/g,(i,n)=>rt[n]);const r=t.labelDecoder??(t.labelDecoder=document.createElement("textarea"));return r.innerHTML=e,r.value}function z(e){return e.length>34?`${e.slice(0,31)}...`:e}async function It(e,t){if(m(t.signal),typeof e=="string"){if(e.trimStart().toLowerCase().startsWith("data:"))return Ct(e);const r=await fetch(e,{signal:t.signal});if(m(t.signal),!r.ok)throw new Error(`Failed to load diagram source: ${r.status} ${r.statusText}`.trim());return r.text()}return e instanceof Blob?e.text():ArrayBuffer.isView(e)?new TextDecoder().decode(e):e instanceof ArrayBuffer?new TextDecoder().decode(e):String(e)}async function Tt(e,t){if(m(t.signal),typeof e=="string"){if(e.trimStart().toLowerCase().startsWith("data:"))return D(Dt(e));const r=await fetch(e,{signal:t.signal});if(m(t.signal),!r.ok)throw new Error(`Failed to load diagram source: ${r.status} ${r.statusText}`.trim());return r.arrayBuffer()}if(e instanceof Blob)return e.arrayBuffer();if(ArrayBuffer.isView(e)){const r=new Uint8Array(e.byteLength);return r.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),D(r)}return e instanceof ArrayBuffer?e:D(new TextEncoder().encode(String(e)))}function m(e){if(e!=null&&e.aborted)throw new DOMException("The operation was aborted.","AbortError")}function Ct(e){const t=e.indexOf(",");if(t<0)return e;const r=e.slice(0,t).toLowerCase(),i=e.slice(t+1);return r.endsWith(";base64")?new TextDecoder().decode(Uint8Array.from(atob(i),n=>n.charCodeAt(0))):decodeURIComponent(i)}function Dt(e){const t=e.indexOf(",");if(t<0)return new TextEncoder().encode(e);const r=e.slice(0,t).toLowerCase(),i=e.slice(t+1);return r.endsWith(";base64")?Uint8Array.from(atob(i),n=>n.charCodeAt(0)):new TextEncoder().encode(decodeURIComponent(i))}function D(e){const t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}function Mt(e){return e!==void 0}function O(e){return String(e??"").trim().replace(/^\./,"").toLowerCase()}export{$t as a,Bt as c};
|
|
1
|
+
var _=Object.defineProperty;var R=(e,t,r)=>t in e?_(e,t,{enumerable:true,configurable:true,writable:true,value:r}):e[t]=r;var f=(e,t,r)=>R(e,typeof t!="symbol"?t+"":t,r);import{c as G,b as Y}from"./core-EjELrtsP.js";import{J as W,i as H,a as j,s as q}from"./vendor-C1aIdQ-w.js";const J=[{extensions:["drawio","dio","vdx","vsdx"],family:"diagram",driverId:"diagram",targetFormat:"diagram",contentTypes:["application/vnd.jgraph.mxfile","application/vnd.visio"]}],F=new Set(["drawio","dio","vdx","vsdx"]),w=96,p="http://www.w3.org/2000/svg",S=36,Z=120,K=60,Q="#ffffff",tt="#9db3d1",V="#1f2937",et="#6b7f99",rt={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"};class it{constructor(t,r={}){f(this,"listeners",{loading:new Set,rendered:new Set,error:new Set,statechange:new Set,warnings:new Set});f(this,"root");f(this,"scale");f(this,"fitMode");f(this,"canvasSize");f(this,"resizeObserver");f(this,"document",null);f(this,"loadGeneration",0);f(this,"loadController");f(this,"removeAbortListener");f(this,"pageIndex",0);f(this,"selectedElementId");f(this,"state");this.host=t,this.scale=r.initialScale??1,this.fitMode=r.fit??"contain",this.root=document.createElement("div"),this.root.className="diagramv-preview",this.host.replaceChildren(this.root),this.state={loading:false,error:null,family:"diagram",warnings:[],capabilities:{zoom:true,fit:true,pan:true,paged:true,search:true,fullscreen:true,metadata:true,download:true},scale:this.scale,pageIndex:0,pageCount:0},typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>{if(this.fitMode==="none")return;const i=this.scale;this.applyScale(),this.scale!==i&&this.emit("statechange",this.state)}))}async load(t,r){var a,c,d;const i=++this.loadGeneration;(a=this.loadController)==null||a.abort(),(c=this.removeAbortListener)==null||c.call(this),this.releaseDocument();const n=new AbortController;this.loadController=n;const s=r.signal,o=()=>{n.abort(),i===this.loadGeneration&&(this.releaseDocument(),this.state.loading=false,this.emit("statechange",this.state))};s==null||s.addEventListener("abort",o,{once:true}),this.removeAbortListener=()=>s==null?void 0:s.removeEventListener("abort",o),this.state={...this.state,loading:true,error:null,title:r.descriptor.name,warnings:[],selectedElementId:void 0},this.emit("loading",this.state),this.emit("statechange",this.state);try{s!=null&&s.aborted&&n.abort(),m(n.signal);const l=O(((d=r.route)==null?void 0:d.sourceFormat)??r.descriptor.extension);if(!F.has(l))throw new Error(`Diagram preview currently supports diagrams.net drawio/dio and Visio VDX/VSDX files, got ${l||"unknown"}.`);const h={...r,signal:n.signal};let u;if(l==="vsdx"){const b=await Tt(t,h);m(n.signal),u=await st(b,h)}else{const b=await It(t,h);m(n.signal),u=l==="vdx"?ct(b):nt(b)}if(i!==this.loadGeneration)return;m(n.signal),this.document=u,this.pageIndex=0,this.selectedElementId=void 0,this.state={...this.state,loading:false,error:null,title:this.document.title??r.descriptor.name,pageIndex:0,pageCount:this.document.pages.length,selectedElementId:void 0,scale:this.scale},this.render(),Y(this.root,{getScale:()=>this.state.scale,setScale:b=>this.setScale(b),signal:n.signal}),this.emit("rendered",this.state),this.emit("statechange",this.state)}catch(l){if(i!==this.loadGeneration)return;this.releaseDocument(),this.state.loading=false,m(n.signal);const h=l instanceof Error?l:new Error(String(l));throw this.state.error=h.message,this.emit("error",h),this.emit("statechange",this.state),h}}destroy(){var t,r;this.loadGeneration++,(t=this.loadController)==null||t.abort(),(r=this.removeAbortListener)==null||r.call(this),this.releaseDocument(),this.state.loading=false,this.root.parentElement===this.host&&this.host.replaceChildren();for(const i of Object.values(this.listeners))i.clear()}getState(){var t;return{...this.state,warnings:[...this.state.warnings],pageIndex:this.pageIndex,pageCount:((t=this.document)==null?void 0:t.pages.length)??0,selectedElementId:this.selectedElementId}}on(t,r){return this.listeners[t].add(r),()=>{this.listeners[t].delete(r)}}setScale(t){Number.isFinite(t)&&(this.scale=Math.max(.25,Math.min(t,3)),this.fitMode="none",this.state.scale=this.scale,this.applyScale(),this.emit("statechange",this.state))}fit(t="contain"){this.fitMode=t,t==="none"&&(this.scale=1),this.applyScale(),this.state.scale=this.scale,this.root.scrollLeft=0,this.root.scrollTop=0,this.emit("statechange",this.state)}pan(t,r){this.root.scrollLeft+=t,this.root.scrollTop+=r}async fullscreen(){var t,r;await((r=(t=this.root).requestFullscreen)==null?void 0:r.call(t))}goToPage(t){if(!this.document||!Number.isInteger(t))return;const r=Math.max(0,Math.min(t,this.document.pages.length-1));r!==this.pageIndex&&(this.pageIndex=r,this.selectedElementId=void 0,this.state.pageIndex=this.pageIndex,this.state.selectedElementId=void 0,this.root.scrollTop=0,this.root.scrollLeft=0,this.render(),this.emit("statechange",this.state))}next(){this.goToPage(this.pageIndex+1)}prev(){this.goToPage(this.pageIndex-1)}render(){var o,a,c,d;const t=(o=this.document)==null?void 0:o.pages[this.pageIndex];if(!t){this.root.replaceChildren();return}const r=St(t);this.canvasSize=r;const i=document.createElement("div");i.className="diagramv-summary",i.textContent=`${t.name} - ${t.nodes.length} node${t.nodes.length===1?"":"s"} - ${t.edges.length} edge${t.edges.length===1?"":"s"}`;const n=document.createElement("div");n.className="diagramv-canvas-wrap",n.style.width=`${r.width}px`,n.style.height=`${r.height}px`;const s=document.createElementNS(p,"svg");s.classList.add("diagramv-canvas"),s.setAttribute("viewBox",`${r.minX} ${r.minY} ${r.width} ${r.height}`),s.setAttribute("role","img"),s.setAttribute("aria-label",t.name),s.appendChild(wt()),s.append(At(t,l=>this.selectElement(l)),yt(t,l=>this.selectElement(l))),n.appendChild(s),(a=this.resizeObserver)==null||a.disconnect(),this.root.replaceChildren(i,n),this.applyScale(),(c=this.resizeObserver)==null||c.observe(this.root),(d=this.resizeObserver)==null||d.observe(i),this.selectedElementId&&this.selectElement(this.selectedElementId,false)}selectElement(t,r=true){this.selectedElementId=t,this.state.selectedElementId=t,this.root.querySelectorAll(".diagramv-node, .diagramv-edge").forEach(i=>{i.classList.toggle("is-selected",i.getAttribute("data-element-id")===t)}),r&&this.emit("statechange",this.state)}applyScale(){const t=this.root.querySelector(".diagramv-canvas-wrap");if(!(!t||!this.canvasSize)){if(this.fitMode!=="none"){const r=this.root.clientWidth,i=this.root.clientHeight-this.root.firstElementChild.offsetHeight;if(r>0&&i>0){const n=r/this.canvasSize.width,s=i/this.canvasSize.height;this.scale=this.fitMode==="width"?n:this.fitMode==="height"?s:Math.min(n,s)}}this.state.scale=this.scale,t.style.width=`${this.canvasSize.width*this.scale}px`,t.style.height=`${this.canvasSize.height*this.scale}px`}}releaseDocument(){var t;(t=this.resizeObserver)==null||t.disconnect(),this.canvasSize=void 0,this.document=null,this.pageIndex=0,this.selectedElementId=void 0,this.state.pageIndex=0,this.state.pageCount=0,this.state.selectedElementId=void 0,this.root.replaceChildren()}emit(t,r){for(const i of this.listeners[t])i(r)}}function Bt(){return{id:"diagram",family:"diagram",supports:e=>F.has(O(e)),createSession:(e,t)=>new it(e,t)}}function $t(e=G()){return[...J,...e.filter(t=>!t.extensions.some(r=>F.has(r)))]}function nt(e){var s;const t=new DOMParser().parseFromString(e,"application/xml");if(t.getElementsByTagName("parsererror")[0])throw new Error("draw.io XML is invalid.");const r={},i=Array.from(t.getElementsByTagName("*")).filter(o=>g(o)==="diagram"),n=i.length?i.map((o,a)=>P(o,a,r)):[P(t.documentElement,0,r)];if(!n.some(o=>o.nodes.length||o.edges.length))throw new Error("draw.io file does not contain supported mxCell geometry.");return{title:t.documentElement.getAttribute("name")??((s=n[0])==null?void 0:s.name),pages:n}}async function st(e,t={}){var o;m(t.signal);const r=await W.loadAsync(e);m(t.signal);const i=await ot(r,t.signal);if(m(t.signal),!i.length)throw new Error("VSDX package is missing visio/pages/page*.xml files.");const n=[],s={};for(let a=0;a<i.length;a+=1){const c=i[a],d=await c.file.async("text");m(t.signal);const l=dt(d,a,s,c.metadata);(l.nodes.length||l.edges.length)&&n.push(l)}if(!n.length)throw new Error("VSDX file does not contain supported shape geometry.");return{title:(o=n[0])==null?void 0:o.name,pages:n}}async function ot(e,t){const r=e.file(/^visio\/pages\/page\d+\.xml$/i).sort((d,l)=>d.name.localeCompare(l.name,void 0,{numeric:true})),i=e.file("visio/pages/pages.xml");if(!i)return r.map(d=>({file:d}));const n=await i.async("text");m(t);const s=new DOMParser().parseFromString(n,"application/xml");if(s.getElementsByTagName("parsererror")[0])return r.map(d=>({file:d}));const o=await at(e,t);m(t);const c=Array.from(s.getElementsByTagName("*")).filter(d=>g(d)==="page").map((d,l)=>{var E;const h=(E=Array.from(d.children).find(I=>g(I)==="rel"))==null?void 0:E.getAttribute("r:id"),u=h?o.get(h):void 0,b=u?e.file(lt(u)):r[l];if(b)return{file:b,metadata:{id:d.getAttribute("ID")??void 0,name:d.getAttribute("NameU")||d.getAttribute("Name")||void 0}}}).filter(Mt);return c.length?c:r.map(d=>({file:d}))}async function at(e,t){const r=new Map,i=e.file("visio/pages/_rels/pages.xml.rels");if(!i)return r;const n=await i.async("text");m(t);const s=new DOMParser().parseFromString(n,"application/xml");if(s.getElementsByTagName("parsererror")[0])return r;for(const o of Array.from(s.getElementsByTagName("*")).filter(a=>g(a)==="relationship")){const a=o.getAttribute("Id"),c=o.getAttribute("Target");a&&c&&r.set(a,c)}return r}function lt(e){const t=e.replace(/\\/g,"/").replace(/^\//,"");return t.toLowerCase().startsWith("visio/pages/")?t:`visio/pages/${t.replace(/^pages\//i,"")}`}function ct(e){var s;const t=new DOMParser().parseFromString(e,"application/xml");if(t.getElementsByTagName("parsererror")[0])throw new Error("VDX XML is invalid.");const r={legacy:true},i=Array.from(t.getElementsByTagName("*")).filter(o=>g(o)==="page"),n=i.length?i.map((o,a)=>M(o,a,r)):[M(t.documentElement,0,r)];if(!n.some(o=>o.nodes.length||o.edges.length))throw new Error("VDX file does not contain supported shape geometry.");return{title:t.documentElement.getAttribute("Name")??((s=n[0])==null?void 0:s.name),pages:n}}function dt(e,t,r,i){const n=new DOMParser().parseFromString(e,"application/xml");if(n.getElementsByTagName("parsererror")[0])throw new Error("Visio page XML is invalid.");return M(n.documentElement,t,r,i)}function M(e,t,r,i){let n;const s=[],o=[];for(const h of Array.from(e.getElementsByTagName("*"))){const u=g(h);u==="pagesheet"&&!n?n=h:u==="shape"?s.push(h):u==="connect"&&o.push(h)}const a=(y(B(n,!!r.legacy),"PageHeight")??8.5)*w,c=gt(o),d=[],l=[];for(const h of s){const u=h.getAttribute("ID")??`shape-${d.length+l.length+1}`,b=h.getAttribute("Type")??"",E=B(h,!!r.legacy),I=y(E,"BeginX"),U=y(E,"EndX"),x=c.get(u),k=L(ut(h),r);if(b==="Shape"&&I==null&&U==null&&!(x!=null&&x.source)&&!(x!=null&&x.target)){const T=ht(E,u,k,a);T.width>0&&T.height>0&&d.push(T);continue}if(b==="Foreign"||b==="Group")continue;const v=mt(E,u,k,a,x);(v.points.length||v.source||v.target)&&l.push(v)}return{id:(i==null?void 0:i.id)??`visio-page-${t+1}`,name:(i==null?void 0:i.name)||e.getAttribute("NameU")||e.getAttribute("Name")||`Page ${t+1}`,nodes:d,edges:l}}function ht(e,t,r,i){const n=(y(e,"PinX")??0)*w,s=(y(e,"PinY")??0)*w,o=Math.max(1,(y(e,"Width")??1)*w),a=Math.max(1,(y(e,"Height")??.5)*w);return{id:t,label:r,x:n-o/2,y:i-s-a/2,width:o,height:a,style:ft(e)}}function mt(e,t,r,i,n={}){const s=y(e,"PinX")??0,o=y(e,"PinY")??0,a=(y(e,"BeginX")??s)*w,c=i-(y(e,"BeginY")??o)*w,d=(y(e,"EndX")??s)*w,l=i-(y(e,"EndY")??o)*w;return{id:t,label:r,source:n.source,target:n.target,points:n.source||n.target?[]:[[a,c],[d,l]],style:"endArrow=block;strokeColor=#6b7f99"}}function gt(e){const t=new Map;for(const r of e){const i=r.getAttribute("FromSheet"),n=r.getAttribute("ToSheet");if(!i||!n)continue;const s=r.getAttribute("FromCell")??"",o=t.get(i)??{};/begin/i.test(s)?o.source=n:/end/i.test(s)&&(o.target=n),t.set(i,o)}return t}function B(e,t){const r=new Map;if(!e)return r;for(const i of Array.from(e.getElementsByTagName("*"))){if(g(i)!=="cell")continue;const n=i.getAttribute("N");n!=null&&!r.has(n)&&r.set(n,i.getAttribute("V"))}if(t){for(const i of Array.from(e.children))if(["xform","xform1d","pageprops","fill","line"].includes(g(i)))for(const n of Array.from(i.children))r.has(n.localName)||r.set(n.localName,n.textContent)}return r}function y(e,t){const r=Number(e.get(t));return Number.isFinite(r)?r:void 0}function ut(e){const t=Array.from(e.children).find(r=>g(r)==="text");return(t==null?void 0:t.textContent)??""}function ft(e){const t=$(e.get("FillForegnd")??void 0),r=$(e.get("LineColor")??void 0);return[t?`fillColor=${t}`:"",r?`strokeColor=${r}`:"","rounded=1"].filter(Boolean).join(";")}function $(e){var i;if(!e||e==="THEMEGUARD(RGB(255,255,255))")return;const t=(i=/^#?[0-9a-f]{6}$/i.exec(e.trim()))==null?void 0:i[0];if(t)return t.startsWith("#")?t:`#${t}`;const r=/RGB\((\d+),\s*(\d+),\s*(\d+)\)/i.exec(e);if(r)return`#${[r[1],r[2],r[3]].map(n=>Number(n).toString(16).padStart(2,"0")).join("")}`}function P(e,t,r){const i=pt(e),n=g(i)==="mxgraphmodel"?i:Array.from(i.getElementsByTagName("*")).find(c=>g(c)==="mxgraphmodel"),s=n?Array.from(n.getElementsByTagName("*")).filter(c=>g(c)==="mxcell"):[],o=[],a=[];for(const c of s){const d=c.getAttribute("id")??`cell-${o.length+a.length+1}`,l=N(c,"mxgeometry")[0];if(c.getAttribute("vertex")==="1"&&l){o.push({id:d,label:L(c.getAttribute("value")??"",r),x:A(l,"x"),y:A(l,"y"),width:A(l,"width",Z),height:A(l,"height",K),style:c.getAttribute("style")??void 0});continue}c.getAttribute("edge")==="1"&&a.push({id:d,label:L(c.getAttribute("value")??"",r),source:c.getAttribute("source")??void 0,target:c.getAttribute("target")??void 0,points:l?vt(l):[],style:c.getAttribute("style")??void 0})}return{id:e.getAttribute("id")??`page-${t+1}`,name:e.getAttribute("name")||`Page ${t+1}`,nodes:o,edges:a}}function pt(e){var r;if(g(e)!=="diagram"||Array.from(e.getElementsByTagName("*")).some(i=>g(i)==="mxgraphmodel"))return e;const t=(r=e.textContent)==null?void 0:r.trim();if(!t)return e;try{const i=bt(t),n=new DOMParser().parseFromString(i,"application/xml");return n.getElementsByTagName("parsererror")[0]?e:n.documentElement}catch{return e}}function bt(e){const t=e.replace(/\s+/g,""),r=typeof atob=="function"?atob(t):Buffer.from(t,"base64").toString("binary"),i=Uint8Array.from(r,o=>o.charCodeAt(0));let n;try{n=H(i)}catch{n=j(i)}const s=q(n).replace(/\+/g,"%20");return decodeURIComponent(s)}function yt(e,t){const r=document.createElementNS(p,"g");r.classList.add("diagramv-nodes");for(const i of e.nodes){const n=document.createElementNS(p,"g");n.classList.add("diagramv-node"),n.setAttribute("data-element-id",i.id),n.setAttribute("tabindex","0"),n.setAttribute("role","button"),n.setAttribute("aria-label",i.label||i.id),n.addEventListener("click",()=>t(i.id)),n.addEventListener("keydown",a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),t(i.id))});const s=X(i.style),o=Et(i,s);if(n.appendChild(o),i.label){const a=document.createElementNS(p,"text");a.setAttribute("x",String(i.x+i.width/2)),a.setAttribute("y",String(i.y+i.height/2+5)),a.setAttribute("fill",s.fontColor??V),a.setAttribute("font-size",s.fontSize??"13"),a.textContent=z(i.label),n.appendChild(a)}r.appendChild(n)}return r}function wt(){const e=document.createElementNS(p,"defs"),t=document.createElementNS(p,"marker");t.setAttribute("id","diagramv-arrow-end"),t.setAttribute("viewBox","0 0 10 10"),t.setAttribute("refX","9"),t.setAttribute("refY","5"),t.setAttribute("markerWidth","7"),t.setAttribute("markerHeight","7"),t.setAttribute("orient","auto-start-reverse");const r=document.createElementNS(p,"path");return r.setAttribute("d","M 0 0 L 10 5 L 0 10 z"),r.setAttribute("fill","context-stroke"),t.appendChild(r),e.appendChild(t),e}function At(e,t){const r=document.createElementNS(p,"g");r.classList.add("diagramv-edges");const i=new Map(e.nodes.map(n=>[n.id,n]));for(const n of e.edges){const s=document.createElementNS(p,"g");s.classList.add("diagramv-edge"),s.setAttribute("data-element-id",n.id),s.setAttribute("tabindex","0"),s.setAttribute("role","button"),s.setAttribute("aria-label",n.label||n.id),s.addEventListener("click",()=>t(n.id)),s.addEventListener("keydown",d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),t(n.id))});const o=xt(n,i),a=X(n.style),c=document.createElementNS(p,"polyline");if(c.setAttribute("points",o.map(([d,l])=>`${d},${l}`).join(" ")),c.setAttribute("stroke",a.strokeColor??et),c.setAttribute("stroke-width",a.strokeWidth??"2"),a.dashed==="1"&&c.setAttribute("stroke-dasharray","8 5"),a.endArrow&&a.endArrow!=="none"&&c.setAttribute("marker-end","url(#diagramv-arrow-end)"),s.appendChild(c),n.label&&o.length){const d=o[Math.floor(o.length/2)],l=document.createElementNS(p,"text");l.setAttribute("x",String(d[0]+8)),l.setAttribute("y",String(d[1]-8)),l.setAttribute("fill",a.fontColor??V),l.setAttribute("font-size",a.fontSize??"13"),l.textContent=z(n.label),s.appendChild(l)}r.appendChild(s)}return r}function Et(e,t){const r=t.shape??"";if(r==="ellipse"||t.ellipse==="1"){const n=document.createElementNS(p,"ellipse");return n.setAttribute("cx",String(e.x+e.width/2)),n.setAttribute("cy",String(e.y+e.height/2)),n.setAttribute("rx",String(e.width/2)),n.setAttribute("ry",String(e.height/2)),C(n,t),n}if(r==="rhombus"||t.rhombus==="1"){const n=document.createElementNS(p,"polygon");return n.setAttribute("points",[[e.x+e.width/2,e.y],[e.x+e.width,e.y+e.height/2],[e.x+e.width/2,e.y+e.height],[e.x,e.y+e.height/2]].map(([s,o])=>`${s},${o}`).join(" ")),C(n,t),n}const i=document.createElementNS(p,"rect");return i.setAttribute("x",String(e.x)),i.setAttribute("y",String(e.y)),i.setAttribute("width",String(e.width)),i.setAttribute("height",String(e.height)),i.setAttribute("rx",t.rounded==="1"?"8":"3"),C(i,t),i}function C(e,t){e.setAttribute("fill",t.fillColor==="none"?"transparent":t.fillColor??Q),e.setAttribute("stroke",t.strokeColor==="none"?"transparent":t.strokeColor??tt),e.setAttribute("stroke-width",t.strokeWidth??"1.4"),t.dashed==="1"&&e.setAttribute("stroke-dasharray","8 5")}function xt(e,t){const r=[],i=e.source?t.get(e.source):void 0,n=e.target?t.get(e.target):void 0;return i&&r.push([i.x+i.width,i.y+i.height/2]),r.push(...e.points),n&&r.push([n.x,n.y+n.height/2]),r.length>=2?r:i&&n?[[i.x+i.width,i.y+i.height/2],[n.x,n.y+n.height/2]]:r}function vt(e){const t=[];for(const i of N(e,"mxpoint"))t.push([A(i,"x"),A(i,"y")]);const r=N(e,"array")[0];if(r)for(const i of N(r,"mxpoint"))t.push([A(i,"x"),A(i,"y")]);return t}function St(e){let t=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const s of e.nodes)t=Math.min(t,s.x),r=Math.min(r,s.y),i=Math.max(i,s.x+s.width),n=Math.max(n,s.y+s.height);for(const s of e.edges)for(const[o,a]of s.points)t=Math.min(t,o),r=Math.min(r,a),i=Math.max(i,o),n=Math.max(n,a);return!Number.isFinite(t)||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(n)?{minX:0,minY:0,width:360,height:260}:(t-=S,r-=S,i+=S,n+=S,{minX:t,minY:r,width:Math.max(360,i-t),height:Math.max(260,n-r)})}function N(e,t){return Array.from(e.children).filter(r=>g(r)===t)}function g(e){return e.localName.toLowerCase()}function A(e,t,r=0){const i=e.getAttribute(t),n=i===null?NaN:Number(i);return Number.isFinite(n)?n:r}function L(e,t){return Nt(e.replace(/<[^>]+>/g," "),t).replace(/\s+/g," ").trim()}function X(e){const t={};for(const r of String(e??"").split(";")){if(!r)continue;const[i,...n]=r.split("="),s=i==null?void 0:i.trim();s&&(t[s]=n.length?n.join("=").trim():"1")}return t}function Nt(e,t){if(!e.includes("&")&&!e.includes("\0"))return e;if(!e.includes("\0")&&!/&(?!amp;|lt;|gt;|quot;|apos;)/.test(e))return e.replace(/&(amp|lt|gt|quot|apos);/g,(i,n)=>rt[n]);const r=t.labelDecoder??(t.labelDecoder=document.createElement("textarea"));return r.innerHTML=e,r.value}function z(e){return e.length>34?`${e.slice(0,31)}...`:e}async function It(e,t){if(m(t.signal),typeof e=="string"){if(e.trimStart().toLowerCase().startsWith("data:"))return Ct(e);const r=await fetch(e,{signal:t.signal});if(m(t.signal),!r.ok)throw new Error(`Failed to load diagram source: ${r.status} ${r.statusText}`.trim());return r.text()}return e instanceof Blob?e.text():ArrayBuffer.isView(e)?new TextDecoder().decode(e):e instanceof ArrayBuffer?new TextDecoder().decode(e):String(e)}async function Tt(e,t){if(m(t.signal),typeof e=="string"){if(e.trimStart().toLowerCase().startsWith("data:"))return D(Dt(e));const r=await fetch(e,{signal:t.signal});if(m(t.signal),!r.ok)throw new Error(`Failed to load diagram source: ${r.status} ${r.statusText}`.trim());return r.arrayBuffer()}if(e instanceof Blob)return e.arrayBuffer();if(ArrayBuffer.isView(e)){const r=new Uint8Array(e.byteLength);return r.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),D(r)}return e instanceof ArrayBuffer?e:D(new TextEncoder().encode(String(e)))}function m(e){if(e!=null&&e.aborted)throw new DOMException("The operation was aborted.","AbortError")}function Ct(e){const t=e.indexOf(",");if(t<0)return e;const r=e.slice(0,t).toLowerCase(),i=e.slice(t+1);return r.endsWith(";base64")?new TextDecoder().decode(Uint8Array.from(atob(i),n=>n.charCodeAt(0))):decodeURIComponent(i)}function Dt(e){const t=e.indexOf(",");if(t<0)return new TextEncoder().encode(e);const r=e.slice(0,t).toLowerCase(),i=e.slice(t+1);return r.endsWith(";base64")?Uint8Array.from(atob(i),n=>n.charCodeAt(0)):new TextEncoder().encode(decodeURIComponent(i))}function D(e){const t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}function Mt(e){return e!==void 0}function O(e){return String(e??"").trim().replace(/^\./,"").toLowerCase()}export{$t as a,Bt as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var A=Object.defineProperty;var j=(o,s,t)=>s in o?A(o,s,{enumerable:true,configurable:true,writable:true,value:t}):o[s]=t;var v=(o,s,t)=>j(o,typeof s!="symbol"?s+"":s,t);import{am as B,an as T}from"./vendor-
|
|
1
|
+
var A=Object.defineProperty;var j=(o,s,t)=>s in o?A(o,s,{enumerable:true,configurable:true,writable:true,value:t}):o[s]=t;var v=(o,s,t)=>j(o,typeof s!="symbol"?s+"":s,t);import{am as B,an as T}from"./vendor-C1aIdQ-w.js";import{i as R,j as H,B as E,g as U,d as k,l as W,w as _,c as z,a as I}from"./core-EjELrtsP.js";const x=new WeakMap;async function X(o,s){var r,c;const t=new Map,n=o.fontTablePart;if(!(n!=null&&n.path)||!((r=n._package)!=null&&r.load))return t;try{const f=await n._package.load(n.path),h=(c=s.defaultView)==null?void 0:c.DOMParser;if(!f||!h)return t;const w=new h().parseFromString(f,"application/xml");if(w.getElementsByTagName("parsererror").length)return t;const d=(m,a)=>{var g;return(g=[...m.attributes].find(C=>C.localName===a))==null?void 0:g.value};for(const m of[...w.getElementsByTagNameNS("*","font")]){const a=d(m,"name");if(!a)continue;const g=C=>{const F=[...m.children].find(L=>L.localName===C);return F?d(F,"val"):void 0};t.set(a.toLowerCase(),{...R(g("family")),...H(g("panose1")),...R(void 0,g("pitch"))})}}catch{}return t}function O(o,s,t=new Map,n){var F,L,P,u;const r=new Map;for(const e of((F=o.fontTablePart)==null?void 0:F.fonts)??[])e.name&&r.set(e.name.toLowerCase(),{fontFamily:e.name,traits:{...R(e.family,e.pitch),...t.get(e.name.toLowerCase())},embedded:(L=e.embedFontRefs)!=null&&L.length?true:void 0});const c=[],f=new WeakSet,h=e=>{if(!e||typeof e!="object"||f.has(e))return;if(f.add(e),Array.isArray(e)){e.forEach(h);return}const i=e;if(typeof i["font-family"]=="string"){const l=x.get(i)??i["font-family"];x.set(i,l),c.push({values:i,stack:l});for(const p of E(l))r.has(p.toLowerCase())||r.set(p.toLowerCase(),{fontFamily:p})}for(const[l,p]of Object.entries(i))l!=="parent"&&!l.startsWith("_")&&h(p)};h((P=o.documentPart)==null?void 0:P.body),h((u=o.stylesPart)==null?void 0:u.styles);for(const e of o.parts??[])for(const i of["body","styles","domNumberings","notes","comments"])h(e[i]);const w=c.filter(({stack:e})=>!/[()]/.test(e)&&!E(e).some(i=>{var l;return(l=r.get(i.toLowerCase()))==null?void 0:l.embedded})),d=new Set(w.flatMap(({stack:e})=>E(e).map(i=>i.toLowerCase()))),m=new Map(n==null?void 0:n.references.map(e=>{var i;return[(i=e.fontFamily)==null?void 0:i.toLowerCase(),e]}));for(const[e,i]of r){const l=m.get(e);l&&d.has(e)&&r.set(e,{...i,...l})}const a=[...r.values()].filter(e=>d.has(e.fontFamily.toLowerCase())),g=[...(n?U({...n,references:a},s):k(a,s,{substitute:true})).fonts,...k([...r.values()].filter(e=>!d.has(e.fontFamily.toLowerCase())),s).fonts],C=new Map(g.map(e=>{var i;return[(i=e.fontFamily)==null?void 0:i.toLowerCase(),e.resolvedFontFamily]}));for(const{values:e,stack:i}of w){const p=E(i).map(b=>C.get(b.toLowerCase())).filter(b=>!!b);e["font-family"]=W(i,b=>{var D;return(D=r.get(b.toLowerCase()))==null?void 0:D.traits},p)}return{fonts:g,references:[...r.values()],loadingReferences:a,warnings:[...new Set([..._(g),...(n==null?void 0:n.warnings)??[]])]}}const V=[{extensions:["docx"],family:"flow",driverId:"docx",targetFormat:"docx"}];class ${constructor(s,t={}){v(this,"listeners",{loading:new Set,rendered:new Set,error:new Set,statechange:new Set,warnings:new Set});v(this,"root");v(this,"documentHost");v(this,"loadController",null);v(this,"state");v(this,"fontLoading");v(this,"fontReferences",[]);v(this,"refreshDocumentFonts");this.host=s,this.root=document.createElement("div"),this.root.className="docxv-preview",this.documentHost=document.createElement("div"),this.documentHost.className="docxv-document",this.root.replaceChildren(this.documentHost),this.host.replaceChildren(this.root),this.state={loading:false,error:null,family:"flow",warnings:[],capabilities:{search:true,print:true,download:true},scale:t.initialScale??1,scrollTop:0},this.fontLoading=I(this,s.ownerDocument,t)}async load(s,t){var d,m,a,g,C,F,L,P;this.stopLoad(),this.fontLoading.reset(t.signal,((d=t.route)==null?void 0:d.targetFormat)??t.descriptor.extension??"docx");const n=new AbortController;this.loadController=n;const r=n.signal,c=document.createElement("div");c.className="docxv-document",this.documentHost=c;let f=c;this.root.replaceChildren(c),this.root.scrollTop=0;const h=new Set,w=()=>n.abort();r.addEventListener("abort",()=>{var u;(u=t.signal)==null||u.removeEventListener("abort",w);for(const e of h)URL.revokeObjectURL(e);h.clear(),f.replaceChildren(),f.remove(),this.loadController===n&&(this.loadController=null,this.state.loading=false,this.state.fonts=[],this.state.warnings=[],this.emit("statechange",this.state))},{once:true}),(m=t.signal)==null||m.addEventListener("abort",w,{once:true}),this.state={...this.state,loading:true,error:null,title:t.descriptor.name,fonts:[],warnings:[]},this.emit("loading",this.state),this.emit("statechange",this.state);try{(a=t.signal)!=null&&a.aborted&&n.abort(),S(r);const u=await J(s,{...t,signal:r});if(r.aborted){(g=t.signal)!=null&&g.aborted&&S(r);return}const e={breakPages:true,ignoreLastRenderedPageBreak:false,className:"docx"},i=await B(u,e);if(r.aborted){(C=t.signal)!=null&&C.aborted&&S(r);return}G(i,r,h);const l=await X(i,this.host.ownerDocument);if(r.aborted){(F=t.signal)!=null&&F.aborted&&S(r);return}const p=O(i,this.host.ownerDocument,l);if(await T(i,c,void 0,e),r.aborted){(L=t.signal)!=null&&L.aborted&&S(r);return}this.state.loading=false,this.state.error=null,this.state.fonts=p.fonts,this.fontReferences=p.loadingReferences,this.state.warnings=p.warnings,this.refreshDocumentFonts=async b=>{if(r.aborted||this.loadController!==n)return;const D=O(i,this.host.ownerDocument,l,b);if(b.loaded.length||b.relayout){const y=this.host.ownerDocument.createElement("div");y.className="docxv-document",y.style.visibility="hidden",this.root.appendChild(y);try{if(await T(i,y,void 0,e),r.aborted||this.loadController!==n)return;const M=this.root.scrollTop,N=this.root.scrollLeft;y.style.visibility="",f=this.documentHost=y,this.root.replaceChildren(y),this.root.scrollTop=M,this.root.scrollLeft=N}finally{f!==y&&y.remove()}}r.aborted||this.loadController!==n||(this.fontReferences=D.loadingReferences,this.state.fonts=D.fonts,this.state.warnings=D.warnings,this.emit("warnings",this.state.warnings),this.emit("rendered",this.getState()),this.emit("statechange",this.getState()))},this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state)}catch(u){if(r.aborted){(P=t.signal)!=null&&P.aborted&&S(r);return}this.stopLoad();const e=u instanceof Error?u:new Error(String(u));throw this.state.loading=false,this.state.error=e.message,this.emit("error",e),this.emit("statechange",this.state),e}finally{r.aborted&&c.replaceChildren()}}destroy(){this.fontLoading.destroy(),this.stopLoad(),this.state.loading=false,this.state.fonts=[],this.state.warnings=[],this.documentHost.replaceChildren(),this.root.replaceChildren(),this.root.parentElement===this.host&&this.host.replaceChildren();for(const s of Object.values(this.listeners))s.clear()}stopLoad(){this.refreshDocumentFonts=void 0,this.fontReferences=[];const s=this.loadController;this.loadController=null,s==null||s.abort()}getState(){var s;return{...this.state,fonts:(s=this.state.fonts)==null?void 0:s.map(t=>({...t,classification:t.classification?{...t.classification}:void 0})),warnings:[...this.state.warnings],scrollTop:this.root.scrollTop}}getFontReferences(){return this.fontReferences}async refreshFonts(s){var t;await((t=this.refreshDocumentFonts)==null?void 0:t.call(this,s))}on(s,t){return this.listeners[s].add(t),()=>{this.listeners[s].delete(t)}}emit(s,t){for(const n of this.listeners[s])n(t)}}function Z(){return{id:"docx",family:"flow",supports:o=>q(o)==="docx",createSession:(o,s)=>new $(o,s)}}function tt(o=z()){return[...V,...o.filter(s=>!s.extensions.includes("docx"))]}async function J(o,s){if(o instanceof Blob)return o;if(typeof o=="string"){const t=await fetch(o,{signal:s.signal});if(!t.ok)throw new Error(`Failed to load DOCX source: ${t.status} ${t.statusText}`.trim());return t.arrayBuffer()}return ArrayBuffer.isView(o)?new Uint8Array(o.buffer,o.byteOffset,o.byteLength).slice().buffer:o.slice(0)}function q(o){return o.trim().replace(/^\./,"").toLowerCase()}function S(o){if(o.aborted)throw new DOMException("DOCX preview aborted.","AbortError")}function G(o,s,t){for(const n of["loadDocumentImage","loadNumberingImage","loadFont"]){const r=o[n];if(!r)continue;const c=new Map;o[n]=(...f)=>{if(s.aborted)return Promise.reject(new DOMException("DOCX preview aborted.","AbortError"));const h=n==="loadDocumentImage"?f[1]??o.documentPart:void 0,w=n==="loadFont"?JSON.stringify(f.slice(0,2)):String(f[0]);let d=c.get(h);d||c.set(h,d=new Map);let m=d.get(w);return m||(m=Promise.resolve(r.apply(o,f)).then(a=>{if(a!=null&&a.startsWith("blob:")){if(s.aborted)return URL.revokeObjectURL(a),null;t.add(a)}return a}),d.set(w,m)),m}}}export{tt as a,Z as c};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var W=Object.defineProperty;var Z=(t,e,r)=>e in t?W(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var T=(t,e,r)=>Z(t,typeof e!="symbol"?e+"":e,r);import{J as z}from"./vendor-CBCxJuSg.js";import{c as X}from"./core-BLayEJn5.js";async function _(t,e){const r=[];for(let i=0;i<t.length;){if(t.startsWith("/*",i)){i=R(t,i);continue}if(t[i]==='"'||t[i]==="'"){i=I(t,i);continue}let a=i,m=false;if(/^@import(?![\w-])/i.test(t.slice(i,i+9))&&(m=true,a=L(t,i+7),t[a]==='"'||t[a]==="'")){const c=I(t,a);t[c-1]===t[a]&&r.push({start:a,end:c,value:j(t.slice(a+1,c-1)),stylesheet:m}),i=c;continue}if((a===0||!/[\w\\-]/.test(t[a-1]))&&/^url\(/i.test(t.slice(a,a+4))){const c=L(t,a+4);let h=c,p;if(t[c]==='"'||t[c]==="'"){if(h=I(t,c),t[h-1]!==t[c]){i=h;continue}p=t.slice(c+1,h-1)}else{for(;h<t.length&&t[h]!==")";)t[h]==="\\"&&h++,h++;p=t.slice(c,h).trimEnd()}const f=L(t,h);if(t[f]===")"){r.push({start:c,end:h,value:j(p),stylesheet:m}),i=f+1;continue}}i++}const n=[];let o=0;for(const i of r){const a=await e(i.value,i.stylesheet);a!==void 0&&(n.push(t.slice(o,i.start),J(a)),o=i.end)}return o?(n.push(t.slice(o)),n.join("")):t}function R(t,e){const r=t.indexOf("*/",e+2);return r<0?t.length:r+2}function L(t,e){for(;e<t.length;)if(/\s/.test(t[e]))e++;else if(t.startsWith("/*",e))e=R(t,e);else break;return e}function I(t,e){const r=t[e++];for(;e<t.length;)if(t[e]==="\\")e+=2;else if(t[e++]===r)return e;return t.length}function j(t){return t.replace(/\\(?:([\da-f]{1,6})(?:\r\n|[\t\n\f\r ])?|(\r\n|[\n\r\f])|(.))/gi,(e,r,n,o)=>{if(r){const i=parseInt(r,16);return String.fromCodePoint(!i||i>1114111||i>=55296&&i<=57343?65533:i)}return n?"":o??""})}function J(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/[\n\r\f]/g,e=>`\\${e.charCodeAt(0).toString(16)} `)}"`}function F(){return typeof window<"u"&&window.origin==="null"}function S(t,e,r){if(F()){const o=typeof t=="string"?new TextEncoder().encode(t):t instanceof ArrayBuffer?new Uint8Array(t):t,i=[];for(let a=0;a<o.length;a+=32768)i.push(String.fromCharCode(...o.subarray(a,a+32768)));return`data:${e};base64,${btoa(i.join(""))}`}const n=t instanceof Uint8Array?new Uint8Array(t):t;return r(new Blob([n],{type:e}))}function U(t,e){const r=e.split(/[?#]/,1)[0];let n=r;try{n=decodeURIComponent(r)}catch{}const o=[];for(const i of`${n.startsWith("/")?"":t+"/"}${n}`.replace(/\\/g,"/").split("/"))i===".."?o.pop():i&&i!=="."&&o.push(i);return o.join("/")}async function V(t,e,r,n,o,i,a){const m=new Map,c=new Map,h=new Map,p=new Set,f=[];for(const l of e){const d=U(r,l.href);if(/^(?:application\/xhtml\+xml|text\/html)$/.test(l.mediaType)){p.add(d);continue}const w=t.file(d);w&&f.push({path:d,mediaType:l.mediaType,file:w})}for(let l=0;l<f.length;l+=8){B(o);const d=f.slice(l,l+8),w=await Promise.all(d.map(C=>C.file.async("arraybuffer")));B(o);for(const[C,u]of d.entries()){const s={path:u.path,mediaType:u.mediaType,bytes:w[C]};m.set(s.path,s),s.mediaType!=="text/css"&&(B(o),c.set(s.path,S(s.bytes,s.mediaType,n)))}}async function y(l,d,w){if(B(o),w.has(l)){const g=`Skipped circular EPUB stylesheet import: ${l}.`;return a.includes(g)||a.push(g),"data:text/css,"}if(c.has(l))return c.get(l);if(p.has(l)||/\.(?:xhtml|html?)$/i.test(l))return;const C=`${d?"stylesheet":"resource"}:${l}`;if(h.has(C))return h.get(C);let u=m.get(l);if(!u){const g=t.file(l);if(g){const x=await g.async("arraybuffer");B(o),u={path:l,bytes:x,mediaType:O(l)},m.set(l,u)}}let s=u==null?void 0:u.bytes,E=(u==null?void 0:u.mediaType)||O(l);if(!u&&i){const g=await i({family:"ebook",sourceFormat:"epub",source:l,relation:d?"stylesheet":"resource",name:l.split("/").pop()??l});B(o),g&&typeof g=="object"&&!(g instanceof Blob)&&!(g instanceof ArrayBuffer)&&!ArrayBuffer.isView(g)?s=g.source:s=g||void 0}let v;if(typeof s=="string")v=s;else if(s!==void 0)if(s instanceof Blob&&s.type&&(E=s.type),E.split(";",1)[0]==="text/css"||d){const g=s instanceof Blob?await s.arrayBuffer():s instanceof ArrayBuffer?s:new Uint8Array(s.buffer,s.byteOffset,s.byteLength);B(o);const x=new Set(w);x.add(l);const $=await k(Q(g,E),K(l),x);B(o),v=S($,"text/css;charset=utf-8",n)}else if(s instanceof Blob&&!F())v=n(s.type?s:new Blob([s],{type:E}));else if(u||s instanceof Blob){const g=s instanceof Blob?await s.arrayBuffer():s instanceof ArrayBuffer?s:new Uint8Array(s.buffer,s.byteOffset,s.byteLength);B(o),v=S(g,E,n)}else{const g=s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength);let x="";for(const $ of g)x+=String.fromCharCode($);v=`data:${E};base64,${btoa(x)}`}return B(o),h.set(C,v),u&&v&&c.set(l,v),v}async function A(l,d,w=false,C=new Set){var g,x;B(o);const u=l.trim();if(!u||/^(?:[a-z][a-z0-9+.-]*:|#|\/\/)/i.test(u))return;const s=U(d,u),E=await y(s,w,C);if(!E)return;const v=((g=u.match(/[?#].*$/))==null?void 0:g[0])??"";return E+(/^(?:blob|data):/i.test(E)?((x=v.match(/#.*/))==null?void 0:x[0])??"":v)}async function k(l,d,w=new Set){return _(l,(C,u)=>A(C,d,u,w))}return B(o),{resolve:A,rewriteCss:k}}function K(t){return t.slice(0,Math.max(0,t.lastIndexOf("/")))}function B(t){if(t!=null&&t.aborted)throw new DOMException("Ebook preview aborted.","AbortError")}function Q(t,e){var m,c;const r=t instanceof Uint8Array?t:new Uint8Array(t),n=r[0]===255&&r[1]===254?"utf-16le":r[0]===254&&r[1]===255?"utf-16be":r[0]===239&&r[1]===187&&r[2]===191?"utf-8":void 0,o=(m=e.match(/;\s*charset\s*=\s*["']?([^;\s"']+)/i))==null?void 0:m[1],i=(c=new TextDecoder("ascii").decode(r.subarray(0,128)).match(/^@charset "([^"\r\n]+)";/))==null?void 0:c[1],a=n??o??i??"utf-8";try{return new TextDecoder(a).decode(r)}catch{return new TextDecoder().decode(r)}}function O(t){var r;return{css:"text/css",otf:"font/otf",ttf:"font/ttf",woff:"font/woff",woff2:"font/woff2",avif:"image/avif",bmp:"image/bmp",gif:"image/gif",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",svg:"image/svg+xml",webp:"image/webp"}[((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""]??"application/octet-stream"}const Y=[{extensions:["epub"],family:"ebook",driverId:"ebook",targetFormat:"epub",contentTypes:["application/epub+zip"]},{extensions:["cbz"],family:"ebook",driverId:"ebook",targetFormat:"cbz",contentTypes:["application/vnd.comicbook+zip","application/x-cbz"]}];class tt{constructor(e,r={}){T(this,"listeners",{loading:new Set,rendered:new Set,error:new Set,statechange:new Set,warnings:new Set});T(this,"root");T(this,"tabs");T(this,"stage");T(this,"createdUrls",[]);T(this,"book",null);T(this,"frame",null);T(this,"loadGeneration",0);T(this,"loadController");T(this,"removeAbortListener");T(this,"state",{loading:false,error:null,family:"ebook",warnings:[],capabilities:{chapters:true,search:true,fullscreen:true,download:true},location:void 0,progress:0,chapterTitle:void 0,chapterIndex:0,chapterCount:0,chapters:[]});this.host=e,this.options=r,this.root=document.createElement("div"),this.root.className="ebookv-preview",this.tabs=document.createElement("div"),this.tabs.className="ebookv-chapters",this.stage=document.createElement("div"),this.stage.className="ebookv-stage",this.root.replaceChildren(this.tabs,this.stage),this.host.replaceChildren(this.root)}async load(e,r){var m,c,h;const n=++this.loadGeneration;(m=this.loadController)==null||m.abort(),(c=this.removeAbortListener)==null||c.call(this),this.releaseBook();const o=new AbortController;this.loadController=o;const i=r.signal,a=()=>{o.abort(),n===this.loadGeneration&&(this.releaseBook(),this.state.loading=false,this.emit("statechange",this.state))};i==null||i.addEventListener("abort",a,{once:true}),this.removeAbortListener=()=>i==null?void 0:i.removeEventListener("abort",a),this.state={...this.state,loading:true,error:null,title:r.descriptor.name,warnings:[],location:void 0,progress:0,chapterTitle:void 0,chapterIndex:0,chapterCount:0,chapters:[]},this.emit("loading",this.state),this.emit("statechange",this.state);try{i!=null&&i.aborted&&o.abort(),b(o.signal);const p=P(((h=r.route)==null?void 0:h.sourceFormat)??r.descriptor.extension);if(p!=="epub"&&p!=="cbz")throw new Error(`Ebook preview currently supports EPUB and CBZ files, got ${p||"unknown"}.`);const f={...r,signal:o.signal},y=k=>(b(o.signal),this.createObjectUrl(k)),A=p==="cbz"?await rt(e,f,y):await et(e,f,y,this.options.resourceResolver);if(n!==this.loadGeneration)return;b(o.signal),this.book=A,this.state={...this.state,loading:false,error:null,title:this.book.title??r.descriptor.name,warnings:this.book.warnings.slice(),chapterCount:this.book.chapters.length,chapters:this.book.chapters.map(k=>({id:k.id,title:k.title}))},this.render(),this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state)}catch(p){if(n!==this.loadGeneration)return;this.releaseBook(),this.state.loading=false,o.signal.aborted&&b(o.signal);const f=p instanceof Error?p:new Error(String(p));throw this.state.error=f.message,this.emit("error",f),this.emit("statechange",this.state),f}}destroy(){var e,r;this.loadGeneration++,(e=this.loadController)==null||e.abort(),(r=this.removeAbortListener)==null||r.call(this),this.releaseBook(),this.state.loading=false,this.root.replaceChildren(),this.root.parentElement===this.host&&this.host.replaceChildren();for(const n of Object.values(this.listeners))n.clear()}getState(){var e;return{...this.state,warnings:this.state.warnings.slice(),chapters:((e=this.state.chapters)==null?void 0:e.slice())??[]}}on(e,r){return this.listeners[e].add(r),()=>{this.listeners[e].delete(r)}}goToPage(e){this.goToChapter(e)}next(){this.goToChapter(Math.min(this.state.chapterIndex+1,Math.max(this.state.chapterCount-1,0)))}prev(){this.goToChapter(Math.max(this.state.chapterIndex-1,0))}goToChapter(e){var o;if(!Number.isInteger(e)||!((o=this.book)!=null&&o.chapters.length))return;const r=Math.max(0,Math.min(e,this.book.chapters.length-1));if(r===this.state.chapterIndex&&this.frame)return;const n=this.book.chapters[r];this.state.chapterIndex=r,this.state.location=n.href,this.state.chapterTitle=n.title,this.state.progress=this.book.chapters.length<=1?1:r/(this.book.chapters.length-1),this.renderTabs(),this.renderChapter(n),this.emit("statechange",this.state)}render(){this.renderTabs(),this.goToChapter(0)}renderTabs(){this.tabs.replaceChildren();for(const[e,r]of this.state.chapters.entries()){const n=document.createElement("button");n.type="button",n.className="ebookv-chapter-tab",n.classList.toggle("is-active",e===this.state.chapterIndex),n.textContent=r.title,n.addEventListener("click",()=>this.goToChapter(e)),this.tabs.appendChild(n)}}renderChapter(e){const r=document.createElement("iframe");r.className="ebookv-frame",r.title=e.title,r.setAttribute("sandbox","allow-same-origin allow-popups"),r.referrerPolicy="no-referrer",r.srcdoc=e.html,this.frame=r,this.stage.replaceChildren(r)}createObjectUrl(e){const r=URL.createObjectURL(e);return this.createdUrls.push(r),r}releaseBook(){this.revokeCreatedUrls(),this.book=null,this.frame=null,this.tabs.replaceChildren(),this.stage.replaceChildren(),this.state.chapterCount=0,this.state.chapterIndex=0,this.state.chapters=[],this.state.chapterTitle=void 0,this.state.location=void 0,this.state.progress=0}revokeCreatedUrls(){for(;this.createdUrls.length;){const e=this.createdUrls.pop();e&&URL.revokeObjectURL(e)}}emit(e,r){for(const n of this.listeners[e])n(r)}}function gt(){return{id:"ebook",family:"ebook",supports:t=>["epub","cbz"].includes(P(t)),createSession:(t,e)=>new tt(t,e)}}function bt(t=X()){return[...Y,...t.filter(e=>!e.extensions.some(r=>r==="epub"||r==="cbz"))]}async function et(t,e={descriptor:{source:t}},r=o=>URL.createObjectURL(o),n){const o=await D(t,e);b(e.signal);const i=await z.loadAsync(o);b(e.signal);const a=[],m=await M(i,"META-INF/container.xml",e.signal);if(!m)throw new Error("Invalid EPUB: missing META-INF/container.xml.");const c=nt(m),h=c?U("",c):null;if(!h)throw new Error("Invalid EPUB: missing rootfile path.");const p=await M(i,h,e.signal);if(!p)throw new Error(`Invalid EPUB: missing package document ${h}.`);const f=G(h),y=q(p,h),A=it(y),k=ot(y),l=at(y,"title"),d=await V(i,A.values(),f,r,e.signal,n,a),w=[];for(const C of k){b(e.signal);const u=A.get(C);if(!u){a.push(`Missing manifest item for spine id ${C}.`);continue}if(!ct(u.mediaType)){a.push(`Skipped non-HTML spine item ${u.href}.`);continue}const s=U(f,u.href),E=await M(i,s,e.signal);if(!E){a.push(`Missing chapter file ${s}.`);continue}const v=await st(E,u.href,f,d,e.signal);w.push({id:u.id,href:u.href,title:v.title??u.href,html:v.html})}if(!w.length)throw new Error("Invalid EPUB: no readable HTML chapters found.");return{title:l||void 0,chapters:w,warnings:a}}async function rt(t,e={descriptor:{source:t}},r=n=>URL.createObjectURL(n)){const n=await D(t,e);b(e.signal);const o=await z.loadAsync(n);b(e.signal);const i=new Intl.Collator(void 0,{numeric:true,sensitivity:"base"}),a=Object.values(o.files).filter(c=>!c.dir&<(c.name)).sort((c,h)=>i.compare(c.name,h.name));if(!a.length)throw new Error("Invalid CBZ: no readable image pages found.");const m=[];for(let c=0;c<a.length;c+=8){b(e.signal);const h=a.slice(c,c+8),p=await Promise.all(h.map(f=>f.async("arraybuffer")));b(e.signal);for(const[f,y]of h.entries()){b(e.signal);const A=c+f,k=ft(y.name),l=S(p[f],k,r),d=`Page ${A+1}`;m.push({id:`page-${A+1}`,title:d,href:y.name,html:ht(d,l)})}}return{title:e.descriptor.name,chapters:m,warnings:[]}}async function D(t,e){if(b(e.signal),typeof t=="string"){const r=await fetch(t,{signal:e.signal});if(!r.ok)throw new Error(`Failed to load EPUB source: ${r.status} ${r.statusText}`.trim());const n=await r.arrayBuffer();return b(e.signal),n}if(ArrayBuffer.isView(t)){const r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),n=new Uint8Array(r.byteLength);return n.set(r),n.buffer}if(t instanceof ArrayBuffer)return t;if(t instanceof Blob){const r=await t.arrayBuffer();return b(e.signal),r}return new TextEncoder().encode(String(t)).buffer}async function M(t,e,r){b(r);const n=t.file(e);if(!n)return null;const o=await n.async("text");return b(r),o}function nt(t){const e=q(t,"container.xml"),r=Array.from(e.getElementsByTagName("*")).find(n=>n.localName==="rootfile");return(r==null?void 0:r.getAttribute("full-path"))??null}function it(t){const e=new Map;for(const r of Array.from(t.getElementsByTagName("*"))){if(r.localName!=="item")continue;const n=r.getAttribute("id"),o=r.getAttribute("href"),i=r.getAttribute("media-type")??"";n&&o&&e.set(n,{id:n,href:o,mediaType:i})}return e}function ot(t){return Array.from(t.getElementsByTagName("*")).filter(e=>e.localName==="itemref").map(e=>e.getAttribute("idref")??"").filter(Boolean)}async function st(t,e,r,n,o){var m,c,h,p;b(o);const i=new DOMParser().parseFromString(t,"text/html"),a=G(U(r,e));if(/\b(?:src|href|poster|style)\b/i.test(t))for(const f of Array.from(i.querySelectorAll("[src], [*|href], [poster], [style], style"))){for(const A of["src","href","xlink:href","poster"]){const k=f.getAttribute(A);if(!k)continue;const l=f.localName.toLowerCase()==="link"&&/(?:^|\s)stylesheet(?:\s|$)/i.test(f.getAttribute("rel")??""),d=await n.resolve(k,a,l);d&&f.setAttribute(A,d)}f.localName.toLowerCase()==="style"&&(f.textContent=await n.rewriteCss(f.textContent??"",a));const y=f.getAttribute("style");y!==null&&f.setAttribute("style",await n.rewriteCss(y,a))}for(const f of i.querySelectorAll("a[href], area[href]")){const y=f.getAttribute("href").trim();y.startsWith("#")&&f.setAttribute("href",`about:srcdoc${y}`)}return b(o),{title:((c=(m=i.querySelector("title"))==null?void 0:m.textContent)==null?void 0:c.trim())||((p=(h=i.querySelector("h1,h2,h3"))==null?void 0:h.textContent)==null?void 0:p.trim())||void 0,html:`<!doctype html>${i.documentElement.outerHTML}`}}function b(t){if(t!=null&&t.aborted)throw new DOMException("Ebook preview aborted.","AbortError")}function q(t,e){const r=new DOMParser().parseFromString(t,"application/xml");if(r.getElementsByTagName("parsererror")[0])throw new Error(`Invalid XML in ${e}.`);return r}function at(t,e){var n;const r=Array.from(t.getElementsByTagName("*")).find(o=>o.localName===e);return((n=r==null?void 0:r.textContent)==null?void 0:n.trim())??""}function ct(t){return t==="application/xhtml+xml"||t==="text/html"}function lt(t){return/\.(?:avif|bmp|gif|jpe?g|png|svg|webp)$/i.test(t)}function ft(t){const e=P(t.split(".").pop());return{avif:"image/avif",bmp:"image/bmp",gif:"image/gif",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",svg:"image/svg+xml",webp:"image/webp"}[e]??"application/octet-stream"}function ht(t,e){return`<!doctype html><html><head><meta charset="utf-8"><title>${H(t)}</title><style>
|
|
1
|
+
var W=Object.defineProperty;var Z=(t,e,r)=>e in t?W(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var T=(t,e,r)=>Z(t,typeof e!="symbol"?e+"":e,r);import{J as z}from"./vendor-C1aIdQ-w.js";import{c as X}from"./core-EjELrtsP.js";async function _(t,e){const r=[];for(let i=0;i<t.length;){if(t.startsWith("/*",i)){i=R(t,i);continue}if(t[i]==='"'||t[i]==="'"){i=I(t,i);continue}let a=i,m=false;if(/^@import(?![\w-])/i.test(t.slice(i,i+9))&&(m=true,a=L(t,i+7),t[a]==='"'||t[a]==="'")){const c=I(t,a);t[c-1]===t[a]&&r.push({start:a,end:c,value:j(t.slice(a+1,c-1)),stylesheet:m}),i=c;continue}if((a===0||!/[\w\\-]/.test(t[a-1]))&&/^url\(/i.test(t.slice(a,a+4))){const c=L(t,a+4);let h=c,p;if(t[c]==='"'||t[c]==="'"){if(h=I(t,c),t[h-1]!==t[c]){i=h;continue}p=t.slice(c+1,h-1)}else{for(;h<t.length&&t[h]!==")";)t[h]==="\\"&&h++,h++;p=t.slice(c,h).trimEnd()}const f=L(t,h);if(t[f]===")"){r.push({start:c,end:h,value:j(p),stylesheet:m}),i=f+1;continue}}i++}const n=[];let o=0;for(const i of r){const a=await e(i.value,i.stylesheet);a!==void 0&&(n.push(t.slice(o,i.start),J(a)),o=i.end)}return o?(n.push(t.slice(o)),n.join("")):t}function R(t,e){const r=t.indexOf("*/",e+2);return r<0?t.length:r+2}function L(t,e){for(;e<t.length;)if(/\s/.test(t[e]))e++;else if(t.startsWith("/*",e))e=R(t,e);else break;return e}function I(t,e){const r=t[e++];for(;e<t.length;)if(t[e]==="\\")e+=2;else if(t[e++]===r)return e;return t.length}function j(t){return t.replace(/\\(?:([\da-f]{1,6})(?:\r\n|[\t\n\f\r ])?|(\r\n|[\n\r\f])|(.))/gi,(e,r,n,o)=>{if(r){const i=parseInt(r,16);return String.fromCodePoint(!i||i>1114111||i>=55296&&i<=57343?65533:i)}return n?"":o??""})}function J(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/[\n\r\f]/g,e=>`\\${e.charCodeAt(0).toString(16)} `)}"`}function F(){return typeof window<"u"&&window.origin==="null"}function S(t,e,r){if(F()){const o=typeof t=="string"?new TextEncoder().encode(t):t instanceof ArrayBuffer?new Uint8Array(t):t,i=[];for(let a=0;a<o.length;a+=32768)i.push(String.fromCharCode(...o.subarray(a,a+32768)));return`data:${e};base64,${btoa(i.join(""))}`}const n=t instanceof Uint8Array?new Uint8Array(t):t;return r(new Blob([n],{type:e}))}function U(t,e){const r=e.split(/[?#]/,1)[0];let n=r;try{n=decodeURIComponent(r)}catch{}const o=[];for(const i of`${n.startsWith("/")?"":t+"/"}${n}`.replace(/\\/g,"/").split("/"))i===".."?o.pop():i&&i!=="."&&o.push(i);return o.join("/")}async function V(t,e,r,n,o,i,a){const m=new Map,c=new Map,h=new Map,p=new Set,f=[];for(const l of e){const d=U(r,l.href);if(/^(?:application\/xhtml\+xml|text\/html)$/.test(l.mediaType)){p.add(d);continue}const w=t.file(d);w&&f.push({path:d,mediaType:l.mediaType,file:w})}for(let l=0;l<f.length;l+=8){B(o);const d=f.slice(l,l+8),w=await Promise.all(d.map(C=>C.file.async("arraybuffer")));B(o);for(const[C,u]of d.entries()){const s={path:u.path,mediaType:u.mediaType,bytes:w[C]};m.set(s.path,s),s.mediaType!=="text/css"&&(B(o),c.set(s.path,S(s.bytes,s.mediaType,n)))}}async function y(l,d,w){if(B(o),w.has(l)){const g=`Skipped circular EPUB stylesheet import: ${l}.`;return a.includes(g)||a.push(g),"data:text/css,"}if(c.has(l))return c.get(l);if(p.has(l)||/\.(?:xhtml|html?)$/i.test(l))return;const C=`${d?"stylesheet":"resource"}:${l}`;if(h.has(C))return h.get(C);let u=m.get(l);if(!u){const g=t.file(l);if(g){const x=await g.async("arraybuffer");B(o),u={path:l,bytes:x,mediaType:O(l)},m.set(l,u)}}let s=u==null?void 0:u.bytes,E=(u==null?void 0:u.mediaType)||O(l);if(!u&&i){const g=await i({family:"ebook",sourceFormat:"epub",source:l,relation:d?"stylesheet":"resource",name:l.split("/").pop()??l});B(o),g&&typeof g=="object"&&!(g instanceof Blob)&&!(g instanceof ArrayBuffer)&&!ArrayBuffer.isView(g)?s=g.source:s=g||void 0}let v;if(typeof s=="string")v=s;else if(s!==void 0)if(s instanceof Blob&&s.type&&(E=s.type),E.split(";",1)[0]==="text/css"||d){const g=s instanceof Blob?await s.arrayBuffer():s instanceof ArrayBuffer?s:new Uint8Array(s.buffer,s.byteOffset,s.byteLength);B(o);const x=new Set(w);x.add(l);const $=await k(Q(g,E),K(l),x);B(o),v=S($,"text/css;charset=utf-8",n)}else if(s instanceof Blob&&!F())v=n(s.type?s:new Blob([s],{type:E}));else if(u||s instanceof Blob){const g=s instanceof Blob?await s.arrayBuffer():s instanceof ArrayBuffer?s:new Uint8Array(s.buffer,s.byteOffset,s.byteLength);B(o),v=S(g,E,n)}else{const g=s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength);let x="";for(const $ of g)x+=String.fromCharCode($);v=`data:${E};base64,${btoa(x)}`}return B(o),h.set(C,v),u&&v&&c.set(l,v),v}async function A(l,d,w=false,C=new Set){var g,x;B(o);const u=l.trim();if(!u||/^(?:[a-z][a-z0-9+.-]*:|#|\/\/)/i.test(u))return;const s=U(d,u),E=await y(s,w,C);if(!E)return;const v=((g=u.match(/[?#].*$/))==null?void 0:g[0])??"";return E+(/^(?:blob|data):/i.test(E)?((x=v.match(/#.*/))==null?void 0:x[0])??"":v)}async function k(l,d,w=new Set){return _(l,(C,u)=>A(C,d,u,w))}return B(o),{resolve:A,rewriteCss:k}}function K(t){return t.slice(0,Math.max(0,t.lastIndexOf("/")))}function B(t){if(t!=null&&t.aborted)throw new DOMException("Ebook preview aborted.","AbortError")}function Q(t,e){var m,c;const r=t instanceof Uint8Array?t:new Uint8Array(t),n=r[0]===255&&r[1]===254?"utf-16le":r[0]===254&&r[1]===255?"utf-16be":r[0]===239&&r[1]===187&&r[2]===191?"utf-8":void 0,o=(m=e.match(/;\s*charset\s*=\s*["']?([^;\s"']+)/i))==null?void 0:m[1],i=(c=new TextDecoder("ascii").decode(r.subarray(0,128)).match(/^@charset "([^"\r\n]+)";/))==null?void 0:c[1],a=n??o??i??"utf-8";try{return new TextDecoder(a).decode(r)}catch{return new TextDecoder().decode(r)}}function O(t){var r;return{css:"text/css",otf:"font/otf",ttf:"font/ttf",woff:"font/woff",woff2:"font/woff2",avif:"image/avif",bmp:"image/bmp",gif:"image/gif",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",svg:"image/svg+xml",webp:"image/webp"}[((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""]??"application/octet-stream"}const Y=[{extensions:["epub"],family:"ebook",driverId:"ebook",targetFormat:"epub",contentTypes:["application/epub+zip"]},{extensions:["cbz"],family:"ebook",driverId:"ebook",targetFormat:"cbz",contentTypes:["application/vnd.comicbook+zip","application/x-cbz"]}];class tt{constructor(e,r={}){T(this,"listeners",{loading:new Set,rendered:new Set,error:new Set,statechange:new Set,warnings:new Set});T(this,"root");T(this,"tabs");T(this,"stage");T(this,"createdUrls",[]);T(this,"book",null);T(this,"frame",null);T(this,"loadGeneration",0);T(this,"loadController");T(this,"removeAbortListener");T(this,"state",{loading:false,error:null,family:"ebook",warnings:[],capabilities:{chapters:true,search:true,fullscreen:true,download:true},location:void 0,progress:0,chapterTitle:void 0,chapterIndex:0,chapterCount:0,chapters:[]});this.host=e,this.options=r,this.root=document.createElement("div"),this.root.className="ebookv-preview",this.tabs=document.createElement("div"),this.tabs.className="ebookv-chapters",this.stage=document.createElement("div"),this.stage.className="ebookv-stage",this.root.replaceChildren(this.tabs,this.stage),this.host.replaceChildren(this.root)}async load(e,r){var m,c,h;const n=++this.loadGeneration;(m=this.loadController)==null||m.abort(),(c=this.removeAbortListener)==null||c.call(this),this.releaseBook();const o=new AbortController;this.loadController=o;const i=r.signal,a=()=>{o.abort(),n===this.loadGeneration&&(this.releaseBook(),this.state.loading=false,this.emit("statechange",this.state))};i==null||i.addEventListener("abort",a,{once:true}),this.removeAbortListener=()=>i==null?void 0:i.removeEventListener("abort",a),this.state={...this.state,loading:true,error:null,title:r.descriptor.name,warnings:[],location:void 0,progress:0,chapterTitle:void 0,chapterIndex:0,chapterCount:0,chapters:[]},this.emit("loading",this.state),this.emit("statechange",this.state);try{i!=null&&i.aborted&&o.abort(),b(o.signal);const p=P(((h=r.route)==null?void 0:h.sourceFormat)??r.descriptor.extension);if(p!=="epub"&&p!=="cbz")throw new Error(`Ebook preview currently supports EPUB and CBZ files, got ${p||"unknown"}.`);const f={...r,signal:o.signal},y=k=>(b(o.signal),this.createObjectUrl(k)),A=p==="cbz"?await rt(e,f,y):await et(e,f,y,this.options.resourceResolver);if(n!==this.loadGeneration)return;b(o.signal),this.book=A,this.state={...this.state,loading:false,error:null,title:this.book.title??r.descriptor.name,warnings:this.book.warnings.slice(),chapterCount:this.book.chapters.length,chapters:this.book.chapters.map(k=>({id:k.id,title:k.title}))},this.render(),this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state)}catch(p){if(n!==this.loadGeneration)return;this.releaseBook(),this.state.loading=false,o.signal.aborted&&b(o.signal);const f=p instanceof Error?p:new Error(String(p));throw this.state.error=f.message,this.emit("error",f),this.emit("statechange",this.state),f}}destroy(){var e,r;this.loadGeneration++,(e=this.loadController)==null||e.abort(),(r=this.removeAbortListener)==null||r.call(this),this.releaseBook(),this.state.loading=false,this.root.replaceChildren(),this.root.parentElement===this.host&&this.host.replaceChildren();for(const n of Object.values(this.listeners))n.clear()}getState(){var e;return{...this.state,warnings:this.state.warnings.slice(),chapters:((e=this.state.chapters)==null?void 0:e.slice())??[]}}on(e,r){return this.listeners[e].add(r),()=>{this.listeners[e].delete(r)}}goToPage(e){this.goToChapter(e)}next(){this.goToChapter(Math.min(this.state.chapterIndex+1,Math.max(this.state.chapterCount-1,0)))}prev(){this.goToChapter(Math.max(this.state.chapterIndex-1,0))}goToChapter(e){var o;if(!Number.isInteger(e)||!((o=this.book)!=null&&o.chapters.length))return;const r=Math.max(0,Math.min(e,this.book.chapters.length-1));if(r===this.state.chapterIndex&&this.frame)return;const n=this.book.chapters[r];this.state.chapterIndex=r,this.state.location=n.href,this.state.chapterTitle=n.title,this.state.progress=this.book.chapters.length<=1?1:r/(this.book.chapters.length-1),this.renderTabs(),this.renderChapter(n),this.emit("statechange",this.state)}render(){this.renderTabs(),this.goToChapter(0)}renderTabs(){this.tabs.replaceChildren();for(const[e,r]of this.state.chapters.entries()){const n=document.createElement("button");n.type="button",n.className="ebookv-chapter-tab",n.classList.toggle("is-active",e===this.state.chapterIndex),n.textContent=r.title,n.addEventListener("click",()=>this.goToChapter(e)),this.tabs.appendChild(n)}}renderChapter(e){const r=document.createElement("iframe");r.className="ebookv-frame",r.title=e.title,r.setAttribute("sandbox","allow-same-origin allow-popups"),r.referrerPolicy="no-referrer",r.srcdoc=e.html,this.frame=r,this.stage.replaceChildren(r)}createObjectUrl(e){const r=URL.createObjectURL(e);return this.createdUrls.push(r),r}releaseBook(){this.revokeCreatedUrls(),this.book=null,this.frame=null,this.tabs.replaceChildren(),this.stage.replaceChildren(),this.state.chapterCount=0,this.state.chapterIndex=0,this.state.chapters=[],this.state.chapterTitle=void 0,this.state.location=void 0,this.state.progress=0}revokeCreatedUrls(){for(;this.createdUrls.length;){const e=this.createdUrls.pop();e&&URL.revokeObjectURL(e)}}emit(e,r){for(const n of this.listeners[e])n(r)}}function gt(){return{id:"ebook",family:"ebook",supports:t=>["epub","cbz"].includes(P(t)),createSession:(t,e)=>new tt(t,e)}}function bt(t=X()){return[...Y,...t.filter(e=>!e.extensions.some(r=>r==="epub"||r==="cbz"))]}async function et(t,e={descriptor:{source:t}},r=o=>URL.createObjectURL(o),n){const o=await D(t,e);b(e.signal);const i=await z.loadAsync(o);b(e.signal);const a=[],m=await M(i,"META-INF/container.xml",e.signal);if(!m)throw new Error("Invalid EPUB: missing META-INF/container.xml.");const c=nt(m),h=c?U("",c):null;if(!h)throw new Error("Invalid EPUB: missing rootfile path.");const p=await M(i,h,e.signal);if(!p)throw new Error(`Invalid EPUB: missing package document ${h}.`);const f=G(h),y=q(p,h),A=it(y),k=ot(y),l=at(y,"title"),d=await V(i,A.values(),f,r,e.signal,n,a),w=[];for(const C of k){b(e.signal);const u=A.get(C);if(!u){a.push(`Missing manifest item for spine id ${C}.`);continue}if(!ct(u.mediaType)){a.push(`Skipped non-HTML spine item ${u.href}.`);continue}const s=U(f,u.href),E=await M(i,s,e.signal);if(!E){a.push(`Missing chapter file ${s}.`);continue}const v=await st(E,u.href,f,d,e.signal);w.push({id:u.id,href:u.href,title:v.title??u.href,html:v.html})}if(!w.length)throw new Error("Invalid EPUB: no readable HTML chapters found.");return{title:l||void 0,chapters:w,warnings:a}}async function rt(t,e={descriptor:{source:t}},r=n=>URL.createObjectURL(n)){const n=await D(t,e);b(e.signal);const o=await z.loadAsync(n);b(e.signal);const i=new Intl.Collator(void 0,{numeric:true,sensitivity:"base"}),a=Object.values(o.files).filter(c=>!c.dir&<(c.name)).sort((c,h)=>i.compare(c.name,h.name));if(!a.length)throw new Error("Invalid CBZ: no readable image pages found.");const m=[];for(let c=0;c<a.length;c+=8){b(e.signal);const h=a.slice(c,c+8),p=await Promise.all(h.map(f=>f.async("arraybuffer")));b(e.signal);for(const[f,y]of h.entries()){b(e.signal);const A=c+f,k=ft(y.name),l=S(p[f],k,r),d=`Page ${A+1}`;m.push({id:`page-${A+1}`,title:d,href:y.name,html:ht(d,l)})}}return{title:e.descriptor.name,chapters:m,warnings:[]}}async function D(t,e){if(b(e.signal),typeof t=="string"){const r=await fetch(t,{signal:e.signal});if(!r.ok)throw new Error(`Failed to load EPUB source: ${r.status} ${r.statusText}`.trim());const n=await r.arrayBuffer();return b(e.signal),n}if(ArrayBuffer.isView(t)){const r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),n=new Uint8Array(r.byteLength);return n.set(r),n.buffer}if(t instanceof ArrayBuffer)return t;if(t instanceof Blob){const r=await t.arrayBuffer();return b(e.signal),r}return new TextEncoder().encode(String(t)).buffer}async function M(t,e,r){b(r);const n=t.file(e);if(!n)return null;const o=await n.async("text");return b(r),o}function nt(t){const e=q(t,"container.xml"),r=Array.from(e.getElementsByTagName("*")).find(n=>n.localName==="rootfile");return(r==null?void 0:r.getAttribute("full-path"))??null}function it(t){const e=new Map;for(const r of Array.from(t.getElementsByTagName("*"))){if(r.localName!=="item")continue;const n=r.getAttribute("id"),o=r.getAttribute("href"),i=r.getAttribute("media-type")??"";n&&o&&e.set(n,{id:n,href:o,mediaType:i})}return e}function ot(t){return Array.from(t.getElementsByTagName("*")).filter(e=>e.localName==="itemref").map(e=>e.getAttribute("idref")??"").filter(Boolean)}async function st(t,e,r,n,o){var m,c,h,p;b(o);const i=new DOMParser().parseFromString(t,"text/html"),a=G(U(r,e));if(/\b(?:src|href|poster|style)\b/i.test(t))for(const f of Array.from(i.querySelectorAll("[src], [*|href], [poster], [style], style"))){for(const A of["src","href","xlink:href","poster"]){const k=f.getAttribute(A);if(!k)continue;const l=f.localName.toLowerCase()==="link"&&/(?:^|\s)stylesheet(?:\s|$)/i.test(f.getAttribute("rel")??""),d=await n.resolve(k,a,l);d&&f.setAttribute(A,d)}f.localName.toLowerCase()==="style"&&(f.textContent=await n.rewriteCss(f.textContent??"",a));const y=f.getAttribute("style");y!==null&&f.setAttribute("style",await n.rewriteCss(y,a))}for(const f of i.querySelectorAll("a[href], area[href]")){const y=f.getAttribute("href").trim();y.startsWith("#")&&f.setAttribute("href",`about:srcdoc${y}`)}return b(o),{title:((c=(m=i.querySelector("title"))==null?void 0:m.textContent)==null?void 0:c.trim())||((p=(h=i.querySelector("h1,h2,h3"))==null?void 0:h.textContent)==null?void 0:p.trim())||void 0,html:`<!doctype html>${i.documentElement.outerHTML}`}}function b(t){if(t!=null&&t.aborted)throw new DOMException("Ebook preview aborted.","AbortError")}function q(t,e){const r=new DOMParser().parseFromString(t,"application/xml");if(r.getElementsByTagName("parsererror")[0])throw new Error(`Invalid XML in ${e}.`);return r}function at(t,e){var n;const r=Array.from(t.getElementsByTagName("*")).find(o=>o.localName===e);return((n=r==null?void 0:r.textContent)==null?void 0:n.trim())??""}function ct(t){return t==="application/xhtml+xml"||t==="text/html"}function lt(t){return/\.(?:avif|bmp|gif|jpe?g|png|svg|webp)$/i.test(t)}function ft(t){const e=P(t.split(".").pop());return{avif:"image/avif",bmp:"image/bmp",gif:"image/gif",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",svg:"image/svg+xml",webp:"image/webp"}[e]??"application/octet-stream"}function ht(t,e){return`<!doctype html><html><head><meta charset="utf-8"><title>${H(t)}</title><style>
|
|
2
2
|
html,body{margin:0;min-height:100%;background:#111827;color:#f8fafc;font-family:system-ui,sans-serif;}
|
|
3
3
|
body{display:flex;align-items:center;justify-content:center;}
|
|
4
4
|
img{display:block;max-width:100%;max-height:100vh;width:auto;height:auto;object-fit:contain;}
|