mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-05-08 03:06:29 +08:00
92c2d9ed4c
This commit does not implement the file link
86 lines
46 KiB
HTML
Vendored
86 lines
46 KiB
HTML
Vendored
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>chm2html — CHM Viewer (Plugin)</title>
|
|
|
|
<script>window.__CHM2HTML_PLUGIN = true;</script>
|
|
|
|
<script type="module">
|
|
// inlined assets/app-B1f0-Pbl.js
|
|
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const i of s)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(s){if(s.ep)return;s.ep=!0;const i=n(s);fetch(s.href,i)}})();const et="modulepreload",tt=function(e){return"/"+e},_e={},nt=function(t,n,r){let s=Promise.resolve();if(n&&n.length>0){let o=function(l){return Promise.all(l.map(f=>Promise.resolve(f).then(d=>({status:"fulfilled",value:d}),d=>({status:"rejected",reason:d}))))};document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),c=a?.nonce||a?.getAttribute("nonce");s=o(n.map(l=>{if(l=tt(l),l in _e)return;_e[l]=!0;const f=l.endsWith(".css"),d=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${d}`))return;const h=document.createElement("link");if(h.rel=f?"stylesheet":et,f||(h.as="script"),h.crossOrigin="",h.href=l,c&&h.setAttribute("nonce",c),document.head.appendChild(h),f)return new Promise((w,v)=>{h.addEventListener("load",w),h.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${l}`)))})}))}function i(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return s.then(o=>{for(const a of o||[])a.status==="rejected"&&i(a.reason);return t().catch(i)})};class C{view;_offset;constructor(t,n=0){this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this._offset=n}get offset(){return this._offset}get remaining(){return this.view.byteLength-this._offset}readUint8(){if(this._offset+1>this.view.byteLength)throw new RangeError(`BufferReader: read past end (offset=${this._offset}, need 1)`);const t=this.view.getUint8(this._offset);return this._offset+=1,t}readInt16LE(){if(this._offset+2>this.view.byteLength)throw new RangeError(`BufferReader: read past end (offset=${this._offset}, need 2)`);const t=this.view.getInt16(this._offset,!0);return this._offset+=2,t}readUint16LE(){if(this._offset+2>this.view.byteLength)throw new RangeError(`BufferReader: read past end (offset=${this._offset}, need 2)`);const t=this.view.getUint16(this._offset,!0);return this._offset+=2,t}readInt32LE(){if(this._offset+4>this.view.byteLength)throw new RangeError(`BufferReader: read past end (offset=${this._offset}, need 4)`);const t=this.view.getInt32(this._offset,!0);return this._offset+=4,t}readUint32LE(){if(this._offset+4>this.view.byteLength)throw new RangeError(`BufferReader: read past end (offset=${this._offset}, need 4)`);const t=this.view.getUint32(this._offset,!0);return this._offset+=4,t}readBigInt64LE(){if(this._offset+8>this.view.byteLength)throw new RangeError(`BufferReader: read past end (offset=${this._offset}, need 8)`);const t=this.view.getBigInt64(this._offset,!0);return this._offset+=8,t}readBigUint64LE(){if(this._offset+8>this.view.byteLength)throw new RangeError(`BufferReader: read past end (offset=${this._offset}, need 8)`);const t=this.view.getBigUint64(this._offset,!0);return this._offset+=8,t}readBytes(t){if(this._offset+t>this.view.byteLength)throw new RangeError(`BufferReader: read past end (offset=${this._offset}, need ${t})`);const n=new Uint8Array(this.view.buffer,this.view.byteOffset+this._offset,t);return this._offset+=t,n.slice()}readAscii(t){const n=this.readBytes(t);return String.fromCharCode(...n)}skip(t){if(this._offset+t>this.view.byteLength)throw new RangeError(`BufferReader: skip past end (offset=${this._offset}, skip ${t})`);this._offset+=t}readCWord(){let t=0n,n;for(;(n=this.readUint8())>=128;)t<<=7n,t+=BigInt(n&127);return(t<<7n)+BigInt(n)}}const Re=88,Te=96;function rt(e){if(e.length!==Re&&e.length!==Te)throw new Error(`ITSF header: unexpected length ${e.length}`);const t=new C(e),n=t.readAscii(4),r=t.readInt32LE(),s=t.readInt32LE();t.readInt32LE();const i=t.readUint32LE(),o=t.readUint32LE(),a=t.readBytes(16),c=t.readBytes(16),l=t.readBigUint64LE(),f=t.readBigUint64LE(),d=t.readBigUint64LE(),h=t.readBigUint64LE();if(n!=="ITSF")throw new Error(`ITSF header: bad signature "${n}"`);if(r===2){if(s<Re)throw new Error(`ITSF v2 header too short: ${s}`)}else if(r===3){if(s<Te)throw new Error(`ITSF v3 header too short: ${s}`)}else throw new Error(`ITSF header: unsupported version ${r}`);let w;if(r===3){if(t.remaining<8)throw new Error("ITSF v3 header: missing data_offset field");w=t.readBigUint64LE()}else w=d+h;return{signature:n,version:r,headerLen:s,lastModified:i,langId:o,dirUuid:a,streamUuid:c,unknownOffset:l,unknownLen:f,dirOffset:d,dirLen:h,dataOffset:w}}const ke=84;function st(e){if(e.length!==ke)throw new Error(`ITSP header: unexpected length ${e.length}`);const t=new C(e),n=t.readAscii(4),r=t.readInt32LE(),s=t.readInt32LE();t.readInt32LE();const i=t.readUint32LE();t.readInt32LE(),t.readInt32LE();const o=t.readInt32LE(),a=t.readInt32LE();t.readInt32LE();const c=t.readUint32LE();t.readInt32LE();const l=t.readUint32LE(),f=t.readBytes(16);if(t.readBytes(16),n!=="ITSP")throw new Error(`ITSP header: bad signature "${n}"`);if(r!==1)throw new Error(`ITSP header: unsupported version ${r}`);if(s!==ke)throw new Error(`ITSP header: unexpected headerLen ${s}`);return{signature:n,version:r,headerLen:s,blockLen:i,blockidxIntvl:0,indexDepth:0,indexRoot:o,indexHead:a,numBlocks:c,langId:l,systemUuid:f}}function Se(e){if(e.length<20)throw new Error(`PMGL header: too short (${e.length})`);const t=new C(e),n=t.readAscii(4),r=t.readUint32LE();t.readUint32LE();const s=t.readInt32LE(),i=t.readInt32LE();if(n!=="PMGL")throw new Error(`PMGL header: bad signature "${n}"`);return{signature:n,freeSpace:r,blockPrev:s,blockNext:i}}function it(e){if(e.length<8)throw new Error(`PMGI header: too short (${e.length})`);const t=new C(e),n=t.readAscii(4),r=t.readUint32LE();if(n!=="PMGI")throw new Error(`PMGI header: bad signature "${n}"`);return{signature:n,freeSpace:r}}const ot=40;function at(e){if(e.length!==ot)throw new Error(`LZXC reset table: unexpected length ${e.length}`);const t=new C(e),n=t.readUint32LE(),r=t.readUint32LE();t.readUint32LE();const s=t.readUint32LE(),i=t.readBigUint64LE(),o=t.readBigUint64LE(),a=t.readBigUint64LE();if(n!==2)throw new Error(`LZXC reset table: unsupported version ${n}`);return{version:n,blockCount:r,tableOffset:s,uncompressedLen:i,compressedLen:o,blockLen:a}}const ct=24,lt=28;function ft(e){if(e.length<ct)throw new Error(`LZXC control data: too short (${e.length})`);const t=new C(e),n=t.readUint32LE(),r=t.readAscii(4),s=t.readUint32LE();let i=t.readUint32LE(),o=t.readUint32LE();const a=t.readUint32LE();if(e.length>=lt&&t.readUint32LE(),r!=="LZXC")throw new Error(`LZXC control data: bad signature "${r}"`);if(s===2&&(i*=32768,o*=32768),o===0||i===0)throw new Error("LZXC control data: zero windowSize or resetInterval");if(o===1)throw new Error("LZXC control data: windowSize is 1");if(i%(o/2)!==0)throw new Error("LZXC control data: resetInterval not a multiple of windowSize/2");return{size:n,signature:r,version:s,resetInterval:i,windowSize:o,windowsPerReset:a}}const Ie=2,F=256,Ce=1,Ae=2,fe=3,dt=20,Q=7,Ge=249,ne=6,j=dt,re=12,V=F+400,se=12,q=Ge+1,ie=7,Y=8,ee=64,de=32,xe=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17]),Ne=new Uint32Array([0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576,32768,49152,65536,98304,131072,196608,262144,393216,524288,655360,786432,917504,1048576,1179648,1310720,1441792,1572864,1703936,1835008,1966080,2097152]);function te(e,t,n,r){let s,i=1,o=0,a=1<<t,c=a>>1,l=c;for(;i<=t;){for(let f=0;f<e;f++)if(n[f]===i){if(s=o,(o+=c)>a)return 1;let d=c;for(;d-- >0;)r[s++]=f}c>>=1,i++}if(o!==a){for(let f=o;f<a;f++)r[f]=0;for(o<<=16,a<<=16,c=32768;i<=16;){for(let f=0;f<e;f++)if(n[f]===i){s=o>>16;for(let d=0;d<i-t;d++)r[s]===0&&(r[l<<1]=0,r[(l<<1)+1]=0,r[s]=l++),s=r[s]<<1,o>>15-d&1&&s++;if(r[s]=f,(o+=c)>a)return 1}c>>=1,i++}}if(o===a)return 0;for(let f=0;f<e;f++)if(n[f])return 1;return 0}class ut{window;windowSize;actualSize;windowPosn;R0;R1;R2;mainElements;headerRead;blockType;blockLength;blockRemaining;framesRead;intelFilesize;intelCurpos;intelStarted;PRETREE_table;PRETREE_len;MAINTREE_table;MAINTREE_len;LENGTH_table;LENGTH_len;ALIGNED_table;ALIGNED_len;constructor(t){if(t<15||t>21)throw new RangeError(`LZXState: invalid window size bits ${t} (must be 15-21)`);const n=1<<t;let r;t===20?r=42:t===21?r=50:r=t<<1,this.window=new Uint8Array(n),this.windowSize=n,this.actualSize=n,this.windowPosn=0,this.R0=this.R1=this.R2=1,this.mainElements=F+(r<<3),this.headerRead=!1,this.framesRead=0,this.blockRemaining=0,this.blockType=0,this.blockLength=0,this.intelCurpos=0,this.intelStarted=!1,this.intelFilesize=0,this.PRETREE_table=new Uint16Array((1<<ne)+(j<<1)),this.PRETREE_len=new Uint8Array(j+ee),this.MAINTREE_table=new Uint16Array((1<<re)+(V<<1)),this.MAINTREE_len=new Uint8Array(V+ee),this.LENGTH_table=new Uint16Array((1<<se)+(q<<1)),this.LENGTH_len=new Uint8Array(q+ee),this.ALIGNED_table=new Uint16Array((1<<ie)+(Y<<1)),this.ALIGNED_len=new Uint8Array(Y+ee)}reset(){this.R0=this.R1=this.R2=1,this.headerRead=!1,this.framesRead=0,this.blockRemaining=0,this.blockType=0,this.intelCurpos=0,this.intelStarted=!1,this.windowPosn=0,this.MAINTREE_len.fill(0),this.LENGTH_len.fill(0)}}const ge=0,ht=1,T=2;function Ue(e,t,n,r,s){const i=e.window,o=e.windowSize;let a=e.windowPosn,c=e.R0,l=e.R1,f=e.R2,d=0,h=0,w=0;const v=r;function k(g){for(;h<g;){const E=w<r?t[w]:0,L=w+1<r?t[w+1]:0;d=(d|(L<<8|E)<<de-16-h)>>>0,h+=16,w+=2}}function U(g){return d>>>de-g>>>0}function A(g){d=d<<g>>>0,h-=g}function p(g){k(g);const E=U(g);return A(g),E}function y(g,E,L,m){k(16);let u=g[U(L)];if(u>=m){let I=1<<de-L;do{if(I>>>=1,u<<=1,u|=d&I?1:0,!I)return-1;u=g[u]}while(u>=m)}const b=E[u];return A(b),u}function B(g,E,L){for(let u=0;u<20;u++)e.PRETREE_len[u]=p(4);if(te(j,ne,e.PRETREE_len,e.PRETREE_table))return!0;let m=E;for(;m<L;){const u=y(e.PRETREE_table,e.PRETREE_len,ne,j);if(u<0)return!0;if(u===17){let b=p(4)+4;for(;b-- >0;)g[m++]=0}else if(u===18){let b=p(5)+20;for(;b-- >0;)g[m++]=0}else if(u===19){let b=p(1)+4;const I=y(e.PRETREE_table,e.PRETREE_len,ne,j);if(I<0)return!0;let S=g[m]-I;for(S<0&&(S+=17);b-- >0;)g[m++]=S}else{let b=g[m]-u;b<0&&(b+=17),g[m++]=b}}return!1}let _=s;if(!e.headerRead){let g=0,E=0;p(1)&&(g=p(16),E=p(16)),e.intelFilesize=g<<16|E,e.headerRead=!0}for(;_>0;){if(e.blockRemaining===0){e.blockType===fe&&(e.blockLength&1&&w++,h=0,d=0),e.blockType=p(3);const g=p(16),E=p(8);switch(e.blockRemaining=e.blockLength=g<<8|E,e.blockType){case Ae:for(let L=0;L<8;L++)e.ALIGNED_len[L]=p(3);if(te(Y,ie,e.ALIGNED_len,e.ALIGNED_table))return T;case Ce:if(B(e.MAINTREE_len,0,256)||B(e.MAINTREE_len,256,e.mainElements)||te(V,re,e.MAINTREE_len,e.MAINTREE_table)||(e.MAINTREE_len[232]!==0&&(e.intelStarted=!0),B(e.LENGTH_len,0,Ge))||te(q,se,e.LENGTH_len,e.LENGTH_table))return T;break;case fe:e.intelStarted=!0,k(16),h>16&&(w-=2),c=(t[w]|t[w+1]<<8|t[w+2]<<16|t[w+3]<<24)>>>0,w+=4,l=(t[w]|t[w+1]<<8|t[w+2]<<16|t[w+3]<<24)>>>0,w+=4,f=(t[w]|t[w+1]<<8|t[w+2]<<16|t[w+3]<<24)>>>0,w+=4;break;default:return T}}if(w>v&&(w>v+2||h<16))return T;for(;e.blockRemaining>0&&_>0;){let g=e.blockRemaining;if(g>_&&(g=_),_-=g,e.blockRemaining-=g,a&=o-1,a+g>o)return ht;switch(e.blockType){case Ce:for(;g>0;){const E=y(e.MAINTREE_table,e.MAINTREE_len,re,V);if(E<0)return T;if(E<F)i[a++]=E,g--;else{const L=E-F;let m=L&Q;if(m===Q){const S=y(e.LENGTH_table,e.LENGTH_len,se,q);if(S<0)return T;m+=S}m+=Ie;let u=L>>3;if(u>2){if(u!==3){const S=xe[u],O=p(S);u=Ne[u]-2+O}else u=1;f=l,l=c,c=u}else u===0?u=c:u===1?(u=l,l=c,c=u):(u=f,f=c,c=u);let b=a,I=b-u;if(a+=m,a>o)return T;for(g-=m;I<0&&m-- >0;)i[b++]=i[I+o],I++;for(;m-- >0;)i[b++]=i[I++]}}break;case Ae:for(;g>0;){const E=y(e.MAINTREE_table,e.MAINTREE_len,re,V);if(E<0)return T;if(E<F)i[a++]=E,g--;else{const L=E-F;let m=L&Q;if(m===Q){const S=y(e.LENGTH_table,e.LENGTH_len,se,q);if(S<0)return T;m+=S}m+=Ie;let u=L>>3;if(u>2){const S=xe[u];if(u=Ne[u]-2,S>3){const O=p(S-3);u+=O<<3;const ve=y(e.ALIGNED_table,e.ALIGNED_len,ie,Y);if(ve<0)return T;u+=ve}else if(S===3){const O=y(e.ALIGNED_table,e.ALIGNED_len,ie,Y);if(O<0)return T;u+=O}else if(S>0){const O=p(S);u+=O}else u=1;f=l,l=c,c=u}else u===0?u=c:u===1?(u=l,l=c,c=u):(u=f,f=c,c=u);let b=a,I=b-u;if(a+=m,a>o)return T;for(g-=m;I<0&&m-- >0;)i[b++]=i[I+o],I++;for(;m-- >0;)i[b++]=i[I++]}}break;case fe:if(w+g>v)return T;i.set(t.subarray(w,w+g),a),w+=g,a+=g;break;default:return T}}}if(_!==0)return T;const R=(a===0?o:a)-s;if(n.set(i.subarray(R,R+s),0),e.windowPosn=a,e.R0=c,e.R1=l,e.R2=f,e.framesRead++<32768&&e.intelFilesize!==0)if(s<=6||!e.intelStarted)e.intelCurpos+=s;else{let g=0;const E=s-10;let L=e.intelCurpos;const m=e.intelFilesize;for(e.intelCurpos=L+s;g<E;){if(n[g++]!==232){L++;continue}const u=n[g]|n[g+1]<<8|n[g+2]<<16|n[g+3]<<24;if(u>=-L&&u<m){const b=u>=0?u-L:u+m;n[g]=b&255,n[g+1]=b>>8&255,n[g+2]=b>>16&255,n[g+3]=b>>24&255}g+=4,L+=5}}return ge}var Z=(e=>(e[e.Uncompressed=0]="Uncompressed",e[e.Compressed=1]="Compressed",e))(Z||{}),N=(e=>(e[e.Normal=1]="Normal",e[e.Meta=2]="Meta",e[e.Special=4]="Special",e[e.Files=8]="Files",e[e.Dirs=16]="Dirs",e[e.All=31]="All",e))(N||{});const gt="::DataSpace/Storage/MSCompressed/Transform/{7FC28940-9D31-11D0-9B27-00A0C91E9C7C}/InstanceData/ResetTable",wt="::DataSpace/Storage/MSCompressed/ControlData",mt="::DataSpace/Storage/MSCompressed/Content",ue=5;class be{reader;langId=null;dirOffset=0n;dirLen=0n;dataOffset=0n;indexRoot=0;indexHead=0;blockLen=0;compressionEnabled=!1;rtUnit;cnUnit;resetTable;windowSize=0;resetInterval=0;resetBlkCount=0;lzxState=null;lzxLastBlock=-1;cacheBlocks;cacheBlockIndices;cacheNumBlocks;constructor(t){this.reader=t,this.cacheNumBlocks=ue,this.cacheBlocks=new Array(ue).fill(null),this.cacheBlockIndices=new Array(ue).fill(0n)}static async open(t){const n=new be(t);return await n.init(),n}async init(){const t=await this.reader.read(0n,96),n=rt(t);this.langId=n.langId,this.dirOffset=n.dirOffset,this.dirLen=n.dirLen,this.dataOffset=n.dataOffset;const r=await this.reader.read(n.dirOffset,84),s=st(r);this.dirOffset+=BigInt(s.headerLen),this.dirLen-=BigInt(s.headerLen),this.indexRoot=s.indexRoot<=-1?s.indexHead:s.indexRoot,this.indexHead=s.indexHead,this.blockLen=s.blockLen;try{const i=await this.resolve(gt),o=await this.resolve(mt),a=await this.resolve(wt);if(i&&i.space!==Z.Compressed&&o&&o.space!==Z.Compressed&&a&&a.space!==Z.Compressed){const c=await this.fetchBytes(this.dataOffset+i.start,40),l=at(c),f=await this.fetchBytes(this.dataOffset+a.start,Number(a.length)),d=ft(f);this.rtUnit=i,this.cnUnit=o,this.resetTable=l,this.windowSize=d.windowSize,this.resetInterval=d.resetInterval,this.resetBlkCount=d.resetInterval/(d.windowSize/2)*d.windowsPerReset,this.compressionEnabled=!0}}catch{this.compressionEnabled=!1}}getLanguageId(){return this.langId}close(){this.reader.close&&this.reader.close(),this.lzxState=null,this.cacheBlocks.fill(null)}setCacheSize(t){if(t===this.cacheNumBlocks)return;const n=new Array(t).fill(null),r=new Array(t).fill(0n);for(let s=0;s<this.cacheNumBlocks;s++)if(this.cacheBlocks[s]){const i=Number(this.cacheBlockIndices[s]%BigInt(t));n[i]||(n[i]=this.cacheBlocks[s],r[i]=this.cacheBlockIndices[s])}this.cacheBlocks=n,this.cacheBlockIndices=r,this.cacheNumBlocks=t}async fetchBytes(t,n){return this.reader.read(t,n)}parsePmglEntry(t){if(t.remaining===0)return null;const n=t.readCWord(),r=t.readBytes(Number(n)),s=new TextDecoder("utf-8").decode(r),i=Number(t.readCWord()),o=t.readCWord(),a=t.readCWord();return{start:o,length:a,space:i,flags:0,path:s}}findInPmgi(t,n){const r=it(t.subarray(0,8)),s=t.length-r.freeSpace,i=new C(t,8),o=X(n);let a=-1;for(;i.offset<s;){const c=Number(i.readCWord()),l=i.readBytes(c),f=new TextDecoder("utf-8").decode(l);if(X(f)>o)return a;a=Number(i.readCWord())}return a}findInPmgl(t,n){const r=Se(t.subarray(0,20)),s=t.length-r.freeSpace,i=new C(t,20);for(;i.offset<s;){i.offset;const o=Number(i.readCWord()),a=i.readBytes(o),c=new TextDecoder("utf-8").decode(a);if(X(c)===X(n)){const l=Number(i.readCWord()),f=i.readCWord(),d=i.readCWord();return{start:f,length:d,space:l,flags:0,path:c}}i.readCWord(),i.readCWord(),i.readCWord()}return null}async resolve(t){const n=await this.resolveIndexed(t);if(n)return n;const r=X(t);for await(const s of this.enumerate(N.All))if(X(s.path)===r)return s;return null}async resolveIndexed(t){let n=this.indexRoot;for(;n!==-1;){const r=await this.fetchBytes(this.dirOffset+BigInt(n)*BigInt(this.blockLen),this.blockLen),s=String.fromCharCode(r[0],r[1],r[2],r[3]);if(s==="PMGL")return this.findInPmgl(r,t);if(s==="PMGI")n=this.findInPmgi(r,t);else return null}return null}async retrieve(t,n=0n,r){if(n<0n||n>=t.length)return new Uint8Array(0);const s=r!==void 0?n+r>t.length?t.length-n:r:t.length-n;return s<=0n?new Uint8Array(0):t.space===Z.Uncompressed?this.fetchBytes(this.dataOffset+t.start+n,Number(s)):this.compressionEnabled?this.decompressRegion(t.start+n,s):new Uint8Array(0)}async getCmpBlockBounds(t){const n=this.dataOffset+this.rtUnit.start+BigInt(this.resetTable.tableOffset),r=await this.fetchBytes(n+t*8n,8),i=new C(r).readBigUint64LE();let o;if(t<BigInt(this.resetTable.blockCount-1)){const l=await this.fetchBytes(n+t*8n+8n,8);o=new C(l).readBigUint64LE()}else o=this.resetTable.compressedLen;const a=o-i;return{start:i+this.dataOffset+this.cnUnit.start,len:a}}async decompressOneBlock(t){const n=Number(this.resetTable.blockLen),r=t%this.cacheNumBlocks;this.cacheBlocks[r]||(this.cacheBlocks[r]=new Uint8Array(n)),this.cacheBlockIndices[r]=BigInt(t);const s=this.cacheBlocks[r],{start:i,len:o}=await this.getCmpBlockBounds(BigInt(t)),a=await this.fetchBytes(i,Number(o));let c=Ue(this.lzxState,a,s,Number(o),n);if(c!==ge&&(console.warn(`LZX decompression error code ${c} for block ${t}, retrying after reset`),this.lzxState.reset(),c=Ue(this.lzxState,a,s,Number(o),n),c!==ge)){const l=Array.from(a.subarray(0,Math.min(32,a.length))).map(f=>f.toString(16).padStart(2,"0")).join(" ");throw new Error(`LZX decompression failed for block ${t}: code ${c}. firstBytes=${l}`)}this.lzxLastBlock=t}async decompressBlock(t){const n=Number(t);if(!this.lzxState){let s=0,i=this.windowSize;for(;i>1;)i>>>=1,s++;this.lzxState=new ut(s),this.lzxLastBlock=-1}let r=n%this.resetBlkCount;if(n-r<=this.lzxLastBlock&&n>=this.lzxLastBlock&&(r=n-this.lzxLastBlock),r!==0)for(let s=r;s>0;s--){const i=n-s;this.lzxLastBlock!==i&&(i%this.resetBlkCount===0&&this.lzxState.reset(),await this.decompressOneBlock(i))}else n%this.resetBlkCount===0&&this.lzxState.reset();return await this.decompressOneBlock(n),this.cacheBlocks[n%this.cacheNumBlocks]}async decompressRegion(t,n){if(n<=0n)return new Uint8Array(0);const r=this.resetTable.blockLen,s=new Uint8Array(Number(n));let i=0n,o=n,a=t;for(;o>0n;){const c=a/r,l=a%r;let f=o;f>r-l&&(f=r-l);const d=Number(c%BigInt(this.cacheNumBlocks));if(this.cacheBlocks[d]!==null&&this.cacheBlockIndices[d]===c)s.set(this.cacheBlocks[d].subarray(Number(l),Number(l+f)),Number(i));else{const h=await this.decompressBlock(c);s.set(h.subarray(Number(l),Number(l+f)),Number(i))}i+=f,o-=f,a+=f}return s}async*enumerate(t=N.All){let n=this.indexHead;for(;n!==-1;){const r=await this.fetchBytes(this.dirOffset+BigInt(n)*BigInt(this.blockLen),this.blockLen),s=Se(r.subarray(0,20)),i=r.length-s.freeSpace,o=new C(r,20);for(;o.offset<i;){const a=this.parsePmglEntry(o);if(!a)break;a.flags=pt(a.path),Pe(a.flags,t)&&(yield a)}n=s.blockNext}}async*enumerateDir(t,n=N.All){let r=t;r.length>0&&!r.endsWith("/")&&(r+="/");let s=!1;for await(const i of this.enumerate(N.All)){if(s){if(!i.path.toLowerCase().startsWith(r.toLowerCase()))break}else if(i.length===0n&&i.path.toLowerCase().startsWith(r.toLowerCase())){if(s=!0,i.path.length===r.length)continue}else continue;Pe(i.flags,n)&&(yield i)}}async getSystemRaw(){const t=await this.resolve("/#SYSTEM");return t?this.retrieve(t):null}}function pt(e){let t=0;return e[e.length-1]==="/"?t|=N.Dirs:t|=N.Files,e[0]==="/"?e.length>1&&(e[1]==="#"||e[1]==="$")?t|=N.Special:t|=N.Normal:t|=N.Meta,t}function Pe(e,t){const n=t&7,r=t&248;return!(!(n&e)||r&&!(r&e))}function X(e){return e.toLowerCase()}function Et(e){return{read(t,n){const r=Number(t),s=Math.min(r+n,e.length);return Promise.resolve(e.slice(r,s))}}}function J(e,t={}){const n=t.charset?.trim();if(n)return{text:D(e,n),encoding:n,source:"explicit"};const r=Lt(e);if(r)return{text:D(e,r),encoding:r,source:"bom"};const s=bt(e);if(s)return{text:D(e,s),encoding:s,source:"utf16-heuristic"};const i=yt(e);if(i)return{text:D(e,i.encoding),encoding:i.encoding,source:i.source};if(vt(e))return{text:new TextDecoder("utf-8").decode(e),encoding:"utf-8",source:"utf8"};try{const o=new TextDecoder("gb18030").decode(e);if(/[\u4e00-\u9fff]/.test(o))return{text:o,encoding:"gb18030",source:"fallback"}}catch{}return{text:D(e,"windows-1252"),encoding:"windows-1252",source:"fallback"}}function ye(e,t){const n=J(e);if(n.source!=="fallback"||!t)return n;const r=Xe(t);if(!r)return n;try{return{text:D(e,r),encoding:r,source:"lang-hint"}}catch{return n}}function Xe(e){switch(e&65535){case 2052:case 2052:return"gb18030";case 1028:case 1028:return"big5";case 1041:case 1041:return"shift_jis";case 1042:case 1042:return"euc-kr";case 1049:case 1049:return"windows-1251";case 1050:case 1050:return"windows-1250";default:return"windows-1252"}}function D(e,t){try{return new TextDecoder(t).decode(e)}catch(n){throw new Error(`Unsupported charset: ${t}`,{cause:n})}}function Lt(e){return e.length>=3&&e[0]===239&&e[1]===187&&e[2]===191?"utf-8":e.length>=2&&e[0]===255&&e[1]===254?"utf-16le":e.length>=2&&e[0]===254&&e[1]===255?"utf-16be":null}function bt(e){const t=Math.min(e.length,256);if(t<8)return null;let n=0,r=0;for(let o=0;o<t;o++)e[o]===0&&(o%2===0?n++:r++);const s=n/Math.ceil(t/2),i=r/Math.max(1,Math.floor(t/2));return i>.3&&s<.05?"utf-16le":s>.3&&i<.05?"utf-16be":null}function yt(e){const t=Bt(e),n=/<\?xml[^>]+encoding\s*=\s*["']([^"']+)["']/iu.exec(t);if(n?.[1])return{encoding:n[1],source:"xml"};const r=/<meta[^>]+charset\s*=\s*["']?\s*([^"'>\s;]+)/iu.exec(t);if(r?.[1])return{encoding:r[1],source:"meta"};const s=/<meta[^>]+content\s*=\s*["'][^"']*charset\s*=\s*([^"'>\s;]+)/iu.exec(t);return s?.[1]?{encoding:s[1],source:"meta"}:null}function Bt(e){const t=Math.min(e.length,4096);let n="";for(let r=0;r<t;r++){const s=e[r];n+=s>=32&&s<=126?String.fromCharCode(s):" "}return n}function vt(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e),!0}catch{return!1}}const _t=Object.freeze(Object.defineProperty({__proto__:null,decodeText:J,decodeTextWithLangHint:ye,guessEncodingForLangId:Xe},Symbol.toStringTag,{value:"Module"}));function Rt(e,t){const n=new C(e),r={};if(n.remaining<4)return r;for(n.readUint32LE();n.remaining>=4;){const s=n.readUint16LE(),i=n.readUint16LE();if(n.remaining<i)break;const o=n.readBytes(i);switch(s){case 0:r.tocFile=W(o,t);break;case 1:r.indexFile=W(o,t);break;case 2:r.defaultTopic=W(o,t);break;case 3:r.title=W(o,t);break;case 4:r.defaultWindow=W(o,t);break;case 5:r.compiledFile=W(o,t);break;case 6:if(o.length>=4){const a=new C(o);r.binaryToc=a.readUint32LE()!==0}break;case 7:if(o.length>=4){const a=new C(o);r.binaryIndex=a.readUint32LE()!==0}break;case 9:r.compilerVersion=W(o,t);break;case 16:r.defaultFont=W(o,t);break}}return r}function W(e,t){let n=e.length;for(;n>0&&e[n-1]===0;)n--;return ye(e.subarray(0,n),t).text}function Tt(e){return{entries:De(e,0).entries}}function De(e,t){const n=[];let r=t;const s=e.length;for(;r<s;){const i=e.indexOf("<",r);if(i===-1)break;const o=e.indexOf(">",i);if(o===-1)break;const c=e.slice(i,o+1).toLowerCase();if(c.startsWith("<li")){r=o+1;const l=kt(e,r);n.push(l.entry),r=l.endPos}else{if(c.startsWith("</ul")||c.startsWith("</ol"))return{entries:n,endPos:o+1};c.startsWith("<ul")||c.startsWith("<ol"),r=o+1}}return{entries:n,endPos:s}}function kt(e,t){const n=e.length;let r=t,s="",i;const o=[];for(;r<n;){const c=e.indexOf("<",r);if(c===-1)break;const l=e.indexOf(">",c);if(l===-1)break;const d=e.slice(c,l+1).toLowerCase();if(d.includes('type="text/sitemap"')||d.includes("type='text/sitemap'")){r=l+1;const h=St(e,r);s=h.name??s,i=h.local??i,r=h.endPos}else if(d.startsWith("<ul")||d.startsWith("<ol")){r=l+1;const h=De(e,r);o.push(...h.entries),r=h.endPos}else if(d.startsWith("</li")){r=l+1;break}else{if(d.startsWith("<li"))break;if(d.startsWith("</ul")||d.startsWith("</ol"))break;r=l+1}}const a={name:s,children:o};return i!==void 0&&(a.local=i),{entry:a,endPos:r}}function St(e,t){const n=e.length;let r=t,s,i;for(;r<n;){const o=e.indexOf("<",r);if(o===-1)break;const a=e.indexOf(">",o);if(a===-1)break;const c=e.slice(o,a+1),l=c.toLowerCase();if(l.startsWith("<param")){const f=Me(c,"name"),d=Me(c,"value");if(f!==null&&d!==null){const h=f.toLowerCase();h==="name"?s=d:h==="local"&&(i=d)}r=a+1}else if(l.startsWith("</object")){r=a+1;break}else r=a+1}return{name:s,local:i,endPos:r}}function Me(e,t){const r=new RegExp(`${t}\\s*=\\s*(?:"([^"]*)"|\\'([^\\']*)\\'|(\\S+))`,"i").exec(e);return r?r[1]??r[2]??r[3]??null:null}async function It(e,t,n={}){const r=t.map(i=>i.toLowerCase()),s=[];for await(const i of e.enumerate(N.All)){if(!(i.flags&N.Files))continue;const o=G(i.path);r.some(a=>o.endsWith(a))&&s.push(i.path)}return xt(s,n.prefer??[])}async function Ct(e,t){return It(e,[".hhc"],{prefer:At(t,".hhc")})}function At(e,t){if(!e)return[];const n=new Set;if(e.tocFile&&n.add(e.tocFile),e.compiledFile&&n.add(`/${$e(e.compiledFile)}${t}`),e.defaultTopic){const r=Be(e.defaultTopic);r.length>0&&n.add(`/${$e(r)}${t}`)}return[...n]}function xt(e,t){if(e.length===0)return null;const n=new Set(t.map(s=>G(s))),r=new Set(t.map(s=>G(Be(s))));return[...e].sort((s,i)=>{const o=Oe(s,n,r),a=Oe(i,n,r);if(o!==a)return a-o;const c=We(s),l=We(i);return c!==l?c-l:s.length!==i.length?s.length-i.length:G(s).localeCompare(G(i))})[0]??null}function Oe(e,t,n){const r=G(e),s=G(Be(e));return t.has(r)?3:n.has(s)?2:1}function We(e){return e.split("/").filter(Boolean).length}function $e(e){return e.replace(/\.[^.]+$/u,"")}function Be(e){const t=e.split("/");return t[t.length-1]??e}function G(e){return e.toLowerCase()}const Nt='<svg class="toc-icon" viewBox="0 0 24 24" width="14" height="14" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg"><path d="M9 6 L15 12 L9 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function Ut(e,t){for(const s of e.querySelectorAll(".toc-label.active"))s.classList.remove("active");const n=t.toLowerCase().split("#")[0],r=e.querySelectorAll(".toc-label.toc-link");for(const s of r){const i=s.closest("li");if(!i)continue;const o=i.dataset.path;if(o&&o.toLowerCase()===n){s.classList.add("active");let a=i.parentElement?.closest("li");for(;a;){a.classList.add("open");const c=a.querySelector(":scope > .toc-toggle");c&&c.setAttribute("aria-expanded","true"),a=a.parentElement?.closest("li")}s.scrollIntoView({block:"nearest"});break}}}function Pt(e,t,n){if(e.innerHTML="",t.entries.length===0){e.textContent="(No TOC)";return}const r=Fe(t.entries,n);e.appendChild(r)}function Fe(e,t){const n=document.createElement("ul");for(const r of e)n.appendChild(Mt(r,t));return n}function Mt(e,t){const n=document.createElement("li");if(e.local){const i=e.local.startsWith("/")?e.local:"/"+e.local;n.dataset.path=i.toLowerCase().split("#")[0]}const r=e.children.length>0;if(r){const i=document.createElement("span");i.className="toc-toggle",i.innerHTML=Nt,i.setAttribute("aria-label","toggle"),i.setAttribute("role","button"),i.setAttribute("tabindex","0"),i.setAttribute("aria-expanded","false"),n.appendChild(i),i.addEventListener("click",o=>{o.stopPropagation();const a=n.classList.toggle("open");i.setAttribute("aria-expanded",String(a))}),i.addEventListener("keydown",o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),i.click())})}else{const i=document.createElement("span");i.className="toc-spacer",n.appendChild(i)}const s=document.createElement("span");if(s.className="toc-label",s.textContent=e.name||"(Untitled)",e.local){s.classList.add("toc-link");const i=e.local.startsWith("/")?e.local:"/"+e.local;s.addEventListener("click",()=>t(i))}if(n.appendChild(s),r){const i=Fe(e.children,t);n.appendChild(i)}return n}function ae(e,t){const n=t.split("#")[0];if(!n)return e;if(n.startsWith("/"))return n;const s=e.substring(0,e.lastIndexOf("/")+1)+n,i=[];for(const o of s.split("/"))o===".."?i.pop():o!=="."&&i.push(o);return i.join("/")}function Ot(e){const t=e.split(".").pop()?.toLowerCase()??"";return{html:"text/html",htm:"text/html",css:"text/css",js:"text/javascript",png:"image/png",gif:"image/gif",jpg:"image/jpeg",jpeg:"image/jpeg",svg:"image/svg+xml",ico:"image/x-icon",woff:"font/woff",woff2:"font/woff2",ttf:"font/ttf",eot:"application/vnd.ms-fontobject"}[t]??"application/octet-stream"}async function we(e,t,n){const r=t.toLowerCase();if(n.has(r))return n.get(r);const s=await e.resolve(t);if(!s)return null;const i=await e.retrieve(s),o=Ot(t);let a;if(o==="text/css"){const{text:l}=J(i),f=await me(e,l,t,n);a=new Blob([f],{type:o})}else{const l=new ArrayBuffer(i.byteLength);new Uint8Array(l).set(i),a=new Blob([l],{type:o})}const c=URL.createObjectURL(a);return n.set(r,c),c}async function me(e,t,n,r){const s=/url\(\s*(['"]?)([^)"']+)\1\s*\)/gi,i=[];for(const a of t.matchAll(s)){const c=a[2].trim();if(c.startsWith("data:")||c.startsWith("http://")||c.startsWith("https://"))continue;const l=ae(n,c),f=await we(e,l,r);f&&i.push({match:a[0],replacement:`url("${f}")`})}let o=t;for(const{match:a,replacement:c}of i)o=o.replaceAll(a,c);return o}async function Wt(e,t,n,r){const s=[];async function i(l,f,d=!1){for(const h of t.matchAll(l)){const w=h.index+h[0].indexOf(h[1]),v=w+h[1].length,k=h[2].trim();if(k.startsWith("data:")||k.startsWith("http://")||k.startsWith("https://")||k.startsWith("//")||k.startsWith("javascript:")||k.startsWith("#")||k==="")continue;const U=ae(n,k),A=await we(e,U,r);if(A)s.push({start:w,end:v,value:`"${A}"`});else if(d){const p=t.lastIndexOf("<img",w),y=t.indexOf(">",v);if(p!==-1&&y!==-1){const B=t.slice(p,y);let _=B;/style=/i.test(B)||(_=_.replace(/<img/i,'<img style="border:2px solid red"')),/title=/i.test(B)||(_=_.replace(/<img/i,`<img title="Image not found: ${U}"`)),s.push({start:p,end:y,value:_})}}}}await i(/\bsrc\s*=\s*("([^"]*)")/gi,!1,!0),await i(/\bsrc\s*=\s*('([^']*)')/gi,!1,!0),await i(/\bbackground\s*=\s*("([^"]*)")/gi),await i(/\bbackground\s*=\s*('([^']*)')/gi);const o=/<link([^>]*?)href\s*=\s*(['"])([^"']+?)\2([^>]*)>/gi;for(const l of t.matchAll(o)){const f=l[0],d=l[1],h=l[3].trim(),w=l[4];if(!h||h.startsWith("data:")||h.startsWith("http://")||h.startsWith("https://")||h.startsWith("//")||h.startsWith("#"))continue;const v=(d+" "+w).match(/rel\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+))/i),k=v?(v[1]||v[2]||v[3]||"").toLowerCase():"",U=l.index,A=U+f.length,p=ae(n,h);if(k.includes("stylesheet")||/rel\s*=\s*stylesheet/i.test(d+w)){const y=await e.resolve(p);if(!y)continue;const B=await e.retrieve(y),_=J(B).text,R=await me(e,_,p,r);s.push({start:U,end:A,value:`<style>${R}</style>`})}else{const y=await we(e,p,r);if(y){const B=f.indexOf(h),_=U+B,R=_+h.length;s.push({start:_,end:R,value:y})}}}const a=/\bstyle\s*=\s*"([^"]*)"/gi;for(const l of t.matchAll(a)){const f=l[1];if(!f.includes("url("))continue;const d=await me(e,f,n,r);if(d!==f){const h=l.index,w=h+l[0].length;s.push({start:h,end:w,value:`style="${d}"`})}}if(s.length===0)return t;s.sort((l,f)=>f.start-l.start);let c=t;for(const{start:l,end:f,value:d}of s)c=c.slice(0,l)+d+c.slice(f);return c}const $t=`
|
|
<script data-chm-nav>
|
|
(function() {
|
|
document.addEventListener('click', function(e) {
|
|
var target = e.target;
|
|
while (target && target.tagName !== 'A') target = target.parentElement;
|
|
if (!target) return;
|
|
var href = target.getAttribute('href');
|
|
if (!href) return;
|
|
if (href.startsWith('http://') || href.startsWith('https://') || href.startsWith('//')) return;
|
|
if (href.startsWith('javascript:')) return;
|
|
e.preventDefault();
|
|
window.parent.postMessage({ type: 'chm-navigate', href: href }, '*');
|
|
}, true);
|
|
})();
|
|
<\/script>
|
|
`;function zt(e){return e=e.replace(/style\s*=\s*"([^"]*)"/gi,(t,n)=>{let r=n;return r=r.replace(/(margin(?:-(?:top|right|bottom|left))?)\s*:\s*([-+]?\d*\.?\d+)([a-z%]*)/gi,(s,i,o,a)=>/^\s*-/.test(o)?`${i}:0${a}`:s),r=r.replace(/margin\s*:\s*([^;]*)/gi,(s,i)=>/[-]\s*\d/.test(i)?"margin:0":s),`style="${r}"`}),e=e.replace(/style\s*=\s*'([^']*)'/gi,(t,n)=>{let r=n;return r=r.replace(/(margin(?:-(?:top|right|bottom|left))?)\s*:\s*([-+]?\d*\.?\d+)([a-z%]*)/gi,(s,i,o,a)=>/^\s*-/.test(o)?`${i}:0${a}`:s),r=r.replace(/margin\s*:\s*([^;]*)/gi,(s,i)=>/[-]\s*\d/.test(i)?"margin:0":s),`style='${r}'`}),e=e.replace(/<style\b[^>]*>([\s\S]*?)<\/style>/gi,(t,n)=>{let r=n;return r=r.replace(/(margin(?:-(?:top|right|bottom|left))?)\s*:\s*([^;}]*)/gi,(s,i,o)=>/[-]\s*\d/.test(o)?`${i}:0`:s),r=r.replace(/margin\s*:\s*([^;}]*)/gi,(s,i)=>/[-]\s*\d/.test(i)?"margin:0":s),`<style>${r}</style>`}),e}async function Ht(e,t,n,r){const s=await e.resolve(t);if(!s){n.innerHTML=`<div style="font-family:sans-serif;color:#c00;padding:2em">Page not found: ${Gt(t)}</div>`;return}const i=await e.retrieve(s),o=e.getLanguageId?e.getLanguageId():void 0,{text:a}=o!=null?ye(i,o):J(i),c=await Wt(e,a,t,r),l=zt(c),f=document.createElement("div");f.className="chm-host-wrapper";const d=f.attachShadow({mode:"open"}),h=`:host { all: initial; display: block; width:100%; height:100%; }
|
|
:host * { box-sizing: border-box; }
|
|
`,w=document.createElement("style");w.textContent=h,d.appendChild(w);const v=document.createElement("div");v.className="chm-host",v.style.width="100%",v.style.height="100%",v.innerHTML=l;const k=document.createElement("script");k.setAttribute("data-chm-nav",""),k.textContent=$t,d.appendChild(k),d.appendChild(v),n.innerHTML="",n.appendChild(f),d.addEventListener("click",A=>{let p=A.target;for(;p&&p.tagName!=="A";)p=p.parentElement;if(!p)return;const B=p.getAttribute("href");B&&(B.startsWith("http://")||B.startsWith("https://")||B.startsWith("//")||B.startsWith("javascript:")||(A.preventDefault(),window.postMessage({type:"chm-navigate",href:B},"*")))},!0);function U(A){const p=A.shadowRoot;if(!p)return;const y=p.querySelector(".chm-host");y&&requestAnimationFrame(()=>{const B=A.getBoundingClientRect(),_=Array.from(y.querySelectorAll("*"));for(const R of _){const g=R.getBoundingClientRect();if(g.left<B.left){const E=Math.ceil(B.left-g.left);if(!R.dataset.chmOrigTransform){const m=getComputedStyle(R);R.dataset.chmOrigTransform=m.transform&&m.transform!=="none"?m.transform:""}const L=R.dataset.chmOrigTransform||"";R.style.transform=`${L} translateX(${E}px)`.trim(),R.dataset.chmShifted="1"}else R.dataset.chmShifted&&(R.style.transform=R.dataset.chmOrigTransform||"",delete R.dataset.chmShifted,delete R.dataset.chmOrigTransform)}})}U(f),d.addEventListener("load",()=>U(f),!0)}function Gt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}const z=document.getElementById("drop-zone"),he=document.getElementById("file-input"),Xt=document.getElementById("title"),oe=document.getElementById("toc-container"),ze=document.getElementById("content-html"),He=document.getElementById("status"),Dt=document.getElementById("viewer"),Ft=document.getElementById("welcome"),Ze=document.getElementById("back-btn"),je=document.getElementById("fwd-btn"),Zt=document.getElementById("resizer"),Ve=document.getElementById("sidebar");let x=null,pe="";const $=[];let M=-1;const H=new URLSearchParams(location.search),jt=!!window.__CHM2HTML_PLUGIN||H.get("plugin")==="1"||document.body.dataset.plugin==="1",Ee=new Map;async function K(e,t=!0){if(!x)return;const[n,r]=Vt(e),s=n||pe;P("Loading…");try{if(await Ht(x,s,ze,Ee),pe=s,t&&($.splice(M+1),$.push(e),M=$.length-1),qt(),Ut(oe,s),r){const i=ze.querySelector(`#${CSS.escape(r)}, [name="${r}"]`);i&&i.scrollIntoView()}P("")}catch(i){P(`Error: ${String(i)}`)}}function Vt(e){const t=e.indexOf("#");return t===-1?[e,""]:[e.slice(0,t),e.slice(t+1)]}function qt(){Ze.disabled=M<=0,je.disabled=M>=$.length-1}window.addEventListener("message",e=>{if(e.data){if(e.data.type==="chm-navigate"){const t=String(e.data.href),n=ae(pe,t);K(n);return}if(e.data.type==="open-chm"){const t=e.data.payload||{};qe(t).catch(n=>P(`Failed to open: ${String(n)}`));return}}});window.chrome&&window.chrome.webview&&typeof window.chrome.webview.addEventListener=="function"&&window.chrome.webview.addEventListener("message",e=>{const t=e.data;t&&t.type==="open-chm"&&qe(t.payload||{}).catch(n=>P(`Failed to open: ${String(n)}`))});async function qe(e){if(e.base64){const t=Ye(e.base64);await le(t,e.name||"file.chm");return}if(e.url){await Le(e.url,e.name);return}if(e.path){await Le(e.path,e.name);return}throw new Error("Unsupported payload for open-chm")}function Ye(e){const t=atob(e),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.charCodeAt(s);return r.buffer}async function Le(e,t){P("Fetching CHM…");const n=await fetch(e);if(!n.ok)throw new Error(`Fetch failed: ${n.status} ${n.statusText}`);const r=await n.arrayBuffer();await le(r,t||Yt(e))}function Yt(e){try{return new URL(e).pathname.split("/").pop()||e}catch{return e}}Ze.addEventListener("click",()=>{M>0&&(M--,K($[M],!1))});je.addEventListener("click",()=>{M<$.length-1&&(M++,K($[M],!1))});async function le(e,t){P("Parsing CHM file…");for(const n of Ee.values())URL.revokeObjectURL(n);Ee.clear(),x&&(x.close(),x=null),$.length=0,M=-1;try{const n=new Uint8Array(e);x=await be.open(Et(n));const r=await x.getSystemRaw(),s=r?Rt(r,x.getLanguageId()??void 0):{},i=s.title||t;Xt.textContent=i,document.title=`chm2html — ${i}`,oe.innerHTML='<p class="toc-loading">Loading TOC…</p>';const o=await Ct(x,s);if(o){const c=await x.resolve(o);if(c){const l=await x.retrieve(c),f=(await nt(async()=>{const{decodeTextWithLangHint:h}=await Promise.resolve().then(()=>_t);return{decodeTextWithLangHint:h}},void 0)).decodeTextWithLangHint(l,x.getLanguageId()??void 0).text,d=Tt(f);Pt(oe,d,h=>K(h))}}else oe.innerHTML='<p class="toc-loading">(No TOC)</p>';const a=s.defaultTopic||await Kt(x);a&&await K(a.startsWith("/")?a:"/"+a),Ft.hidden=!0,Dt.hidden=!1,P("")}catch(n){P(`Failed to open: ${String(n)}`),console.error(n)}}async function Kt(e){for await(const t of e.enumerate(N.All)){const n=t.path.toLowerCase();if(n.endsWith(".html")||n.endsWith(".htm"))return t.path}return null}he.addEventListener("change",()=>{const e=he.files?.[0];e&&Ke(e),he.value=""});z.addEventListener("dragover",e=>{e.preventDefault(),z.classList.add("drag-over")});z.addEventListener("dragleave",()=>{z.classList.remove("drag-over")});z.addEventListener("drop",e=>{e.preventDefault(),z.classList.remove("drag-over");const t=e.dataTransfer?.files[0];t&&Ke(t)});function Ke(e){const t=new FileReader;t.onload=()=>le(t.result,e.name),t.onerror=()=>P(`Read file failed: ${e.name}`),t.readAsArrayBuffer(e)}let ce=!1,Je=0,Qe=0;Zt.addEventListener("mousedown",e=>{ce=!0,Je=e.clientX,Qe=Ve.offsetWidth,document.body.style.cursor="col-resize",document.body.style.userSelect="none",e.preventDefault()});document.addEventListener("mousemove",e=>{if(!ce)return;const t=e.clientX-Je,n=Math.max(150,Math.min(600,Qe+t));Ve.style.width=n+"px"});document.addEventListener("mouseup",()=>{ce&&(ce=!1,document.body.style.cursor="",document.body.style.userSelect="")});function P(e){He.textContent=e,He.hidden=!e}if(jt){try{z&&(z.hidden=!0)}catch{}try{const e=document.getElementById("open-btn");e&&(e.hidden=!0)}catch{}(async()=>{const e=H.get("chm")||H.get("chmUrl")||H.get("url"),t=H.get("chmBase64")||H.get("base64"),n=H.get("name")||void 0;try{if(t){const r=Ye(t);await le(r,n||"file.chm")}else e?await Le(e,n):P("Waiting for host to provide CHM…")}catch(r){P(`Plugin open failed: ${String(r)}`)}})()}
|
|
|
|
</script>
|
|
|
|
<style>/* inlined assets/app-EEkus9An.css */
|
|
*,*:before,*:after{box-sizing:border-box;margin:0;padding:0}[hidden]{display:none!important}html{height:100%;overflow:hidden}body{height:100%;overflow:hidden;display:flex;flex-direction:column;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:14px;background:#f5f5f5;color:#222}#toolbar{display:flex;align-items:center;height:42px;padding:0 12px;background:#2c2c2c;color:#eee;gap:8px;flex-shrink:0;user-select:none;position:relative;z-index:10}#toolbar-left{display:flex;align-items:center;gap:4px}#toolbar-right{margin-left:auto;display:flex;align-items:center}.toolbar-title{position:absolute;left:50%;transform:translate(-50%);max-width:50%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;pointer-events:none}.btn{padding:5px 12px;border:1px solid #555;border-radius:4px;background:#3a3a3a;color:#eee;cursor:pointer;font-size:13px;line-height:1.4;transition:background .15s,border-color .15s}.btn:hover:not(:disabled){background:#505050;border-color:#888}.btn:disabled{opacity:.35;cursor:default}.btn.icon-btn{padding:5px 9px}.btn-large{padding:10px 24px;font-size:15px}#status{font-size:12px;color:#ffd;padding:0 8px}#welcome{display:flex;align-items:center;justify-content:center;flex:1;min-height:0;overflow:auto}#drop-zone{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;width:400px;max-width:90vw;padding:48px 32px;border:2px dashed #ccc;border-radius:12px;background:#fff;transition:border-color .2s,background .2s}#drop-zone.drag-over{border-color:#2196f3;background:#e3f2fd}.drop-icon{font-size:48px}.drop-primary{font-size:16px;color:#444}.drop-secondary{font-size:13px;color:#999}#viewer{display:flex;flex:1;min-height:0;overflow:hidden}#sidebar{display:flex;flex-direction:column;width:280px;min-width:150px;max-width:600px;min-height:0;background:#fafafa;border-right:1px solid #ddd;overflow:hidden}#toc-header{padding:8px 12px;font-weight:600;font-size:12px;text-transform:uppercase;letter-spacing:.05em;color:#666;border-bottom:1px solid #e0e0e0;flex-shrink:0}#toc-container{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;padding:6px 0}.toc-loading{padding:12px;color:#888;font-style:italic}#toc-container ul{list-style:none;padding:0;margin:0}#toc-container li{display:flex;flex-direction:column}#toc-container li>.toc-toggle,#toc-container li>.toc-spacer,#toc-container li>.toc-label{display:inline-block}#toc-container li{flex-direction:row;flex-wrap:wrap;align-items:flex-start}#toc-container li>ul{display:none;width:100%;padding-left:18px}#toc-container li.open>ul{display:block}.toc-toggle{flex-shrink:0;width:18px;font-size:10px;cursor:pointer;color:#888;padding:5px 2px;user-select:none}.toc-toggle:hover{color:#333}.toc-spacer{flex-shrink:0;width:18px}.toc-label{flex:1;padding:4px 8px 4px 2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px;color:#333;cursor:default}.toc-label.toc-link{cursor:pointer;color:#1565c0}.toc-label.toc-link:hover{text-decoration:underline;background:#e8f0fe;border-radius:3px}.toc-label.active{background:#1565c0;color:#fff;border-radius:3px}.toc-label.active:hover{background:#0f4a86;color:#fff;text-decoration:none}#resizer{width:2px;cursor:col-resize;background:#ddd;transition:background .15s,box-shadow .12s;flex-shrink:0;position:relative}#resizer:before{content:"";position:absolute;inset:0 -9px;background:transparent;cursor:col-resize}#resizer:hover,#resizer:active{background:#2196f3;box-shadow:0 0 0 1px #2196f314 inset}#content{flex:1;min-height:0;min-width:0;overflow:hidden;position:relative}#content-frame{width:100%;height:100%;border:none;background:#fff}#content-html{background:#fff;min-height:0}.chm-host,.chm-host *{all:revert}.chm-host{display:block;width:100%;height:100%;min-height:0}.icon,.toc-icon{vertical-align:middle;display:inline-block}.icon{width:18px;height:18px}.btn.icon-btn svg,.icon,.toc-icon{width:18px;height:18px}.btn.icon-btn svg path,.icon path,.toc-icon path{stroke:currentColor;fill:none}.toc-toggle{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;margin-right:6px}.toc-spacer{display:inline-block;width:20px;height:20px;margin-right:6px}.toc-toggle .toc-icon{transition:transform .18s cubic-bezier(.4,0,.2,1);transform-origin:50% 50%;display:block}#toc-container li.open>.toc-toggle .toc-icon,.toc-toggle[aria-expanded=true] .toc-icon{transform:rotate(90deg)}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Top toolbar (no Open control in plugin mode) -->
|
|
<header id="toolbar">
|
|
<div id="toolbar-left">
|
|
<button id="back-btn" class="btn icon-btn" disabled title="Back" aria-label="Back">
|
|
<svg class="icon" viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M15 6 L9 12 L15 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
</button>
|
|
<button id="fwd-btn" class="btn icon-btn" disabled title="Forward" aria-label="Forward">
|
|
<svg class="icon" viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M9 6 L15 12 L9 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
<span id="title" class="toolbar-title">chm2html</span>
|
|
<div id="toolbar-right">
|
|
<div id="status" hidden></div>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- Welcome hidden in plugin mode (host will supply file) -->
|
|
<div id="welcome" hidden>
|
|
<div id="drop-zone">
|
|
<div class="drop-icon">📄</div>
|
|
<p class="drop-primary">Drop a <strong>.chm</strong> file here</p>
|
|
<p class="drop-secondary">or</p>
|
|
<label class="btn btn-large" id="open-btn-welcome" for="file-input" style="cursor:pointer">Choose file…</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Main viewer (visible) -->
|
|
<div id="viewer">
|
|
<div id="sidebar">
|
|
<div id="toc-header">Contents</div>
|
|
<div id="toc-container"></div>
|
|
</div>
|
|
<div id="resizer"></div>
|
|
<div id="content">
|
|
<div id="content-html" tabindex="0" style="width:100%;height:100%;outline:none;overflow:auto;"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Hidden file input kept for compatibility (host may not use it) -->
|
|
<input id="file-input" type="file" accept=".chm" style="display:none" />
|
|
|
|
|
|
</body>
|
|
</html>
|