@qumra/fanar 0.0.13 → 0.0.14

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.
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{TONE_SOFT,TONE_SOLID,cn,useUIText}from"./chunk-6DTSIOCB.js";import{useCallback,useEffect,useRef,useState}from"react";var INITIAL={playing:false,time:0,duration:0,buffered:0,volume:1,muted:false,rate:1,waiting:false,ended:false};function useMedia(){const ref=useRef(null);const[state,setState]=useState(INITIAL);useEffect(()=>{const el=ref.current;if(!el)return;const patch=p=>setState(s=>({...s,...p}));const onTime=()=>{let end=0;const b=el.buffered;for(let i=0;i<b.length;i++){if(b.start(i)<=el.currentTime&&el.currentTime<=b.end(i))end=b.end(i)}patch({time:el.currentTime,buffered:end})};const onMeta=()=>patch({duration:Number.isFinite(el.duration)?el.duration:0,ended:false});const onPlay=()=>patch({playing:true,ended:false});const onPause=()=>patch({playing:false});const onEnded=()=>patch({playing:false,ended:true});const onWaiting=()=>patch({waiting:true});const onPlaying=()=>patch({waiting:false,playing:true});const onVolume=()=>patch({volume:el.volume,muted:el.muted});const onRate=()=>patch({rate:el.playbackRate});el.addEventListener("timeupdate",onTime);el.addEventListener("progress",onTime);el.addEventListener("loadedmetadata",onMeta);el.addEventListener("durationchange",onMeta);el.addEventListener("play",onPlay);el.addEventListener("pause",onPause);el.addEventListener("ended",onEnded);el.addEventListener("waiting",onWaiting);el.addEventListener("playing",onPlaying);el.addEventListener("volumechange",onVolume);el.addEventListener("ratechange",onRate);if(el.readyState>=1)onMeta();return()=>{el.removeEventListener("timeupdate",onTime);el.removeEventListener("progress",onTime);el.removeEventListener("loadedmetadata",onMeta);el.removeEventListener("durationchange",onMeta);el.removeEventListener("play",onPlay);el.removeEventListener("pause",onPause);el.removeEventListener("ended",onEnded);el.removeEventListener("waiting",onWaiting);el.removeEventListener("playing",onPlaying);el.removeEventListener("volumechange",onVolume);el.removeEventListener("ratechange",onRate)}},[]);useEffect(()=>{if(!state.playing)return;let raf=0;const tick=()=>{const el=ref.current;if(el)setState(s=>s.time===el.currentTime?s:{...s,time:el.currentTime});raf=requestAnimationFrame(tick)};raf=requestAnimationFrame(tick);return()=>cancelAnimationFrame(raf)},[state.playing]);const toggle=useCallback(()=>{const el=ref.current;if(!el)return;if(el.paused)void el.play();else el.pause()},[]);const seek=useCallback(to=>{const el=ref.current;if(!el)return;el.currentTime=Math.max(0,Math.min(to,el.duration||0))},[]);const skip=useCallback(by=>{const el=ref.current;if(el)seek(el.currentTime+by)},[seek]);const setVolume=useCallback(v=>{const el=ref.current;if(!el)return;el.volume=Math.max(0,Math.min(1,v));if(el.volume>0)el.muted=false},[]);const toggleMute=useCallback(()=>{const el=ref.current;if(el)el.muted=!el.muted},[]);const setRate=useCallback(r=>{const el=ref.current;if(el)el.playbackRate=r},[]);return{ref,state,toggle,seek,skip,setVolume,toggleMute,setRate}}function formatTime(seconds){if(!Number.isFinite(seconds)||seconds<0)return"0:00";const total=Math.floor(seconds);const s=total%60;const m=Math.floor(total/60)%60;const h=Math.floor(total/3600);const pad=n=>String(n).padStart(2,"0");return h>0?`${h}:${pad(m)}:${pad(s)}`:`${m}:${pad(s)}`}var RATES=[.5,.75,1,1.25,1.5,2];import{useCallback as useCallback2,useRef as useRef2,useState as useState2}from"react";import{jsx,jsxs}from"react/jsx-runtime";function Scrubber({time,duration,buffered,onSeek,chapters,label,size="md"}){const ui=useUIText();const bar=useRef2(null);const[hover,setHover]=useState2(null);const pct=duration>0?time/duration*100:0;const buf=duration>0?(buffered??0)/duration*100:0;const atPointer=useCallback2(clientX=>{const box=bar.current?.getBoundingClientRect();if(!box||duration<=0)return null;const ratio=Math.max(0,Math.min(1,(clientX-box.left)/box.width));return ratio*duration},[duration]);const h=size==="sm"?"h-1":"h-1.5";return jsxs("div",{dir:"ltr",className:"relative group/scrub w-full py-2 select-none",children:[hover!==null&&jsx("span",{"data-num":true,style:{insetInlineStart:`${hover/duration*100}%`},className:"absolute bottom-full mb-1 -translate-x-1/2 px-1.5 py-0.5 rounded-xs bg-night text-white text-micro font-bold pointer-events-none whitespace-nowrap",children:formatTime(hover)}),jsxs("div",{ref:bar,onMouseMove:e=>setHover(atPointer(e.clientX)),onMouseLeave:()=>setHover(null),className:cn("relative w-full rounded-full bg-white/25 overflow-visible",h),children:[jsx("span",{"aria-hidden":"true",style:{width:`${buf}%`},className:cn("absolute inset-y-0 start-0 rounded-full bg-white/30",h)}),jsx("span",{"aria-hidden":"true",style:{width:`${pct}%`},className:cn("absolute inset-y-0 start-0 rounded-full bg-brand",h)}),chapters?.map(c=>duration>0&&c.at>0&&c.at<duration?jsx("span",{title:c.title,"aria-hidden":"true",style:{insetInlineStart:`${c.at/duration*100}%`},className:"absolute inset-y-0 w-0.5 -translate-x-1/2 bg-night/50"},`${c.at}-${c.title}`):null),jsx("span",{"aria-hidden":"true",style:{insetInlineStart:`${pct}%`},className:"absolute top-1/2 -translate-y-1/2 -translate-x-1/2 size-3 rounded-full bg-white shadow-raise scale-0 transition-transform group-hover/scrub:scale-100 group-focus-within/scrub:scale-100"}),jsx("input",{type:"range",min:0,max:duration||0,step:.1,value:time,"aria-label":label??ui.playbackPosition,"aria-valuetext":`${formatTime(time)} \u0645\u0646 ${formatTime(duration)}`,onChange:e=>onSeek(Number(e.target.value)),className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]})]})}import{useCallback as useCallback3,useEffect as useEffect2,useRef as useRef3,useState as useState3}from"react";import{Gauge,Loader2,Maximize,Minimize,Pause,PictureInPicture2,Play,RotateCcw,RotateCw,Volume2,VolumeX,X}from"lucide-react";import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function CtrlButton({onClick,label,children,active}){return jsx2("button",{type:"button",onClick,"aria-label":label,title:label,className:cn("size-9 rounded-sm inline-flex items-center justify-center shrink-0 cursor-pointer transition-colors","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white",active?"bg-white/20 text-white":"text-white/80 hover:bg-white/15 hover:text-white"),children})}function SuggestionCard({item,wide}){return jsxs2("button",{type:"button",onClick:item.onSelect,className:cn("group/sug flex flex-col gap-1.5 text-start cursor-pointer shrink-0","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white rounded-sm",wide?"w-full":"w-40"),children:[jsxs2("span",{className:"relative block w-full aspect-video rounded-sm overflow-clip bg-white/10 border border-white/15 transition-colors group-hover/sug:border-brand-100",children:[item.poster&&jsx2("img",{src:item.poster,alt:"",loading:"lazy",className:"w-full h-full object-cover"}),typeof item.duration==="number"&&jsx2("span",{"data-num":true,className:"absolute bottom-1 end-1 px-1 py-px rounded-xs bg-black/75 text-white text-micro font-bold",children:formatTime(item.duration)})]}),jsx2("span",{className:"text-caption font-bold text-white/90 leading-snug line-clamp-2 group-hover/sug:text-white",children:item.title})]})}function VideoPlayer({src,poster,title,chapters,captions,suggestions,suggestAt=10,autoPlay,loop,className}){const ui=useUIText();const{ref,state,toggle,seek,skip,setVolume,toggleMute,setRate}=useMedia();const shell=useRef3(null);const[full,setFull]=useState3(false);const[rateOpen,setRateOpen]=useState3(false);const[idle,setIdle]=useState3(false);const[dismissed,setDismissed]=useState3(false);const idleTimer=useRef3(void 0);const wake=useCallback3(()=>{setIdle(false);clearTimeout(idleTimer.current);idleTimer.current=setTimeout(()=>setIdle(true),2500)},[]);useEffect2(()=>{if(!state.playing)clearTimeout(idleTimer.current)},[state.playing]);useEffect2(()=>()=>clearTimeout(idleTimer.current),[]);useEffect2(()=>{const onFs=()=>setFull(document.fullscreenElement===shell.current);document.addEventListener("fullscreenchange",onFs);return()=>document.removeEventListener("fullscreenchange",onFs)},[]);async function toggleFull(){if(document.fullscreenElement)await document.exitFullscreen();else await shell.current?.requestFullscreen()}async function togglePip(){const el=ref.current;if(!el)return;if(document.pictureInPictureElement)await document.exitPictureInPicture();else await el.requestPictureInPicture()}const onKey=e=>{const keys=[" ","k","ArrowRight","ArrowLeft","ArrowUp","ArrowDown","m","f","j","l"];if(!keys.includes(e.key))return;e.preventDefault();wake();const el=ref.current;if(!el)return;switch(e.key){case" ":case"k":toggle();break;case"ArrowRight":case"l":skip(e.key==="l"?10:5);break;case"ArrowLeft":case"j":skip(e.key==="j"?-10:-5);break;case"ArrowUp":setVolume(el.volume+.1);break;case"ArrowDown":setVolume(el.volume-.1);break;case"m":toggleMute();break;case"f":void toggleFull();break}};const showChrome=!state.playing||!idle||state.ended;const has=Boolean(suggestions?.length);const remaining=state.duration-state.time;const nearEnd=state.duration>0&&remaining<=suggestAt&&!state.ended;const showStrip=has&&nearEnd&&!dismissed;const showEndScreen=has&&state.ended;return jsxs2("div",{ref:shell,role:"group","aria-label":title??ui.videoPlayer,tabIndex:0,onKeyDown:onKey,onMouseMove:wake,onMouseLeave:()=>state.playing&&setIdle(true),className:cn("relative bg-night rounded-card overflow-clip group/player","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",full?"w-screen h-screen rounded-none":"w-full aspect-video",className),children:[jsx2("video",{ref,src,poster,autoPlay,loop,playsInline:true,onClick:toggle,className:"w-full h-full object-contain cursor-pointer bg-night",children:captions&&jsx2("track",{kind:"captions",src:captions,srcLang:"ar",label:ui.arabic,default:true})}),state.waiting&&jsx2("span",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:jsx2(Loader2,{size:40,className:"animate-spin text-white/90","aria-hidden":"true"})}),(!state.playing||state.ended)&&!state.waiting&&!showEndScreen&&jsx2("button",{type:"button",onClick:toggle,"aria-label":state.ended?"\u0634\u063A\u0651\u0644 \u0645\u0646 \u0627\u0644\u0623\u0648\u0644":"\u062A\u0634\u063A\u064A\u0644",className:"absolute inset-0 flex items-center justify-center cursor-pointer group/big",children:jsx2("span",{className:"size-16 rounded-full bg-brand text-white flex items-center justify-center shadow-pop transition-transform group-hover/big:scale-110",children:state.ended?jsx2(RotateCcw,{size:26,"aria-hidden":"true"}):jsx2(Play,{size:28,className:"ml-1 icon-fixed",fill:"currentColor","aria-hidden":"true"})})}),title&&jsx2("div",{className:cn("absolute inset-x-0 top-0 p-4 bg-gradient-to-b from-black/70 to-transparent transition-opacity duration-200 pointer-events-none",showChrome?"opacity-100":"opacity-0"),children:jsx2("span",{className:"text-body font-extrabold text-white [text-wrap:balance]",children:title})}),showStrip&&jsx2("div",{className:"absolute inset-x-0 bottom-20 px-3 animate-[fade-in_.2s_ease-out]",children:jsxs2("div",{className:"flex items-end gap-3 p-3 rounded-card bg-black/70 backdrop-blur-sm border border-white/10",children:[jsxs2("div",{className:"flex flex-col gap-2 min-w-0 flex-1",children:[jsxs2("span",{className:"flex items-center gap-2 text-caption font-extrabold text-white/90",children:["\u0634\u0648\u0641 \u0643\u0645\u0627\u0646",jsxs2("span",{"data-num":true,className:"text-micro font-bold text-brand-100",children:["\u0627\u0644\u0645\u0642\u0637\u0639 \u0628\u064A\u062E\u0644\u0635 \u062E\u0644\u0627\u0644 ",Math.max(0,Math.ceil(remaining))," \u062B"]})]}),jsx2("div",{className:"flex gap-2.5 overflow-x-auto pb-1",children:suggestions?.slice(0,4).map(s=>jsx2(SuggestionCard,{item:s},s.id))})]}),jsx2("button",{type:"button",onClick:()=>setDismissed(true),"aria-label":ui.hideSuggestions,className:"size-8 rounded-sm shrink-0 flex items-center justify-center text-white/60 hover:bg-white/15 hover:text-white cursor-pointer transition-colors",children:jsx2(X,{size:16,"aria-hidden":"true"})})]})}),showEndScreen&&jsxs2("div",{className:"absolute inset-0 bg-night/92 backdrop-blur-sm flex flex-col gap-4 p-5 overflow-y-auto animate-[fade-in_.22s_ease-out]",children:[jsxs2("div",{className:"flex items-center justify-between gap-3 shrink-0",children:[jsx2("span",{className:"text-body font-extrabold text-white",children:ui.seeMore}),jsxs2("button",{type:"button",onClick:toggle,className:"inline-flex items-center gap-2 h-9 px-3.5 rounded-sm bg-white/10 text-white text-ui font-bold cursor-pointer transition-colors hover:bg-white/20",children:[jsx2(RotateCcw,{size:15,"aria-hidden":"true"}),"\u0634\u063A\u0651\u0644 \u0645\u0646 \u0627\u0644\u0623\u0648\u0644"]})]}),jsx2("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fill,minmax(150px,1fr))]",children:suggestions?.map(s=>jsx2(SuggestionCard,{item:s,wide:true},s.id))})]}),jsxs2("div",{className:cn("absolute inset-x-0 bottom-0 px-3 pb-2 pt-8 bg-gradient-to-t from-black/80 to-transparent transition-opacity duration-200",showChrome?"opacity-100":"opacity-0 pointer-events-none"),children:[jsx2(Scrubber,{time:state.time,duration:state.duration,buffered:state.buffered,onSeek:seek,chapters}),jsxs2("div",{className:"flex items-center gap-1 flex-wrap",children:[jsx2(CtrlButton,{onClick:toggle,label:state.playing?"\u0625\u064A\u0642\u0627\u0641 \u0645\u0624\u0642\u062A":"\u062A\u0634\u063A\u064A\u0644",children:state.playing?jsx2(Pause,{size:18,fill:"currentColor"}):jsx2(Play,{size:18,fill:"currentColor"})}),jsx2(CtrlButton,{onClick:()=>skip(-10),label:ui.back10,children:jsx2(RotateCcw,{size:17})}),jsx2(CtrlButton,{onClick:()=>skip(10),label:ui.forward10,children:jsx2(RotateCw,{size:17})}),jsxs2("span",{className:"flex items-center group/vol",children:[jsx2(CtrlButton,{onClick:toggleMute,label:state.muted?"\u062A\u0634\u063A\u064A\u0644 \u0627\u0644\u0635\u0648\u062A":"\u0643\u062A\u0645",children:state.muted||state.volume===0?jsx2(VolumeX,{size:18}):jsx2(Volume2,{size:18})}),jsx2("span",{className:"h-9 flex items-center overflow-clip w-0 group-hover/vol:w-20 focus-within:w-20 transition-[width] duration-200",children:jsx2("input",{type:"range",min:0,max:1,step:.05,value:state.muted?0:state.volume,onChange:e=>setVolume(Number(e.target.value)),"aria-label":ui.volume,dir:"ltr",className:"w-20 accent-brand cursor-pointer"})})]}),jsxs2("span",{"data-num":true,className:"px-2 text-caption font-bold text-white/90 whitespace-nowrap",children:[formatTime(state.time)," / ",formatTime(state.duration)]}),jsx2("span",{className:"flex-1"}),jsxs2("span",{className:"relative flex",children:[jsx2(CtrlButton,{onClick:()=>setRateOpen(v=>!v),label:ui.playbackSpeed,active:rateOpen,children:jsxs2("span",{className:"flex items-center gap-1",children:[jsx2(Gauge,{size:17}),state.rate!==1&&jsxs2("span",{"data-num":true,className:"text-micro font-extrabold",children:[state.rate,"\xD7"]})]})}),rateOpen&&jsx2("div",{className:"absolute bottom-full end-0 mb-2 py-1 rounded-card bg-night border border-white/15 shadow-pop min-w-20",children:RATES.map(r=>jsx2("button",{type:"button",onClick:()=>{setRate(r);setRateOpen(false)},className:cn("w-full px-3 py-1.5 text-ui text-center cursor-pointer transition-colors",r===state.rate?"text-brand-100 font-extrabold":"text-white/80 hover:bg-white/10"),children:jsxs2("span",{"data-num":true,children:[r,"\xD7"]})},r))})]}),"pictureInPictureEnabled"in document&&jsx2(CtrlButton,{onClick:()=>void togglePip(),label:ui.pictureInPicture,children:jsx2(PictureInPicture2,{size:17})}),jsx2(CtrlButton,{onClick:()=>void toggleFull(),label:full?"\u062E\u0631\u0648\u062C \u0645\u0646 \u0645\u0644\u0621 \u0627\u0644\u0634\u0627\u0634\u0629":"\u0645\u0644\u0621 \u0627\u0644\u0634\u0627\u0634\u0629",children:full?jsx2(Minimize,{size:17}):jsx2(Maximize,{size:17})})]})]})]})}import{memo,useEffect as useEffect3,useImperativeHandle,useMemo,useRef as useRef4,useState as useState4}from"react";import{Gauge as Gauge2,Loader2 as Loader22,Pause as Pause2,Play as Play2,RotateCcw as RotateCcw2,RotateCw as RotateCw2,Volume2 as Volume22,VolumeX as VolumeX2}from"lucide-react";import{jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";var PEAKS_CACHE=new Map;var ANALYSIS_BUCKETS=512;var BAR=3;var GAP=2;async function analyse(src,buckets){const cached=PEAKS_CACHE.get(src);if(cached!==void 0)return cached;try{const res=await fetch(src);const raw=await res.arrayBuffer();const Ctx2=window.AudioContext??window.webkitAudioContext;if(!Ctx2)throw new Error("\u0645\u0627\u0641\u064A\u0634 Web Audio");const ctx=new Ctx2;const buffer=await ctx.decodeAudioData(raw);const data=buffer.getChannelData(0);const per=Math.floor(data.length/buckets);const peaks=[];for(let i=0;i<buckets;i++){let max=0;for(let j=0;j<per;j++){const v=Math.abs(data[i*per+j]??0);if(v>max)max=v}peaks.push(max)}void ctx.close();const top=Math.max(...peaks,.01);const normalised=peaks.map(p=>p/top);PEAKS_CACHE.set(src,normalised);return normalised}catch{PEAKS_CACHE.set(src,null);return null}}var BarRow=memo(function BarRow2({peaks,color}){return jsx3("div",{"aria-hidden":"true",className:"absolute inset-0 flex items-center justify-between",style:{gap:GAP},children:peaks.map((p,i)=>jsx3("span",{style:{height:`${Math.max(8,p*100)}%`,width:BAR},className:cn("shrink-0 rounded-full",color)},i))})});function Waveform({peaks,time,duration,onSeek,bars,height=48}){const ui=useUIText();const box=useRef4(null);const[count,setCount]=useState4(bars??0);const[width,setWidth]=useState4(0);useEffect3(()=>{const el=box.current;if(!el)return;const measure=()=>{setWidth(el.clientWidth);if(!bars)setCount(Math.max(8,Math.floor(el.clientWidth/(BAR+GAP))))};measure();const ro=new ResizeObserver(measure);ro.observe(el);return()=>ro.disconnect()},[bars]);const shown=useMemo(()=>{if(count<=0)return[];const per=peaks.length/count;return Array.from({length:count},(_,i)=>{let max=0;for(let j=Math.floor(i*per);j<Math.floor((i+1)*per);j++){if(peaks[j]>max)max=peaks[j]}return max})},[peaks,count]);const played=duration>0?Math.min(1,time/duration):0;const grey=useMemo(()=>jsx3(BarRow,{peaks:shown,color:"bg-border/50"}),[shown]);const teal=useMemo(()=>jsx3(BarRow,{peaks:shown,color:"bg-brand"}),[shown]);return jsxs3("div",{dir:"ltr",className:"relative w-full",style:{height},children:[jsx3("div",{ref:box,className:"absolute inset-0",children:grey}),jsx3("div",{"aria-hidden":"true",className:"absolute inset-y-0 start-0 overflow-clip pointer-events-none",style:{width:`${played*100}%`},children:jsx3("div",{className:"relative h-full",style:{width:width||"100%"},children:teal})}),jsx3("input",{type:"range",min:0,max:duration||0,step:.1,value:time,"aria-label":ui.playbackPosition,"aria-valuetext":`${formatTime(time)} \u0645\u0646 ${formatTime(duration)}`,onChange:e=>onSeek(Number(e.target.value)),className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]})}function Btn({onClick,label,children,small}){return jsx3("button",{type:"button",onClick,"aria-label":label,title:label,className:cn("rounded-sm inline-flex items-center justify-center shrink-0 cursor-pointer transition-colors","text-muted hover:bg-hover hover:text-ink","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",small?"size-8":"size-9"),children})}function AudioPlayer({src,title,meta,cover,variant="card",bars,onLevel,mediaRef,className}){const ui=useUIText();const{ref,state,toggle,seek,skip,setVolume,toggleMute,setRate}=useMedia();const[peaks,setPeaks]=useState4(null);const[analysing,setAnalysing]=useState4(false);const[rateOpen,setRateOpen]=useState4(false);const alive=useRef4(true);useEffect3(()=>{alive.current=true;return()=>{alive.current=false}},[]);useEffect3(()=>{if(variant==="row")return;let live=true;void Promise.resolve().then(()=>live&&setAnalysing(true));void analyse(src,ANALYSIS_BUCKETS).then(p=>{live=false;if(!alive.current)return;setPeaks(p);setAnalysing(false)})},[src,variant]);useImperativeHandle(mediaRef,()=>ref.current,[ref]);useEffect3(()=>{if(!onLevel)return;if(!peaks||state.duration<=0||!state.playing){onLevel(0);return}const i=Math.min(peaks.length-1,Math.floor(state.time/state.duration*peaks.length));onLevel(peaks[i]??0)},[onLevel,peaks,state.time,state.duration,state.playing]);const PlayBtn=jsx3("button",{type:"button",onClick:toggle,"aria-label":state.playing?"\u0625\u064A\u0642\u0627\u0641 \u0645\u0624\u0642\u062A":"\u062A\u0634\u063A\u064A\u0644",className:cn("rounded-full bg-brand text-white flex items-center justify-center shrink-0 cursor-pointer transition-colors hover:bg-brand-hover","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",variant==="row"?"size-9":"size-11"),children:state.playing?jsx3(Pause2,{size:variant==="row"?16:18,fill:"currentColor","aria-hidden":"true"}):jsx3(Play2,{size:variant==="row"?16:18,className:"ml-0.5 icon-fixed",fill:"currentColor","aria-hidden":"true"})});const audio=jsx3("audio",{ref,src,preload:"metadata"});if(variant==="row"){return jsxs3("div",{className:cn("flex items-center gap-3 p-2.5 rounded-card border border-line bg-surface",className),children:[audio,PlayBtn,jsxs3("span",{className:"flex flex-col gap-1 flex-1 min-w-0",children:[title&&jsx3("span",{className:"text-ui font-bold text-ink truncate",children:title}),jsxs3("span",{dir:"ltr",className:"relative h-1 rounded-full bg-hover overflow-clip",children:[jsx3("span",{"aria-hidden":"true",style:{width:`${state.duration?state.time/state.duration*100:0}%`},className:"absolute inset-y-0 start-0 bg-brand rounded-full"}),jsx3("input",{type:"range",min:0,max:state.duration||0,step:.1,value:state.time,"aria-label":ui.playbackPosition,onChange:e=>seek(Number(e.target.value)),className:"absolute inset-0 w-full opacity-0 cursor-pointer"})]})]}),jsxs3("span",{"data-num":true,className:"text-micro text-muted2 shrink-0",children:[formatTime(state.time)," / ",formatTime(state.duration)]})]})}return jsxs3("div",{className:cn("flex flex-col gap-3.5 p-4 rounded-card border border-line bg-surface",className),children:[audio,(title||cover)&&jsxs3("div",{className:"flex items-center gap-3",children:[cover&&jsx3("img",{src:cover,alt:"",className:"size-12 rounded-sm object-cover border border-line shrink-0"}),jsxs3("span",{className:"flex flex-col gap-0.5 min-w-0",children:[title&&jsx3("span",{className:"text-body font-extrabold text-ink truncate",children:title}),meta&&jsx3("span",{className:"text-caption text-muted truncate",children:meta})]})]}),jsx3("div",{className:"min-h-12 flex items-center",children:analysing?jsxs3("span",{className:"w-full flex items-center justify-center gap-2 text-caption text-muted2",children:[jsx3(Loader22,{size:14,className:"animate-spin","aria-hidden":"true"}),"\u0628\u064A\u062D\u0644\u0651\u0644 \u0627\u0644\u0645\u0648\u062C\u0629\u2026"]}):peaks?jsx3(Waveform,{peaks,time:state.time,duration:state.duration,onSeek:seek,bars}):jsxs3("span",{dir:"ltr",className:"relative w-full h-1.5 rounded-full bg-hover",children:[jsx3("span",{"aria-hidden":"true",style:{width:`${state.duration?state.time/state.duration*100:0}%`},className:"absolute inset-y-0 start-0 bg-brand rounded-full"}),jsx3("input",{type:"range",min:0,max:state.duration||0,step:.1,value:state.time,"aria-label":ui.playbackPosition,onChange:e=>seek(Number(e.target.value)),className:"absolute inset-0 w-full opacity-0 cursor-pointer"})]})}),jsxs3("div",{className:"flex items-center gap-1 flex-wrap",children:[PlayBtn,jsx3(Btn,{onClick:()=>skip(-10),label:ui.back10,children:jsx3(RotateCcw2,{size:16})}),jsx3(Btn,{onClick:()=>skip(10),label:ui.forward10,children:jsx3(RotateCw2,{size:16})}),jsxs3("span",{className:"flex items-center group/vol",children:[jsx3(Btn,{onClick:toggleMute,label:state.muted?"\u062A\u0634\u063A\u064A\u0644 \u0627\u0644\u0635\u0648\u062A":"\u0643\u062A\u0645",children:state.muted||state.volume===0?jsx3(VolumeX2,{size:16}):jsx3(Volume22,{size:16})}),jsx3("span",{className:"h-9 flex items-center overflow-clip w-0 group-hover/vol:w-16 focus-within:w-16 transition-[width] duration-200",children:jsx3("input",{type:"range",min:0,max:1,step:.05,value:state.muted?0:state.volume,onChange:e=>setVolume(Number(e.target.value)),"aria-label":ui.volume,dir:"ltr",className:"w-16 accent-brand cursor-pointer"})})]}),jsxs3("span",{"data-num":true,className:"px-2 text-caption font-bold text-ink2 whitespace-nowrap",children:[formatTime(state.time)," / ",formatTime(state.duration)]}),jsx3("span",{className:"flex-1"}),jsxs3("span",{className:"relative flex",children:[jsx3(Btn,{onClick:()=>setRateOpen(v=>!v),label:ui.playbackSpeed,children:jsxs3("span",{className:"flex items-center gap-1",children:[jsx3(Gauge2,{size:16}),state.rate!==1&&jsxs3("span",{"data-num":true,className:"text-micro font-extrabold text-brand-ink",children:[state.rate,"\xD7"]})]})}),rateOpen&&jsx3("div",{className:"absolute bottom-full end-0 mb-2 py-1 rounded-card bg-surface border border-line shadow-panel min-w-20 z-20",children:RATES.map(r=>jsx3("button",{type:"button",onClick:()=>{setRate(r);setRateOpen(false)},className:cn("w-full px-3 py-1.5 text-ui text-center cursor-pointer transition-colors",r===state.rate?"bg-soft text-brand-ink font-extrabold":"text-ink2 hover:bg-hover"),children:jsxs3("span",{"data-num":true,children:[r,"\xD7"]})},r))})]})]})]})}import{useEffect as useEffect4,useRef as useRef5,useState as useState5}from"react";var SOURCES=new WeakMap;function useAudioLevel(ref,{bands=5,enabled=true}={}){const level=useRef5(0);const bandsRef=useRef5(Array.from({length:bands},()=>0));const[ready,setReady]=useState5(false);const[failed,setFailed]=useState5(false);useEffect4(()=>{const el=ref.current;if(!el||!enabled)return;let raf=0;let analyser=null;let dead=false;function connect(){if(dead||analyser)return;const media=ref.current;if(!media)return;try{let entry=SOURCES.get(media);if(!entry){const Ctx2=window.AudioContext??window.webkitAudioContext;if(!Ctx2)throw new Error("\u0645\u0627\u0641\u064A\u0634 Web Audio");const ctx=new Ctx2;const source=ctx.createMediaElementSource(media);source.connect(ctx.destination);entry={ctx,source};SOURCES.set(media,entry)}void entry.ctx.resume();analyser=entry.ctx.createAnalyser();analyser.fftSize=1024;analyser.smoothingTimeConstant=.75;entry.source.connect(analyser);setReady(true);loop()}catch{setFailed(true)}}const spectrum=new Uint8Array(512);const wave=new Uint8Array(1024);let peak=.02;function loop(){if(dead||!analyser)return;analyser.getByteFrequencyData(spectrum);analyser.getByteTimeDomainData(wave);let sum=0;for(let i=0;i<wave.length;i++){const v=(wave[i]-128)/128;sum+=v*v}const rms=Math.sqrt(sum/wave.length);peak=Math.max(rms,peak*.995);level.current=Math.min(1,rms/Math.max(peak,.015));const out=[];for(let b=0;b<bands;b++){const from=Math.floor(spectrum.length**(b/bands))-1;const to=Math.floor(spectrum.length**((b+1)/bands));let peak2=0;for(let i=Math.max(0,from);i<to;i++){if(spectrum[i]>peak2)peak2=spectrum[i]}out.push(peak2/255)}bandsRef.current=out;raf=requestAnimationFrame(loop)}el.addEventListener("play",connect);if(!el.paused)connect();return()=>{dead=true;cancelAnimationFrame(raf);el.removeEventListener("play",connect);analyser?.disconnect()}},[ref,bands,enabled]);return{level,bands:bandsRef,ready,failed}}import{createContext,useCallback as useCallback4,useContext,useEffect as useEffect7,useMemo as useMemo2,useRef as useRef8,useState as useState8}from"react";import{useEffect as useEffect5,useLayoutEffect,useRef as useRef6,useState as useState6}from"react";import{X as X2}from"lucide-react";import{jsx as jsx4,jsxs as jsxs4}from"react/jsx-runtime";var GAP2=10;var EDGE=12;var WIDTH=264;function CoachHintSurface({item,onClose}){const ui=useUIText();const anchors=useCoachAnchors();const box=useRef6(null);const[pos,setPos]=useState6(null);const anchorId=item.where?.anchor;const gone=anchorId!==void 0&&!anchors.get(anchorId);useLayoutEffect(()=>{if(!anchorId)return;const el=anchors.get(anchorId);if(!el)return;function place(){const target=anchors.get(anchorId);const self=box.current;if(!target||!self)return;const a=target.getBoundingClientRect();const h=self.offsetHeight;const below=a.bottom+GAP2;const above=window.innerHeight-a.top+GAP2;const flip=below+h>window.innerHeight-EDGE&&above>below;const left=Math.min(window.innerWidth-WIDTH-EDGE,Math.max(EDGE,a.left+a.width/2-WIDTH/2));setPos({top:flip?a.top-h-GAP2:a.bottom+GAP2,left,above:flip})}place();window.addEventListener("scroll",place,true);window.addEventListener("resize",place);return()=>{window.removeEventListener("scroll",place,true);window.removeEventListener("resize",place)}},[anchorId,anchors]);useEffect5(()=>{if(!anchorId)return;const el=anchors.get(anchorId);if(!el)return;const prev=el.style.boxShadow;el.style.boxShadow="0 0 0 3px var(--color-soft), 0 0 0 4px var(--color-brand)";el.style.borderRadius=el.style.borderRadius||"var(--radius-field)";return()=>{el.style.boxShadow=prev}},[anchorId,anchors]);useEffect5(()=>{if(gone)onClose()},[gone,onClose]);useEffect5(()=>{const onKey=e=>{if(e.key==="Escape")onClose()};document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[onClose]);if(gone)return null;return jsxs4("div",{ref:box,role:"status",style:{width:WIDTH,top:pos?.top??-9999,left:pos?.left??-9999},className:cn("fixed z-[80] rounded-card border border-line bg-surface shadow-pop p-3 flex flex-col gap-1.5","animate-qfade",pos?"opacity-100":"opacity-0"),children:[jsxs4("div",{className:"flex items-start gap-2",children:[jsxs4("span",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[item.title&&jsx4("span",{className:"text-ui font-extrabold text-ink",children:item.title}),jsx4("span",{className:"text-caption leading-[1.75] text-ink2 [text-wrap:pretty]",children:item.text})]}),jsx4("button",{type:"button","aria-label":ui.close,onClick:onClose,className:"size-6 -me-1 -mt-0.5 rounded-xs flex items-center justify-center text-muted hover:text-ink hover:bg-hover cursor-pointer transition-colors shrink-0",children:jsx4(X2,{size:13,"aria-hidden":"true"})})]}),jsx4("span",{"aria-hidden":"true",className:cn("absolute start-1/2 -ms-1.5 size-3 rotate-45 bg-surface border-line",pos?.above?"-bottom-1.5 border-e border-b":"-top-1.5 border-s border-t")})]})}import{useEffect as useEffect6,useRef as useRef7,useState as useState7}from"react";import{X as X3}from"lucide-react";import{Fragment,jsx as jsx5,jsxs as jsxs5}from"react/jsx-runtime";function CoachAudioSurface({item,onClose,orb,region}){const ui=useUIText();const box={top:0,bottom:0,insetInlineStart:0,insetInlineEnd:0,...region};const anchors=useCoachAnchors();const[time,setTime]=useState7(0);const wrap=useRef7(null);const level=useRef7(0);const active=item.lines.findIndex(l=>time>=l.start&&time<l.end);const line=active>=0?item.lines[active]:item.lines[0];useEffect6(()=>{const onKey=e=>{if(e.key==="Escape")onClose()};document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[onClose]);useEffect6(()=>{const el=wrap.current?.querySelector("audio");if(!el)return;const onTime=()=>setTime(el.currentTime);el.addEventListener("timeupdate",onTime);return()=>el.removeEventListener("timeupdate",onTime)},[]);useEffect6(()=>{const id=item.where?.anchor;if(!id)return;const el=anchors.get(id);if(!el)return;const prev=el.style.boxShadow;el.style.boxShadow="0 0 0 3px var(--color-soft), 0 0 0 4px var(--color-brand)";return()=>{el.style.boxShadow=prev}},[item,anchors]);useEffect6(()=>{if(!orb)return;let raf=0;let alive=true;let peaks=null;void(async()=>{try{const Ctx2=window.AudioContext??window.webkitAudioContext;if(!Ctx2)return;const raw=await(await fetch(item.src)).arrayBuffer();const ctx=new Ctx2;const buffer=await ctx.decodeAudioData(raw);void ctx.close();if(!alive)return;const data=buffer.getChannelData(0);const BUCKETS=600;const per=Math.floor(data.length/BUCKETS);const out=new Float32Array(BUCKETS);for(let i=0;i<BUCKETS;i++){let sum=0;for(let j=0;j<per;j++){const v=data[i*per+j];sum+=v*v}out[i]=Math.min(1,Math.sqrt(sum/per)*3.2)}peaks=out}catch{}})();const el=wrap.current?.querySelector("audio");const loop=()=>{if(peaks&&el&&el.duration>0){const i=Math.floor(el.currentTime/el.duration*peaks.length);level.current=peaks[Math.min(i,peaks.length-1)]??0}raf=requestAnimationFrame(loop)};loop();return()=>{alive=false;cancelAnimationFrame(raf)}},[item.src,orb]);return jsxs5(Fragment,{children:[jsx5("button",{type:"button","aria-label":ui.closeExplainer,onClick:onClose,style:box,className:"fixed z-[78] bg-night/25 backdrop-blur-[1.5px] cursor-pointer animate-qfade"}),jsxs5("div",{ref:wrap,style:box,className:"fixed z-[79] flex flex-col pointer-events-none",children:[orb&&jsx5("div",{"aria-hidden":"true",className:"flex-1 min-h-0 flex items-center justify-center animate-qfade",children:orb(level)}),jsx5("div",{className:"shrink-0 pointer-events-auto animate-tip-up",role:"region","aria-label":item.headline,children:jsx5("div",{className:"bg-surface border-t border-line shadow-sheet",children:jsxs5("div",{className:"mx-auto max-w-shell px-[22px] py-3 flex flex-col gap-2.5",children:[jsxs5("div",{className:"flex items-center gap-2.5",children:[jsx5("span",{"aria-live":"polite",className:"flex-1 min-w-0 text-ui font-bold leading-[1.7] text-ink [text-wrap:pretty]",children:line?.text}),jsx5("button",{type:"button","aria-label":ui.close,onClick:onClose,className:"size-8 rounded-sm flex items-center justify-center text-muted hover:text-ink hover:bg-hover cursor-pointer transition-colors shrink-0",children:jsx5(X3,{size:15,"aria-hidden":"true"})})]}),jsx5(AudioPlayer,{src:item.src,title:item.headline,meta:item.meta})]})})})]})]})}import{jsx as jsx6,jsxs as jsxs6}from"react/jsx-runtime";var Ctx=createContext(null);var AnchorCtx=createContext(null);function useCoachAnchors(){const ctx=useContext(AnchorCtx);if(!ctx)throw new Error("<Coach> \u0644\u0627\u0632\u0645 \u064A\u0643\u0648\u0646 \u062C\u0648\u0651\u0647 <CoachProvider>");return ctx}function readSeen(key){try{return JSON.parse(localStorage.getItem(key)??"[]")}catch{return[]}}function CoachProvider({items,path,orb,region,storageKey="qumra-coach-seen",disabled,children}){const[seenIds,setSeenIds]=useState8(()=>readSeen(storageKey));const[openId,setOpenId]=useState8(null);const[openPath,setOpenPath]=useState8(path);const shownId=openPath===path?openId:null;const anchors=useRef8(new Map);const anchorApi=useMemo2(()=>({set:(id,el)=>{if(el)anchors.current.set(id,el);else anchors.current.delete(id)},get:id=>anchors.current.get(id)??null}),[]);const markSeen=useCallback4(id=>{setSeenIds(prev=>{if(prev.includes(id))return prev;const next=[...prev,id];try{localStorage.setItem(storageKey,JSON.stringify(next))}catch{}return next})},[storageKey]);const close=useCallback4(()=>{setOpenId(id=>{if(id)markSeen(id);return null})},[markSeen]);useEffect7(()=>{if(disabled)return;const candidate=items.find(it=>(it.when??"enter")!=="manual"&&(it.where?.path===void 0||it.where.path===path)&&!seenIds.includes(it.id));if(!candidate)return;const when=candidate.when??"enter";const delay=when.startsWith("idle:")?Number(when.slice(5,-1))*1e3:0;const timer=setTimeout(()=>{setOpenId(candidate.id);setOpenPath(path)},delay);return()=>clearTimeout(timer)},[items,path,disabled]);const api=useMemo2(()=>({show:id=>{if(disabled||seenIds.includes(id))return;setOpenId(id);setOpenPath(path)},replay:id=>{setOpenId(id);setOpenPath(path)},close,current:items.find(it=>it.id===shownId)??null,seen:id=>seenIds.includes(id),reset:()=>{setSeenIds([]);try{localStorage.removeItem(storageKey)}catch{}}}),[items,shownId,path,seenIds,close,disabled,storageKey]);const current=api.current;return jsx6(AnchorCtx.Provider,{value:anchorApi,children:jsxs6(Ctx.Provider,{value:api,children:[children,current?.kind==="hint"&&jsx6(CoachHintSurface,{item:current,onClose:close}),current?.kind==="audio"&&jsx6(CoachAudioSurface,{item:current,onClose:close,orb,region})]})})}function useCoach(){const ctx=useContext(Ctx);if(!ctx)throw new Error("useCoach \u0644\u0627\u0632\u0645 \u064A\u062A\u0646\u0627\u062F\u0649 \u062C\u0648\u0651\u0647 <CoachProvider>");return ctx}function useCoachOptional(){return useContext(Ctx)}import{cloneElement,isValidElement,useEffect as useEffect8,useRef as useRef9}from"react";import{jsx as jsx7}from"react/jsx-runtime";function Coach({id,asChild,children}){const anchors=useCoachAnchors();const own=useRef9(null);useEffect8(()=>{if(asChild)return;const el=own.current?.firstElementChild??own.current;anchors.set(id,el);return()=>anchors.set(id,null)},[id,anchors,asChild]);if(asChild&&isValidElement(children)){return cloneElement(children,{ref:el=>anchors.set(id,el)})}return jsx7("span",{ref:own,className:"contents",children})}var coachSeconds=item=>item.lines[item.lines.length-1]?.end??0;import{Info}from"lucide-react";var BADGE_BASE="inline-flex items-center gap-1.5 rounded-full font-bold whitespace-nowrap";var BADGE_SIZE={sm:"text-micro px-2 py-0.5",md:"text-caption px-2.5 py-1"};var BADGE_DOT="size-1.5 rounded-full bg-current shrink-0";var COUNTER="inline-flex items-center justify-center min-w-[18px] h-[18px] px-1.5 rounded-full bg-danger text-white text-micro font-extrabold leading-none";var AVATAR_SIZES={xs:"size-7 text-micro",sm:"size-9 text-ui",md:"size-11 text-body",lg:"size-14 text-h4"};var AVATAR_IMG="object-cover border border-line shrink-0";var AVATAR_SQUARE="rounded-field";var AVATAR_ROUND="rounded-full";var AVATAR_FALLBACK="flex items-center justify-center font-extrabold bg-soft text-brand-ink shrink-0";function initials(name){return name.trim().split(/\s+/).slice(0,2).map(w=>w[0]).join("")}var CARD="bg-surface border border-line rounded-card";var CARD_PADDED="p-5";var STAT_CARD="relative bg-surface border border-line rounded-card p-4 flex flex-col gap-2";var STAT_ROW="flex items-center gap-2.5";var STAT_ICON="size-[30px] rounded-sm flex items-center justify-center shrink-0";var STAT_LABEL="text-ui text-muted";var STAT_VALUE="text-h3 font-extrabold leading-none whitespace-nowrap";var STAT_HINT="text-micro text-muted2";var COACH_MARK="size-7 rounded-full shrink-0 flex items-center justify-center text-brand cursor-pointer transition-colors hover:bg-soft hover:text-brand-hover focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand";var COACH_MARK_STAT="ms-auto -me-1 -mt-1";var CARD_HEAD="flex items-start justify-between gap-4";var CARD_HEAD_TEXT="flex flex-col gap-1 min-w-0";var CARD_TITLE="text-lead font-extrabold text-ink m-0";var CARD_DESC="text-ui text-muted m-0";var CARD_HEAD_ACTIONS="shrink-0 flex items-center gap-1.5";var PAGE_HEAD="flex items-start justify-between gap-3.5 flex-wrap";var PAGE_HEAD_TEXT="flex flex-col gap-1 min-w-0";var PAGE_TITLE="text-h3 font-black text-ink m-0";var PAGE_HINT="text-ui text-muted m-0";var PAGE_ACTIONS="flex items-center gap-2.5 shrink-0 flex-wrap";var PROGRESS_WRAP="flex flex-col gap-1.5";var PROGRESS_LABEL_ROW="flex items-center justify-between gap-3 text-caption";var PROGRESS_TRACK="h-1.5 rounded-full bg-hover";var PROGRESS_BAR="h-full rounded-full transition-[width] duration-500";var PROGRESS_FILL={neutral:"bg-muted2",brand:"bg-brand",amber:"bg-amber",green:"bg-green-solid",red:"bg-danger",violet:"bg-violet-solid"};var SKELETON_BASE="bg-skeleton animate-skeleton";var SKELETON_VARIANT={text:"h-3.5 rounded-xs w-full",block:"h-20 rounded-field w-full",circle:"size-10 rounded-full"};import{jsx as jsx8,jsxs as jsxs7}from"react/jsx-runtime";function Badge({children,tone="neutral",variant="soft",size="md",dot,icon,className}){return jsxs7("span",{className:cn(BADGE_BASE,BADGE_SIZE[size],variant==="solid"?TONE_SOLID[tone]:TONE_SOFT[tone],className),children:[dot&&jsx8("span",{"aria-hidden":"true",className:BADGE_DOT}),icon,children]})}function Counter({value,max=99}){if(value<=0)return null;return jsx8("span",{"data-num":true,dir:"ltr",className:COUNTER,children:value>max?`${max}+`:value})}function Avatar({name,src,size="md",square,className}){const shape=square?AVATAR_SQUARE:AVATAR_ROUND;if(src){return jsx8("img",{src,alt:name,loading:"lazy",className:cn(AVATAR_IMG,shape,AVATAR_SIZES[size],className)})}return jsx8("span",{role:"img","aria-label":name,className:cn(AVATAR_FALLBACK,shape,AVATAR_SIZES[size],className),children:initials(name)})}function StatCard({icon:Icon,tone="brand",label,value,hint,coachId,className}){const ui=useUIText();const coach=useCoachOptional();const explained=Boolean(coachId&&coach);const body=jsxs7("div",{className:cn(STAT_CARD,className),children:[jsxs7("span",{className:STAT_ROW,children:[Icon&&jsx8("span",{"aria-hidden":"true",className:cn(STAT_ICON,TONE_SOFT[tone]),children:jsx8(Icon,{size:15,strokeWidth:2})}),jsx8("span",{className:STAT_LABEL,children:label}),explained&&jsx8("button",{type:"button",onClick:()=>coach.replay(coachId),"aria-label":typeof label==="string"?`\u0645\u0627 \u0645\u0639\u0646\u0649 \xAB${label}\xBB\u061F`:"\u0645\u0627 \u0645\u0639\u0646\u0649 \u0647\u0630\u0627 \u0627\u0644\u0631\u0642\u0645\u061F",title:ui.whatIsThisNumber,className:cn(COACH_MARK_STAT,COACH_MARK),children:jsx8(Info,{size:15,strokeWidth:2,"aria-hidden":"true"})})]}),jsx8("span",{"data-num":true,className:STAT_VALUE,children:value}),hint&&jsx8("span",{className:STAT_HINT,children:hint})]});return explained?jsx8(Coach,{id:coachId,children:body}):body}function Card({children,padded=true,className}){return jsx8("div",{className:cn(CARD,padded?CARD_PADDED:"overflow-clip",className),children})}function CardHeader({title,description,action,coachId}){const ui=useUIText();const coach=useCoachOptional();const explained=Boolean(coachId&&coach);const head=jsxs7("div",{className:CARD_HEAD,children:[jsxs7("div",{className:CARD_HEAD_TEXT,children:[jsx8("h3",{className:CARD_TITLE,children:title}),description&&jsx8("p",{className:CARD_DESC,children:description})]}),(action||explained)&&jsxs7("div",{className:CARD_HEAD_ACTIONS,children:[action,explained&&jsx8("button",{type:"button",onClick:()=>coach.replay(coachId),"aria-label":typeof title==="string"?`\u0645\u0627 \u0645\u0639\u0646\u0649 \xAB${title}\xBB\u061F`:"\u0645\u0627 \u0647\u0630\u0627 \u0627\u0644\u0642\u0633\u0645\u061F",title:ui.explainToMe,className:COACH_MARK,children:jsx8(Info,{size:15,strokeWidth:2,"aria-hidden":"true"})})]})]});return explained?jsx8(Coach,{id:coachId,children:head}):head}function PageHeader({title,hint,actions}){return jsxs7("div",{className:PAGE_HEAD,children:[jsxs7("div",{className:PAGE_HEAD_TEXT,children:[jsx8("h1",{className:cn(PAGE_TITLE,"[text-wrap:balance]"),children:title}),hint&&jsx8("p",{className:cn(PAGE_HINT,"[text-wrap:pretty]"),children:hint})]}),actions&&jsx8("div",{className:PAGE_ACTIONS,children:actions})]})}function Progress({value,max=100,label,tone="brand",className}){const safe=Math.min(max,Math.max(0,value));const pct=safe/max*100;return jsxs7("div",{className:cn(PROGRESS_WRAP,className),children:[label&&jsxs7("span",{className:PROGRESS_LABEL_ROW,children:[jsx8("span",{className:"text-ink2",children:label}),jsxs7("span",{"data-num":true,className:"text-muted font-bold",children:[Math.round(pct),"%"]})]}),jsx8("span",{role:"progressbar","aria-valuenow":safe,"aria-valuemin":0,"aria-valuemax":max,className:cn(PROGRESS_TRACK,"overflow-clip block"),children:jsx8("span",{className:cn("block",PROGRESS_BAR,PROGRESS_FILL[tone]),style:{width:`${pct}%`}})})]})}function Skeleton({variant="text",width,className}){return jsx8("span",{"aria-hidden":"true",style:{width},className:cn("block",SKELETON_BASE,SKELETON_VARIANT[variant],className)})}export{useMedia,formatTime,Scrubber,VideoPlayer,AudioPlayer,useAudioLevel,CoachProvider,useCoach,useCoachOptional,Coach,coachSeconds,Badge,Counter,Avatar,StatCard,Card,CardHeader,PageHeader,Progress,Skeleton};
2
+ import{TONE_SOFT,TONE_SOLID,cn,useUIText}from"./chunk-ZE4S6DBP.js";import{useCallback,useEffect,useRef,useState}from"react";var INITIAL={playing:false,time:0,duration:0,buffered:0,volume:1,muted:false,rate:1,waiting:false,ended:false};function useMedia(){const ref=useRef(null);const[state,setState]=useState(INITIAL);useEffect(()=>{const el=ref.current;if(!el)return;const patch=p=>setState(s=>({...s,...p}));const onTime=()=>{let end=0;const b=el.buffered;for(let i=0;i<b.length;i++){if(b.start(i)<=el.currentTime&&el.currentTime<=b.end(i))end=b.end(i)}patch({time:el.currentTime,buffered:end})};const onMeta=()=>patch({duration:Number.isFinite(el.duration)?el.duration:0,ended:false});const onPlay=()=>patch({playing:true,ended:false});const onPause=()=>patch({playing:false});const onEnded=()=>patch({playing:false,ended:true});const onWaiting=()=>patch({waiting:true});const onPlaying=()=>patch({waiting:false,playing:true});const onVolume=()=>patch({volume:el.volume,muted:el.muted});const onRate=()=>patch({rate:el.playbackRate});el.addEventListener("timeupdate",onTime);el.addEventListener("progress",onTime);el.addEventListener("loadedmetadata",onMeta);el.addEventListener("durationchange",onMeta);el.addEventListener("play",onPlay);el.addEventListener("pause",onPause);el.addEventListener("ended",onEnded);el.addEventListener("waiting",onWaiting);el.addEventListener("playing",onPlaying);el.addEventListener("volumechange",onVolume);el.addEventListener("ratechange",onRate);if(el.readyState>=1)onMeta();return()=>{el.removeEventListener("timeupdate",onTime);el.removeEventListener("progress",onTime);el.removeEventListener("loadedmetadata",onMeta);el.removeEventListener("durationchange",onMeta);el.removeEventListener("play",onPlay);el.removeEventListener("pause",onPause);el.removeEventListener("ended",onEnded);el.removeEventListener("waiting",onWaiting);el.removeEventListener("playing",onPlaying);el.removeEventListener("volumechange",onVolume);el.removeEventListener("ratechange",onRate)}},[]);useEffect(()=>{if(!state.playing)return;let raf=0;const tick=()=>{const el=ref.current;if(el)setState(s=>s.time===el.currentTime?s:{...s,time:el.currentTime});raf=requestAnimationFrame(tick)};raf=requestAnimationFrame(tick);return()=>cancelAnimationFrame(raf)},[state.playing]);const toggle=useCallback(()=>{const el=ref.current;if(!el)return;if(el.paused)void el.play();else el.pause()},[]);const seek=useCallback(to=>{const el=ref.current;if(!el)return;el.currentTime=Math.max(0,Math.min(to,el.duration||0))},[]);const skip=useCallback(by=>{const el=ref.current;if(el)seek(el.currentTime+by)},[seek]);const setVolume=useCallback(v=>{const el=ref.current;if(!el)return;el.volume=Math.max(0,Math.min(1,v));if(el.volume>0)el.muted=false},[]);const toggleMute=useCallback(()=>{const el=ref.current;if(el)el.muted=!el.muted},[]);const setRate=useCallback(r=>{const el=ref.current;if(el)el.playbackRate=r},[]);return{ref,state,toggle,seek,skip,setVolume,toggleMute,setRate}}function formatTime(seconds){if(!Number.isFinite(seconds)||seconds<0)return"0:00";const total=Math.floor(seconds);const s=total%60;const m=Math.floor(total/60)%60;const h=Math.floor(total/3600);const pad=n=>String(n).padStart(2,"0");return h>0?`${h}:${pad(m)}:${pad(s)}`:`${m}:${pad(s)}`}var RATES=[.5,.75,1,1.25,1.5,2];import{useCallback as useCallback2,useRef as useRef2,useState as useState2}from"react";import{jsx,jsxs}from"react/jsx-runtime";function Scrubber({time,duration,buffered,onSeek,chapters,label,size="md"}){const ui=useUIText();const bar=useRef2(null);const[hover,setHover]=useState2(null);const pct=duration>0?time/duration*100:0;const buf=duration>0?(buffered??0)/duration*100:0;const atPointer=useCallback2(clientX=>{const box=bar.current?.getBoundingClientRect();if(!box||duration<=0)return null;const ratio=Math.max(0,Math.min(1,(clientX-box.left)/box.width));return ratio*duration},[duration]);const h=size==="sm"?"h-1":"h-1.5";return jsxs("div",{dir:"ltr",className:"relative group/scrub w-full py-2 select-none",children:[hover!==null&&jsx("span",{"data-num":true,style:{insetInlineStart:`${hover/duration*100}%`},className:"absolute bottom-full mb-1 -translate-x-1/2 px-1.5 py-0.5 rounded-xs bg-night text-white text-micro font-bold pointer-events-none whitespace-nowrap",children:formatTime(hover)}),jsxs("div",{ref:bar,onMouseMove:e=>setHover(atPointer(e.clientX)),onMouseLeave:()=>setHover(null),className:cn("relative w-full rounded-full bg-white/25 overflow-visible",h),children:[jsx("span",{"aria-hidden":"true",style:{width:`${buf}%`},className:cn("absolute inset-y-0 start-0 rounded-full bg-white/30",h)}),jsx("span",{"aria-hidden":"true",style:{width:`${pct}%`},className:cn("absolute inset-y-0 start-0 rounded-full bg-brand",h)}),chapters?.map(c=>duration>0&&c.at>0&&c.at<duration?jsx("span",{title:c.title,"aria-hidden":"true",style:{insetInlineStart:`${c.at/duration*100}%`},className:"absolute inset-y-0 w-0.5 -translate-x-1/2 bg-night/50"},`${c.at}-${c.title}`):null),jsx("span",{"aria-hidden":"true",style:{insetInlineStart:`${pct}%`},className:"absolute top-1/2 -translate-y-1/2 -translate-x-1/2 size-3 rounded-full bg-white shadow-raise scale-0 transition-transform group-hover/scrub:scale-100 group-focus-within/scrub:scale-100"}),jsx("input",{type:"range",min:0,max:duration||0,step:.1,value:time,"aria-label":label??ui.playbackPosition,"aria-valuetext":`${formatTime(time)} \u0645\u0646 ${formatTime(duration)}`,onChange:e=>onSeek(Number(e.target.value)),className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]})]})}import{useCallback as useCallback3,useEffect as useEffect2,useRef as useRef3,useState as useState3}from"react";import{Gauge,Loader2,Maximize,Minimize,Pause,PictureInPicture2,Play,RotateCcw,RotateCw,Volume2,VolumeX,X}from"lucide-react";import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function CtrlButton({onClick,label,children,active}){return jsx2("button",{type:"button",onClick,"aria-label":label,title:label,className:cn("size-9 rounded-sm inline-flex items-center justify-center shrink-0 cursor-pointer transition-colors","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white",active?"bg-white/20 text-white":"text-white/80 hover:bg-white/15 hover:text-white"),children})}function SuggestionCard({item,wide}){return jsxs2("button",{type:"button",onClick:item.onSelect,className:cn("group/sug flex flex-col gap-1.5 text-start cursor-pointer shrink-0","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white rounded-sm",wide?"w-full":"w-40"),children:[jsxs2("span",{className:"relative block w-full aspect-video rounded-sm overflow-clip bg-white/10 border border-white/15 transition-colors group-hover/sug:border-brand-100",children:[item.poster&&jsx2("img",{src:item.poster,alt:"",loading:"lazy",className:"w-full h-full object-cover"}),typeof item.duration==="number"&&jsx2("span",{"data-num":true,className:"absolute bottom-1 end-1 px-1 py-px rounded-xs bg-black/75 text-white text-micro font-bold",children:formatTime(item.duration)})]}),jsx2("span",{className:"text-caption font-bold text-white/90 leading-snug line-clamp-2 group-hover/sug:text-white",children:item.title})]})}function VideoPlayer({src,poster,title,chapters,captions,suggestions,suggestAt=10,autoPlay,loop,className}){const ui=useUIText();const{ref,state,toggle,seek,skip,setVolume,toggleMute,setRate}=useMedia();const shell=useRef3(null);const[full,setFull]=useState3(false);const[rateOpen,setRateOpen]=useState3(false);const[idle,setIdle]=useState3(false);const[dismissed,setDismissed]=useState3(false);const idleTimer=useRef3(void 0);const wake=useCallback3(()=>{setIdle(false);clearTimeout(idleTimer.current);idleTimer.current=setTimeout(()=>setIdle(true),2500)},[]);useEffect2(()=>{if(!state.playing)clearTimeout(idleTimer.current)},[state.playing]);useEffect2(()=>()=>clearTimeout(idleTimer.current),[]);useEffect2(()=>{const onFs=()=>setFull(document.fullscreenElement===shell.current);document.addEventListener("fullscreenchange",onFs);return()=>document.removeEventListener("fullscreenchange",onFs)},[]);async function toggleFull(){if(document.fullscreenElement)await document.exitFullscreen();else await shell.current?.requestFullscreen()}async function togglePip(){const el=ref.current;if(!el)return;if(document.pictureInPictureElement)await document.exitPictureInPicture();else await el.requestPictureInPicture()}const onKey=e=>{const keys=[" ","k","ArrowRight","ArrowLeft","ArrowUp","ArrowDown","m","f","j","l"];if(!keys.includes(e.key))return;e.preventDefault();wake();const el=ref.current;if(!el)return;switch(e.key){case" ":case"k":toggle();break;case"ArrowRight":case"l":skip(e.key==="l"?10:5);break;case"ArrowLeft":case"j":skip(e.key==="j"?-10:-5);break;case"ArrowUp":setVolume(el.volume+.1);break;case"ArrowDown":setVolume(el.volume-.1);break;case"m":toggleMute();break;case"f":void toggleFull();break}};const showChrome=!state.playing||!idle||state.ended;const has=Boolean(suggestions?.length);const remaining=state.duration-state.time;const nearEnd=state.duration>0&&remaining<=suggestAt&&!state.ended;const showStrip=has&&nearEnd&&!dismissed;const showEndScreen=has&&state.ended;return jsxs2("div",{ref:shell,role:"group","aria-label":title??ui.videoPlayer,tabIndex:0,onKeyDown:onKey,onMouseMove:wake,onMouseLeave:()=>state.playing&&setIdle(true),className:cn("relative bg-night rounded-card overflow-clip group/player","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",full?"w-screen h-screen rounded-none":"w-full aspect-video",className),children:[jsx2("video",{ref,src,poster,autoPlay,loop,playsInline:true,onClick:toggle,className:"w-full h-full object-contain cursor-pointer bg-night",children:captions&&jsx2("track",{kind:"captions",src:captions,srcLang:"ar",label:ui.arabic,default:true})}),state.waiting&&jsx2("span",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:jsx2(Loader2,{size:40,className:"animate-spin text-white/90","aria-hidden":"true"})}),(!state.playing||state.ended)&&!state.waiting&&!showEndScreen&&jsx2("button",{type:"button",onClick:toggle,"aria-label":state.ended?"\u0634\u063A\u0651\u0644 \u0645\u0646 \u0627\u0644\u0623\u0648\u0644":"\u062A\u0634\u063A\u064A\u0644",className:"absolute inset-0 flex items-center justify-center cursor-pointer group/big",children:jsx2("span",{className:"size-16 rounded-full bg-brand text-white flex items-center justify-center shadow-pop transition-transform group-hover/big:scale-110",children:state.ended?jsx2(RotateCcw,{size:26,"aria-hidden":"true"}):jsx2(Play,{size:28,className:"ml-1 icon-fixed",fill:"currentColor","aria-hidden":"true"})})}),title&&jsx2("div",{className:cn("absolute inset-x-0 top-0 p-4 bg-gradient-to-b from-black/70 to-transparent transition-opacity duration-200 pointer-events-none",showChrome?"opacity-100":"opacity-0"),children:jsx2("span",{className:"text-body font-extrabold text-white [text-wrap:balance]",children:title})}),showStrip&&jsx2("div",{className:"absolute inset-x-0 bottom-20 px-3 animate-[fade-in_.2s_ease-out]",children:jsxs2("div",{className:"flex items-end gap-3 p-3 rounded-card bg-black/70 backdrop-blur-sm border border-white/10",children:[jsxs2("div",{className:"flex flex-col gap-2 min-w-0 flex-1",children:[jsxs2("span",{className:"flex items-center gap-2 text-caption font-extrabold text-white/90",children:["\u0634\u0648\u0641 \u0643\u0645\u0627\u0646",jsxs2("span",{"data-num":true,className:"text-micro font-bold text-brand-100",children:["\u0627\u0644\u0645\u0642\u0637\u0639 \u0628\u064A\u062E\u0644\u0635 \u062E\u0644\u0627\u0644 ",Math.max(0,Math.ceil(remaining))," \u062B"]})]}),jsx2("div",{className:"flex gap-2.5 overflow-x-auto pb-1",children:suggestions?.slice(0,4).map(s=>jsx2(SuggestionCard,{item:s},s.id))})]}),jsx2("button",{type:"button",onClick:()=>setDismissed(true),"aria-label":ui.hideSuggestions,className:"size-8 rounded-sm shrink-0 flex items-center justify-center text-white/60 hover:bg-white/15 hover:text-white cursor-pointer transition-colors",children:jsx2(X,{size:16,"aria-hidden":"true"})})]})}),showEndScreen&&jsxs2("div",{className:"absolute inset-0 bg-night/92 backdrop-blur-sm flex flex-col gap-4 p-5 overflow-y-auto animate-[fade-in_.22s_ease-out]",children:[jsxs2("div",{className:"flex items-center justify-between gap-3 shrink-0",children:[jsx2("span",{className:"text-body font-extrabold text-white",children:ui.seeMore}),jsxs2("button",{type:"button",onClick:toggle,className:"inline-flex items-center gap-2 h-9 px-3.5 rounded-sm bg-white/10 text-white text-ui font-bold cursor-pointer transition-colors hover:bg-white/20",children:[jsx2(RotateCcw,{size:15,"aria-hidden":"true"}),"\u0634\u063A\u0651\u0644 \u0645\u0646 \u0627\u0644\u0623\u0648\u0644"]})]}),jsx2("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fill,minmax(150px,1fr))]",children:suggestions?.map(s=>jsx2(SuggestionCard,{item:s,wide:true},s.id))})]}),jsxs2("div",{className:cn("absolute inset-x-0 bottom-0 px-3 pb-2 pt-8 bg-gradient-to-t from-black/80 to-transparent transition-opacity duration-200",showChrome?"opacity-100":"opacity-0 pointer-events-none"),children:[jsx2(Scrubber,{time:state.time,duration:state.duration,buffered:state.buffered,onSeek:seek,chapters}),jsxs2("div",{className:"flex items-center gap-1 flex-wrap",children:[jsx2(CtrlButton,{onClick:toggle,label:state.playing?"\u0625\u064A\u0642\u0627\u0641 \u0645\u0624\u0642\u062A":"\u062A\u0634\u063A\u064A\u0644",children:state.playing?jsx2(Pause,{size:18,fill:"currentColor"}):jsx2(Play,{size:18,fill:"currentColor"})}),jsx2(CtrlButton,{onClick:()=>skip(-10),label:ui.back10,children:jsx2(RotateCcw,{size:17})}),jsx2(CtrlButton,{onClick:()=>skip(10),label:ui.forward10,children:jsx2(RotateCw,{size:17})}),jsxs2("span",{className:"flex items-center group/vol",children:[jsx2(CtrlButton,{onClick:toggleMute,label:state.muted?"\u062A\u0634\u063A\u064A\u0644 \u0627\u0644\u0635\u0648\u062A":"\u0643\u062A\u0645",children:state.muted||state.volume===0?jsx2(VolumeX,{size:18}):jsx2(Volume2,{size:18})}),jsx2("span",{className:"h-9 flex items-center overflow-clip w-0 group-hover/vol:w-20 focus-within:w-20 transition-[width] duration-200",children:jsx2("input",{type:"range",min:0,max:1,step:.05,value:state.muted?0:state.volume,onChange:e=>setVolume(Number(e.target.value)),"aria-label":ui.volume,dir:"ltr",className:"w-20 accent-brand cursor-pointer"})})]}),jsxs2("span",{"data-num":true,className:"px-2 text-caption font-bold text-white/90 whitespace-nowrap",children:[formatTime(state.time)," / ",formatTime(state.duration)]}),jsx2("span",{className:"flex-1"}),jsxs2("span",{className:"relative flex",children:[jsx2(CtrlButton,{onClick:()=>setRateOpen(v=>!v),label:ui.playbackSpeed,active:rateOpen,children:jsxs2("span",{className:"flex items-center gap-1",children:[jsx2(Gauge,{size:17}),state.rate!==1&&jsxs2("span",{"data-num":true,className:"text-micro font-extrabold",children:[state.rate,"\xD7"]})]})}),rateOpen&&jsx2("div",{className:"absolute bottom-full end-0 mb-2 py-1 rounded-card bg-night border border-white/15 shadow-pop min-w-20",children:RATES.map(r=>jsx2("button",{type:"button",onClick:()=>{setRate(r);setRateOpen(false)},className:cn("w-full px-3 py-1.5 text-ui text-center cursor-pointer transition-colors",r===state.rate?"text-brand-100 font-extrabold":"text-white/80 hover:bg-white/10"),children:jsxs2("span",{"data-num":true,children:[r,"\xD7"]})},r))})]}),"pictureInPictureEnabled"in document&&jsx2(CtrlButton,{onClick:()=>void togglePip(),label:ui.pictureInPicture,children:jsx2(PictureInPicture2,{size:17})}),jsx2(CtrlButton,{onClick:()=>void toggleFull(),label:full?"\u062E\u0631\u0648\u062C \u0645\u0646 \u0645\u0644\u0621 \u0627\u0644\u0634\u0627\u0634\u0629":"\u0645\u0644\u0621 \u0627\u0644\u0634\u0627\u0634\u0629",children:full?jsx2(Minimize,{size:17}):jsx2(Maximize,{size:17})})]})]})]})}import{memo,useEffect as useEffect3,useImperativeHandle,useMemo,useRef as useRef4,useState as useState4}from"react";import{Gauge as Gauge2,Loader2 as Loader22,Pause as Pause2,Play as Play2,RotateCcw as RotateCcw2,RotateCw as RotateCw2,Volume2 as Volume22,VolumeX as VolumeX2}from"lucide-react";import{jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";var PEAKS_CACHE=new Map;var ANALYSIS_BUCKETS=512;var BAR=3;var GAP=2;async function analyse(src,buckets){const cached=PEAKS_CACHE.get(src);if(cached!==void 0)return cached;try{const res=await fetch(src);const raw=await res.arrayBuffer();const Ctx2=window.AudioContext??window.webkitAudioContext;if(!Ctx2)throw new Error("\u0645\u0627\u0641\u064A\u0634 Web Audio");const ctx=new Ctx2;const buffer=await ctx.decodeAudioData(raw);const data=buffer.getChannelData(0);const per=Math.floor(data.length/buckets);const peaks=[];for(let i=0;i<buckets;i++){let max=0;for(let j=0;j<per;j++){const v=Math.abs(data[i*per+j]??0);if(v>max)max=v}peaks.push(max)}void ctx.close();const top=Math.max(...peaks,.01);const normalised=peaks.map(p=>p/top);PEAKS_CACHE.set(src,normalised);return normalised}catch{PEAKS_CACHE.set(src,null);return null}}var BarRow=memo(function BarRow2({peaks,color}){return jsx3("div",{"aria-hidden":"true",className:"absolute inset-0 flex items-center justify-between",style:{gap:GAP},children:peaks.map((p,i)=>jsx3("span",{style:{height:`${Math.max(8,p*100)}%`,width:BAR},className:cn("shrink-0 rounded-full",color)},i))})});function Waveform({peaks,time,duration,onSeek,bars,height=48}){const ui=useUIText();const box=useRef4(null);const[count,setCount]=useState4(bars??0);const[width,setWidth]=useState4(0);useEffect3(()=>{const el=box.current;if(!el)return;const measure=()=>{setWidth(el.clientWidth);if(!bars)setCount(Math.max(8,Math.floor(el.clientWidth/(BAR+GAP))))};measure();const ro=new ResizeObserver(measure);ro.observe(el);return()=>ro.disconnect()},[bars]);const shown=useMemo(()=>{if(count<=0)return[];const per=peaks.length/count;return Array.from({length:count},(_,i)=>{let max=0;for(let j=Math.floor(i*per);j<Math.floor((i+1)*per);j++){if(peaks[j]>max)max=peaks[j]}return max})},[peaks,count]);const played=duration>0?Math.min(1,time/duration):0;const grey=useMemo(()=>jsx3(BarRow,{peaks:shown,color:"bg-border/50"}),[shown]);const teal=useMemo(()=>jsx3(BarRow,{peaks:shown,color:"bg-brand"}),[shown]);return jsxs3("div",{dir:"ltr",className:"relative w-full",style:{height},children:[jsx3("div",{ref:box,className:"absolute inset-0",children:grey}),jsx3("div",{"aria-hidden":"true",className:"absolute inset-y-0 start-0 overflow-clip pointer-events-none",style:{width:`${played*100}%`},children:jsx3("div",{className:"relative h-full",style:{width:width||"100%"},children:teal})}),jsx3("input",{type:"range",min:0,max:duration||0,step:.1,value:time,"aria-label":ui.playbackPosition,"aria-valuetext":`${formatTime(time)} \u0645\u0646 ${formatTime(duration)}`,onChange:e=>onSeek(Number(e.target.value)),className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]})}function Btn({onClick,label,children,small}){return jsx3("button",{type:"button",onClick,"aria-label":label,title:label,className:cn("rounded-sm inline-flex items-center justify-center shrink-0 cursor-pointer transition-colors","text-muted hover:bg-hover hover:text-ink","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",small?"size-8":"size-9"),children})}function AudioPlayer({src,title,meta,cover,variant="card",bars,onLevel,mediaRef,className}){const ui=useUIText();const{ref,state,toggle,seek,skip,setVolume,toggleMute,setRate}=useMedia();const[peaks,setPeaks]=useState4(null);const[analysing,setAnalysing]=useState4(false);const[rateOpen,setRateOpen]=useState4(false);const alive=useRef4(true);useEffect3(()=>{alive.current=true;return()=>{alive.current=false}},[]);useEffect3(()=>{if(variant==="row")return;let live=true;void Promise.resolve().then(()=>live&&setAnalysing(true));void analyse(src,ANALYSIS_BUCKETS).then(p=>{live=false;if(!alive.current)return;setPeaks(p);setAnalysing(false)})},[src,variant]);useImperativeHandle(mediaRef,()=>ref.current,[ref]);useEffect3(()=>{if(!onLevel)return;if(!peaks||state.duration<=0||!state.playing){onLevel(0);return}const i=Math.min(peaks.length-1,Math.floor(state.time/state.duration*peaks.length));onLevel(peaks[i]??0)},[onLevel,peaks,state.time,state.duration,state.playing]);const PlayBtn=jsx3("button",{type:"button",onClick:toggle,"aria-label":state.playing?"\u0625\u064A\u0642\u0627\u0641 \u0645\u0624\u0642\u062A":"\u062A\u0634\u063A\u064A\u0644",className:cn("rounded-full bg-brand text-white flex items-center justify-center shrink-0 cursor-pointer transition-colors hover:bg-brand-hover","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",variant==="row"?"size-9":"size-11"),children:state.playing?jsx3(Pause2,{size:variant==="row"?16:18,fill:"currentColor","aria-hidden":"true"}):jsx3(Play2,{size:variant==="row"?16:18,className:"ml-0.5 icon-fixed",fill:"currentColor","aria-hidden":"true"})});const audio=jsx3("audio",{ref,src,preload:"metadata"});if(variant==="row"){return jsxs3("div",{className:cn("flex items-center gap-3 p-2.5 rounded-card border border-line bg-surface",className),children:[audio,PlayBtn,jsxs3("span",{className:"flex flex-col gap-1 flex-1 min-w-0",children:[title&&jsx3("span",{className:"text-ui font-bold text-ink truncate",children:title}),jsxs3("span",{dir:"ltr",className:"relative h-1 rounded-full bg-hover overflow-clip",children:[jsx3("span",{"aria-hidden":"true",style:{width:`${state.duration?state.time/state.duration*100:0}%`},className:"absolute inset-y-0 start-0 bg-brand rounded-full"}),jsx3("input",{type:"range",min:0,max:state.duration||0,step:.1,value:state.time,"aria-label":ui.playbackPosition,onChange:e=>seek(Number(e.target.value)),className:"absolute inset-0 w-full opacity-0 cursor-pointer"})]})]}),jsxs3("span",{"data-num":true,className:"text-micro text-muted2 shrink-0",children:[formatTime(state.time)," / ",formatTime(state.duration)]})]})}return jsxs3("div",{className:cn("flex flex-col gap-3.5 p-4 rounded-card border border-line bg-surface",className),children:[audio,(title||cover)&&jsxs3("div",{className:"flex items-center gap-3",children:[cover&&jsx3("img",{src:cover,alt:"",className:"size-12 rounded-sm object-cover border border-line shrink-0"}),jsxs3("span",{className:"flex flex-col gap-0.5 min-w-0",children:[title&&jsx3("span",{className:"text-body font-extrabold text-ink truncate",children:title}),meta&&jsx3("span",{className:"text-caption text-muted truncate",children:meta})]})]}),jsx3("div",{className:"min-h-12 flex items-center",children:analysing?jsxs3("span",{className:"w-full flex items-center justify-center gap-2 text-caption text-muted2",children:[jsx3(Loader22,{size:14,className:"animate-spin","aria-hidden":"true"}),"\u0628\u064A\u062D\u0644\u0651\u0644 \u0627\u0644\u0645\u0648\u062C\u0629\u2026"]}):peaks?jsx3(Waveform,{peaks,time:state.time,duration:state.duration,onSeek:seek,bars}):jsxs3("span",{dir:"ltr",className:"relative w-full h-1.5 rounded-full bg-hover",children:[jsx3("span",{"aria-hidden":"true",style:{width:`${state.duration?state.time/state.duration*100:0}%`},className:"absolute inset-y-0 start-0 bg-brand rounded-full"}),jsx3("input",{type:"range",min:0,max:state.duration||0,step:.1,value:state.time,"aria-label":ui.playbackPosition,onChange:e=>seek(Number(e.target.value)),className:"absolute inset-0 w-full opacity-0 cursor-pointer"})]})}),jsxs3("div",{className:"flex items-center gap-1 flex-wrap",children:[PlayBtn,jsx3(Btn,{onClick:()=>skip(-10),label:ui.back10,children:jsx3(RotateCcw2,{size:16})}),jsx3(Btn,{onClick:()=>skip(10),label:ui.forward10,children:jsx3(RotateCw2,{size:16})}),jsxs3("span",{className:"flex items-center group/vol",children:[jsx3(Btn,{onClick:toggleMute,label:state.muted?"\u062A\u0634\u063A\u064A\u0644 \u0627\u0644\u0635\u0648\u062A":"\u0643\u062A\u0645",children:state.muted||state.volume===0?jsx3(VolumeX2,{size:16}):jsx3(Volume22,{size:16})}),jsx3("span",{className:"h-9 flex items-center overflow-clip w-0 group-hover/vol:w-16 focus-within:w-16 transition-[width] duration-200",children:jsx3("input",{type:"range",min:0,max:1,step:.05,value:state.muted?0:state.volume,onChange:e=>setVolume(Number(e.target.value)),"aria-label":ui.volume,dir:"ltr",className:"w-16 accent-brand cursor-pointer"})})]}),jsxs3("span",{"data-num":true,className:"px-2 text-caption font-bold text-ink2 whitespace-nowrap",children:[formatTime(state.time)," / ",formatTime(state.duration)]}),jsx3("span",{className:"flex-1"}),jsxs3("span",{className:"relative flex",children:[jsx3(Btn,{onClick:()=>setRateOpen(v=>!v),label:ui.playbackSpeed,children:jsxs3("span",{className:"flex items-center gap-1",children:[jsx3(Gauge2,{size:16}),state.rate!==1&&jsxs3("span",{"data-num":true,className:"text-micro font-extrabold text-brand-ink",children:[state.rate,"\xD7"]})]})}),rateOpen&&jsx3("div",{className:"absolute bottom-full end-0 mb-2 py-1 rounded-card bg-surface border border-line shadow-panel min-w-20 z-20",children:RATES.map(r=>jsx3("button",{type:"button",onClick:()=>{setRate(r);setRateOpen(false)},className:cn("w-full px-3 py-1.5 text-ui text-center cursor-pointer transition-colors",r===state.rate?"bg-soft text-brand-ink font-extrabold":"text-ink2 hover:bg-hover"),children:jsxs3("span",{"data-num":true,children:[r,"\xD7"]})},r))})]})]})]})}import{useEffect as useEffect4,useRef as useRef5,useState as useState5}from"react";var SOURCES=new WeakMap;function useAudioLevel(ref,{bands=5,enabled=true}={}){const level=useRef5(0);const bandsRef=useRef5(Array.from({length:bands},()=>0));const[ready,setReady]=useState5(false);const[failed,setFailed]=useState5(false);useEffect4(()=>{const el=ref.current;if(!el||!enabled)return;let raf=0;let analyser=null;let dead=false;function connect(){if(dead||analyser)return;const media=ref.current;if(!media)return;try{let entry=SOURCES.get(media);if(!entry){const Ctx2=window.AudioContext??window.webkitAudioContext;if(!Ctx2)throw new Error("\u0645\u0627\u0641\u064A\u0634 Web Audio");const ctx=new Ctx2;const source=ctx.createMediaElementSource(media);source.connect(ctx.destination);entry={ctx,source};SOURCES.set(media,entry)}void entry.ctx.resume();analyser=entry.ctx.createAnalyser();analyser.fftSize=1024;analyser.smoothingTimeConstant=.75;entry.source.connect(analyser);setReady(true);loop()}catch{setFailed(true)}}const spectrum=new Uint8Array(512);const wave=new Uint8Array(1024);let peak=.02;function loop(){if(dead||!analyser)return;analyser.getByteFrequencyData(spectrum);analyser.getByteTimeDomainData(wave);let sum=0;for(let i=0;i<wave.length;i++){const v=(wave[i]-128)/128;sum+=v*v}const rms=Math.sqrt(sum/wave.length);peak=Math.max(rms,peak*.995);level.current=Math.min(1,rms/Math.max(peak,.015));const out=[];for(let b=0;b<bands;b++){const from=Math.floor(spectrum.length**(b/bands))-1;const to=Math.floor(spectrum.length**((b+1)/bands));let peak2=0;for(let i=Math.max(0,from);i<to;i++){if(spectrum[i]>peak2)peak2=spectrum[i]}out.push(peak2/255)}bandsRef.current=out;raf=requestAnimationFrame(loop)}el.addEventListener("play",connect);if(!el.paused)connect();return()=>{dead=true;cancelAnimationFrame(raf);el.removeEventListener("play",connect);analyser?.disconnect()}},[ref,bands,enabled]);return{level,bands:bandsRef,ready,failed}}import{createContext,useCallback as useCallback4,useContext,useEffect as useEffect7,useMemo as useMemo2,useRef as useRef8,useState as useState8}from"react";import{useEffect as useEffect5,useLayoutEffect,useRef as useRef6,useState as useState6}from"react";import{X as X2}from"lucide-react";import{jsx as jsx4,jsxs as jsxs4}from"react/jsx-runtime";var GAP2=10;var EDGE=12;var WIDTH=264;function CoachHintSurface({item,onClose}){const ui=useUIText();const anchors=useCoachAnchors();const box=useRef6(null);const[pos,setPos]=useState6(null);const anchorId=item.where?.anchor;const gone=anchorId!==void 0&&!anchors.get(anchorId);useLayoutEffect(()=>{if(!anchorId)return;const el=anchors.get(anchorId);if(!el)return;function place(){const target=anchors.get(anchorId);const self=box.current;if(!target||!self)return;const a=target.getBoundingClientRect();const h=self.offsetHeight;const below=a.bottom+GAP2;const above=window.innerHeight-a.top+GAP2;const flip=below+h>window.innerHeight-EDGE&&above>below;const left=Math.min(window.innerWidth-WIDTH-EDGE,Math.max(EDGE,a.left+a.width/2-WIDTH/2));setPos({top:flip?a.top-h-GAP2:a.bottom+GAP2,left,above:flip})}place();window.addEventListener("scroll",place,true);window.addEventListener("resize",place);return()=>{window.removeEventListener("scroll",place,true);window.removeEventListener("resize",place)}},[anchorId,anchors]);useEffect5(()=>{if(!anchorId)return;const el=anchors.get(anchorId);if(!el)return;const prev=el.style.boxShadow;el.style.boxShadow="0 0 0 3px var(--color-soft), 0 0 0 4px var(--color-brand)";el.style.borderRadius=el.style.borderRadius||"var(--radius-field)";return()=>{el.style.boxShadow=prev}},[anchorId,anchors]);useEffect5(()=>{if(gone)onClose()},[gone,onClose]);useEffect5(()=>{const onKey=e=>{if(e.key==="Escape")onClose()};document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[onClose]);if(gone)return null;return jsxs4("div",{ref:box,role:"status",style:{width:WIDTH,top:pos?.top??-9999,left:pos?.left??-9999},className:cn("fixed z-[80] rounded-card border border-line bg-surface shadow-pop p-3 flex flex-col gap-1.5","animate-qfade",pos?"opacity-100":"opacity-0"),children:[jsxs4("div",{className:"flex items-start gap-2",children:[jsxs4("span",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[item.title&&jsx4("span",{className:"text-ui font-extrabold text-ink",children:item.title}),jsx4("span",{className:"text-caption leading-[1.75] text-ink2 [text-wrap:pretty]",children:item.text})]}),jsx4("button",{type:"button","aria-label":ui.close,onClick:onClose,className:"size-6 -me-1 -mt-0.5 rounded-xs flex items-center justify-center text-muted hover:text-ink hover:bg-hover cursor-pointer transition-colors shrink-0",children:jsx4(X2,{size:13,"aria-hidden":"true"})})]}),jsx4("span",{"aria-hidden":"true",className:cn("absolute start-1/2 -ms-1.5 size-3 rotate-45 bg-surface border-line",pos?.above?"-bottom-1.5 border-e border-b":"-top-1.5 border-s border-t")})]})}import{useEffect as useEffect6,useRef as useRef7,useState as useState7}from"react";import{X as X3}from"lucide-react";import{Fragment,jsx as jsx5,jsxs as jsxs5}from"react/jsx-runtime";function CoachAudioSurface({item,onClose,orb,region}){const ui=useUIText();const box={top:0,bottom:0,insetInlineStart:0,insetInlineEnd:0,...region};const anchors=useCoachAnchors();const[time,setTime]=useState7(0);const wrap=useRef7(null);const level=useRef7(0);const active=item.lines.findIndex(l=>time>=l.start&&time<l.end);const line=active>=0?item.lines[active]:item.lines[0];useEffect6(()=>{const onKey=e=>{if(e.key==="Escape")onClose()};document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[onClose]);useEffect6(()=>{const el=wrap.current?.querySelector("audio");if(!el)return;const onTime=()=>setTime(el.currentTime);el.addEventListener("timeupdate",onTime);return()=>el.removeEventListener("timeupdate",onTime)},[]);useEffect6(()=>{const id=item.where?.anchor;if(!id)return;const el=anchors.get(id);if(!el)return;const prev=el.style.boxShadow;el.style.boxShadow="0 0 0 3px var(--color-soft), 0 0 0 4px var(--color-brand)";return()=>{el.style.boxShadow=prev}},[item,anchors]);useEffect6(()=>{if(!orb)return;let raf=0;let alive=true;let peaks=null;void(async()=>{try{const Ctx2=window.AudioContext??window.webkitAudioContext;if(!Ctx2)return;const raw=await(await fetch(item.src)).arrayBuffer();const ctx=new Ctx2;const buffer=await ctx.decodeAudioData(raw);void ctx.close();if(!alive)return;const data=buffer.getChannelData(0);const BUCKETS=600;const per=Math.floor(data.length/BUCKETS);const out=new Float32Array(BUCKETS);for(let i=0;i<BUCKETS;i++){let sum=0;for(let j=0;j<per;j++){const v=data[i*per+j];sum+=v*v}out[i]=Math.min(1,Math.sqrt(sum/per)*3.2)}peaks=out}catch{}})();const el=wrap.current?.querySelector("audio");const loop=()=>{if(peaks&&el&&el.duration>0){const i=Math.floor(el.currentTime/el.duration*peaks.length);level.current=peaks[Math.min(i,peaks.length-1)]??0}raf=requestAnimationFrame(loop)};loop();return()=>{alive=false;cancelAnimationFrame(raf)}},[item.src,orb]);return jsxs5(Fragment,{children:[jsx5("button",{type:"button","aria-label":ui.closeExplainer,onClick:onClose,style:box,className:"fixed z-[78] bg-night/25 backdrop-blur-[1.5px] cursor-pointer animate-qfade"}),jsxs5("div",{ref:wrap,style:box,className:"fixed z-[79] flex flex-col pointer-events-none",children:[orb&&jsx5("div",{"aria-hidden":"true",className:"flex-1 min-h-0 flex items-center justify-center animate-qfade",children:orb(level)}),jsx5("div",{className:"shrink-0 pointer-events-auto animate-tip-up",role:"region","aria-label":item.headline,children:jsx5("div",{className:"bg-surface border-t border-line shadow-sheet",children:jsxs5("div",{className:"mx-auto max-w-shell px-[22px] py-3 flex flex-col gap-2.5",children:[jsxs5("div",{className:"flex items-center gap-2.5",children:[jsx5("span",{"aria-live":"polite",className:"flex-1 min-w-0 text-ui font-bold leading-[1.7] text-ink [text-wrap:pretty]",children:line?.text}),jsx5("button",{type:"button","aria-label":ui.close,onClick:onClose,className:"size-8 rounded-sm flex items-center justify-center text-muted hover:text-ink hover:bg-hover cursor-pointer transition-colors shrink-0",children:jsx5(X3,{size:15,"aria-hidden":"true"})})]}),jsx5(AudioPlayer,{src:item.src,title:item.headline,meta:item.meta})]})})})]})]})}import{jsx as jsx6,jsxs as jsxs6}from"react/jsx-runtime";var Ctx=createContext(null);var AnchorCtx=createContext(null);function useCoachAnchors(){const ctx=useContext(AnchorCtx);if(!ctx)throw new Error("<Coach> \u0644\u0627\u0632\u0645 \u064A\u0643\u0648\u0646 \u062C\u0648\u0651\u0647 <CoachProvider>");return ctx}function readSeen(key){try{return JSON.parse(localStorage.getItem(key)??"[]")}catch{return[]}}function CoachProvider({items,path,orb,region,storageKey="qumra-coach-seen",disabled,children}){const[seenIds,setSeenIds]=useState8(()=>readSeen(storageKey));const[openId,setOpenId]=useState8(null);const[openPath,setOpenPath]=useState8(path);const shownId=openPath===path?openId:null;const anchors=useRef8(new Map);const anchorApi=useMemo2(()=>({set:(id,el)=>{if(el)anchors.current.set(id,el);else anchors.current.delete(id)},get:id=>anchors.current.get(id)??null}),[]);const markSeen=useCallback4(id=>{setSeenIds(prev=>{if(prev.includes(id))return prev;const next=[...prev,id];try{localStorage.setItem(storageKey,JSON.stringify(next))}catch{}return next})},[storageKey]);const close=useCallback4(()=>{setOpenId(id=>{if(id)markSeen(id);return null})},[markSeen]);useEffect7(()=>{if(disabled)return;const candidate=items.find(it=>(it.when??"enter")!=="manual"&&(it.where?.path===void 0||it.where.path===path)&&!seenIds.includes(it.id));if(!candidate)return;const when=candidate.when??"enter";const delay=when.startsWith("idle:")?Number(when.slice(5,-1))*1e3:0;const timer=setTimeout(()=>{setOpenId(candidate.id);setOpenPath(path)},delay);return()=>clearTimeout(timer)},[items,path,disabled]);const api=useMemo2(()=>({show:id=>{if(disabled||seenIds.includes(id))return;setOpenId(id);setOpenPath(path)},replay:id=>{setOpenId(id);setOpenPath(path)},close,current:items.find(it=>it.id===shownId)??null,seen:id=>seenIds.includes(id),reset:()=>{setSeenIds([]);try{localStorage.removeItem(storageKey)}catch{}}}),[items,shownId,path,seenIds,close,disabled,storageKey]);const current=api.current;return jsx6(AnchorCtx.Provider,{value:anchorApi,children:jsxs6(Ctx.Provider,{value:api,children:[children,current?.kind==="hint"&&jsx6(CoachHintSurface,{item:current,onClose:close}),current?.kind==="audio"&&jsx6(CoachAudioSurface,{item:current,onClose:close,orb,region})]})})}function useCoach(){const ctx=useContext(Ctx);if(!ctx)throw new Error("useCoach \u0644\u0627\u0632\u0645 \u064A\u062A\u0646\u0627\u062F\u0649 \u062C\u0648\u0651\u0647 <CoachProvider>");return ctx}function useCoachOptional(){return useContext(Ctx)}import{cloneElement,isValidElement,useEffect as useEffect8,useRef as useRef9}from"react";import{jsx as jsx7}from"react/jsx-runtime";function Coach({id,asChild,children}){const anchors=useCoachAnchors();const own=useRef9(null);useEffect8(()=>{if(asChild)return;const el=own.current?.firstElementChild??own.current;anchors.set(id,el);return()=>anchors.set(id,null)},[id,anchors,asChild]);if(asChild&&isValidElement(children)){return cloneElement(children,{ref:el=>anchors.set(id,el)})}return jsx7("span",{ref:own,className:"contents",children})}var coachSeconds=item=>item.lines[item.lines.length-1]?.end??0;import{Info}from"lucide-react";import{jsx as jsx8,jsxs as jsxs7}from"react/jsx-runtime";function Badge({children,tone="neutral",variant="soft",size="md",dot,icon,className}){return jsxs7("span",{className:cn("inline-flex items-center gap-1.5 rounded-full font-bold whitespace-nowrap",size==="sm"?"text-micro px-2 py-0.5":"text-caption px-2.5 py-1",variant==="solid"?TONE_SOLID[tone]:TONE_SOFT[tone],className),children:[dot&&jsx8("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-current shrink-0"}),icon,children]})}function Counter({value,max=99}){if(value<=0)return null;return jsx8("span",{"data-num":true,dir:"ltr",className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1.5 rounded-full bg-danger text-white text-micro font-extrabold leading-none",children:value>max?`${max}+`:value})}var AVATAR_SIZES={xs:"size-7 text-micro",sm:"size-9 text-ui",md:"size-11 text-body",lg:"size-14 text-h4"};function initials(name){return name.trim().split(/\s+/).slice(0,2).map(w=>w[0]).join("")}function Avatar({name,src,size="md",square,className}){const shape=square?"rounded-field":"rounded-full";if(src){return jsx8("img",{src,alt:name,loading:"lazy",className:cn("object-cover border border-line shrink-0",shape,AVATAR_SIZES[size],className)})}return jsx8("span",{role:"img","aria-label":name,className:cn("flex items-center justify-center font-extrabold bg-soft text-brand-ink shrink-0",shape,AVATAR_SIZES[size],className),children:initials(name)})}function StatCard({icon:Icon,tone="brand",label,value,hint,coachId,className}){const ui=useUIText();const coach=useCoachOptional();const explained=Boolean(coachId&&coach);const body=jsxs7("div",{className:cn("relative bg-surface border border-line rounded-card p-4 flex flex-col gap-2",className),children:[jsxs7("span",{className:"flex items-center gap-2.5",children:[Icon&&jsx8("span",{"aria-hidden":"true",className:cn("size-[30px] rounded-sm flex items-center justify-center shrink-0",TONE_SOFT[tone]),children:jsx8(Icon,{size:15,strokeWidth:2})}),jsx8("span",{className:"text-ui text-muted",children:label}),explained&&jsx8("button",{type:"button",onClick:()=>coach.replay(coachId),"aria-label":typeof label==="string"?`\u0645\u0627 \u0645\u0639\u0646\u0649 \xAB${label}\xBB\u061F`:"\u0645\u0627 \u0645\u0639\u0646\u0649 \u0647\u0630\u0627 \u0627\u0644\u0631\u0642\u0645\u061F",title:ui.whatIsThisNumber,className:cn("ms-auto -me-1 -mt-1 size-7 rounded-full shrink-0 flex items-center justify-center","text-brand cursor-pointer transition-colors","hover:bg-soft hover:text-brand-hover","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand"),children:jsx8(Info,{size:15,strokeWidth:2,"aria-hidden":"true"})})]}),jsx8("span",{"data-num":true,className:"text-h3 font-extrabold leading-none whitespace-nowrap",children:value}),hint&&jsx8("span",{className:"text-micro text-muted2",children:hint})]});return explained?jsx8(Coach,{id:coachId,children:body}):body}function Card({children,padded=true,className}){return jsx8("div",{className:cn("bg-surface border border-line rounded-card",padded?"p-5":"overflow-clip",className),children})}function CardHeader({title,description,action,coachId}){const ui=useUIText();const coach=useCoachOptional();const explained=Boolean(coachId&&coach);const head=jsxs7("div",{className:"flex items-start justify-between gap-4",children:[jsxs7("div",{className:"flex flex-col gap-1 min-w-0",children:[jsx8("h3",{className:"text-lead font-extrabold text-ink m-0",children:title}),description&&jsx8("p",{className:"text-ui text-muted m-0",children:description})]}),(action||explained)&&jsxs7("div",{className:"shrink-0 flex items-center gap-1.5",children:[action,explained&&jsx8("button",{type:"button",onClick:()=>coach.replay(coachId),"aria-label":typeof title==="string"?`\u0645\u0627 \u0645\u0639\u0646\u0649 \xAB${title}\xBB\u061F`:"\u0645\u0627 \u0647\u0630\u0627 \u0627\u0644\u0642\u0633\u0645\u061F",title:ui.explainToMe,className:cn("size-7 rounded-full shrink-0 flex items-center justify-center","text-brand cursor-pointer transition-colors","hover:bg-soft hover:text-brand-hover","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand"),children:jsx8(Info,{size:15,strokeWidth:2,"aria-hidden":"true"})})]})]});return explained?jsx8(Coach,{id:coachId,children:head}):head}function PageHeader({title,hint,actions}){return jsxs7("div",{className:"flex items-start justify-between gap-3.5 flex-wrap",children:[jsxs7("div",{className:"flex flex-col gap-1 min-w-0",children:[jsx8("h1",{className:"text-h3 font-black text-ink m-0 [text-wrap:balance]",children:title}),hint&&jsx8("p",{className:"text-ui text-muted m-0 [text-wrap:pretty]",children:hint})]}),actions&&jsx8("div",{className:"flex items-center gap-2.5 shrink-0 flex-wrap",children:actions})]})}function Progress({value,max=100,label,tone="brand",className}){const safe=Math.min(max,Math.max(0,value));const pct=safe/max*100;const fill={neutral:"bg-muted2",brand:"bg-brand",amber:"bg-amber",green:"bg-green-solid",red:"bg-danger",violet:"bg-violet-solid"};return jsxs7("div",{className:cn("flex flex-col gap-1.5",className),children:[label&&jsxs7("span",{className:"flex items-center justify-between gap-3 text-caption",children:[jsx8("span",{className:"text-ink2",children:label}),jsxs7("span",{"data-num":true,className:"text-muted font-bold",children:[Math.round(pct),"%"]})]}),jsx8("span",{role:"progressbar","aria-valuenow":safe,"aria-valuemin":0,"aria-valuemax":max,className:"h-1.5 rounded-full bg-hover overflow-clip block",children:jsx8("span",{className:cn("block h-full rounded-full transition-[width] duration-500",fill[tone]),style:{width:`${pct}%`}})})]})}function Skeleton({variant="text",width,className}){return jsx8("span",{"aria-hidden":"true",style:{width},className:cn("block bg-skeleton animate-skeleton",variant==="text"&&"h-3.5 rounded-xs w-full",variant==="block"&&"h-20 rounded-field w-full",variant==="circle"&&"size-10 rounded-full",className)})}export{useMedia,formatTime,Scrubber,VideoPlayer,AudioPlayer,useAudioLevel,CoachProvider,useCoach,useCoachOptional,Coach,coachSeconds,Badge,Counter,Avatar,StatCard,Card,CardHeader,PageHeader,Progress,Skeleton};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{buttonClasses,cn,toLatinDigits}from"./chunk-ZE4S6DBP.js";import{forwardRef}from"react";import{Loader2}from"lucide-react";import{jsx,jsxs}from"react/jsx-runtime";var ICON_ONLY={sm:"w-9 px-0!",md:"w-10 px-0!",lg:"w-12 px-0!",xl:"w-14 px-0!"};var SPINNER={sm:14,md:15,lg:17,xl:20};var Button=forwardRef(function Button2({variant="primary",size="md",icon,iconEnd,iconOnly,loading,block,disabled,className,children,type="button",...rest},ref){return jsxs("button",{ref,type,disabled:disabled||loading,"aria-busy":loading||void 0,className:buttonClasses(variant,size,cn("disabled:opacity-50 disabled:cursor-not-allowed",iconOnly&&ICON_ONLY[size],block&&"w-full",className)),...rest,children:[loading?jsx(Loader2,{size:SPINNER[size],className:"animate-spin shrink-0","aria-hidden":"true"}):icon&&jsx("span",{className:"flex shrink-0",children:icon}),!iconOnly&&children,!loading&&iconEnd&&jsx("span",{className:"flex shrink-0",children:iconEnd})]})});import{forwardRef as forwardRef2,useId}from"react";import{AlertCircle,Check,ChevronDown,Minus,Search}from"lucide-react";import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function FieldShell({id,label,labelAside,labelSize,hint,error,required,hideLabel,className,children}){const labelEl=label&&jsxs2("label",{htmlFor:id,className:cn(labelSize??"text-ui","font-bold text-ink2",hideLabel&&"sr-only"),children:[label,required&&jsx2("span",{className:"text-danger ms-1","aria-hidden":"true",children:"*"})]});return jsxs2("div",{className:cn("flex flex-col gap-1.5",className),children:[labelAside?jsxs2("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[labelEl,labelAside]}):labelEl,children,error?jsxs2("span",{id:`${id}-error`,role:"alert",className:"flex items-center gap-1.5 text-caption text-red",children:[jsx2(AlertCircle,{size:12,className:"shrink-0","aria-hidden":"true"}),error]}):hint?jsx2("span",{id:`${id}-hint`,className:"text-caption text-muted",children:hint}):null]})}var SIZES={sm:"h-9 text-ui",md:"h-11 text-body",lg:"h-14 text-base border-[1.5px]!"};var base=invalid=>cn("w-full bg-surface text-ink rounded-field border transition-colors outline-none","placeholder:text-muted2","focus:border-brand","disabled:bg-bg disabled:text-muted disabled:cursor-not-allowed",invalid?"border-danger":"border-border hover:border-brand");var Input=forwardRef2(function Input2({label,labelAside,hint,error,size="md",hideLabel,icon,suffix,action,numeric,required,className,wrapperClassName,id:idProp,onChange,type,inputMode,...rest},ref){const auto=useId();const id=idProp??auto;const invalid=Boolean(error);const lg=size==="lg";return jsx2(FieldShell,{id,label,labelAside,labelSize:lg?"text-body":void 0,hint,error,required,hideLabel,className:wrapperClassName,children:jsxs2("div",{className:"relative flex items-center",children:[icon&&jsx2("span",{className:cn("absolute flex text-muted pointer-events-none",lg?"start-4.5":"start-3.5"),"aria-hidden":"true",children:icon}),jsx2("input",{ref,id,required,type:numeric?"text":type,inputMode:numeric?inputMode??"decimal":inputMode,"aria-invalid":invalid||void 0,"aria-describedby":error?`${id}-error`:hint?`${id}-hint`:void 0,"data-num":numeric||void 0,"data-suffix":numeric&&suffix?"":void 0,"data-icon":numeric&&icon?"":void 0,onChange:numeric?e=>{const fixed=toLatinDigits(e.target.value);if(fixed!==e.target.value)e.target.value=fixed;onChange?.(e)}:onChange,className:cn(base(invalid),SIZES[size],lg?"px-4.5":"px-3.5",icon&&(lg?"ps-12":"ps-10"),suffix&&"pe-14",action&&(lg?"pe-14":"pe-11"),className),...rest}),suffix&&jsx2("span",{className:cn("absolute text-ui text-muted pointer-events-none",lg?"end-4.5":"end-3.5"),children:suffix}),action&&jsx2("span",{className:cn("absolute flex",lg?"end-4":"end-3"),children:action})]})})});var SearchInput=forwardRef2(function SearchInput2(props,ref){return jsx2(Input,{ref,icon:jsx2(Search,{size:16}),hideLabel:true,...props})});var Textarea=forwardRef2(function Textarea2({label,hint,error,required,hideLabel,rows=3,className,wrapperClassName,id:idProp,...rest},ref){const auto=useId();const id=idProp??auto;return jsx2(FieldShell,{id,label,hint,error,required,hideLabel,className:wrapperClassName,children:jsx2("textarea",{ref,id,rows,required,"aria-invalid":Boolean(error)||void 0,className:cn(base(Boolean(error)),"text-body px-3.5 py-3 resize-y min-h-20",className),...rest})})});var Select=forwardRef2(function Select2({label,hint,error,size="md",hideLabel,options,required,className,wrapperClassName,id:idProp,...rest},ref){const auto=useId();const id=idProp??auto;return jsx2(FieldShell,{id,label,hint,error,required,hideLabel,className:wrapperClassName,children:jsxs2("div",{className:"relative flex items-center",children:[jsx2("select",{ref,id,required,className:cn(base(Boolean(error)),SIZES[size],"appearance-none ps-3.5 pe-9 cursor-pointer font-medium",className),...rest,children:options.map(o=>jsx2("option",{value:o.value,children:o.label},o.value))}),jsx2(ChevronDown,{size:15,"aria-hidden":"true",className:"absolute end-3.5 text-muted2 pointer-events-none"})]})})});var CONTROL="peer appearance-none size-[19px] shrink-0 bg-surface border-[1.5px] border-border cursor-pointer transition-colors checked:bg-brand checked:border-brand hover:border-brand focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand disabled:bg-bg disabled:cursor-not-allowed";var Checkbox=forwardRef2(function Checkbox2({label,description,indeterminate,className,id:idProp,...rest},ref){const auto=useId();const id=idProp??auto;return jsxs2("span",{className:"flex items-start gap-2.5",children:[jsxs2("span",{className:"relative inline-flex items-center justify-center mt-px",children:[jsx2("input",{ref:el=>{if(el)el.indeterminate=Boolean(indeterminate);if(typeof ref==="function")ref(el);else if(ref)ref.current=el},id,type:"checkbox",className:cn(CONTROL,"rounded-xs",indeterminate&&"bg-brand border-brand",className),...rest}),indeterminate?jsx2(Minus,{size:12,strokeWidth:3,"aria-hidden":"true",className:"absolute text-white pointer-events-none"}):jsx2(Check,{size:12,strokeWidth:3,"aria-hidden":"true",className:"absolute text-white opacity-0 peer-checked:opacity-100 pointer-events-none transition-opacity"})]}),(label||description)&&jsxs2("label",{htmlFor:id,className:"flex flex-col gap-0.5 cursor-pointer select-none",children:[label&&jsx2("span",{className:"text-body text-ink",children:label}),description&&jsx2("span",{className:"text-caption text-muted",children:description})]})]})});var Radio=forwardRef2(function Radio2({label,description,className,id:idProp,...rest},ref){const auto=useId();const id=idProp??auto;return jsxs2("span",{className:"flex items-start gap-2.5",children:[jsxs2("span",{className:"relative inline-flex items-center justify-center mt-px",children:[jsx2("input",{ref,id,type:"radio",className:cn(CONTROL,"rounded-full",className),...rest}),jsx2("span",{"aria-hidden":"true",className:"absolute size-1.5 rounded-full bg-white opacity-0 peer-checked:opacity-100 pointer-events-none transition-opacity"})]}),(label||description)&&jsxs2("label",{htmlFor:id,className:"flex flex-col gap-0.5 cursor-pointer select-none",children:[label&&jsx2("span",{className:"text-body text-ink",children:label}),description&&jsx2("span",{className:"text-caption text-muted",children:description})]})]})});function RadioGroup({label,children,inline}){return jsxs2("fieldset",{className:"flex flex-col gap-2.5 border-0 p-0 m-0",children:[jsx2("legend",{className:"text-ui font-bold text-ink2 p-0 mb-1",children:label}),jsx2("div",{className:cn("flex gap-3",inline?"flex-row flex-wrap gap-5":"flex-col"),children})]})}function Switch({checked,onCheckedChange,label,description,disabled,id:idProp}){const auto=useId();const id=idProp??auto;const control=jsx2("button",{id,type:"button",role:"switch","aria-checked":checked,"aria-labelledby":label?`${id}-label`:void 0,disabled,onClick:()=>onCheckedChange(!checked),className:cn("relative shrink-0 w-11 h-6 rounded-full cursor-pointer transition-colors duration-200","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand","disabled:opacity-50 disabled:cursor-not-allowed",checked?"bg-brand":"bg-border"),children:jsx2("span",{"aria-hidden":"true",className:cn("absolute top-1/2 -translate-y-1/2 size-5 rounded-full bg-white shadow-sm transition-all duration-200",checked?"start-[calc(100%-1.375rem)]":"start-0.5")})});if(!label)return control;return jsxs2("span",{className:"flex items-start gap-3",children:[control,jsxs2("span",{className:"flex flex-col gap-0.5",children:[jsx2("span",{id:`${id}-label`,className:"text-body text-ink",children:label}),description&&jsx2("span",{className:"text-caption text-muted",children:description})]})]})}export{Button,Input,SearchInput,Textarea,Select,Checkbox,Radio,RadioGroup,Switch};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ var TEXT_SCALE=["micro","caption","ui","body","lead","base","h4","h3","h2","h1","display","hero","title","mega"];var RADIUS_SCALE=["mark","xs","sm","field","card","lg","section","full"];var SHADOW_SCALE=["raise","tip","panel","pop","modal","toast","sheet"];var CONTAINER_SCALE=["page","shell","note","lead"];var ANIMATE_SCALE=["qfade","qslide","tip","tip-up","drawer","drawer-rtl","savebar","skeleton"];var COLOR_SCALE=["surface","bg","line","hover","ink","ink2","muted","muted2","border","soft","soft2","brand-100","brand-900","brand-ink","brand","brand-hover","brand-deep","skeleton","tint","tint2","mint","amber-900","amber","amber-bg","amber-ink","amber-line","amber-hover","green","green-bg","green-bg2","green-line","green-solid","violet","violet-bg","violet-line","violet-solid","red-100","red","red-bg","red-line","danger","danger-hover","night","hero-body","hero-meta","hero-dim","hero-text","code-bg","code-plain","code-key","code-tag","code-attr","code-str","code-num","code-note","code-dim","code-line","code-chip"];var TOKENS={"--font-sans":'"Alexandria", system-ui, sans-serif',"--color-surface":"#ffffff","--color-bg":"#f7f9f9","--color-line":"#edf1f1","--color-hover":"#f2f6f6","--color-ink":"#020809","--color-ink2":"#3d4545","--color-muted":"#5f6a6a","--color-muted2":"#687373","--color-border":"#7f8c8c","--color-soft":"#eaf2f3","--color-soft2":"#dceded","--color-brand-100":"#a5c9cc","--color-brand-900":"#0a2528","--color-brand-ink":"#0f4a4e","--color-brand":"#207982","--color-brand-hover":"#1a646c","--color-brand-deep":"#0b3b3e","--color-skeleton":"#d6dcdc","--color-tint":"#f4faf8","--color-tint2":"#eff6f3","--color-mint":"#7dd3c0","--color-amber-900":"#3d2a05","--color-amber":"#f8ac33","--color-amber-bg":"#fef6e9","--color-amber-ink":"#85570f","--color-amber-line":"#fbd79a","--color-amber-hover":"#de9219","--color-green":"#1e7a45","--color-green-bg":"#f1faf4","--color-green-bg2":"#e9f6ee","--color-green-line":"#bfe6ce","--color-green-solid":"#1e7a45","--color-violet":"#4b3e8e","--color-violet-bg":"#edeaf6","--color-violet-line":"#ded8ef","--color-violet-solid":"#6d5eb8","--color-red-100":"#f3a79e","--color-red":"#8e2b20","--color-red-bg":"#fdecea","--color-red-line":"#f3c9c4","--color-danger":"#c94134","--color-danger-hover":"#a3362b","--color-night":"#0b0f12","--color-hero-body":"#bfd9d8","--color-hero-meta":"#8fb3b2","--color-hero-dim":"#5e7a79","--color-hero-text":"#d7e3e2","--color-code-bg":"#1f1f1f","--color-code-plain":"#d4d4d4","--color-code-key":"#569cd6","--color-code-tag":"#4ec9b0","--color-code-attr":"#9cdcfe","--color-code-str":"#ce9178","--color-code-num":"#b5cea8","--color-code-note":"#6a9955","--color-code-dim":"#858585","--color-code-line":"#303031","--color-code-chip":"#f4f7f7","--text-micro":"11px","--text-caption":"12px","--text-ui":"13px","--text-body":"14px","--text-lead":"15px","--text-base":"16px","--text-base--line-height":"initial","--text-h4":"17px","--text-h3":"20px","--text-h2":"24px","--text-h1":"30px","--text-display":"36px","--text-hero":"44px","--text-title":"40px","--text-mega":"54px","--container-page":"1600px","--container-shell":"1600px","--container-note":"340px","--container-lead":"520px","--radius-mark":"3px","--radius-xs":"5px","--radius-sm":"7px","--radius-field":"9px","--radius-card":"12px","--radius-lg":"14px","--radius-section":"18px","--radius-full":"999px","--shadow-raise":"0 1px 3px var(--shadow-color)","--shadow-tip":"0 6px 18px var(--shadow-color)","--shadow-panel":"0 10px 30px var(--shadow-color)","--shadow-pop":"0 18px 44px var(--shadow-color)","--shadow-modal":"0 24px 60px rgb(2 8 9 / 0.28)","--shadow-toast":"0 16px 40px rgb(2 8 9 / 0.26)","--shadow-sheet":"0 -14px 40px rgb(2 8 9 / 0.28), inset 0 1px 0 rgb(255 255 255 / 0.06)","--shadow-color":"rgb(2 8 9 / 0.14)","--animate-qfade":"qfade 0.16s ease-out","--animate-qslide":"qslidein 0.22s ease-out","--animate-tip":"tip-in 0.26s cubic-bezier(0.2, 0.8, 0.2, 1)","--animate-tip-up":"tip-up 0.3s cubic-bezier(0.2, 0.9, 0.2, 1)","--animate-drawer":"drawer-ltr 0.32s cubic-bezier(0.2, 0.9, 0.2, 1)","--animate-drawer-rtl":"drawer-rtl 0.32s cubic-bezier(0.2, 0.9, 0.2, 1)","--animate-savebar":"savebar-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1)","--animate-skeleton":"skeleton-pulse 1.6s ease-in-out infinite","--num-align":"right","--num-align-far":"left","--num-pad-right":"0.875rem","--num-pad-left":"3.5rem","--num-icon-pad-right":"2.5rem","--num-icon-pad-left":"0.875rem"};var DARK_TOKENS={"--color-surface":"#101718","--color-bg":"#0a0f10","--color-line":"#1e2829","--color-hover":"#1a2425","--color-ink":"#f2f6f6","--color-ink2":"#c7d1d1","--color-muted":"#93a0a0","--color-muted2":"#7a8787","--color-border":"#5e6b6c","--color-soft":"#12363a","--color-soft2":"#17454a","--color-brand-ink":"#7dd3c0","--color-skeleton":"#2c3232","--color-amber":"#f8ac33","--color-amber-bg":"#2b2009","--color-amber-ink":"#f5c77a","--color-amber-line":"#5c4415","--color-green":"#6ecf9a","--color-green-bg":"#0d2119","--color-green-bg2":"#102a22","--color-green-line":"#245140","--color-violet":"#b9aeea","--color-violet-bg":"#1e1a33","--color-violet-line":"#38305c","--color-red":"#f3a79e","--color-red-bg":"#2c1613","--color-red-line":"#5c2a24","--color-code-chip":"#17201f","--shadow-color":"rgb(0 0 0 / 0.55)"};import{extendTailwindMerge}from"tailwind-merge";var twMerge=extendTailwindMerge({extend:{classGroups:{"font-size":[{text:TEXT_SCALE}],rounded:[{rounded:RADIUS_SCALE}],shadow:[{shadow:SHADOW_SCALE}],"max-w":[{"max-w":CONTAINER_SCALE}],animate:[{animate:ANIMATE_SCALE}]}}});function cn(...parts){return twMerge(parts.filter(p=>typeof p==="string"&&p.length>0).join(" "))}var TONE_SOFT={neutral:"bg-hover text-muted",brand:"bg-soft text-brand-ink",amber:"bg-amber-bg text-amber-ink",green:"bg-green-bg2 text-green",red:"bg-red-bg text-red",violet:"bg-violet-bg text-violet"};var TONE_SOLID={neutral:"bg-ink2 text-surface",brand:"bg-brand text-white",amber:"bg-amber text-amber-900",green:"bg-green-solid text-white",red:"bg-danger text-white",violet:"bg-violet-solid text-white"};function toLatinDigits(s){return s.replace(/[٠-٩۰-۹٫٬]/g,c=>{const code=c.charCodeAt(0);if(code===1643)return".";if(code===1644)return"";const base=code>=1776?1776:1632;return String(code-base)})}var VARIANTS={primary:"bg-brand border-brand text-white hover:bg-brand-hover",soft:"bg-soft border-soft2 text-brand-ink hover:bg-soft2",outline:"bg-surface border-border text-ink2 hover:border-brand hover:text-brand-ink",ghost:"bg-transparent border-transparent text-ink2 hover:bg-hover",danger:"bg-danger border-danger text-white hover:bg-danger-hover",link:"bg-transparent border-transparent text-brand-ink hover:underline underline-offset-4 px-0!"};var SIZES={sm:"h-9 px-3.5 gap-1.5 text-ui rounded-sm",md:"h-11 px-4 gap-2 text-body rounded-field",lg:"h-12 px-5 gap-2 text-lead rounded-card",xl:"h-14 px-5.5 gap-4 text-h3 font-extrabold rounded-field"};function buttonClasses(variant="primary",size="md",extra){return cn("inline-flex items-center justify-center border font-bold whitespace-nowrap","cursor-pointer transition-colors duration-150 select-none","focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand",SIZES[size],VARIANTS[variant],extra)}import{createContext,useCallback,useContext,useSyncExternalStore}from"react";var langStore={subscribe(cb){if(typeof MutationObserver==="undefined")return()=>{};const o=new MutationObserver(cb);o.observe(document.documentElement,{attributes:true,attributeFilter:["lang"]});return()=>o.disconnect()},get:()=>typeof document==="undefined"?"ar-EG":document.documentElement.lang||"ar-EG"};var LocaleCtx=createContext(null);function useMoneyLocale(){const fromProvider=useContext(LocaleCtx);const serverSnapshot=useCallback(()=>fromProvider??"ar-EG",[fromProvider]);return useSyncExternalStore(langStore.subscribe,langStore.get,serverSnapshot)}function useMoneyLang(){return useMoneyLocale().startsWith("en")}var AR=0;var EN=1;var TEXT={close:["\u0625\u063A\u0644\u0627\u0642","Close"],select:["\u0627\u062E\u062A\u0631\u2026","Select\u2026"],search:["\u0627\u0628\u062D\u062B\u2026","Search\u2026"],searchEverything:["\u0627\u0628\u062D\u062B \u0641\u064A \u0643\u0644 \u062D\u0627\u062C\u0629\u2026","Search everything\u2026"],noResults:["\u0645\u0627\u0641\u064A\u0634 \u0646\u062A\u0627\u064A\u062C","No results"],searchOrAdd:["\u0627\u0628\u062D\u062B \u0623\u0648 \u0623\u0636\u0641\u2026","Search or add\u2026"],now:["\u0627\u0644\u0622\u0646","Now"],videoPlayer:["\u0645\u0634\u063A\u0651\u0644 \u0627\u0644\u0641\u064A\u062F\u064A\u0648","Video player"],rating:["\u0627\u0644\u062A\u0642\u064A\u064A\u0645","Rating"],activeFilters:["\u0627\u0644\u0641\u0644\u0627\u062A\u0631 \u0627\u0644\u0645\u0637\u0628\u0651\u0642\u0629:","Active filters:"],clearAll:["\u0645\u0633\u062D \u0627\u0644\u0643\u0644","Clear all"],row:["\u0635\u0641\u0651","row"],dropImages:["\u0627\u0633\u062D\u0628 \u0627\u0644\u0635\u0648\u0631 \u0647\u0646\u0627","Drop images here"],chooseFromDevice:["\u0627\u062E\u062A\u0631 \u0645\u0646 \u0627\u0644\u062C\u0647\u0627\u0632","Choose from device"],previousPeriod:["\u0627\u0644\u0641\u062A\u0631\u0629 \u0627\u0644\u0633\u0627\u0628\u0642\u0629","Previous period"],less:["\u0623\u0642\u0644","Less"],more:["\u0623\u0643\u062B\u0631","More"],totalSales:["\u0625\u062C\u0645\u0627\u0644\u064A \u0627\u0644\u0645\u0628\u064A\u0639\u0627\u062A","Total sales"],netToYou:["\u0635\u0627\u0641\u064A \u0644\u0643","Net to you"],verifiedAccount:["\u062D\u0633\u0627\u0628 \u0645\u0648\u062B\u0651\u0642","Verified account"],grabHint:["\u0639\u0646\u0635\u0631 \u0642\u0627\u0628\u0644 \u0644\u0625\u0639\u0627\u062F\u0629 \u0627\u0644\u062A\u0631\u062A\u064A\u0628. \u0627\u0636\u063A\u0637 \u0645\u0633\u0627\u0641\u0629 \u0644\u0645\u0633\u0643\u0647 \u062B\u0645 \u0627\u0644\u0623\u0633\u0647\u0645 \u0644\u062A\u062D\u0631\u064A\u0643\u0647.","Reorderable item. Press space to grab it, then the arrows to move it."],notifications:["\u0627\u0644\u0625\u0634\u0639\u0627\u0631\u0627\u062A","Notifications"],dismiss:["\u0625\u062E\u0641\u0627\u0621","Dismiss"],unread:["\u063A\u064A\u0631 \u0645\u0642\u0631\u0648\u0621","Unread"],noNotifications:["\u0645\u0641\u064A\u0634 \u0625\u0634\u0639\u0627\u0631\u0627\u062A","No notifications"],noNotificationsDesc:["\u0623\u0648\u0644 \u0645\u0627 \u064A\u062D\u0635\u0644 \u062D\u0627\u062C\u0629 \u062A\u0633\u062A\u0627\u0647\u0644\u060C \u0647\u062A\u0644\u0627\u0642\u064A\u0647\u0627 \u0647\u0646\u0627.","When something worth knowing happens, it lands here."],markAllRead:["\u062A\u0639\u0644\u064A\u0645 \u0627\u0644\u0643\u0644 \u0643\u0645\u0642\u0631\u0648\u0621","Mark all as read"],viewAllNotifications:["\u0639\u0631\u0636 \u0643\u0644 \u0627\u0644\u0625\u0634\u0639\u0627\u0631\u0627\u062A","View all notifications"],newNotifications:["\u0625\u0634\u0639\u0627\u0631\u0627\u062A \u062C\u062F\u064A\u062F\u0629","New notifications"],reloadPreview:["\u0625\u0639\u0627\u062F\u0629 \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u0639\u0627\u064A\u0646\u0629","Reload preview"],previousMonth:["\u0627\u0644\u0634\u0647\u0631 \u0627\u0644\u0644\u064A \u0642\u0628\u0644\u0647","Previous month"],nextMonth:["\u0627\u0644\u0634\u0647\u0631 \u0627\u0644\u0644\u064A \u0628\u0639\u062F\u0647","Next month"],whatIsThisNumber:["\u0645\u0627 \u0645\u0639\u0646\u0649 \u0647\u0630\u0627 \u0627\u0644\u0631\u0642\u0645\u061F","What does this number mean?"],explainToMe:["\u0627\u0634\u0631\u062D \u0644\u064A","Explain this"],clearSearch:["\u0645\u0633\u062D \u0627\u0644\u0628\u062D\u062B","Clear search"],alerts:["\u0627\u0644\u062A\u0646\u0628\u064A\u0647\u0627\u062A","Alerts"],whatIsThisOption:["\u0645\u0627 \u0647\u0630\u0627 \u0627\u0644\u062E\u064A\u0627\u0631\u061F","What is this option?"],shouldBeHere:["\u0627\u0644\u0645\u0641\u0631\u0648\u0636 \u062A\u0643\u0648\u0646 \u0647\u0646\u0627","Should be here"],closeExplainer:["\u0625\u063A\u0644\u0627\u0642 \u0627\u0644\u0634\u0631\u062D","Close explainer"],cancelRecording:["\u0625\u0644\u063A\u0627\u0621 \u0627\u0644\u062A\u0633\u062C\u064A\u0644","Cancel recording"],sendRecording:["\u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u062A\u0633\u062C\u064A\u0644","Send recording"],attachFile:["\u0625\u0631\u0641\u0627\u0642 \u0645\u0644\u0641","Attach file"],recordVoice:["\u062A\u0633\u062C\u064A\u0644 \u0635\u0648\u062A\u064A","Record a voice note"],playbackPosition:["\u0645\u0648\u0636\u0639 \u0627\u0644\u062A\u0634\u063A\u064A\u0644","Playback position"],volume:["\u0645\u0633\u062A\u0648\u0649 \u0627\u0644\u0635\u0648\u062A","Volume"],hideSuggestions:["\u0625\u062E\u0641\u0627\u0621 \u0627\u0644\u0627\u0642\u062A\u0631\u0627\u062D\u0627\u062A","Hide suggestions"],askShehab:["\u0627\u0633\u0623\u0644 \u0634\u0647\u0627\u0628\u2026","Ask Shehab\u2026"],shehabThinking:["\u0634\u0647\u0627\u0628 \u0628\u064A\u0641\u0643\u0651\u0631\u2026","Shehab is thinking\u2026"],undo:["\u062A\u0631\u0627\u062C\u0639","Undo"],from:["\u0645\u0646","from"],tryAnotherReply:["\u062C\u0631\u0651\u0628 \u0631\u062F \u062A\u0627\u0646\u064A","Try another reply"],helpfulReply:["\u0631\u062F \u0645\u0641\u064A\u062F","Helpful reply"],unhelpfulReply:["\u0631\u062F \u0645\u0634 \u0645\u0641\u064A\u062F","Unhelpful reply"],aiDisclaimer:["\u0634\u0647\u0627\u0628 \u0645\u0645\u0643\u0646 \u064A\u063A\u0644\u0637. \u0631\u0627\u062C\u0639 \u0627\u0644\u0623\u0631\u0642\u0627\u0645 \u0642\u0628\u0644 \u0645\u0627 \u062A\u062A\u0635\u0631\u0651\u0641 \u0639\u0644\u064A\u0647\u0627.","Shehab can get things wrong. Check the numbers before acting on them."],back10:["\u0631\u062C\u0648\u0639 \u0661\u0660 \u062B\u0648\u0627\u0646\u064A","Back 10 seconds"],forward10:["\u062A\u0642\u062F\u064A\u0645 \u0661\u0660 \u062B\u0648\u0627\u0646\u064A","Forward 10 seconds"],playbackSpeed:["\u0633\u0631\u0639\u0629 \u0627\u0644\u062A\u0634\u063A\u064A\u0644","Playback speed"],arabic:["\u0627\u0644\u0639\u0631\u0628\u064A\u0629","Arabic"],seeMore:["\u0634\u0648\u0641 \u0643\u0645\u0627\u0646","See more"],pictureInPicture:["\u0646\u0627\u0641\u0630\u0629 \u0639\u0627\u0626\u0645\u0629","Picture in picture"]};function useUIText(){return useMoneyLang()?BUNDLES[EN]:BUNDLES[AR]}function build(i){const out={};for(const key of Object.keys(TEXT))out[key]=TEXT[key][i];return out}var BUNDLES=[build(AR),build(EN)];import{useEffect,useId}from"react";import{AlertTriangle,CheckCircle2,Info,X,XCircle}from"lucide-react";import{jsx,jsxs}from"react/jsx-runtime";function Sheet({open,title,onClose,action,children,closeLabel}){const ui=useUIText();useEffect(()=>{if(!open)return;function onKey(e){if(e.key==="Escape")onClose()}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,onClose]);if(!open)return null;return jsxs("div",{className:"fixed inset-0 z-50 flex flex-col justify-end",role:"dialog","aria-modal":"true","aria-label":title,children:[jsx("button",{type:"button","aria-label":closeLabel??ui.close,onClick:onClose,className:"flex-1 bg-black/50 backdrop-blur-[3px] cursor-default animate-[fade-in_0.2s_ease-out]"}),jsxs("div",{className:cn("bg-surface rounded-t-section max-h-[82dvh] flex flex-col overflow-clip shadow-sheet","animate-[sheet-up_0.26s_cubic-bezier(.22,.61,.36,1)]","pb-[env(safe-area-inset-bottom)]"),children:[jsx("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:"shrink-0 pt-3 pb-1.5 flex justify-center cursor-grab active:cursor-grabbing",children:jsx("span",{"aria-hidden":"true",className:"h-1.5 w-11 rounded-full bg-border"})}),jsxs("div",{className:"shrink-0 flex items-center justify-between gap-3 px-5 pb-3",children:[jsx("span",{className:"text-h4 font-black tracking-tight",children:title}),jsxs("span",{className:"flex items-center gap-3",children:[action,jsx("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:"size-9 rounded-full bg-bg flex items-center justify-center text-muted active:bg-hover active:scale-95 transition-transform cursor-pointer",children:jsx(X,{size:17,strokeWidth:2.4,"aria-hidden":"true"})})]})]}),jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-3 pb-4 flex flex-col overscroll-contain",children})]})]})}function Modal({open,title,description,onClose,footer,children,size="md",closeLabel}){const ui=useUIText();const titleId=useId();useEffect(()=>{if(!open)return;function onKey(e){if(e.key==="Escape")onClose()}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,onClose]);if(!open)return null;const widths={sm:"max-w-md",md:"max-w-xl",lg:"max-w-3xl"};return jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",role:"dialog","aria-modal":"true","aria-labelledby":titleId,children:[jsx("button",{type:"button","aria-label":closeLabel??ui.close,onClick:onClose,className:"absolute inset-0 bg-black/45 backdrop-blur-[2px] cursor-default"}),jsxs("div",{className:cn("relative w-full bg-surface rounded-lg border border-line flex flex-col max-h-[85dvh] animate-qfade shadow-modal",widths[size]),children:[jsxs("header",{className:"shrink-0 flex items-start justify-between gap-4 p-5 border-b border-line",children:[jsxs("div",{className:"flex flex-col gap-1 min-w-0",children:[jsx("h2",{id:titleId,className:"text-h4 font-extrabold text-ink m-0",children:title}),description&&jsx("p",{className:"text-ui text-muted m-0",children:description})]}),jsx("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:"shrink-0 size-8 rounded-sm flex items-center justify-center text-muted hover:bg-hover hover:text-ink transition-colors cursor-pointer",children:jsx(X,{size:17,"aria-hidden":"true"})})]}),children&&jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-5",children}),footer&&jsx("footer",{className:"shrink-0 flex items-center justify-end gap-2.5 p-5 border-t border-line",children:footer})]})]})}function Drawer({open,title,description,onClose,footer,children,bodyClassName,closeLabel}){const ui=useUIText();const titleId=useId();useEffect(()=>{if(!open)return;function onKey(e){if(e.key==="Escape")onClose()}document.addEventListener("keydown",onKey);return()=>document.removeEventListener("keydown",onKey)},[open,onClose]);if(!open)return null;return jsxs("div",{className:"fixed inset-0 z-50 flex",role:"dialog","aria-modal":"true","aria-labelledby":titleId,children:[jsx("button",{type:"button","aria-label":closeLabel??ui.close,onClick:onClose,className:"flex-1 bg-black/45 backdrop-blur-[2px] cursor-default"}),jsxs("aside",{className:"w-full sm:w-[420px] bg-surface border-s border-line flex flex-col animate-qfade",children:[jsxs("header",{className:"shrink-0 h-16 px-4 border-b border-line flex items-center justify-between gap-3",children:[jsxs("span",{className:"flex flex-col gap-0.5 min-w-0",children:[jsx("span",{id:titleId,className:"text-lead font-extrabold truncate",children:title}),description&&jsx("span",{className:"text-caption text-muted truncate",children:description})]}),jsx("button",{type:"button",onClick:onClose,"aria-label":closeLabel??ui.close,className:"shrink-0 size-8 rounded-sm flex items-center justify-center text-muted hover:bg-hover hover:text-ink transition-colors cursor-pointer",children:jsx(X,{size:17,"aria-hidden":"true"})})]}),children&&jsx("div",{className:cn("flex-1 min-h-0 overflow-y-auto",bodyClassName??"p-4"),children}),footer&&jsx("footer",{className:"shrink-0 p-4 border-t border-line flex gap-2.5",children:footer})]})]})}var ALERT_ICON={neutral:Info,brand:Info,amber:AlertTriangle,green:CheckCircle2,red:XCircle,violet:Info};var ALERT_BORDER={neutral:"border-line",brand:"border-soft2",amber:"border-amber-line",green:"border-green-line",red:"border-red-line",violet:"border-violet-line"};function Alert({tone="brand",title,children,actions}){const Icon=ALERT_ICON[tone];const urgent=tone==="red"||tone==="amber";return jsxs("div",{role:urgent?"alert":"status",className:cn("flex items-start gap-3 p-4 rounded-card border",TONE_SOFT[tone],ALERT_BORDER[tone]),children:[jsx(Icon,{size:18,strokeWidth:2,"aria-hidden":"true"}),jsxs("div",{className:"flex flex-col gap-1.5 flex-1 min-w-0",children:[title&&jsx("span",{className:"text-body font-extrabold",children:title}),children&&jsx("span",{className:"text-ui leading-[1.7] opacity-90 [text-wrap:pretty]",children}),actions&&jsx("span",{className:"flex items-center gap-2 mt-1",children:actions})]})]})}function Toast({children,action,icon}){return jsxs("div",{role:"status","aria-live":"polite",className:"flex items-center gap-3 px-4 py-3.5 rounded-card bg-brand-900 shadow-toast animate-[fade-in_0.18s_ease-out]",children:[icon??jsx(CheckCircle2,{size:17,className:"text-brand-100 shrink-0","aria-hidden":"true"}),jsx("span",{className:"text-body font-bold text-white flex-1",children}),action]})}function EmptyState({icon:Icon,title,description,action}){return jsxs("div",{className:"flex flex-col items-center justify-center gap-2.5 py-12 px-5 text-center",children:[Icon&&jsx("span",{"aria-hidden":"true",className:"size-12 rounded-card bg-hover flex items-center justify-center text-muted mb-1",children:jsx(Icon,{size:21})}),jsx("span",{className:"text-lead font-extrabold text-ink",children:title}),description&&jsx("span",{className:"text-ui leading-[1.75] text-muted max-w-note [text-wrap:pretty]",children:description}),action&&jsx("span",{className:"mt-1",children:action})]})}export{TEXT_SCALE,RADIUS_SCALE,SHADOW_SCALE,CONTAINER_SCALE,ANIMATE_SCALE,COLOR_SCALE,TOKENS,DARK_TOKENS,cn,TONE_SOFT,TONE_SOLID,toLatinDigits,buttonClasses,LocaleCtx,useMoneyLocale,useMoneyLang,useUIText,Sheet,Modal,Drawer,Alert,Toast,EmptyState};
package/dist/editor.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{Tooltip}from"./chunk-3EPEIAG2.js";import{Button,Input}from"./chunk-K3TNXSD7.js";import{Modal,cn}from"./chunk-6DTSIOCB.js";import{useEffect as useEffect4,useMemo as useMemo2,useRef as useRef4,useState as useState6}from"react";import{EditorProvider,useCurrentEditor as useCurrentEditor6}from"@tiptap/react";import{CharacterCount as CharacterCount2}from"@tiptap/extension-character-count";import Dropcursor from"@tiptap/extension-dropcursor";import{Placeholder}from"@tiptap/extension-placeholder";import StarterKit from"@tiptap/starter-kit";import{Color}from"@tiptap/extension-color";import{Highlight}from"@tiptap/extension-highlight";import Image from"@tiptap/extension-image";import Link from"@tiptap/extension-link";import ListItem from"@tiptap/extension-list-item";import{Table}from"@tiptap/extension-table";import{TableCell}from"@tiptap/extension-table-cell";import{TableHeader}from"@tiptap/extension-table-header";import{TableRow}from"@tiptap/extension-table-row";import TextAlign from"@tiptap/extension-text-align";import{TextStyle}from"@tiptap/extension-text-style";import Underline from"@tiptap/extension-underline";import ImageResize from"tiptap-extension-resize-image";import TextDirection from"tiptap-text-direction";function contentExtensions(){return[StarterKit.configure({bulletList:{keepMarks:true,keepAttributes:false},orderedList:{keepMarks:true,keepAttributes:false}}),TextDirection.configure({types:["heading","paragraph"],defaultDirection:"rtl"}),TextAlign.configure({types:["heading","paragraph"]}),TextStyle,Color.configure({types:[TextStyle.name,ListItem.name]}),Underline,Highlight.configure({multicolor:true}),Link.configure({openOnClick:false,autolink:true,defaultProtocol:"https"}),Image.configure({inline:true}),ImageResize.configure(),Table.configure({resizable:true}),TableRow,TableHeader,TableCell]}import{useCallback,useId,useMemo,useRef}from"react";import{useCurrentEditor}from"@tiptap/react";import{BubbleMenu}from"@tiptap/react/menus";import{PluginKey}from"@tiptap/pm/state";import{Bold,Code,Highlighter,Italic,Link2,Strikethrough,Underline as Underline2}from"lucide-react";import{jsx,jsxs}from"react/jsx-runtime";function BubbleButton({onClick,isActive,label,children}){return jsx("button",{type:"button",onClick,"aria-label":label,"aria-pressed":isActive,className:cn("size-7 rounded-xs inline-flex items-center justify-center cursor-pointer transition-colors",isActive?"bg-brand text-white":"text-ink2 hover:bg-hover hover:text-ink"),children})}function EditorBubbleMenu(){const{editor}=useCurrentEditor();const key=useId();const pluginKey=useMemo(()=>new PluginKey(`qumraBubble${key}`),[key]);const menuRef=useRef(null);const onShow=useCallback(()=>{const el=menuRef.current;if(el)el.style.opacity="0"},[]);const onUpdate=useCallback(()=>{const el=menuRef.current;if(el)el.style.opacity="1"},[]);const scrollTarget=useMemo(()=>{if(typeof window==="undefined")return void 0;const dom=editor?.view?.dom;let node=dom?.parentElement??null;while(node){const{overflowY}=getComputedStyle(node);if(overflowY==="auto"||overflowY==="scroll")return node;node=node.parentElement}return void 0},[editor]);if(!editor)return null;const e=editor;return jsx(BubbleMenu,{editor,pluginKey,ref:el=>{menuRef.current=el},options:{placement:"top",offset:8,...scrollTarget?{scrollTarget}:{},onShow,onUpdate},shouldShow:({editor:ed,from,to})=>{if(from===to)return false;if(ed.isActive("image")||ed.isActive("codeBlock"))return false;return true},children:jsxs("div",{className:"flex items-center gap-0.5 p-1 rounded-card border border-line bg-surface shadow-pop",children:[jsx(BubbleButton,{label:"\u0639\u0631\u064A\u0636",onClick:()=>e.chain().focus().toggleBold().run(),isActive:e.isActive("bold"),children:jsx(Bold,{size:14})}),jsx(BubbleButton,{label:"\u0645\u0627\u0626\u0644",onClick:()=>e.chain().focus().toggleItalic().run(),isActive:e.isActive("italic"),children:jsx(Italic,{size:14})}),jsx(BubbleButton,{label:"\u062A\u062D\u062A\u0647 \u062E\u0637",onClick:()=>e.chain().focus().toggleUnderline().run(),isActive:e.isActive("underline"),children:jsx(Underline2,{size:14})}),jsx(BubbleButton,{label:"\u064A\u062A\u0634\u0637\u0628",onClick:()=>e.chain().focus().toggleStrike().run(),isActive:e.isActive("strike"),children:jsx(Strikethrough,{size:14})}),jsx("span",{"aria-hidden":"true",className:"w-px h-5 bg-line mx-0.5"}),jsx(BubbleButton,{label:"\u0643\u0648\u062F",onClick:()=>e.chain().focus().toggleCode().run(),isActive:e.isActive("code"),children:jsx(Code,{size:14})}),jsx(BubbleButton,{label:"\u062A\u0638\u0644\u064A\u0644",onClick:()=>e.chain().focus().toggleHighlight().run(),isActive:e.isActive("highlight"),children:jsx(Highlighter,{size:14})}),jsx("span",{"aria-hidden":"true",className:"w-px h-5 bg-line mx-0.5"}),jsx(BubbleButton,{label:"\u0631\u0627\u0628\u0637",isActive:e.isActive("link"),onClick:()=>{const previous=e.getAttributes("link").href||"";const url=window.prompt("\u0631\u0627\u0628\u0637",previous);if(url===null)return;const chain=e.chain().focus().extendMarkRange("link");if(url==="")chain.unsetLink().run();else chain.setLink({href:/^https?:\/\//i.test(url)?url:`https://${url}`}).run()},children:jsx(Link2,{size:14})})]})})}import{useEffect as useEffect2,useRef as useRef3,useState as useState4}from"react";import{useCurrentEditor as useCurrentEditor5}from"@tiptap/react";import{useEffect,useRef as useRef2,useState}from"react";import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function useDismiss(open,close){const ref=useRef2(null);useEffect(()=>{if(!open)return;function onDown(e){if(ref.current&&!ref.current.contains(e.target))close()}function onKey(e){if(e.key==="Escape")close()}document.addEventListener("mousedown",onDown);document.addEventListener("keydown",onKey);return()=>{document.removeEventListener("mousedown",onDown);document.removeEventListener("keydown",onKey)}},[open,close]);return ref}var PANEL="absolute z-50 top-[calc(100%+6px)] start-0 bg-surface border border-line rounded-card shadow-panel overflow-clip animate-[fade-in_.14s_ease-out]";function Popover({trigger,children,width,className}){const[open,setOpen]=useState(false);const ref=useDismiss(open,()=>setOpen(false));return jsxs2("div",{ref,className:cn("relative flex",className),children:[trigger({open,toggle:()=>setOpen(v=>!v)}),open&&jsx2("div",{className:cn(PANEL,width??"w-56"),children:children({close:()=>setOpen(false)})})]})}function MenuItem({onClick,icon,children,danger,active}){return jsxs2("button",{type:"button",onClick,className:cn("w-full px-3 py-2 flex items-center gap-2.5 text-start text-ui cursor-pointer transition-colors",danger?"text-red hover:bg-red-bg":"text-ink2 hover:bg-hover",active&&"bg-soft text-brand-ink font-bold"),children:[icon,jsx2("span",{className:"flex-1 min-w-0 truncate",children})]})}function MenuSeparator(){return jsx2("span",{"aria-hidden":"true",className:"block h-px bg-line my-1"})}function ToolbarButton({onClick,isActive,disabled,tooltip,shortcut,children}){return jsx2(Tooltip,{content:jsxs2("span",{className:"flex items-center gap-2",children:[tooltip,shortcut&&jsx2("kbd",{dir:"ltr",className:"px-1 py-px rounded-xs bg-white/15 text-micro font-mono",children:shortcut})]}),children:jsx2("button",{type:"button",onClick,disabled,"aria-label":tooltip,"aria-pressed":isActive,className:cn("size-8 rounded-sm inline-flex items-center justify-center shrink-0 cursor-pointer transition-colors","focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand","disabled:opacity-40 disabled:cursor-not-allowed",isActive?"bg-soft text-brand-ink":"text-muted hover:bg-hover hover:text-ink"),children})})}function ToolbarGroup({children}){return jsx2("div",{className:"flex items-center gap-0.5 pe-1 me-1 border-e border-line last:border-e-0 last:pe-0 last:me-0",children})}function ColorGrid({colors,current,onPick,onClear,clearLabel,fallback}){return jsxs2("div",{className:"p-3 flex flex-col gap-2.5",children:[jsx2("div",{className:"grid grid-cols-4 gap-1.5",children:colors.map(color=>jsx2("button",{type:"button",onClick:()=>onPick(color),"aria-label":color,style:{background:color},className:cn("size-8 rounded-sm border cursor-pointer transition-transform hover:scale-110",current.toLowerCase()===color.toLowerCase()?"border-ink ring-2 ring-brand":"border-line")},color))}),jsxs2("div",{className:"flex items-center gap-2.5 pt-2.5 border-t border-line",children:[jsx2("input",{type:"color",value:current||fallback,onChange:e=>onPick(e.target.value),"aria-label":"\u0644\u0648\u0646 \u0645\u062E\u0635\u0651\u0635",className:"size-8 p-0 border-none bg-transparent cursor-pointer"}),jsx2("button",{type:"button",onClick:onClear,className:"text-caption text-muted hover:text-ink cursor-pointer transition-colors",children:clearLabel})]})]})}import{useCurrentEditor as useCurrentEditor2}from"@tiptap/react";import{AlignCenter,AlignLeft,AlignRight,Bold as BoldIcon,Code as CodeIcon,Eraser,Italic as ItalicIcon,List,ListOrdered,Minus,Quote,Redo,Strikethrough as StrikeIcon,Underline as UnderlineIcon,Undo}from"lucide-react";import{Fragment,jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";function Bold2(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleBold().run(),isActive:editor.isActive("bold"),tooltip:"\u0639\u0631\u064A\u0636",shortcut:"Ctrl+B",children:jsx3(BoldIcon,{size:16})})}function Italic2(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleItalic().run(),isActive:editor.isActive("italic"),tooltip:"\u0645\u0627\u0626\u0644",shortcut:"Ctrl+I",children:jsx3(ItalicIcon,{size:16})})}function Underline3(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleUnderline().run(),isActive:editor.isActive("underline"),tooltip:"\u062A\u062D\u062A\u0647 \u062E\u0637",shortcut:"Ctrl+U",children:jsx3(UnderlineIcon,{size:16})})}function Strikethrough2(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleStrike().run(),isActive:editor.isActive("strike"),tooltip:"\u064A\u062A\u0634\u0637\u0628",shortcut:"Ctrl+Shift+S",children:jsx3(StrikeIcon,{size:16})})}function Code2(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleCode().run(),isActive:editor.isActive("code"),tooltip:"\u0643\u0648\u062F",shortcut:"Ctrl+E",children:jsx3(CodeIcon,{size:16})})}function BulletList(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleBulletList().run(),isActive:editor.isActive("bulletList"),tooltip:"\u0642\u0627\u0626\u0645\u0629 \u0646\u0642\u0637\u064A\u0629",shortcut:"Ctrl+Shift+8",children:jsx3(List,{size:16})})}function OrderedList(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleOrderedList().run(),isActive:editor.isActive("orderedList"),tooltip:"\u0642\u0627\u0626\u0645\u0629 \u0645\u0631\u0642\u0651\u0645\u0629",shortcut:"Ctrl+Shift+7",children:jsx3(ListOrdered,{size:16})})}function BlockQuote(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleBlockquote().run(),isActive:editor.isActive("blockquote"),tooltip:"\u0627\u0642\u062A\u0628\u0627\u0633",shortcut:"Ctrl+Shift+B",children:jsx3(Quote,{size:16})})}function HorizontalRule(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().setHorizontalRule().run(),tooltip:"\u0641\u0627\u0635\u0644 \u0623\u0641\u0642\u064A",children:jsx3(Minus,{size:16})})}function ClearMarks(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().unsetAllMarks().run(),tooltip:"\u0645\u0633\u062D \u0627\u0644\u062A\u0646\u0633\u064A\u0642",children:jsx3(Eraser,{size:16})})}function UndoRedo(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsxs3(Fragment,{children:[jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().undo().run(),disabled:!editor.can().chain().focus().undo().run(),tooltip:"\u062A\u0631\u0627\u062C\u0639",shortcut:"Ctrl+Z",children:jsx3(Undo,{size:16})}),jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().redo().run(),disabled:!editor.can().chain().focus().redo().run(),tooltip:"\u0625\u0639\u0627\u062F\u0629",shortcut:"Ctrl+Y",children:jsx3(Redo,{size:16})})]})}function Alignment(){const{editor}=useCurrentEditor2();if(!editor)return null;const items=[{key:"right",tooltip:"\u0645\u062D\u0627\u0630\u0627\u0629 \u064A\u0645\u064A\u0646",Icon:AlignRight},{key:"center",tooltip:"\u062A\u0648\u0633\u064A\u0637",Icon:AlignCenter},{key:"left",tooltip:"\u0645\u062D\u0627\u0630\u0627\u0629 \u0634\u0645\u0627\u0644",Icon:AlignLeft}];return jsx3(Fragment,{children:items.map(({key,tooltip,Icon})=>jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().setTextAlign(key).run(),isActive:editor.isActive({textAlign:key}),disabled:!editor.can().chain().focus().setTextAlign(key).run(),tooltip,children:jsx3(Icon,{size:16})},key))})}function CharacterCount({maxChars}){const{editor}=useCurrentEditor2();if(!editor)return null;const chars=editor.storage.characterCount?.characters()??0;const words=editor.storage.characterCount?.words()??0;const over=maxChars?chars>maxChars:false;const near=maxChars?chars>maxChars*.9:false;return jsxs3("span",{className:cn("flex items-center gap-2 text-caption select-none",over?"text-red font-bold":near?"text-amber-ink font-bold":"text-muted2"),children:[jsxs3("span",{"data-num":true,children:[chars,maxChars?`/${maxChars}`:""," \u062D\u0631\u0641"]}),jsx3("span",{"aria-hidden":"true",className:"text-line",children:"|"}),jsxs3("span",{"data-num":true,children:[words," \u0643\u0644\u0645\u0629"]})]})}import{useState as useState2}from"react";import{useCurrentEditor as useCurrentEditor3}from"@tiptap/react";import{CalendarClock,ChevronDown,Columns,Highlighter as Highlighter2,Image as ImageIcon,Link2 as Link22,Merge,Palette,Plus,Rows,Split,Table as TableIcon,Trash2}from"lucide-react";import{Fragment as Fragment2,jsx as jsx4,jsxs as jsxs4}from"react/jsx-runtime";var HEADINGS=[{level:0,label:"\u0646\u0635 \u0639\u0627\u062F\u064A",size:"text-body"},{level:1,label:"\u0639\u0646\u0648\u0627\u0646 \u0661",size:"text-h2"},{level:2,label:"\u0639\u0646\u0648\u0627\u0646 \u0662",size:"text-h3"},{level:3,label:"\u0639\u0646\u0648\u0627\u0646 \u0663",size:"text-h4"},{level:4,label:"\u0639\u0646\u0648\u0627\u0646 \u0664",size:"text-lead"},{level:5,label:"\u0639\u0646\u0648\u0627\u0646 \u0665",size:"text-body"},{level:6,label:"\u0639\u0646\u0648\u0627\u0646 \u0666",size:"text-ui"}];function HeadingSelector(){const{editor}=useCurrentEditor3();if(!editor)return null;const current=HEADINGS.find(h=>h.level===0?editor.isActive("paragraph"):editor.isActive("heading",{level:h.level}))??HEADINGS[0];return jsx4(Popover,{width:"w-48",trigger:({open,toggle})=>jsxs4("button",{type:"button",onClick:toggle,"aria-haspopup":"menu","aria-expanded":open,className:cn("h-8 px-2.5 rounded-sm inline-flex items-center gap-1.5 text-ui font-bold cursor-pointer transition-colors","focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand",open?"bg-soft text-brand-ink":"text-ink2 hover:bg-hover"),children:[jsx4("span",{className:"truncate max-w-24",children:current.label}),jsx4(ChevronDown,{size:14,className:cn("shrink-0 transition-transform",open&&"rotate-180")})]}),children:({close})=>jsx4("div",{role:"menu",className:"py-1",children:HEADINGS.map(h=>{const active=h.level===0?editor.isActive("paragraph"):editor.isActive("heading",{level:h.level});return jsx4("button",{type:"button",role:"menuitem",onClick:()=>{if(h.level===0)editor.chain().focus().setParagraph().run();else editor.chain().focus().toggleHeading({level:h.level}).run();close()},className:cn("w-full px-3 py-2 flex items-center justify-between gap-3 text-start cursor-pointer transition-colors",active?"bg-soft text-brand-ink":"text-ink2 hover:bg-hover"),children:jsx4("span",{className:cn(h.size,active?"font-extrabold":"font-bold"),children:h.label})},h.level)})})})}function normalizeUrl(url){const t=url.trim();if(!t)return"";if(/^(https?:\/\/|mailto:|#)/i.test(t))return t;return`https://${t}`}function Link3(){const{editor}=useCurrentEditor3();const[open,setOpen]=useState2(false);const[url,setUrl]=useState2("");if(!editor)return null;function apply(){const chain=editor.chain().focus().extendMarkRange("link");if(url.trim()==="")chain.unsetLink().run();else chain.setLink({href:normalizeUrl(url)}).run();setOpen(false)}return jsxs4(Fragment2,{children:[jsx4(ToolbarButton,{onClick:()=>{setUrl(editor.getAttributes("link").href||"");setOpen(true)},isActive:editor.isActive("link"),tooltip:"\u0631\u0627\u0628\u0637",shortcut:"Ctrl+K",children:jsx4(Link22,{size:16})}),jsx4(Modal,{open,onClose:()=>setOpen(false),title:"\u0625\u0636\u0627\u0641\u0629 \u0631\u0627\u0628\u0637",description:"\u0633\u064A\u0628\u0647 \u0641\u0627\u0636\u064A \u0648\u0627\u0645\u0633\u062D \u0639\u0634\u0627\u0646 \u062A\u0634\u064A\u0644 \u0627\u0644\u0631\u0627\u0628\u0637.",size:"sm",footer:jsxs4(Fragment2,{children:[jsx4(Button,{variant:"outline",onClick:()=>setOpen(false),children:"\u0625\u0644\u063A\u0627\u0621"}),jsx4(Button,{onClick:apply,children:url.trim()?"\u0623\u0636\u0641":"\u0634\u064A\u0644 \u0627\u0644\u0631\u0627\u0628\u0637"})]}),children:jsx4(Input,{label:"\u0627\u0644\u0639\u0646\u0648\u0627\u0646",dir:"ltr",placeholder:"example.com",value:url,onChange:e=>setUrl(e.target.value),onKeyDown:e=>e.key==="Enter"&&apply()})})]})}function ImageTool({onPick}){const{editor}=useCurrentEditor3();const[open,setOpen]=useState2(false);const[src,setSrc]=useState2("");if(!editor)return null;const insert=url=>editor.chain().focus().setImage({src:url}).run();return jsxs4(Fragment2,{children:[jsx4(ToolbarButton,{onClick:()=>onPick?onPick(insert):setOpen(true),isActive:editor.isActive("image"),tooltip:"\u0635\u0648\u0631\u0629",children:jsx4(ImageIcon,{size:16})}),!onPick&&jsx4(Modal,{open,onClose:()=>setOpen(false),title:"\u0625\u062F\u0631\u0627\u062C \u0635\u0648\u0631\u0629",size:"sm",footer:jsxs4(Fragment2,{children:[jsx4(Button,{variant:"outline",onClick:()=>setOpen(false),children:"\u0625\u0644\u063A\u0627\u0621"}),jsx4(Button,{disabled:!src.trim(),onClick:()=>{insert(src.trim());setSrc("");setOpen(false)},children:"\u0623\u062F\u0631\u062C"})]}),children:jsx4(Input,{label:"\u0631\u0627\u0628\u0637 \u0627\u0644\u0635\u0648\u0631\u0629",dir:"ltr",placeholder:"https://\u2026",value:src,onChange:e=>setSrc(e.target.value),hint:"\u0648\u062A\u0642\u062F\u0631 \u0643\u0645\u0627\u0646 \u062A\u0633\u062D\u0628 \u0635\u0648\u0631\u0629 \u0648\u062A\u0641\u0644\u062A\u0647\u0627 \u062C\u0648\u0651\u0647 \u0627\u0644\u0645\u062D\u0631\u0631 \u0645\u0628\u0627\u0634\u0631\u0629\u064B."})})]})}function TableTool(){const{editor}=useCurrentEditor3();if(!editor)return null;const inTable=editor.isActive("table");return jsx4(Popover,{width:"w-56",trigger:({open,toggle})=>jsx4(ToolbarButton,{onClick:toggle,isActive:inTable||open,tooltip:"\u062C\u062F\u0648\u0644",children:jsx4(TableIcon,{size:16})}),children:({close})=>{const run=fn=>()=>{fn();close()};return jsxs4("div",{role:"menu",className:"py-1",children:[jsx4(MenuItem,{icon:jsx4(Plus,{size:14}),onClick:run(()=>editor.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:true}).run()),children:"\u0623\u062F\u0631\u062C \u062C\u062F\u0648\u0644 \u0663\xD7\u0663"}),inTable&&jsxs4(Fragment2,{children:[jsx4(MenuSeparator,{}),jsx4(MenuItem,{icon:jsx4(Rows,{size:14}),onClick:run(()=>editor.chain().focus().addRowBefore().run()),children:"\u0635\u0641 \u0642\u0628\u0644"}),jsx4(MenuItem,{icon:jsx4(Rows,{size:14}),onClick:run(()=>editor.chain().focus().addRowAfter().run()),children:"\u0635\u0641 \u0628\u0639\u062F"}),jsx4(MenuItem,{danger:true,icon:jsx4(Trash2,{size:14}),onClick:run(()=>editor.chain().focus().deleteRow().run()),children:"\u0627\u062D\u0630\u0641 \u0627\u0644\u0635\u0641"}),jsx4(MenuSeparator,{}),jsx4(MenuItem,{icon:jsx4(Columns,{size:14}),onClick:run(()=>editor.chain().focus().addColumnBefore().run()),children:"\u0639\u0645\u0648\u062F \u0642\u0628\u0644"}),jsx4(MenuItem,{icon:jsx4(Columns,{size:14}),onClick:run(()=>editor.chain().focus().addColumnAfter().run()),children:"\u0639\u0645\u0648\u062F \u0628\u0639\u062F"}),jsx4(MenuItem,{danger:true,icon:jsx4(Trash2,{size:14}),onClick:run(()=>editor.chain().focus().deleteColumn().run()),children:"\u0627\u062D\u0630\u0641 \u0627\u0644\u0639\u0645\u0648\u062F"}),jsx4(MenuSeparator,{}),jsx4(MenuItem,{icon:jsx4(Merge,{size:14}),onClick:run(()=>editor.chain().focus().mergeCells().run()),children:"\u0627\u062F\u0645\u062C \u0627\u0644\u062E\u0644\u0627\u064A\u0627"}),jsx4(MenuItem,{icon:jsx4(Split,{size:14}),onClick:run(()=>editor.chain().focus().splitCell().run()),children:"\u0627\u0642\u0633\u0645 \u0627\u0644\u062E\u0644\u064A\u0629"}),jsx4(MenuSeparator,{}),jsx4(MenuItem,{danger:true,icon:jsx4(Trash2,{size:14}),onClick:run(()=>editor.chain().focus().deleteTable().run()),children:"\u0627\u062D\u0630\u0641 \u0627\u0644\u062C\u062F\u0648\u0644"})]})]})}})}var TEXT_COLORS=["#000000","#434343","#666666","#999999","#E03131","#C2255C","#9C36B5","#6741D9","#3B5BDB","#1971C2","#0C8599","#099268","#2F9E44","#66A80F","#F08C00","#E8590C"];var HIGHLIGHT_COLORS=["#FBBF24","#F87171","#FB923C","#A78BFA","#60A5FA","#34D399","#F472B6","#2DD4BF","#FCD34D","#FCA5A5","#FDBA74","#C4B5FD","#93C5FD","#6EE7B7","#F9A8D4","#99F6E4"];function ColorTool(){const{editor}=useCurrentEditor3();if(!editor)return null;const current=editor.getAttributes("textStyle").color||"";return jsx4(Popover,{trigger:({open,toggle})=>jsx4(ToolbarButton,{onClick:toggle,isActive:open,tooltip:"\u0644\u0648\u0646 \u0627\u0644\u0646\u0635",children:jsxs4("span",{className:"flex flex-col items-center gap-0.5",children:[jsx4(Palette,{size:16,style:current?{color:current}:void 0}),jsx4("span",{"aria-hidden":"true",className:"w-4 h-0.5 rounded-full",style:{background:current||"currentColor"}})]})}),children:({close})=>jsx4(ColorGrid,{colors:TEXT_COLORS,current,fallback:"#000000",clearLabel:"\u0634\u064A\u0644 \u0627\u0644\u0644\u0648\u0646",onPick:c=>{editor.chain().focus().setColor(c).run();close()},onClear:()=>{editor.chain().focus().unsetColor().run();close()}})})}function HighlightTool(){const{editor}=useCurrentEditor3();if(!editor)return null;const current=editor.getAttributes("highlight").color||"";return jsx4(Popover,{trigger:({open,toggle})=>jsx4(ToolbarButton,{onClick:toggle,isActive:editor.isActive("highlight")||open,tooltip:"\u062A\u0638\u0644\u064A\u0644",children:jsxs4("span",{className:"flex flex-col items-center gap-0.5",children:[jsx4(Highlighter2,{size:16}),jsx4("span",{"aria-hidden":"true",className:"w-4 h-0.5 rounded-full",style:{background:current||"transparent"}})]})}),children:({close})=>jsx4(ColorGrid,{colors:HIGHLIGHT_COLORS,current,fallback:"#FBBF24",clearLabel:"\u0634\u064A\u0644 \u0627\u0644\u062A\u0638\u0644\u064A\u0644",onPick:c=>{editor.chain().focus().toggleHighlight({color:c}).run();close()},onClear:()=>{editor.chain().focus().unsetHighlight().run();close()}})})}var DATE_FORMATS=[{label:"\u0663\u0661 \u064A\u0648\u0644\u064A\u0648 \u0662\u0660\u0662\u0666",opts:{day:"numeric",month:"long",year:"numeric"}},{label:"\u0663\u0661 \u064A\u0648\u0644 \u0662\u0660\u0662\u0666",opts:{day:"numeric",month:"short",year:"numeric"}},{label:"\u0627\u0644\u062C\u0645\u0639\u0629\u060C \u0663\u0661 \u064A\u0648\u0644\u064A\u0648",opts:{weekday:"long",day:"numeric",month:"long"}},{label:"\u0662\u0660\u0662\u0666/\u0660\u0667/\u0663\u0661",opts:{year:"numeric",month:"2-digit",day:"2-digit"}},{label:"\u0660\u0662:\u0665\u0661 \u0635",opts:{hour:"2-digit",minute:"2-digit"}},{label:"\u0660\u0662:\u0665\u0661:\u0663\u0660 \u0635",opts:{hour:"2-digit",minute:"2-digit",second:"2-digit"}}];function DateTime({locale="ar-EG"}){const{editor}=useCurrentEditor3();if(!editor)return null;return jsx4(Popover,{width:"w-56",trigger:({open,toggle})=>jsx4(ToolbarButton,{onClick:toggle,isActive:open,tooltip:"\u062A\u0627\u0631\u064A\u062E \u0648\u0648\u0642\u062A",children:jsx4(CalendarClock,{size:16})}),children:({close})=>jsx4("div",{role:"menu",className:"py-1",children:DATE_FORMATS.map(f=>{const text=new Intl.DateTimeFormat(locale,f.opts).format(new Date);return jsx4(MenuItem,{onClick:()=>{editor.chain().focus().insertContent(text).run();close()},children:text},f.label)})})})}import{useCallback as useCallback2,useState as useState3}from"react";import{useCurrentEditor as useCurrentEditor4}from"@tiptap/react";import{ChevronDown as ChevronDown2,ChevronUp,Replace,Search}from"lucide-react";import{Fragment as Fragment3,jsx as jsx5,jsxs as jsxs5}from"react/jsx-runtime";function FindReplace(){const{editor}=useCurrentEditor4();const[term,setTerm]=useState3("");const[replacement,setReplacement]=useState3("");const[matches,setMatches]=useState3([]);const[index,setIndex]=useState3(0);const jump=useCallback2(m=>editor?.chain().setTextSelection(m).scrollIntoView().run(),[editor]);const find=useCallback2(value=>{if(!editor||!value.trim()){setMatches([]);setIndex(0);return}const found=[];const needle=value.toLowerCase();editor.state.doc.descendants((node,pos)=>{if(!node.isText)return;const text=node.text?.toLowerCase()??"";let at=text.indexOf(needle);while(at!==-1){found.push({from:pos+at,to:pos+at+value.length});at=text.indexOf(needle,at+1)}});setMatches(found);setIndex(0);if(found[0])jump(found[0])},[editor,jump]);if(!editor)return null;const step=by=>{if(matches.length===0)return;const next=(index+by+matches.length)%matches.length;setIndex(next);jump(matches[next])};const replaceOne=()=>{const m=matches[index];if(!m)return;editor.chain().focus().setTextSelection(m).insertContent(replacement).run();find(term)};const replaceAll=()=>{if(matches.length===0)return;const chain=editor.chain().focus();for(const m of[...matches].sort((a,b)=>b.from-a.from)){chain.setTextSelection(m).insertContent(replacement)}chain.run();find(term)};return jsx5(Popover,{width:"w-72",trigger:({open,toggle})=>jsx5(ToolbarButton,{onClick:toggle,isActive:open,tooltip:"\u0628\u062D\u062B \u0648\u0627\u0633\u062A\u0628\u062F\u0627\u0644",shortcut:"Ctrl+H",children:jsx5(Search,{size:16})}),children:()=>jsxs5("div",{className:"p-3 flex flex-col gap-2.5",children:[jsxs5("div",{className:"flex items-end gap-1.5",children:[jsx5(Input,{autoFocus:true,size:"sm",label:"\u0627\u0628\u062D\u062B \u0639\u0646",hideLabel:true,placeholder:"\u0627\u0628\u062D\u062B \u0639\u0646\u2026",value:term,wrapperClassName:"flex-1 min-w-0",onChange:e=>{setTerm(e.target.value);find(e.target.value)},onKeyDown:e=>{if(e.key!=="Enter")return;e.preventDefault();step(e.shiftKey?-1:1)}}),jsx5(Button,{size:"sm",variant:"outline",iconOnly:true,"aria-label":"\u0627\u0644\u0633\u0627\u0628\u0642",disabled:matches.length===0,onClick:()=>step(-1),icon:jsx5(ChevronUp,{size:14})}),jsx5(Button,{size:"sm",variant:"outline",iconOnly:true,"aria-label":"\u0627\u0644\u062A\u0627\u0644\u064A",disabled:matches.length===0,onClick:()=>step(1),icon:jsx5(ChevronDown2,{size:14})})]}),term.trim()&&jsx5("span",{className:"text-micro text-muted2","aria-live":"polite",children:matches.length>0?jsxs5(Fragment3,{children:[jsx5("span",{"data-num":true,children:index+1})," \u0645\u0646 ",jsx5("span",{"data-num":true,children:matches.length})]}):"\u0645\u0627\u0641\u064A\u0634 \u0646\u062A\u0627\u064A\u062C"}),jsxs5("div",{className:"flex items-end gap-1.5",children:[jsx5(Input,{size:"sm",label:"\u0627\u0633\u062A\u0628\u062F\u0644 \u0628\u0640",hideLabel:true,placeholder:"\u0627\u0633\u062A\u0628\u062F\u0644 \u0628\u0640\u2026",value:replacement,wrapperClassName:"flex-1 min-w-0",onChange:e=>setReplacement(e.target.value),onKeyDown:e=>{if(e.key==="Enter"){e.preventDefault();replaceOne()}}}),jsx5(Button,{size:"sm",variant:"outline",iconOnly:true,"aria-label":"\u0627\u0633\u062A\u0628\u062F\u0644",disabled:matches.length===0,onClick:replaceOne,icon:jsx5(Replace,{size:14})})]}),jsx5(Button,{size:"sm",variant:"soft",block:true,disabled:matches.length===0,onClick:replaceAll,children:"\u0627\u0633\u062A\u0628\u062F\u0644 \u0627\u0644\u0643\u0644"})]})})}import{jsx as jsx6,jsxs as jsxs6}from"react/jsx-runtime";function useEditorTick(){const[,setTick]=useState4(0);const{editor}=useCurrentEditor5();const raf=useRef3(0);useEffect2(()=>{if(!editor)return;const bump=()=>{cancelAnimationFrame(raf.current);raf.current=requestAnimationFrame(()=>setTick(t=>t+1))};editor.on("selectionUpdate",bump);editor.on("transaction",bump);return()=>{cancelAnimationFrame(raf.current);editor.off("selectionUpdate",bump);editor.off("transaction",bump)}},[editor])}function Toolbar({basic,onPickImage,hideImage,locale}){useEditorTick();const{editor}=useCurrentEditor5();if(!editor)return null;if(basic){return jsxs6("div",{className:"w-full border-b border-line px-1.5 py-1 flex flex-wrap items-center gap-0.5",children:[jsx6(ToolbarGroup,{children:jsx6(UndoRedo,{})}),jsx6(ToolbarGroup,{children:jsx6(HeadingSelector,{})}),jsxs6(ToolbarGroup,{children:[jsx6(Bold2,{}),jsx6(Italic2,{}),jsx6(Underline3,{})]}),jsxs6(ToolbarGroup,{children:[jsx6(BulletList,{}),jsx6(OrderedList,{})]}),jsxs6(ToolbarGroup,{children:[jsx6(Link3,{}),!hideImage&&jsx6(ImageTool,{onPick:onPickImage}),jsx6(ColorTool,{})]})]})}return jsxs6("div",{className:"w-full border-b border-line px-1.5 py-1.5 flex flex-wrap items-center gap-y-1",children:[jsx6(ToolbarGroup,{children:jsx6(UndoRedo,{})}),jsx6(ToolbarGroup,{children:jsx6(HeadingSelector,{})}),jsxs6(ToolbarGroup,{children:[jsx6(Bold2,{}),jsx6(Italic2,{}),jsx6(Underline3,{}),jsx6(Strikethrough2,{})]}),jsxs6(ToolbarGroup,{children:[jsx6(BulletList,{}),jsx6(OrderedList,{}),jsx6(BlockQuote,{})]}),jsx6(ToolbarGroup,{children:jsx6(Alignment,{})}),jsxs6(ToolbarGroup,{children:[jsx6(Link3,{}),!hideImage&&jsx6(ImageTool,{onPick:onPickImage}),jsx6(TableTool,{}),jsx6(DateTime,{locale})]}),jsxs6(ToolbarGroup,{children:[jsx6(ColorTool,{}),jsx6(HighlightTool,{})]}),jsxs6(ToolbarGroup,{children:[jsx6(Code2,{}),jsx6(HorizontalRule,{}),jsx6(ClearMarks,{}),jsx6(FindReplace,{})]})]})}function EditorFooter({maxChars}){return jsx6("div",{className:"border-t border-line px-3 py-1.5 flex justify-end",children:jsx6(CharacterCount,{maxChars})})}import{forwardRef,useEffect as useEffect3,useImperativeHandle,useState as useState5}from"react";import{Extension}from"@tiptap/core";import{PluginKey as PluginKey2}from"@tiptap/pm/state";import{ReactRenderer}from"@tiptap/react";import Suggestion from"@tiptap/suggestion";import{jsx as jsx7,jsxs as jsxs7}from"react/jsx-runtime";var SLASH_ITEMS=[{title:"\u0639\u0646\u0648\u0627\u0646 \u0643\u0628\u064A\u0631",hint:"H1",icon:"H1",command:({editor,range})=>editor.chain().focus().deleteRange(range).setHeading({level:1}).run()},{title:"\u0639\u0646\u0648\u0627\u0646 \u0645\u062A\u0648\u0633\u0637",hint:"H2",icon:"H2",command:({editor,range})=>editor.chain().focus().deleteRange(range).setHeading({level:2}).run()},{title:"\u0639\u0646\u0648\u0627\u0646 \u0635\u063A\u064A\u0631",hint:"H3",icon:"H3",command:({editor,range})=>editor.chain().focus().deleteRange(range).setHeading({level:3}).run()},{title:"\u0642\u0627\u0626\u0645\u0629 \u0646\u0642\u0637\u064A\u0629",icon:"\u2022",command:({editor,range})=>editor.chain().focus().deleteRange(range).toggleBulletList().run()},{title:"\u0642\u0627\u0626\u0645\u0629 \u0645\u0631\u0642\u0651\u0645\u0629",icon:"\u0661.",command:({editor,range})=>editor.chain().focus().deleteRange(range).toggleOrderedList().run()},{title:"\u0627\u0642\u062A\u0628\u0627\u0633",icon:"\u275D",command:({editor,range})=>editor.chain().focus().deleteRange(range).toggleBlockquote().run()},{title:"\u0628\u0644\u0648\u0643 \u0643\u0648\u062F",icon:"</>",command:({editor,range})=>editor.chain().focus().deleteRange(range).toggleCodeBlock().run()},{title:"\u062C\u062F\u0648\u0644",hint:"\u0663\xD7\u0663",icon:"\u229E",command:({editor,range})=>editor.chain().focus().deleteRange(range).insertTable({rows:3,cols:3,withHeaderRow:true}).run()},{title:"\u0641\u0627\u0635\u0644 \u0623\u0641\u0642\u064A",icon:"\u2500",command:({editor,range})=>editor.chain().focus().deleteRange(range).setHorizontalRule().run()}];var SlashList=forwardRef(function SlashList2({items,command},ref){const[active,setActive]=useState5(0);useEffect3(()=>setActive(0),[items]);useImperativeHandle(ref,()=>({onKeyDown:({event})=>{if(event.key==="ArrowUp"){setActive(i=>i<=0?items.length-1:i-1);return true}if(event.key==="ArrowDown"){setActive(i=>i>=items.length-1?0:i+1);return true}if(event.key==="Enter"){const item=items[active];if(item)command(item);return true}return false}}));if(items.length===0)return null;return jsx7("div",{className:"w-64 max-h-72 overflow-y-auto rounded-card border border-line bg-surface shadow-pop py-1 animate-[fade-in_.12s_ease-out]",children:items.map((item,i)=>jsxs7("button",{type:"button",onMouseEnter:()=>setActive(i),onClick:()=>command(item),className:cn("w-full px-3 py-2 flex items-center gap-3 text-start cursor-pointer transition-colors",i===active?"bg-soft text-brand-ink":"text-ink2 hover:bg-hover"),children:[jsx7("span",{"aria-hidden":"true",className:"size-7 shrink-0 rounded-sm bg-bg border border-line flex items-center justify-center text-micro font-extrabold",children:item.icon}),jsx7("span",{className:"flex-1 min-w-0 text-ui font-bold truncate",children:item.title}),item.hint&&jsx7("span",{dir:"ltr",className:"text-micro text-muted2 shrink-0",children:item.hint})]},item.title))})});var SlashCommandsPluginKey=new PluginKey2("qumraSlashCommands");var SlashCommands=Extension.create({name:"qumraSlashCommands",addOptions(){return{suggestion:{char:"/",pluginKey:SlashCommandsPluginKey,command:({editor,range,props})=>{props.command({editor,range})}}}},addProseMirrorPlugins(){return[Suggestion({editor:this.editor,...this.options.suggestion})]}});function place(el,rect){const rtl=getComputedStyle(document.documentElement).direction==="rtl";const gap=6;const{offsetHeight:h,offsetWidth:w}=el;const below=window.innerHeight-rect.bottom;const top=below<h+gap&&rect.top>h+gap?rect.top-h-gap:rect.bottom+gap;let left=rtl?rect.right-w:rect.left;left=Math.max(8,Math.min(left,window.innerWidth-w-8));el.style.top=`${top+window.scrollY}px`;el.style.left=`${left+window.scrollX}px`}function createSlashSuggestion(){return{items:({query})=>!query?SLASH_ITEMS:SLASH_ITEMS.filter(i=>i.title.includes(query)||i.icon.toLowerCase().includes(query.toLowerCase())),render:()=>{let component=null;let host=null;const reposition=clientRect=>{const rect=clientRect?.();if(host&&rect)place(host,rect)};return{onStart:props=>{component=new ReactRenderer(SlashList,{props,editor:props.editor});host=document.createElement("div");host.style.position="absolute";host.style.zIndex="60";host.appendChild(component.element);document.body.appendChild(host);reposition(props.clientRect)},onUpdate:props=>{component?.updateProps(props);reposition(props.clientRect)},onKeyDown:props=>{if(props.event.key==="Escape"){host?.remove();return true}const api=component?.ref;return api?.onKeyDown?.(props)??false},onExit:()=>{host?.remove();component?.destroy();host=null;component=null}}}}}import{jsx as jsx8,jsxs as jsxs8}from"react/jsx-runtime";function Editor({content,onChange,placeholder,maxChars,basic,disabled,onPickImage,hideImage,locale="ar-EG",className}){const extensions=useMemo2(()=>[...contentExtensions(),Placeholder.configure({placeholder:placeholder??""}),CharacterCount2.configure(maxChars?{limit:maxChars}:{}),Dropcursor.configure({color:"var(--color-brand)",width:2}),SlashCommands.configure({suggestion:createSlashSuggestion()})],[placeholder,maxChars]);const lastEmitted=useRef4("");const[initialContent]=useState6(()=>content||"");const editorProps=useMemo2(()=>({attributes:{class:"qumra-tiptap",dir:"auto"},handleDrop:(view,event,_slice,moved)=>{if(moved||!event.dataTransfer?.files?.length)return false;const file=event.dataTransfer.files[0];if(!file?.type.startsWith("image/"))return false;const reader=new FileReader;reader.onload=()=>{const at=view.posAtCoords({left:event.clientX,top:event.clientY});if(!at)return;const node=view.state.schema.nodes.image.create({src:reader.result});view.dispatch(view.state.tr.insert(at.pos,node))};reader.readAsDataURL(file);return true},handlePaste:(view,event)=>{const items=event.clipboardData?.items;if(!items)return false;for(const item of Array.from(items)){if(!item.type.startsWith("image/"))continue;const file=item.getAsFile();if(!file)continue;const reader=new FileReader;reader.onload=()=>{const node=view.state.schema.nodes.image.create({src:reader.result});view.dispatch(view.state.tr.insert(view.state.selection.from,node))};reader.readAsDataURL(file);return true}return false}}),[]);const handleUpdate=({editor})=>{const html=editor.getHTML();if(html===lastEmitted.current)return;lastEmitted.current=html;onChange(html)};return jsx8("div",{className:cn("relative","bg-surface border border-border rounded-field","focus-within:border-brand transition-colors","[&>*:first-child]:rounded-t-field",disabled&&"opacity-60 pointer-events-none",className),children:jsxs8(EditorProvider,{immediatelyRender:false,extensions,content:initialContent,onUpdate:handleUpdate,slotBefore:!disabled&&jsx8(Toolbar,{basic,onPickImage,hideImage,locale}),slotAfter:!disabled&&jsx8(EditorFooter,{maxChars}),editorProps,children:[jsx8(EditorBubbleMenu,{}),jsx8(SyncContent,{content,disabled,lastEmitted})]})})}function SyncContent({content,disabled,lastEmitted}){const{editor}=useCurrentEditor6();useEffect4(()=>{if(!editor)return;const incoming=content||"";if(incoming!==editor.getHTML()){editor.commands.setContent(incoming,{emitUpdate:false});lastEmitted.current=editor.getHTML()}if(editor.isEditable===Boolean(disabled)){editor.setEditable(!disabled,false)}},[content,disabled,editor,lastEmitted]);return null}import{generateHTML,generateJSON}from"@tiptap/core";function emptyDoc(){return{type:"doc",content:[{type:"paragraph"}]}}function htmlToDoc(html){try{return generateJSON(html?.trim()?html:"<p></p>",contentExtensions())}catch{return emptyDoc()}}function docToHtml(doc){if(!isDoc(doc))return"";try{return generateHTML(doc,contentExtensions())}catch{return""}}function isDoc(value){return!!value&&typeof value==="object"&&!Array.isArray(value)&&value.type==="doc"}export{Editor,docToHtml,htmlToDoc,isDoc};
2
+ import{Tooltip}from"./chunk-ENHEJXVH.js";import{Button,Input}from"./chunk-VAMRF7HE.js";import{Modal,cn}from"./chunk-ZE4S6DBP.js";import{useEffect as useEffect4,useMemo as useMemo2,useRef as useRef4,useState as useState6}from"react";import{EditorProvider,useCurrentEditor as useCurrentEditor6}from"@tiptap/react";import{CharacterCount as CharacterCount2}from"@tiptap/extension-character-count";import Dropcursor from"@tiptap/extension-dropcursor";import{Placeholder}from"@tiptap/extension-placeholder";import StarterKit from"@tiptap/starter-kit";import{Color}from"@tiptap/extension-color";import{Highlight}from"@tiptap/extension-highlight";import Image from"@tiptap/extension-image";import Link from"@tiptap/extension-link";import ListItem from"@tiptap/extension-list-item";import{Table}from"@tiptap/extension-table";import{TableCell}from"@tiptap/extension-table-cell";import{TableHeader}from"@tiptap/extension-table-header";import{TableRow}from"@tiptap/extension-table-row";import TextAlign from"@tiptap/extension-text-align";import{TextStyle}from"@tiptap/extension-text-style";import Underline from"@tiptap/extension-underline";import ImageResize from"tiptap-extension-resize-image";import TextDirection from"tiptap-text-direction";function contentExtensions(){return[StarterKit.configure({bulletList:{keepMarks:true,keepAttributes:false},orderedList:{keepMarks:true,keepAttributes:false}}),TextDirection.configure({types:["heading","paragraph"],defaultDirection:"rtl"}),TextAlign.configure({types:["heading","paragraph"]}),TextStyle,Color.configure({types:[TextStyle.name,ListItem.name]}),Underline,Highlight.configure({multicolor:true}),Link.configure({openOnClick:false,autolink:true,defaultProtocol:"https"}),Image.configure({inline:true}),ImageResize.configure(),Table.configure({resizable:true}),TableRow,TableHeader,TableCell]}import{useCallback,useId,useMemo,useRef}from"react";import{useCurrentEditor}from"@tiptap/react";import{BubbleMenu}from"@tiptap/react/menus";import{PluginKey}from"@tiptap/pm/state";import{Bold,Code,Highlighter,Italic,Link2,Strikethrough,Underline as Underline2}from"lucide-react";import{jsx,jsxs}from"react/jsx-runtime";function BubbleButton({onClick,isActive,label,children}){return jsx("button",{type:"button",onClick,"aria-label":label,"aria-pressed":isActive,className:cn("size-7 rounded-xs inline-flex items-center justify-center cursor-pointer transition-colors",isActive?"bg-brand text-white":"text-ink2 hover:bg-hover hover:text-ink"),children})}function EditorBubbleMenu(){const{editor}=useCurrentEditor();const key=useId();const pluginKey=useMemo(()=>new PluginKey(`qumraBubble${key}`),[key]);const menuRef=useRef(null);const onShow=useCallback(()=>{const el=menuRef.current;if(el)el.style.opacity="0"},[]);const onUpdate=useCallback(()=>{const el=menuRef.current;if(el)el.style.opacity="1"},[]);const scrollTarget=useMemo(()=>{if(typeof window==="undefined")return void 0;const dom=editor?.view?.dom;let node=dom?.parentElement??null;while(node){const{overflowY}=getComputedStyle(node);if(overflowY==="auto"||overflowY==="scroll")return node;node=node.parentElement}return void 0},[editor]);if(!editor)return null;const e=editor;return jsx(BubbleMenu,{editor,pluginKey,ref:el=>{menuRef.current=el},options:{placement:"top",offset:8,...scrollTarget?{scrollTarget}:{},onShow,onUpdate},shouldShow:({editor:ed,from,to})=>{if(from===to)return false;if(ed.isActive("image")||ed.isActive("codeBlock"))return false;return true},children:jsxs("div",{className:"flex items-center gap-0.5 p-1 rounded-card border border-line bg-surface shadow-pop",children:[jsx(BubbleButton,{label:"\u0639\u0631\u064A\u0636",onClick:()=>e.chain().focus().toggleBold().run(),isActive:e.isActive("bold"),children:jsx(Bold,{size:14})}),jsx(BubbleButton,{label:"\u0645\u0627\u0626\u0644",onClick:()=>e.chain().focus().toggleItalic().run(),isActive:e.isActive("italic"),children:jsx(Italic,{size:14})}),jsx(BubbleButton,{label:"\u062A\u062D\u062A\u0647 \u062E\u0637",onClick:()=>e.chain().focus().toggleUnderline().run(),isActive:e.isActive("underline"),children:jsx(Underline2,{size:14})}),jsx(BubbleButton,{label:"\u064A\u062A\u0634\u0637\u0628",onClick:()=>e.chain().focus().toggleStrike().run(),isActive:e.isActive("strike"),children:jsx(Strikethrough,{size:14})}),jsx("span",{"aria-hidden":"true",className:"w-px h-5 bg-line mx-0.5"}),jsx(BubbleButton,{label:"\u0643\u0648\u062F",onClick:()=>e.chain().focus().toggleCode().run(),isActive:e.isActive("code"),children:jsx(Code,{size:14})}),jsx(BubbleButton,{label:"\u062A\u0638\u0644\u064A\u0644",onClick:()=>e.chain().focus().toggleHighlight().run(),isActive:e.isActive("highlight"),children:jsx(Highlighter,{size:14})}),jsx("span",{"aria-hidden":"true",className:"w-px h-5 bg-line mx-0.5"}),jsx(BubbleButton,{label:"\u0631\u0627\u0628\u0637",isActive:e.isActive("link"),onClick:()=>{const previous=e.getAttributes("link").href||"";const url=window.prompt("\u0631\u0627\u0628\u0637",previous);if(url===null)return;const chain=e.chain().focus().extendMarkRange("link");if(url==="")chain.unsetLink().run();else chain.setLink({href:/^https?:\/\//i.test(url)?url:`https://${url}`}).run()},children:jsx(Link2,{size:14})})]})})}import{useEffect as useEffect2,useRef as useRef3,useState as useState4}from"react";import{useCurrentEditor as useCurrentEditor5}from"@tiptap/react";import{useEffect,useRef as useRef2,useState}from"react";import{jsx as jsx2,jsxs as jsxs2}from"react/jsx-runtime";function useDismiss(open,close){const ref=useRef2(null);useEffect(()=>{if(!open)return;function onDown(e){if(ref.current&&!ref.current.contains(e.target))close()}function onKey(e){if(e.key==="Escape")close()}document.addEventListener("mousedown",onDown);document.addEventListener("keydown",onKey);return()=>{document.removeEventListener("mousedown",onDown);document.removeEventListener("keydown",onKey)}},[open,close]);return ref}var PANEL="absolute z-50 top-[calc(100%+6px)] start-0 bg-surface border border-line rounded-card shadow-panel overflow-clip animate-[fade-in_.14s_ease-out]";function Popover({trigger,children,width,className}){const[open,setOpen]=useState(false);const ref=useDismiss(open,()=>setOpen(false));return jsxs2("div",{ref,className:cn("relative flex",className),children:[trigger({open,toggle:()=>setOpen(v=>!v)}),open&&jsx2("div",{className:cn(PANEL,width??"w-56"),children:children({close:()=>setOpen(false)})})]})}function MenuItem({onClick,icon,children,danger,active}){return jsxs2("button",{type:"button",onClick,className:cn("w-full px-3 py-2 flex items-center gap-2.5 text-start text-ui cursor-pointer transition-colors",danger?"text-red hover:bg-red-bg":"text-ink2 hover:bg-hover",active&&"bg-soft text-brand-ink font-bold"),children:[icon,jsx2("span",{className:"flex-1 min-w-0 truncate",children})]})}function MenuSeparator(){return jsx2("span",{"aria-hidden":"true",className:"block h-px bg-line my-1"})}function ToolbarButton({onClick,isActive,disabled,tooltip,shortcut,children}){return jsx2(Tooltip,{content:jsxs2("span",{className:"flex items-center gap-2",children:[tooltip,shortcut&&jsx2("kbd",{dir:"ltr",className:"px-1 py-px rounded-xs bg-white/15 text-micro font-mono",children:shortcut})]}),children:jsx2("button",{type:"button",onClick,disabled,"aria-label":tooltip,"aria-pressed":isActive,className:cn("size-8 rounded-sm inline-flex items-center justify-center shrink-0 cursor-pointer transition-colors","focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand","disabled:opacity-40 disabled:cursor-not-allowed",isActive?"bg-soft text-brand-ink":"text-muted hover:bg-hover hover:text-ink"),children})})}function ToolbarGroup({children}){return jsx2("div",{className:"flex items-center gap-0.5 pe-1 me-1 border-e border-line last:border-e-0 last:pe-0 last:me-0",children})}function ColorGrid({colors,current,onPick,onClear,clearLabel,fallback}){return jsxs2("div",{className:"p-3 flex flex-col gap-2.5",children:[jsx2("div",{className:"grid grid-cols-4 gap-1.5",children:colors.map(color=>jsx2("button",{type:"button",onClick:()=>onPick(color),"aria-label":color,style:{background:color},className:cn("size-8 rounded-sm border cursor-pointer transition-transform hover:scale-110",current.toLowerCase()===color.toLowerCase()?"border-ink ring-2 ring-brand":"border-line")},color))}),jsxs2("div",{className:"flex items-center gap-2.5 pt-2.5 border-t border-line",children:[jsx2("input",{type:"color",value:current||fallback,onChange:e=>onPick(e.target.value),"aria-label":"\u0644\u0648\u0646 \u0645\u062E\u0635\u0651\u0635",className:"size-8 p-0 border-none bg-transparent cursor-pointer"}),jsx2("button",{type:"button",onClick:onClear,className:"text-caption text-muted hover:text-ink cursor-pointer transition-colors",children:clearLabel})]})]})}import{useCurrentEditor as useCurrentEditor2}from"@tiptap/react";import{AlignCenter,AlignLeft,AlignRight,Bold as BoldIcon,Code as CodeIcon,Eraser,Italic as ItalicIcon,List,ListOrdered,Minus,Quote,Redo,Strikethrough as StrikeIcon,Underline as UnderlineIcon,Undo}from"lucide-react";import{Fragment,jsx as jsx3,jsxs as jsxs3}from"react/jsx-runtime";function Bold2(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleBold().run(),isActive:editor.isActive("bold"),tooltip:"\u0639\u0631\u064A\u0636",shortcut:"Ctrl+B",children:jsx3(BoldIcon,{size:16})})}function Italic2(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleItalic().run(),isActive:editor.isActive("italic"),tooltip:"\u0645\u0627\u0626\u0644",shortcut:"Ctrl+I",children:jsx3(ItalicIcon,{size:16})})}function Underline3(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleUnderline().run(),isActive:editor.isActive("underline"),tooltip:"\u062A\u062D\u062A\u0647 \u062E\u0637",shortcut:"Ctrl+U",children:jsx3(UnderlineIcon,{size:16})})}function Strikethrough2(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleStrike().run(),isActive:editor.isActive("strike"),tooltip:"\u064A\u062A\u0634\u0637\u0628",shortcut:"Ctrl+Shift+S",children:jsx3(StrikeIcon,{size:16})})}function Code2(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleCode().run(),isActive:editor.isActive("code"),tooltip:"\u0643\u0648\u062F",shortcut:"Ctrl+E",children:jsx3(CodeIcon,{size:16})})}function BulletList(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleBulletList().run(),isActive:editor.isActive("bulletList"),tooltip:"\u0642\u0627\u0626\u0645\u0629 \u0646\u0642\u0637\u064A\u0629",shortcut:"Ctrl+Shift+8",children:jsx3(List,{size:16})})}function OrderedList(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleOrderedList().run(),isActive:editor.isActive("orderedList"),tooltip:"\u0642\u0627\u0626\u0645\u0629 \u0645\u0631\u0642\u0651\u0645\u0629",shortcut:"Ctrl+Shift+7",children:jsx3(ListOrdered,{size:16})})}function BlockQuote(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().toggleBlockquote().run(),isActive:editor.isActive("blockquote"),tooltip:"\u0627\u0642\u062A\u0628\u0627\u0633",shortcut:"Ctrl+Shift+B",children:jsx3(Quote,{size:16})})}function HorizontalRule(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().setHorizontalRule().run(),tooltip:"\u0641\u0627\u0635\u0644 \u0623\u0641\u0642\u064A",children:jsx3(Minus,{size:16})})}function ClearMarks(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().unsetAllMarks().run(),tooltip:"\u0645\u0633\u062D \u0627\u0644\u062A\u0646\u0633\u064A\u0642",children:jsx3(Eraser,{size:16})})}function UndoRedo(){const{editor}=useCurrentEditor2();if(!editor)return null;return jsxs3(Fragment,{children:[jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().undo().run(),disabled:!editor.can().chain().focus().undo().run(),tooltip:"\u062A\u0631\u0627\u062C\u0639",shortcut:"Ctrl+Z",children:jsx3(Undo,{size:16})}),jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().redo().run(),disabled:!editor.can().chain().focus().redo().run(),tooltip:"\u0625\u0639\u0627\u062F\u0629",shortcut:"Ctrl+Y",children:jsx3(Redo,{size:16})})]})}function Alignment(){const{editor}=useCurrentEditor2();if(!editor)return null;const items=[{key:"right",tooltip:"\u0645\u062D\u0627\u0630\u0627\u0629 \u064A\u0645\u064A\u0646",Icon:AlignRight},{key:"center",tooltip:"\u062A\u0648\u0633\u064A\u0637",Icon:AlignCenter},{key:"left",tooltip:"\u0645\u062D\u0627\u0630\u0627\u0629 \u0634\u0645\u0627\u0644",Icon:AlignLeft}];return jsx3(Fragment,{children:items.map(({key,tooltip,Icon})=>jsx3(ToolbarButton,{onClick:()=>editor.chain().focus().setTextAlign(key).run(),isActive:editor.isActive({textAlign:key}),disabled:!editor.can().chain().focus().setTextAlign(key).run(),tooltip,children:jsx3(Icon,{size:16})},key))})}function CharacterCount({maxChars}){const{editor}=useCurrentEditor2();if(!editor)return null;const chars=editor.storage.characterCount?.characters()??0;const words=editor.storage.characterCount?.words()??0;const over=maxChars?chars>maxChars:false;const near=maxChars?chars>maxChars*.9:false;return jsxs3("span",{className:cn("flex items-center gap-2 text-caption select-none",over?"text-red font-bold":near?"text-amber-ink font-bold":"text-muted2"),children:[jsxs3("span",{"data-num":true,children:[chars,maxChars?`/${maxChars}`:""," \u062D\u0631\u0641"]}),jsx3("span",{"aria-hidden":"true",className:"text-line",children:"|"}),jsxs3("span",{"data-num":true,children:[words," \u0643\u0644\u0645\u0629"]})]})}import{useState as useState2}from"react";import{useCurrentEditor as useCurrentEditor3}from"@tiptap/react";import{CalendarClock,ChevronDown,Columns,Highlighter as Highlighter2,Image as ImageIcon,Link2 as Link22,Merge,Palette,Plus,Rows,Split,Table as TableIcon,Trash2}from"lucide-react";import{Fragment as Fragment2,jsx as jsx4,jsxs as jsxs4}from"react/jsx-runtime";var HEADINGS=[{level:0,label:"\u0646\u0635 \u0639\u0627\u062F\u064A",size:"text-body"},{level:1,label:"\u0639\u0646\u0648\u0627\u0646 \u0661",size:"text-h2"},{level:2,label:"\u0639\u0646\u0648\u0627\u0646 \u0662",size:"text-h3"},{level:3,label:"\u0639\u0646\u0648\u0627\u0646 \u0663",size:"text-h4"},{level:4,label:"\u0639\u0646\u0648\u0627\u0646 \u0664",size:"text-lead"},{level:5,label:"\u0639\u0646\u0648\u0627\u0646 \u0665",size:"text-body"},{level:6,label:"\u0639\u0646\u0648\u0627\u0646 \u0666",size:"text-ui"}];function HeadingSelector(){const{editor}=useCurrentEditor3();if(!editor)return null;const current=HEADINGS.find(h=>h.level===0?editor.isActive("paragraph"):editor.isActive("heading",{level:h.level}))??HEADINGS[0];return jsx4(Popover,{width:"w-48",trigger:({open,toggle})=>jsxs4("button",{type:"button",onClick:toggle,"aria-haspopup":"menu","aria-expanded":open,className:cn("h-8 px-2.5 rounded-sm inline-flex items-center gap-1.5 text-ui font-bold cursor-pointer transition-colors","focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand",open?"bg-soft text-brand-ink":"text-ink2 hover:bg-hover"),children:[jsx4("span",{className:"truncate max-w-24",children:current.label}),jsx4(ChevronDown,{size:14,className:cn("shrink-0 transition-transform",open&&"rotate-180")})]}),children:({close})=>jsx4("div",{role:"menu",className:"py-1",children:HEADINGS.map(h=>{const active=h.level===0?editor.isActive("paragraph"):editor.isActive("heading",{level:h.level});return jsx4("button",{type:"button",role:"menuitem",onClick:()=>{if(h.level===0)editor.chain().focus().setParagraph().run();else editor.chain().focus().toggleHeading({level:h.level}).run();close()},className:cn("w-full px-3 py-2 flex items-center justify-between gap-3 text-start cursor-pointer transition-colors",active?"bg-soft text-brand-ink":"text-ink2 hover:bg-hover"),children:jsx4("span",{className:cn(h.size,active?"font-extrabold":"font-bold"),children:h.label})},h.level)})})})}function normalizeUrl(url){const t=url.trim();if(!t)return"";if(/^(https?:\/\/|mailto:|#)/i.test(t))return t;return`https://${t}`}function Link3(){const{editor}=useCurrentEditor3();const[open,setOpen]=useState2(false);const[url,setUrl]=useState2("");if(!editor)return null;function apply(){const chain=editor.chain().focus().extendMarkRange("link");if(url.trim()==="")chain.unsetLink().run();else chain.setLink({href:normalizeUrl(url)}).run();setOpen(false)}return jsxs4(Fragment2,{children:[jsx4(ToolbarButton,{onClick:()=>{setUrl(editor.getAttributes("link").href||"");setOpen(true)},isActive:editor.isActive("link"),tooltip:"\u0631\u0627\u0628\u0637",shortcut:"Ctrl+K",children:jsx4(Link22,{size:16})}),jsx4(Modal,{open,onClose:()=>setOpen(false),title:"\u0625\u0636\u0627\u0641\u0629 \u0631\u0627\u0628\u0637",description:"\u0633\u064A\u0628\u0647 \u0641\u0627\u0636\u064A \u0648\u0627\u0645\u0633\u062D \u0639\u0634\u0627\u0646 \u062A\u0634\u064A\u0644 \u0627\u0644\u0631\u0627\u0628\u0637.",size:"sm",footer:jsxs4(Fragment2,{children:[jsx4(Button,{variant:"outline",onClick:()=>setOpen(false),children:"\u0625\u0644\u063A\u0627\u0621"}),jsx4(Button,{onClick:apply,children:url.trim()?"\u0623\u0636\u0641":"\u0634\u064A\u0644 \u0627\u0644\u0631\u0627\u0628\u0637"})]}),children:jsx4(Input,{label:"\u0627\u0644\u0639\u0646\u0648\u0627\u0646",dir:"ltr",placeholder:"example.com",value:url,onChange:e=>setUrl(e.target.value),onKeyDown:e=>e.key==="Enter"&&apply()})})]})}function ImageTool({onPick}){const{editor}=useCurrentEditor3();const[open,setOpen]=useState2(false);const[src,setSrc]=useState2("");if(!editor)return null;const insert=url=>editor.chain().focus().setImage({src:url}).run();return jsxs4(Fragment2,{children:[jsx4(ToolbarButton,{onClick:()=>onPick?onPick(insert):setOpen(true),isActive:editor.isActive("image"),tooltip:"\u0635\u0648\u0631\u0629",children:jsx4(ImageIcon,{size:16})}),!onPick&&jsx4(Modal,{open,onClose:()=>setOpen(false),title:"\u0625\u062F\u0631\u0627\u062C \u0635\u0648\u0631\u0629",size:"sm",footer:jsxs4(Fragment2,{children:[jsx4(Button,{variant:"outline",onClick:()=>setOpen(false),children:"\u0625\u0644\u063A\u0627\u0621"}),jsx4(Button,{disabled:!src.trim(),onClick:()=>{insert(src.trim());setSrc("");setOpen(false)},children:"\u0623\u062F\u0631\u062C"})]}),children:jsx4(Input,{label:"\u0631\u0627\u0628\u0637 \u0627\u0644\u0635\u0648\u0631\u0629",dir:"ltr",placeholder:"https://\u2026",value:src,onChange:e=>setSrc(e.target.value),hint:"\u0648\u062A\u0642\u062F\u0631 \u0643\u0645\u0627\u0646 \u062A\u0633\u062D\u0628 \u0635\u0648\u0631\u0629 \u0648\u062A\u0641\u0644\u062A\u0647\u0627 \u062C\u0648\u0651\u0647 \u0627\u0644\u0645\u062D\u0631\u0631 \u0645\u0628\u0627\u0634\u0631\u0629\u064B."})})]})}function TableTool(){const{editor}=useCurrentEditor3();if(!editor)return null;const inTable=editor.isActive("table");return jsx4(Popover,{width:"w-56",trigger:({open,toggle})=>jsx4(ToolbarButton,{onClick:toggle,isActive:inTable||open,tooltip:"\u062C\u062F\u0648\u0644",children:jsx4(TableIcon,{size:16})}),children:({close})=>{const run=fn=>()=>{fn();close()};return jsxs4("div",{role:"menu",className:"py-1",children:[jsx4(MenuItem,{icon:jsx4(Plus,{size:14}),onClick:run(()=>editor.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:true}).run()),children:"\u0623\u062F\u0631\u062C \u062C\u062F\u0648\u0644 \u0663\xD7\u0663"}),inTable&&jsxs4(Fragment2,{children:[jsx4(MenuSeparator,{}),jsx4(MenuItem,{icon:jsx4(Rows,{size:14}),onClick:run(()=>editor.chain().focus().addRowBefore().run()),children:"\u0635\u0641 \u0642\u0628\u0644"}),jsx4(MenuItem,{icon:jsx4(Rows,{size:14}),onClick:run(()=>editor.chain().focus().addRowAfter().run()),children:"\u0635\u0641 \u0628\u0639\u062F"}),jsx4(MenuItem,{danger:true,icon:jsx4(Trash2,{size:14}),onClick:run(()=>editor.chain().focus().deleteRow().run()),children:"\u0627\u062D\u0630\u0641 \u0627\u0644\u0635\u0641"}),jsx4(MenuSeparator,{}),jsx4(MenuItem,{icon:jsx4(Columns,{size:14}),onClick:run(()=>editor.chain().focus().addColumnBefore().run()),children:"\u0639\u0645\u0648\u062F \u0642\u0628\u0644"}),jsx4(MenuItem,{icon:jsx4(Columns,{size:14}),onClick:run(()=>editor.chain().focus().addColumnAfter().run()),children:"\u0639\u0645\u0648\u062F \u0628\u0639\u062F"}),jsx4(MenuItem,{danger:true,icon:jsx4(Trash2,{size:14}),onClick:run(()=>editor.chain().focus().deleteColumn().run()),children:"\u0627\u062D\u0630\u0641 \u0627\u0644\u0639\u0645\u0648\u062F"}),jsx4(MenuSeparator,{}),jsx4(MenuItem,{icon:jsx4(Merge,{size:14}),onClick:run(()=>editor.chain().focus().mergeCells().run()),children:"\u0627\u062F\u0645\u062C \u0627\u0644\u062E\u0644\u0627\u064A\u0627"}),jsx4(MenuItem,{icon:jsx4(Split,{size:14}),onClick:run(()=>editor.chain().focus().splitCell().run()),children:"\u0627\u0642\u0633\u0645 \u0627\u0644\u062E\u0644\u064A\u0629"}),jsx4(MenuSeparator,{}),jsx4(MenuItem,{danger:true,icon:jsx4(Trash2,{size:14}),onClick:run(()=>editor.chain().focus().deleteTable().run()),children:"\u0627\u062D\u0630\u0641 \u0627\u0644\u062C\u062F\u0648\u0644"})]})]})}})}var TEXT_COLORS=["#000000","#434343","#666666","#999999","#E03131","#C2255C","#9C36B5","#6741D9","#3B5BDB","#1971C2","#0C8599","#099268","#2F9E44","#66A80F","#F08C00","#E8590C"];var HIGHLIGHT_COLORS=["#FBBF24","#F87171","#FB923C","#A78BFA","#60A5FA","#34D399","#F472B6","#2DD4BF","#FCD34D","#FCA5A5","#FDBA74","#C4B5FD","#93C5FD","#6EE7B7","#F9A8D4","#99F6E4"];function ColorTool(){const{editor}=useCurrentEditor3();if(!editor)return null;const current=editor.getAttributes("textStyle").color||"";return jsx4(Popover,{trigger:({open,toggle})=>jsx4(ToolbarButton,{onClick:toggle,isActive:open,tooltip:"\u0644\u0648\u0646 \u0627\u0644\u0646\u0635",children:jsxs4("span",{className:"flex flex-col items-center gap-0.5",children:[jsx4(Palette,{size:16,style:current?{color:current}:void 0}),jsx4("span",{"aria-hidden":"true",className:"w-4 h-0.5 rounded-full",style:{background:current||"currentColor"}})]})}),children:({close})=>jsx4(ColorGrid,{colors:TEXT_COLORS,current,fallback:"#000000",clearLabel:"\u0634\u064A\u0644 \u0627\u0644\u0644\u0648\u0646",onPick:c=>{editor.chain().focus().setColor(c).run();close()},onClear:()=>{editor.chain().focus().unsetColor().run();close()}})})}function HighlightTool(){const{editor}=useCurrentEditor3();if(!editor)return null;const current=editor.getAttributes("highlight").color||"";return jsx4(Popover,{trigger:({open,toggle})=>jsx4(ToolbarButton,{onClick:toggle,isActive:editor.isActive("highlight")||open,tooltip:"\u062A\u0638\u0644\u064A\u0644",children:jsxs4("span",{className:"flex flex-col items-center gap-0.5",children:[jsx4(Highlighter2,{size:16}),jsx4("span",{"aria-hidden":"true",className:"w-4 h-0.5 rounded-full",style:{background:current||"transparent"}})]})}),children:({close})=>jsx4(ColorGrid,{colors:HIGHLIGHT_COLORS,current,fallback:"#FBBF24",clearLabel:"\u0634\u064A\u0644 \u0627\u0644\u062A\u0638\u0644\u064A\u0644",onPick:c=>{editor.chain().focus().toggleHighlight({color:c}).run();close()},onClear:()=>{editor.chain().focus().unsetHighlight().run();close()}})})}var DATE_FORMATS=[{label:"\u0663\u0661 \u064A\u0648\u0644\u064A\u0648 \u0662\u0660\u0662\u0666",opts:{day:"numeric",month:"long",year:"numeric"}},{label:"\u0663\u0661 \u064A\u0648\u0644 \u0662\u0660\u0662\u0666",opts:{day:"numeric",month:"short",year:"numeric"}},{label:"\u0627\u0644\u062C\u0645\u0639\u0629\u060C \u0663\u0661 \u064A\u0648\u0644\u064A\u0648",opts:{weekday:"long",day:"numeric",month:"long"}},{label:"\u0662\u0660\u0662\u0666/\u0660\u0667/\u0663\u0661",opts:{year:"numeric",month:"2-digit",day:"2-digit"}},{label:"\u0660\u0662:\u0665\u0661 \u0635",opts:{hour:"2-digit",minute:"2-digit"}},{label:"\u0660\u0662:\u0665\u0661:\u0663\u0660 \u0635",opts:{hour:"2-digit",minute:"2-digit",second:"2-digit"}}];function DateTime({locale="ar-EG"}){const{editor}=useCurrentEditor3();if(!editor)return null;return jsx4(Popover,{width:"w-56",trigger:({open,toggle})=>jsx4(ToolbarButton,{onClick:toggle,isActive:open,tooltip:"\u062A\u0627\u0631\u064A\u062E \u0648\u0648\u0642\u062A",children:jsx4(CalendarClock,{size:16})}),children:({close})=>jsx4("div",{role:"menu",className:"py-1",children:DATE_FORMATS.map(f=>{const text=new Intl.DateTimeFormat(locale,f.opts).format(new Date);return jsx4(MenuItem,{onClick:()=>{editor.chain().focus().insertContent(text).run();close()},children:text},f.label)})})})}import{useCallback as useCallback2,useState as useState3}from"react";import{useCurrentEditor as useCurrentEditor4}from"@tiptap/react";import{ChevronDown as ChevronDown2,ChevronUp,Replace,Search}from"lucide-react";import{Fragment as Fragment3,jsx as jsx5,jsxs as jsxs5}from"react/jsx-runtime";function FindReplace(){const{editor}=useCurrentEditor4();const[term,setTerm]=useState3("");const[replacement,setReplacement]=useState3("");const[matches,setMatches]=useState3([]);const[index,setIndex]=useState3(0);const jump=useCallback2(m=>editor?.chain().setTextSelection(m).scrollIntoView().run(),[editor]);const find=useCallback2(value=>{if(!editor||!value.trim()){setMatches([]);setIndex(0);return}const found=[];const needle=value.toLowerCase();editor.state.doc.descendants((node,pos)=>{if(!node.isText)return;const text=node.text?.toLowerCase()??"";let at=text.indexOf(needle);while(at!==-1){found.push({from:pos+at,to:pos+at+value.length});at=text.indexOf(needle,at+1)}});setMatches(found);setIndex(0);if(found[0])jump(found[0])},[editor,jump]);if(!editor)return null;const step=by=>{if(matches.length===0)return;const next=(index+by+matches.length)%matches.length;setIndex(next);jump(matches[next])};const replaceOne=()=>{const m=matches[index];if(!m)return;editor.chain().focus().setTextSelection(m).insertContent(replacement).run();find(term)};const replaceAll=()=>{if(matches.length===0)return;const chain=editor.chain().focus();for(const m of[...matches].sort((a,b)=>b.from-a.from)){chain.setTextSelection(m).insertContent(replacement)}chain.run();find(term)};return jsx5(Popover,{width:"w-72",trigger:({open,toggle})=>jsx5(ToolbarButton,{onClick:toggle,isActive:open,tooltip:"\u0628\u062D\u062B \u0648\u0627\u0633\u062A\u0628\u062F\u0627\u0644",shortcut:"Ctrl+H",children:jsx5(Search,{size:16})}),children:()=>jsxs5("div",{className:"p-3 flex flex-col gap-2.5",children:[jsxs5("div",{className:"flex items-end gap-1.5",children:[jsx5(Input,{autoFocus:true,size:"sm",label:"\u0627\u0628\u062D\u062B \u0639\u0646",hideLabel:true,placeholder:"\u0627\u0628\u062D\u062B \u0639\u0646\u2026",value:term,wrapperClassName:"flex-1 min-w-0",onChange:e=>{setTerm(e.target.value);find(e.target.value)},onKeyDown:e=>{if(e.key!=="Enter")return;e.preventDefault();step(e.shiftKey?-1:1)}}),jsx5(Button,{size:"sm",variant:"outline",iconOnly:true,"aria-label":"\u0627\u0644\u0633\u0627\u0628\u0642",disabled:matches.length===0,onClick:()=>step(-1),icon:jsx5(ChevronUp,{size:14})}),jsx5(Button,{size:"sm",variant:"outline",iconOnly:true,"aria-label":"\u0627\u0644\u062A\u0627\u0644\u064A",disabled:matches.length===0,onClick:()=>step(1),icon:jsx5(ChevronDown2,{size:14})})]}),term.trim()&&jsx5("span",{className:"text-micro text-muted2","aria-live":"polite",children:matches.length>0?jsxs5(Fragment3,{children:[jsx5("span",{"data-num":true,children:index+1})," \u0645\u0646 ",jsx5("span",{"data-num":true,children:matches.length})]}):"\u0645\u0627\u0641\u064A\u0634 \u0646\u062A\u0627\u064A\u062C"}),jsxs5("div",{className:"flex items-end gap-1.5",children:[jsx5(Input,{size:"sm",label:"\u0627\u0633\u062A\u0628\u062F\u0644 \u0628\u0640",hideLabel:true,placeholder:"\u0627\u0633\u062A\u0628\u062F\u0644 \u0628\u0640\u2026",value:replacement,wrapperClassName:"flex-1 min-w-0",onChange:e=>setReplacement(e.target.value),onKeyDown:e=>{if(e.key==="Enter"){e.preventDefault();replaceOne()}}}),jsx5(Button,{size:"sm",variant:"outline",iconOnly:true,"aria-label":"\u0627\u0633\u062A\u0628\u062F\u0644",disabled:matches.length===0,onClick:replaceOne,icon:jsx5(Replace,{size:14})})]}),jsx5(Button,{size:"sm",variant:"soft",block:true,disabled:matches.length===0,onClick:replaceAll,children:"\u0627\u0633\u062A\u0628\u062F\u0644 \u0627\u0644\u0643\u0644"})]})})}import{jsx as jsx6,jsxs as jsxs6}from"react/jsx-runtime";function useEditorTick(){const[,setTick]=useState4(0);const{editor}=useCurrentEditor5();const raf=useRef3(0);useEffect2(()=>{if(!editor)return;const bump=()=>{cancelAnimationFrame(raf.current);raf.current=requestAnimationFrame(()=>setTick(t=>t+1))};editor.on("selectionUpdate",bump);editor.on("transaction",bump);return()=>{cancelAnimationFrame(raf.current);editor.off("selectionUpdate",bump);editor.off("transaction",bump)}},[editor])}function Toolbar({basic,onPickImage,hideImage,locale}){useEditorTick();const{editor}=useCurrentEditor5();if(!editor)return null;if(basic){return jsxs6("div",{className:"w-full border-b border-line px-1.5 py-1 flex flex-wrap items-center gap-0.5",children:[jsx6(ToolbarGroup,{children:jsx6(UndoRedo,{})}),jsx6(ToolbarGroup,{children:jsx6(HeadingSelector,{})}),jsxs6(ToolbarGroup,{children:[jsx6(Bold2,{}),jsx6(Italic2,{}),jsx6(Underline3,{})]}),jsxs6(ToolbarGroup,{children:[jsx6(BulletList,{}),jsx6(OrderedList,{})]}),jsxs6(ToolbarGroup,{children:[jsx6(Link3,{}),!hideImage&&jsx6(ImageTool,{onPick:onPickImage}),jsx6(ColorTool,{})]})]})}return jsxs6("div",{className:"w-full border-b border-line px-1.5 py-1.5 flex flex-wrap items-center gap-y-1",children:[jsx6(ToolbarGroup,{children:jsx6(UndoRedo,{})}),jsx6(ToolbarGroup,{children:jsx6(HeadingSelector,{})}),jsxs6(ToolbarGroup,{children:[jsx6(Bold2,{}),jsx6(Italic2,{}),jsx6(Underline3,{}),jsx6(Strikethrough2,{})]}),jsxs6(ToolbarGroup,{children:[jsx6(BulletList,{}),jsx6(OrderedList,{}),jsx6(BlockQuote,{})]}),jsx6(ToolbarGroup,{children:jsx6(Alignment,{})}),jsxs6(ToolbarGroup,{children:[jsx6(Link3,{}),!hideImage&&jsx6(ImageTool,{onPick:onPickImage}),jsx6(TableTool,{}),jsx6(DateTime,{locale})]}),jsxs6(ToolbarGroup,{children:[jsx6(ColorTool,{}),jsx6(HighlightTool,{})]}),jsxs6(ToolbarGroup,{children:[jsx6(Code2,{}),jsx6(HorizontalRule,{}),jsx6(ClearMarks,{}),jsx6(FindReplace,{})]})]})}function EditorFooter({maxChars}){return jsx6("div",{className:"border-t border-line px-3 py-1.5 flex justify-end",children:jsx6(CharacterCount,{maxChars})})}import{forwardRef,useEffect as useEffect3,useImperativeHandle,useState as useState5}from"react";import{Extension}from"@tiptap/core";import{PluginKey as PluginKey2}from"@tiptap/pm/state";import{ReactRenderer}from"@tiptap/react";import Suggestion from"@tiptap/suggestion";import{jsx as jsx7,jsxs as jsxs7}from"react/jsx-runtime";var SLASH_ITEMS=[{title:"\u0639\u0646\u0648\u0627\u0646 \u0643\u0628\u064A\u0631",hint:"H1",icon:"H1",command:({editor,range})=>editor.chain().focus().deleteRange(range).setHeading({level:1}).run()},{title:"\u0639\u0646\u0648\u0627\u0646 \u0645\u062A\u0648\u0633\u0637",hint:"H2",icon:"H2",command:({editor,range})=>editor.chain().focus().deleteRange(range).setHeading({level:2}).run()},{title:"\u0639\u0646\u0648\u0627\u0646 \u0635\u063A\u064A\u0631",hint:"H3",icon:"H3",command:({editor,range})=>editor.chain().focus().deleteRange(range).setHeading({level:3}).run()},{title:"\u0642\u0627\u0626\u0645\u0629 \u0646\u0642\u0637\u064A\u0629",icon:"\u2022",command:({editor,range})=>editor.chain().focus().deleteRange(range).toggleBulletList().run()},{title:"\u0642\u0627\u0626\u0645\u0629 \u0645\u0631\u0642\u0651\u0645\u0629",icon:"\u0661.",command:({editor,range})=>editor.chain().focus().deleteRange(range).toggleOrderedList().run()},{title:"\u0627\u0642\u062A\u0628\u0627\u0633",icon:"\u275D",command:({editor,range})=>editor.chain().focus().deleteRange(range).toggleBlockquote().run()},{title:"\u0628\u0644\u0648\u0643 \u0643\u0648\u062F",icon:"</>",command:({editor,range})=>editor.chain().focus().deleteRange(range).toggleCodeBlock().run()},{title:"\u062C\u062F\u0648\u0644",hint:"\u0663\xD7\u0663",icon:"\u229E",command:({editor,range})=>editor.chain().focus().deleteRange(range).insertTable({rows:3,cols:3,withHeaderRow:true}).run()},{title:"\u0641\u0627\u0635\u0644 \u0623\u0641\u0642\u064A",icon:"\u2500",command:({editor,range})=>editor.chain().focus().deleteRange(range).setHorizontalRule().run()}];var SlashList=forwardRef(function SlashList2({items,command},ref){const[active,setActive]=useState5(0);useEffect3(()=>setActive(0),[items]);useImperativeHandle(ref,()=>({onKeyDown:({event})=>{if(event.key==="ArrowUp"){setActive(i=>i<=0?items.length-1:i-1);return true}if(event.key==="ArrowDown"){setActive(i=>i>=items.length-1?0:i+1);return true}if(event.key==="Enter"){const item=items[active];if(item)command(item);return true}return false}}));if(items.length===0)return null;return jsx7("div",{className:"w-64 max-h-72 overflow-y-auto rounded-card border border-line bg-surface shadow-pop py-1 animate-[fade-in_.12s_ease-out]",children:items.map((item,i)=>jsxs7("button",{type:"button",onMouseEnter:()=>setActive(i),onClick:()=>command(item),className:cn("w-full px-3 py-2 flex items-center gap-3 text-start cursor-pointer transition-colors",i===active?"bg-soft text-brand-ink":"text-ink2 hover:bg-hover"),children:[jsx7("span",{"aria-hidden":"true",className:"size-7 shrink-0 rounded-sm bg-bg border border-line flex items-center justify-center text-micro font-extrabold",children:item.icon}),jsx7("span",{className:"flex-1 min-w-0 text-ui font-bold truncate",children:item.title}),item.hint&&jsx7("span",{dir:"ltr",className:"text-micro text-muted2 shrink-0",children:item.hint})]},item.title))})});var SlashCommandsPluginKey=new PluginKey2("qumraSlashCommands");var SlashCommands=Extension.create({name:"qumraSlashCommands",addOptions(){return{suggestion:{char:"/",pluginKey:SlashCommandsPluginKey,command:({editor,range,props})=>{props.command({editor,range})}}}},addProseMirrorPlugins(){return[Suggestion({editor:this.editor,...this.options.suggestion})]}});function place(el,rect){const rtl=getComputedStyle(document.documentElement).direction==="rtl";const gap=6;const{offsetHeight:h,offsetWidth:w}=el;const below=window.innerHeight-rect.bottom;const top=below<h+gap&&rect.top>h+gap?rect.top-h-gap:rect.bottom+gap;let left=rtl?rect.right-w:rect.left;left=Math.max(8,Math.min(left,window.innerWidth-w-8));el.style.top=`${top+window.scrollY}px`;el.style.left=`${left+window.scrollX}px`}function createSlashSuggestion(){return{items:({query})=>!query?SLASH_ITEMS:SLASH_ITEMS.filter(i=>i.title.includes(query)||i.icon.toLowerCase().includes(query.toLowerCase())),render:()=>{let component=null;let host=null;const reposition=clientRect=>{const rect=clientRect?.();if(host&&rect)place(host,rect)};return{onStart:props=>{component=new ReactRenderer(SlashList,{props,editor:props.editor});host=document.createElement("div");host.style.position="absolute";host.style.zIndex="60";host.appendChild(component.element);document.body.appendChild(host);reposition(props.clientRect)},onUpdate:props=>{component?.updateProps(props);reposition(props.clientRect)},onKeyDown:props=>{if(props.event.key==="Escape"){host?.remove();return true}const api=component?.ref;return api?.onKeyDown?.(props)??false},onExit:()=>{host?.remove();component?.destroy();host=null;component=null}}}}}import{jsx as jsx8,jsxs as jsxs8}from"react/jsx-runtime";function Editor({content,onChange,placeholder,maxChars,basic,disabled,onPickImage,hideImage,locale="ar-EG",className}){const extensions=useMemo2(()=>[...contentExtensions(),Placeholder.configure({placeholder:placeholder??""}),CharacterCount2.configure(maxChars?{limit:maxChars}:{}),Dropcursor.configure({color:"var(--color-brand)",width:2}),SlashCommands.configure({suggestion:createSlashSuggestion()})],[placeholder,maxChars]);const lastEmitted=useRef4("");const[initialContent]=useState6(()=>content||"");const editorProps=useMemo2(()=>({attributes:{class:"qumra-tiptap",dir:"auto"},handleDrop:(view,event,_slice,moved)=>{if(moved||!event.dataTransfer?.files?.length)return false;const file=event.dataTransfer.files[0];if(!file?.type.startsWith("image/"))return false;const reader=new FileReader;reader.onload=()=>{const at=view.posAtCoords({left:event.clientX,top:event.clientY});if(!at)return;const node=view.state.schema.nodes.image.create({src:reader.result});view.dispatch(view.state.tr.insert(at.pos,node))};reader.readAsDataURL(file);return true},handlePaste:(view,event)=>{const items=event.clipboardData?.items;if(!items)return false;for(const item of Array.from(items)){if(!item.type.startsWith("image/"))continue;const file=item.getAsFile();if(!file)continue;const reader=new FileReader;reader.onload=()=>{const node=view.state.schema.nodes.image.create({src:reader.result});view.dispatch(view.state.tr.insert(view.state.selection.from,node))};reader.readAsDataURL(file);return true}return false}}),[]);const handleUpdate=({editor})=>{const html=editor.getHTML();if(html===lastEmitted.current)return;lastEmitted.current=html;onChange(html)};return jsx8("div",{className:cn("relative","bg-surface border border-border rounded-field","focus-within:border-brand transition-colors","[&>*:first-child]:rounded-t-field",disabled&&"opacity-60 pointer-events-none",className),children:jsxs8(EditorProvider,{immediatelyRender:false,extensions,content:initialContent,onUpdate:handleUpdate,slotBefore:!disabled&&jsx8(Toolbar,{basic,onPickImage,hideImage,locale}),slotAfter:!disabled&&jsx8(EditorFooter,{maxChars}),editorProps,children:[jsx8(EditorBubbleMenu,{}),jsx8(SyncContent,{content,disabled,lastEmitted})]})})}function SyncContent({content,disabled,lastEmitted}){const{editor}=useCurrentEditor6();useEffect4(()=>{if(!editor)return;const incoming=content||"";if(incoming!==editor.getHTML()){editor.commands.setContent(incoming,{emitUpdate:false});lastEmitted.current=editor.getHTML()}if(editor.isEditable===Boolean(disabled)){editor.setEditable(!disabled,false)}},[content,disabled,editor,lastEmitted]);return null}import{generateHTML,generateJSON}from"@tiptap/core";function emptyDoc(){return{type:"doc",content:[{type:"paragraph"}]}}function htmlToDoc(html){try{return generateJSON(html?.trim()?html:"<p></p>",contentExtensions())}catch{return emptyDoc()}}function docToHtml(doc){if(!isDoc(doc))return"";try{return generateHTML(doc,contentExtensions())}catch{return""}}function isDoc(value){return!!value&&typeof value==="object"&&!Array.isArray(value)&&value.type==="doc"}export{Editor,docToHtml,htmlToDoc,isDoc};