@nice2dev/ui-video 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),re=require("@nice2dev/ui"),l=require("@nice2dev/ui-core"),d=require("react"),ce={id:l.createId(),name:"Untitled Project",resolution:{width:1920,height:1080,label:"1080p"},frameRate:30,duration:0,tracks:[{id:"1",type:"video",name:"Video 1",items:[],muted:!1,locked:!1,visible:!0},{id:"2",type:"audio",name:"Audio 1",items:[],muted:!1,locked:!1,visible:!0}],assets:[],settings:{backgroundColor:"#000000",audio:{sampleRate:48e3,channels:2,bitrate:320},video:{codec:"h264",bitrate:8e3,profile:"high"}}},le=[{type:"blur",name:"Blur",icon:"droplet"},{type:"brightness",name:"Brightness",icon:"sun"},{type:"contrast",name:"Contrast",icon:"moon"},{type:"saturation",name:"Saturation",icon:"palette"},{type:"grayscale",name:"Grayscale",icon:"square"},{type:"sepia",name:"Sepia",icon:"image"},{type:"chromaKey",name:"Chroma Key",icon:"layers"},{type:"crop",name:"Crop",icon:"crop"},{type:"zoom",name:"Zoom",icon:"search"}],de=[{type:"fade",name:"Fade"},{type:"dissolve",name:"Dissolve"},{type:"wipe",name:"Wipe"},{type:"slide",name:"Slide"},{type:"zoom",name:"Zoom"},{type:"push",name:"Push"}],ue=[{target:".nice-video-editor",titleKey:"tutorial.videoEditorPro.intro.title",title:"Video editor",contentKey:"tutorial.videoEditorPro.intro.content",content:"Add media to the timeline, arrange and trim clips, apply effects and transitions, then configure and run the export.",placement:"auto"}],me=({project:R,onProjectChange:C,onExport:$,onAssetUpload:A,className:P="",tutorial:z})=>{const[u,i]=d.useState(R||ce),[_,f]=d.useState("timeline"),[O,h]=d.useState(null),[g,b]=d.useState(null),[T,N]=d.useState(0),[F,L]=d.useState(!1),[y,K]=d.useState(1),[U,S]=d.useState(!0),[I,D]=d.useState(null),J=d.useRef(null),Q=d.useRef(null),w=d.useRef(null);d.useEffect(()=>{R&&i(R)},[R]),d.useEffect(()=>()=>{w.current&&clearInterval(w.current)},[]);const j=d.useCallback(t=>{const o={...u,...t};i(o),C==null||C(o)},[u,C]),v=async t=>{const o=[];for(const a of Array.from(t)){const c=a.type.startsWith("video/")?"video":a.type.startsWith("audio/")?"audio":"image";let m;A?m=await A(a):m={id:l.createId(),type:c,name:a.name,url:URL.createObjectURL(a),size:a.size},o.push(m)}j({assets:[...u.assets,...o]})},E=t=>{const o={id:l.createId(),type:t,name:`${t.charAt(0).toUpperCase()+t.slice(1)} ${u.tracks.filter(a=>a.type===t).length+1}`,items:[],muted:!1,locked:!1,visible:!0};j({tracks:[...u.tracks,o]})},q=t=>{j({tracks:u.tracks.filter(o=>o.id!==t)}),O===t&&h(null)},V=t=>{j({tracks:u.tracks.map(o=>o.id===t?{...o,muted:!o.muted}:o)})},Y=t=>{j({tracks:u.tracks.map(o=>o.id===t?{...o,locked:!o.locked}:o)})},k=(t,o)=>{const a=u.tracks.find(x=>x.id===t);if(!a||a.locked)return;const c=a.items[a.items.length-1],m=c?c.startTime+c.duration:0,p={id:l.createId(),assetId:o.id,type:o.type,startTime:m,duration:o.duration||5,offset:0,properties:{x:0,y:0,opacity:1,scale:1,volume:1},effects:[],transitions:[]};j({tracks:u.tracks.map(x=>x.id===t?{...x,items:[...x.items,p]}:x)})},W=(t,o,a)=>{const c={id:l.createId(),type:a,name:a.charAt(0).toUpperCase()+a.slice(1),parameters:X(a)};j({tracks:u.tracks.map(m=>m.id===t?{...m,items:m.items.map(p=>p.id===o?{...p,effects:[...p.effects,c]}:p)}:m)})},M=(t,o,a,c)=>{const m={id:l.createId(),type:a,duration:.5,position:c};j({tracks:u.tracks.map(p=>p.id===t?{...p,items:p.items.map(x=>x.id===o?{...x,transitions:[...x.transitions,m]}:x)}:p)})},X=t=>{switch(t){case"blur":return{radius:5};case"brightness":return{value:100};case"contrast":return{value:100};case"saturation":return{value:100};case"grayscale":return{amount:100};case"sepia":return{amount:100};case"chromaKey":return{color:"var(--nice-success, #00ff00)",threshold:40};case"crop":return{top:0,right:0,bottom:0,left:0};case"zoom":return{scale:1,x:0,y:0};default:return{}}},ee=()=>{F?(w.current&&clearInterval(w.current),L(!1)):(w.current=setInterval(()=>{N(t=>{const o=Math.max(...u.tracks.flatMap(a=>a.items.map(c=>c.startTime+c.duration)),0);return t>=o?(clearInterval(w.current),L(!1),0):t+1/u.frameRate})},1e3/u.frameRate),L(!0))},H=t=>{N(Math.max(0,t))},G=async()=>{if($){D(0);try{const t=setInterval(()=>{D(o=>o!==null&&o<90?o+Math.random()*10:o)},500);await $(u,u.settings.video.codec),clearInterval(t),D(100),setTimeout(()=>D(null),2e3)}catch(t){D(null),console.error("Export failed:",t)}}},Z=t=>{const o=Math.floor(t/60),a=Math.floor(t%60),c=Math.floor(t%1*u.frameRate);return`${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}:${c.toString().padStart(2,"0")}`},B=()=>{for(const t of u.tracks){const o=t.items.find(a=>a.id===g);if(o)return{track:t,item:o}}return null},se=e.jsxs("header",{className:"video-editor__header",children:[e.jsxs("div",{className:"header__project-info",children:[e.jsx("input",{type:"text",value:u.name,onChange:t=>j({name:t.target.value}),className:"project-name-input"}),e.jsxs("span",{className:"project-settings",children:[u.resolution.width,"x",u.resolution.height," • ",u.frameRate,"fps"]})]}),e.jsx("div",{className:"header__tabs",children:["timeline","effects","transitions","export"].map(t=>e.jsx("button",{className:`tab-button ${_===t?"tab-button--active":""}`,onClick:()=>f(t),children:t.charAt(0).toUpperCase()+t.slice(1)},t))}),e.jsx("div",{className:"header__actions",children:e.jsx("button",{className:"action-button action-button--primary",onClick:G,disabled:I!==null,children:I!==null?`Exporting ${Math.round(I)}%`:"Export"})})]}),ae=g&&_!=="export"?(()=>{const t=B();if(!t)return null;const{track:o,item:a}=t;return e.jsxs("div",{className:"item-inspector",children:[e.jsx("h4",{children:"Item Properties"}),e.jsxs("div",{className:"inspector-section",children:[e.jsxs("label",{children:["Start Time",e.jsx("input",{type:"number",step:"0.1",value:a.startTime,onChange:c=>{const m=parseFloat(c.target.value);j({tracks:u.tracks.map(p=>p.id===o.id?{...p,items:p.items.map(x=>x.id===a.id?{...x,startTime:m}:x)}:p)})}})]}),e.jsxs("label",{children:["Duration",e.jsx("input",{type:"number",step:"0.1",value:a.duration,onChange:c=>{const m=parseFloat(c.target.value);j({tracks:u.tracks.map(p=>p.id===o.id?{...p,items:p.items.map(x=>x.id===a.id?{...x,duration:m}:x)}:p)})}})]}),e.jsxs("label",{children:["Opacity",e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:a.properties.opacity??1,onChange:c=>{const m=parseFloat(c.target.value);j({tracks:u.tracks.map(p=>p.id===o.id?{...p,items:p.items.map(x=>x.id===a.id?{...x,properties:{...x.properties,opacity:m}}:x)}:p)})}})]})]}),e.jsxs("h4",{children:["Effects (",a.effects.length,")"]}),e.jsx("div",{className:"effects-list",children:a.effects.map(c=>e.jsx("div",{className:"effect-badge",children:c.name},c.id))})]})})():null,s=U?e.jsxs("aside",{className:"video-editor__asset-library",children:[e.jsxs("div",{className:"asset-library__header",children:[e.jsx("h3",{children:"Assets"}),e.jsx("button",{"aria-label":"Close",className:"close-button",onClick:()=>S(!1),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]}),e.jsx("div",{className:"asset-library__upload",children:e.jsxs("label",{className:"upload-zone",children:[e.jsx("input",{type:"file",multiple:!0,accept:"video/*,audio/*,image/*",onChange:t=>t.target.files&&v(t.target.files),hidden:!0}),e.jsx("span",{className:"upload-icon",children:"+"}),e.jsx("span",{children:"Drop files or click to upload"})]})}),e.jsx("div",{className:"asset-library__list",children:u.assets.map(t=>e.jsxs("div",{className:"asset-item",draggable:!0,onDragStart:o=>o.dataTransfer.setData("assetId",t.id),children:[e.jsx("div",{className:"asset-thumbnail",children:t.thumbnail?e.jsx("img",{src:t.thumbnail,alt:t.name}):e.jsx("span",{className:"asset-type-icon",children:e.jsx(l.NiceIcon,{name:t.type==="video"?"video":t.type==="audio"?"music":"image",size:24})})}),e.jsxs("div",{className:"asset-info",children:[e.jsx("span",{className:"asset-name",children:t.name}),e.jsxs("span",{className:"asset-meta",children:[(t.size/1024/1024).toFixed(1),"MB"]})]})]},t.id))})]}):void 0,n=e.jsx("div",{className:"video-editor__preview-area",children:e.jsxs("div",{className:"preview-container",children:[e.jsxs("div",{className:"preview-canvas",style:{aspectRatio:`${u.resolution.width}/${u.resolution.height}`},children:[e.jsx("video",{ref:Q,className:"preview-video"}),e.jsx("div",{className:"preview-overlay",children:!U&&e.jsx("button",{className:"toggle-library-button",onClick:()=>S(!0),"aria-label":"Show asset library",children:e.jsx(l.NiceIcon,{name:"folder",size:16})})})]}),e.jsxs("div",{className:"playback-controls",children:[e.jsx("button",{onClick:()=>H(0),"aria-label":"Go to start",children:e.jsx(l.NiceIcon,{name:"skip-back",size:16})}),e.jsx("button",{onClick:()=>H(T-1/u.frameRate),"aria-label":"Previous frame",children:e.jsx(l.NiceIcon,{name:"chevron-left",size:16})}),e.jsx("button",{onClick:ee,className:"play-button","aria-label":F?"Pause":"Play",children:e.jsx(l.NiceIcon,{name:F?"pause":"play",size:18})}),e.jsx("button",{onClick:()=>H(T+1/u.frameRate),"aria-label":"Next frame",children:e.jsx(l.NiceIcon,{name:"chevron-right",size:16})}),e.jsx("span",{className:"time-display",children:Z(T)})]})]})}),r=e.jsxs("div",{className:"video-editor__panel",children:[_==="timeline"&&e.jsxs("div",{className:"timeline-panel",children:[e.jsxs("div",{className:"timeline-toolbar",children:[e.jsxs("div",{className:"track-buttons",children:[e.jsx("button",{onClick:()=>E("video"),children:"+ Video Track"}),e.jsx("button",{onClick:()=>E("audio"),children:"+ Audio Track"}),e.jsx("button",{onClick:()=>E("text"),children:"+ Text Track"})]}),e.jsxs("div",{className:"zoom-controls",children:[e.jsx("button",{onClick:()=>K(Math.max(.25,y-.25)),children:"-"}),e.jsxs("span",{children:[Math.round(y*100),"%"]}),e.jsx("button",{onClick:()=>K(Math.min(4,y+.25)),children:"+"})]})]}),e.jsxs("div",{className:"timeline-container",ref:J,children:[e.jsx("div",{className:"timeline-ruler",children:Array.from({length:Math.ceil(30/y)}).map((t,o)=>e.jsx("div",{className:"ruler-mark",style:{left:`${o*50*y}px`},children:Z(o)},o))}),e.jsx("div",{className:"timeline-playhead",style:{left:`${T*50*y}px`}}),e.jsx("div",{className:"timeline-tracks",children:u.tracks.map(t=>e.jsxs("div",{className:`timeline-track ${O===t.id?"timeline-track--selected":""} ${t.locked?"timeline-track--locked":""}`,onClick:()=>h(t.id),onDrop:o=>{o.preventDefault();const a=o.dataTransfer.getData("assetId"),c=u.assets.find(m=>m.id===a);c&&k(t.id,c)},onDragOver:o=>o.preventDefault(),children:[e.jsxs("div",{className:"track-header",children:[e.jsx("span",{className:"track-name",children:t.name}),e.jsxs("div",{className:"track-controls",children:[e.jsx("button",{className:t.muted?"active":"",onClick:o=>{o.stopPropagation(),V(t.id)},children:e.jsx(l.NiceIcon,{name:t.muted?"volume-off":"volume",size:14})}),e.jsx("button",{className:t.locked?"active":"",onClick:o=>{o.stopPropagation(),Y(t.id)},children:e.jsx(l.NiceIcon,{name:t.locked?"lock":"unlock",size:14})}),e.jsx("button",{onClick:o=>{o.stopPropagation(),q(t.id)},"aria-label":"Remove track",children:e.jsx(l.NiceIcon,{name:"trash",size:14})})]})]}),e.jsx("div",{className:"track-items",children:t.items.map(o=>{const a=u.assets.find(c=>c.id===o.assetId);return e.jsxs("div",{className:`track-item track-item--${o.type} ${g===o.id?"track-item--selected":""}`,style:{left:`${o.startTime*50*y}px`,width:`${o.duration*50*y}px`},onClick:c=>{c.stopPropagation(),b(o.id)},children:[e.jsx("span",{className:"item-name",children:(a==null?void 0:a.name)||"Untitled"}),o.transitions.length>0&&e.jsx("span",{className:"item-transitions",children:e.jsx(l.NiceIcon,{name:"wand",size:12})}),o.effects.length>0&&e.jsx("span",{className:"item-effects",children:e.jsx(l.NiceIcon,{name:"palette",size:12})})]},o.id)})})]},t.id))})]})]}),_==="effects"&&e.jsxs("div",{className:"effects-panel",children:[e.jsx("h3",{children:"Video Effects"}),e.jsx("p",{className:"panel-hint",children:"Select a clip to apply effects"}),e.jsx("div",{className:"effects-grid",children:le.map(t=>e.jsxs("button",{className:"effect-preset",disabled:!g,onClick:()=>{const o=B();o&&W(o.track.id,o.item.id,t.type)},children:[e.jsx("span",{className:"effect-icon",children:e.jsx(l.NiceIcon,{name:t.icon,size:16})}),e.jsx("span",{className:"effect-name",children:t.name})]},t.type))})]}),_==="transitions"&&e.jsxs("div",{className:"transitions-panel",children:[e.jsx("h3",{children:"Transitions"}),e.jsx("p",{className:"panel-hint",children:"Select a clip and add transitions between clips"}),e.jsx("div",{className:"transitions-grid",children:de.map(t=>e.jsxs("div",{className:"transition-preset",children:[e.jsx("span",{className:"transition-name",children:t.name}),e.jsxs("div",{className:"transition-buttons",children:[e.jsx("button",{disabled:!g,onClick:()=>{const o=B();o&&M(o.track.id,o.item.id,t.type,"start")},children:"In"}),e.jsx("button",{disabled:!g,onClick:()=>{const o=B();o&&M(o.track.id,o.item.id,t.type,"end")},children:"Out"})]})]},t.type))})]}),_==="export"&&e.jsxs("div",{className:"export-panel",children:[e.jsx("h3",{children:"Export Settings"}),e.jsxs("div",{className:"export-settings",children:[e.jsxs("div",{className:"setting-group",children:[e.jsx("label",{children:"Resolution"}),e.jsxs("select",{value:`${u.resolution.width}x${u.resolution.height}`,onChange:t=>{const[o,a]=t.target.value.split("x").map(Number);j({resolution:{width:o,height:a}})},children:[e.jsx("option",{value:"1920x1080",children:"1080p (1920x1080)"}),e.jsx("option",{value:"2560x1440",children:"1440p (2560x1440)"}),e.jsx("option",{value:"3840x2160",children:"4K (3840x2160)"}),e.jsx("option",{value:"1280x720",children:"720p (1280x720)"})]})]}),e.jsxs("div",{className:"setting-group",children:[e.jsx("label",{children:"Frame Rate"}),e.jsxs("select",{value:u.frameRate,onChange:t=>j({frameRate:parseInt(t.target.value)}),children:[e.jsx("option",{value:"24",children:"24 fps"}),e.jsx("option",{value:"30",children:"30 fps"}),e.jsx("option",{value:"60",children:"60 fps"}),e.jsx("option",{value:"120",children:"120 fps"})]})]}),e.jsxs("div",{className:"setting-group",children:[e.jsx("label",{children:"Video Codec"}),e.jsxs("select",{value:u.settings.video.codec,onChange:t=>j({settings:{...u.settings,video:{...u.settings.video,codec:t.target.value}}}),children:[e.jsx("option",{value:"h264",children:"H.264 (Best Compatibility)"}),e.jsx("option",{value:"h265",children:"H.265/HEVC (Smaller Size)"}),e.jsx("option",{value:"vp9",children:"VP9 (Web Optimized)"}),e.jsx("option",{value:"av1",children:"AV1 (Future Standard)"})]})]}),e.jsxs("div",{className:"setting-group",children:[e.jsx("label",{children:"Video Bitrate (Mbps)"}),e.jsx("input",{type:"number",value:u.settings.video.bitrate/1e3,onChange:t=>j({settings:{...u.settings,video:{...u.settings.video,bitrate:parseFloat(t.target.value)*1e3}}}),min:"1",max:"100"})]})]}),e.jsx("button",{className:"export-button",onClick:G,disabled:I!==null,children:I!==null?`Exporting... ${Math.round(I)}%`:"Export Video"}),I!==null&&e.jsx("div",{className:"export-progress",children:e.jsx("div",{className:"export-progress-bar",style:{width:`${I}%`}})})]})]});return e.jsxs(re.NiceAppShell,{flush:!0,className:`nice-video-editor ${P}`,height:"100%",style:{position:"relative",minHeight:600},toolbar:se,sidebar:s,rightSidebar:ae??void 0,bottomPanel:r,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(l.NiceTutorialButton,{steps:l.resolveTutorial(z,ue)})}),n]})},he={video:{source:"screen",showCursor:!0,frameRate:30,resolution:{width:1920,height:1080}},audio:{enabled:!0,source:"both",echoCancellation:!0,noiseSuppression:!0},output:{format:"webm",quality:"high"}},pe=({options:R,onRecordingStart:C,onRecordingStop:$,onRecordingPause:A,onRecordingResume:P,onError:z,className:u=""})=>{var t,o;const[i,_]=d.useState({...he,...R}),[f,O]=d.useState(null),[h,g]=d.useState("idle"),[b,T]=d.useState([]),[N,F]=d.useState(null),[L,y]=d.useState(null),[K,U]=d.useState(!1),[S,I]=d.useState(!1),[D,J]=d.useState("pen"),[Q,w]=d.useState("var(--nice-danger, #ff0000)"),j=d.useRef(null),v=d.useRef([]),E=d.useRef(null),q=d.useRef(null),V=d.useRef(null),Y=d.useRef(0);d.useEffect(()=>()=>{N&&N.getTracks().forEach(a=>a.stop()),V.current&&clearInterval(V.current)},[N]);const k=a=>{_(c=>({...c,...a,video:{...c.video,...a.video},audio:{...c.audio,...a.audio},output:{...c.output,...a.output}}))},W=async()=>{try{g("preparing");const a={video:{cursor:i.video.showCursor?"always":"never",frameRate:i.video.frameRate},audio:i.audio.source==="system"||i.audio.source==="both"},c=await navigator.mediaDevices.getDisplayMedia(a);if(i.audio.enabled&&(i.audio.source==="microphone"||i.audio.source==="both"))try{(await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:i.audio.echoCancellation,noiseSuppression:i.audio.noiseSuppression}})).getAudioTracks().forEach(p=>c.addTrack(p))}catch(m){console.warn("Could not access microphone:",m)}F(c),E.current&&(E.current.srcObject=c,E.current.play()),g("idle")}catch(a){g("error"),z==null||z(a instanceof Error?a:new Error("Failed to start preview"))}},M=async()=>{N||await W();for(let a=3;a>0;a--)y(a),await new Promise(c=>setTimeout(c,1e3));y(null);try{const a=N||await X();if(!a)throw new Error("No stream available");const c=se(i.output.format),m=new MediaRecorder(a,{mimeType:c,videoBitsPerSecond:ae(i.output.quality)});v.current=[],m.ondataavailable=x=>{x.data.size>0&&v.current.push(x.data)},m.onstop=()=>{const x=new Blob(v.current,{type:c});f&&($==null||$({...f,status:"stopped"},x))},j.current=m,m.start(1e3),Y.current=Date.now();const p={id:l.createId(),status:"recording",startTime:new Date,duration:0,size:0,options:i,chunks:[]};O(p),g("recording"),C==null||C(p),V.current=setInterval(()=>{O(x=>x?{...x,duration:(Date.now()-Y.current)/1e3,size:v.current.reduce((ne,oe)=>ne+oe.size,0)}:null)},100)}catch(a){g("error"),z==null||z(a instanceof Error?a:new Error("Failed to start recording"))}},X=async()=>(await W(),N),ee=()=>{j.current&&h==="recording"&&(j.current.pause(),g("paused"),A==null||A())},H=()=>{j.current&&h==="paused"&&(j.current.resume(),g("recording"),P==null||P())},G=()=>{V.current&&clearInterval(V.current),j.current&&(h==="recording"||h==="paused")&&(j.current.stop(),g("stopped")),N&&(N.getTracks().forEach(a=>a.stop()),F(null))},Z=d.useCallback(a=>{if(h!=="recording")return;const c={id:l.createId(),time:(f==null?void 0:f.duration)||0,label:a||`Marker ${b.length+1}`,color:s()};T(m=>[...m,c])},[h,f==null?void 0:f.duration,b.length]),B=a=>{T(c=>c.filter(m=>m.id!==a))},se=a=>{switch(a){case"mp4":return"video/mp4";case"mkv":return"video/x-matroska";default:return"video/webm;codecs=vp9"}},ae=a=>{switch(a){case"low":return 25e5;case"medium":return 5e6;case"lossless":return 2e7;default:return 8e6}},s=()=>{const a=["var(--nice-danger, #ff4444)","#44ff44","#4444ff","#ffff44","#ff44ff","#44ffff"];return a[Math.floor(Math.random()*a.length)]},n=a=>{const c=Math.floor(a/3600),m=Math.floor(a%3600/60),p=Math.floor(a%60),x=Math.floor(a%1*100);return c>0?`${c}:${m.toString().padStart(2,"0")}:${p.toString().padStart(2,"0")}`:`${m.toString().padStart(2,"0")}:${p.toString().padStart(2,"0")}.${x.toString().padStart(2,"0")}`},r=a=>a<1024?`${a} B`:a<1024*1024?`${(a/1024).toFixed(1)} KB`:`${(a/1024/1024).toFixed(1)} MB`;return e.jsxs("div",{className:`nice-screen-recorder ${u}`,children:[e.jsxs("div",{className:"recorder__preview",children:[L!==null&&e.jsx("div",{className:"countdown-overlay",children:e.jsx("span",{className:"countdown-number",children:L})}),e.jsx("video",{ref:E,className:"preview-video",muted:!0,playsInline:!0}),S&&e.jsx("canvas",{ref:q,className:"annotation-canvas"}),!N&&h==="idle"&&e.jsx("div",{className:"preview-placeholder",children:e.jsxs("button",{className:"start-preview-button",onClick:W,children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"monitor",size:18})}),e.jsx("span",{children:"Select Screen to Record"})]})}),h==="recording"&&e.jsxs("div",{className:"recording-indicator",children:[e.jsx("span",{className:"recording-dot"}),e.jsx("span",{children:"REC"})]})]}),e.jsxs("div",{className:"recorder__controls",children:[e.jsxs("div",{className:"controls__main",children:[h==="idle"&&e.jsxs("button",{className:"control-button control-button--record",onClick:M,disabled:!!L,children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"circle",size:18})}),e.jsx("span",{children:"Start Recording"})]}),h==="recording"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"control-button control-button--pause",onClick:ee,children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"pause",size:18})}),e.jsx("span",{children:"Pause"})]}),e.jsxs("button",{className:"control-button control-button--stop",onClick:G,children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"stop",size:18})}),e.jsx("span",{children:"Stop"})]})]}),h==="paused"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"control-button control-button--resume",onClick:H,children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"play",size:18})}),e.jsx("span",{children:"Resume"})]}),e.jsxs("button",{className:"control-button control-button--stop",onClick:G,children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"stop",size:18})}),e.jsx("span",{children:"Stop"})]})]}),h==="stopped"&&e.jsxs("button",{className:"control-button control-button--new",onClick:()=>{g("idle"),O(null),T([])},children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"refresh",size:18})}),e.jsx("span",{children:"New Recording"})]})]}),e.jsxs("div",{className:"controls__secondary",children:[(h==="recording"||h==="paused")&&e.jsxs("button",{className:"control-button control-button--marker",onClick:()=>Z(),children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"tag",size:18})}),e.jsx("span",{children:"Add Marker"})]}),e.jsxs("button",{className:`control-button ${S?"control-button--active":""}`,onClick:()=>I(!S),disabled:h!=="recording",children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"pen",size:18})}),e.jsx("span",{children:"Annotate"})]}),e.jsx("button",{className:"control-button control-button--settings",onClick:()=>U(!K),disabled:h==="recording","aria-label":"Settings",children:e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:"settings",size:18})})})]})]}),e.jsxs("div",{className:"recorder__status",children:[e.jsxs("div",{className:"status__info",children:[e.jsxs("span",{className:"status-item",children:[e.jsx("strong",{children:"Duration:"})," ",n((f==null?void 0:f.duration)||0)]}),e.jsxs("span",{className:"status-item",children:[e.jsx("strong",{children:"Size:"})," ",r((f==null?void 0:f.size)||0)]}),e.jsxs("span",{className:"status-item",children:[e.jsx("strong",{children:"Markers:"})," ",b.length]})]}),e.jsxs("div",{className:"status__quality",children:[i.video.resolution&&e.jsxs("span",{children:[i.video.resolution.width,"x",i.video.resolution.height]}),e.jsxs("span",{children:[i.video.frameRate,"fps"]}),e.jsx("span",{className:i.audio.enabled?"audio-on":"audio-off",children:e.jsx(l.NiceIcon,{name:i.audio.enabled?"volume":"volume-off",size:14})})]})]}),S&&h==="recording"&&e.jsxs("div",{className:"recorder__annotation-tools",children:[e.jsx("div",{className:"tool-group",children:["pen","arrow","rectangle","text"].map(a=>e.jsx("button",{className:`tool-button ${D===a?"tool-button--active":""}`,onClick:()=>J(a),"aria-label":a,children:e.jsx(l.NiceIcon,{name:a==="pen"?"pen":a==="arrow"?"arrow-right":a==="rectangle"?"square":"type",size:16})},a))}),e.jsx("div",{className:"color-group",children:["var(--nice-danger, #ff0000)","var(--nice-success, #00ff00)","var(--nice-primary, #0000ff)","var(--nice-warning, #ffff00)","var(--nice-bg, #fff)","var(--nice-text, #000000)"].map(a=>e.jsx("button",{className:`color-button ${Q===a?"color-button--active":""}`,style:{backgroundColor:a},onClick:()=>w(a)},a))})]}),b.length>0&&e.jsxs("div",{className:"recorder__markers",children:[e.jsx("h4",{children:"Markers"}),e.jsx("div",{className:"markers-list",children:b.map(a=>e.jsxs("div",{className:"marker-item",style:{borderLeftColor:a.color},children:[e.jsx("span",{className:"marker-time",children:n(a.time)}),e.jsx("input",{type:"text",value:a.label,onChange:c=>{T(m=>m.map(p=>p.id===a.id?{...p,label:c.target.value}:p))},className:"marker-label"}),e.jsx("button",{"aria-label":"Close",className:"marker-remove",onClick:()=>B(a.id),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]},a.id))})]}),K&&e.jsxs("div",{className:"recorder__settings",children:[e.jsxs("div",{className:"settings-header",children:[e.jsx("h3",{children:"Recording Settings"}),e.jsx("button",{"aria-label":"Close",className:"close-button",onClick:()=>U(!1),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]}),e.jsxs("div",{className:"settings-section",children:[e.jsx("h4",{children:"Video"}),e.jsxs("label",{children:["Source",e.jsxs("select",{value:i.video.source,onChange:a=>k({video:{...i.video,source:a.target.value}}),children:[e.jsx("option",{value:"screen",children:"Entire Screen"}),e.jsx("option",{value:"window",children:"Application Window"}),e.jsx("option",{value:"tab",children:"Browser Tab"}),e.jsx("option",{value:"camera",children:"Camera"})]})]}),e.jsxs("label",{children:["Resolution",e.jsxs("select",{value:`${(t=i.video.resolution)==null?void 0:t.width}x${(o=i.video.resolution)==null?void 0:o.height}`,onChange:a=>{const[c,m]=a.target.value.split("x").map(Number);k({video:{...i.video,resolution:{width:c,height:m}}})},children:[e.jsx("option",{value:"1920x1080",children:"1080p (1920x1080)"}),e.jsx("option",{value:"2560x1440",children:"1440p (2560x1440)"}),e.jsx("option",{value:"3840x2160",children:"4K (3840x2160)"}),e.jsx("option",{value:"1280x720",children:"720p (1280x720)"})]})]}),e.jsxs("label",{children:["Frame Rate",e.jsxs("select",{value:i.video.frameRate,onChange:a=>k({video:{...i.video,frameRate:parseInt(a.target.value)}}),children:[e.jsx("option",{value:"15",children:"15 fps"}),e.jsx("option",{value:"24",children:"24 fps"}),e.jsx("option",{value:"30",children:"30 fps"}),e.jsx("option",{value:"60",children:"60 fps"})]})]}),e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:i.video.showCursor,onChange:a=>k({video:{...i.video,showCursor:a.target.checked}})}),"Show Cursor"]})]}),e.jsxs("div",{className:"settings-section",children:[e.jsx("h4",{children:"Audio"}),e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:i.audio.enabled,onChange:a=>k({audio:{...i.audio,enabled:a.target.checked}})}),"Enable Audio"]}),i.audio.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:["Source",e.jsxs("select",{value:i.audio.source,onChange:a=>k({audio:{...i.audio,source:a.target.value}}),children:[e.jsx("option",{value:"system",children:"System Audio"}),e.jsx("option",{value:"microphone",children:"Microphone"}),e.jsx("option",{value:"both",children:"Both"})]})]}),e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:i.audio.echoCancellation,onChange:a=>k({audio:{...i.audio,echoCancellation:a.target.checked}})}),"Echo Cancellation"]}),e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:i.audio.noiseSuppression,onChange:a=>k({audio:{...i.audio,noiseSuppression:a.target.checked}})}),"Noise Suppression"]})]})]}),e.jsxs("div",{className:"settings-section",children:[e.jsx("h4",{children:"Output"}),e.jsxs("label",{children:["Format",e.jsxs("select",{value:i.output.format,onChange:a=>k({output:{...i.output,format:a.target.value}}),children:[e.jsx("option",{value:"webm",children:"WebM (Best Web)"}),e.jsx("option",{value:"mp4",children:"MP4 (Most Compatible)"}),e.jsx("option",{value:"mkv",children:"MKV (Lossless)"})]})]}),e.jsxs("label",{children:["Quality",e.jsxs("select",{value:i.output.quality,onChange:a=>k({output:{...i.output,quality:a.target.value}}),children:[e.jsx("option",{value:"low",children:"Low (Smaller file)"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High (Recommended)"}),e.jsx("option",{value:"lossless",children:"Lossless (Largest file)"})]})]})]})]})]})},xe={id:l.createId(),name:"My Stream",protocol:"rtmp",destinations:[],sources:[],layout:{name:"Default",canvas:{width:1920,height:1080,backgroundColor:"#000000"},layers:[]},settings:{video:{resolution:{width:1920,height:1080},frameRate:30,codec:"h264",bitrate:6e3,keyframe:2,profile:"high"},audio:{sampleRate:48e3,bitrate:160,channels:2,codec:"aac"}}},ie=[{platform:"youtube",name:"YouTube",icon:"video",defaultUrl:"rtmp://a.rtmp.youtube.com/live2"},{platform:"twitch",name:"Twitch",icon:"gamepad",defaultUrl:"rtmp://live.twitch.tv/app"},{platform:"facebook",name:"Facebook",icon:"users",defaultUrl:"rtmps://live-api-s.facebook.com:443/rtmp"},{platform:"custom-rtmp",name:"Custom RTMP",icon:"link",defaultUrl:""},{platform:"custom-srt",name:"Custom SRT",icon:"lock",defaultUrl:""}],te=[{type:"camera",name:"Camera",icon:"camera"},{type:"screen",name:"Screen Capture",icon:"monitor"},{type:"window",name:"Window Capture",icon:"window"},{type:"browser",name:"Browser Source",icon:"globe"},{type:"image",name:"Image",icon:"image"},{type:"video",name:"Video",icon:"video"},{type:"microphone",name:"Microphone",icon:"mic"},{type:"system-audio",name:"System Audio",icon:"volume"}],ve=({config:R,onConfigChange:C,onStreamStart:$,onStreamStop:A,onStatsUpdate:P,onError:z,className:u=""})=>{const[i,_]=d.useState(R||xe),[f,O]=d.useState("sources"),[h,g]=d.useState(!1),[b,T]=d.useState({duration:0,viewers:0,peakViewers:0,bitrate:0,fps:0,droppedFrames:0,cpuUsage:0,memoryUsage:0}),[N,F]=d.useState(null),[L,y]=d.useState(!1),[K,U]=d.useState(!1),[S,I]=d.useState([i.layout]),[D,J]=d.useState(0),Q=d.useRef(null),w=d.useRef(null),j=d.useRef(0);d.useEffect(()=>{R&&_(R)},[R]),d.useEffect(()=>()=>{w.current&&clearInterval(w.current)},[]);const v=d.useCallback(s=>{const n={...i,...s};_(n),C==null||C(n)},[i,C]),E=s=>{const n=ie.find(t=>t.platform===s),r={id:l.createId(),name:(n==null?void 0:n.name)||"Custom",platform:s,url:(n==null?void 0:n.defaultUrl)||"",streamKey:"",enabled:!0,status:"idle"};v({destinations:[...i.destinations,r]}),U(!1)},q=(s,n)=>{v({destinations:i.destinations.map(r=>r.id===s?{...r,...n}:r)})},V=s=>{v({destinations:i.destinations.filter(n=>n.id!==s)})},Y=async s=>{const n=te.find(o=>o.type===s),r={id:l.createId(),type:s,name:`${(n==null?void 0:n.name)||s} ${i.sources.filter(o=>o.type===s).length+1}`,settings:{},volume:1,muted:!1};try{if(s==="camera"||s==="microphone"){const o=s==="camera"?{video:!0}:{audio:!0},c=(await navigator.mediaDevices.enumerateDevices()).filter(m=>s==="camera"?m.kind==="videoinput":m.kind==="audioinput");c.length>0&&(r.settings.deviceId=c[0].deviceId)}else(s==="screen"||s==="window")&&await navigator.mediaDevices.getDisplayMedia({video:!0})}catch(o){console.warn(`Could not access ${s}:`,o)}v({sources:[...i.sources,r]});const t={id:l.createId(),sourceId:r.id,position:{x:0,y:0},size:{width:i.layout.canvas.width,height:i.layout.canvas.height},visible:!0,opacity:1,zIndex:i.layout.layers.length};v({layout:{...i.layout,layers:[...i.layout.layers,t]}}),y(!1)},k=(s,n)=>{v({sources:i.sources.map(r=>r.id===s?{...r,...n}:r)})},W=s=>{v({sources:i.sources.filter(n=>n.id!==s),layout:{...i.layout,layers:i.layout.layers.filter(n=>n.sourceId!==s)}})},M=(s,n)=>{v({layout:{...i.layout,layers:i.layout.layers.map(r=>r.id===s?{...r,...n}:r)}})},X=s=>{const n=i.layout.layers.findIndex(r=>r.id===s);if(n<i.layout.layers.length-1){const r=[...i.layout.layers];[r[n],r[n+1]]=[r[n+1],r[n]],r.forEach((t,o)=>{t.zIndex=o}),v({layout:{...i.layout,layers:r}})}},ee=s=>{const n=i.layout.layers.findIndex(r=>r.id===s);if(n>0){const r=[...i.layout.layers];[r[n],r[n-1]]=[r[n-1],r[n]],r.forEach((t,o)=>{t.zIndex=o}),v({layout:{...i.layout,layers:r}})}},H=()=>{const s={name:`Scene ${S.length+1}`,canvas:{...i.layout.canvas},layers:[]};I([...S,s])},G=s=>{const n=[...S];n[D]=i.layout,I(n),J(s),v({layout:S[s]})},Z=async()=>{try{v({destinations:i.destinations.map(s=>s.enabled?{...s,status:"connecting"}:s)}),await new Promise(s=>setTimeout(s,2e3)),v({destinations:i.destinations.map(s=>s.enabled?{...s,status:"live"}:s)}),g(!0),j.current=Date.now(),$==null||$(),w.current=setInterval(()=>{const s={duration:(Date.now()-j.current)/1e3,viewers:Math.floor(Math.random()*100)+b.viewers,peakViewers:Math.max(b.peakViewers,b.viewers),bitrate:i.settings.video.bitrate+Math.floor(Math.random()*500-250),fps:i.settings.video.frameRate-Math.random()*2,droppedFrames:b.droppedFrames+(Math.random()>.95?1:0),cpuUsage:15+Math.random()*30,memoryUsage:40+Math.random()*20};T(s),P==null||P(s)},1e3)}catch(s){z==null||z(s instanceof Error?s:new Error("Failed to start stream")),v({destinations:i.destinations.map(n=>({...n,status:"error"}))})}},B=()=>{w.current&&clearInterval(w.current),v({destinations:i.destinations.map(s=>({...s,status:"idle"}))}),g(!1),A==null||A()},se=s=>{const n=Math.floor(s/3600),r=Math.floor(s%3600/60),t=Math.floor(s%60);return`${n.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}:${t.toString().padStart(2,"0")}`},ae=s=>{switch(s){case"live":return"var(--nice-success, #00ff00)";case"connecting":return"var(--nice-warning, #ffff00)";case"error":return"var(--nice-danger, #ff0000)";default:return"var(--nice-text-secondary, #888888)"}};return e.jsxs("div",{className:`nice-live-streaming ${u}`,children:[e.jsxs("header",{className:"streaming__header",children:[e.jsxs("div",{className:"header__title",children:[e.jsx("input",{type:"text",value:i.name,onChange:s=>v({name:s.target.value}),className:"stream-name-input"}),h&&e.jsxs("span",{className:"live-badge",children:[e.jsx("span",{className:"live-dot"})," LIVE"]})]}),e.jsx("div",{className:"header__stats",children:h&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"stat-item",children:[e.jsx(l.NiceIcon,{name:"clock",size:14})," ",se(b.duration)]}),e.jsxs("span",{className:"stat-item",children:[e.jsx(l.NiceIcon,{name:"users",size:14})," ",b.viewers]}),e.jsxs("span",{className:"stat-item",children:[e.jsx(l.NiceIcon,{name:"bar-chart",size:14})," ",Math.round(b.bitrate)," kbps"]}),e.jsxs("span",{className:"stat-item",children:[e.jsx(l.NiceIcon,{name:"video",size:14})," ",b.fps.toFixed(1)," fps"]})]})}),e.jsx("div",{className:"header__actions",children:h?e.jsx("button",{className:"action-button action-button--stop",onClick:B,children:"End Stream"}):e.jsx("button",{className:"action-button action-button--go-live",onClick:Z,disabled:i.destinations.filter(s=>s.enabled).length===0,children:"Go Live"})})]}),e.jsxs("div",{className:"streaming__main",children:[e.jsxs("div",{className:"streaming__preview",children:[e.jsxs("div",{className:"scenes-bar",children:[S.map((s,n)=>e.jsx("button",{className:`scene-button ${D===n?"scene-button--active":""}`,onClick:()=>G(n),children:s.name},n)),e.jsx("button",{className:"scene-button scene-button--add",onClick:H,children:"+"})]}),e.jsx("div",{ref:Q,className:"preview-canvas",style:{aspectRatio:`${i.layout.canvas.width}/${i.layout.canvas.height}`,backgroundColor:i.layout.canvas.backgroundColor},children:i.layout.layers.sort((s,n)=>s.zIndex-n.zIndex).map(s=>{var r;const n=i.sources.find(t=>t.id===s.sourceId);return!s.visible||!n?null:e.jsx("div",{className:`canvas-layer ${N===s.id?"canvas-layer--selected":""}`,style:{left:`${s.position.x/i.layout.canvas.width*100}%`,top:`${s.position.y/i.layout.canvas.height*100}%`,width:`${s.size.width/i.layout.canvas.width*100}%`,height:`${s.size.height/i.layout.canvas.height*100}%`,opacity:s.opacity,zIndex:s.zIndex},onClick:()=>F(s.id),children:e.jsxs("div",{className:"layer-content",children:[e.jsx("span",{className:"layer-icon",children:e.jsx(l.NiceIcon,{name:((r=te.find(t=>t.type===n.type))==null?void 0:r.icon)??"box",size:16})}),e.jsx("span",{className:"layer-name",children:n.name})]})},s.id)})})]}),e.jsxs("aside",{className:"streaming__panel",children:[e.jsx("div",{className:"panel-tabs",children:["sources","audio","destinations","settings"].map(s=>e.jsx("button",{className:`panel-tab ${f===s?"panel-tab--active":""}`,onClick:()=>O(s),children:s.charAt(0).toUpperCase()+s.slice(1)},s))}),e.jsxs("div",{className:"panel-content",children:[f==="sources"&&e.jsxs("div",{className:"sources-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h3",{children:"Sources"}),e.jsx("button",{className:"add-button",onClick:()=>y(!0),disabled:h,children:"+ Add"})]}),e.jsx("div",{className:"sources-list",children:i.sources.filter(s=>s.type!=="microphone"&&s.type!=="system-audio").map(s=>{var r;const n=i.layout.layers.find(t=>t.sourceId===s.id);return e.jsxs("div",{className:`source-item ${N===(n==null?void 0:n.id)?"source-item--selected":""}`,onClick:()=>n&&F(n.id),children:[e.jsx("span",{className:"source-icon",children:e.jsx(l.NiceIcon,{name:((r=te.find(t=>t.type===s.type))==null?void 0:r.icon)??"box",size:16})}),e.jsx("span",{className:"source-name",children:s.name}),e.jsxs("div",{className:"source-controls",children:[e.jsx("button",{className:n!=null&&n.visible?"":"inactive",onClick:t=>{t.stopPropagation(),n&&M(n.id,{visible:!n.visible})},children:e.jsx(l.NiceIcon,{name:n!=null&&n.visible?"eye":"eye-off",size:14})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),n&&X(n.id)},children:e.jsx(l.NiceIcon,{name:"arrow-up",size:14})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),n&&ee(n.id)},children:e.jsx(l.NiceIcon,{name:"arrow-down",size:14})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),W(s.id)},disabled:h,children:e.jsx(l.NiceIcon,{name:"trash",size:14})})]})]},s.id)})}),N&&e.jsxs("div",{className:"layer-properties",children:[e.jsx("h4",{children:"Properties"}),(()=>{const s=i.layout.layers.find(n=>n.id===N);return s?e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:["X Position",e.jsx("input",{type:"number",value:s.position.x,onChange:n=>M(s.id,{position:{...s.position,x:parseInt(n.target.value)||0}})})]}),e.jsxs("label",{children:["Y Position",e.jsx("input",{type:"number",value:s.position.y,onChange:n=>M(s.id,{position:{...s.position,y:parseInt(n.target.value)||0}})})]}),e.jsxs("label",{children:["Width",e.jsx("input",{type:"number",value:s.size.width,onChange:n=>M(s.id,{size:{...s.size,width:parseInt(n.target.value)||100}})})]}),e.jsxs("label",{children:["Height",e.jsx("input",{type:"number",value:s.size.height,onChange:n=>M(s.id,{size:{...s.size,height:parseInt(n.target.value)||100}})})]}),e.jsxs("label",{children:["Opacity",e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:s.opacity,onChange:n=>M(s.id,{opacity:parseFloat(n.target.value)})})]})]}):null})()]})]}),f==="audio"&&e.jsxs("div",{className:"audio-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h3",{children:"Audio Mixer"}),e.jsx("button",{className:"add-button",onClick:()=>{y(!0)},disabled:h,children:"+ Add"})]}),e.jsxs("div",{className:"audio-sources",children:[i.sources.filter(s=>s.type==="microphone"||s.type==="system-audio"||s.type==="video").map(s=>{var n;return e.jsxs("div",{className:"audio-source",children:[e.jsxs("div",{className:"audio-header",children:[e.jsx("span",{className:"audio-icon",children:e.jsx(l.NiceIcon,{name:((n=te.find(r=>r.type===s.type))==null?void 0:n.icon)??"box",size:16})}),e.jsx("span",{className:"audio-name",children:s.name}),e.jsx("button",{className:s.muted?"muted":"",onClick:()=>k(s.id,{muted:!s.muted}),children:e.jsx(l.NiceIcon,{name:s.muted?"volume-off":"volume",size:14})})]}),e.jsxs("div",{className:"audio-slider",children:[e.jsx("input",{type:"range",min:"0",max:"1",step:"0.01",value:s.volume??1,onChange:r=>k(s.id,{volume:parseFloat(r.target.value)}),disabled:s.muted}),e.jsxs("span",{className:"volume-value",children:[Math.round((s.volume??1)*100),"%"]})]}),e.jsx("div",{className:"audio-meter",children:e.jsx("div",{className:"meter-fill",style:{width:`${(s.volume??1)*70+Math.random()*30}%`}})})]},s.id)}),i.sources.filter(s=>s.type==="microphone"||s.type==="system-audio").length===0&&e.jsx("p",{className:"empty-message",children:"No audio sources added"})]})]}),f==="destinations"&&e.jsxs("div",{className:"destinations-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h3",{children:"Destinations"}),e.jsx("button",{className:"add-button",onClick:()=>U(!0),disabled:h,children:"+ Add"})]}),e.jsxs("div",{className:"destinations-list",children:[i.destinations.map(s=>{var n;return e.jsxs("div",{className:"destination-item",children:[e.jsxs("div",{className:"destination-header",children:[e.jsx("span",{className:"status-indicator",style:{backgroundColor:ae(s.status)}}),e.jsx("span",{className:"destination-icon",children:e.jsx(l.NiceIcon,{name:((n=ie.find(r=>r.platform===s.platform))==null?void 0:n.icon)??"link",size:16})}),e.jsx("span",{className:"destination-name",children:s.name}),e.jsxs("label",{className:"toggle",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:r=>q(s.id,{enabled:r.target.checked}),disabled:h}),e.jsx("span",{className:"toggle-slider"})]})]}),e.jsxs("div",{className:"destination-config",children:[e.jsxs("label",{children:["Server URL",e.jsx("input",{type:"text",value:s.url,onChange:r=>q(s.id,{url:r.target.value}),placeholder:"rtmp://...",disabled:h})]}),e.jsxs("label",{children:["Stream Key",e.jsx("input",{type:"password",value:s.streamKey||"",onChange:r=>q(s.id,{streamKey:r.target.value}),placeholder:"Enter stream key",disabled:h})]})]}),e.jsx("button",{className:"remove-button",onClick:()=>V(s.id),disabled:h,children:"Remove"})]},s.id)}),i.destinations.length===0&&e.jsx("p",{className:"empty-message",children:"No destinations configured"})]})]}),f==="settings"&&e.jsxs("div",{className:"settings-panel",children:[e.jsxs("div",{className:"setting-section",children:[e.jsx("h4",{children:"Video"}),e.jsxs("label",{children:["Resolution",e.jsxs("select",{value:`${i.settings.video.resolution.width}x${i.settings.video.resolution.height}`,onChange:s=>{const[n,r]=s.target.value.split("x").map(Number);v({settings:{...i.settings,video:{...i.settings.video,resolution:{width:n,height:r}}},layout:{...i.layout,canvas:{...i.layout.canvas,width:n,height:r}}})},disabled:h,children:[e.jsx("option",{value:"1920x1080",children:"1080p (1920x1080)"}),e.jsx("option",{value:"1280x720",children:"720p (1280x720)"}),e.jsx("option",{value:"2560x1440",children:"1440p (2560x1440)"})]})]}),e.jsxs("label",{children:["Frame Rate",e.jsxs("select",{value:i.settings.video.frameRate,onChange:s=>v({settings:{...i.settings,video:{...i.settings.video,frameRate:parseInt(s.target.value)}}}),disabled:h,children:[e.jsx("option",{value:"24",children:"24 fps"}),e.jsx("option",{value:"30",children:"30 fps"}),e.jsx("option",{value:"60",children:"60 fps"})]})]}),e.jsxs("label",{children:["Bitrate (kbps)",e.jsx("input",{type:"number",value:i.settings.video.bitrate,onChange:s=>v({settings:{...i.settings,video:{...i.settings.video,bitrate:parseInt(s.target.value)||6e3}}}),min:"1000",max:"50000",disabled:h})]}),e.jsxs("label",{children:["Keyframe Interval (sec)",e.jsx("input",{type:"number",value:i.settings.video.keyframe,onChange:s=>v({settings:{...i.settings,video:{...i.settings.video,keyframe:parseInt(s.target.value)||2}}}),min:"1",max:"10",disabled:h})]})]}),e.jsxs("div",{className:"setting-section",children:[e.jsx("h4",{children:"Audio"}),e.jsxs("label",{children:["Sample Rate",e.jsxs("select",{value:i.settings.audio.sampleRate,onChange:s=>v({settings:{...i.settings,audio:{...i.settings.audio,sampleRate:parseInt(s.target.value)}}}),disabled:h,children:[e.jsx("option",{value:"44100",children:"44.1 kHz"}),e.jsx("option",{value:"48000",children:"48 kHz"})]})]}),e.jsxs("label",{children:["Audio Bitrate (kbps)",e.jsxs("select",{value:i.settings.audio.bitrate,onChange:s=>v({settings:{...i.settings,audio:{...i.settings.audio,bitrate:parseInt(s.target.value)}}}),disabled:h,children:[e.jsx("option",{value:"96",children:"96 kbps"}),e.jsx("option",{value:"128",children:"128 kbps"}),e.jsx("option",{value:"160",children:"160 kbps"}),e.jsx("option",{value:"320",children:"320 kbps"})]})]})]})]})]})]})]}),h&&e.jsx("footer",{className:"streaming__footer",children:e.jsxs("div",{className:"footer-stats",children:[e.jsxs("span",{className:"stat",children:[e.jsx("label",{children:"CPU"}),e.jsxs("span",{className:"value",children:[b.cpuUsage.toFixed(1),"%"]})]}),e.jsxs("span",{className:"stat",children:[e.jsx("label",{children:"Memory"}),e.jsxs("span",{className:"value",children:[b.memoryUsage.toFixed(1),"%"]})]}),e.jsxs("span",{className:"stat",children:[e.jsx("label",{children:"Dropped"}),e.jsx("span",{className:"value",children:b.droppedFrames})]}),e.jsxs("span",{className:"stat",children:[e.jsx("label",{children:"Peak Viewers"}),e.jsx("span",{className:"value",children:b.peakViewers})]})]})}),L&&e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Add Source"}),e.jsx("button",{"aria-label":"Close",className:"close-button",onClick:()=>y(!1),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-content",children:e.jsx("div",{className:"source-type-grid",children:te.map(s=>e.jsxs("button",{className:"source-type-button",onClick:()=>Y(s.type),children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:s.icon,size:24})}),e.jsx("span",{className:"name",children:s.name})]},s.type))})})]})}),K&&e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Add Destination"}),e.jsx("button",{"aria-label":"Close",className:"close-button",onClick:()=>U(!1),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-content",children:e.jsx("div",{className:"platform-grid",children:ie.map(s=>e.jsxs("button",{className:"platform-button",onClick:()=>E(s.platform),children:[e.jsx("span",{className:"icon",children:e.jsx(l.NiceIcon,{name:s.icon,size:24})}),e.jsx("span",{className:"name",children:s.name})]},s.platform))})})]})})]})};exports.NiceLiveStreaming=ve;exports.NiceScreenRecorder=pe;exports.NiceVideoEditor=me;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),oe=require("@nice2dev/ui"),l=require("@nice2dev/ui-core"),u=require("react"),le={id:l.createId(),name:"Untitled Project",resolution:{width:1920,height:1080,label:"1080p"},frameRate:30,duration:0,tracks:[{id:"1",type:"video",name:"Video 1",items:[],muted:!1,locked:!1,visible:!0},{id:"2",type:"audio",name:"Audio 1",items:[],muted:!1,locked:!1,visible:!0}],assets:[],settings:{backgroundColor:"#000000",audio:{sampleRate:48e3,channels:2,bitrate:320},video:{codec:"h264",bitrate:8e3,profile:"high"}}},de=[{type:"blur",name:"Blur",icon:"droplet"},{type:"brightness",name:"Brightness",icon:"sun"},{type:"contrast",name:"Contrast",icon:"moon"},{type:"saturation",name:"Saturation",icon:"palette"},{type:"grayscale",name:"Grayscale",icon:"square"},{type:"sepia",name:"Sepia",icon:"image"},{type:"chromaKey",name:"Chroma Key",icon:"layers"},{type:"crop",name:"Crop",icon:"crop"},{type:"zoom",name:"Zoom",icon:"search"}],ue=[{type:"fade",name:"Fade"},{type:"dissolve",name:"Dissolve"},{type:"wipe",name:"Wipe"},{type:"slide",name:"Slide"},{type:"zoom",name:"Zoom"},{type:"push",name:"Push"}],me=[{target:".nice-video-editor",titleKey:"tutorial.videoEditorPro.intro.title",title:"Video editor",contentKey:"tutorial.videoEditorPro.intro.content",content:"Add media to the timeline, arrange and trim clips, apply effects and transitions, then configure and run the export.",placement:"auto"}],ve=({project:z,onProjectChange:w,onExport:$,onAssetUpload:A,className:F="",tutorial:R})=>{const{t:g}=l.useNiceTranslation(),[a,n]=u.useState(z||le),[T,j]=u.useState("timeline"),[B,v]=u.useState(null),[b,f]=u.useState(null),[E,N]=u.useState(0),[L,U]=u.useState(!1),[y,q]=u.useState(1),[V,C]=u.useState(!0),[I,D]=u.useState(null),Q=u.useRef(null),X=u.useRef(null),S=u.useRef(null);u.useEffect(()=>{z&&n(z)},[z]),u.useEffect(()=>()=>{S.current&&clearInterval(S.current)},[]);const _=u.useCallback(t=>{const c={...a,...t};n(c),w==null||w(c)},[a,w]),x=async t=>{const c=[];for(const i of Array.from(t)){const d=i.type.startsWith("video/")?"video":i.type.startsWith("audio/")?"audio":"image";let m;A?m=await A(i):m={id:l.createId(),type:d,name:i.name,url:URL.createObjectURL(i),size:i.size},c.push(m)}_({assets:[...a.assets,...c]})},P=t=>{const c={id:l.createId(),type:t,name:`${t.charAt(0).toUpperCase()+t.slice(1)} ${a.tracks.filter(i=>i.type===t).length+1}`,items:[],muted:!1,locked:!1,visible:!0};_({tracks:[...a.tracks,c]})},W=t=>{_({tracks:a.tracks.filter(c=>c.id!==t)}),B===t&&v(null)},O=t=>{_({tracks:a.tracks.map(c=>c.id===t?{...c,muted:!c.muted}:c)})},Z=t=>{_({tracks:a.tracks.map(c=>c.id===t?{...c,locked:!c.locked}:c)})},k=(t,c)=>{const i=a.tracks.find(p=>p.id===t);if(!i||i.locked)return;const d=i.items[i.items.length-1],m=d?d.startTime+d.duration:0,h={id:l.createId(),assetId:c.id,type:c.type,startTime:m,duration:c.duration||5,offset:0,properties:{x:0,y:0,opacity:1,scale:1,volume:1},effects:[],transitions:[]};_({tracks:a.tracks.map(p=>p.id===t?{...p,items:[...p.items,h]}:p)})},H=(t,c,i)=>{const d={id:l.createId(),type:i,name:i.charAt(0).toUpperCase()+i.slice(1),parameters:ee(i)};_({tracks:a.tracks.map(m=>m.id===t?{...m,items:m.items.map(h=>h.id===c?{...h,effects:[...h.effects,d]}:h)}:m)})},M=(t,c,i,d)=>{const m={id:l.createId(),type:i,duration:.5,position:d};_({tracks:a.tracks.map(h=>h.id===t?{...h,items:h.items.map(p=>p.id===c?{...p,transitions:[...p.transitions,m]}:p)}:h)})},ee=t=>{switch(t){case"blur":return{radius:5};case"brightness":return{value:100};case"contrast":return{value:100};case"saturation":return{value:100};case"grayscale":return{amount:100};case"sepia":return{amount:100};case"chromaKey":return{color:"var(--nice-success, #00ff00)",threshold:40};case"crop":return{top:0,right:0,bottom:0,left:0};case"zoom":return{scale:1,x:0,y:0};default:return{}}},se=()=>{L?(S.current&&clearInterval(S.current),U(!1)):(S.current=setInterval(()=>{N(t=>{const c=Math.max(...a.tracks.flatMap(i=>i.items.map(d=>d.startTime+d.duration)),0);return t>=c?(clearInterval(S.current),U(!1),0):t+1/a.frameRate})},1e3/a.frameRate),U(!0))},G=t=>{N(Math.max(0,t))},Y=async()=>{if($){D(0);try{const t=setInterval(()=>{D(c=>c!==null&&c<90?c+Math.random()*10:c)},500);await $(a,a.settings.video.codec),clearInterval(t),D(100),setTimeout(()=>D(null),2e3)}catch(t){D(null),console.error("Export failed:",t)}}},J=t=>{const c=Math.floor(t/60),i=Math.floor(t%60),d=Math.floor(t%1*a.frameRate);return`${c.toString().padStart(2,"0")}:${i.toString().padStart(2,"0")}:${d.toString().padStart(2,"0")}`},K=()=>{for(const t of a.tracks){const c=t.items.find(i=>i.id===b);if(c)return{track:t,item:c}}return null},ie=e.jsxs("header",{className:"nice-video-studio__header",children:[e.jsxs("div",{className:"nice-video-studio__header-project-info",children:[e.jsx("input",{type:"text",value:a.name,onChange:t=>_({name:t.target.value}),className:"nice-video-studio__project-name-input"}),e.jsxs("span",{className:"nice-video-studio__project-settings",children:[a.resolution.width,"x",a.resolution.height," • ",a.frameRate,"fps"]})]}),e.jsx("div",{className:"nice-video-studio__header-tabs",children:["timeline","effects","transitions","export"].map(t=>e.jsx("button",{className:`nice-video-studio__tab-button ${T===t?"nice-video-studio__tab-button--active":""}`,onClick:()=>j(t),children:t.charAt(0).toUpperCase()+t.slice(1)},t))}),e.jsx("div",{className:"nice-video-studio__header-actions",children:e.jsx("button",{className:"nice-video-studio__action-button nice-video-studio__action-button--primary",onClick:Y,disabled:I!==null,children:I!==null?`Exporting ${Math.round(I)}%`:"Export"})})]}),te=b&&T!=="export"?(()=>{const t=K();if(!t)return null;const{track:c,item:i}=t;return e.jsxs("div",{className:"nice-video-studio__item-inspector",children:[e.jsx("h4",{children:g("videoEditor.itemProperties","Item Properties")}),e.jsxs("div",{className:"nice-video-studio__inspector-section",children:[e.jsxs("label",{children:[g("videoEditor.startTime","Start Time"),e.jsx("input",{type:"number",step:"0.1",value:i.startTime,onChange:d=>{const m=parseFloat(d.target.value);_({tracks:a.tracks.map(h=>h.id===c.id?{...h,items:h.items.map(p=>p.id===i.id?{...p,startTime:m}:p)}:h)})}})]}),e.jsxs("label",{children:[g("videoEditor.duration","Duration"),e.jsx("input",{type:"number",step:"0.1",value:i.duration,onChange:d=>{const m=parseFloat(d.target.value);_({tracks:a.tracks.map(h=>h.id===c.id?{...h,items:h.items.map(p=>p.id===i.id?{...p,duration:m}:p)}:h)})}})]}),e.jsxs("label",{children:[g("videoEditor.opacity","Opacity"),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:i.properties.opacity??1,onChange:d=>{const m=parseFloat(d.target.value);_({tracks:a.tracks.map(h=>h.id===c.id?{...h,items:h.items.map(p=>p.id===i.id?{...p,properties:{...p.properties,opacity:m}}:p)}:h)})}})]})]}),e.jsxs("h4",{children:["Effects (",i.effects.length,")"]}),e.jsx("div",{className:"nice-video-studio__effects-list",children:i.effects.map(d=>e.jsx("div",{className:"nice-video-studio__effect-badge",children:d.name},d.id))})]})})():null,s=V?e.jsxs("aside",{className:"nice-video-studio__asset-library",children:[e.jsxs("div",{className:"nice-video-studio__asset-library-header",children:[e.jsx("h3",{children:g("videoEditor.assets","Assets")}),e.jsx("button",{"aria-label":g("videoEditor.close","Close"),className:"nice-video-studio__close-button",onClick:()=>C(!1),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]}),e.jsx("div",{className:"nice-video-studio__asset-library-upload",children:e.jsxs("label",{className:"nice-video-studio__upload-zone",children:[e.jsx("input",{type:"file",multiple:!0,accept:"video/*,audio/*,image/*",onChange:t=>t.target.files&&x(t.target.files),hidden:!0}),e.jsx("span",{className:"nice-video-studio__upload-icon",children:"+"}),e.jsx("span",{children:g("videoEditor.dropFilesOrClickTo","Drop files or click to upload")})]})}),e.jsx("div",{className:"nice-video-studio__asset-library-list",children:a.assets.map(t=>e.jsxs("div",{className:"nice-video-studio__asset-item",draggable:!0,onDragStart:c=>c.dataTransfer.setData("assetId",t.id),children:[e.jsx("div",{className:"nice-video-studio__asset-thumbnail",children:t.thumbnail?e.jsx("img",{src:t.thumbnail,alt:t.name}):e.jsx("span",{className:"nice-video-studio__asset-type-icon",children:e.jsx(l.NiceIcon,{name:t.type==="video"?"video":t.type==="audio"?"music":"image",size:24})})}),e.jsxs("div",{className:"nice-video-studio__asset-info",children:[e.jsx("span",{className:"nice-video-studio__asset-name",children:t.name}),e.jsxs("span",{className:"nice-video-studio__asset-meta",children:[(t.size/1024/1024).toFixed(1),"MB"]})]})]},t.id))})]}):void 0,r=e.jsx("div",{className:"nice-video-studio__preview-area",children:e.jsxs("div",{className:"nice-video-studio__preview-container",children:[e.jsxs("div",{className:"nice-video-studio__preview-canvas",style:{aspectRatio:`${a.resolution.width}/${a.resolution.height}`},children:[e.jsx("video",{ref:X,className:"nice-video-studio__preview-video"}),e.jsx("div",{className:"nice-video-studio__preview-overlay",children:!V&&e.jsx("button",{className:"nice-video-studio__toggle-library-button",onClick:()=>C(!0),"aria-label":g("videoEditor.showAssetLibrary","Show asset library"),children:e.jsx(l.NiceIcon,{name:"folder",size:16})})})]}),e.jsxs("div",{className:"nice-video-studio__playback-controls",children:[e.jsx("button",{onClick:()=>G(0),"aria-label":g("videoEditor.goToStart","Go to start"),children:e.jsx(l.NiceIcon,{name:"skip-back",size:16})}),e.jsx("button",{onClick:()=>G(E-1/a.frameRate),"aria-label":g("videoEditor.previousFrame","Previous frame"),children:e.jsx(l.NiceIcon,{name:"chevron-left",size:16})}),e.jsx("button",{onClick:se,className:"nice-video-studio__play-button","aria-label":L?"Pause":"Play",children:e.jsx(l.NiceIcon,{name:L?"pause":"play",size:18})}),e.jsx("button",{onClick:()=>G(E+1/a.frameRate),"aria-label":g("videoEditor.nextFrame","Next frame"),children:e.jsx(l.NiceIcon,{name:"chevron-right",size:16})}),e.jsx("span",{className:"nice-video-studio__time-display",children:J(E)})]})]})}),o=e.jsxs("div",{className:"nice-video-studio__panel",children:[T==="timeline"&&e.jsxs("div",{className:"nice-video-studio__timeline-panel",children:[e.jsxs("div",{className:"nice-video-studio__timeline-toolbar",children:[e.jsxs("div",{className:"nice-video-studio__track-buttons",children:[e.jsx("button",{onClick:()=>P("video"),children:"+ Video Track"}),e.jsx("button",{onClick:()=>P("audio"),children:"+ Audio Track"}),e.jsx("button",{onClick:()=>P("text"),children:"+ Text Track"})]}),e.jsxs("div",{className:"nice-video-studio__zoom-controls",children:[e.jsx("button",{onClick:()=>q(Math.max(.25,y-.25)),children:"-"}),e.jsxs("span",{children:[Math.round(y*100),"%"]}),e.jsx("button",{onClick:()=>q(Math.min(4,y+.25)),children:"+"})]})]}),e.jsxs("div",{className:"nice-video-studio__timeline-container",ref:Q,children:[e.jsx("div",{className:"nice-video-studio__timeline-ruler",children:Array.from({length:Math.ceil(30/y)}).map((t,c)=>e.jsx("div",{className:"nice-video-studio__ruler-mark",style:{left:`${c*50*y}px`},children:J(c)},c))}),e.jsx("div",{className:"nice-video-studio__timeline-playhead",style:{left:`${E*50*y}px`}}),e.jsx("div",{className:"nice-video-studio__timeline-tracks",children:a.tracks.map(t=>e.jsxs("div",{className:`nice-video-studio__timeline-track ${B===t.id?"nice-video-studio__timeline-track--selected":""} ${t.locked?"nice-video-studio__timeline-track--locked":""}`,onClick:()=>v(t.id),onDrop:c=>{c.preventDefault();const i=c.dataTransfer.getData("assetId"),d=a.assets.find(m=>m.id===i);d&&k(t.id,d)},onDragOver:c=>c.preventDefault(),children:[e.jsxs("div",{className:"nice-video-studio__track-header",children:[e.jsx("span",{className:"nice-video-studio__track-name",children:t.name}),e.jsxs("div",{className:"nice-video-studio__track-controls",children:[e.jsx("button",{className:`nice-video-studio__track-toggle ${t.muted?"nice-video-studio__track-toggle--active":""}`,onClick:c=>{c.stopPropagation(),O(t.id)},children:e.jsx(l.NiceIcon,{name:t.muted?"volume-off":"volume",size:14})}),e.jsx("button",{className:`nice-video-studio__track-toggle ${t.locked?"nice-video-studio__track-toggle--active":""}`,onClick:c=>{c.stopPropagation(),Z(t.id)},children:e.jsx(l.NiceIcon,{name:t.locked?"lock":"unlock",size:14})}),e.jsx("button",{onClick:c=>{c.stopPropagation(),W(t.id)},"aria-label":g("videoEditor.removeTrack","Remove track"),children:e.jsx(l.NiceIcon,{name:"trash",size:14})})]})]}),e.jsx("div",{className:"nice-video-studio__track-items",children:t.items.map(c=>{const i=a.assets.find(d=>d.id===c.assetId);return e.jsxs("div",{className:`nice-video-studio__track-item nice-video-studio__track-item--${c.type} ${b===c.id?"nice-video-studio__track-item--selected":""}`,style:{left:`${c.startTime*50*y}px`,width:`${c.duration*50*y}px`},onClick:d=>{d.stopPropagation(),f(c.id)},children:[e.jsx("span",{className:"nice-video-studio__item-name",children:(i==null?void 0:i.name)||"Untitled"}),c.transitions.length>0&&e.jsx("span",{className:"nice-video-studio__item-transitions",children:e.jsx(l.NiceIcon,{name:"wand",size:12})}),c.effects.length>0&&e.jsx("span",{className:"nice-video-studio__item-effects",children:e.jsx(l.NiceIcon,{name:"palette",size:12})})]},c.id)})})]},t.id))})]})]}),T==="effects"&&e.jsxs("div",{className:"nice-video-studio__effects-panel",children:[e.jsx("h3",{children:g("videoEditor.videoEffects","Video Effects")}),e.jsx("p",{className:"nice-video-studio__panel-hint",children:g("videoEditor.selectAClipToApply","Select a clip to apply effects")}),e.jsx("div",{className:"nice-video-studio__effects-grid",children:de.map(t=>e.jsxs("button",{className:"nice-video-studio__effect-preset",disabled:!b,onClick:()=>{const c=K();c&&H(c.track.id,c.item.id,t.type)},children:[e.jsx("span",{className:"nice-video-studio__effect-icon",children:e.jsx(l.NiceIcon,{name:t.icon,size:16})}),e.jsx("span",{className:"nice-video-studio__effect-name",children:t.name})]},t.type))})]}),T==="transitions"&&e.jsxs("div",{className:"nice-video-studio__transitions-panel",children:[e.jsx("h3",{children:g("videoEditor.transitions","Transitions")}),e.jsx("p",{className:"nice-video-studio__panel-hint",children:g("videoEditor.selectAClipAndAdd","Select a clip and add transitions between clips")}),e.jsx("div",{className:"nice-video-studio__transitions-grid",children:ue.map(t=>e.jsxs("div",{className:"nice-video-studio__transition-preset",children:[e.jsx("span",{className:"nice-video-studio__transition-name",children:t.name}),e.jsxs("div",{className:"nice-video-studio__transition-buttons",children:[e.jsx("button",{disabled:!b,onClick:()=>{const c=K();c&&M(c.track.id,c.item.id,t.type,"start")},children:"In"}),e.jsx("button",{disabled:!b,onClick:()=>{const c=K();c&&M(c.track.id,c.item.id,t.type,"end")},children:"Out"})]})]},t.type))})]}),T==="export"&&e.jsxs("div",{className:"nice-video-studio__export-panel",children:[e.jsx("h3",{children:g("videoEditor.exportSettings","Export Settings")}),e.jsxs("div",{className:"nice-video-studio__export-settings",children:[e.jsxs("div",{className:"nice-video-studio__setting-group",children:[e.jsx("label",{children:g("videoEditor.resolution","Resolution")}),e.jsxs("select",{value:`${a.resolution.width}x${a.resolution.height}`,onChange:t=>{const[c,i]=t.target.value.split("x").map(Number);_({resolution:{width:c,height:i}})},children:[e.jsx("option",{value:"1920x1080",children:"1080p (1920x1080)"}),e.jsx("option",{value:"2560x1440",children:"1440p (2560x1440)"}),e.jsx("option",{value:"3840x2160",children:"4K (3840x2160)"}),e.jsx("option",{value:"1280x720",children:"720p (1280x720)"})]})]}),e.jsxs("div",{className:"nice-video-studio__setting-group",children:[e.jsx("label",{children:g("videoEditor.frameRate","Frame Rate")}),e.jsxs("select",{value:a.frameRate,onChange:t=>_({frameRate:parseInt(t.target.value)}),children:[e.jsx("option",{value:"24",children:"24 fps"}),e.jsx("option",{value:"30",children:"30 fps"}),e.jsx("option",{value:"60",children:"60 fps"}),e.jsx("option",{value:"120",children:"120 fps"})]})]}),e.jsxs("div",{className:"nice-video-studio__setting-group",children:[e.jsx("label",{children:g("videoEditor.videoCodec","Video Codec")}),e.jsxs("select",{value:a.settings.video.codec,onChange:t=>_({settings:{...a.settings,video:{...a.settings.video,codec:t.target.value}}}),children:[e.jsx("option",{value:"h264",children:"H.264 (Best Compatibility)"}),e.jsx("option",{value:"h265",children:"H.265/HEVC (Smaller Size)"}),e.jsx("option",{value:"vp9",children:"VP9 (Web Optimized)"}),e.jsx("option",{value:"av1",children:"AV1 (Future Standard)"})]})]}),e.jsxs("div",{className:"nice-video-studio__setting-group",children:[e.jsx("label",{children:"Video Bitrate (Mbps)"}),e.jsx("input",{type:"number",value:a.settings.video.bitrate/1e3,onChange:t=>_({settings:{...a.settings,video:{...a.settings.video,bitrate:parseFloat(t.target.value)*1e3}}}),min:"1",max:"100"})]})]}),e.jsx("button",{className:"nice-video-studio__export-button",onClick:Y,disabled:I!==null,children:I!==null?`Exporting... ${Math.round(I)}%`:"Export Video"}),I!==null&&e.jsx("div",{className:"nice-video-studio__export-progress",children:e.jsx("div",{className:"nice-video-studio__export-progress-bar",style:{width:`${I}%`}})})]})]});return e.jsxs(oe.NiceAppShell,{flush:!0,className:`nice-video-editor nice-video-studio ${F}`,height:"100%",style:{position:"relative",minHeight:600},toolbar:ie,sidebar:s,rightSidebar:te??void 0,bottomPanel:o,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(l.NiceTutorialButton,{steps:l.resolveTutorial(R,me)})}),r]})},he={video:{source:"screen",showCursor:!0,frameRate:30,resolution:{width:1920,height:1080}},audio:{enabled:!0,source:"both",echoCancellation:!0,noiseSuppression:!0},output:{format:"webm",quality:"high"}},pe=({options:z,onRecordingStart:w,onRecordingStop:$,onRecordingPause:A,onRecordingResume:F,onError:R,className:g=""})=>{var t,c;const{t:a}=l.useNiceTranslation(),[n,T]=u.useState({...he,...z}),[j,B]=u.useState(null),[v,b]=u.useState("idle"),[f,E]=u.useState([]),[N,L]=u.useState(null),[U,y]=u.useState(null),[q,V]=u.useState(!1),[C,I]=u.useState(!1),[D,Q]=u.useState("pen"),[X,S]=u.useState("var(--nice-danger, #ff0000)"),_=u.useRef(null),x=u.useRef([]),P=u.useRef(null),W=u.useRef(null),O=u.useRef(null),Z=u.useRef(0);u.useEffect(()=>()=>{N&&N.getTracks().forEach(i=>i.stop()),O.current&&clearInterval(O.current)},[N]);const k=i=>{T(d=>({...d,...i,video:{...d.video,...i.video},audio:{...d.audio,...i.audio},output:{...d.output,...i.output}}))},H=async()=>{try{b("preparing");const i={video:{cursor:n.video.showCursor?"always":"never",frameRate:n.video.frameRate},audio:n.audio.source==="system"||n.audio.source==="both"},d=await navigator.mediaDevices.getDisplayMedia(i);if(n.audio.enabled&&(n.audio.source==="microphone"||n.audio.source==="both"))try{(await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:n.audio.echoCancellation,noiseSuppression:n.audio.noiseSuppression}})).getAudioTracks().forEach(h=>d.addTrack(h))}catch(m){console.warn("Could not access microphone:",m)}L(d),P.current&&(P.current.srcObject=d,P.current.play()),b("idle")}catch(i){b("error"),R==null||R(i instanceof Error?i:new Error("Failed to start preview"))}},M=async()=>{N||await H();for(let i=3;i>0;i--)y(i),await new Promise(d=>setTimeout(d,1e3));y(null);try{const i=N||await ee();if(!i)throw new Error("No stream available");const d=ie(n.output.format),m=new MediaRecorder(i,{mimeType:d,videoBitsPerSecond:te(n.output.quality)});x.current=[],m.ondataavailable=p=>{p.data.size>0&&x.current.push(p.data)},m.onstop=()=>{const p=new Blob(x.current,{type:d});j&&($==null||$({...j,status:"stopped"},p))},_.current=m,m.start(1e3),Z.current=Date.now();const h={id:l.createId(),status:"recording",startTime:new Date,duration:0,size:0,options:n,chunks:[]};B(h),b("recording"),w==null||w(h),O.current=setInterval(()=>{B(p=>p?{...p,duration:(Date.now()-Z.current)/1e3,size:x.current.reduce((re,ce)=>re+ce.size,0)}:null)},100)}catch(i){b("error"),R==null||R(i instanceof Error?i:new Error("Failed to start recording"))}},ee=async()=>(await H(),N),se=()=>{_.current&&v==="recording"&&(_.current.pause(),b("paused"),A==null||A())},G=()=>{_.current&&v==="paused"&&(_.current.resume(),b("recording"),F==null||F())},Y=()=>{O.current&&clearInterval(O.current),_.current&&(v==="recording"||v==="paused")&&(_.current.stop(),b("stopped")),N&&(N.getTracks().forEach(i=>i.stop()),L(null))},J=u.useCallback(i=>{if(v!=="recording")return;const d={id:l.createId(),time:(j==null?void 0:j.duration)||0,label:i||`Marker ${f.length+1}`,color:s()};E(m=>[...m,d])},[v,j==null?void 0:j.duration,f.length]),K=i=>{E(d=>d.filter(m=>m.id!==i))},ie=i=>{switch(i){case"mp4":return"video/mp4";case"mkv":return"video/x-matroska";default:return"video/webm;codecs=vp9"}},te=i=>{switch(i){case"low":return 25e5;case"medium":return 5e6;case"lossless":return 2e7;default:return 8e6}},s=()=>{const i=["var(--nice-danger, #ff4444)","#44ff44","#4444ff","#ffff44","#ff44ff","#44ffff"];return i[Math.floor(Math.random()*i.length)]},r=i=>{const d=Math.floor(i/3600),m=Math.floor(i%3600/60),h=Math.floor(i%60),p=Math.floor(i%1*100);return d>0?`${d}:${m.toString().padStart(2,"0")}:${h.toString().padStart(2,"0")}`:`${m.toString().padStart(2,"0")}:${h.toString().padStart(2,"0")}.${p.toString().padStart(2,"0")}`},o=i=>i<1024?`${i} B`:i<1024*1024?`${(i/1024).toFixed(1)} KB`:`${(i/1024/1024).toFixed(1)} MB`;return e.jsxs("div",{className:`nice-screen-recorder ${g}`,children:[e.jsxs("div",{className:"nice-screen-recorder__preview",children:[U!==null&&e.jsx("div",{className:"nice-screen-recorder__countdown-overlay",children:e.jsx("span",{className:"nice-screen-recorder__countdown-number",children:U})}),e.jsx("video",{ref:P,className:"nice-screen-recorder__preview-video",muted:!0,playsInline:!0}),C&&e.jsx("canvas",{ref:W,className:"nice-screen-recorder__annotation-canvas"}),!N&&v==="idle"&&e.jsx("div",{className:"nice-screen-recorder__preview-placeholder",children:e.jsxs("button",{className:"nice-screen-recorder__start-preview-button",onClick:H,children:[e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"monitor",size:18})}),e.jsx("span",{children:a("screenRecorder.selectScreenToRecord","Select Screen to Record")})]})}),v==="recording"&&e.jsxs("div",{className:"nice-screen-recorder__recording-indicator",children:[e.jsx("span",{className:"nice-screen-recorder__recording-dot"}),e.jsx("span",{children:"REC"})]})]}),e.jsxs("div",{className:"nice-screen-recorder__controls",children:[e.jsxs("div",{className:"nice-screen-recorder__controls-main",children:[v==="idle"&&e.jsxs("button",{className:"nice-screen-recorder__control-button nice-screen-recorder__control-button--record",onClick:M,disabled:!!U,children:[e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"circle",size:18})}),e.jsx("span",{children:a("screenRecorder.startRecording","Start Recording")})]}),v==="recording"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"nice-screen-recorder__control-button nice-screen-recorder__control-button--pause",onClick:se,children:[e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"pause",size:18})}),e.jsx("span",{children:a("screenRecorder.pause","Pause")})]}),e.jsxs("button",{className:"nice-screen-recorder__control-button nice-screen-recorder__control-button--stop",onClick:Y,children:[e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"stop",size:18})}),e.jsx("span",{children:a("screenRecorder.stop","Stop")})]})]}),v==="paused"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"nice-screen-recorder__control-button nice-screen-recorder__control-button--resume",onClick:G,children:[e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"play",size:18})}),e.jsx("span",{children:a("screenRecorder.resume","Resume")})]}),e.jsxs("button",{className:"nice-screen-recorder__control-button nice-screen-recorder__control-button--stop",onClick:Y,children:[e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"stop",size:18})}),e.jsx("span",{children:a("screenRecorder.stop","Stop")})]})]}),v==="stopped"&&e.jsxs("button",{className:"nice-screen-recorder__control-button nice-screen-recorder__control-button--new",onClick:()=>{b("idle"),B(null),E([])},children:[e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"refresh",size:18})}),e.jsx("span",{children:a("screenRecorder.newRecording","New Recording")})]})]}),e.jsxs("div",{className:"nice-screen-recorder__controls-secondary",children:[(v==="recording"||v==="paused")&&e.jsxs("button",{className:"nice-screen-recorder__control-button nice-screen-recorder__control-button--marker",onClick:()=>J(),children:[e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"tag",size:18})}),e.jsx("span",{children:a("screenRecorder.addMarker","Add Marker")})]}),e.jsxs("button",{className:`nice-screen-recorder__control-button ${C?"nice-screen-recorder__control-button--active":""}`,onClick:()=>I(!C),disabled:v!=="recording",children:[e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"pen",size:18})}),e.jsx("span",{children:a("screenRecorder.annotate","Annotate")})]}),e.jsx("button",{className:"nice-screen-recorder__control-button nice-screen-recorder__control-button--settings",onClick:()=>V(!q),disabled:v==="recording","aria-label":a("screenRecorder.settings","Settings"),children:e.jsx("span",{className:"nice-screen-recorder__icon",children:e.jsx(l.NiceIcon,{name:"settings",size:18})})})]})]}),e.jsxs("div",{className:"nice-screen-recorder__status",children:[e.jsxs("div",{className:"nice-screen-recorder__status-info",children:[e.jsxs("span",{className:"nice-screen-recorder__status-item",children:[e.jsx("strong",{children:"Duration:"})," ",r((j==null?void 0:j.duration)||0)]}),e.jsxs("span",{className:"nice-screen-recorder__status-item",children:[e.jsx("strong",{children:"Size:"})," ",o((j==null?void 0:j.size)||0)]}),e.jsxs("span",{className:"nice-screen-recorder__status-item",children:[e.jsx("strong",{children:"Markers:"})," ",f.length]})]}),e.jsxs("div",{className:"nice-screen-recorder__status-quality",children:[n.video.resolution&&e.jsxs("span",{children:[n.video.resolution.width,"x",n.video.resolution.height]}),e.jsxs("span",{children:[n.video.frameRate,"fps"]}),e.jsx("span",{className:`nice-screen-recorder__audio-status nice-screen-recorder__audio-status--${n.audio.enabled?"on":"off"}`,children:e.jsx(l.NiceIcon,{name:n.audio.enabled?"volume":"volume-off",size:14})})]})]}),C&&v==="recording"&&e.jsxs("div",{className:"nice-screen-recorder__annotation-tools",children:[e.jsx("div",{className:"nice-screen-recorder__tool-group",children:["pen","arrow","rectangle","text"].map(i=>e.jsx("button",{className:`nice-screen-recorder__tool-button ${D===i?"nice-screen-recorder__tool-button--active":""}`,onClick:()=>Q(i),"aria-label":i,children:e.jsx(l.NiceIcon,{name:i==="pen"?"pen":i==="arrow"?"arrow-right":i==="rectangle"?"square":"type",size:16})},i))}),e.jsx("div",{className:"nice-screen-recorder__color-group",children:["var(--nice-danger, #ff0000)","var(--nice-success, #00ff00)","var(--nice-primary, #0000ff)","var(--nice-warning, #ffff00)","var(--nice-bg, #fff)","var(--nice-text, #000000)"].map(i=>e.jsx("button",{className:`nice-screen-recorder__color-button ${X===i?"nice-screen-recorder__color-button--active":""}`,style:{backgroundColor:i},onClick:()=>S(i)},i))})]}),f.length>0&&e.jsxs("div",{className:"nice-screen-recorder__markers",children:[e.jsx("h4",{children:a("screenRecorder.markers","Markers")}),e.jsx("div",{className:"nice-screen-recorder__markers-list",children:f.map(i=>e.jsxs("div",{className:"nice-screen-recorder__marker-item",style:{borderLeftColor:i.color},children:[e.jsx("span",{className:"nice-screen-recorder__marker-time",children:r(i.time)}),e.jsx("input",{type:"text",value:i.label,onChange:d=>{E(m=>m.map(h=>h.id===i.id?{...h,label:d.target.value}:h))},className:"nice-screen-recorder__marker-label"}),e.jsx("button",{"aria-label":a("screenRecorder.close","Close"),className:"nice-screen-recorder__marker-remove",onClick:()=>K(i.id),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]},i.id))})]}),q&&e.jsxs("div",{className:"nice-screen-recorder__settings",children:[e.jsxs("div",{className:"nice-screen-recorder__settings-header",children:[e.jsx("h3",{children:a("screenRecorder.recordingSettings","Recording Settings")}),e.jsx("button",{"aria-label":a("screenRecorder.close","Close"),className:"nice-screen-recorder__close-button",onClick:()=>V(!1),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]}),e.jsxs("div",{className:"nice-screen-recorder__settings-section",children:[e.jsx("h4",{children:a("screenRecorder.video","Video")}),e.jsxs("label",{children:[a("screenRecorder.source","Source"),e.jsxs("select",{value:n.video.source,onChange:i=>k({video:{...n.video,source:i.target.value}}),children:[e.jsx("option",{value:"screen",children:a("screenRecorder.entireScreen","Entire Screen")}),e.jsx("option",{value:"window",children:a("screenRecorder.applicationWindow","Application Window")}),e.jsx("option",{value:"tab",children:a("screenRecorder.browserTab","Browser Tab")}),e.jsx("option",{value:"camera",children:a("screenRecorder.camera","Camera")})]})]}),e.jsxs("label",{children:[a("screenRecorder.resolution","Resolution"),e.jsxs("select",{value:`${(t=n.video.resolution)==null?void 0:t.width}x${(c=n.video.resolution)==null?void 0:c.height}`,onChange:i=>{const[d,m]=i.target.value.split("x").map(Number);k({video:{...n.video,resolution:{width:d,height:m}}})},children:[e.jsx("option",{value:"1920x1080",children:"1080p (1920x1080)"}),e.jsx("option",{value:"2560x1440",children:"1440p (2560x1440)"}),e.jsx("option",{value:"3840x2160",children:"4K (3840x2160)"}),e.jsx("option",{value:"1280x720",children:"720p (1280x720)"})]})]}),e.jsxs("label",{children:[a("screenRecorder.frameRate","Frame Rate"),e.jsxs("select",{value:n.video.frameRate,onChange:i=>k({video:{...n.video,frameRate:parseInt(i.target.value)}}),children:[e.jsx("option",{value:"15",children:"15 fps"}),e.jsx("option",{value:"24",children:"24 fps"}),e.jsx("option",{value:"30",children:"30 fps"}),e.jsx("option",{value:"60",children:"60 fps"})]})]}),e.jsxs("label",{className:"nice-screen-recorder__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.video.showCursor,onChange:i=>k({video:{...n.video,showCursor:i.target.checked}})}),a("screenRecorder.showCursor","Show Cursor")]})]}),e.jsxs("div",{className:"nice-screen-recorder__settings-section",children:[e.jsx("h4",{children:a("screenRecorder.audio","Audio")}),e.jsxs("label",{className:"nice-screen-recorder__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.audio.enabled,onChange:i=>k({audio:{...n.audio,enabled:i.target.checked}})}),a("screenRecorder.enableAudio","Enable Audio")]}),n.audio.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:[a("screenRecorder.source","Source"),e.jsxs("select",{value:n.audio.source,onChange:i=>k({audio:{...n.audio,source:i.target.value}}),children:[e.jsx("option",{value:"system",children:a("screenRecorder.systemAudio","System Audio")}),e.jsx("option",{value:"microphone",children:a("screenRecorder.microphone","Microphone")}),e.jsx("option",{value:"both",children:a("screenRecorder.both","Both")})]})]}),e.jsxs("label",{className:"nice-screen-recorder__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.audio.echoCancellation,onChange:i=>k({audio:{...n.audio,echoCancellation:i.target.checked}})}),a("screenRecorder.echoCancellation","Echo Cancellation")]}),e.jsxs("label",{className:"nice-screen-recorder__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.audio.noiseSuppression,onChange:i=>k({audio:{...n.audio,noiseSuppression:i.target.checked}})}),a("screenRecorder.noiseSuppression","Noise Suppression")]})]})]}),e.jsxs("div",{className:"nice-screen-recorder__settings-section",children:[e.jsx("h4",{children:a("screenRecorder.output","Output")}),e.jsxs("label",{children:[a("screenRecorder.format","Format"),e.jsxs("select",{value:n.output.format,onChange:i=>k({output:{...n.output,format:i.target.value}}),children:[e.jsx("option",{value:"webm",children:"WebM (Best Web)"}),e.jsx("option",{value:"mp4",children:"MP4 (Most Compatible)"}),e.jsx("option",{value:"mkv",children:"MKV (Lossless)"})]})]}),e.jsxs("label",{children:[a("screenRecorder.quality","Quality"),e.jsxs("select",{value:n.output.quality,onChange:i=>k({output:{...n.output,quality:i.target.value}}),children:[e.jsx("option",{value:"low",children:"Low (Smaller file)"}),e.jsx("option",{value:"medium",children:a("screenRecorder.medium","Medium")}),e.jsx("option",{value:"high",children:"High (Recommended)"}),e.jsx("option",{value:"lossless",children:"Lossless (Largest file)"})]})]})]})]})]})},xe={id:l.createId(),name:"My Stream",protocol:"rtmp",destinations:[],sources:[],layout:{name:"Default",canvas:{width:1920,height:1080,backgroundColor:"#000000"},layers:[]},settings:{video:{resolution:{width:1920,height:1080},frameRate:30,codec:"h264",bitrate:6e3,keyframe:2,profile:"high"},audio:{sampleRate:48e3,bitrate:160,channels:2,codec:"aac"}}},ae=[{platform:"youtube",name:"YouTube",icon:"video",defaultUrl:"rtmp://a.rtmp.youtube.com/live2"},{platform:"twitch",name:"Twitch",icon:"gamepad",defaultUrl:"rtmp://live.twitch.tv/app"},{platform:"facebook",name:"Facebook",icon:"users",defaultUrl:"rtmps://live-api-s.facebook.com:443/rtmp"},{platform:"custom-rtmp",name:"Custom RTMP",icon:"link",defaultUrl:""},{platform:"custom-srt",name:"Custom SRT",icon:"lock",defaultUrl:""}],ne=[{type:"camera",name:"Camera",icon:"camera"},{type:"screen",name:"Screen Capture",icon:"monitor"},{type:"window",name:"Window Capture",icon:"window"},{type:"browser",name:"Browser Source",icon:"globe"},{type:"image",name:"Image",icon:"image"},{type:"video",name:"Video",icon:"video"},{type:"microphone",name:"Microphone",icon:"mic"},{type:"system-audio",name:"System Audio",icon:"volume"}],_e=({config:z,onConfigChange:w,onStreamStart:$,onStreamStop:A,onStatsUpdate:F,onError:R,className:g=""})=>{const{t:a}=l.useNiceTranslation(),[n,T]=u.useState(z||xe),[j,B]=u.useState("sources"),[v,b]=u.useState(!1),[f,E]=u.useState({duration:0,viewers:0,peakViewers:0,bitrate:0,fps:0,droppedFrames:0,cpuUsage:0,memoryUsage:0}),[N,L]=u.useState(null),[U,y]=u.useState(!1),[q,V]=u.useState(!1),[C,I]=u.useState([n.layout]),[D,Q]=u.useState(0),X=u.useRef(null),S=u.useRef(null),_=u.useRef(0);u.useEffect(()=>{z&&T(z)},[z]),u.useEffect(()=>()=>{S.current&&clearInterval(S.current)},[]);const x=u.useCallback(s=>{const r={...n,...s};T(r),w==null||w(r)},[n,w]),P=s=>{const r=ae.find(t=>t.platform===s),o={id:l.createId(),name:(r==null?void 0:r.name)||"Custom",platform:s,url:(r==null?void 0:r.defaultUrl)||"",streamKey:"",enabled:!0,status:"idle"};x({destinations:[...n.destinations,o]}),V(!1)},W=(s,r)=>{x({destinations:n.destinations.map(o=>o.id===s?{...o,...r}:o)})},O=s=>{x({destinations:n.destinations.filter(r=>r.id!==s)})},Z=async s=>{const r=ne.find(c=>c.type===s),o={id:l.createId(),type:s,name:`${(r==null?void 0:r.name)||s} ${n.sources.filter(c=>c.type===s).length+1}`,settings:{},volume:1,muted:!1};try{if(s==="camera"||s==="microphone"){const c=s==="camera"?{video:!0}:{audio:!0},d=(await navigator.mediaDevices.enumerateDevices()).filter(m=>s==="camera"?m.kind==="videoinput":m.kind==="audioinput");d.length>0&&(o.settings.deviceId=d[0].deviceId)}else(s==="screen"||s==="window")&&await navigator.mediaDevices.getDisplayMedia({video:!0})}catch(c){console.warn(`Could not access ${s}:`,c)}x({sources:[...n.sources,o]});const t={id:l.createId(),sourceId:o.id,position:{x:0,y:0},size:{width:n.layout.canvas.width,height:n.layout.canvas.height},visible:!0,opacity:1,zIndex:n.layout.layers.length};x({layout:{...n.layout,layers:[...n.layout.layers,t]}}),y(!1)},k=(s,r)=>{x({sources:n.sources.map(o=>o.id===s?{...o,...r}:o)})},H=s=>{x({sources:n.sources.filter(r=>r.id!==s),layout:{...n.layout,layers:n.layout.layers.filter(r=>r.sourceId!==s)}})},M=(s,r)=>{x({layout:{...n.layout,layers:n.layout.layers.map(o=>o.id===s?{...o,...r}:o)}})},ee=s=>{const r=n.layout.layers.findIndex(o=>o.id===s);if(r<n.layout.layers.length-1){const o=[...n.layout.layers];[o[r],o[r+1]]=[o[r+1],o[r]],o.forEach((t,c)=>{t.zIndex=c}),x({layout:{...n.layout,layers:o}})}},se=s=>{const r=n.layout.layers.findIndex(o=>o.id===s);if(r>0){const o=[...n.layout.layers];[o[r],o[r-1]]=[o[r-1],o[r]],o.forEach((t,c)=>{t.zIndex=c}),x({layout:{...n.layout,layers:o}})}},G=()=>{const s={name:`Scene ${C.length+1}`,canvas:{...n.layout.canvas},layers:[]};I([...C,s])},Y=s=>{const r=[...C];r[D]=n.layout,I(r),Q(s),x({layout:C[s]})},J=async()=>{try{x({destinations:n.destinations.map(s=>s.enabled?{...s,status:"connecting"}:s)}),await new Promise(s=>setTimeout(s,2e3)),x({destinations:n.destinations.map(s=>s.enabled?{...s,status:"live"}:s)}),b(!0),_.current=Date.now(),$==null||$(),S.current=setInterval(()=>{const s={duration:(Date.now()-_.current)/1e3,viewers:Math.floor(Math.random()*100)+f.viewers,peakViewers:Math.max(f.peakViewers,f.viewers),bitrate:n.settings.video.bitrate+Math.floor(Math.random()*500-250),fps:n.settings.video.frameRate-Math.random()*2,droppedFrames:f.droppedFrames+(Math.random()>.95?1:0),cpuUsage:15+Math.random()*30,memoryUsage:40+Math.random()*20};E(s),F==null||F(s)},1e3)}catch(s){R==null||R(s instanceof Error?s:new Error("Failed to start stream")),x({destinations:n.destinations.map(r=>({...r,status:"error"}))})}},K=()=>{S.current&&clearInterval(S.current),x({destinations:n.destinations.map(s=>({...s,status:"idle"}))}),b(!1),A==null||A()},ie=s=>{const r=Math.floor(s/3600),o=Math.floor(s%3600/60),t=Math.floor(s%60);return`${r.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}:${t.toString().padStart(2,"0")}`},te=s=>{switch(s){case"live":return"var(--nice-success, #00ff00)";case"connecting":return"var(--nice-warning, #ffff00)";case"error":return"var(--nice-danger, #ff0000)";default:return"var(--nice-text-secondary, #888888)"}};return e.jsxs("div",{className:`nice-live-streaming ${g}`,children:[e.jsxs("header",{className:"nice-live-streaming__header",children:[e.jsxs("div",{className:"nice-live-streaming__header-title",children:[e.jsx("input",{type:"text",value:n.name,onChange:s=>x({name:s.target.value}),className:"nice-live-streaming__stream-name-input"}),v&&e.jsxs("span",{className:"nice-live-streaming__live-badge",children:[e.jsx("span",{className:"nice-live-streaming__live-dot"})," ",a("liveStreaming.live","LIVE")]})]}),e.jsx("div",{className:"nice-live-streaming__header-stats",children:v&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"nice-live-streaming__stat-item",children:[e.jsx(l.NiceIcon,{name:"clock",size:14})," ",ie(f.duration)]}),e.jsxs("span",{className:"nice-live-streaming__stat-item",children:[e.jsx(l.NiceIcon,{name:"users",size:14})," ",f.viewers]}),e.jsxs("span",{className:"nice-live-streaming__stat-item",children:[e.jsx(l.NiceIcon,{name:"bar-chart",size:14})," ",Math.round(f.bitrate)," kbps"]}),e.jsxs("span",{className:"nice-live-streaming__stat-item",children:[e.jsx(l.NiceIcon,{name:"video",size:14})," ",f.fps.toFixed(1)," fps"]})]})}),e.jsx("div",{className:"nice-live-streaming__header-actions",children:v?e.jsx("button",{className:"nice-live-streaming__action-button nice-live-streaming__action-button--stop",onClick:K,children:a("liveStreaming.endStream","End Stream")}):e.jsx("button",{className:"nice-live-streaming__action-button nice-live-streaming__action-button--go-live",onClick:J,disabled:n.destinations.filter(s=>s.enabled).length===0,children:a("liveStreaming.goLive","Go Live")})})]}),e.jsxs("div",{className:"nice-live-streaming__main",children:[e.jsxs("div",{className:"nice-live-streaming__preview",children:[e.jsxs("div",{className:"nice-live-streaming__scenes-bar",children:[C.map((s,r)=>e.jsx("button",{className:`nice-live-streaming__scene-button ${D===r?"nice-live-streaming__scene-button--active":""}`,onClick:()=>Y(r),children:s.name},r)),e.jsx("button",{className:"nice-live-streaming__scene-button nice-live-streaming__scene-button--add",onClick:G,children:"+"})]}),e.jsx("div",{ref:X,className:"nice-live-streaming__preview-canvas",style:{aspectRatio:`${n.layout.canvas.width}/${n.layout.canvas.height}`,backgroundColor:n.layout.canvas.backgroundColor},children:n.layout.layers.sort((s,r)=>s.zIndex-r.zIndex).map(s=>{var o;const r=n.sources.find(t=>t.id===s.sourceId);return!s.visible||!r?null:e.jsx("div",{className:`nice-live-streaming__canvas-layer ${N===s.id?"nice-live-streaming__canvas-layer--selected":""}`,style:{left:`${s.position.x/n.layout.canvas.width*100}%`,top:`${s.position.y/n.layout.canvas.height*100}%`,width:`${s.size.width/n.layout.canvas.width*100}%`,height:`${s.size.height/n.layout.canvas.height*100}%`,opacity:s.opacity,zIndex:s.zIndex},onClick:()=>L(s.id),children:e.jsxs("div",{className:"nice-live-streaming__layer-content",children:[e.jsx("span",{className:"nice-live-streaming__layer-icon",children:e.jsx(l.NiceIcon,{name:((o=ne.find(t=>t.type===r.type))==null?void 0:o.icon)??"box",size:16})}),e.jsx("span",{className:"nice-live-streaming__layer-name",children:r.name})]})},s.id)})})]}),e.jsxs("aside",{className:"nice-live-streaming__panel",children:[e.jsx("div",{className:"nice-live-streaming__panel-tabs",children:["sources","audio","destinations","settings"].map(s=>e.jsx("button",{className:`nice-live-streaming__panel-tab ${j===s?"nice-live-streaming__panel-tab--active":""}`,onClick:()=>B(s),children:s.charAt(0).toUpperCase()+s.slice(1)},s))}),e.jsxs("div",{className:"nice-live-streaming__panel-content",children:[j==="sources"&&e.jsxs("div",{className:"nice-live-streaming__sources-panel",children:[e.jsxs("div",{className:"nice-live-streaming__panel-header",children:[e.jsx("h3",{children:a("liveStreaming.sources","Sources")}),e.jsx("button",{className:"nice-live-streaming__add-button",onClick:()=>y(!0),disabled:v,children:"+ Add"})]}),e.jsx("div",{className:"nice-live-streaming__sources-list",children:n.sources.filter(s=>s.type!=="microphone"&&s.type!=="system-audio").map(s=>{var o;const r=n.layout.layers.find(t=>t.sourceId===s.id);return e.jsxs("div",{className:`nice-live-streaming__source-item ${N===(r==null?void 0:r.id)?"nice-live-streaming__source-item--selected":""}`,onClick:()=>r&&L(r.id),children:[e.jsx("span",{className:"nice-live-streaming__source-icon",children:e.jsx(l.NiceIcon,{name:((o=ne.find(t=>t.type===s.type))==null?void 0:o.icon)??"box",size:16})}),e.jsx("span",{className:"nice-live-streaming__source-name",children:s.name}),e.jsxs("div",{className:"nice-live-streaming__source-controls",children:[e.jsx("button",{className:`nice-live-streaming__visibility-toggle ${r!=null&&r.visible?"":"nice-live-streaming__visibility-toggle--hidden"}`,onClick:t=>{t.stopPropagation(),r&&M(r.id,{visible:!r.visible})},children:e.jsx(l.NiceIcon,{name:r!=null&&r.visible?"eye":"eye-off",size:14})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),r&&ee(r.id)},children:e.jsx(l.NiceIcon,{name:"arrow-up",size:14})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),r&&se(r.id)},children:e.jsx(l.NiceIcon,{name:"arrow-down",size:14})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),H(s.id)},disabled:v,children:e.jsx(l.NiceIcon,{name:"trash",size:14})})]})]},s.id)})}),N&&e.jsxs("div",{className:"nice-live-streaming__layer-properties",children:[e.jsx("h4",{children:a("liveStreaming.properties","Properties")}),(()=>{const s=n.layout.layers.find(r=>r.id===N);return s?e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:[a("liveStreaming.xPosition","X Position"),e.jsx("input",{type:"number",value:s.position.x,onChange:r=>M(s.id,{position:{...s.position,x:parseInt(r.target.value)||0}})})]}),e.jsxs("label",{children:[a("liveStreaming.yPosition","Y Position"),e.jsx("input",{type:"number",value:s.position.y,onChange:r=>M(s.id,{position:{...s.position,y:parseInt(r.target.value)||0}})})]}),e.jsxs("label",{children:[a("liveStreaming.width","Width"),e.jsx("input",{type:"number",value:s.size.width,onChange:r=>M(s.id,{size:{...s.size,width:parseInt(r.target.value)||100}})})]}),e.jsxs("label",{children:[a("liveStreaming.height","Height"),e.jsx("input",{type:"number",value:s.size.height,onChange:r=>M(s.id,{size:{...s.size,height:parseInt(r.target.value)||100}})})]}),e.jsxs("label",{children:[a("liveStreaming.opacity","Opacity"),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:s.opacity,onChange:r=>M(s.id,{opacity:parseFloat(r.target.value)})})]})]}):null})()]})]}),j==="audio"&&e.jsxs("div",{className:"nice-live-streaming__audio-panel",children:[e.jsxs("div",{className:"nice-live-streaming__panel-header",children:[e.jsx("h3",{children:a("liveStreaming.audioMixer","Audio Mixer")}),e.jsx("button",{className:"nice-live-streaming__add-button",onClick:()=>{y(!0)},disabled:v,children:"+ Add"})]}),e.jsxs("div",{className:"nice-live-streaming__audio-sources",children:[n.sources.filter(s=>s.type==="microphone"||s.type==="system-audio"||s.type==="video").map(s=>{var r;return e.jsxs("div",{className:"nice-live-streaming__audio-source",children:[e.jsxs("div",{className:"nice-live-streaming__audio-header",children:[e.jsx("span",{className:"nice-live-streaming__audio-icon",children:e.jsx(l.NiceIcon,{name:((r=ne.find(o=>o.type===s.type))==null?void 0:r.icon)??"box",size:16})}),e.jsx("span",{className:"nice-live-streaming__audio-name",children:s.name}),e.jsx("button",{className:`nice-live-streaming__mute-toggle ${s.muted?"nice-live-streaming__mute-toggle--muted":""}`,onClick:()=>k(s.id,{muted:!s.muted}),children:e.jsx(l.NiceIcon,{name:s.muted?"volume-off":"volume",size:14})})]}),e.jsxs("div",{className:"nice-live-streaming__audio-slider",children:[e.jsx("input",{type:"range",min:"0",max:"1",step:"0.01",value:s.volume??1,onChange:o=>k(s.id,{volume:parseFloat(o.target.value)}),disabled:s.muted}),e.jsxs("span",{className:"nice-live-streaming__volume-value",children:[Math.round((s.volume??1)*100),"%"]})]}),e.jsx("div",{className:"nice-live-streaming__audio-meter",children:e.jsx("div",{className:"nice-live-streaming__meter-fill",style:{width:`${(s.volume??1)*70+Math.random()*30}%`}})})]},s.id)}),n.sources.filter(s=>s.type==="microphone"||s.type==="system-audio").length===0&&e.jsx("p",{className:"nice-live-streaming__empty-message",children:a("liveStreaming.noAudioSourcesAdded","No audio sources added")})]})]}),j==="destinations"&&e.jsxs("div",{className:"nice-live-streaming__destinations-panel",children:[e.jsxs("div",{className:"nice-live-streaming__panel-header",children:[e.jsx("h3",{children:a("liveStreaming.destinations","Destinations")}),e.jsx("button",{className:"nice-live-streaming__add-button",onClick:()=>V(!0),disabled:v,children:"+ Add"})]}),e.jsxs("div",{className:"nice-live-streaming__destinations-list",children:[n.destinations.map(s=>{var r;return e.jsxs("div",{className:"nice-live-streaming__destination-item",children:[e.jsxs("div",{className:"nice-live-streaming__destination-header",children:[e.jsx("span",{className:"nice-live-streaming__status-indicator",style:{backgroundColor:te(s.status)}}),e.jsx("span",{className:"nice-live-streaming__destination-icon",children:e.jsx(l.NiceIcon,{name:((r=ae.find(o=>o.platform===s.platform))==null?void 0:r.icon)??"link",size:16})}),e.jsx("span",{className:"nice-live-streaming__destination-name",children:s.name}),e.jsxs("label",{className:"nice-live-streaming__toggle",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:o=>W(s.id,{enabled:o.target.checked}),disabled:v}),e.jsx("span",{className:"nice-live-streaming__toggle-slider"})]})]}),e.jsxs("div",{className:"nice-live-streaming__destination-config",children:[e.jsxs("label",{children:[a("liveStreaming.serverUrl","Server URL"),e.jsx("input",{type:"text",value:s.url,onChange:o=>W(s.id,{url:o.target.value}),placeholder:a("liveStreaming.rtmp","rtmp://..."),disabled:v})]}),e.jsxs("label",{children:[a("liveStreaming.streamKey","Stream Key"),e.jsx("input",{type:"password",value:s.streamKey||"",onChange:o=>W(s.id,{streamKey:o.target.value}),placeholder:a("liveStreaming.enterStreamKey","Enter stream key"),disabled:v})]})]}),e.jsx("button",{className:"nice-live-streaming__remove-button",onClick:()=>O(s.id),disabled:v,children:a("liveStreaming.remove","Remove")})]},s.id)}),n.destinations.length===0&&e.jsx("p",{className:"nice-live-streaming__empty-message",children:a("liveStreaming.noDestinationsConfigured","No destinations configured")})]})]}),j==="settings"&&e.jsxs("div",{className:"nice-live-streaming__settings-panel",children:[e.jsxs("div",{className:"nice-live-streaming__setting-section",children:[e.jsx("h4",{children:a("liveStreaming.video","Video")}),e.jsxs("label",{children:[a("liveStreaming.resolution","Resolution"),e.jsxs("select",{value:`${n.settings.video.resolution.width}x${n.settings.video.resolution.height}`,onChange:s=>{const[r,o]=s.target.value.split("x").map(Number);x({settings:{...n.settings,video:{...n.settings.video,resolution:{width:r,height:o}}},layout:{...n.layout,canvas:{...n.layout.canvas,width:r,height:o}}})},disabled:v,children:[e.jsx("option",{value:"1920x1080",children:"1080p (1920x1080)"}),e.jsx("option",{value:"1280x720",children:"720p (1280x720)"}),e.jsx("option",{value:"2560x1440",children:"1440p (2560x1440)"})]})]}),e.jsxs("label",{children:[a("liveStreaming.frameRate","Frame Rate"),e.jsxs("select",{value:n.settings.video.frameRate,onChange:s=>x({settings:{...n.settings,video:{...n.settings.video,frameRate:parseInt(s.target.value)}}}),disabled:v,children:[e.jsx("option",{value:"24",children:"24 fps"}),e.jsx("option",{value:"30",children:"30 fps"}),e.jsx("option",{value:"60",children:"60 fps"})]})]}),e.jsxs("label",{children:["Bitrate (kbps)",e.jsx("input",{type:"number",value:n.settings.video.bitrate,onChange:s=>x({settings:{...n.settings,video:{...n.settings.video,bitrate:parseInt(s.target.value)||6e3}}}),min:"1000",max:"50000",disabled:v})]}),e.jsxs("label",{children:["Keyframe Interval (sec)",e.jsx("input",{type:"number",value:n.settings.video.keyframe,onChange:s=>x({settings:{...n.settings,video:{...n.settings.video,keyframe:parseInt(s.target.value)||2}}}),min:"1",max:"10",disabled:v})]})]}),e.jsxs("div",{className:"nice-live-streaming__setting-section",children:[e.jsx("h4",{children:a("liveStreaming.audio","Audio")}),e.jsxs("label",{children:[a("liveStreaming.sampleRate","Sample Rate"),e.jsxs("select",{value:n.settings.audio.sampleRate,onChange:s=>x({settings:{...n.settings,audio:{...n.settings.audio,sampleRate:parseInt(s.target.value)}}}),disabled:v,children:[e.jsx("option",{value:"44100",children:"44.1 kHz"}),e.jsx("option",{value:"48000",children:"48 kHz"})]})]}),e.jsxs("label",{children:["Audio Bitrate (kbps)",e.jsxs("select",{value:n.settings.audio.bitrate,onChange:s=>x({settings:{...n.settings,audio:{...n.settings.audio,bitrate:parseInt(s.target.value)}}}),disabled:v,children:[e.jsx("option",{value:"96",children:"96 kbps"}),e.jsx("option",{value:"128",children:"128 kbps"}),e.jsx("option",{value:"160",children:"160 kbps"}),e.jsx("option",{value:"320",children:"320 kbps"})]})]})]})]})]})]})]}),v&&e.jsx("footer",{className:"nice-live-streaming__footer",children:e.jsxs("div",{className:"nice-live-streaming__footer-stats",children:[e.jsxs("span",{className:"nice-live-streaming__stat",children:[e.jsx("label",{children:"CPU"}),e.jsxs("span",{className:"nice-live-streaming__value",children:[f.cpuUsage.toFixed(1),"%"]})]}),e.jsxs("span",{className:"nice-live-streaming__stat",children:[e.jsx("label",{children:a("liveStreaming.memory","Memory")}),e.jsxs("span",{className:"nice-live-streaming__value",children:[f.memoryUsage.toFixed(1),"%"]})]}),e.jsxs("span",{className:"nice-live-streaming__stat",children:[e.jsx("label",{children:a("liveStreaming.dropped","Dropped")}),e.jsx("span",{className:"nice-live-streaming__value",children:f.droppedFrames})]}),e.jsxs("span",{className:"nice-live-streaming__stat",children:[e.jsx("label",{children:a("liveStreaming.peakViewers","Peak Viewers")}),e.jsx("span",{className:"nice-live-streaming__value",children:f.peakViewers})]})]})}),U&&e.jsx("div",{className:"nice-live-streaming__modal-overlay",children:e.jsxs("div",{className:"nice-live-streaming__modal",children:[e.jsxs("div",{className:"nice-live-streaming__modal-header",children:[e.jsx("h3",{children:a("liveStreaming.addSource","Add Source")}),e.jsx("button",{"aria-label":a("liveStreaming.close","Close"),className:"nice-live-streaming__close-button",onClick:()=>y(!1),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]}),e.jsx("div",{className:"nice-live-streaming__modal-content",children:e.jsx("div",{className:"nice-live-streaming__source-type-grid",children:ne.map(s=>e.jsxs("button",{className:"nice-live-streaming__source-type-button",onClick:()=>Z(s.type),children:[e.jsx("span",{className:"nice-live-streaming__icon",children:e.jsx(l.NiceIcon,{name:s.icon,size:24})}),e.jsx("span",{className:"nice-live-streaming__name",children:s.name})]},s.type))})})]})}),q&&e.jsx("div",{className:"nice-live-streaming__modal-overlay",children:e.jsxs("div",{className:"nice-live-streaming__modal",children:[e.jsxs("div",{className:"nice-live-streaming__modal-header",children:[e.jsx("h3",{children:a("liveStreaming.addDestination","Add Destination")}),e.jsx("button",{"aria-label":a("liveStreaming.close","Close"),className:"nice-live-streaming__close-button",onClick:()=>V(!1),children:e.jsx(l.NiceIcon,{name:"close",size:16})})]}),e.jsx("div",{className:"nice-live-streaming__modal-content",children:e.jsx("div",{className:"nice-live-streaming__platform-grid",children:ae.map(s=>e.jsxs("button",{className:"nice-live-streaming__platform-button",onClick:()=>P(s.platform),children:[e.jsx("span",{className:"nice-live-streaming__icon",children:e.jsx(l.NiceIcon,{name:s.icon,size:24})}),e.jsx("span",{className:"nice-live-streaming__name",children:s.name})]},s.platform))})})]})})]})};exports.NiceLiveStreaming=_e;exports.NiceScreenRecorder=pe;exports.NiceVideoEditor=ve;