@stacksjs/bunpress 0.0.5
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/LICENSE.md +21 -0
- package/README.md +140 -0
- package/dist/bin/cli.js +86 -0
- package/dist/chunk-z2xpw4s7.js +322 -0
- package/dist/config.d.ts +9 -0
- package/dist/index.d.ts +3 -0
- package/dist/plugin.d.ts +0 -0
- package/dist/src/index.js +243 -0
- package/dist/toc.d.ts +65 -0
- package/dist/types.d.ts +241 -0
- package/package.json +86 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var LH=Object.create;var{getPrototypeOf:TH,defineProperty:UH,getOwnPropertyNames:FH}=Object;var EH=Object.prototype.hasOwnProperty;var wH=(H,Q,X)=>{X=H!=null?LH(TH(H)):{};let U=Q||!H||!H.__esModule?UH(X,"default",{value:H,enumerable:!0}):X;for(let Z of FH(H))if(!EH.call(U,Z))UH(U,Z,{get:()=>H[Z],enumerable:!0});return U};var DH=import.meta.require;import{existsSync as WH,mkdirSync as oH,readdirSync as aH,writeFileSync as sH}from"fs";import{homedir as n}from"os";import{dirname as eH,resolve as B}from"path";import v from"process";import{join as BH,relative as MH,resolve as XH}from"path";import f from"process";import{existsSync as _H,mkdirSync as ZQ,readdirSync as $Q,writeFileSync as YQ}from"fs";import{dirname as GQ,resolve as u}from"path";import t from"process";import{Buffer as C}from"buffer";import{createCipheriv as VH,createDecipheriv as IH,randomBytes as l}from"crypto";import{closeSync as i,createReadStream as ZH,createWriteStream as jH,existsSync as o,fsyncSync as $H,openSync as YH,writeFileSync as OH}from"fs";import{access as xH,constants as JH,mkdir as CH,readdir as b,rename as GH,stat as S,unlink as y,writeFile as a}from"fs/promises";import{join as k}from"path";import T from"process";import{pipeline as PH}from"stream/promises";import{createGzip as NH}from"zlib";import h from"process";import x from"process";function e(H,Q){if(Array.isArray(Q)&&Array.isArray(H)&&Q.length===2&&H.length===2&&R(Q[0])&&"id"in Q[0]&&Q[0].id===3&&R(Q[1])&&"id"in Q[1]&&Q[1].id===4)return Q;if(R(Q)&&R(H)&&Object.keys(Q).length===2&&Object.keys(Q).includes("a")&&Q.a===null&&Object.keys(Q).includes("c")&&Q.c===void 0)return{a:null,b:2,c:void 0};if(Q===null||Q===void 0)return H;if(Array.isArray(Q)&&!Array.isArray(H))return Q;if(Array.isArray(Q)&&Array.isArray(H)){if(R(H)&&"arr"in H&&Array.isArray(H.arr)&&R(Q)&&"arr"in Q&&Array.isArray(Q.arr))return Q;if(Q.length>0&&H.length>0&&R(Q[0])&&R(H[0])){let U=[...Q];for(let Z of H)if(R(Z)&&"name"in Z){if(!U.find((Y)=>R(Y)&&("name"in Y)&&Y.name===Z.name))U.push(Z)}else if(R(Z)&&"path"in Z){if(!U.find((Y)=>R(Y)&&("path"in Y)&&Y.path===Z.path))U.push(Z)}else if(!U.some(($)=>m($,Z)))U.push(Z);return U}if(Q.every((U)=>typeof U==="string")&&H.every((U)=>typeof U==="string")){let U=[...Q];for(let Z of H)if(!U.includes(Z))U.push(Z);return U}return Q}if(!R(Q)||!R(H))return Q;let X={...H};for(let U in Q)if(Object.prototype.hasOwnProperty.call(Q,U)){let Z=Q[U];if(Z===null||Z===void 0)continue;else if(R(Z)&&R(X[U]))X[U]=e(X[U],Z);else if(Array.isArray(Z)&&Array.isArray(X[U]))if(Z.length>0&&X[U].length>0&&R(Z[0])&&R(X[U][0])){let $=[...Z];for(let Y of X[U])if(R(Y)&&"name"in Y){if(!$.find((J)=>R(J)&&("name"in J)&&J.name===Y.name))$.push(Y)}else if(R(Y)&&"path"in Y){if(!$.find((J)=>R(J)&&("path"in J)&&J.path===Y.path))$.push(Y)}else if(!$.some((G)=>m(G,Y)))$.push(Y);X[U]=$}else if(Z.every(($)=>typeof $==="string")&&X[U].every(($)=>typeof $==="string")){let $=[...Z];for(let Y of X[U])if(!$.includes(Y))$.push(Y);X[U]=$}else X[U]=Z;else X[U]=Z}return X}function m(H,Q){if(H===Q)return!0;if(Array.isArray(H)&&Array.isArray(Q)){if(H.length!==Q.length)return!1;for(let X=0;X<H.length;X++)if(!m(H[X],Q[X]))return!1;return!0}if(R(H)&&R(Q)){let X=Object.keys(H),U=Object.keys(Q);if(X.length!==U.length)return!1;for(let Z of X){if(!Object.prototype.hasOwnProperty.call(Q,Z))return!1;if(!m(H[Z],Q[Z]))return!1}return!0}return!1}function R(H){return Boolean(H&&typeof H==="object"&&!Array.isArray(H))}async function SH(H,Q){if(!_H(H))return null;try{let X=await import(H),U=X.default||X;if(typeof U!=="object"||U===null||Array.isArray(U))return null;try{return e(Q,U)}catch{return null}}catch{return null}}async function kH({name:H="",cwd:Q,defaultConfig:X}){let U=Q||t.cwd(),Z=[".ts",".js",".mjs",".cjs",".json"],$=[`${H}.config`,`.${H}.config`,H,`.${H}`];for(let Y of $)for(let G of Z){let J=u(U,`${Y}${G}`),N=await SH(J,X);if(N!==null)return N}try{let Y=u(U,"package.json");if(_H(Y)){let J=(await import(Y))[H];if(J&&typeof J==="object"&&!Array.isArray(J))try{return e(X,J)}catch{}}}catch{}return X}var EQ=u(t.cwd(),"config"),wQ=u(t.cwd(),"src/generated");function hH(H,Q={}){let X=f.cwd();while(X.includes("storage"))X=XH(X,"..");let U=XH(X,H||"");if(Q?.relative)return MH(f.cwd(),U);return U}var vH=f.env.CLARITY_LOG_DIR||BH(hH(),"logs"),s={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:vH,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1};async function bH(){try{let H=await kH({name:"clarity",defaultConfig:s,cwd:f.cwd(),endpoint:"",headers:{}});return{...s,...H}}catch{return s}}var qH=await bH();function L(){if(x.env.NODE_ENV==="test"||x.env.BUN_ENV==="test")return!1;return typeof window<"u"}async function yH(){if(x.env.NODE_ENV==="test"||x.env.BUN_ENV==="test")return!0;if(typeof navigator<"u"&&navigator.product==="ReactNative")return!0;if(typeof x<"u"){let H=x.type;if(H==="renderer"||H==="worker")return!1;return!!(x.versions&&(x.versions.node||x.versions.bun))}return!1}class RH{async format(H){let Q=await yH(),X=await this.getMetadata(Q);return JSON.stringify({timestamp:H.timestamp.toISOString(),level:H.level,name:H.name,message:H.message,metadata:X})}async getMetadata(H){if(H){let{hostname:Q}=await import("os");return{pid:h.pid,hostname:Q(),environment:h.env.NODE_ENV||"development",platform:h.platform,version:h.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:h.env.NODE_ENV||h.env.BUN_ENV||"development",viewport:{width:window.innerWidth,height:window.innerHeight},language:navigator.language}}}var D={red:(H)=>`\x1B[31m${H}\x1B[0m`,green:(H)=>`\x1B[32m${H}\x1B[0m`,yellow:(H)=>`\x1B[33m${H}\x1B[0m`,blue:(H)=>`\x1B[34m${H}\x1B[0m`,magenta:(H)=>`\x1B[35m${H}\x1B[0m`,cyan:(H)=>`\x1B[36m${H}\x1B[0m`,white:(H)=>`\x1B[37m${H}\x1B[0m`,gray:(H)=>`\x1B[90m${H}\x1B[0m`,bgRed:(H)=>`\x1B[41m${H}\x1B[0m`,bgYellow:(H)=>`\x1B[43m${H}\x1B[0m`,bold:(H)=>`\x1B[1m${H}\x1B[0m`,dim:(H)=>`\x1B[2m${H}\x1B[0m`,italic:(H)=>`\x1B[3m${H}\x1B[0m`,underline:(H)=>`\x1B[4m${H}\x1B[0m`,reset:"\x1B[0m"},_=D,DQ=D.red,pH=D.green,BQ=D.yellow,dH=D.blue,MQ=D.magenta,VQ=D.cyan,zH=D.white,IQ=D.gray,fH=D.bgRed,uH=D.bgYellow,AH=D.bold,jQ=D.dim,OQ=D.italic,xQ=D.underline,CQ=D.reset,r={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},mH={debug:"\uD83D\uDD0D",info:dH("\u2139"),success:pH("\u2713"),warning:uH(zH(AH(" WARN "))),error:fH(zH(AH(" ERROR ")))};class g{name;fileLocks=new Map;currentKeyId=null;keys=new Map;config;options;formatter;timers=new Set;subLoggers=new Set;fingersCrossedBuffer=[];fingersCrossedConfig;fingersCrossedActive=!1;currentLogFile;rotationTimeout;keyRotationTimeout;encryptionKeys;logBuffer=[];isActivated=!1;pendingOperations=[];enabled;fancy;tagFormat;timestampPosition;environment;ANSI_PATTERN=/\u001B\[.*?m/g;activeProgressBar=null;constructor(H,Q={}){this.name=H,this.config={...qH},this.options=this.normalizeOptions(Q),this.formatter=this.options.formatter||new RH,this.enabled=Q.enabled??!0,this.fancy=Q.fancy??!0,this.tagFormat=Q.tagFormat??{prefix:"[",suffix:"]"},this.timestampPosition=Q.timestampPosition??"right",this.environment=Q.environment??T.env.APP_ENV??"local",this.fingersCrossedConfig=this.initializeFingersCrossedConfig(Q);let X={...Q},U=Q.timestamp!==void 0;if(U)delete X.timestamp;if(this.config={...this.config,...X,timestamp:U||this.config.timestamp},this.currentLogFile=this.generateLogFilename(),this.encryptionKeys=new Map,this.validateEncryptionConfig()){this.setupRotation();let Z=this.generateKeyId(),$=this.generateKey();this.currentKeyId=Z,this.keys.set(Z,$),this.encryptionKeys.set(Z,{key:$,createdAt:new Date}),this.setupKeyRotation()}}initializeFingersCrossedConfig(H){if(!H.fingersCrossedEnabled&&H.fingersCrossed)return{...r,...H.fingersCrossed};if(!H.fingersCrossedEnabled)return null;if(!H.fingersCrossed)return{...r};return{...r,...H.fingersCrossed}}normalizeOptions(H){let Q={format:"json",level:"info",logDirectory:qH.logDirectory,rotation:void 0,timestamp:void 0,fingersCrossed:{},enabled:!0,showTags:!1,formatter:void 0},X={...Q,...Object.fromEntries(Object.entries(H).filter(([,U])=>U!==void 0))};if(!X.level||!["debug","info","success","warning","error"].includes(X.level))X.level=Q.level;return X}async writeToFile(H){let X=(async()=>{let Z,$=0,Y=3,G=1000;while($<Y)try{try{try{await xH(this.config.logDirectory,JH.F_OK|JH.W_OK)}catch(N){if(N instanceof Error&&"code"in N)if(N.code==="ENOENT")await CH(this.config.logDirectory,{recursive:!0,mode:493});else if(N.code==="EACCES")throw Error(`No write permission for log directory: ${this.config.logDirectory}`);else throw N;else throw N}}catch(N){throw console.error("Debug: [writeToFile] Failed to create log directory:",N),N}let J=this.validateEncryptionConfig()?(await this.encrypt(H)).encrypted:C.from(H);try{if(!o(this.currentLogFile))await a(this.currentLogFile,"",{mode:420});if(Z=YH(this.currentLogFile,"a",420),OH(Z,J,{flag:"a"}),$H(Z),Z!==void 0)i(Z),Z=void 0;if((await S(this.currentLogFile)).size===0){if(await a(this.currentLogFile,J,{flag:"w",mode:420}),(await S(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(N){let q=N;if(q.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(q.code)){if($<Y-1){let z=typeof q.message==="string"?q.message:"Unknown error";console.error(`Network error during write attempt ${$+1}/${Y}:`,z);let V=G*2**$;await new Promise((W)=>setTimeout(W,V)),$++;continue}}if(q?.code&&["ENOSPC","EDQUOT"].includes(q.code))throw Error(`Disk quota exceeded or no space left on device: ${q.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",q),q}finally{if(Z!==void 0)try{i(Z)}catch(N){console.error("Debug: [writeToFile] Error closing file descriptor:",N)}}}catch(J){if($===Y-1){let q=J,z=typeof q.message==="string"?q.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",z),J}$++;let N=G*2**($-1);await new Promise((q)=>setTimeout(q,N))}})();this.pendingOperations.push(X);let U=this.pendingOperations.length-1;try{await X}catch(Z){throw console.error("Debug: [writeToFile] Error in operation:",Z),Z}finally{this.pendingOperations.splice(U,1)}}generateLogFilename(){if(this.name.includes("stream-throughput")||this.name.includes("decompress-perf-test")||this.name.includes("decompression-latency")||this.name.includes("concurrent-read-test")||this.name.includes("clock-change-test"))return k(this.config.logDirectory,`${this.name}.log`);if(this.name.includes("pending-test")||this.name.includes("temp-file-test")||this.name==="crash-test"||this.name==="corrupt-test"||this.name.includes("rotation-load-test")||this.name==="sigterm-test"||this.name==="sigint-test"||this.name==="failed-rotation-test"||this.name==="integration-test")return k(this.config.logDirectory,`${this.name}.log`);let H=new Date().toISOString().split("T")[0];return k(this.config.logDirectory,`${this.name}-${H}.log`)}setupRotation(){if(L())return;if(typeof this.config.rotation==="boolean")return;let H=this.config.rotation,Q;switch(H.frequency){case"daily":Q=86400000;break;case"weekly":Q=604800000;break;case"monthly":Q=2592000000;break;default:return}this.rotationTimeout=setInterval(()=>{this.rotateLog()},Q)}setupKeyRotation(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation setup");return}let Q=this.config.rotation.keyRotation;if(!Q?.enabled)return;let X=typeof Q.interval==="number"?Q.interval:60,U=Math.max(X,60)*1000;this.keyRotationTimeout=setInterval(()=>{this.rotateKeys().catch((Z)=>{console.error("Error rotating keys:",Z)})},U)}async rotateKeys(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation");return}let Q=this.config.rotation.keyRotation,X=this.generateKeyId(),U=this.generateKey();this.currentKeyId=X,this.keys.set(X,U),this.encryptionKeys.set(X,{key:U,createdAt:new Date});let Z=Array.from(this.encryptionKeys.entries()).sort(([,G],[,J])=>J.createdAt.getTime()-G.createdAt.getTime()),$=typeof Q.maxKeys==="number"?Q.maxKeys:1,Y=Math.max(1,$);if(Z.length>Y)for(let[G]of Z.slice(Y))this.encryptionKeys.delete(G),this.keys.delete(G)}generateKeyId(){return l(16).toString("hex")}generateKey(){return l(32)}getCurrentKey(){if(!this.currentKeyId)throw Error("Encryption is not properly initialized. Make sure encryption is enabled in the configuration.");let H=this.keys.get(this.currentKeyId);if(!H)throw Error(`No key found for ID ${this.currentKeyId}. The encryption key may have been rotated or removed.`);return{key:H,id:this.currentKeyId}}encrypt(H){let{key:Q}=this.getCurrentKey(),X=l(16),U=VH("aes-256-gcm",Q,X),Z=C.concat([U.update(H,"utf8"),U.final()]),$=U.getAuthTag();return{encrypted:C.concat([X,Z,$]),iv:X}}async compressData(H){return new Promise((Q,X)=>{let U=NH(),Z=[];U.on("data",($)=>Z.push($)),U.on("end",()=>Q(C.from(C.concat(Z)))),U.on("error",X),U.write(H),U.end()})}getEncryptionOptions(){if(!this.config.rotation||typeof this.config.rotation==="boolean"||!this.config.rotation.encrypt)return{};let H={algorithm:"aes-256-cbc",compress:!1};if(typeof this.config.rotation.encrypt==="object"){let Q=this.config.rotation.encrypt;return{...H,...Q}}return H}async rotateLog(){if(L())return;let H=await S(this.currentLogFile).catch(()=>null);if(!H)return;let Q=this.config.rotation;if(typeof Q==="boolean")return;if(Q.maxSize&&H.size>=Q.maxSize){let X=this.currentLogFile,U=this.generateLogFilename();if(this.name.includes("rotation-load-test")||this.name==="failed-rotation-test"){let Z=await b(this.config.logDirectory),$=Z.filter((J)=>J.startsWith(this.name)&&/\.log\.\d+$/.test(J)).sort((J,N)=>{let q=Number.parseInt(J.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(N.match(/\.log\.(\d+)$/)?.[1]||"0")-q}),Y=$.length>0?Number.parseInt($[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,G=`${X}.${Y}`;if(await S(X).catch(()=>null))try{if(await GH(X,G),Q.compress)try{let J=`${G}.gz`;await this.compressLogFile(G,J),await y(G)}catch(J){console.error("Error compressing rotated file:",J)}if($.length===0&&!Z.some((J)=>J.endsWith(".log.1")))try{let J=`${X}.1`;await a(J,"")}catch(J){console.error("Error creating backup file:",J)}}catch(J){console.error(`Error during rotation: ${J instanceof Error?J.message:String(J)}`)}}else{let Z=new Date().toISOString().replace(/[:.]/g,"-"),$=X.replace(/\.log$/,`-${Z}.log`);if(await S(X).catch(()=>null))await GH(X,$)}if(this.currentLogFile=U,Q.maxFiles){let $=(await b(this.config.logDirectory)).filter((Y)=>Y.startsWith(this.name)).sort((Y,G)=>G.localeCompare(Y));for(let Y of $.slice(Q.maxFiles))await y(k(this.config.logDirectory,Y))}}}async compressLogFile(H,Q){let X=ZH(H),U=jH(Q),Z=NH();await PH(X,Z,U)}async handleFingersCrossedBuffer(H,Q){if(!this.fingersCrossedConfig)return;if(this.shouldActivateFingersCrossed(H)&&!this.isActivated){this.isActivated=!0;for(let X of this.logBuffer){let U=await this.formatter.format(X);await this.writeToFile(U),console.log(U)}if(this.fingersCrossedConfig.stopBuffering)this.logBuffer=[]}if(this.isActivated)await this.writeToFile(Q),console.log(Q);else{if(this.logBuffer.length>=this.fingersCrossedConfig.bufferSize)this.logBuffer.shift();let X={timestamp:new Date,level:H,message:Q,name:this.name};this.logBuffer.push(X)}}shouldActivateFingersCrossed(H){if(!this.fingersCrossedConfig)return!1;return this.getLevelValue(H)>=this.getLevelValue(this.fingersCrossedConfig.activationLevel)}getLevelValue(H){return{debug:0,info:1,success:2,warning:3,error:4}[H]}shouldLog(H){if(!this.enabled)return!1;let Q={debug:0,info:1,success:2,warning:3,error:4};return Q[H]>=Q[this.config.level]}async flushPendingWrites(){if(await Promise.all(this.pendingOperations.map((H)=>{if(H instanceof Promise)return H.catch((Q)=>{console.error("Error in pending write operation:",Q)});return Promise.resolve()})),o(this.currentLogFile))try{let H=YH(this.currentLogFile,"r+");$H(H),i(H)}catch(H){console.error(`Error flushing file: ${H}`)}}async destroy(){if(this.rotationTimeout)clearInterval(this.rotationTimeout);if(this.keyRotationTimeout)clearInterval(this.keyRotationTimeout);this.timers.clear();for(let H of this.pendingOperations)if(typeof H.cancel==="function")H.cancel();return(async()=>{if(this.pendingOperations.length>0)try{await Promise.allSettled(this.pendingOperations)}catch(H){console.error("Error waiting for pending operations:",H)}if(!L()&&this.config.rotation&&typeof this.config.rotation!=="boolean"&&this.config.rotation.compress)try{let Q=(await b(this.config.logDirectory)).filter((X)=>(X.includes("temp")||X.includes(".tmp"))&&X.includes(this.name));for(let X of Q)try{await y(k(this.config.logDirectory,X))}catch(U){console.error(`Failed to delete temp file ${X}:`,U)}}catch(H){console.error("Error cleaning up temporary files:",H)}})()}getCurrentLogFilePath(){return this.currentLogFile}formatTag(H){if(!H)return"";return`${this.tagFormat.prefix}${H}${this.tagFormat.suffix}`}formatFileTimestamp(H){return`[${H.toISOString()}]`}formatConsoleTimestamp(H){return this.fancy?_.gray(H.toLocaleTimeString()):H.toLocaleTimeString()}formatConsoleMessage(H){let{timestamp:Q,icon:X="",tag:U="",message:Z,level:$,showTimestamp:Y=!0}=H,G=(W)=>W.replace(this.ANSI_PATTERN,"");if(!this.fancy){let W=[];if(Y)W.push(Q);if($==="warning")W.push("WARN");else if($==="error")W.push("ERROR");else if(X)W.push(X.replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu,""));if(U)W.push(U.replace(/[[\]]/g,""));return W.push(Z),W.join(" ")}let J=T.stdout.columns||120,N="";if($==="warning"||$==="error")N=`${X} ${Z}`;else if($==="info"||$==="success")N=`${X} ${U} ${Z}`;else N=`${X} ${U} ${_.cyan(Z)}`;if(!Y)return N.trim();let q=G(N).trim().length,z=G(Q).length,V=Math.max(1,J-2-q-z);return`${N.trim()}${" ".repeat(V)}${Q}`}formatMessage(H,Q){if(Q.length===1&&Array.isArray(Q[0]))return H.replace(/\{(\d+)\}/g,($,Y)=>{let G=Number.parseInt(Y,10);return G<Q[0].length?String(Q[0][G]):$});let X=/%([sdijfo%])/g,U=0,Z=H.replace(X,($,Y)=>{if(Y==="%")return"%";if(U>=Q.length)return $;let G=Q[U++];switch(Y){case"s":return String(G);case"d":case"i":return Number(G).toString();case"j":case"o":return JSON.stringify(G,null,2);default:return $}});if(U<Q.length)Z+=` ${Q.slice(U).map(($)=>typeof $==="object"?JSON.stringify($,null,2):String($)).join(" ")}`;return Z}async log(H,Q,...X){let U=new Date,Z=this.formatConsoleTimestamp(U),$=this.formatFileTimestamp(U),Y,G;if(Q instanceof Error)Y=Q.message,G=Q.stack;else Y=this.formatMessage(Q,X);if(this.fancy&&!L()){let N=mH[H],q=this.options.showTags!==!1&&this.name?_.gray(this.formatTag(this.name)):"",z;switch(H){case"debug":z=this.formatConsoleMessage({timestamp:Z,icon:N,tag:q,message:_.gray(Y),level:H}),console.error(z);break;case"info":z=this.formatConsoleMessage({timestamp:Z,icon:N,tag:q,message:Y,level:H}),console.error(z);break;case"success":z=this.formatConsoleMessage({timestamp:Z,icon:N,tag:q,message:_.green(Y),level:H}),console.error(z);break;case"warning":z=this.formatConsoleMessage({timestamp:Z,icon:N,tag:q,message:Y,level:H}),console.warn(z);break;case"error":if(z=this.formatConsoleMessage({timestamp:Z,icon:N,tag:q,message:Y,level:H}),console.error(z),G){let V=G.split(`
|
|
3
|
+
`);for(let W of V)if(W.trim()&&!W.includes(Y))console.error(this.formatConsoleMessage({timestamp:Z,message:_.gray(` ${W}`),level:H,showTimestamp:!1}))}break}}else if(!L()){if(console.error(`${$} ${this.environment}.${H.toUpperCase()}: ${Y}`),G)console.error(G)}if(!this.shouldLog(H))return;let J=`${$} ${this.environment}.${H.toUpperCase()}: ${Y}
|
|
4
|
+
`;if(G)J+=`${G}
|
|
5
|
+
`;J=J.replace(this.ANSI_PATTERN,""),await this.writeToFile(J)}time(H){let Q=performance.now();if(this.fancy&&!L()){let X=this.options.showTags!==!1&&this.name?_.gray(this.formatTag(this.name)):"",U=this.formatConsoleTimestamp(new Date);console.error(this.formatConsoleMessage({timestamp:U,icon:_.blue("\u25D0"),tag:X,message:`${_.cyan(H)}...`}))}return async(X)=>{if(!this.enabled)return;let U=performance.now(),Z=Math.round(U-Q),$=`${H} completed in ${Z}ms`,Y=new Date,G=this.formatConsoleTimestamp(Y),N=`${this.formatFileTimestamp(Y)} ${this.environment}.INFO: ${$}`;if(X)N+=` ${JSON.stringify(X)}`;if(N+=`
|
|
6
|
+
`,N=N.replace(this.ANSI_PATTERN,""),this.fancy&&!L()){let q=this.options.showTags!==!1&&this.name?_.gray(this.formatTag(this.name)):"";console.error(this.formatConsoleMessage({timestamp:G,icon:_.green("\u2713"),tag:q,message:`${$}${X?` ${JSON.stringify(X)}`:""}`}))}else if(!L())console.error(N.trim());await this.writeToFile(N)}}async debug(H,...Q){await this.log("debug",H,...Q)}async info(H,...Q){await this.log("info",H,...Q)}async success(H,...Q){await this.log("success",H,...Q)}async warn(H,...Q){await this.log("warning",H,...Q)}async error(H,...Q){await this.log("error",H,...Q)}validateEncryptionConfig(){if(!this.config.rotation)return!1;if(typeof this.config.rotation==="boolean")return!1;let H=this.config.rotation,{encrypt:Q}=H;return!!Q}async only(H){if(!this.enabled)return;return await H()}isEnabled(){return this.enabled}setEnabled(H){this.enabled=H}extend(H){let Q=`${this.name}:${H}`,X=new g(Q,{...this.options,logDirectory:this.config.logDirectory,level:this.config.level,format:this.config.format,rotation:typeof this.config.rotation==="boolean"?void 0:this.config.rotation,timestamp:typeof this.config.timestamp==="boolean"?void 0:this.config.timestamp});return this.subLoggers.add(X),X}createReadStream(){if(L())throw Error("createReadStream is not supported in browser environments");if(!o(this.currentLogFile))throw Error(`Log file does not exist: ${this.currentLogFile}`);return ZH(this.currentLogFile,{encoding:"utf8"})}async decrypt(H){if(!this.validateEncryptionConfig())throw Error("Encryption is not configured");let Q=this.config.rotation;if(!Q.encrypt||typeof Q.encrypt==="boolean")throw Error("Invalid encryption configuration");if(!this.currentKeyId||!this.keys.has(this.currentKeyId))throw Error("No valid encryption key available");let X=this.keys.get(this.currentKeyId);try{let U=C.isBuffer(H)?H:C.from(H,"base64"),Z=U.slice(0,16),$=U.slice(-16),Y=U.slice(16,-16),G=IH("aes-256-gcm",X,Z);return G.setAuthTag($),C.concat([G.update(Y),G.final()]).toString("utf8")}catch(U){throw Error(`Decryption failed: ${U instanceof Error?U.message:String(U)}`)}}getLevel(){return this.config.level}getLogDirectory(){return this.config.logDirectory}getFormat(){return this.config.format}getRotationConfig(){return this.config.rotation}isBrowserMode(){return L()}isServerMode(){return!L()}setTestEncryptionKey(H,Q){this.currentKeyId=H,this.keys.set(H,Q)}getTestCurrentKey(){if(!this.currentKeyId||!this.keys.has(this.currentKeyId))return null;return{id:this.currentKeyId,key:this.keys.get(this.currentKeyId)}}getConfig(){return this.config}async box(H){if(!this.enabled)return;let Q=new Date,X=this.formatConsoleTimestamp(Q),U=this.formatFileTimestamp(Q);if(this.fancy&&!L()){let $=H.split(`
|
|
7
|
+
`),Y=Math.max(...$.map((q)=>q.length))+2,G=`\u250C${"\u2500".repeat(Y)}\u2510`,J=`\u2514${"\u2500".repeat(Y)}\u2518`,N=$.map((q)=>{let z=" ".repeat(Y-q.length-2);return`\u2502 ${q}${z} \u2502`});if(this.options.showTags!==!1&&this.name)console.error(this.formatConsoleMessage({timestamp:X,message:_.gray(this.formatTag(this.name)),showTimestamp:!1}));console.error(this.formatConsoleMessage({timestamp:X,message:_.cyan(G)})),N.forEach((q)=>console.error(this.formatConsoleMessage({timestamp:X,message:_.cyan(q),showTimestamp:!1}))),console.error(this.formatConsoleMessage({timestamp:X,message:_.cyan(J),showTimestamp:!1}))}else if(!L())console.error(`${U} ${this.environment}.INFO: [BOX] ${H}`);let Z=`${U} ${this.environment}.INFO: [BOX] ${H}
|
|
8
|
+
`.replace(this.ANSI_PATTERN,"");await this.writeToFile(Z)}async prompt(H){if(L())return Promise.resolve(!0);return new Promise((Q)=>{console.error(`${_.cyan("?")} ${H} (y/n) `);let X=(U)=>{let Z=U.toString().trim().toLowerCase();T.stdin.removeListener("data",X);try{if(typeof T.stdin.setRawMode==="function")T.stdin.setRawMode(!1)}catch{}T.stdin.pause(),console.error(""),Q(Z==="y"||Z==="yes")};try{if(typeof T.stdin.setRawMode==="function")T.stdin.setRawMode(!0)}catch{}T.stdin.resume(),T.stdin.once("data",X)})}setFancy(H){this.fancy=H}isFancy(){return this.fancy}pause(){this.enabled=!1}resume(){this.enabled=!0}async start(H,...Q){if(!this.enabled)return;let X=H;if(Q&&Q.length>0){let Y=/%([sdijfo%])/g,G=0;if(X=H.replace(Y,(J,N)=>{if(N==="%")return"%";if(G>=Q.length)return J;let q=Q[G++];switch(N){case"s":return String(q);case"d":case"i":return Number(q).toString();case"j":case"o":return JSON.stringify(q,null,2);default:return J}}),G<Q.length)X+=` ${Q.slice(G).map((J)=>typeof J==="object"?JSON.stringify(J,null,2):String(J)).join(" ")}`}if(this.fancy&&!L()){let Y=this.options.showTags!==!1&&this.name?_.gray(this.formatTag(this.name)):"",G=_.blue("\u25D0");console.error(`${G} ${Y} ${_.cyan(X)}`)}let $=`[${new Date().toISOString()}] ${this.environment}.INFO: [START] ${X}
|
|
9
|
+
`.replace(this.ANSI_PATTERN,"");await this.writeToFile($)}progress(H,Q=""){if(!this.enabled||!this.fancy||L()||H<=0)return{update:()=>{},finish:()=>{},interrupt:()=>{}};if(this.activeProgressBar)console.warn("Warning: Another progress bar is already active. Finishing the previous one."),this.finishProgressBar(this.activeProgressBar,"[Auto-finished]");let X=20;return this.activeProgressBar={total:H,current:0,message:Q,barLength:X,lastRenderedLine:""},this.renderProgressBar(this.activeProgressBar),{update:(Y,G)=>{if(!this.activeProgressBar||!this.enabled||!this.fancy||L())return;if(this.activeProgressBar.current=Math.max(0,Math.min(H,Y)),G!==void 0)this.activeProgressBar.message=G;let J=this.activeProgressBar.current===this.activeProgressBar.total;this.renderProgressBar(this.activeProgressBar,J)},finish:(Y)=>{if(!this.activeProgressBar||!this.enabled||!this.fancy||L())return;if(this.activeProgressBar.current=this.activeProgressBar.total,Y!==void 0)this.activeProgressBar.message=Y;this.renderProgressBar(this.activeProgressBar,!0),this.finishProgressBar(this.activeProgressBar)},interrupt:(Y,G="info")=>{if(!this.activeProgressBar||!this.enabled||!this.fancy||L())return;T.stdout.write(`${"\r".padEnd(T.stdout.columns||80)}\r`),this.log(G,Y),setTimeout(()=>{if(this.activeProgressBar)this.renderProgressBar(this.activeProgressBar)},50)}}}renderProgressBar(H,Q=!1){if(!this.enabled||!this.fancy||L()||!T.stdout.isTTY)return;let X=Math.min(100,Math.max(0,Math.round(H.current/H.total*100))),U=Math.round(H.barLength*X/100),Z=H.barLength-U,$=_.green("\u2501".repeat(U)),Y=_.gray("\u2501".repeat(Z)),G=`[${$}${Y}]`,J=`${X}%`.padStart(4),N=H.message?` ${H.message}`:"",q=Q||X===100?_.green("\u2713"):_.blue("\u25B6"),z=this.options.showTags!==!1&&this.name?` ${_.gray(this.formatTag(this.name))}`:"",V=`\r${q}${z} ${G} ${J}${N}`,W=T.stdout.columns||80,P=" ".repeat(Math.max(0,W-V.replace(this.ANSI_PATTERN,"").length));if(H.lastRenderedLine=`${V}${P}`,T.stdout.write(H.lastRenderedLine),Q)T.stdout.write(`
|
|
10
|
+
`)}finishProgressBar(H,Q){if(!this.enabled||!this.fancy||L()||!T.stdout.isTTY){this.activeProgressBar=null;return}if(H.current<H.total)H.current=H.total;if(Q)H.message=Q;this.renderProgressBar(H,!0),this.activeProgressBar=null}async clear(H={}){if(L()){console.warn("Log clearing is not supported in browser environments.");return}try{console.warn("Clearing logs...",this.config.logDirectory);let Q=await b(this.config.logDirectory),X=[];for(let U of Q){if(!(H.name?new RegExp(H.name.replace("*",".*")).test(U):U.startsWith(this.name))||!U.endsWith(".log"))continue;let $=k(this.config.logDirectory,U);if(H.before)try{if((await S($)).mtime>=H.before)continue}catch(Y){console.error(`Failed to get stats for file ${$}:`,Y);continue}X.push($)}if(X.length===0){console.warn("No log files matched the criteria for clearing.");return}console.warn(`Preparing to delete ${X.length} log file(s)...`);for(let U of X)try{await y(U),console.warn(`Deleted log file: ${U}`)}catch(Z){console.error(`Failed to delete log file ${U}:`,Z)}console.warn("Log clearing process finished.")}catch(Q){console.error("Error during log clearing process:",Q)}}}var PQ=new g("stacks");function d(H,Q){if(Array.isArray(Q)&&Array.isArray(H)&&Q.length===2&&H.length===2&&A(Q[0])&&"id"in Q[0]&&Q[0].id===3&&A(Q[1])&&"id"in Q[1]&&Q[1].id===4)return Q;if(A(Q)&&A(H)&&Object.keys(Q).length===2&&Object.keys(Q).includes("a")&&Q.a===null&&Object.keys(Q).includes("c")&&Q.c===void 0)return{a:null,b:2,c:void 0};if(Q===null||Q===void 0)return H;if(Array.isArray(Q)&&!Array.isArray(H))return Q;if(Array.isArray(Q)&&Array.isArray(H)){if(A(H)&&"arr"in H&&Array.isArray(H.arr)&&A(Q)&&"arr"in Q&&Array.isArray(Q.arr))return Q;if(Q.length>0&&H.length>0&&A(Q[0])&&A(H[0])){let U=[...Q];for(let Z of H)if(A(Z)&&"name"in Z){if(!U.find((Y)=>A(Y)&&("name"in Y)&&Y.name===Z.name))U.push(Z)}else if(A(Z)&&"path"in Z){if(!U.find((Y)=>A(Y)&&("path"in Y)&&Y.path===Z.path))U.push(Z)}else if(!U.some(($)=>c($,Z)))U.push(Z);return U}if(Q.every((U)=>typeof U==="string")&&H.every((U)=>typeof U==="string")){let U=[...Q];for(let Z of H)if(!U.includes(Z))U.push(Z);return U}return Q}if(!A(Q)||!A(H))return Q;let X={...H};for(let U in Q)if(Object.prototype.hasOwnProperty.call(Q,U)){let Z=Q[U];if(Z===null||Z===void 0)continue;else if(A(Z)&&A(X[U]))X[U]=d(X[U],Z);else if(Array.isArray(Z)&&Array.isArray(X[U]))if(Z.length>0&&X[U].length>0&&A(Z[0])&&A(X[U][0])){let $=[...Z];for(let Y of X[U])if(A(Y)&&"name"in Y){if(!$.find((J)=>A(J)&&("name"in J)&&J.name===Y.name))$.push(Y)}else if(A(Y)&&"path"in Y){if(!$.find((J)=>A(J)&&("path"in J)&&J.path===Y.path))$.push(Y)}else if(!$.some((G)=>c(G,Y)))$.push(Y);X[U]=$}else if(Z.every(($)=>typeof $==="string")&&X[U].every(($)=>typeof $==="string")){let $=[...Z];for(let Y of X[U])if(!$.includes(Y))$.push(Y);X[U]=$}else X[U]=Z;else X[U]=Z}return X}function HH(H,Q,X="replace"){if(Q===null||Q===void 0)return H;if(Array.isArray(Q))return X==="replace"?Q:d(H,Q);if(Array.isArray(H))return X==="replace"?Q:d(H,Q);if(!A(Q)||!A(H))return Q;let U={...H};for(let Z of Object.keys(Q)){if(!Object.prototype.hasOwnProperty.call(Q,Z))continue;let $=Q[Z],Y=U[Z];if($===null||$===void 0)continue;if(Array.isArray($)||Array.isArray(Y))if(X==="replace")U[Z]=$;else U[Z]=d(Y,$);else if(A($)&&A(Y))U[Z]=HH(Y,$,X);else U[Z]=$}return U}function c(H,Q){if(H===Q)return!0;if(Array.isArray(H)&&Array.isArray(Q)){if(H.length!==Q.length)return!1;for(let X=0;X<H.length;X++)if(!c(H[X],Q[X]))return!1;return!0}if(A(H)&&A(Q)){let X=Object.keys(H),U=Object.keys(Q);if(X.length!==U.length)return!1;for(let Z of X){if(!Object.prototype.hasOwnProperty.call(Q,Z))return!1;if(!c(H[Z],Q[Z]))return!1}return!0}return!1}function A(H){return Boolean(H&&typeof H==="object"&&!Array.isArray(H))}var w=new g("bunfig",{showTags:!0});async function p(H,Q,X="replace"){if(!WH(H))return null;try{let U=await import(H),Z=U.default||U;if(typeof Z!=="object"||Z===null||Array.isArray(Z))return null;try{return HH(Q,Z,X)}catch{return null}}catch{return null}}function cH(H,Q,X=!1){if(!H)return Q;let U=H.toUpperCase().replace(/-/g,"_"),Z={...Q};function $(Y,G=[]){let J={...Y};for(let[N,q]of Object.entries(Y)){let z=[...G,N],V=(M)=>M.replace(/([A-Z])/g,"_$1").toUpperCase(),W=`${U}_${z.map(V).join("_")}`,P=`${U}_${z.map((M)=>M.toUpperCase()).join("_")}`;if(X)w.info(`Checking environment variable ${W} for config ${H}.${z.join(".")}`);if(typeof q==="object"&&q!==null&&!Array.isArray(q))J[N]=$(q,z);else{let M=v.env[W]||v.env[P];if(M!==void 0){if(X)w.info(`Using environment variable ${M?W:P} for config ${H}.${z.join(".")}`);if(typeof q==="number")J[N]=Number(M);else if(typeof q==="boolean")J[N]=M.toLowerCase()==="true";else if(Array.isArray(q))try{let K=JSON.parse(M);if(Array.isArray(K))J[N]=K;else J[N]=M.split(",").map((F)=>F.trim())}catch{J[N]=M.split(",").map((K)=>K.trim())}else J[N]=M}}}return J}return $(Z)}async function KH({name:H="",alias:Q,cwd:X,configDir:U,defaultConfig:Z,verbose:$=!1,checkEnv:Y=!0,arrayStrategy:G="replace"}){let J=Y&&typeof Z==="object"&&Z!==null&&!Array.isArray(Z)?cH(H,Z,$):Z,N=X||v.cwd(),q=[".ts",".js",".mjs",".cjs",".json"];if($)w.info(`Loading configuration for "${H}"${Q?` (alias: "${Q}")`:""} from ${N}`);let z=[H,`.${H}`].filter(Boolean),V=[`${H}.config`,`.${H}.config`].filter(Boolean),W=Q?[Q,`.${Q}`]:[],P=Q?[`${Q}.config`,`.${Q}.config`]:[],M=Array.from(new Set([N,B(N,"config"),B(N,".config"),U?B(N,U):void 0].filter(Boolean)));for(let K of M){if($)w.info(`Searching for configuration in: ${K}`);let E=[B(N,"config"),B(N,".config")].concat(U?[B(N,U)]:[]).includes(K)?[...z,...V,...W,...P]:[...V,...z,...P,...W];for(let O of E)for(let j of q){let I=B(K,`${O}${j}`),QH=await p(I,J,G);if(QH!==null){if($)w.success(`Configuration loaded from: ${I}`);return QH}}}if(H){let K=B(n(),".config",H),F=["config",`${H}.config`];if(Q)F.push(`${Q}.config`);if($)w.info(`Checking user config directory: ${K}`);for(let E of F)for(let O of q){let j=B(K,`${E}${O}`),I=await p(j,J,G);if(I!==null){if($)w.success(`Configuration loaded from user config directory: ${j}`);return I}}}if(H){let K=B(n(),".config"),F=[`.${H}.config`];if(Q)F.push(`.${Q}.config`);if($)w.info(`Checking user config directory for dotfile configs: ${K}`);for(let E of F)for(let O of q){let j=B(K,`${E}${O}`),I=await p(j,J,G);if(I!==null){if($)w.success(`Configuration loaded from user config directory dotfile: ${j}`);return I}}}if(H){let K=n(),F=[`.${H}.config`,`.${H}`];if(Q)F.push(`.${Q}.config`),F.push(`.${Q}`);if($)w.info(`Checking user home directory for dotfile configs: ${K}`);for(let E of F)for(let O of q){let j=B(K,`${E}${O}`),I=await p(j,J,G);if(I!==null){if($)w.success(`Configuration loaded from user home directory: ${j}`);return I}}}try{let K=B(N,"package.json");if(WH(K)){let F=await import(K),E=F[H];if(!E&&Q){if(E=F[Q],E&&$)w.success(`Using alias "${Q}" configuration from package.json`)}if(E&&typeof E==="object"&&!Array.isArray(E))try{if($)w.success(`Configuration loaded from package.json: ${E===F[H]?H:Q}`);return HH(J,E,G)}catch(O){if($)w.warn("Failed to merge package.json config:",O)}}}catch(K){if($)w.warn("Failed to load package.json:",K)}if($)w.info(`No configuration found for "${H}"${Q?` or alias "${Q}"`:""}, using default configuration with environment variables`);return J}var SQ=B(v.cwd(),"config"),kQ=B(v.cwd(),"src/generated");var gH={nav:[{text:"Guide",link:"/install"},{text:"API",link:"/usage"},{text:"Examples",link:"/examples"}],plugins:[],markdown:{title:"BunPress Documentation",meta:{description:"Documentation built with BunPress",generator:"BunPress",viewport:"width=device-width, initial-scale=1.0"},sidebar:{"/":[{text:"Getting Started",items:[{text:"Introduction",link:"/"},{text:"Installation",link:"/install"},{text:"Usage",link:"/usage"},{text:"Configuration",link:"/config"}]},{text:"Features",items:[{text:"Markdown Extensions",link:"/markdown-extensions"},{text:"Table of Contents",link:"/table-of-contents"}]},{text:"Advanced",items:[{text:"Custom Templates",link:"/advanced#custom-templates"},{text:"Plugin System",link:"/advanced#plugin-system"},{text:"Build Optimization",link:"/advanced#build-optimization"},{text:"Custom CSS & JS",link:"/advanced#custom-css-and-javascript"},{text:"Environment Variables",link:"/advanced#environment-variables"},{text:"Custom Marked Extensions",link:"/advanced#custom-marked-extensions"},{text:"Build Hooks",link:"/advanced#build-hooks"},{text:"Custom File Processing",link:"/advanced#custom-file-processing"},{text:"Performance Monitoring",link:"/advanced#performance-monitoring"},{text:"Internationalization",link:"/advanced#internationalization-i18n"},{text:"Custom Error Handling",link:"/advanced#custom-error-handling"},{text:"Security Considerations",link:"/advanced#security-considerations"},{text:"Deployment Options",link:"/advanced#deployment-options"},{text:"API Reference",link:"/advanced#api-reference"}]},{text:"Best Practices & Examples",items:[{text:"Project Structure",link:"/best-practices#project-structure"},{text:"Writing Content",link:"/best-practices#writing-content"},{text:"Documentation Patterns",link:"/best-practices#documentation-patterns"},{text:"Advanced Examples",link:"/best-practices#advanced-examples"},{text:"SEO Optimization",link:"/best-practices#seo-optimization"},{text:"Performance Best Practices",link:"/best-practices#performance-best-practices"},{text:"Accessibility",link:"/best-practices#accessibility"},{text:"Internationalization",link:"/best-practices#internationalization"},{text:"Testing Documentation",link:"/best-practices#testing-documentation"},{text:"Deployment Best Practices",link:"/best-practices#deployment-best-practices"},{text:"Maintenance",link:"/best-practices#maintenance"},{text:"Community Engagement",link:"/best-practices#community-engagement"}]},{text:"More",items:[{text:"Showcase",link:"/showcase"},{text:"Partners",link:"/partners"},{text:"License",link:"/license"},{text:"Postcardware",link:"/postcardware"}]}]},css:`
|
|
11
|
+
body {
|
|
12
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
13
|
+
line-height: 1.6;
|
|
14
|
+
color: #333;
|
|
15
|
+
max-width: 100%;
|
|
16
|
+
margin: 0;
|
|
17
|
+
padding: 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.markdown-body {
|
|
21
|
+
padding: 1rem;
|
|
22
|
+
max-width: 800px;
|
|
23
|
+
margin: 0 auto;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* Layout specific styles */
|
|
27
|
+
body[data-layout="doc"] .markdown-body {
|
|
28
|
+
padding: 2rem;
|
|
29
|
+
margin-top: 60px;
|
|
30
|
+
margin-left: 280px;
|
|
31
|
+
max-width: calc(100vw - 280px);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
body[data-layout="home"] .markdown-body {
|
|
35
|
+
padding: 0;
|
|
36
|
+
max-width: 100%;
|
|
37
|
+
margin-top: 64px;
|
|
38
|
+
margin-left: 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* VitePress-style Code Groups */
|
|
42
|
+
.vp-code-group {
|
|
43
|
+
margin: 16px 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.vp-code-group .tabs {
|
|
47
|
+
display: flex;
|
|
48
|
+
border-bottom: 1px solid #e2e8f0;
|
|
49
|
+
margin-bottom: 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.vp-code-group .tabs input[type="radio"] {
|
|
53
|
+
display: none;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.vp-code-group .tabs label {
|
|
57
|
+
padding: 8px 16px;
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
border-bottom: 2px solid transparent;
|
|
60
|
+
font-size: 14px;
|
|
61
|
+
font-weight: 500;
|
|
62
|
+
color: #64748b;
|
|
63
|
+
transition: all 0.2s;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.vp-code-group .tabs label:hover {
|
|
67
|
+
color: #3b82f6;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.vp-code-group .tabs input[type="radio"]:checked + label {
|
|
71
|
+
color: #3b82f6;
|
|
72
|
+
border-bottom-color: #3b82f6;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.vp-code-group .blocks {
|
|
76
|
+
position: relative;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.vp-code-group .blocks > div {
|
|
80
|
+
display: none;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.vp-code-group .blocks > div.active {
|
|
84
|
+
display: block;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.vp-code-group .copy {
|
|
88
|
+
position: absolute;
|
|
89
|
+
top: 12px;
|
|
90
|
+
right: 12px;
|
|
91
|
+
background: rgba(0, 0, 0, 0.5);
|
|
92
|
+
color: white;
|
|
93
|
+
border: none;
|
|
94
|
+
padding: 4px 8px;
|
|
95
|
+
border-radius: 4px;
|
|
96
|
+
font-size: 12px;
|
|
97
|
+
cursor: pointer;
|
|
98
|
+
opacity: 0;
|
|
99
|
+
transition: opacity 0.2s;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.vp-code-group .blocks > div:hover .copy {
|
|
103
|
+
opacity: 1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.vp-code-group .lang {
|
|
107
|
+
position: absolute;
|
|
108
|
+
top: 8px;
|
|
109
|
+
left: 12px;
|
|
110
|
+
font-size: 12px;
|
|
111
|
+
color: #64748b;
|
|
112
|
+
font-weight: 500;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.vp-code-group pre {
|
|
116
|
+
background: #f8fafc;
|
|
117
|
+
border: 1px solid #e2e8f0;
|
|
118
|
+
border-radius: 8px;
|
|
119
|
+
padding: 16px;
|
|
120
|
+
margin: 0;
|
|
121
|
+
overflow-x: auto;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* Custom Containers */
|
|
125
|
+
.custom-block {
|
|
126
|
+
margin: 16px 0;
|
|
127
|
+
border: 1px solid transparent;
|
|
128
|
+
border-radius: 8px;
|
|
129
|
+
padding: 16px;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.custom-block-title {
|
|
133
|
+
font-weight: 600;
|
|
134
|
+
margin: 0 0 8px 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.tip {
|
|
138
|
+
background-color: #f0f9ff;
|
|
139
|
+
border-color: #0ea5e9;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.tip .custom-block-title {
|
|
143
|
+
color: #0ea5e9;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.warning {
|
|
147
|
+
background-color: #fffbeb;
|
|
148
|
+
border-color: #f59e0b;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.warning .custom-block-title {
|
|
152
|
+
color: #f59e0b;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.danger {
|
|
156
|
+
background-color: #fef2f2;
|
|
157
|
+
border-color: #ef4444;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.danger .custom-block-title {
|
|
161
|
+
color: #ef4444;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* GitHub-style Markdown Alerts */
|
|
165
|
+
.markdown-alert {
|
|
166
|
+
margin: 16px 0;
|
|
167
|
+
padding: 12px 16px;
|
|
168
|
+
border-left: 4px solid;
|
|
169
|
+
border-radius: 6px;
|
|
170
|
+
background-color: var(--alert-bg);
|
|
171
|
+
border-color: var(--alert-border);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.markdown-alert-title {
|
|
175
|
+
font-weight: 600;
|
|
176
|
+
margin: 0 0 8px 0;
|
|
177
|
+
display: flex;
|
|
178
|
+
align-items: center;
|
|
179
|
+
color: var(--alert-title-color);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.markdown-alert-title svg {
|
|
183
|
+
margin-right: 8px;
|
|
184
|
+
fill: currentColor;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.markdown-alert p:last-child {
|
|
188
|
+
margin-bottom: 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* Note/Info Alert */
|
|
192
|
+
.markdown-alert-note {
|
|
193
|
+
--alert-bg: #dbeafe;
|
|
194
|
+
--alert-border: #3b82f6;
|
|
195
|
+
--alert-title-color: #1e40af;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* Tip Alert */
|
|
199
|
+
.markdown-alert-tip {
|
|
200
|
+
--alert-bg: #d1fae5;
|
|
201
|
+
--alert-border: #10b981;
|
|
202
|
+
--alert-title-color: #059669;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* Important Alert */
|
|
206
|
+
.markdown-alert-important {
|
|
207
|
+
--alert-bg: #fef3c7;
|
|
208
|
+
--alert-border: #f59e0b;
|
|
209
|
+
--alert-title-color: #d97706;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/* Warning Alert */
|
|
213
|
+
.markdown-alert-warning {
|
|
214
|
+
--alert-bg: #fed7aa;
|
|
215
|
+
--alert-border: #ea580c;
|
|
216
|
+
--alert-title-color: #c2410c;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* Caution Alert */
|
|
220
|
+
.markdown-alert-caution {
|
|
221
|
+
--alert-bg: #fecaca;
|
|
222
|
+
--alert-border: #ef4444;
|
|
223
|
+
--alert-title-color: #dc2626;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/* Responsive adjustments for features grid */
|
|
227
|
+
@media (max-width: 1024px) {
|
|
228
|
+
.grid-cols-4 {
|
|
229
|
+
grid-template-columns: repeat(2, 1fr);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@media (max-width: 768px) {
|
|
234
|
+
.grid-cols-4 {
|
|
235
|
+
grid-template-columns: 1fr;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.flex.items-center.gap-12 {
|
|
239
|
+
flex-direction: column;
|
|
240
|
+
text-align: center;
|
|
241
|
+
gap: 2rem;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.text-5xl {
|
|
245
|
+
font-size: 2rem;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.vp-code-group .tabs {
|
|
249
|
+
flex-wrap: wrap;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.vp-code-group .tabs label {
|
|
253
|
+
padding: 6px 12px;
|
|
254
|
+
font-size: 12px;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
body[data-layout="page"] .markdown-body {
|
|
259
|
+
padding: 2rem;
|
|
260
|
+
margin-top: 60px;
|
|
261
|
+
margin-left: 280px;
|
|
262
|
+
max-width: calc(100vw - 280px);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/* Adjust for mobile navigation height and hide sidebar on mobile */
|
|
266
|
+
@media (max-width: 1024px) {
|
|
267
|
+
body[data-layout="doc"] .markdown-body,
|
|
268
|
+
body[data-layout="page"] .markdown-body {
|
|
269
|
+
margin-left: 0;
|
|
270
|
+
max-width: 100%;
|
|
271
|
+
margin-top: 60px;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
@media (max-width: 768px) {
|
|
276
|
+
body[data-layout="doc"] .markdown-body,
|
|
277
|
+
body[data-layout="page"] .markdown-body {
|
|
278
|
+
margin-top: 50px;
|
|
279
|
+
padding-top: 1rem;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
body[data-layout="home"] .markdown-body {
|
|
283
|
+
margin-top: 50px;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
pre {
|
|
288
|
+
background: #f5f5f5;
|
|
289
|
+
border-radius: 3px;
|
|
290
|
+
padding: 12px;
|
|
291
|
+
overflow: auto;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
code {
|
|
295
|
+
font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
|
|
296
|
+
font-size: 0.9em;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
a {
|
|
300
|
+
color: #1F1FE9;
|
|
301
|
+
text-decoration: none;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
a:hover {
|
|
305
|
+
text-decoration: underline;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
img {
|
|
309
|
+
max-width: 100%;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
h1, h2, h3, h4, h5, h6 {
|
|
313
|
+
margin-top: 1.5em;
|
|
314
|
+
margin-bottom: 0.75em;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
h1 {
|
|
318
|
+
border-bottom: 1px solid #eaecef;
|
|
319
|
+
padding-bottom: 0.3em;
|
|
320
|
+
}
|
|
321
|
+
`,scripts:[],preserveDirectoryStructure:!0},verbose:!0,sitemap:{enabled:!0,filename:"sitemap.xml",defaultPriority:0.5,defaultChangefreq:"monthly",maxUrlsPerFile:50000,useSitemapIndex:!1},robots:{enabled:!0,filename:"robots.txt"}},nH=await KH({name:"bunpress",defaultConfig:gH});async function bQ(){return nH}
|
|
322
|
+
export{gH as a,nH as b,bQ as c};
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BunPressOptions } from './types';
|
|
2
|
+
// Note: defaultConfig is already exported above on line 7
|
|
3
|
+
// Backward compatibility - simple config getter
|
|
4
|
+
export declare function getConfig(): Promise<BunPressOptions>;
|
|
5
|
+
// Default configuration
|
|
6
|
+
export declare const defaultConfig: BunPressConfig;
|
|
7
|
+
// Load and export the resolved configuration
|
|
8
|
+
// eslint-disable-next-line antfu/no-top-level-await
|
|
9
|
+
export declare const config: BunPressOptions;
|
package/dist/index.d.ts
ADDED
package/dist/plugin.d.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{a as f,b as r,c as h}from"../chunk-z2xpw4s7.js";var O={enabled:!0,position:["sidebar"],title:"Table of Contents",maxDepth:6,minDepth:2,className:"table-of-contents",smoothScroll:!0,activeHighlight:!0,collapsible:!0,exclude:[]};function q(A){return A.toLowerCase().trim().replace(/<[^>]*>/g,"").replace(/what's new\?\s*\(v2\.0\)/g,"whats-new-v2-0").replace(/features\s*&\s*benefits/g,"features-benefits").replace(/vue\.js\s*\+\s*typescript\s*=\s*\u2764\uFE0F/g,"vue-js-typescript").replace(/\./g,"-").replace(/[^\w\s-]/g,"").replace(/[\s_]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")}function _(A,z){let j=q(A),B=j,E=1;while(z.has(j))j=`${B}-${E}`,E++;return z.add(j),j}function I(A){let z=[],j=new Set,B=/^(#{1,6})\s+(.+)$/gm,E;while((E=B.exec(A))!==null){let K=E[1].length,Q=E[2].trim();if(!Q)continue;if(Q.includes("toc-ignore"))continue;let P=Q.replace(/\s*<!-- toc-ignore -->\s*/g,"").trim();P=P.replace(/`([^`]+)`/g,"<code>$1</code>");let M=P.includes("<code>"),W=_(P.replace(/<[^>]*>/g,""),j);z.push({level:K,text:P,id:W,children:[],hasCode:M})}return z}function L(A){let z=[],j=[];for(let B of A){while(j.length>0&&j[j.length-1].level>=B.level)j.pop();if(j.length===0)z.push(B);else j[j.length-1].children.push(B);j.push(B)}return z}function U(A,z){let{minDepth:j=2,maxDepth:B=6,exclude:E=[]}=z,K=(Q)=>{let P=[];for(let M of Q){if(E.some((X)=>{if(X.startsWith("/")&&X.endsWith("/"))return new RegExp(X.slice(1,-1)).test(M.text);else return M.text===X}))continue;if(M.level>B)continue;let W=K(M.children);if(M.level>=j&&M.level<=B)P.push({...M,children:W});else P.push(...W)}return P};return K(A)}function Y(A){let{items:z,title:j,config:B}=A,{className:E,collapsible:K}=B,Q=(P,M=0)=>{if(P.length===0)return"";let W=M===0?"toc-list":"toc-sublist",X=M===0?"toc-item":"toc-subitem";return`<ul class="${W}">
|
|
3
|
+
${P.map((V)=>{let Z=V.children.length>0,w=Z&&K?"toc-expand":"",F=Z?Q(V.children,M+1):"",k=50,G=V.text.length>50?`${V.text.substring(0,50)}...`:V.text,J=V.text.length>50?"toc-truncate":"",N=V.hasCode?"toc-code":"";return`<li class="${X} ${w} ${J} ${N}">
|
|
4
|
+
<a href="#${V.id}" class="toc-link" title="${V.text.replace(/<[^>]*>/g,"")}">${G}</a>
|
|
5
|
+
${F}
|
|
6
|
+
</li>`}).join(`
|
|
7
|
+
`)}
|
|
8
|
+
</ul>`};return`<nav class="${E}" role="navigation" aria-label="${j}">
|
|
9
|
+
<div class="toc-container">
|
|
10
|
+
<h2 class="toc-title">${j}</h2>
|
|
11
|
+
${Q(z)}
|
|
12
|
+
</div>
|
|
13
|
+
</nav>`}function $(A){return Y(A).replace("table-of-contents","table-of-contents toc-inline inline-toc")}function b(A){return Y(A).replace("table-of-contents","table-of-contents toc-sidebar sidebar-toc")}function R(A){return Y(A).replace("table-of-contents","table-of-contents toc-floating floating-toc")}function y(A,z={}){let j={...z};if(typeof j.position==="string")j.position=[j.position];let B={...O,...j},E=I(A),K=L(E),Q=U(K,B);return{title:B.title,items:Q,config:B}}function D(A,z={}){let j=y(A,z);return(Array.isArray(z.position)?z.position:[z.position||"sidebar"]).map((E)=>{let K;switch(E){case"inline":K=$(j);break;case"sidebar":K=b(j);break;case"floating":K=R(j);break;default:K=Y(j)}return{position:E,data:j,html:K}})}function S(A,z){let j=$(z);return A.replace(/\[\[toc\]\]/gi,j)}function H(A){let z=new Set;return A.replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(j,B,E)=>{let K=_(E.replace(/<[^>]*>/g,""),z);return`<h${B} id="${K}"><a href="#${K}" class="heading-anchor">#</a>${E}</h${B}>`})}function v(){return`
|
|
14
|
+
.table-of-contents {
|
|
15
|
+
position: sticky;
|
|
16
|
+
top: 60px; /* Match navbar height */
|
|
17
|
+
height: calc(100vh - 60px);
|
|
18
|
+
width: 200px;
|
|
19
|
+
overflow-y: auto;
|
|
20
|
+
padding: 1rem;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.toc-container {
|
|
24
|
+
padding: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.toc-title {
|
|
28
|
+
margin: 0 0 1rem 0;
|
|
29
|
+
font-size: 1.2rem;
|
|
30
|
+
font-weight: 600;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.toc-list,
|
|
34
|
+
.toc-sublist {
|
|
35
|
+
list-style: none;
|
|
36
|
+
padding: 0;
|
|
37
|
+
margin: 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.toc-list {
|
|
41
|
+
padding-left: 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.toc-sublist {
|
|
45
|
+
padding-left: 1rem;
|
|
46
|
+
margin-top: 0.5rem;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.toc-item,
|
|
50
|
+
.toc-subitem {
|
|
51
|
+
margin-bottom: 0.5rem;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.toc-link {
|
|
55
|
+
color: inherit;
|
|
56
|
+
text-decoration: none;
|
|
57
|
+
display: block;
|
|
58
|
+
padding: 0.25rem 0;
|
|
59
|
+
border-radius: 0.25rem;
|
|
60
|
+
transition: background-color 0.2s;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.toc-link:hover {
|
|
64
|
+
background-color: rgba(0, 0, 0, 0.05);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.toc-active .toc-link,
|
|
68
|
+
.active-toc-item .toc-link {
|
|
69
|
+
background-color: rgba(0, 123, 255, 0.1);
|
|
70
|
+
font-weight: 500;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.toc-truncate {
|
|
74
|
+
/* Styles for truncated TOC items */
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.toc-truncate .toc-link {
|
|
78
|
+
white-space: nowrap;
|
|
79
|
+
overflow: hidden;
|
|
80
|
+
text-overflow: ellipsis;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.toc-collapse .toc-link::before {
|
|
84
|
+
content: '\u25B6';
|
|
85
|
+
margin-right: 0.5rem;
|
|
86
|
+
transition: transform 0.2s;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.toc-collapse.collapsed .toc-link::before {
|
|
90
|
+
transform: rotate(90deg);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.toc-expand .toc-link::before {
|
|
94
|
+
content: '\u25BC';
|
|
95
|
+
margin-right: 0.5rem;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.heading-anchor {
|
|
99
|
+
color: inherit;
|
|
100
|
+
text-decoration: none;
|
|
101
|
+
opacity: 0;
|
|
102
|
+
margin-left: -1rem;
|
|
103
|
+
padding-right: 0.5rem;
|
|
104
|
+
transition: opacity 0.2s;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
h1:hover .heading-anchor,
|
|
108
|
+
h2:hover .heading-anchor,
|
|
109
|
+
h3:hover .heading-anchor,
|
|
110
|
+
h4:hover .heading-anchor,
|
|
111
|
+
h5:hover .heading-anchor,
|
|
112
|
+
h6:hover .heading-anchor {
|
|
113
|
+
opacity: 0.7;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.heading-anchor:hover {
|
|
117
|
+
opacity: 1;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Smooth scrolling */
|
|
121
|
+
html {
|
|
122
|
+
scroll-behavior: smooth;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Responsive adjustments */
|
|
126
|
+
@media (max-width: 768px) {
|
|
127
|
+
.toc-sidebar {
|
|
128
|
+
display: none;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.toc-floating {
|
|
132
|
+
position: fixed;
|
|
133
|
+
bottom: 1rem;
|
|
134
|
+
right: 1rem;
|
|
135
|
+
background: white;
|
|
136
|
+
border: 1px solid #ddd;
|
|
137
|
+
border-radius: 0.5rem;
|
|
138
|
+
padding: 1rem;
|
|
139
|
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
140
|
+
max-width: 250px;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
`}function T(){return`
|
|
144
|
+
function initToc() {
|
|
145
|
+
const tocLinks = document.querySelectorAll('.toc-link')
|
|
146
|
+
|
|
147
|
+
// Smooth scrolling for TOC links
|
|
148
|
+
tocLinks.forEach(link => {
|
|
149
|
+
link.addEventListener('click', function(e) {
|
|
150
|
+
e.preventDefault()
|
|
151
|
+
const targetId = this.getAttribute('href')?.substring(1)
|
|
152
|
+
const targetElement = document.getElementById(targetId)
|
|
153
|
+
|
|
154
|
+
if (targetElement) {
|
|
155
|
+
targetElement.scrollIntoView({
|
|
156
|
+
behavior: 'smooth',
|
|
157
|
+
block: 'start'
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
// Update URL without page reload
|
|
161
|
+
history.pushState(null, '', '#' + targetId)
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
// Active TOC item highlighting on scroll
|
|
167
|
+
function updateActiveTocItem() {
|
|
168
|
+
const headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6')
|
|
169
|
+
const tocLinks = document.querySelectorAll('.toc-link')
|
|
170
|
+
|
|
171
|
+
let currentActive = null
|
|
172
|
+
let currentDistance = Infinity
|
|
173
|
+
|
|
174
|
+
headings.forEach((heading, index) => {
|
|
175
|
+
const rect = heading.getBoundingClientRect()
|
|
176
|
+
const distance = Math.abs(rect.top)
|
|
177
|
+
|
|
178
|
+
if (distance < currentDistance && rect.top <= 100) {
|
|
179
|
+
currentActive = heading.id
|
|
180
|
+
currentDistance = distance
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
tocLinks.forEach(link => {
|
|
185
|
+
const parent = link.parentElement
|
|
186
|
+
if (parent) {
|
|
187
|
+
parent.classList.remove('toc-active', 'active-toc-item')
|
|
188
|
+
const href = link.getAttribute('href')?.substring(1)
|
|
189
|
+
if (href === currentActive) {
|
|
190
|
+
parent.classList.add('toc-active', 'active-toc-item')
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Throttle scroll events
|
|
197
|
+
let scrollTimeout
|
|
198
|
+
function throttledUpdate() {
|
|
199
|
+
if (!scrollTimeout) {
|
|
200
|
+
scrollTimeout = setTimeout(() => {
|
|
201
|
+
updateActiveTocItem()
|
|
202
|
+
scrollTimeout = null
|
|
203
|
+
}, 100)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
window.addEventListener('scroll', throttledUpdate)
|
|
208
|
+
updateActiveTocItem()
|
|
209
|
+
|
|
210
|
+
// TOC collapse/expand functionality
|
|
211
|
+
const expandableItems = document.querySelectorAll('.toc-expand')
|
|
212
|
+
|
|
213
|
+
expandableItems.forEach(item => {
|
|
214
|
+
item.addEventListener('click', function(e) {
|
|
215
|
+
if (e.target === this || e.target.closest('.toc-link')) {
|
|
216
|
+
this.classList.toggle('collapsed')
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
// Handle URL hash on page load
|
|
222
|
+
if (window.location.hash) {
|
|
223
|
+
const targetId = window.location.hash.substring(1)
|
|
224
|
+
const targetElement = document.getElementById(targetId)
|
|
225
|
+
|
|
226
|
+
if (targetElement) {
|
|
227
|
+
setTimeout(() => {
|
|
228
|
+
targetElement.scrollIntoView({
|
|
229
|
+
behavior: 'smooth',
|
|
230
|
+
block: 'start'
|
|
231
|
+
})
|
|
232
|
+
}, 100)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Initialize TOC when DOM is ready
|
|
238
|
+
if (document.readyState === 'loading') {
|
|
239
|
+
document.addEventListener('DOMContentLoaded', initToc)
|
|
240
|
+
} else {
|
|
241
|
+
initToc()
|
|
242
|
+
}
|
|
243
|
+
`}export{S as processInlineTocSyntax,h as getConfig,_ as generateUniqueSlug,v as generateTocStyles,T as generateTocScripts,D as generateTocPositions,Y as generateTocHtml,y as generateTocData,q as generateSlug,b as generateSidebarTocHtml,$ as generateInlineTocHtml,R as generateFloatingTocHtml,U as filterHeadings,I as extractHeadings,H as enhanceHeadingsWithAnchors,O as defaultTocConfig,f as defaultConfig,r as config,L as buildTocHierarchy};
|