bitcoin-inscription-viewer
Version:
🔍 A robust, production-ready React/TypeScript library for viewing Bitcoin Ordinals inscriptions with advanced optimization features including LRU caching, LaserEyes wallet integration, virtual scrolling, and performance monitoring
1 lines • 246 kB
JavaScript
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r,{useRef as s,useCallback as a,useEffect as i,useState as o,useMemo as l}from"react";import{Copy as c,Download as d,ZoomOut as h,ZoomIn as m,RotateCw as u,Move as p,Maximize2 as g,Pause as f,Play as x,VolumeX as b,Volume2 as y,Expand as v,Minimize as w,Eye as N,EyeOff as k,ExternalLink as T,RotateCcw as A,Square as C,Sun as E,Settings as R,AlertTriangle as S,Shield as I,ChevronLeft as L,ChevronRight as M,Home as j,RefreshCw as P,Info as _,Search as z,Hash as O,WrapText as D,Check as U,ChevronDown as F,FileText as H,Loader2 as $,AlertCircle as B,Trash2 as G,Plus as q,XCircle as V,CheckCircle as W}from"lucide-react";import*as K from"three";import{TrianglesDrawMode as X,TriangleFanDrawMode as J,TriangleStripDrawMode as Y,Loader as Z,LoaderUtils as Q,FileLoader as ee,MeshPhysicalMaterial as te,Vector2 as ne,Color as re,LinearSRGBColorSpace as se,SRGBColorSpace as ae,SpotLight as ie,PointLight as oe,DirectionalLight as le,Matrix4 as ce,Vector3 as de,Quaternion as he,InstancedMesh as me,InstancedBufferAttribute as ue,Object3D as pe,TextureLoader as ge,ImageBitmapLoader as fe,BufferAttribute as xe,InterleavedBuffer as be,InterleavedBufferAttribute as ye,LinearMipmapLinearFilter as ve,NearestMipmapLinearFilter as we,LinearMipmapNearestFilter as Ne,NearestMipmapNearestFilter as ke,LinearFilter as Te,NearestFilter as Ae,RepeatWrapping as Ce,MirroredRepeatWrapping as Ee,ClampToEdgeWrapping as Re,PointsMaterial as Se,Material as Ie,LineBasicMaterial as Le,MeshStandardMaterial as Me,DoubleSide as je,MeshBasicMaterial as Pe,PropertyBinding as _e,BufferGeometry as ze,SkinnedMesh as Oe,Mesh as De,LineSegments as Ue,Line as Fe,LineLoop as He,Points as $e,Group as Be,PerspectiveCamera as Ge,MathUtils as qe,OrthographicCamera as Ve,Skeleton as We,AnimationClip as Ke,Bone as Xe,InterpolateDiscrete as Je,InterpolateLinear as Ye,Texture as Ze,VectorKeyframeTrack as Qe,NumberKeyframeTrack as et,QuaternionKeyframeTrack as tt,ColorManagement as nt,FrontSide as rt,Interpolant as st,Box3 as at,Sphere as it,Float32BufferAttribute as ot,MeshPhongMaterial as lt}from"three";const ct=r.forwardRef(({className:t="",variant:n="default",size:r="default",children:s,...a},i)=>e("button",{className:`inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 ${{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"}[n]} ${{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}[r]} ${t}`,ref:i,...a,children:s}));ct.displayName="Button";class dt{constructor(e=3,t=.5){Object.defineProperty(this,"tokens",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"lastRefill",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxTokens",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"refillRate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"refillInterval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxTokens=e,this.refillRate=t,this.refillInterval=1e3/t,this.tokens=e,this.lastRefill=Date.now()}canMakeRequest(){return this.refillTokens(),this.tokens>0&&(this.tokens--,!0)}async waitForToken(){for(;!this.canMakeRequest();){const e=Math.max(100,this.refillInterval);await new Promise(t=>setTimeout(t,e))}}getWaitTime(){return this.refillTokens(),this.tokens>0?0:this.refillInterval}refillTokens(){const e=Date.now(),t=e-this.lastRefill,n=Math.floor(t/this.refillInterval);n>0&&(this.tokens=Math.min(this.maxTokens,this.tokens+n),this.lastRefill=e)}getTokenCount(){return this.refillTokens(),this.tokens}reset(){this.tokens=this.maxTokens,this.lastRefill=Date.now()}}const ht=new dt(2,.3);async function mt(e,t){return e.includes("ordinals.com")&&(await ht.waitForToken(),console.log(`🚦 Making throttled request to: ${e} (${ht.getTokenCount()} tokens remaining)`)),fetch(e,t)}function ut(){return ht.canMakeRequest()}function pt(){return ht.getWaitTime()}async function gt(e,t,n){console.log(`🔍 Starting content analysis for: ${e}`,{originalInscriptionId:t,knownContentType:n});try{const t=e.includes("/inscription/")||e.includes("/inscriptions")||e.includes("/block/")||e.includes("/sat/")||e.includes("/address/")||e.includes("/output/")||e.includes("/r/");let n,r=!1;try{console.log(`📡 Attempting ${t?"JSON API":"range"} request for: ${e}`);const s={};if(t?(s.Accept="application/json",s["User-Agent"]="InscriptionViewer/1.0.0"):s.Range="bytes=0-8191",n=await mt(e,{headers:s}),206!==n.status||t)if(416!==n.status||t){if(!n.ok){if(404===n.status||400===n.status)throw new Error(`PERMANENT_ERROR_${n.status}: ${n.statusText}`);throw new Error(`HTTP ${n.status}: ${n.statusText}`)}}else console.log(`⚠️ Range not supported, falling back to full request for: ${e}`),n=await mt(e);else r=!0,console.log(`✅ Range request successful for: ${e}`)}catch(t){if(t.message?.includes("PERMANENT_ERROR"))throw t;console.log(`⚠️ Range request failed, trying full request for: ${e}`,t),n=await mt(e)}if(!n.ok){if(404===n.status||400===n.status)throw new Error(`PERMANENT_ERROR_${n.status}: ${n.statusText}`);throw new Error(`HTTP ${n.status}: ${n.statusText}`)}const s=n.headers.get("content-type")||"application/octet-stream",a=n.headers.get("content-length");console.log(`📊 Content analysis - Type: ${s}, Length: ${a}, Range: ${r}`);const i=await n.arrayBuffer(),o=new Uint8Array(r?i:i.slice(0,8192)),l=new TextDecoder("utf-8",{fatal:!1});console.log(`📦 Received ${o.length} bytes for analysis`);let c="";try{c=l.decode(o)}catch{}const d=function(e,t,n){const r=e.toLowerCase();let s;if(console.log(`🔬 Analyzing content type - MIME: ${r}, Bytes: ${t.length}, Has text: ${!!n}`),t.length>=4){const e=Array.from(t.slice(0,4)).map(e=>e.toString(16).padStart(2,"0")).join(""),n=t.length>=8?Array.from(t.slice(0,8)).map(e=>e.toString(16).padStart(2,"0")).join(""):"";if(console.log(`🔍 Magic bytes: ${e} (first 4), ${n} (first 8)`),"89504e47"===e)return console.log("✅ Detected PNG by magic bytes"),{detectedType:"image",renderStrategy:"native",fileExtension:"png",isInlineable:!0,category:"media",displayName:"PNG Image",description:"Portable Network Graphics (detected by content)"};if(e.startsWith("ffd8"))return console.log("✅ Detected JPEG by magic bytes"),{detectedType:"image",renderStrategy:"native",fileExtension:"jpg",isInlineable:!0,category:"media",displayName:"JPEG Image",description:"JPEG compressed image (detected by content)"};if("47494638"===e)return console.log("✅ Detected GIF by magic bytes"),{detectedType:"image",renderStrategy:"native",fileExtension:"gif",isInlineable:!0,category:"media",displayName:"GIF Animation",description:"Graphics Interchange Format (detected by content)"};if("52494646"===e&&t.length>=12){if("57454250"===Array.from(t.slice(8,12)).map(e=>e.toString(16).padStart(2,"0")).join(""))return console.log("✅ Detected WebP by magic bytes"),{detectedType:"image",renderStrategy:"native",fileExtension:"webp",isInlineable:!0,category:"media",displayName:"WebP Image",description:"WebP compressed image (detected by content)"}}if(t.length>=4&&"%PDF"===String.fromCharCode(...t.slice(0,4)))return console.log("✅ Detected PDF by magic bytes"),{detectedType:"pdf",renderStrategy:"iframe",fileExtension:"pdf",isInlineable:!1,category:"document",displayName:"PDF Document",description:"Portable Document Format (detected by content)"};if(e.startsWith("504b"))return console.log("✅ Detected ZIP by magic bytes"),{detectedType:"archive",renderStrategy:"download",fileExtension:"zip",isInlineable:!1,category:"archive",displayName:"ZIP Archive",description:"ZIP compressed archive (detected by content)"}}if(n){const e=n.trim();if(console.log(`📝 Analyzing text content: ${e.substring(0,100)}...`),e.includes("<!DOCTYPE")||e.includes("<html")||e.includes("<head>")||e.includes("<body>")||e.includes("<")&&e.includes(">")&&e.includes("</"))return console.log("✅ Detected HTML by content structure"),{detectedType:"html",renderStrategy:"native",fileExtension:"html",isInlineable:!0,category:"document",displayName:"HTML Document",description:"HyperText Markup Language (detected by content)"};if(e.startsWith("{")&&e.includes("}")||e.startsWith("[")&&e.includes("]"))try{return JSON.parse(e),console.log("✅ Detected JSON by content structure"),{detectedType:"json",renderStrategy:"native",fileExtension:"json",isInlineable:!0,category:"data",displayName:"JSON Data",description:"JavaScript Object Notation (detected by content)"}}catch{console.log("❌ Content looks like JSON but failed to parse")}if(e.includes("<svg")||e.includes('xmlns="http://www.w3.org/2000/svg"'))return console.log("✅ Detected SVG by content structure"),{detectedType:"svg",renderStrategy:"native",fileExtension:"svg",isInlineable:!0,category:"media",displayName:"SVG Vector",description:"Scalable Vector Graphics (detected by content)"};if(e.includes("<?xml")||e.includes("<")&&e.includes(">")&&e.includes("</"))return console.log("✅ Detected XML by content structure"),{detectedType:"text",renderStrategy:"native",fileExtension:"xml",encoding:"utf-8",isInlineable:!0,category:"document",displayName:"XML Document",description:"Extensible Markup Language (detected by content)"}}console.log(`🏷️ Analyzing by MIME type: ${r}`),r.includes("audio/mpeg")||r.includes("audio/mp3")?s="mp3":r.includes("model/gltf-binary")?s="glb":r.includes("model/gltf")?s="gltf":r.includes("image/jpeg")?s="jpg":r.includes("image/png")?s="png":r.includes("video/mp4")?s="mp4":r.includes("image/svg")?s="svg":r.includes("text/html")&&(s="html");if(r.includes("application/json")||r.includes("text/json")||"json"===s||"jsonl"===s||"ndjson"===s)return{detectedType:"json",renderStrategy:"native",fileExtension:s||"json",encoding:"utf-8",isInlineable:!0,category:"data",displayName:"JSON Data",description:"JavaScript Object Notation data file"};if("text/html"===r||"html"===s||"htm"===s)return{detectedType:"html",renderStrategy:"native",fileExtension:s||"html",isInlineable:!0,category:"document",displayName:"HTML Document",description:"HyperText Markup Language document"};const a={js:"JavaScript",jsx:"JSX",ts:"TypeScript",tsx:"TSX",css:"CSS",scss:"SCSS",sass:"Sass",less:"Less",php:"PHP",asp:"ASP",aspx:"ASP.NET",py:"Python",java:"Java",c:"C",cpp:"C++",cc:"C++",h:"C Header",hpp:"C++ Header",cs:"C#",vb:"Visual Basic",fs:"F#",rb:"Ruby",go:"Go",rs:"Rust",kt:"Kotlin",swift:"Swift",dart:"Dart",scala:"Scala",pl:"Perl",pm:"Perl Module",hs:"Haskell",ml:"ML",elm:"Elm",clj:"Clojure",lisp:"Lisp",scm:"Scheme",rkt:"Racket",sh:"Shell Script",bash:"Bash",zsh:"Zsh",fish:"Fish",ps1:"PowerShell",bat:"Batch",cmd:"Command",xml:"XML",xsl:"XSLT",xsd:"XML Schema",sql:"SQL",psql:"PostgreSQL",mysql:"MySQL",asm:"Assembly",s:"Assembly",nasm:"NASM",lua:"Lua",vim:"Vim Script",r:"R",matlab:"MATLAB",julia:"Julia",nim:"Nim",zig:"Zig"};if(a[s||""]||r.includes("javascript")||r.includes("python")||r.includes("x-python")||r.includes("x-perl")||r.includes("x-ruby")||r.includes("x-php")||r.includes("x-c")||r.includes("x-java")||r.includes("x-go")||r.includes("x-rust")||r.includes("x-csharp")||r.includes("x-kotlin")||r.includes("x-swift")||r.includes("x-dart")||r.includes("x-scala")||r.includes("x-shell")||r.includes("x-sql")||r.includes("x-lua")){const e=a[s||""]||"Source Code";return{detectedType:"code",renderStrategy:"native",fileExtension:s,encoding:"utf-8",isInlineable:!0,category:"code",displayName:e,description:`${e} source code`}}if(r.startsWith("text/")||["txt","md","markdown","rst","asciidoc","org","tex","rtf","csv","tsv","ini","cfg","conf","log","yaml","yml","toml","properties","env","gitignore","gitconfig","dockerfile","makefile","readme","license","changelog","authors","contributors","copying","install","news"].includes(s||"")){let e="Text File",t="Plain text document";return r.includes("markdown")||"md"===s||"markdown"===s?(e="Markdown",t="Markdown formatted text"):r.includes("csv")||"csv"===s?(e="CSV Data",t="Comma-separated values data"):"yaml"===s||"yml"===s?(e="YAML Config",t="YAML configuration file"):"toml"===s?(e="TOML Config",t="TOML configuration file"):"log"===s&&(e="Log File",t="Application log file"),{detectedType:"text",renderStrategy:"native",fileExtension:s,encoding:"utf-8",isInlineable:!0,category:"document",displayName:e,description:t}}if(r.startsWith("image/")){let e="Image",t="Image file";return"image/svg+xml"===r||"svg"===s?{detectedType:"svg",renderStrategy:"native",fileExtension:"svg",isInlineable:!0,category:"media",displayName:"SVG Vector",description:"Scalable Vector Graphics"}:("image/webp"===r||"webp"===s?(e="WebP Image",t="WebP compressed image"):"image/avif"===r||"avif"===s?(e="AVIF Image",t="AV1 Image File Format"):r.includes("heic")||r.includes("heif")||"heic"===s||"heif"===s?(e="HEIC Image",t="High Efficiency Image Container"):"image/jpeg"===r||"jpg"===s||"jpeg"===s?(e="JPEG Image",t="JPEG compressed image"):"image/png"===r||"png"===s?(e="PNG Image",t="Portable Network Graphics"):"image/gif"===r||"gif"===s?(e="GIF Animation",t="Graphics Interchange Format"):"image/bmp"===r||"bmp"===s?(e="BMP Bitmap",t="Windows Bitmap"):"image/tiff"===r||"tiff"===s||"tif"===s?(e="TIFF Image",t="Tagged Image File Format"):"image/x-icon"!==r&&"ico"!==s||(e="Icon File",t="Windows Icon"),{detectedType:"image",renderStrategy:"native",fileExtension:s,isInlineable:!0,category:"media",displayName:e,description:t})}if(r.startsWith("audio/")){let e="Audio",t="Audio file";return r.includes("mp3")||"mp3"===s?(e="MP3 Audio",t="MPEG Layer-3 audio"):r.includes("wav")||"wav"===s?(e="WAV Audio",t="Waveform audio file"):r.includes("ogg")||"ogg"===s?(e="OGG Audio",t="Ogg Vorbis audio"):r.includes("flac")||"flac"===s?(e="FLAC Audio",t="Free Lossless Audio Codec"):r.includes("aac")||"aac"===s?(e="AAC Audio",t="Advanced Audio Coding"):r.includes("m4a")||"m4a"===s?(e="M4A Audio",t="MPEG-4 Audio"):"opus"===s&&(e="Opus Audio",t="Opus compressed audio"),{detectedType:"audio",renderStrategy:"native",fileExtension:s,isInlineable:!0,category:"media",displayName:e,description:t}}if(r.startsWith("video/")){let e="Video",t="Video file";return r.includes("mp4")||"mp4"===s?(e="MP4 Video",t="MPEG-4 video"):r.includes("webm")||"webm"===s?(e="WebM Video",t="WebM video format"):r.includes("ogg")||"ogv"===s?(e="OGV Video",t="Ogg video format"):r.includes("avi")||"avi"===s?(e="AVI Video",t="Audio Video Interleave"):r.includes("mov")||"mov"===s?(e="QuickTime Video",t="QuickTime movie"):"mkv"===s?(e="MKV Video",t="Matroska video"):"wmv"===s&&(e="WMV Video",t="Windows Media Video"),{detectedType:"video",renderStrategy:"native",fileExtension:s,isInlineable:!0,category:"media",displayName:e,description:t}}const i=["obj","gltf","glb","stl","3ds","dae","fbx","blend","max","ma","mb","c4d","x3d","wrl","ply"];if(r.startsWith("model/")||i.includes(s||"")){let e="3D Model",t="3D model file";return r.includes("gltf")||"gltf"===s?(e="GLTF Model",t="GL Transmission Format 3D model"):"glb"===s?(e="GLB Model",t="Binary GLTF 3D model"):"obj"===s?(e="OBJ Model",t="Wavefront OBJ 3D model"):"stl"===s?(e="STL Model",t="Stereolithography 3D model"):"fbx"===s?(e="FBX Model",t="Autodesk FBX 3D model"):"blend"===s&&(e="Blender File",t="Blender 3D project file"),{detectedType:"3d",renderStrategy:"native",fileExtension:s,isInlineable:!0,category:"media",displayName:e,description:t}}const o=["ttf","otf","woff","woff2","eot","fon","pfb","pfm"];if(r.includes("font")||o.includes(s||"")){let e="Font File",t="Font file";return"ttf"===s?(e="TrueType Font",t="TrueType font file"):"otf"===s?(e="OpenType Font",t="OpenType font file"):"woff"!==s&&"woff2"!==s||(e="Web Font",t="Web Open Font Format"),{detectedType:"font",renderStrategy:"iframe",fileExtension:s,isInlineable:!1,category:"font",displayName:e,description:t}}const l=["zip","rar","7z","tar","gz","bz2","xz","lzma","lz4","zst","cab","dmg","iso"];if(r.includes("zip")||r.includes("compressed")||r.includes("archive")||l.includes(s||"")){let e="Archive",t="Compressed archive file";return"zip"===s?(e="ZIP Archive",t="ZIP compressed archive"):"rar"===s?(e="RAR Archive",t="WinRAR compressed archive"):"7z"===s?(e="7-Zip Archive",t="7-Zip compressed archive"):"tar"===s?(e="TAR Archive",t="Tape archive file"):"gz"===s&&(e="GZIP Archive",t="GZIP compressed file"),{detectedType:"archive",renderStrategy:"download",fileExtension:s,isInlineable:!1,category:"archive",displayName:e,description:t}}if("application/pdf"===r||"pdf"===s)return{detectedType:"pdf",renderStrategy:"iframe",fileExtension:"pdf",isInlineable:!1,category:"document",displayName:"PDF Document",description:"Portable Document Format"};const c={doc:"Word Document",docx:"Word Document",xls:"Excel Spreadsheet",xlsx:"Excel Spreadsheet",ppt:"PowerPoint Presentation",pptx:"PowerPoint Presentation",odt:"OpenDocument Text",ods:"OpenDocument Spreadsheet",odp:"OpenDocument Presentation"};if(r.includes("officedocument")||r.includes("opendocument")||c[s||""]){return{detectedType:"document",renderStrategy:"download",fileExtension:s,isInlineable:!1,category:"document",displayName:c[s||""]||"Office Document",description:"Microsoft Office or OpenDocument file"}}if(["epub","mobi","azw","azw3","fb2","lit","pdb"].includes(s||""))return{detectedType:"ebook",renderStrategy:"download",fileExtension:s,isInlineable:!1,category:"document",displayName:"E-book",description:"Electronic book file"};if(["exe","msi","app","deb","rpm","dmg","pkg","appimage","flatpak","snap"].includes(s||"")||r.includes("executable"))return{detectedType:"executable",renderStrategy:"download",fileExtension:s,isInlineable:!1,category:"executable",displayName:"Executable File",description:"Application or installer"};const d={db:"Database",sqlite:"SQLite Database",mdb:"Access Database",xsd:"XML Schema",dtd:"Document Type Definition",plist:"Property List",reg:"Registry File",bin:"Binary Data",dat:"Data File",dump:"Memory Dump"};if(d[s||""])return{detectedType:"data",renderStrategy:"download",fileExtension:s,isInlineable:!1,category:"data",displayName:d[s||""]||"Data File",description:"Data or database file"};if(n){if(n.includes("<!DOCTYPE")||n.includes("<html")||n.includes("<head>")||n.includes("<body>"))return{detectedType:"html",renderStrategy:"native",fileExtension:s,isInlineable:!0,category:"document",displayName:"HTML Document",description:"HyperText Markup Language document"};const e=n.trim();if(e.startsWith("{")&&e.includes("}")||e.startsWith("[")&&e.includes("]"))try{return JSON.parse(e),{detectedType:"json",renderStrategy:"native",fileExtension:s,isInlineable:!0,category:"data",displayName:"JSON Data",description:"JavaScript Object Notation data"}}catch{}return n.includes("<?xml")||n.includes("<root")||n.includes("<")&&n.includes(">")?{detectedType:"text",renderStrategy:"native",fileExtension:s,encoding:"utf-8",isInlineable:!0,category:"document",displayName:"XML Document",description:"Extensible Markup Language document"}:n.includes("<svg")||n.includes('xmlns="http://www.w3.org/2000/svg"')?{detectedType:"svg",renderStrategy:"native",fileExtension:s,isInlineable:!0,category:"media",displayName:"SVG Vector",description:"Scalable Vector Graphics"}:{detectedType:"text",renderStrategy:"native",fileExtension:s,encoding:"utf-8",isInlineable:!0,category:"document",displayName:"Text File",description:"Plain text document"}}if(t.length>=4){const e=Array.from(t.slice(0,4)).map(e=>e.toString(16).padStart(2,"0")).join("");if(t.length>=8&&Array.from(t.slice(0,8)).map(e=>e.toString(16).padStart(2,"0")).join(""),"89504e47"===e)return{detectedType:"image",renderStrategy:"native",fileExtension:"png",isInlineable:!0,category:"media",displayName:"PNG Image",description:"Portable Network Graphics"};if(e.startsWith("ffd8"))return{detectedType:"image",renderStrategy:"native",fileExtension:"jpg",isInlineable:!0,category:"media",displayName:"JPEG Image",description:"JPEG compressed image"};if("47494638"===e)return{detectedType:"image",renderStrategy:"native",fileExtension:"gif",isInlineable:!0,category:"media",displayName:"GIF Animation",description:"Graphics Interchange Format"};if("52494646"===e&&t.length>=12){if("WEBP"===Array.from(t.slice(8,12)).map(e=>String.fromCharCode(e)).join(""))return{detectedType:"image",renderStrategy:"native",fileExtension:"webp",isInlineable:!0,category:"media",displayName:"WebP Image",description:"WebP compressed image"}}if(t.length>=4&&"%PDF"===String.fromCharCode(...t.slice(0,4)))return{detectedType:"pdf",renderStrategy:"iframe",fileExtension:"pdf",isInlineable:!1,category:"document",displayName:"PDF Document",description:"Portable Document Format"};if("504b0304"===e||"504b0506"===e||"504b0708"===e)return{detectedType:"archive",renderStrategy:"download",fileExtension:"zip",isInlineable:!1,category:"archive",displayName:"ZIP Archive",description:"ZIP compressed archive"}}return{detectedType:"binary",renderStrategy:"iframe",fileExtension:s,isInlineable:!1,category:"unknown",displayName:"Unknown File",description:`Unknown file type (${r})`}}(s,o,c);return{contentInfo:{...d,mimeType:s},preview:"text"===d.detectedType?c.slice(0,200):void 0}}catch(e){return{contentInfo:{mimeType:"application/octet-stream",detectedType:"unknown",renderStrategy:"iframe",isInlineable:!1},error:e.message}}}function ft(e,t){return!!(t&&t>1048576)||("video"===e.detectedType||"audio"===e.detectedType||("3d"===e.detectedType||"iframe"===e.renderStrategy))}class xt{constructor(e=100,t=30){Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxAge",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e,this.maxAge=60*t*1e3}get(e){const t=this.cache.get(e);return t?Date.now()-t.timestamp>this.maxAge?(this.cache.delete(e),null):t.data:null}set(e,t,n){if(this.cache.size>=this.maxSize){const e=this.cache.keys().next().value;e&&this.cache.delete(e)}this.cache.set(e,{data:t,timestamp:Date.now(),contentType:n})}has(e){const t=this.cache.get(e);return!!t&&(!(Date.now()-t.timestamp>this.maxAge)||(this.cache.delete(e),!1))}delete(e){return this.cache.delete(e)}clear(){this.cache.clear()}getStats(){return{size:this.cache.size,maxSize:this.maxSize,maxAge:this.maxAge}}async fetchContent(e){const t=this.get(e);if(t)return{data:t,contentType:this.cache.get(e)?.contentType||"text/plain"};try{const t=await fetch(e,{headers:{Accept:"application/json","User-Agent":"InscriptionViewer/1.0.0"}});if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);const n=t.headers.get("content-type")||"text/plain";let r;if(n.includes("application/json"))r=await t.json();else if(n.includes("text/"))r=await t.text();else if(n.startsWith("image/")||n.startsWith("audio/")||n.startsWith("video/"))r=e;else{const e=await t.blob();r=URL.createObjectURL(e)}return this.set(e,r,n),{data:r,contentType:n}}catch(e){throw console.error("Failed to fetch content:",e),e}}cleanup(){const e=Date.now(),t=[];this.cache.forEach((n,r)=>{e-n.timestamp>this.maxAge&&t.push(r)}),t.forEach(e=>this.cache.delete(e))}}const bt=new xt;class yt{constructor(e){Object.defineProperty(this,"wallet",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"cacheMaxAge",{enumerable:!0,configurable:!0,writable:!0,value:6e5}),this.wallet=e||null}setWallet(e){this.wallet=e}isAvailable(){return null!==this.wallet&&this.wallet.isConnected()}getAddress(){return this.wallet?.getAddress()||null}async getInscriptionContent(e){if(!this.isAvailable())return console.warn("LaserEyes wallet not available for inscription content fetch"),null;const t=this.cache.get(e);if(t&&Date.now()-t.timestamp<this.cacheMaxAge)return console.log(`🎯 Using cached LaserEyes content for inscription ${e}`),t.data;try{console.log(`🔥 Fetching inscription content via LaserEyes for: ${e}`);const t=await this.wallet.getInscriptionContent(e);if(!t)return console.warn(`No content returned from LaserEyes for inscription: ${e}`),null;let n,r;"string"==typeof t?(n=t,r="text/plain"):t.content&&t.contentType?(n=t.content,r=t.contentType):t instanceof ArrayBuffer||t.buffer?(n=t instanceof ArrayBuffer?t:t.buffer,r="application/octet-stream"):(n=JSON.stringify(t),r="application/json");const s={content:n,contentType:r,inscriptionId:e};return this.cache.set(e,{data:s,timestamp:Date.now()}),console.log(`✅ Successfully fetched inscription content via LaserEyes for: ${e}`),s}catch(t){return console.error(`❌ Failed to fetch inscription content via LaserEyes for ${e}:`,t),null}}clearCache(e){e?this.cache.delete(e):this.cache.clear()}getCacheStats(){return{size:this.cache.size,entries:Array.from(this.cache.keys())}}}const vt=new yt;function wt({content:n,mimeType:s,fileExtension:a,maxHeight:i=400,showControls:o=!1}){const[l,h]=r.useState(!1),m=r.useMemo(()=>s.includes("javascript")||s.includes("json")||s.includes("xml")||s.includes("html")||["javascript","typescript","json","html","css","xml","yaml","python","java","c","cpp","rust","go"].some(e=>s.includes(e))||["js","ts","jsx","tsx","json","html","css","xml","yaml","yml","py","java","c","cpp","rs","go","php","rb","sql"].includes(a||""),[s,a]),u=r.useMemo(()=>{if(s.includes("javascript"))return"javascript";if(s.includes("typescript"))return"typescript";if(s.includes("json"))return"json";if(s.includes("html"))return"html";if(s.includes("css"))return"css";if(s.includes("xml"))return"xml";if(s.includes("yaml"))return"yaml";if(s.includes("python"))return"python";return{js:"javascript",ts:"typescript",jsx:"javascript",tsx:"typescript",json:"json",html:"html",css:"css",xml:"xml",yaml:"yaml",yml:"yaml",py:"python",java:"java",c:"c",cpp:"cpp",rs:"rust",go:"go",php:"php",rb:"ruby",sql:"sql"}[a||""]||"text"},[s,a]);return t("div",{className:"w-full h-full flex flex-col",children:[o&&t("div",{className:"flex justify-between items-center p-2 border-b bg-gray-50 dark:bg-gray-800",children:[t("div",{className:"text-xs text-gray-600 dark:text-gray-400",children:[e("span",{className:"font-mono",children:u}),t("span",{className:"ml-2",children:["(",n.length.toLocaleString()," chars)"]})]}),t("div",{className:"flex gap-1",children:[t(ct,{variant:"ghost",size:"sm",onClick:async()=>{try{await navigator.clipboard.writeText(n),h(!0),setTimeout(()=>h(!1),2e3)}catch(e){console.error("Failed to copy:",e)}},className:"h-6 px-2 text-xs",children:[e(c,{className:"h-3 w-3 mr-1"}),l?"Copied!":"Copy"]}),t(ct,{variant:"ghost",size:"sm",onClick:()=>{const e=new Blob([n],{type:s}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download=`content.${a||"txt"}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(t)},className:"h-6 px-2 text-xs",children:[e(d,{className:"h-3 w-3 mr-1"}),"Download"]})]})]}),e("div",{className:"flex-1 overflow-hidden w-full",style:{maxHeight:i-(o?70:0),minHeight:"100px"},children:e("pre",{className:"text-xs p-4 w-full h-full overflow-auto font-mono whitespace-pre-wrap break-words scrollbar-hide "+(m?"text-gray-800 dark:text-gray-200":"text-gray-900 dark:text-gray-100"),style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:n})})]})}function Nt(e,t="Unknown"){if(!e||"string"!=typeof e)return t;const n=e.split("/");return n.length<2||!n[1]?t:n[1].toUpperCase()}function kt(e,t="Unknown"){if(!e||"string"!=typeof e)return t;return(e.startsWith(".")?e.slice(1):e).toUpperCase()}function Tt(e,t,n="Unknown"){if(t){const e=kt(t,"");if(e&&"Unknown"!==e)return e}if(e){const t=Nt(e,"");if(t&&"Unknown"!==t)return t}return n}function At(e,t=""){if(null==e)return t;try{return String(e).toUpperCase()}catch{return t}}function Ct(e){if(!e||!Number.isFinite(e)||e<0)return"00:00";const t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${n.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`}function Et(e){if(!e||!Number.isFinite(e)||e<0)return"0 B";const t=["B","KB","MB","GB","TB"];let n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n.toFixed(0===r?0:1)} ${t[r]}`}function Rt({src:n,alt:o="Inscription image",mimeType:l,fileExtension:c,maxHeight:f=400,showControls:x=!1}){const[b,y]=r.useState(1),[v,w]=r.useState(0),[N,k]=r.useState({x:0,y:0}),[T,A]=r.useState(!1),[C,E]=r.useState(!1),[R,S]=r.useState(!1),[I,L]=r.useState(null),[M,j]=r.useState(!1),[P,_]=r.useState({x:0,y:0}),z=s(null),O=s(null),D=a(e=>{E(!0);const t=e.target;L({width:t.naturalWidth,height:t.naturalHeight})},[]),U=a(()=>{S(!0),E(!1)},[]),F=a(()=>{y(1),w(0),k({x:0,y:0})},[]),H=a(()=>{y(e=>Math.min(5,e+.2))},[]),$=a(()=>{y(e=>{const t=Math.max(.1,e-.2);return t<=1&&k({x:0,y:0}),t})},[]),B=a(()=>{w(e=>(e+90)%360),k({x:0,y:0})},[]),G=a(e=>{b>1&&(j(!0),_({x:e.clientX-N.x,y:e.clientY-N.y}),e.preventDefault())},[b,N]),q=a(e=>{M&&b>1&&k({x:e.clientX-P.x,y:e.clientY-P.y})},[M,P,b]),V=a(()=>{j(!1)},[]);i(()=>{const e=e=>{if(C)switch(e.key){case"+":case"=":e.preventDefault(),H();break;case"-":e.preventDefault(),$();break;case"r":case"R":e.preventDefault(),B();break;case"Escape":T&&A(!1);break;case"0":e.preventDefault(),F()}};if(T)return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[C,T,H,$,B,F]);const W=a(e=>{if(e.ctrlKey||e.metaKey){e.preventDefault();const t=e.deltaY>0?-.1:.1;y(e=>Math.max(.1,Math.min(5,e+t)))}},[]),K=T?"100vh":f-(x&&C?70:0)+"px";return R?e("div",{className:"w-full h-full flex items-center justify-center bg-gray-100 dark:bg-gray-800 rounded-lg",children:t("div",{className:"text-center text-gray-500",children:[e("div",{className:"text-4xl mb-4 opacity-50",children:"🖼️"}),e("div",{className:"text-sm font-medium mb-1",children:"Failed to load image"}),t("div",{className:"text-xs text-gray-400",children:[l," • ",c]}),e(ct,{variant:"outline",size:"sm",className:"mt-3",onClick:()=>{S(!1),E(!1)},children:"Retry"})]})}):t("div",{className:"w-full h-full flex flex-col "+(T?"fixed inset-0 z-50 bg-black":"rounded-lg overflow-hidden border"),children:[x&&C&&t("div",{className:"flex justify-between items-center p-3 border-b bg-gray-50 dark:bg-gray-800",children:[t("div",{className:"text-xs text-gray-600 dark:text-gray-400 space-x-3",children:[e("span",{className:"font-mono bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded",children:Nt(l)}),I&&t("span",{children:[I.width," × ",I.height]}),t("span",{children:[Math.round(100*b),"%"]})]}),t("div",{className:"flex gap-1",children:[e(ct,{variant:"ghost",size:"sm",onClick:$,className:"h-8 px-2 text-xs",disabled:b<=.2,title:"Zoom out (-)",children:e(h,{className:"h-3 w-3"})}),e(ct,{variant:"ghost",size:"sm",onClick:H,className:"h-8 px-2 text-xs",disabled:b>=5,title:"Zoom in (+)",children:e(m,{className:"h-3 w-3"})}),e(ct,{variant:"ghost",size:"sm",onClick:B,className:"h-8 px-2 text-xs",title:"Rotate (R)",children:e(u,{className:"h-3 w-3"})}),e(ct,{variant:"ghost",size:"sm",onClick:F,className:"h-8 px-2 text-xs",title:"Reset (0)",children:"Reset"}),b>1&&e(ct,{variant:"ghost",size:"sm",className:"h-8 px-2 text-xs pointer-events-none",title:"Pan mode active",children:e(p,{className:"h-3 w-3"})}),e(ct,{variant:"ghost",size:"sm",onClick:()=>A(!T),className:"h-8 px-2 text-xs",title:"Fullscreen",children:e(g,{className:"h-3 w-3"})}),e(ct,{variant:"ghost",size:"sm",onClick:async()=>{try{const e=await fetch(n),t=await e.blob(),r=URL.createObjectURL(t),s=document.createElement("a");s.href=r,s.download=`image.${c||"png"}`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r)}catch(e){console.error("Failed to download:",e)}},className:"h-8 px-2 text-xs",title:"Download",children:e(d,{className:"h-3 w-3"})})]})]}),t("div",{ref:O,className:"flex-1 relative overflow-hidden bg-gray-50 dark:bg-gray-900",style:{height:K,minHeight:T?"100vh":"200px",cursor:b>1?M?"grabbing":"grab":"default"},onMouseDown:G,onMouseMove:q,onMouseUp:V,onMouseLeave:V,onWheel:W,children:[e("div",{className:"absolute inset-0 flex items-center justify-center transition-transform duration-200",style:{transform:`translate(${N.x}px, ${N.y}px)`},children:e("img",{ref:z,src:n,alt:o,className:"max-w-full max-h-full object-contain transition-transform duration-200 select-none",style:{transform:`scale(${b}) rotate(${v}deg)`,imageRendering:b>2?"pixelated":"auto"},onLoad:D,onError:U,draggable:!1})}),!C&&!R&&e("div",{className:"absolute inset-0 flex items-center justify-center",children:t("div",{className:"text-center text-gray-500",children:[e("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500 mx-auto mb-4"}),e("div",{className:"text-sm font-medium",children:"Loading image..."}),e("div",{className:"text-xs text-gray-400 mt-1",children:"Please wait"})]})}),T&&t("div",{className:"absolute top-4 right-4 flex gap-2",children:[e("div",{className:"bg-black/70 text-white text-xs px-3 py-1 rounded",children:"Press ESC to exit • Use +/- to zoom • R to rotate"}),e(ct,{variant:"ghost",size:"sm",onClick:()=>A(!1),className:"bg-black/70 text-white hover:bg-black/90 border-white/20",children:"✕ Exit"})]}),1!==b&&!T&&t("div",{className:"absolute bottom-4 left-4 bg-black/70 text-white text-xs px-2 py-1 rounded",children:[Math.round(100*b),"%"]})]})]})}function St({src:n,mimeType:s,fileExtension:a,maxHeight:i=400,showControls:o=!0}){const l=r.useRef(null),[c,h]=r.useState(null),[m,u]=r.useState(!0),[p,v]=r.useState(!1),[w,N]=r.useState(!1),[k,T]=r.useState(!1),[A,C]=r.useState(null),E=()=>{const e=l.current;e&&(p?e.pause():e.play())},R=async()=>{try{const e=await fetch(n),t=await e.blob(),r=URL.createObjectURL(t),s=document.createElement("a");s.href=r,s.download=`video.${a||"mp4"}`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r)}catch(e){console.error("Failed to download:",e)}};return e("div",c?{className:"w-full h-full flex items-center justify-center bg-gray-100 dark:bg-gray-800",children:t("div",{className:"text-center text-gray-500",children:[e("div",{className:"text-2xl mb-2",children:"🎬"}),e("div",{className:"text-sm",children:"Failed to load video"}),t("div",{className:"text-xs mt-1 text-gray-400",children:[s," • ",a]}),e("div",{className:"mt-3",children:t(ct,{variant:"outline",size:"sm",onClick:R,className:"text-xs",children:[e(d,{className:"h-3 w-3 mr-1"}),"Download Video"]})})]})}:{className:"w-full h-full flex flex-col rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700",children:t("div",{className:"flex-1 relative bg-black rounded-lg overflow-hidden",onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),children:[m&&e("div",{className:"absolute inset-0 z-20 flex items-center justify-center",children:t("div",{className:"text-center text-white",children:[e("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-white mx-auto mb-2"}),e("div",{className:"text-sm",children:"Loading video..."})]})}),e("video",{ref:l,src:n,className:"w-full h-full object-contain rounded-lg",style:{maxHeight:i},onLoadedMetadata:e=>{const t=e.currentTarget;C({width:t.videoWidth,height:t.videoHeight}),u(!1)},onCanPlay:()=>{u(!1)},onError:()=>{h("Failed to load video"),u(!1)},onPlay:()=>{v(!0)},onPause:()=>{v(!1)},preload:"metadata",onClick:E}),!m&&e("div",{className:"absolute inset-0 z-10 flex items-center justify-center pointer-events-none",children:e(ct,{variant:"default",size:"lg",onClick:E,className:"pointer-events-auto bg-white hover:bg-gray-100 text-black border-2 border-gray-300 hover:border-gray-400 rounded-full p-6 transition-all duration-300 shadow-2xl backdrop-blur-sm",children:p?e(f,{className:"h-12 w-12"}):e(x,{className:"h-12 w-12 ml-1"})})}),k&&!m&&e("div",{className:"absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/40 to-transparent p-4 transition-all duration-200",children:t("div",{className:"flex items-center justify-between",children:[e("div",{className:"flex items-center gap-2",children:e(ct,{variant:"ghost",size:"sm",onClick:E,className:"text-white hover:bg-white/20 h-8 w-8 p-0",children:e(p?f:x,{className:"h-4 w-4"})})}),t("div",{className:"flex items-center gap-2",children:[e(ct,{variant:"ghost",size:"sm",onClick:()=>{const e=l.current;e&&(e.muted=!e.muted,N(e.muted))},className:"text-white hover:bg-white/20 h-8 w-8 p-0",children:e(w?b:y,{className:"h-4 w-4"})}),e(ct,{variant:"ghost",size:"sm",onClick:()=>{const e=l.current;e&&(document.fullscreenElement?document.exitFullscreen():e.requestFullscreen())},className:"text-white hover:bg-white/20 h-8 w-8 p-0",children:e(g,{className:"h-4 w-4"})})]})]})})]})})}function It({src:s,mimeType:a,fileExtension:i,maxHeight:o=300,showControls:l=!0}){console.log("🎵 AudioRenderer render:",{src:s.substring(0,50),showControls:l,mimeType:a,fileExtension:i});const c=r.useRef(null),[h,m]=r.useState(null),[u,p]=r.useState(!0),[g,v]=r.useState(!1),[w,N]=r.useState(!1),[k,T]=r.useState(!1),[A,C]=r.useState(0);r.useEffect(()=>{console.log("🎵 AudioRenderer props:",{showControls:l,shouldShowControls:true,mimeType:a,fileExtension:i,src:s})},[l,a,i,s]);const E=r.useMemo(()=>{const e=i?.toLowerCase()||"";return["mp3","wav","ogg","m4a","aac","flac","webm","opus"].includes(e)||a.startsWith("audio/")},[a,i]),R=()=>{const e=c.current;e&&(g?e.pause():e.play())},S=async()=>{try{const e=await fetch(s),t=await e.blob(),n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.download=`audio.${i||"mp3"}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}catch(e){console.error("Failed to download:",e)}};return e("div",E?h?{className:"w-full h-full flex items-center justify-center bg-gray-100 dark:bg-gray-800",children:t("div",{className:"text-center text-gray-500",children:[e("div",{className:"text-2xl mb-2",children:"⚠️"}),e("div",{className:"text-sm text-red-600 dark:text-red-400",children:"Audio Load Error"}),e("div",{className:"text-xs mt-1 text-gray-400",children:h}),t("div",{className:"text-xs mt-1 text-gray-400",children:[Nt(a)," • ",kt(i)]}),e("div",{className:"mt-3",children:t(ct,{variant:"outline",size:"sm",onClick:S,className:"text-xs",children:[e(d,{className:"h-3 w-3 mr-1"}),"Download Audio"]})})]})}:{className:"w-full h-full flex flex-col rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700",children:t("div",{className:"flex-1 relative bg-gradient-to-br from-blue-50 to-purple-50 dark:from-gray-800 dark:to-gray-900 rounded-lg",style:{minHeight:"120px"},onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),children:[e("audio",{ref:c,src:s,onLoadedMetadata:e=>{const t=e.currentTarget;t.duration>0&&(C(t.duration),p(!1),console.log("✅ Audio metadata loaded - duration:",t.duration))},onCanPlay:()=>{p(!1),console.log("✅ Audio can play")},onError:e=>{console.error("❌ Audio error:",e),m("Failed to load audio"),p(!1)},onPlay:()=>{v(!0)},onPause:()=>{v(!1)},preload:"metadata",className:"hidden"}),e("div",{className:"absolute inset-0 flex items-center justify-center cursor-pointer rounded-lg",onClick:R,children:t("div",{className:"text-center",children:[t(n,u?{children:[e("div",{className:"text-4xl mb-4 animate-pulse",children:"🔄"}),e("div",{className:"text-lg font-medium text-gray-700 dark:text-gray-300",children:"Loading Audio..."})]}:{children:[e("div",{className:"text-6xl mb-4 opacity-30",children:"🎵"}),e("div",{className:"text-lg font-medium text-gray-700 dark:text-gray-300",children:g?"Now Playing":"Audio Player"})]}),t("div",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1 opacity-75",children:[Nt(a)," • ",kt(i)]})]})}),!u&&e("div",{className:"absolute inset-0 z-10 flex items-center justify-center pointer-events-none",children:e(ct,{variant:"default",size:"lg",onClick:R,className:"pointer-events-auto bg-white hover:bg-gray-100 text-black border-2 border-gray-300 hover:border-gray-400 rounded-full p-6 transition-all duration-300 shadow-2xl backdrop-blur-sm",children:g?e(f,{className:"h-12 w-12"}):e(x,{className:"h-12 w-12 ml-1"})})}),k&&!u&&e("div",{className:"absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/40 to-transparent p-4 transition-all duration-200",children:t("div",{className:"flex items-center justify-between",children:[t("div",{className:"flex items-center gap-2",children:[e(ct,{variant:"ghost",size:"sm",onClick:R,className:"text-white hover:bg-white/20 h-8 w-8 p-0",children:e(g?f:x,{className:"h-4 w-4"})}),A>0&&t("span",{className:"text-white text-xs",children:[Math.floor(A/60),":",(A%60).toFixed(0).padStart(2,"0")]})]}),t("div",{className:"flex items-center gap-2",children:[e(ct,{variant:"ghost",size:"sm",onClick:()=>{const e=c.current;e&&(e.muted=!e.muted,N(e.muted))},className:"text-white hover:bg-white/20 h-8 w-8 p-0",children:e(w?b:y,{className:"h-4 w-4"})}),e(ct,{variant:"ghost",size:"sm",onClick:S,className:"text-white hover:bg-white/20 h-8 w-8 p-0",children:e(d,{className:"h-4 w-4"})})]})]})})]})}:{className:"w-full h-full flex items-center justify-center bg-gray-100 dark:bg-gray-800",children:t("div",{className:"text-center text-gray-500",children:[e("div",{className:"text-2xl mb-2",children:"🎵"}),e("div",{className:"text-sm",children:"Audio format not supported"}),t("div",{className:"text-xs mt-1 text-gray-400",children:[Nt(a)," • ",kt(i)]}),e("div",{className:"mt-3",children:t(ct,{variant:"outline",size:"sm",onClick:S,className:"text-xs",children:[e(d,{className:"h-3 w-3 mr-1"}),"Download Audio"]})})]})})}function Lt({content:n,mimeType:s,maxHeight:a=400,showControls:i=!1}){const[o,l]=r.useState(null),[h,m]=r.useState(null),[u,p]=r.useState(new Set),[g,f]=r.useState(!1),[x,b]=r.useState(!1);r.useEffect(()=>{try{const e=JSON.parse(n);l(e),m(null)}catch(e){m(e.message),l(null)}},[n]);const y=async()=>{try{await navigator.clipboard.writeText(n),b(!0),setTimeout(()=>b(!1),2e3)}catch(e){console.error("Failed to copy:",e)}},N=e=>{const t=new Set(u);t.has(e)?t.delete(e):t.add(e),p(t)},k=(n,r="",s=0)=>{if(null===n)return e("span",{className:"text-gray-500",children:"null"});if("boolean"==typeof n)return e("span",{className:"text-blue-600 dark:text-blue-400",children:n.toString()});if("number"==typeof n)return e("span",{className:"text-purple-600 dark:text-purple-400",children:n});if("string"==typeof n)return t("span",{className:"text-green-600 dark:text-green-400",children:['"',n,'"']});if(Array.isArray(n)){const a=u.has(r);return t("div",{children:[e("span",{className:"cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700 px-1 rounded",onClick:()=>N(r),children:t("span",{className:"text-gray-500",children:[a?"►":"▼"," [",n.length,"]"]})}),!a&&e("div",{className:"ml-4",children:n.map((a,i)=>t("div",{className:"font-mono text-sm",children:[t("span",{className:"text-gray-400",children:[i,": "]}),k(a,`${r}[${i}]`,s+1),i<n.length-1&&e("span",{className:"text-gray-500",children:","})]},i))})]})}if("object"==typeof n){const a=Object.keys(n),i=u.has(r);return t("div",{children:[e("span",{className:"cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700 px-1 rounded",onClick:()=>N(r),children:t("span",{className:"text-gray-500",children:[i?"►":"▼"," ",`{${a.length}}`]})}),!i&&e("div",{className:"ml-4",children:a.map((i,o)=>t("div",{className:"font-mono text-sm",children:[t("span",{className:"text-blue-600 dark:text-blue-400",children:['"',i,'"']}),e("span",{className:"text-gray-500",children:": "}),k(n[i],r?`${r}.${i}`:i,s+1),o<a.length-1&&e("span",{className:"text-gray-500",children:","})]},i))})]})}return e("span",{children:String(n)})};return t("div",h?{className:"w-full h-full flex flex-col bg-white dark:bg-gray-900",children:[i&&t("div",{className:"flex justify-between items-center p-2 border-b bg-red-50 dark:bg-red-900/20",children:[e("div",{className:"text-xs text-red-600 dark:text-red-400",children:e("span",{className:"font-mono",children:"Invalid JSON"})}),t(ct,{variant:"ghost",size:"sm",onClick:y,className:"h-6 px-2 text-xs",children:[e(c,{className:"h-3 w-3 mr-1"}),"Copy Raw"]})]}),t("div",{className:"flex-1 p-4",children:[e("div",{className:"text-red-600 dark:text-red-400 mb-2",children:"JSON Parse Error:"}),e("div",{className:"text-sm text-red-500 mb-4",children:h}),e("pre",{className:"text-xs font-mono bg-gray-100 dark:bg-gray-800 p-3 rounded overflow-auto whitespace-pre-wrap scrollbar-hide",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:n})]})]}:{className:"w-full h-full flex flex-col",children:[i&&t("div",{className:"flex justify-between items-center p-2 border-b bg-gray-50 dark:bg-gray-800",children:[t("div",{className:"text-xs text-gray-600 dark:text-gray-400",children:[e("span",{className:"font-mono",children:"JSON"}),t("span",{className:"ml-2",children:["(",n.length.toLocaleString()," chars)"]})]}),t("div",{className:"flex gap-1",children:[t(ct,{variant:"ghost",size:"sm",onClick:()=>{if(g)p(new Set);else{const e=new Set,t=(n,r="")=>{"object"==typeof n&&null!==n&&(r&&e.add(r),Object.keys(n).forEach(e=>{const s=r?`${r}.${e}`:e;t(n[e],s)}))};o&&t(o),p(e)}f(!g)},className:"h-6 px-2 text-xs",children:[e(g?v:w,{className:"h-3 w-3 mr-1"}),g?"Expand":"Collapse"]}),t(ct,{variant:"ghost",size:"sm",onClick:y,className:"h-6 px-2 text-xs",children:[e(c,{className:"h-3 w-3 mr-1"}),x?"Copied!":"Copy"]}),t(ct,{variant:"ghost",size:"sm",onClick:()=>{const e=new Blob([n],{type:"application/json"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download="data.json",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(t)},className:"h-6 px-2 text-xs",children:[e(d,{className:"h-3 w-3 mr-1"}),"Download"]})]})]}),e("div",{className:"flex-1 overflow-hidden p-4 font-mono text-sm w-full",style:{maxHeight:a-(i?60:0),minHeight:"100px"},children:e("div",{className:"w-full h-full overflow-auto scrollbar-hide",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:o&&k(o)})})]})}function Mt({content:n,src:s,mimeType:a,maxHeight:i=400,showControls:o=!1}){const[l,c]=r.useState(!1),[h,m]=r.useState(null),u=r.useRef(null),p=r.useMemo(()=>{if(!n)return s;try{const e=new Blob([n],{type:"text/html"});return URL.createObjectURL(e)}catch(e){return m(e.message),null}},[n,s]);r.useEffect(()=>()=>{p&&p.startsWith("blob:")&&URL.revokeObjectURL(p)},[p]);return h?e("div",{className:"w-full h-full flex items-center justify-center bg-gray-100 dark:bg-gray-800",children:t("div",{className:"text-center text-gray-500",children:[e("div",{className:"text-2xl mb-2",children:"🌐"}),e("div",{className:"text-sm",children:"Failed to render HTML"}),e("div",{className:"text-xs mt-1 text-gray-400",children:h})]})}):t("div",{className:"w-full h-full flex flex-col",children:[o&&t("div",{className:"flex justify-between items-center p-2 border-b bg-gray-50 dark:bg-gray-800",children:[t("div",{className:"text-xs text-gray-600 dark:text-gray-400",children:[e("span",{className:"font-mono",children:"HTML"}),n&&t("span",{className:"ml-2",children:["(",n.length.toLocaleString()," chars)"]})]}),t("div",{className:"flex gap-1",children:[n&&t(ct,{variant:"ghost",size:"sm",onClick:()=>c(!l),className:"h-6 px-2 text-xs",children:[e(l?N:k,{className:"h-3 w-3 mr-1"}),l?"Rendered":"Source"]}),t(ct,{variant:"ghost",size:"sm",onClick:()=>{p&&window.open(p,"_blank")},className:"h-6 px-2 text-xs",children:[e(T,{className:"h-3 w-3 mr-1"}),"Open"]}),n&&t(ct,{variant:"ghost",size:"sm",onClick:()=>{const e=new Blob([n||""],{type:"text/html"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download="content.html",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(t)},className:"h-6 px-2 text-xs",children:[e(d,{className:"h-3 w-3 mr-1"}),"Download"]})]})]}),e("div",{className:"flex-1 overflow-hidden",style:{maxHeight:i-(o?60:0),minHeight:"200px"},children:l&&n?e("pre",{className:"text-xs p-4 h-full overflow-auto font-mono whitespace-pre-wrap break-words bg-gray-50 dark:bg-gray-900 text-gray-800 dark:text-gray-200 scrollbar-hide",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:n}):e("iframe",{ref:u,src:p||void 0,className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",title:"HTML Content",onError:()=>m("Failed to load HTML content")})})]})}function jt(e,t){if(t===X)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t===J||t===Y){let n=e.getIndex();if(null===n){const t=[],r=e.getAttribute("position");if(void 0===r)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<r.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}const r=n.count-2,s=[];if(t===J)for(let e=1;e<=r;e++)s.push(n.getX(0)),s.push(n.getX(e)),s.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(s.push(n.getX(e)),s.push(n.getX(e+1)),s.push(n.getX(e+2))):(s.push(n.getX(e+2)),s.push(n.getX(e+1)),s.push(n.getX(e)));s.length/3!==r&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const a=e.clone();return a.setIndex(s),a.clearGroups(),a}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e}class Pt extends Z{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(functi