@turnix-co/konva-editor 2.0.53 → 2.0.56
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.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export{default as Konva}from'konva';import*as be from'react';import be__default,{forwardRef,useRef,useEffect,useCallback,useImperativeHandle,memo,useState,createElement,useMemo,useId,useLayoutEffect}from'react';import {Group,Image as Image$1,Line,Rect,Arc,Arrow,Wedge,Ring,Ellipse,RegularPolygon,Star,Circle,Text,Stage,Layer,Transformer}from'react-konva';import {useSelector,useDispatch}from'react-redux';export{Provider as ReduxProvider}from'react-redux';import {createSlice,configureStore}from'@reduxjs/toolkit';import _l from'perfect-freehand';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {Html}from'react-konva-utils';import {CameraPlus,Camera,Stop,X,Microphone,MicrophoneSlash,Record,Download,Cursor,PenNib,Eraser,TextAa,Shapes,Cards,Image as Image$2,Square,Circle as Circle$1,Triangle,Hexagon,Star as Star$1,Pizza,ArrowRight,LineSegment,Circuitry,ListBullets,ToggleRight,Textbox,TextUnderline,MonitorPlay,ArrowCounterClockwise,ArrowClockwise,Trash,Export,SidebarSimple,Plus,ArrowUpIcon,Lock,LinkIcon,SpeakerHifiIcon,NotePencilIcon,Palette,ScissorsIcon,PencilSimple,CopySimple,Chat,Stack,Check,Play,SpeakerSimpleSlash,SpeakerHigh,ScribbleLoop,Exam,CheckCircle,XCircle,TextB,TextItalic,Warning,CloudArrowUp as CloudArrowUp$1,ArrowsDownUp,Shuffle}from'@phosphor-icons/react/dist/ssr';import {CaretLeft,CloudArrowUp,EyeIcon,Stack as Stack$1,X as X$1,DotsSixVertical,ArrowUp,ArrowDown,Question,FrameCorners,Cards as Cards$1,TextT,Shapes as Shapes$1,VideoCamera,Image as Image$3}from'@phosphor-icons/react';import {createPortal}from'react-dom';import _d from'use-image';import {motion,AnimatePresence,Reorder}from'framer-motion';import {useSyncExternalStoreWithSelector}from'use-sync-external-store/shim/with-selector.js';import {v4}from'uuid';import {QueryClient}from'@tanstack/react-query';var Ol=e=>{throw TypeError(e)};var Nl=(e,o,t)=>o.has(e)||Ol("Cannot "+t);var K=(e,o,t)=>(Nl(e,o,"read from private field"),t?t.call(e):o.get(e)),Te=(e,o,t)=>o.has(e)?Ol("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(e):o.set(e,t),ke=(e,o,t,a)=>(Nl(e,o,"write to private field"),o.set(e,t),t);var Vl=(e,o,t,a)=>({set _(r){ke(e,o,r);},get _(){return K(e,o,a)}});var xe=()=>useDispatch(),ee=e=>useSelector(e),yt=xe,aa=ee;var nn=20,ql=e=>({id:`slide-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:e||`Slide ${Date.now()}`,thumbnail:void 0,backgroundColor:"#ffffff",lines:[],shapes:[],images:[],videos:[],flashcards:[],photoFrames:[],texts:[],activityType:"",multipleChoices:[],trueFalses:[],shortAnswers:[],LongAnswer:[],fillInTheBlanks:[],showMcqForm:false,showFlashcardForm:false,editingActivity:null,editingFlashcard:null,createdAt:Date.now(),updatedAt:Date.now()}),sn=ql("Slide 1"),rm={slides:[sn],currentSlideId:sn.id,history:{[sn.id]:{past:[],future:[]}},isSketchMode:true,editingTextId:null},Ul=createSlice({name:"canvas",initialState:rm,reducers:{addSlide:e=>{if(e.slides.length>=nn)return;let o=ql(`Slide ${e.slides.length+1}`);e.slides.push(o),e.currentSlideId=o.id,e.history[o.id]={past:[],future:[]};},deleteSlide:(e,o)=>{if(e.slides.length<=1)return;let t=e.slides.findIndex(a=>a.id===o.payload);if(t!==-1&&(e.slides.splice(t,1),delete e.history[o.payload],e.currentSlideId===o.payload)){let a=Math.max(0,t-1);e.currentSlideId=e.slides[a].id;}},duplicateSlide:(e,o)=>{if(e.slides.length>=nn)return;let t=e.slides.findIndex(s=>s.id===o.payload);if(t===-1)return;let a=e.slides[t],r={...a,id:`slide-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:`${a.name} (Copy)`,createdAt:Date.now(),updatedAt:Date.now(),lines:JSON.parse(JSON.stringify(a.lines)),images:JSON.parse(JSON.stringify(a.images)),videos:JSON.parse(JSON.stringify(a.videos)),shapes:JSON.parse(JSON.stringify(a.shapes)),flashcards:JSON.parse(JSON.stringify(a.flashcards)),photoFrames:JSON.parse(JSON.stringify(a.photoFrames))};e.slides.splice(t+1,0,r),e.currentSlideId=r.id,e.history[r.id]={past:[],future:[]};},setCurrentSlide:(e,o)=>{e.slides.find(a=>a.id===o.payload)&&(e.currentSlideId=o.payload);},updateSlideThumbnail:(e,o)=>{let t=e.slides.find(a=>a.id===o.payload.id);t&&(t.thumbnail=o.payload.thumbnail,t.updatedAt=Date.now());},setBackgroundColor:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.backgroundColor=o.payload,t.updatedAt=Date.now());},reorderSlides:(e,o)=>{let{fromIndex:t,toIndex:a}=o.payload;if(t<0||t>=e.slides.length||a<0||a>=e.slides.length)return;let[r]=e.slides.splice(t,1);e.slides.splice(a,0,r);},loadSlides:(e,o)=>{e.slides=o.payload.slides.map(t=>({...t,showMcqForm:false})),e.currentSlideId=o.payload.currentSlideId,e.history={},o.payload.slides.forEach(t=>{e.history[t.id]={past:[],future:[]};});},addLine:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,id:o.payload.id||`line-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,timestamp:o.payload.timestamp||Date.now(),x:o.payload.x||0,y:o.payload.y||0};t.lines.push(a),t.updatedAt=Date.now();}},removeLine:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);t&&o.payload>=0&&o.payload<t.lines.length&&(t.lines.splice(o.payload,1),t.updatedAt=Date.now());},updateLastLine:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);t&&t.lines.length>0&&(t.lines[t.lines.length-1].points=o.payload,t.updatedAt=Date.now());},finalizeDrawing:e=>{let o=e.slides.find(t=>t.id===e.currentSlideId);o&&(o.updatedAt=Date.now());},setLines:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.lines=o.payload,t.updatedAt=Date.now());},updateLinePosition:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.lines.find(r=>r.id===o.payload.id);a&&(a.x=o.payload.x,a.y=o.payload.y,t.updatedAt=Date.now());}},updateLineTransform:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.lines.find(r=>r.id===o.payload.id);a&&(a.x=o.payload.x,a.y=o.payload.y,a.scaleX=o.payload.scaleX,a.scaleY=o.payload.scaleY,a.rotation=o.payload.rotation,t.updatedAt=Date.now());}},deleteLineById:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.lines.findIndex(r=>r.id===o.payload);a!==-1&&(t.lines.splice(a,1),t.updatedAt=Date.now());}},duplicateLine:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.lines.find(r=>r.id===o.payload);if(a){let r={...a,id:`line-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,x:(a.x||0)+20,y:(a.y||0)+20,timestamp:Date.now()};t.lines.push(r),t.updatedAt=Date.now();}}},updateElementOrder:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r,newTimestamp:s}=o.payload;switch(r){case "image":let n=t.images.find(g=>g.id===a);n&&(n.timestamp=s);break;case "video":let i=t.videos.find(g=>g.id===a);i&&(i.timestamp=s);break;case "shape":let u=t.shapes.find(g=>g.id===a);u&&(u.timestamp=s);break;case "text":let l=t.texts.find(g=>g.id===a);l&&(l.timestamp=s);break;case "flashcard":let c=t.flashcards.find(g=>g.id===a);c&&(c.timestamp=s);break;case "photoFrame":let d=t.photoFrames.find(g=>g.id===a);d&&(d.timestamp=s);break;case "mcq":let m=t.multipleChoices.find(g=>g.id===a);m&&(m.timestamp=s);break;case "trueFalse":let f=t.trueFalses.find(g=>g.id===a);f&&(f.timestamp=s);break;case "shortAnswer":let h=t.shortAnswers.find(g=>g.id===a);h&&(h.timestamp=s);break;case "longAnswer":let x=t.LongAnswer.find(g=>g.id===a);x&&(x.timestamp=s);break;case "fillInTheBlanks":let p=t.fillInTheBlanks.find(g=>g.id===a);p&&(p.timestamp=s);break;case "line":let v=t.lines.find(g=>g.id===a);v&&(v.timestamp=s);break}t.updatedAt=Date.now();}},addImage(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.images.push(a),t.updatedAt=Date.now();}},updateImage(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.images[a]={...t.images[a],...o.payload},t.updatedAt=Date.now());}},deleteImage(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.images=t.images.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateImage(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload);if(a){let r={...a,id:`img-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.images.push(r),t.updatedAt=Date.now();}}},addVideo(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.videos.push(a),t.updatedAt=Date.now();}},updateVideo(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.videos.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.videos[a]={...t.videos[a],...o.payload},t.updatedAt=Date.now());}},toggleVideoPlaying(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.videos.find(r=>r.id===o.payload);a&&(a.isPlaying=!a.isPlaying,t.updatedAt=Date.now());}},deleteVideo(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.videos=t.videos.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateVideo(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.videos.find(r=>r.id===o.payload);if(a){let r={...a,id:`vid-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,isPlaying:false,timestamp:Date.now()};t.videos.push(r),t.updatedAt=Date.now();}}},addShape(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.shapes?.push(a),t.updatedAt=Date.now();}},updateShape(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.shapes.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.shapes[a]={...t.shapes[a],...o.payload},t.updatedAt=Date.now());}},duplicateShape(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.shapes.find(r=>r.id===o.payload);if(a){let r={...a,id:`shape-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.shapes.push(r),t.updatedAt=Date.now();}}},deleteShape(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.shapes=t.shapes.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},addMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.multipleChoices||(t.multipleChoices=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.multipleChoices.length>0){let r=t.multipleChoices[t.multipleChoices.length-1];a.x=r.x+20,a.y=r.y+20;}t.multipleChoices.push(a),t.updatedAt=Date.now();}},updateMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t&&t.multipleChoices){let a=t.multipleChoices.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.multipleChoices[a]={...t.multipleChoices[a],...o.payload},t.updatedAt=Date.now());}},editMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t&&t.multipleChoices){let a=t.multipleChoices.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.multipleChoices[a]={...t.multipleChoices[a],...o.payload},t.updatedAt=Date.now());}},duplicateMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.multipleChoices.find(r=>r.id===o.payload);if(a){let r={...a,id:`mcq-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.multipleChoices.push(r),t.updatedAt=Date.now();}}},deleteMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.multipleChoices=t.multipleChoices.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},addTrueFalse(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.trueFalses||(t.trueFalses=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.trueFalses.length>0){let r=t.trueFalses[t.trueFalses.length-1];a.x=r.x+20,a.y=r.y+20;}t.trueFalses.push(a),t.updatedAt=Date.now();}},updateTrueFalse(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.trueFalses.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.trueFalses[a]={...t.trueFalses[a],...o.payload},t.updatedAt=Date.now());}},deleteTrueFalse(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.trueFalses=t.trueFalses.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateTrueFalse(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.trueFalses.find(r=>r.id===o.payload);if(a){let r={...a,id:`shape-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.trueFalses.push(r),t.updatedAt=Date.now();}}},addShortAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.shortAnswers||(t.shortAnswers=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.shortAnswers.length>0){let r=t.shortAnswers[t.shortAnswers.length-1];a.x=r.x+20,a.y=r.y+20;}t.shortAnswers.push(a),t.updatedAt=Date.now();}},updateShortAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.shortAnswers.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.shortAnswers[a]={...t.shortAnswers[a],...o.payload},t.updatedAt=Date.now());}},duplicateShortAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.shortAnswers.find(r=>r.id===o.payload);if(a){let r={...a,id:`shortAnswer-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.shortAnswers.push(r),t.updatedAt=Date.now();}}},deleteShortAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.shortAnswers=t.shortAnswers.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},addLongAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.LongAnswer||(t.LongAnswer=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.LongAnswer.length>0){let r=t.LongAnswer[t.LongAnswer.length-1];a.x=r.x+20,a.y=r.y+20;}t.LongAnswer.push(a),t.updatedAt=Date.now();}},updateLongAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.LongAnswer.find(r=>r.id===o.payload.id);a&&(Object.assign(a,o.payload),t.updatedAt=Date.now());}},deleteLongAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.LongAnswer=t.LongAnswer.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateLongAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.LongAnswer.find(r=>r.id===o.payload);if(a){let r={...a,id:`${a.id}-copy-${Date.now()}`,timestamp:Date.now()};t.LongAnswer.push(r),t.updatedAt=Date.now();}}},setShowMcqForm(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.showMcqForm=o.payload,t.updatedAt=Date.now());},setShowFlashcardForm(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.showFlashcardForm=o.payload,t.updatedAt=Date.now());},addFillInTheBlanks(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.fillInTheBlanks||(t.fillInTheBlanks=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.fillInTheBlanks.length>0){let r=t.fillInTheBlanks[t.fillInTheBlanks.length-1];a.x=r.x+20,a.y=r.y+20;}t.fillInTheBlanks.push(a),t.updatedAt=Date.now();}},updateFillInTheBlanks(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.fillInTheBlanks.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.fillInTheBlanks[a]={...t.fillInTheBlanks[a],...o.payload},t.updatedAt=Date.now());}},deleteFillInTheBlanks(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.fillInTheBlanks=t.fillInTheBlanks.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateFillInTheBlanks(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.fillInTheBlanks.find(r=>r.id===o.payload);if(a){let r={...a,id:`fillInTheBlank-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.fillInTheBlanks.push(r),t.updatedAt=Date.now();}}},setActivityType(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.activityType=o.payload,t.updatedAt=Date.now());},setEditingActivity(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.editingActivity=o.payload,t.updatedAt=Date.now());},bringToFront(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r}=o.payload;if(r==="image"){let s=t.images.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.images.splice(s,1);t.images.push(n);}}else if(r==="video"){let s=t.videos.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.videos.splice(s,1);t.videos.push(n);}}else if(r==="shape"){let s=t.shapes.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.shapes.splice(s,1);t.shapes.push(n);}}else if(r==="flashcard"){let s=t.flashcards.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.flashcards.splice(s,1);t.flashcards.push(n);}}else if(r==="photoFrame"){let s=t.photoFrames.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.photoFrames.splice(s,1);t.photoFrames.push(n);}}else if(r==="text"){let s=t.texts.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.texts.splice(s,1);t.texts.push(n);}}else if(r==="trueFalse"){let s=t.trueFalses.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.trueFalses.splice(s,1);t.trueFalses.push(n);}}else if(r==="shortAnswer"){let s=t.shortAnswers.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.shortAnswers.splice(s,1);t.shortAnswers.push(n);}}else if(r==="fillInTheBlanks"){let s=t.fillInTheBlanks.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.fillInTheBlanks.splice(s,1);t.fillInTheBlanks.push(n);}}t.updatedAt=Date.now();}},sendToBack(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r}=o.payload;if(r==="image"){let s=t.images.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.images.splice(s,1);t.images.unshift(n);}}else if(r==="video"){let s=t.videos.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.videos.splice(s,1);t.videos.unshift(n);}}else if(r==="shape"){let s=t.shapes.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.shapes.splice(s,1);t.shapes.unshift(n);}}else if(r==="flashcard"){let s=t.flashcards.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.flashcards.splice(s,1);t.flashcards.unshift(n);}}else if(r==="photoFrame"){let s=t.photoFrames.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.photoFrames.splice(s,1);t.photoFrames.unshift(n);}}else if(r==="text"){let s=t.texts.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.texts.splice(s,1);t.texts.unshift(n);}}t.updatedAt=Date.now();}},toggleLock(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r}=o.payload,n=(r==="image"?t.images:r==="video"?t.videos:r==="shape"?t.shapes:r==="flashcard"?t.flashcards:r==="photoFrame"?t.photoFrames:r==="trueFalse"?t.trueFalses:r==="shortAnswer"?t.shortAnswers:r==="fillInTheBlanks"?t.fillInTheBlanks:t.texts).find(i=>i.id===a);n&&(n.locked=!n.locked,"draggable"in n&&(n.draggable=!n.locked),t.updatedAt=Date.now());}},setLink(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r,link:s}=o.payload,i=(r==="image"?t.images:r==="video"?t.videos:r==="shape"?t.shapes:r==="flashcard"?t.flashcards:r==="photoFrame"?t.photoFrames:r==="mcq"?t.multipleChoices:r==="trueFalse"?t.trueFalses:r==="shortAnswer"?t.shortAnswers:r==="fillInTheBlanks"?t.fillInTheBlanks:t.texts).find(u=>u.id===a);i&&(i.link=s,t.updatedAt=Date.now());}},setAltText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r,altText:s}=o.payload,i=(r==="image"?t.images:r==="video"?t.videos:r==="shape"?t.shapes:r==="flashcard"?t.flashcards:r==="photoFrame"?t.photoFrames:r==="trueFalse"?t.trueFalses:r==="shortAnswer"?t.shortAnswers:r==="fillInTheBlanks"?t.fillInTheBlanks:t.texts).find(u=>u.id===a);i&&(i.altText=s,t.updatedAt=Date.now());}},setAudioData(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r,audioData:s}=o.payload,i=(r==="image"?t.images:r==="video"?t.videos:r==="shape"?t.shapes:r==="flashcard"?t.flashcards:r==="photoFrame"?t.photoFrames:r==="trueFalse"?t.trueFalses:r==="shortAnswer"?t.shortAnswers:r==="fillInTheBlanks"?t.fillInTheBlanks:t.texts).find(u=>u.id===a);i&&(i.audioData=s,t.updatedAt=Date.now());}},clearCanvas:e=>{let o=e.slides.find(t=>t.id===e.currentSlideId);o&&(o.lines=[],o.images=[],o.videos=[],o.shapes=[],o.flashcards=[],o.photoFrames=[],o.texts=[],o.multipleChoices=[],o.trueFalses=[],o.shortAnswers=[],o.LongAnswer=[],o.fillInTheBlanks=[],o.updatedAt=Date.now());},addText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.texts.push(a),t.updatedAt=Date.now();}},updateText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.texts.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.texts[a]={...t.texts[a],...o.payload},t.updatedAt=Date.now());}},deleteText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.texts=t.texts.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.texts.find(r=>r.id===o.payload);if(a){let r={...a,id:`text-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.texts.push(r),t.updatedAt=Date.now();}}},addFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.flashcards.length>=40){alert("You can add maximum 40 flashcards");return}t.flashcards.push(a),t.updatedAt=Date.now();}},updateFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.flashcards.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.flashcards[a]={...t.flashcards[a],...o.payload},t.updatedAt=Date.now());}},deleteFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.flashcards=t.flashcards.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.flashcards.find(r=>r.id===o.payload);if(a){let r={...a,id:`flashcard-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,currentIndex:0,timestamp:Date.now()};t.flashcards.push(r),t.updatedAt=Date.now();}}},editFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.editingFlashcard=o.payload);},nextFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.flashcards.find(r=>r.id===o.payload);if(a&&a.images.length>0){if(a.order==="sequential")a.currentIndex=(a.currentIndex+1)%a.images.length;else {a.navigationHistory||(a.navigationHistory=[a.currentIndex]);let r=a.images.map((s,n)=>n).filter(s=>s!==a.currentIndex);if(r.length>0){let s=r[Math.floor(Math.random()*r.length)];a.navigationHistory.push(s),a.currentIndex=s;}}t.updatedAt=Date.now();}}},previousFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.flashcards.find(r=>r.id===o.payload);a&&a.images.length>0&&(a.order==="sequential"?a.currentIndex=(a.currentIndex-1+a.images.length)%a.images.length:a.navigationHistory&&a.navigationHistory.length>1&&(a.navigationHistory.pop(),a.currentIndex=a.navigationHistory[a.navigationHistory.length-1]),t.updatedAt=Date.now());}},addPhotoFrame(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.photoFrames.push(a),t.updatedAt=Date.now();}},updatePhotoFrame(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.photoFrames[a]={...t.photoFrames[a],...o.payload},t.updatedAt=Date.now());}},deletePhotoFrame(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.photoFrames=t.photoFrames.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicatePhotoFrame(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload);if(a){let r={...a,id:`photoframe-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,isCapturing:false,timestamp:Date.now()};t.photoFrames.push(r),t.updatedAt=Date.now();}}},toggleImageDrawingMode(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload);a&&(a.isDrawingMode=!a.isDrawingMode,a.annotations||(a.annotations=[]),t.updatedAt=Date.now());}},addImageAnnotation(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload.imageId);a&&(a.annotations||(a.annotations=[]),a.annotations.push(o.payload.line),t.updatedAt=Date.now());}},updateImageAnnotation(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload.imageId);a&&a.annotations&&a.annotations.length>0&&(a.annotations[a.annotations.length-1].points=o.payload.points,t.updatedAt=Date.now());}},clearImageAnnotations(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload);a&&(a.annotations=[],t.updatedAt=Date.now());}},togglePhotoFrameDrawingMode(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload);a&&(a.isDrawingMode=!a.isDrawingMode,a.annotations||(a.annotations=[]),t.updatedAt=Date.now());}},addPhotoFrameAnnotation(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload.frameId);a&&(a.annotations||(a.annotations=[]),a.annotations.push(o.payload.line),t.updatedAt=Date.now());}},updatePhotoFrameAnnotation(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload.frameId);a&&a.annotations&&a.annotations.length>0&&(a.annotations[a.annotations.length-1].points=o.payload.points,t.updatedAt=Date.now());}},clearPhotoFrameAnnotations(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload);a&&(a.annotations=[],t.updatedAt=Date.now());}},undo:e=>{let o=e.history[e.currentSlideId];if(o&&o.past.length>0){let t=e.slides.findIndex(a=>a.id===e.currentSlideId);if(t>=0)try{let a=e.slides[t];o.future.unshift(JSON.parse(JSON.stringify(a)));let r=o.past.pop();e.slides[t]=r;}catch(a){console.warn("Failed to undo - data too large:",a),o.past=[],o.future=[];}}},redo:e=>{let o=e.history[e.currentSlideId];if(o&&o.future.length>0){let t=e.slides.findIndex(a=>a.id===e.currentSlideId);if(t>=0)try{let a=e.slides[t];o.past.push(JSON.parse(JSON.stringify(a)));let r=o.future.shift();e.slides[t]=r;}catch(a){console.warn("Failed to redo - data too large:",a),o.past=[],o.future=[];}}},saveToHistory:e=>{let o=e.slides.findIndex(t=>t.id===e.currentSlideId);if(o>=0){let t=e.slides[o],a=e.history[e.currentSlideId];if(a)try{let r=JSON.parse(JSON.stringify(t));a.past.push(r),a.future=[],a.past.length>20&&a.past.shift();}catch(r){console.warn("Failed to save to history - data too large:",r),a.past.length>5&&(a.past=a.past.slice(-5)),a.future=[];}}},toggleSketchMode:e=>{e.isSketchMode=!e.isSketchMode;},setSketchMode:(e,o)=>{e.isSketchMode=o.payload;},setEditingTextId:(e,o)=>{e.editingTextId=o.payload;}}}),{addSlide:ln,deleteSlide:dn,duplicateSlide:un,setCurrentSlide:cn,updateSlideThumbnail:fn,setBackgroundColor:mn,reorderSlides:sm,loadSlides:Xa,addLine:pn,removeLine:Ur,addImage:hn,updateImage:Ya,deleteImage:gn,duplicateImage:Hr,addVideo:zr,updateVideo:Wr,deleteVideo:xn,duplicateVideo:Gr,toggleVideoPlaying:Eo,addShape:bn,updateShape:Ja,duplicateShape:Kr,deleteShape:vn,addText:yn,updateText:wt,deleteText:wn,duplicateText:_r,addFlashcard:Ln,updateFlashcard:Za,deleteFlashcard:Sn,duplicateFlashcard:jr,editFlashcard:Bo,nextFlashcard:In,previousFlashcard:Cn,addPhotoFrame:kn,updatePhotoFrame:Aa,deletePhotoFrame:Mn,duplicatePhotoFrame:$r,toggleImageDrawingMode:Tn,addImageAnnotation:An,updateImageAnnotation:nm,clearImageAnnotations:im,togglePhotoFrameDrawingMode:Pn,addPhotoFrameAnnotation:Dn,updatePhotoFrameAnnotation:lm,clearPhotoFrameAnnotations:dm,addMultipleChoice:Rn,updateMultipleChoice:oa,editMultipleChoice:um,deleteMultipleChoice:Fn,duplicateMultipleChoice:Xr,addTrueFalse:En,updateTrueFalse:ra,deleteTrueFalse:Bn,duplicateTrueFalse:Yr,addShortAnswer:On,updateShortAnswer:Oo,deleteShortAnswer:Nn,duplicateShortAnswer:Jr,addLongAnswer:Vn,updateLongAnswer:No,deleteLongAnswer:qn,duplicateLongAnswer:Zr,addFillInTheBlanks:Un,updateFillInTheBlanks:Vo,deleteFillInTheBlanks:Hn,duplicateFillInTheBlanks:Qr,setShowMcqForm:sa,setShowFlashcardForm:Pa,setActivityType:zn,setEditingActivity:qo,bringToFront:Wn,sendToBack:Gn,toggleLock:Kn,setLink:es,setAltText:ts,setAudioData:as,updateLastLine:cm,finalizeDrawing:_n,setLines:fm,updateLinePosition:mm,updateLineTransform:os,deleteLineById:jn,duplicateLine:$n,updateElementOrder:Uo,clearCanvas:Xn,undo:Yn,redo:Jn,saveToHistory:ue,toggleSketchMode:pm,setSketchMode:dt,setEditingTextId:Ho}=Ul.actions,zo=e=>e.canvas.currentSlideId,ge=e=>{let o=e.canvas.currentSlideId,t=e.canvas.slides.findIndex(a=>a.id===o);return t>=0?e.canvas.slides[t]:void 0},Wo=e=>e.canvas.slides,Zn=e=>e.canvas.slides.length<nn,hm=e=>o=>{let t=o.canvas.slides.findIndex(a=>a.id===e);return t>=0?o.canvas.slides[t]:void 0},Hl=Ul.reducer;var Wl=e=>{let o=xe(),t=useRef(null),a=useRef(false),r=ee(f=>f.toolbar.selectedTool),s=ee(f=>f.toolbar.penColor),n=ee(f=>f.toolbar.strokeWidth),i=ee(f=>f.canvas.isSketchMode),u=ee(f=>f.canvas.slides.find(x=>x.id===f.canvas.currentSlideId)?.lines||[]),l=useCallback(f=>{t.current=f;},[]),c=useCallback(f=>{r==="pen"&&t.current&&(o(ue()),t.current.startDrawing(f),a.current=true);},[r,o]),d=useCallback(f=>{!t.current||!a.current||t.current.draw(f);},[]),m=useCallback(()=>{if(!t.current||!a.current)return;let f=t.current.stopDrawing();a.current=false,f&&f.points.length>=4&&o(pn(f)),o(_n()),e?.();},[o,e]);return {lines:u,tool:r,color:s,strokeWidth:n,isSketchMode:i,setCanvasRef:l,startDrawing:c,draw:d,stopDrawing:m}};var jl=forwardRef(({width:e,height:o,tool:t,color:a,strokeWidth:r,isSketchMode:s,style:n},i)=>{let u=useRef(null),l=useRef(false),c=useRef([]),d=useRef(null),m=useRef(t),f=useRef(a),h=useRef(r),x=useRef(s);useEffect(()=>{m.current=t,f.current=a,h.current=r,x.current=s;},[t,a,r,s]);let p=useCallback(()=>{let g=u.current;if(!g)return;let b=g.getContext("2d");b&&b.clearRect(0,0,g.width,g.height);},[]),v=useCallback(()=>{let g=u.current,b=c.current;if(!g||b.length<1)return;let y=g.getContext("2d");if(!y)return;if(y.clearRect(0,0,g.width,g.height),m.current==="eraser"?(y.globalCompositeOperation="destination-out",y.fillStyle="rgba(0,0,0,1)"):(y.globalCompositeOperation="source-over",y.fillStyle=f.current),b.length===1){y.beginPath(),y.arc(b[0].x,b[0].y,h.current/2,0,Math.PI*2),y.fill();return}let I=_l(b,{size:h.current,thinning:.5,smoothing:.5,streamline:.5,simulatePressure:true,easing:C=>C,start:{taper:0,cap:true},end:{taper:0,cap:true}});if(!(I.length<2)){y.beginPath(),y.moveTo(I[0][0],I[0][1]);for(let C=1;C<I.length;C++)y.lineTo(I[C][0],I[C][1]);y.closePath(),y.fill();}},[]);return useImperativeHandle(i,()=>({startDrawing:g=>{l.current=true,c.current=[{x:g.x,y:g.y}],d.current=g,v();},draw:g=>{if(!l.current||!d.current)return;let b=g.x-d.current.x,y=g.y-d.current.y;Math.sqrt(b*b+y*y)<2||(c.current.push({x:g.x,y:g.y}),d.current=g,v());},stopDrawing:()=>{if(!l.current)return null;if(l.current=false,c.current.length<2)return c.current=[],d.current=null,p(),null;let b=_l(c.current,{size:h.current,thinning:.5,smoothing:.5,streamline:.5,simulatePressure:true,easing:S=>S,start:{taper:0,cap:true},end:{taper:0,cap:true}}).flatMap(S=>[S[0],S[1]]),y={tool:m.current,points:b,color:f.current,strokeWidth:h.current,isSketch:true};return c.current=[],d.current=null,p(),y},clear:()=>{p(),c.current=[],d.current=null,l.current=false;},isDrawing:()=>l.current,getCanvasElement:()=>u.current}),[p,v]),useEffect(()=>{let g=u.current;g&&(g.width=e,g.height=o);},[e,o]),jsx("canvas",{ref:u,width:e,height:o,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:1e3,...n}})});jl.displayName="DirectDrawingCanvas";var $l=jl;var Yl=e=>{let o=xe(),a=ee(ge)?.images||[],r=useRef(new Map),s=useRef(new Map),n=useRef(new Set);useEffect(()=>{let c=new Set(a.map(d=>d.id));n.current.forEach(d=>{if(!c.has(d)){let m=s.current.get(d);m&&(m.src="",s.current.delete(d)),r.current.delete(d);}}),n.current=c;},[a]),useEffect(()=>()=>{s.current.forEach(c=>{c.src="";}),s.current.clear(),r.current.clear();},[]);let i=useCallback(c=>{if(s.current.has(c.id))return s.current.get(c.id);let d=new window.Image;return d.crossOrigin="anonymous",d.src=c.src,s.current.set(c.id,d),d},[]),u=useCallback((c,d)=>{let m=c.target,f=m.id();a.find(x=>x.id===f)&&(o(Ya({id:f,x:m.x(),y:m.y(),width:m.width(),height:m.height(),rotation:m.rotation()})),d?.());},[a,o]),l=useCallback((c,d)=>{let m=d.target,f=r.current.get(c);if(!f){console.error("\u274C Image node not found for id:",c);return}let h=m.scaleX(),x=m.scaleY(),p=m.rotation(),v=f.width(),g=f.height(),b=Math.max(5,v*h),y=Math.max(5,g*x);m.scaleX(1),m.scaleY(1),f.width(b),f.height(y),o(Ya({id:c,width:b,height:y,x:m.x(),y:m.y(),rotation:p})),m.getLayer()?.batchDraw(),e?.();},[o,e]);return {images:a,getLoadedImage:i,imageRefs:r,handleDragEnd:u,handleImageTransformEnd:l}};var Jl=e=>{let o=useDispatch(),t=useSelector(ge),a=useRef(new Map),r=useMemo(()=>t?.multipleChoices||[],[t?.multipleChoices]),s=useCallback((i,u)=>{let l=u.target,c=l.scaleX(),d=l.scaleY(),m=l.rotation(),f=Math.max(5,l.width()*c),h=Math.max(5,l.height()*d);l.scaleX(1),l.scaleY(1),l.width(f),l.height(h),o(oa({id:i,width:f,height:h,x:l.x(),y:l.y(),rotation:m})),l.getLayer()?.batchDraw(),e?.();},[o,e]);return {multipleChoice:r,handleMcqTransform:s,mcqRefs:a,handleDragEnd:(i,u)=>{o(oa({id:u,x:i.target.x(),y:i.target.y()})),e?.();}}};var Zl=e=>{let o=useDispatch(),t=useSelector(ge),a=useRef(new Map),r=useMemo(()=>t?.trueFalses||[],[t?.trueFalses]),s=useCallback((i,u)=>{let l=u.target,c=l.scaleX(),d=l.scaleY(),m=l.rotation(),f=Math.max(5,l.width()*c),h=Math.max(5,l.height()*d);l.scaleX(1),l.scaleY(1),l.width(f),l.height(h),o(ra({id:i,width:f,height:h,x:l.x(),y:l.y(),rotation:m})),l.getLayer()?.batchDraw(),e?.();},[o,e]);return {trueFalse:r,handleTrueFalseTransform:s,handleTrueFalseDragEnd:(i,u)=>{o(ra({id:u,x:i.target.x(),y:i.target.y()})),e?.();},trueFalseRefs:a}};var Ql=e=>{let o=xe(),a=ee(ge)?.videos||[],r=useRef(new Map),s=useCallback(u=>{o(Eo(u));},[o]),n=useCallback((u,l)=>{let c=l.target;o(Wr({id:u,x:c.x(),y:c.y()})),e?.();},[o,e]),i=useCallback((u,l)=>{let c=l.target,d=c.scaleX(),m=c.scaleY(),f=c.rotation(),h=Math.max(5,c.width()*d),x=Math.max(5,c.height()*m);c.scaleX(1),c.scaleY(1),c.width(h),c.height(x),o(Wr({id:u,width:h,height:x,x:c.x(),y:c.y(),rotation:f})),c.getLayer()?.batchDraw(),e?.();},[o,e]);return {videos:a,videoRefs:r,handleVideoClick:s,handleVideoDragEnd:n,handleVideoTransformEnd:i}};var ad=e=>{let o=xe(),a=ee(ge)?.shapes||[],r=useRef(new Map),s=useRef(new Map),[n,i]=useState(false),u=useCallback((c,d)=>{let m=d.target;o(Ja({id:c,x:m.x(),y:m.y()})),e?.();},[o,e]),l=useCallback((c,d)=>{let m=d.target,f=a.find(b=>b.id===c);if(!f)return;let h=m.scaleX(),x=m.scaleY(),p=f.type?.toLowerCase();p==="arrow"||p==="line"||(m.scaleX(1),m.scaleY(1));let g={id:c,x:m.x(),y:m.y(),width:Math.max(5,m.width()*h),height:Math.max(5,m.height()*x),rotation:m.rotation()};switch(p){case "circle":g.radius=m.width()*h/2;break;case "star":g.innerRadius=m.width()*h/4,g.outerRadius=m.width()*h/2;break;case "triangle":g.radius=m.width()*h/2;break;case "ellipse":g.radiusX=m.width()*h/2,g.radiusY=m.height()*x/2;break;case "polygon":g.radius=m.width()*h/2;break;case "ring":let b=h;g.innerRadius=f.innerRadius&&f.innerRadius*b,g.outerRadius=f.outerRadius&&f.outerRadius*b;break;case "wedge":g.radius=f.radius&&f.radius*h;break;case "arc":g.innerRadius=f.innerRadius&&f.innerRadius*h,g.outerRadius=f.outerRadius&&f.outerRadius*h;break;case "arrow":case "line":{g.scaleX=h,g.scaleY=x,delete g.width,delete g.height;break}}o(Ja(g)),e?.();},[o,e,a]);return {shapes:a,shapeRefs:r,isDragging:n,loadedShapesRef:s,handleShapeDragEnd:u,handleShapeResizeEnd:l}};var rd=(e,o)=>{let t=yt(),r=ee(ge)?.texts||[],s=useRef(new Map),[n,i]=useState(null),[u,l]=useState("");return {texts:r,textRefs:s,handleDragEnd:(p,v)=>{let g=p.target;t(ue()),t(wt({id:v,x:g.x(),y:g.y()})),e();},handleTransformEnd:p=>{let v=s.current.get(p);if(!v)return;let g=v.scaleX(),b=v.scaleY(),y=r.find(I=>I.id===p);if(!y)return;let S=(g+b)/2;v.scaleX(1),v.scaleY(1),t(ue()),t(wt({id:p,x:v.x(),y:v.y(),width:Math.max(5,(y.width||100)*g),height:Math.max(5,(y.height||50)*b),fontSize:Math.round(Math.max(8,y.fontSize*S)),rotation:v.rotation()})),e();},handleDoubleClick:p=>{let v=r.find(g=>g.id===p);v&&!v.locked&&(i(p),l(v.text));},startEditing:p=>{let v=r.find(g=>g.id===p);v&&!v.locked&&(i(p),l(v.text));},editingTextId:n,editingValue:u,handleEditingChange:p=>{l(p);},finishEditing:()=>{if(n){let p=s.current.get(n),v=r.find(b=>b.id===n);t(ue());let g={id:n,text:u};if(v&&(v.fontWeight!==void 0&&(g.fontWeight=v.fontWeight),v.fontStyle!==void 0&&(g.fontStyle=v.fontStyle),v.textDecoration!==void 0&&(g.textDecoration=v.textDecoration)),o?.current&&u.trim()){let b=o.current,y=b.offsetWidth,S=b.offsetHeight,I=1;if(p){let H=p.getStage();H&&(I=H.scaleX());}let C=14,L=(y-C)/I,P=(S-C)/I,A=u.split(`
|
|
2
|
+
export{default as Konva}from'konva';import*as be from'react';import be__default,{forwardRef,useRef,useEffect,useCallback,useImperativeHandle,memo,useState,createElement,useMemo,useId,useLayoutEffect}from'react';import {Group,Image as Image$1,Line,Rect,Arc,Arrow,Wedge,Ring,Ellipse,RegularPolygon,Star,Circle,Text,Stage,Layer,Transformer}from'react-konva';import {useSelector,useDispatch}from'react-redux';export{Provider as ReduxProvider}from'react-redux';import {createSlice,configureStore}from'@reduxjs/toolkit';import _l from'perfect-freehand';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {Html}from'react-konva-utils';import {CameraPlus,Camera,Stop,X,Microphone,MicrophoneSlash,Record,Download,Cursor,PenNib,Eraser,TextAa,Shapes,Cards,Image as Image$2,Square,Circle as Circle$1,Triangle,Hexagon,Star as Star$1,Pizza,ArrowRight,LineSegment,Circuitry,ListBullets,ToggleRight,Textbox,TextUnderline,MonitorPlay,ArrowCounterClockwise,ArrowClockwise,Trash,Export,SidebarSimple,Plus,ArrowUpIcon,Lock,LinkIcon,SpeakerHifiIcon,NotePencilIcon,Palette,ScissorsIcon,PencilSimple,CopySimple,Chat,Stack,Check,Play,SpeakerSimpleSlash,SpeakerHigh,ScribbleLoop,Exam,CheckCircle,XCircle,TextB,TextItalic,Warning,CloudArrowUp as CloudArrowUp$1,ArrowsDownUp,Shuffle}from'@phosphor-icons/react/dist/ssr';import {CaretLeft,CloudArrowUp,EyeIcon,Stack as Stack$1,X as X$1,DotsSixVertical,ArrowUp,ArrowDown,Question,FrameCorners,Cards as Cards$1,TextT,Shapes as Shapes$1,VideoCamera,Image as Image$3}from'@phosphor-icons/react';import {createPortal}from'react-dom';import _d from'use-image';import {motion,AnimatePresence,Reorder}from'framer-motion';import {useSyncExternalStoreWithSelector}from'use-sync-external-store/shim/with-selector.js';import {v4}from'uuid';import {QueryClient}from'@tanstack/react-query';var Ol=e=>{throw TypeError(e)};var Nl=(e,o,t)=>o.has(e)||Ol("Cannot "+t);var K=(e,o,t)=>(Nl(e,o,"read from private field"),t?t.call(e):o.get(e)),Te=(e,o,t)=>o.has(e)?Ol("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(e):o.set(e,t),ke=(e,o,t,a)=>(Nl(e,o,"write to private field"),o.set(e,t),t);var Vl=(e,o,t,a)=>({set _(r){ke(e,o,r);},get _(){return K(e,o,a)}});var xe=()=>useDispatch(),ee=e=>useSelector(e),yt=xe,aa=ee;var nn=20,ql=e=>({id:`slide-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:e||`Slide ${Date.now()}`,thumbnail:void 0,backgroundColor:"#ffffff",lines:[],shapes:[],images:[],videos:[],flashcards:[],photoFrames:[],texts:[],activityType:"",multipleChoices:[],trueFalses:[],shortAnswers:[],LongAnswer:[],fillInTheBlanks:[],showMcqForm:false,showFlashcardForm:false,editingActivity:null,editingFlashcard:null,createdAt:Date.now(),updatedAt:Date.now()}),sn=ql("Slide 1"),rm={slides:[sn],currentSlideId:sn.id,history:{[sn.id]:{past:[],future:[]}},isSketchMode:true,editingTextId:null},Ul=createSlice({name:"canvas",initialState:rm,reducers:{addSlide:e=>{if(e.slides.length>=nn)return;let o=ql(`Slide ${e.slides.length+1}`);e.slides.push(o),e.currentSlideId=o.id,e.history[o.id]={past:[],future:[]};},deleteSlide:(e,o)=>{if(e.slides.length<=1)return;let t=e.slides.findIndex(a=>a.id===o.payload);if(t!==-1&&(e.slides.splice(t,1),delete e.history[o.payload],e.currentSlideId===o.payload)){let a=Math.max(0,t-1);e.currentSlideId=e.slides[a].id;}},duplicateSlide:(e,o)=>{if(e.slides.length>=nn)return;let t=e.slides.findIndex(s=>s.id===o.payload);if(t===-1)return;let a=e.slides[t],r={...a,id:`slide-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:`${a.name} (Copy)`,createdAt:Date.now(),updatedAt:Date.now(),lines:JSON.parse(JSON.stringify(a.lines)),images:JSON.parse(JSON.stringify(a.images)),videos:JSON.parse(JSON.stringify(a.videos)),shapes:JSON.parse(JSON.stringify(a.shapes)),flashcards:JSON.parse(JSON.stringify(a.flashcards)),photoFrames:JSON.parse(JSON.stringify(a.photoFrames))};e.slides.splice(t+1,0,r),e.currentSlideId=r.id,e.history[r.id]={past:[],future:[]};},setCurrentSlide:(e,o)=>{e.slides.find(a=>a.id===o.payload)&&(e.currentSlideId=o.payload);},updateSlideThumbnail:(e,o)=>{let t=e.slides.find(a=>a.id===o.payload.id);t&&(t.thumbnail=o.payload.thumbnail,t.updatedAt=Date.now());},setBackgroundColor:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.backgroundColor=o.payload,t.updatedAt=Date.now());},reorderSlides:(e,o)=>{let{fromIndex:t,toIndex:a}=o.payload;if(t<0||t>=e.slides.length||a<0||a>=e.slides.length)return;let[r]=e.slides.splice(t,1);e.slides.splice(a,0,r);},loadSlides:(e,o)=>{e.slides=o.payload.slides.map(t=>({...t,showMcqForm:false})),e.currentSlideId=o.payload.currentSlideId,e.history={},o.payload.slides.forEach(t=>{e.history[t.id]={past:[],future:[]};});},addLine:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,id:o.payload.id||`line-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,timestamp:o.payload.timestamp||Date.now(),x:o.payload.x||0,y:o.payload.y||0};t.lines.push(a),t.updatedAt=Date.now();}},removeLine:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);t&&o.payload>=0&&o.payload<t.lines.length&&(t.lines.splice(o.payload,1),t.updatedAt=Date.now());},updateLastLine:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);t&&t.lines.length>0&&(t.lines[t.lines.length-1].points=o.payload,t.updatedAt=Date.now());},finalizeDrawing:e=>{let o=e.slides.find(t=>t.id===e.currentSlideId);o&&(o.updatedAt=Date.now());},setLines:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.lines=o.payload,t.updatedAt=Date.now());},updateLinePosition:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.lines.find(r=>r.id===o.payload.id);a&&(a.x=o.payload.x,a.y=o.payload.y,t.updatedAt=Date.now());}},updateLineTransform:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.lines.find(r=>r.id===o.payload.id);a&&(a.x=o.payload.x,a.y=o.payload.y,a.scaleX=o.payload.scaleX,a.scaleY=o.payload.scaleY,a.rotation=o.payload.rotation,t.updatedAt=Date.now());}},deleteLineById:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.lines.findIndex(r=>r.id===o.payload);a!==-1&&(t.lines.splice(a,1),t.updatedAt=Date.now());}},duplicateLine:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.lines.find(r=>r.id===o.payload);if(a){let r={...a,id:`line-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,x:(a.x||0)+20,y:(a.y||0)+20,timestamp:Date.now()};t.lines.push(r),t.updatedAt=Date.now();}}},updateElementOrder:(e,o)=>{let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r,newTimestamp:s}=o.payload;switch(r){case "image":let n=t.images.find(g=>g.id===a);n&&(n.timestamp=s);break;case "video":let i=t.videos.find(g=>g.id===a);i&&(i.timestamp=s);break;case "shape":let u=t.shapes.find(g=>g.id===a);u&&(u.timestamp=s);break;case "text":let l=t.texts.find(g=>g.id===a);l&&(l.timestamp=s);break;case "flashcard":let c=t.flashcards.find(g=>g.id===a);c&&(c.timestamp=s);break;case "photoFrame":let d=t.photoFrames.find(g=>g.id===a);d&&(d.timestamp=s);break;case "mcq":let m=t.multipleChoices.find(g=>g.id===a);m&&(m.timestamp=s);break;case "trueFalse":let f=t.trueFalses.find(g=>g.id===a);f&&(f.timestamp=s);break;case "shortAnswer":let h=t.shortAnswers.find(g=>g.id===a);h&&(h.timestamp=s);break;case "longAnswer":let x=t.LongAnswer.find(g=>g.id===a);x&&(x.timestamp=s);break;case "fillInTheBlanks":let p=t.fillInTheBlanks.find(g=>g.id===a);p&&(p.timestamp=s);break;case "line":let v=t.lines.find(g=>g.id===a);v&&(v.timestamp=s);break}t.updatedAt=Date.now();}},addImage(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.images.push(a),t.updatedAt=Date.now();}},updateImage(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.images[a]={...t.images[a],...o.payload},t.updatedAt=Date.now());}},deleteImage(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.images=t.images.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateImage(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload);if(a){let r={...a,id:`img-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.images.push(r),t.updatedAt=Date.now();}}},addVideo(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.videos.push(a),t.updatedAt=Date.now();}},updateVideo(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.videos.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.videos[a]={...t.videos[a],...o.payload},t.updatedAt=Date.now());}},toggleVideoPlaying(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.videos.find(r=>r.id===o.payload);a&&(a.isPlaying=!a.isPlaying,t.updatedAt=Date.now());}},deleteVideo(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.videos=t.videos.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateVideo(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.videos.find(r=>r.id===o.payload);if(a){let r={...a,id:`vid-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,isPlaying:false,timestamp:Date.now()};t.videos.push(r),t.updatedAt=Date.now();}}},addShape(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.shapes?.push(a),t.updatedAt=Date.now();}},updateShape(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.shapes.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.shapes[a]={...t.shapes[a],...o.payload},t.updatedAt=Date.now());}},duplicateShape(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.shapes.find(r=>r.id===o.payload);if(a){let r={...a,id:`shape-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.shapes.push(r),t.updatedAt=Date.now();}}},deleteShape(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.shapes=t.shapes.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},addMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.multipleChoices||(t.multipleChoices=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.multipleChoices.length>0){let r=t.multipleChoices[t.multipleChoices.length-1];a.x=r.x+20,a.y=r.y+20;}t.multipleChoices.push(a),t.updatedAt=Date.now();}},updateMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t&&t.multipleChoices){let a=t.multipleChoices.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.multipleChoices[a]={...t.multipleChoices[a],...o.payload},t.updatedAt=Date.now());}},editMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t&&t.multipleChoices){let a=t.multipleChoices.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.multipleChoices[a]={...t.multipleChoices[a],...o.payload},t.updatedAt=Date.now());}},duplicateMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.multipleChoices.find(r=>r.id===o.payload);if(a){let r={...a,id:`mcq-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.multipleChoices.push(r),t.updatedAt=Date.now();}}},deleteMultipleChoice(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.multipleChoices=t.multipleChoices.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},addTrueFalse(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.trueFalses||(t.trueFalses=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.trueFalses.length>0){let r=t.trueFalses[t.trueFalses.length-1];a.x=r.x+20,a.y=r.y+20;}t.trueFalses.push(a),t.updatedAt=Date.now();}},updateTrueFalse(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.trueFalses.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.trueFalses[a]={...t.trueFalses[a],...o.payload},t.updatedAt=Date.now());}},deleteTrueFalse(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.trueFalses=t.trueFalses.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateTrueFalse(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.trueFalses.find(r=>r.id===o.payload);if(a){let r={...a,id:`shape-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.trueFalses.push(r),t.updatedAt=Date.now();}}},addShortAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.shortAnswers||(t.shortAnswers=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.shortAnswers.length>0){let r=t.shortAnswers[t.shortAnswers.length-1];a.x=r.x+20,a.y=r.y+20;}t.shortAnswers.push(a),t.updatedAt=Date.now();}},updateShortAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.shortAnswers.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.shortAnswers[a]={...t.shortAnswers[a],...o.payload},t.updatedAt=Date.now());}},duplicateShortAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.shortAnswers.find(r=>r.id===o.payload);if(a){let r={...a,id:`shortAnswer-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.shortAnswers.push(r),t.updatedAt=Date.now();}}},deleteShortAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.shortAnswers=t.shortAnswers.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},addLongAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.LongAnswer||(t.LongAnswer=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.LongAnswer.length>0){let r=t.LongAnswer[t.LongAnswer.length-1];a.x=r.x+20,a.y=r.y+20;}t.LongAnswer.push(a),t.updatedAt=Date.now();}},updateLongAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.LongAnswer.find(r=>r.id===o.payload.id);a&&(Object.assign(a,o.payload),t.updatedAt=Date.now());}},deleteLongAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.LongAnswer=t.LongAnswer.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateLongAnswer(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.LongAnswer.find(r=>r.id===o.payload);if(a){let r={...a,id:`${a.id}-copy-${Date.now()}`,timestamp:Date.now()};t.LongAnswer.push(r),t.updatedAt=Date.now();}}},setShowMcqForm(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.showMcqForm=o.payload,t.updatedAt=Date.now());},setShowFlashcardForm(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.showFlashcardForm=o.payload,t.updatedAt=Date.now());},addFillInTheBlanks(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){t.fillInTheBlanks||(t.fillInTheBlanks=[]);let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.fillInTheBlanks.length>0){let r=t.fillInTheBlanks[t.fillInTheBlanks.length-1];a.x=r.x+20,a.y=r.y+20;}t.fillInTheBlanks.push(a),t.updatedAt=Date.now();}},updateFillInTheBlanks(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.fillInTheBlanks.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.fillInTheBlanks[a]={...t.fillInTheBlanks[a],...o.payload},t.updatedAt=Date.now());}},deleteFillInTheBlanks(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.fillInTheBlanks=t.fillInTheBlanks.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateFillInTheBlanks(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.fillInTheBlanks.find(r=>r.id===o.payload);if(a){let r={...a,id:`fillInTheBlank-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.fillInTheBlanks.push(r),t.updatedAt=Date.now();}}},setActivityType(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.activityType=o.payload,t.updatedAt=Date.now());},setEditingActivity(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.editingActivity=o.payload,t.updatedAt=Date.now());},bringToFront(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r}=o.payload;if(r==="image"){let s=t.images.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.images.splice(s,1);t.images.push(n);}}else if(r==="video"){let s=t.videos.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.videos.splice(s,1);t.videos.push(n);}}else if(r==="shape"){let s=t.shapes.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.shapes.splice(s,1);t.shapes.push(n);}}else if(r==="flashcard"){let s=t.flashcards.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.flashcards.splice(s,1);t.flashcards.push(n);}}else if(r==="photoFrame"){let s=t.photoFrames.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.photoFrames.splice(s,1);t.photoFrames.push(n);}}else if(r==="text"){let s=t.texts.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.texts.splice(s,1);t.texts.push(n);}}else if(r==="trueFalse"){let s=t.trueFalses.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.trueFalses.splice(s,1);t.trueFalses.push(n);}}else if(r==="shortAnswer"){let s=t.shortAnswers.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.shortAnswers.splice(s,1);t.shortAnswers.push(n);}}else if(r==="fillInTheBlanks"){let s=t.fillInTheBlanks.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.fillInTheBlanks.splice(s,1);t.fillInTheBlanks.push(n);}}t.updatedAt=Date.now();}},sendToBack(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r}=o.payload;if(r==="image"){let s=t.images.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.images.splice(s,1);t.images.unshift(n);}}else if(r==="video"){let s=t.videos.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.videos.splice(s,1);t.videos.unshift(n);}}else if(r==="shape"){let s=t.shapes.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.shapes.splice(s,1);t.shapes.unshift(n);}}else if(r==="flashcard"){let s=t.flashcards.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.flashcards.splice(s,1);t.flashcards.unshift(n);}}else if(r==="photoFrame"){let s=t.photoFrames.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.photoFrames.splice(s,1);t.photoFrames.unshift(n);}}else if(r==="text"){let s=t.texts.findIndex(n=>n.id===a);if(s!==-1){let[n]=t.texts.splice(s,1);t.texts.unshift(n);}}t.updatedAt=Date.now();}},toggleLock(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r}=o.payload,n=(r==="image"?t.images:r==="video"?t.videos:r==="shape"?t.shapes:r==="flashcard"?t.flashcards:r==="photoFrame"?t.photoFrames:r==="trueFalse"?t.trueFalses:r==="shortAnswer"?t.shortAnswers:r==="fillInTheBlanks"?t.fillInTheBlanks:t.texts).find(i=>i.id===a);n&&(n.locked=!n.locked,"draggable"in n&&(n.draggable=!n.locked),t.updatedAt=Date.now());}},setLink(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r,link:s}=o.payload,i=(r==="image"?t.images:r==="video"?t.videos:r==="shape"?t.shapes:r==="flashcard"?t.flashcards:r==="photoFrame"?t.photoFrames:r==="mcq"?t.multipleChoices:r==="trueFalse"?t.trueFalses:r==="shortAnswer"?t.shortAnswers:r==="fillInTheBlanks"?t.fillInTheBlanks:t.texts).find(u=>u.id===a);i&&(i.link=s,t.updatedAt=Date.now());}},setAltText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r,altText:s}=o.payload,i=(r==="image"?t.images:r==="video"?t.videos:r==="shape"?t.shapes:r==="flashcard"?t.flashcards:r==="photoFrame"?t.photoFrames:r==="trueFalse"?t.trueFalses:r==="shortAnswer"?t.shortAnswers:r==="fillInTheBlanks"?t.fillInTheBlanks:t.texts).find(u=>u.id===a);i&&(i.altText=s,t.updatedAt=Date.now());}},setAudioData(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let{id:a,type:r,audioData:s}=o.payload,i=(r==="image"?t.images:r==="video"?t.videos:r==="shape"?t.shapes:r==="flashcard"?t.flashcards:r==="photoFrame"?t.photoFrames:r==="trueFalse"?t.trueFalses:r==="shortAnswer"?t.shortAnswers:r==="fillInTheBlanks"?t.fillInTheBlanks:t.texts).find(u=>u.id===a);i&&(i.audioData=s,t.updatedAt=Date.now());}},clearCanvas:e=>{let o=e.slides.find(t=>t.id===e.currentSlideId);o&&(o.lines=[],o.images=[],o.videos=[],o.shapes=[],o.flashcards=[],o.photoFrames=[],o.texts=[],o.multipleChoices=[],o.trueFalses=[],o.shortAnswers=[],o.LongAnswer=[],o.fillInTheBlanks=[],o.updatedAt=Date.now());},addText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.texts.push(a),t.updatedAt=Date.now();}},updateText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.texts.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.texts[a]={...t.texts[a],...o.payload},t.updatedAt=Date.now());}},deleteText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.texts=t.texts.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateText(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.texts.find(r=>r.id===o.payload);if(a){let r={...a,id:`text-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,timestamp:Date.now()};t.texts.push(r),t.updatedAt=Date.now();}}},addFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};if(t.flashcards.length>=40){alert("You can add maximum 40 flashcards");return}t.flashcards.push(a),t.updatedAt=Date.now();}},updateFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.flashcards.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.flashcards[a]={...t.flashcards[a],...o.payload},t.updatedAt=Date.now());}},deleteFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.flashcards=t.flashcards.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicateFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.flashcards.find(r=>r.id===o.payload);if(a){let r={...a,id:`flashcard-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,currentIndex:0,timestamp:Date.now()};t.flashcards.push(r),t.updatedAt=Date.now();}}},editFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.editingFlashcard=o.payload);},nextFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.flashcards.find(r=>r.id===o.payload);if(a&&a.images.length>0){if(a.order==="sequential")a.currentIndex=(a.currentIndex+1)%a.images.length;else {a.navigationHistory||(a.navigationHistory=[a.currentIndex]);let r=a.images.map((s,n)=>n).filter(s=>s!==a.currentIndex);if(r.length>0){let s=r[Math.floor(Math.random()*r.length)];a.navigationHistory.push(s),a.currentIndex=s;}}t.updatedAt=Date.now();}}},previousFlashcard(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.flashcards.find(r=>r.id===o.payload);a&&a.images.length>0&&(a.order==="sequential"?a.currentIndex=(a.currentIndex-1+a.images.length)%a.images.length:a.navigationHistory&&a.navigationHistory.length>1&&(a.navigationHistory.pop(),a.currentIndex=a.navigationHistory[a.navigationHistory.length-1]),t.updatedAt=Date.now());}},addPhotoFrame(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a={...o.payload,timestamp:o.payload.timestamp||Date.now()};t.photoFrames.push(a),t.updatedAt=Date.now();}},updatePhotoFrame(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.findIndex(r=>r.id===o.payload.id);a!==-1&&(t.photoFrames[a]={...t.photoFrames[a],...o.payload},t.updatedAt=Date.now());}},deletePhotoFrame(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);t&&(t.photoFrames=t.photoFrames.filter(a=>a.id!==o.payload),t.updatedAt=Date.now());},duplicatePhotoFrame(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload);if(a){let r={...a,id:`photoframe-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,x:a.x+20,y:a.y+20,isCapturing:false,timestamp:Date.now()};t.photoFrames.push(r),t.updatedAt=Date.now();}}},toggleImageDrawingMode(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload);a&&(a.isDrawingMode=!a.isDrawingMode,a.annotations||(a.annotations=[]),t.updatedAt=Date.now());}},addImageAnnotation(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload.imageId);a&&(a.annotations||(a.annotations=[]),a.annotations.push(o.payload.line),t.updatedAt=Date.now());}},updateImageAnnotation(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload.imageId);a&&a.annotations&&a.annotations.length>0&&(a.annotations[a.annotations.length-1].points=o.payload.points,t.updatedAt=Date.now());}},clearImageAnnotations(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.images.find(r=>r.id===o.payload);a&&(a.annotations=[],t.updatedAt=Date.now());}},togglePhotoFrameDrawingMode(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload);a&&(a.isDrawingMode=!a.isDrawingMode,a.annotations||(a.annotations=[]),t.updatedAt=Date.now());}},addPhotoFrameAnnotation(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload.frameId);a&&(a.annotations||(a.annotations=[]),a.annotations.push(o.payload.line),t.updatedAt=Date.now());}},updatePhotoFrameAnnotation(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload.frameId);a&&a.annotations&&a.annotations.length>0&&(a.annotations[a.annotations.length-1].points=o.payload.points,t.updatedAt=Date.now());}},clearPhotoFrameAnnotations(e,o){let t=e.slides.find(a=>a.id===e.currentSlideId);if(t){let a=t.photoFrames.find(r=>r.id===o.payload);a&&(a.annotations=[],t.updatedAt=Date.now());}},undo:e=>{let o=e.history[e.currentSlideId];if(o&&o.past.length>0){let t=e.slides.findIndex(a=>a.id===e.currentSlideId);if(t>=0)try{let a=e.slides[t];o.future.unshift(JSON.parse(JSON.stringify(a)));let r=o.past.pop();e.slides[t]=r;}catch(a){console.warn("Failed to undo - data too large:",a),o.past=[],o.future=[];}}},redo:e=>{let o=e.history[e.currentSlideId];if(o&&o.future.length>0){let t=e.slides.findIndex(a=>a.id===e.currentSlideId);if(t>=0)try{let a=e.slides[t];o.past.push(JSON.parse(JSON.stringify(a)));let r=o.future.shift();e.slides[t]=r;}catch(a){console.warn("Failed to redo - data too large:",a),o.past=[],o.future=[];}}},saveToHistory:e=>{let o=e.slides.findIndex(t=>t.id===e.currentSlideId);if(o>=0){let t=e.slides[o],a=e.history[e.currentSlideId];if(a)try{let r=JSON.parse(JSON.stringify(t));a.past.push(r),a.future=[],a.past.length>20&&a.past.shift();}catch(r){console.warn("Failed to save to history - data too large:",r),a.past.length>5&&(a.past=a.past.slice(-5)),a.future=[];}}},toggleSketchMode:e=>{e.isSketchMode=!e.isSketchMode;},setSketchMode:(e,o)=>{e.isSketchMode=o.payload;},setEditingTextId:(e,o)=>{e.editingTextId=o.payload;}}}),{addSlide:ln,deleteSlide:dn,duplicateSlide:un,setCurrentSlide:cn,updateSlideThumbnail:fn,setBackgroundColor:mn,reorderSlides:sm,loadSlides:Xa,addLine:pn,removeLine:Ur,addImage:hn,updateImage:Ya,deleteImage:gn,duplicateImage:Hr,addVideo:zr,updateVideo:Wr,deleteVideo:xn,duplicateVideo:Gr,toggleVideoPlaying:Eo,addShape:bn,updateShape:Ja,duplicateShape:Kr,deleteShape:vn,addText:yn,updateText:wt,deleteText:wn,duplicateText:_r,addFlashcard:Ln,updateFlashcard:Za,deleteFlashcard:Sn,duplicateFlashcard:jr,editFlashcard:Bo,nextFlashcard:In,previousFlashcard:Cn,addPhotoFrame:kn,updatePhotoFrame:Aa,deletePhotoFrame:Mn,duplicatePhotoFrame:$r,toggleImageDrawingMode:Tn,addImageAnnotation:An,updateImageAnnotation:nm,clearImageAnnotations:im,togglePhotoFrameDrawingMode:Pn,addPhotoFrameAnnotation:Dn,updatePhotoFrameAnnotation:lm,clearPhotoFrameAnnotations:dm,addMultipleChoice:Rn,updateMultipleChoice:oa,editMultipleChoice:um,deleteMultipleChoice:Fn,duplicateMultipleChoice:Xr,addTrueFalse:En,updateTrueFalse:ra,deleteTrueFalse:Bn,duplicateTrueFalse:Yr,addShortAnswer:On,updateShortAnswer:Oo,deleteShortAnswer:Nn,duplicateShortAnswer:Jr,addLongAnswer:Vn,updateLongAnswer:No,deleteLongAnswer:qn,duplicateLongAnswer:Zr,addFillInTheBlanks:Un,updateFillInTheBlanks:Vo,deleteFillInTheBlanks:Hn,duplicateFillInTheBlanks:Qr,setShowMcqForm:sa,setShowFlashcardForm:Pa,setActivityType:zn,setEditingActivity:qo,bringToFront:Wn,sendToBack:Gn,toggleLock:Kn,setLink:es,setAltText:ts,setAudioData:as,updateLastLine:cm,finalizeDrawing:_n,setLines:fm,updateLinePosition:mm,updateLineTransform:os,deleteLineById:jn,duplicateLine:$n,updateElementOrder:Uo,clearCanvas:Xn,undo:Yn,redo:Jn,saveToHistory:ue,toggleSketchMode:pm,setSketchMode:dt,setEditingTextId:Ho}=Ul.actions,zo=e=>e.canvas.currentSlideId,ge=e=>{let o=e.canvas.currentSlideId,t=e.canvas.slides.findIndex(a=>a.id===o);return t>=0?e.canvas.slides[t]:void 0},Wo=e=>e.canvas.slides,Zn=e=>e.canvas.slides.length<nn,hm=e=>o=>{let t=o.canvas.slides.findIndex(a=>a.id===e);return t>=0?o.canvas.slides[t]:void 0},Hl=Ul.reducer;var Wl=e=>{let o=xe(),t=useRef(null),a=useRef(false),r=ee(f=>f.toolbar.selectedTool),s=ee(f=>f.toolbar.penColor),n=ee(f=>f.toolbar.strokeWidth),i=ee(f=>f.canvas.isSketchMode),u=ee(f=>f.canvas.slides.find(x=>x.id===f.canvas.currentSlideId)?.lines||[]),l=useCallback(f=>{t.current=f;},[]),c=useCallback(f=>{r==="pen"&&t.current&&(o(ue()),t.current.startDrawing(f),a.current=true);},[r,o]),d=useCallback(f=>{!t.current||!a.current||t.current.draw(f);},[]),m=useCallback(()=>{if(!t.current||!a.current)return;let f=t.current.stopDrawing();a.current=false,f&&f.points.length>=4&&o(pn(f)),o(_n()),e?.();},[o,e]);return {lines:u,tool:r,color:s,strokeWidth:n,isSketchMode:i,setCanvasRef:l,startDrawing:c,draw:d,stopDrawing:m}};var jl=forwardRef(({width:e,height:o,tool:t,color:a,strokeWidth:r,isSketchMode:s,style:n},i)=>{let u=useRef(null),l=useRef(false),c=useRef([]),d=useRef(null),m=useRef(t),f=useRef(a),h=useRef(r),x=useRef(s);useEffect(()=>{m.current=t,f.current=a,h.current=r,x.current=s;},[t,a,r,s]);let p=useCallback(()=>{let g=u.current;if(!g)return;let b=g.getContext("2d");b&&b.clearRect(0,0,g.width,g.height);},[]),v=useCallback(()=>{let g=u.current,b=c.current;if(!g||b.length<1)return;let y=g.getContext("2d");if(!y)return;if(y.clearRect(0,0,g.width,g.height),m.current==="eraser"?(y.globalCompositeOperation="destination-out",y.fillStyle="rgba(0,0,0,1)"):(y.globalCompositeOperation="source-over",y.fillStyle=f.current),b.length===1){y.beginPath(),y.arc(b[0].x,b[0].y,h.current/2,0,Math.PI*2),y.fill();return}let I=_l(b,{size:h.current,thinning:.5,smoothing:.5,streamline:.5,simulatePressure:true,easing:C=>C,start:{taper:0,cap:true},end:{taper:0,cap:true}});if(!(I.length<2)){y.beginPath(),y.moveTo(I[0][0],I[0][1]);for(let C=1;C<I.length;C++)y.lineTo(I[C][0],I[C][1]);y.closePath(),y.fill();}},[]);return useImperativeHandle(i,()=>({startDrawing:g=>{l.current=true,c.current=[{x:g.x,y:g.y}],d.current=g,v();},draw:g=>{if(!l.current||!d.current)return;let b=g.x-d.current.x,y=g.y-d.current.y;Math.sqrt(b*b+y*y)<2||(c.current.push({x:g.x,y:g.y}),d.current=g,v());},stopDrawing:()=>{if(!l.current)return null;if(l.current=false,c.current.length<2)return c.current=[],d.current=null,p(),null;let b=_l(c.current,{size:h.current,thinning:.5,smoothing:.5,streamline:.5,simulatePressure:true,easing:S=>S,start:{taper:0,cap:true},end:{taper:0,cap:true}}).flatMap(S=>[S[0],S[1]]),y={tool:m.current,points:b,color:f.current,strokeWidth:h.current,isSketch:true};return c.current=[],d.current=null,p(),y},clear:()=>{p(),c.current=[],d.current=null,l.current=false;},isDrawing:()=>l.current,getCanvasElement:()=>u.current}),[p,v]),useEffect(()=>{let g=u.current;g&&(g.width=e,g.height=o);},[e,o]),jsx("canvas",{ref:u,width:e,height:o,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:1e3,...n}})});jl.displayName="DirectDrawingCanvas";var $l=jl;var Yl=e=>{let o=xe(),a=ee(ge)?.images||[],r=useRef(new Map),s=useRef(new Map),n=useRef(new Set);useEffect(()=>{let c=new Set(a.map(d=>d.id));n.current.forEach(d=>{if(!c.has(d)){let m=s.current.get(d);m&&(m.src="",s.current.delete(d)),r.current.delete(d);}}),n.current=c;},[a]),useEffect(()=>()=>{s.current.forEach(c=>{c.src="";}),s.current.clear(),r.current.clear();},[]);let i=useCallback(c=>{if(s.current.has(c.id))return s.current.get(c.id);let d=new window.Image;return (c.src.startsWith("http://")||c.src.startsWith("https://"))&&(d.crossOrigin="anonymous"),d.src=c.src,s.current.set(c.id,d),d},[]),u=useCallback((c,d)=>{let m=c.target,f=m.id();a.find(x=>x.id===f)&&(o(Ya({id:f,x:m.x(),y:m.y(),width:m.width(),height:m.height(),rotation:m.rotation()})),d?.());},[a,o]),l=useCallback((c,d)=>{let m=d.target,f=r.current.get(c);if(!f){console.error("\u274C Image node not found for id:",c);return}let h=m.scaleX(),x=m.scaleY(),p=m.rotation(),v=f.width(),g=f.height(),b=Math.max(5,v*h),y=Math.max(5,g*x);m.scaleX(1),m.scaleY(1),f.width(b),f.height(y),o(Ya({id:c,width:b,height:y,x:m.x(),y:m.y(),rotation:p})),m.getLayer()?.batchDraw(),e?.();},[o,e]);return {images:a,getLoadedImage:i,imageRefs:r,handleDragEnd:u,handleImageTransformEnd:l}};var Jl=e=>{let o=useDispatch(),t=useSelector(ge),a=useRef(new Map),r=useMemo(()=>t?.multipleChoices||[],[t?.multipleChoices]),s=useCallback((i,u)=>{let l=u.target,c=l.scaleX(),d=l.scaleY(),m=l.rotation(),f=Math.max(5,l.width()*c),h=Math.max(5,l.height()*d);l.scaleX(1),l.scaleY(1),l.width(f),l.height(h),o(oa({id:i,width:f,height:h,x:l.x(),y:l.y(),rotation:m})),l.getLayer()?.batchDraw(),e?.();},[o,e]);return {multipleChoice:r,handleMcqTransform:s,mcqRefs:a,handleDragEnd:(i,u)=>{o(oa({id:u,x:i.target.x(),y:i.target.y()})),e?.();}}};var Zl=e=>{let o=useDispatch(),t=useSelector(ge),a=useRef(new Map),r=useMemo(()=>t?.trueFalses||[],[t?.trueFalses]),s=useCallback((i,u)=>{let l=u.target,c=l.scaleX(),d=l.scaleY(),m=l.rotation(),f=Math.max(5,l.width()*c),h=Math.max(5,l.height()*d);l.scaleX(1),l.scaleY(1),l.width(f),l.height(h),o(ra({id:i,width:f,height:h,x:l.x(),y:l.y(),rotation:m})),l.getLayer()?.batchDraw(),e?.();},[o,e]);return {trueFalse:r,handleTrueFalseTransform:s,handleTrueFalseDragEnd:(i,u)=>{o(ra({id:u,x:i.target.x(),y:i.target.y()})),e?.();},trueFalseRefs:a}};var Ql=e=>{let o=xe(),a=ee(ge)?.videos||[],r=useRef(new Map),s=useCallback(u=>{o(Eo(u));},[o]),n=useCallback((u,l)=>{let c=l.target;o(Wr({id:u,x:c.x(),y:c.y()})),e?.();},[o,e]),i=useCallback((u,l)=>{let c=l.target,d=c.scaleX(),m=c.scaleY(),f=c.rotation(),h=Math.max(5,c.width()*d),x=Math.max(5,c.height()*m);c.scaleX(1),c.scaleY(1),c.width(h),c.height(x),o(Wr({id:u,width:h,height:x,x:c.x(),y:c.y(),rotation:f})),c.getLayer()?.batchDraw(),e?.();},[o,e]);return {videos:a,videoRefs:r,handleVideoClick:s,handleVideoDragEnd:n,handleVideoTransformEnd:i}};var ad=e=>{let o=xe(),a=ee(ge)?.shapes||[],r=useRef(new Map),s=useRef(new Map),[n,i]=useState(false),u=useCallback((c,d)=>{let m=d.target;o(Ja({id:c,x:m.x(),y:m.y()})),e?.();},[o,e]),l=useCallback((c,d)=>{let m=d.target,f=a.find(b=>b.id===c);if(!f)return;let h=m.scaleX(),x=m.scaleY(),p=f.type?.toLowerCase();p==="arrow"||p==="line"||(m.scaleX(1),m.scaleY(1));let g={id:c,x:m.x(),y:m.y(),width:Math.max(5,m.width()*h),height:Math.max(5,m.height()*x),rotation:m.rotation()};switch(p){case "circle":g.radius=m.width()*h/2;break;case "star":g.innerRadius=m.width()*h/4,g.outerRadius=m.width()*h/2;break;case "triangle":g.radius=m.width()*h/2;break;case "ellipse":g.radiusX=m.width()*h/2,g.radiusY=m.height()*x/2;break;case "polygon":g.radius=m.width()*h/2;break;case "ring":let b=h;g.innerRadius=f.innerRadius&&f.innerRadius*b,g.outerRadius=f.outerRadius&&f.outerRadius*b;break;case "wedge":g.radius=f.radius&&f.radius*h;break;case "arc":g.innerRadius=f.innerRadius&&f.innerRadius*h,g.outerRadius=f.outerRadius&&f.outerRadius*h;break;case "arrow":case "line":{g.scaleX=h,g.scaleY=x,delete g.width,delete g.height;break}}o(Ja(g)),e?.();},[o,e,a]);return {shapes:a,shapeRefs:r,isDragging:n,loadedShapesRef:s,handleShapeDragEnd:u,handleShapeResizeEnd:l}};var rd=(e,o)=>{let t=yt(),r=ee(ge)?.texts||[],s=useRef(new Map),[n,i]=useState(null),[u,l]=useState("");return {texts:r,textRefs:s,handleDragEnd:(p,v)=>{let g=p.target;t(ue()),t(wt({id:v,x:g.x(),y:g.y()})),e();},handleTransformEnd:p=>{let v=s.current.get(p);if(!v)return;let g=v.scaleX(),b=v.scaleY(),y=r.find(I=>I.id===p);if(!y)return;let S=(g+b)/2;v.scaleX(1),v.scaleY(1),t(ue()),t(wt({id:p,x:v.x(),y:v.y(),width:Math.max(5,(y.width||100)*g),height:Math.max(5,(y.height||50)*b),fontSize:Math.round(Math.max(8,y.fontSize*S)),rotation:v.rotation()})),e();},handleDoubleClick:p=>{let v=r.find(g=>g.id===p);v&&!v.locked&&(i(p),l(v.text));},startEditing:p=>{let v=r.find(g=>g.id===p);v&&!v.locked&&(i(p),l(v.text));},editingTextId:n,editingValue:u,handleEditingChange:p=>{l(p);},finishEditing:()=>{if(n){let p=s.current.get(n),v=r.find(b=>b.id===n);t(ue());let g={id:n,text:u};if(v&&(v.fontWeight!==void 0&&(g.fontWeight=v.fontWeight),v.fontStyle!==void 0&&(g.fontStyle=v.fontStyle),v.textDecoration!==void 0&&(g.textDecoration=v.textDecoration)),o?.current&&u.trim()){let b=o.current,y=b.offsetWidth,S=b.offsetHeight,I=1;if(p){let H=p.getStage();H&&(I=H.scaleX());}let C=14,L=(y-C)/I,P=(S-C)/I,A=u.split(`
|
|
3
3
|
`).length,F=r.find(H=>H.id===n)?.fontSize||24,R=A*F*1.2+10;g.width=Math.max(200,L),g.height=Math.max(50,P,R);}else if(p&&u.trim()){let b=p.text(),y=p.width();p.text(u),p.width(void 0);let S=p.width(),I=p.height();p.text(b),p.width(y),g.width=Math.max(200,S+20),g.height=Math.max(50,I+20);}t(wt(g)),i(null),l(""),t(Ho(null)),e();}}}};var sd=e=>{let o=useDispatch(),a=useSelector(ge)?.shortAnswers||[],r=useRef(new Map),s=useCallback((n,i)=>{let u=n.target;o(Oo({id:i,x:u.x(),y:u.y()})),e?.();},[o,e]);return {shortAnswers:a,saRefs:r,handleShortAnswerDragEnd:s}};var nd=e=>{let o=useDispatch(),t=useSelector(ge),a=useMemo(()=>t?.LongAnswer||[],[t?.LongAnswer]),r=useCallback((s,n)=>{let i=s.target;o(No({id:n,x:i.x(),y:i.y()})),e?.();},[o,e]);return {longAnswers:a,handleLongAnswerDragEnd:r}};var ld=e=>{let o=xe(),a=ee(ge)?.flashcards||[],r=useRef(new Map),s=useRef(new Map),n=useCallback((d,m)=>{if(s.current.has(m))return s.current.get(m);let f=new window.Image;return f.src=d,s.current.set(m,f),f},[]),i=useCallback((d,m)=>{let f=d.target,h=f.id();a.find(p=>p.id===h)&&(o(Za({id:h,x:f.x(),y:f.y()})),m?.());},[a,o]),u=useCallback((d,m)=>{let f=m.target,h=f.scaleX(),x=f.scaleY(),p=f.rotation(),v=Math.max(50,f.width()*h),g=Math.max(50,f.height()*x);f.scaleX(1),f.scaleY(1),f.width(v),f.height(g),o(Za({id:d,width:v,height:g,x:f.x(),y:f.y(),rotation:p})),f.getLayer()?.batchDraw(),e?.();},[o,e]),l=useCallback(d=>{o(In(d)),e?.();},[o,e]),c=useCallback(d=>{o(Cn(d)),e?.();},[o,e]);return {flashcards:a,getLoadedImage:n,flashcardRefs:r,handleDragEnd:i,handleFlashcardTransformEnd:u,handleNext:l,handlePrevious:c}};var cd=e=>{let o=xe(),a=ee(ge)?.photoFrames||[],r=useRef(new Map),[s,n]=useState(new Map),i=useCallback((f,h)=>{console.log("handleDragEnd"),o(Aa({id:h,x:f.target.x(),y:f.target.y()})),e?.();},[o,e]),u=useCallback((f,h)=>{let x=h.target,p=x.scaleX(),v=x.scaleY(),g=x.rotation(),b=a.find(I=>I.id===f);if(!b)return;let y=Math.max(100,b.width*p),S=Math.max(100,b.height*v);x.scaleX(1),x.scaleY(1),o(Aa({id:f,width:y,height:S,x:x.x(),y:x.y(),rotation:g})),x.getLayer()?.batchDraw(),e?.();},[o,e,a]),l=useCallback(async f=>{try{let h=await navigator.mediaDevices.getUserMedia({video:{width:640,height:480},audio:!1});return n(x=>{let p=new Map(x);return p.set(f,h),p}),o(Aa({id:f,isCapturing:!0})),e?.(),h}catch(h){return console.error("Error accessing camera:",h),null}},[o,e]),c=useCallback(f=>{let h=s.get(f);h&&(h.getTracks().forEach(x=>x.stop()),n(x=>{let p=new Map(x);return p.delete(f),p}),o(Aa({id:f,isCapturing:false})),e?.());},[s,o,e]),d=useCallback((f,h)=>{let x=document.createElement("canvas");x.width=h.videoWidth,x.height=h.videoHeight;let p=x.getContext("2d");if(p){p.drawImage(h,0,0,x.width,x.height);let v=x.toDataURL("image/jpeg",.8);return o(Aa({id:f,capturedImageUrl:v,isCapturing:false})),c(f),e?.(),v}return null},[o,c,e]),m=useRef(s);return useEffect(()=>{m.current=s;},[s]),useEffect(()=>()=>{m.current.forEach(f=>{f.getTracks().forEach(h=>h.stop());});},[]),{photoFrames:a,photoFrameRefs:r,handleDragEnd:i,handlePhotoFrameTransformEnd:u,startCamera:l,stopCamera:c,capturePhoto:d,cameraStreams:s}};var fd=()=>{let e=useRef(null),o=useMemo(()=>({minWidth:340,minHeight:400,maxWidth:520,maxHeight:600}),[]),t=useCallback((s,n)=>e.current?.nodes()[0]?.name()==="mcq-element"?{...n,width:Math.max(o.minWidth,Math.min(n.width,o.maxWidth)),height:Math.max(o.minHeight,Math.min(n.height,o.maxHeight))}:n,[o]),a=useCallback((s,n,i,u,l,c,d=[])=>{if(e.current){if(s&&!d.find(h=>h.id===s)?.isPlaying){let h=n.get(s)||i.get(s)||u.get(s)||l.get(s)||c.get(s);if(h){e.current.boundBoxFunc(t),e.current.nodes([h]),e.current.getLayer()?.batchDraw();return}}e.current.nodes([]),e.current.getLayer()?.batchDraw();}},[]),r=useCallback(()=>{e.current&&(e.current.nodes([]),e.current.getLayer()?.batchDraw());},[]);return {transformerRef:e,attachTransformer:a,deselectTransformer:r,boundBoxFunc:t}};var Wm=(e,o)=>{let t=useRef(void 0);return useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]),useCallback((...a)=>{t.current&&clearTimeout(t.current),t.current=setTimeout(()=>{e(...a);},o);},[o])},gd=(e,o)=>{let t=yt(),a=useRef(e);useEffect(()=>{a.current=e;},[e]);let r=useCallback(()=>{if(o.current)try{let n=o.current.toDataURL({pixelRatio:1,mimeType:"image/jpeg",quality:.6});n&&n.startsWith("data:")&&t(fn({id:a.current,thumbnail:n}));}catch(n){console.warn("Could not generate thumbnail (likely CORS issue with images):",n);}},[o,t]),s=Wm(r,500);return {generateThumbnail:r,debouncedGenerateThumbnail:s}};var Km=e=>e.flatMap(o=>[o[0],o[1]]),ss=(e,o)=>{let t=_l(e,{size:o?.size||8,thinning:o?.thinning||.5,smoothing:o?.smoothing||.5,streamline:o?.streamline||.5,simulatePressure:o?.simulatePressure!==false,easing:a=>a,start:{taper:0,cap:true},end:{taper:0,cap:true}});return Km(t)};var xd=e=>{let o=xe(),t=useRef(false),a=useRef(false),r=useRef([]),[s,n]=useState(null),i=ee(b=>b.toolbar.selectedTool),u=ee(b=>b.toolbar.penColor),l=ee(b=>b.toolbar.strokeWidth),c=ee(b=>b.canvas.isSketchMode),d=ee(b=>b.canvas.slides.find(S=>S.id===b.canvas.currentSlideId)?.images.find(S=>S.id===e)),m=d?.annotations||[],f=d?.isDrawingMode||false,h=d?.width||1,x=d?.height||1,p=useCallback(b=>{if(i!=="pen"&&i!=="eraser")return;t.current=true,a.current=false,r.current=[{x:b.x,y:b.y}];let y=b.x/h,S=b.y/x;n({tool:i,points:[y,S],color:u,strokeWidth:l/h,isSketch:c});},[i,u,l,c,h,x]),v=useCallback(b=>{if(!t.current||!s)return;a.current=true;let y=r.current[r.current.length-1];if(Math.sqrt(Math.pow(b.x-y.x,2)+Math.pow(b.y-y.y,2))<2)return;r.current.push({x:b.x,y:b.y});let I;if(c)I=ss(r.current,{size:l*2,thinning:.6,smoothing:.5,streamline:.5,simulatePressure:true}).map((L,P)=>P%2===0?L/h:L/x);else {let C=b.x/h,L=b.y/x;I=[...s.points,C,L];}n(C=>C?{...C,points:I}:null);},[c,l,s,h,x]),g=useCallback(()=>{t.current&&(s&&s.points.length>0&&o(An({imageId:e,line:s})),n(null),t.current=false,a.current=false,r.current=[]);},[o,e,s]);return {annotations:m,activeLine:s,isDrawingMode:f,startDrawing:p,draw:v,stopDrawing:g,tool:i}};var wd=memo(({img:e,loadedImage:o,imageRefs:t,onDragEnd:a,onTransform:r,onSelect:s,onContextMenu:n})=>{let{annotations:i,activeLine:u,stopDrawing:m,tool:f}=xd(e.id);useEffect(()=>{let g=t.current.get(e.id);g&&(g.width()!==e.width||g.height()!==e.height)&&(console.log("\u{1F504} Syncing dimensions from Redux to Konva:",{id:e.id,reduxWidth:e.width,reduxHeight:e.height,konvaWidth:g.width(),konvaHeight:g.height()}),g.width(e.width),g.height(e.height),g.getLayer()?.batchDraw());},[e.id,e.width,e.height,t]);let h=false;useEffect(()=>{return;},[m,h]);let x=g=>{{s(e.id);return}},p=g=>{return;},v=g=>{};return jsxs(Group,{listening:f!=="pen"&&f!=="eraser",children:[jsx(Image$1,{id:e.id,ref:g=>{if(g){t.current.set(e.id,g),g.width(e.width),g.height(e.height),g.getLayer()?.batchDraw();let b=g.getStage()?.container();if(b){let y=S=>{let I=g.getStage()?.getPointerPosition();if(I){let C={x:e.x,y:e.y,width:e.width,height:e.height};I.x>=C.x&&I.x<=C.x+C.width&&I.y>=C.y&&I.y<=C.y+C.height&&n(S,e.id,"image");}};b.addEventListener("contextmenu",y),g._contextMenuCleanup=()=>{b.removeEventListener("contextmenu",y);};}}else {let b=t.current.get(e.id);b?._contextMenuCleanup&&b._contextMenuCleanup(),t.current.delete(e.id);}},rotation:e.rotation,draggable:f!=="pen"&&f!=="eraser",onDragEnd:a,onTransformEnd:g=>r(e.id,g),image:o,x:e.x,y:e.y,width:e.width,height:e.height,...f!=="pen"&&f!=="eraser"?{onClick:x,onTap:x,onMouseDown:x,onTouchStart:x,onMouseMove:p,onTouchMove:p,onMouseUp:v,onTouchEnd:v}:{}}),i?.map((g,b)=>{let y=g.points.map((I,C)=>C%2===0?I*e.width+e.x:I*e.height+e.y),S=g.strokeWidth*e.width;return jsx(Line,{points:y,stroke:g.tool==="eraser"?"white":g.color,strokeWidth:S,tension:.5,lineCap:"round",lineJoin:"round",globalCompositeOperation:g.tool==="eraser"?"destination-out":"source-over",fill:g.isSketch?g.color:void 0,closed:g.isSketch,listening:false},b)}),u&&jsx(Line,{points:u.points.map((g,b)=>b%2===0?g*e.width+e.x:g*e.height+e.y),stroke:u.tool==="eraser"?"white":u.color,strokeWidth:u.strokeWidth*e.width,tension:.5,lineCap:"round",lineJoin:"round",globalCompositeOperation:u.tool==="eraser"?"destination-out":"source-over",fill:u.isSketch?u.color:void 0,closed:u.isSketch,listening:false},"active")]})});wd.displayName="ImageWithDrawing";var si=memo(({images:e,getLoadedImage:o,imageRefs:t,onDragEnd:a,onTransform:r,onSelect:s,onContextMenu:n})=>jsx(Fragment,{children:e.map(i=>{let u=o(i);return u?jsx(wd,{img:i,loadedImage:u,imageRefs:t,onDragEnd:a,onTransform:r,onSelect:s,onContextMenu:n},i.id):null})}));si.displayName="ImageLayer";var tp=({src:e,x:o,id:t,y:a,width:r,height:s,isSelected:n,rotation:i=0,onTransformEnd:u,onDragEnd:l})=>{let c=xe(),d=useRef(null),m=f=>{c(Eo(f));};return jsxs(Group,{draggable:true,x:o,y:a,width:r,height:s,rotation:i,onDragEnd:l,onTransformEnd:u,children:[jsx(Rect,{width:r,height:s,fill:"black",stroke:n?"#4A90E2":"transparent",strokeWidth:2}),jsx(Html,{divProps:{style:{width:`${r}px`,height:`${s}px`,overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"center"}},children:jsx("video",{ref:d,src:e,controls:true,autoPlay:true,onClick:()=>m(t),onSeeking:f=>f.stopPropagation(),style:{width:"100%",height:"100%",objectFit:"contain",pointerEvents:"auto"}})})]})},Ld=tp;var dp=({video:e,isSelected:o,onClick:t,onDragEnd:a,onTransformEnd:r,onContextMenu:s,nodeRef:n})=>{let[i,u]=useState(null),l=useSelector(x=>x.toolbar.selectedTool),c=l==="pen"||l==="eraser";if(useEffect(()=>{if(e.thumbnailDataUrl){let x=new window.Image;x.src=e.thumbnailDataUrl,x.onload=()=>{u(x);};}},[e.thumbnailDataUrl]),!i)return null;let d=e.width/2,m=e.height/2,f=Math.min(e.width,e.height)*.08,h=Math.max(40,Math.min(f,80));return jsxs(Group,{draggable:!c,listening:!c,x:e.x,y:e.y,rotation:e.rotation,width:e.width,height:e.height,...c?{}:{onDragEnd:a,onTransformEnd:r},ref:x=>{if(n(x),x){let p=x.getStage()?.container();if(p){let v=g=>{let b=x.getStage()?.getPointerPosition();if(b){let y={x:e.x,y:e.y,width:e.width,height:e.height};b.x>=y.x&&b.x<=y.x+y.width&&b.y>=y.y&&b.y<=y.y+y.height&&s(g);}};p.addEventListener("contextmenu",v),x._contextMenuCleanup=()=>{p.removeEventListener("contextmenu",v);};}}},children:[jsx(Image$1,{image:i,width:e.width,height:e.height,listening:!c,...c?{}:{onClick:t,onTap:t},shadowColor:"black",shadowBlur:o?10:0,shadowOpacity:o?.3:0}),jsx(Circle,{x:d,y:m,radius:h,fill:"white",listening:!c,shadowColor:"black",shadowBlur:20,shadowOpacity:.4,shadowOffsetX:0,shadowOffsetY:2,...c?{}:{onClick:t,onTap:t}}),jsx(Circle,{x:d,y:m,radius:h*.88,fill:"rgba(0, 0, 0, 0.75)",listening:!c,...c?{}:{onClick:t,onTap:t}}),jsx(RegularPolygon,{x:d+h*.1,y:m,sides:3,radius:h*.35,fill:"white",rotation:90,listening:!c,...c?{}:{onClick:t,onTap:t}})]})},Id=dp;var li=memo(({videos:e,selectedId:o,videoRefs:t,onVideoClick:a,onDragEnd:r,onTransformEnd:s,onContextMenu:n})=>jsx(Fragment,{children:e.map(i=>jsxs(be__default.Fragment,{children:[jsx(Id,{video:i,isSelected:!i.isPlaying&&o===i.id,onClick:()=>a(i.id),onDragEnd:u=>r(i.id,u),onTransformEnd:u=>s(i.id,u),onContextMenu:u=>n(u,i.id,"video"),nodeRef:u=>{u?t.current.set(i.id,u):t.current.delete(i.id);}}),i.isPlaying&&(()=>{let u=i.x,l=i.y;if(i.isRecorded){let c=typeof window<"u"?window.innerWidth:i.width,d=typeof window<"u"?window.innerHeight:i.height;u=(c-i.width)/2,l=(d-i.height)/2;}return jsx(Ld,{id:i.id,src:i.objectUrl,x:u,y:l,width:i.width,height:i.height,isSelected:false,rotation:i.rotation,onTransformEnd:c=>s(i.id,c),onDragEnd:c=>r(i.id,c)})})()]},i.id))}));li.displayName="VideoLayer";var di=memo(({shapes:e,shapeRefs:o,handleShapeDragEnd:t,handleShapeResizeEnd:a,onSelect:r,handleShapeDragStart:s,onContextMenu:n})=>{let i=useSelector(l=>l.toolbar.selectedTool),u=i==="pen"||i==="eraser";return jsx(Fragment,{children:e.map((l,c)=>{let d=l.id||c,m={id:l.id,x:l.x,y:l.y,rotation:l.rotation,draggable:!l.locked&&!u,listening:!u,fill:l.color||"#096B76",stroke:"#000000",strokeWidth:2,opacity:1};switch(l.type?.toLowerCase()){case "circle":return jsx(Circle,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},radius:l.radius||l.width/2,width:l.width,height:l.width},d);case "star":return jsx(Star,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},numPoints:5,innerRadius:l.innerRadius||l.width/4,outerRadius:l.outerRadius||l.width/2},d);case "triangle":return jsx(RegularPolygon,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},sides:3,radius:l.radius||l.width/2},d);case "polygon":return jsx(RegularPolygon,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},sides:l.sides||6,radius:l.radius||l.width/2},d);case "ellipse":return jsx(Ellipse,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},radiusX:l.radiusX||l.width/2,radiusY:l.radiusY||l.height/2},d);case "ring":return jsx(Ring,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},innerRadius:l.innerRadius||l.width/4,outerRadius:l.outerRadius||l.width/2},d);case "wedge":return jsx(Wedge,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},radius:l.radius||l.width/2,angle:l.angle||60},d);case "arrow":return jsx(Arrow,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,scaleX:l.scaleX||1,scaleY:l.scaleY||1,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},points:l.points||[0,0,l.width,0],pointerLength:l.pointerLength||10,pointerWidth:l.pointerWidth||10,stroke:"#000000",strokeWidth:l.strokeWidth||3,fill:"transparent"},d);case "line":return jsx(Line,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,scaleX:l.scaleX||1,scaleY:l.scaleY||1,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},points:l.points||[0,0,l.width,0],stroke:"#000000",strokeWidth:l.strokeWidth||3,fill:"transparent"},d);case "arc":return jsx(Arc,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},innerRadius:l.innerRadius||l.width/4,outerRadius:l.outerRadius||l.width/2,angle:l.angle||90},d);case "rectangle":default:return jsx(Rect,{ref:f=>{f?o.current.set(l.id,f):o.current.delete(l.id);},...m,draggable:!l.locked&&!u,...u?{}:{onDragStart:f=>{s?.();},onDragEnd:f=>t(l.id,f),onTransformEnd:f=>a(l.id,f),onClick:()=>r(l.id),onContextMenu:f=>{f.evt.preventDefault(),n(f.evt,l.id,"shape");}},width:l.width,height:l.height,cornerRadius:l.type==="rounded-rectangle"?10:0},d)}})})});di.displayName="ShapeLayer";var Md=({texts:e,textRefs:o,onDragEnd:t,onTransformEnd:a,onSelect:r,onContextMenu:s,onDoubleClick:n,editingTextId:i})=>{let u=useSelector(c=>c.toolbar.selectedTool),l=u==="pen"||u==="eraser";return jsx(Fragment,{children:e.map(c=>{let d=c.id===i,m=c.fontWeight==="bold",f=m?Math.max(1,c.fontSize/25):0;return jsx(Text,{id:c.id,ref:h=>{h?o.current.set(c.id,h):o.current.delete(c.id);},text:c.text,x:c.x,y:c.y,width:c.width,height:c.height,rotation:c.rotation,draggable:!c.locked&&!d&&!l,listening:!l,fontSize:c.fontSize,fontFamily:c.fontFamily,fontStyle:c.fontStyle,fontWeight:c.fontWeight,textDecoration:c.textDecoration,fill:c.fill,stroke:m?c.fill:void 0,strokeWidth:f,align:c.align,wrap:"none",lineHeight:1.2,opacity:d?0:1,visible:!d,...l?{}:{onClick:()=>r(c.id),onTap:()=>r(c.id),onDblClick:()=>n(c.id),onDblTap:()=>n(c.id),onDragEnd:h=>t(h,c.id),onTransformEnd:()=>a(c.id),onContextMenu:h=>{h.evt.preventDefault();let x=h.evt;s(x,c.id,"text");}}},c.id)})})};var Ep=({flashcard:e,isSelected:o,onClick:t,onDragEnd:a,onTransformEnd:r,onContextMenu:s,onNext:n,onPrevious:i,nodeRef:u})=>{let[l,c]=useState(null);if(useEffect(()=>{if(e.images.length>0&&e.images[e.currentIndex]){let p=new window.Image;p.src=e.images[e.currentIndex],p.onload=()=>{c(p);};}},[e.images,e.currentIndex]),!l||e.images.length===0)return null;let d=8,m=2,f=Math.min(e.width,e.height)*.08,h=Math.max(16,Math.min(f,32)),x=15;return jsxs(Group,{id:e.id,draggable:e.draggable&&!e.locked,x:e.x,y:e.y,rotation:e.rotation,width:e.width,height:e.height,onDragEnd:a,onTransformEnd:r,ref:p=>{if(u(p),p){let v=p.getStage()?.container();if(v){let g=b=>{let y=p.getStage()?.getPointerPosition();if(y){let S={x:e.x,y:e.y,width:e.width,height:e.height};y.x>=S.x&&y.x<=S.x+S.width&&y.y>=S.y&&y.y<=S.y+S.height&&s(b);}};v.addEventListener("contextmenu",g),p._contextMenuCleanup=()=>{v.removeEventListener("contextmenu",g);};}}},children:[jsx(Rect,{width:e.width,height:e.height,cornerRadius:d,fill:"white",shadowColor:"black",shadowBlur:o?12:8,shadowOpacity:o?.3:.2,shadowOffsetX:0,shadowOffsetY:2,onClick:t,onTap:t}),jsx(Rect,{width:e.width,height:e.height,cornerRadius:d,stroke:"#E5E7EB",strokeWidth:m,listening:false}),jsx(Image$1,{x:m+4,y:m+4,image:l,width:e.width-(m+4)*2,height:e.height-(m+4)*2,cornerRadius:d-m,onClick:t,onTap:t}),jsx(Rect,{x:m,y:e.height-50,width:e.width-m*2,height:50,cornerRadius:[0,0,d-m,d-m],fillLinearGradientStartPoint:{x:0,y:0},fillLinearGradientEndPoint:{x:0,y:50},fillLinearGradientColorStops:[0,"rgba(255, 255, 255, 0)",1,"rgba(255, 255, 255, 0.95)"],listening:false}),e.images.length>1&&(e.order==="sequential"||e.order==="random"&&e.navigationHistory&&e.navigationHistory.length>1)&&jsxs(Group,{x:x+h,y:e.height/2,onClick:p=>{p.cancelBubble=true,i();},onTap:p=>{p.cancelBubble=true,i();},children:[jsx(Circle,{radius:h,fill:"white",shadowColor:"black",shadowBlur:4,shadowOpacity:.15}),jsx(Line,{points:[-4,-6,-10,0,-4,6],stroke:"#6B7280",strokeWidth:2,lineCap:"round",lineJoin:"round"})]}),e.images.length>1&&jsxs(Group,{x:e.width-x-h,y:e.height/2,onClick:p=>{p.cancelBubble=true,n();},onTap:p=>{p.cancelBubble=true,n();},children:[jsx(Circle,{radius:h,fill:"white",shadowColor:"black",shadowBlur:4,shadowOpacity:.15}),jsx(Line,{points:[4,-6,10,0,4,6],stroke:"#6B7280",strokeWidth:2,lineCap:"round",lineJoin:"round"})]}),jsx(Rect,{x:e.width-60,y:e.height-35,width:50,height:24,cornerRadius:4,fill:"rgba(255, 255, 255, 0.9)"}),jsx(Text,{x:e.width-60,y:e.height-35,width:50,height:24,text:`${e.currentIndex+1}/${e.images.length}`,fontSize:11,fontFamily:"Arial",fill:"#6B7280",align:"center",verticalAlign:"middle"})]})},Pd=Ep;var fi=memo(({flashcards:e,flashcardRefs:o,selectedId:t,onDragEnd:a,onTransform:r,onSelect:s,onNext:n,onPrevious:i,onContextMenu:u})=>jsx(Fragment,{children:e.map(l=>jsx(Pd,{flashcard:l,isSelected:t===l.id,onClick:()=>s(l.id),onDragEnd:a,onTransformEnd:c=>r(l.id,c),onContextMenu:c=>u(c,l.id,"flashcard"),onNext:()=>n(l.id),onPrevious:()=>i(l.id),nodeRef:c=>{c?o.current.set(l.id,c):o.current.delete(l.id);}},l.id))}));fi.displayName="FlashcardLayer";var Rd=e=>{let o=xe(),t=useRef(false),a=useRef(false),r=useRef([]),[s,n]=useState(null);ee(b=>b.toolbar.selectedTool);let u=ee(b=>b.toolbar.penColor),l=ee(b=>b.toolbar.strokeWidth),c=ee(b=>b.canvas.isSketchMode),d=ee(b=>b.canvas.slides.find(S=>S.id===b.canvas.currentSlideId)?.photoFrames.find(S=>S.id===e)),m=d?.annotations||[],f=d?.isDrawingMode||false,h=d?.width||1,x=d?.height||1,p=useCallback(b=>{if(!f)return;t.current=true,a.current=false,r.current=[{x:b.x,y:b.y}];let y=b.x/h,S=b.y/x;n({tool:"pen",points:[y,S],color:u,strokeWidth:l/h,isSketch:c});},[f,u,l,c,h,x]),v=useCallback(b=>{if(!t.current||!s)return;a.current=true;let y=r.current[r.current.length-1];if(Math.sqrt(Math.pow(b.x-y.x,2)+Math.pow(b.y-y.y,2))<2)return;r.current.push({x:b.x,y:b.y});let I;if(c)I=ss(r.current,{size:l*2,thinning:.6,smoothing:.5,streamline:.5,simulatePressure:true}).map((L,P)=>P%2===0?L/h:L/x);else {let C=b.x/h,L=b.y/x;I=[...s.points,C,L];}n(C=>C?{...C,points:I}:null);},[c,l,s,h,x]),g=useCallback(()=>{t.current&&(s&&s.points.length>0&&o(Dn({frameId:e,line:s})),n(null),t.current=false,a.current=false,r.current=[]);},[o,e,s]);return {annotations:m,activeLine:s,isDrawingMode:f,startDrawing:p,draw:v,stopDrawing:g}};var Wp=({photoFrame:e,isSelected:o,onClick:t,onDragEnd:a,onTransformEnd:r,onContextMenu:s,onStartCamera:n,onCapture:i,cameraStream:u,nodeRef:l})=>{let[c,d]=useState(null),[m,f]=useState(null),h=useRef(null),x=useRef(null),p=useRef(null),v=useRef(null),g=useRef(0),b=33,y=useSelector(D=>D.toolbar.selectedTool),S=y==="pen"||y==="eraser",{annotations:I,activeLine:C,isDrawingMode:L,startDrawing:P,draw:A,stopDrawing:U}=Rd(e.id);useEffect(()=>{if(!L)return;let D=()=>{U();},z=()=>{U();};return window.addEventListener("mouseup",D),window.addEventListener("touchend",z),()=>{window.removeEventListener("mouseup",D),window.removeEventListener("touchend",z);}},[U,L]),useEffect(()=>{if(e.capturedImageUrl){let D=new window.Image;D.src=e.capturedImageUrl,D.onload=()=>{d(D);};}},[e.capturedImageUrl]),useEffect(()=>{if(e.isCapturing&&u){h.current||(h.current=document.createElement("video"),h.current.autoplay=true,h.current.playsInline=true),x.current||(x.current=document.createElement("canvas"));let D=h.current,z=x.current;D.srcObject=u;let X=()=>{z.width=D.videoWidth||640,z.height=D.videoHeight||480,console.log("\u{1F4F9} Starting live capture, canvas size:",z.width,z.height);let _=Y=>{if(Y-g.current<b){p.current=requestAnimationFrame(_);return}g.current=Y;let Z=z.getContext("2d");if(Z&&D.readyState===D.HAVE_ENOUGH_DATA){Z.drawImage(D,0,0,z.width,z.height);let Q=z.toDataURL("image/jpeg",.6),pe=new window.Image;pe.onload=()=>{f(pe);},pe.src=Q;}p.current=requestAnimationFrame(_);};p.current=requestAnimationFrame(_);};return D.onloadedmetadata=X,D.readyState>=D.HAVE_METADATA&&X(),D.play().catch(_=>console.error("Error playing video:",_)),()=>{p.current&&(cancelAnimationFrame(p.current),p.current=null);}}return ()=>{f(null),v.current&&(v.current.src="");}},[e.isCapturing,u]);let F=()=>{h.current&&e.isCapturing&&i(h.current);},E=D=>{if(e.capturedImageUrl){if(!L){t();return}let z=D.currentTarget,X=z.getAbsoluteTransform().copy(),Y=z.getStage()?.getPointerPosition();if(Y){X.invert();let Z=X.point(Y);P(Z);}D.cancelBubble=true;}else t();},R=D=>{if(!L||!e.capturedImageUrl)return;let z=D.currentTarget,X=z.getAbsoluteTransform().copy(),Y=z.getStage()?.getPointerPosition();if(Y){X.invert();let Z=X.point(Y);A(Z);}},H=()=>{!L||!e.capturedImageUrl||U();},N=e.isCapturing?m:c,te=Math.min(e.width,e.height)*.12,q=Math.max(25,Math.min(te,50)),G=e.width/2,oe=e.height/2;return jsxs(Group,{id:e.id,draggable:!L&&!S,listening:true,x:e.x,y:e.y,...S?{}:{onDragEnd:a,onTransformEnd:r},rotation:e.rotation,width:e.width,height:e.height,ref:D=>{if(l(D),D){let z=D.getStage()?.container();if(z){let X=_=>{let Y=D.getStage()?.getPointerPosition();if(Y){let Z={x:e.x,y:e.y,width:e.width,height:e.height};Y.x>=Z.x&&Y.x<=Z.x+Z.width&&Y.y>=Z.y&&Y.y<=Z.y+Z.height&&s(_);}};z.addEventListener("contextmenu",X),D._contextMenuCleanup=()=>{z.removeEventListener("contextmenu",X);};}}},children:[jsx(Rect,{x:-20,y:-20,width:e.width+50,height:e.height+50,fill:N?"transparent":"white",strokeWidth:o?0:2,cornerRadius:8,listening:true,onClick:t,onTap:t,shadowColor:"rgba(0,0,0,0.35)",shadowBlur:15,shadowOpacity:.4,shadowOffset:{x:0,y:4}}),N&&jsx(Image$1,{image:N,width:e.width,height:e.height,cornerRadius:8,listening:true,onClick:E,onTap:E,onMouseDown:E,onTouchStart:E,onMouseMove:R,onTouchMove:R,onMouseUp:H,onTouchEnd:H,...S?{}:{onDragEnd:a,onTransformEnd:r}}),I?.map((D,z)=>{let X=D.points.map((Y,Z)=>Z%2===0?Y*e.width:Y*e.height),_=D.strokeWidth*e.width;return jsx(Line,{points:X,stroke:D.tool==="eraser"?"white":D.color,strokeWidth:_,tension:.5,lineCap:"round",lineJoin:"round",globalCompositeOperation:D.tool==="eraser"?"destination-out":"source-over",fill:D.isSketch?D.color:void 0,closed:D.isSketch,listening:false},z)}),C&&jsx(Line,{points:C.points.map((D,z)=>z%2===0?D*e.width:D*e.height),stroke:C.tool==="eraser"?"white":C.color,strokeWidth:C.strokeWidth*e.width,tension:.5,lineCap:"round",lineJoin:"round",globalCompositeOperation:C.tool==="eraser"?"destination-out":"source-over",fill:C.isSketch?C.color:void 0,closed:C.isSketch,listening:false},"active"),!N&&!e.isCapturing&&jsxs(Fragment,{children:[jsx(Text,{x:10,y:6,width:e.width,text:"Take a Photo",fontSize:22,fontStyle:"bold",fill:"#000000CC",fontFamily:"Arial"}),jsx(Text,{x:12,y:32,width:e.width,text:"Capture a photo to add directly into your canvas.",fontSize:12,fill:"#00000099",fontFamily:"Arial"}),jsx(Rect,{x:0,y:oe-90,width:e.width,fill:"#EBF6F7",height:180,stroke:"#00000066",strokeWidth:1.5,dash:[4,4],cornerRadius:8}),!e.capturedImageUrl&&jsxs(Fragment,{children:[jsx(Rect,{x:G-q+6,y:oe-60,width:q*1.6,height:q*1.6,radius:q,fill:"white",cornerRadius:8,listening:true,onClick:D=>{D.cancelBubble=true,e.isCapturing?F():n();},onTap:D=>{D.cancelBubble=true,e.isCapturing?F():n();}}),jsx(Html,{groupProps:{x:G-12,y:oe-40,width:q*2,height:16},children:jsx(CameraPlus,{weight:"fill",color:"#096B76",size:24,onClick:D=>{D.stopPropagation(),e.isCapturing?F():n();}})})]}),jsx(Text,{x:0,y:oe,width:e.width,height:40,text:"Click on the camera to start",fontStyle:"bold",fontSize:18,fontFamily:"Arial",fill:"#666",align:"center",verticalAlign:"middle"}),jsx(Text,{x:0,y:oe+24,width:e.width,height:40,text:"Make sure you have good lighting!",fontSize:14,fontFamily:"Arial",fill:"#666",align:"center",verticalAlign:"middle"}),jsx(Rect,{x:G-24,y:oe+104,width:q*1.6,height:q*1.6,radius:q,fill:"#096B76",cornerRadius:q,listening:true,onClick:D=>{D.cancelBubble=true,e.isCapturing?F():n();},onTap:D=>{D.cancelBubble=true,e.isCapturing?F():n();}}),jsx(Html,{groupProps:{x:G-8,y:oe+120,width:q*2,height:16},children:jsx(Camera,{weight:"fill",color:"white",size:24,onClick:D=>{D.stopPropagation(),e.isCapturing?F():n();}})})]}),e.isCapturing&&jsxs(Fragment,{children:[jsx(Rect,{x:10,y:10,width:60,height:25,fill:"rgba(231, 76, 60, 0.9)",cornerRadius:4}),jsx(Text,{x:10,y:10,width:60,height:25,text:"\u25CF LIVE",fontSize:12,fontFamily:"Arial",fontStyle:"bold",fill:"white",align:"center",verticalAlign:"middle"})]})]})},Od=Wp;var xi=memo(({photoFrames:e,photoFrameRefs:o,selectedId:t,onDragEnd:a,onTransform:r,onSelect:s,onStartCamera:n,onCapture:i,cameraStreams:u,onContextMenu:l})=>jsx(Fragment,{children:e.map(c=>jsx(Od,{photoFrame:c,isSelected:t===c.id,onClick:()=>s(c.id),onDragEnd:d=>a(d,c.id),onTransformEnd:d=>r(c.id,d),onContextMenu:d=>l(d,c.id,"photoFrame"),onStartCamera:()=>n(c.id),onCapture:d=>i(c.id,d),cameraStream:u.get(c.id),nodeRef:d=>{d?o.current.set(c.id,d):o.current.delete(c.id);}},c.id))}));xi.displayName="PhotoFrameLayer";var Ud=({x:e,y:o,onAction:t,onClose:a,type:r,elementId:s="",isDrawingMode:n,menuRef:i})=>{useEffect(()=>{let d=f=>{i?.current&&!i.current.contains(f.target)&&a();},m=f=>{f.key==="Escape"&&a();};return document.addEventListener("mousedown",d),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",m);}},[a]);let u=useMemo(()=>[{action:"order",label:"Order",icon:jsx(ArrowUpIcon,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),hasSubmenu:true},{action:"lock",label:"Lock",icon:jsx(Lock,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),hasSubmenu:true},{action:"link",label:"Link",icon:jsx(LinkIcon,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),hideForTypes:["line"]},{action:"voice",label:"Voice",icon:jsx(SpeakerHifiIcon,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),hideForTypes:["line"]},{action:"edit",label:"Edit",icon:jsx(NotePencilIcon,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),showForTypes:["mcq","trueFalse","shortAnswer","longAnswer","fillInTheBlanks"]},{action:"editFlashcard",label:"Edit Flashcard",icon:jsx(NotePencilIcon,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),showForTypes:["flashcard"]},{action:"color",label:"Change Color",icon:jsx(Palette,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),showForTypes:["shape"]},{action:"crop",label:"Crop Image",icon:jsx(ScissorsIcon,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),showForTypes:["image"]},{action:"draw",label:n?"Exit Drawing Mode":"Draw on Image",icon:jsx(PencilSimple,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),showForTypes:["image","photoFrame"]},{action:"duplicate",label:"Duplicate",icon:jsx(CopySimple,{className:"h-5 w-5",weight:"fill",color:"#00000099"})},{action:"infinite-clone",label:"Infinite Clone",icon:jsx(Square,{className:"h-5 w-5",weight:"fill",color:"#00000099"})},{action:"make-response",label:"Make Response",icon:jsx(Chat,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),hideForTypes:["line"]},{action:"accessibility",label:"Accessibility",icon:jsx(EyeIcon,{className:"h-5 w-5",weight:"fill",color:"#00000099"}),hideForTypes:["line"]},{action:"layers",label:"Layers",icon:jsx(Stack,{className:"h-5 w-5",weight:"fill",color:"#00000099"})},{action:"delete",label:"Delete",icon:jsx(Trash,{className:"h-5 w-5",weight:"fill",color:"#E92222"}),isDanger:true}].filter(m=>!(m.showForTypes&&!m.showForTypes.includes(r)||m.hideForTypes&&m.hideForTypes.includes(r))),[r,n]),l=(d,m)=>{d==="order"||d==="lock"?t(d,m):(t(d),a());},c=jsx("div",{ref:i,className:"absolute z-100 min-w-[200px] rounded-2xl border border-gray-200 bg-white shadow-xl",style:{left:`${e}px`,top:`${o}px`},children:jsx("div",{className:"space-y-1 p-2",children:u.map((d,m)=>jsxs("button",{onClick:f=>l(d.action,f),className:`flex w-full items-center justify-between rounded-md px-4 py-2 text-left text-sm transition-colors hover:cursor-pointer hover:bg-[#0000000A] ${d.isDanger?"text-red-600 hover:bg-red-50":"text-gray-700"}`,children:[jsxs("div",{className:"flex items-center gap-3",children:[d.icon,jsx("span",{className:`font-medium ${d.isDanger?"text-[#E92222]":"text-[#00000099]"}`,children:d.label})]}),d.hasSubmenu&&jsx("svg",{className:"h-4 w-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]},m))})});return createPortal(c,document.body)};var Hd=({x:e,y:o,items:t,onClose:a})=>{let r=useRef(null);return useEffect(()=>{let s=n=>{r.current&&!r.current.contains(n.target)&&a();};return document.addEventListener("mousedown",s),()=>{document.removeEventListener("mousedown",s);}},[a]),jsx("div",{ref:r,className:"fixed z-101 min-w-[180px] rounded-lg border border-gray-200 bg-white shadow-xl",style:{left:`${e}px`,top:`${o}px`},children:jsx("div",{className:"py-2",children:t.map((s,n)=>jsx("button",{onClick:()=>{s.onClick(),a();},className:"flex w-full items-center px-4 py-2.5 text-left text-sm text-gray-700 transition-colors hover:bg-gray-50",children:jsx("span",{className:"font-medium",children:s.label})},n))})})};var zd=({title:e,label:o,placeholder:t,defaultValue:a="",onSave:r,onClose:s})=>{let[n,i]=useState(a),u=useRef(null);useEffect(()=>{u.current?.focus();},[]);let l=()=>{r(n),s();};return jsx("div",{className:"fixed inset-0 z-102 flex items-center justify-center bg-black/50",children:jsxs("div",{className:"w-full max-w-md rounded-lg bg-white p-6 shadow-2xl",children:[jsxs("div",{className:"mb-4 flex items-center justify-between",children:[jsx("h2",{className:"text-xl font-semibold text-gray-900",children:e}),jsx("button",{onClick:s,className:"rounded-lg p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600",children:jsx(X,{className:"h-5 w-5"})})]}),jsxs("div",{className:"mb-6",children:[jsx("label",{className:"mb-2 block text-sm font-medium text-gray-700",children:o}),jsx("input",{ref:u,type:"text",value:n,onChange:d=>i(d.target.value),onKeyDown:d=>{d.key==="Enter"?l():d.key==="Escape"&&s();},placeholder:t,className:"w-full rounded-lg border border-gray-300 px-4 py-2 focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 focus:outline-none"})]}),jsxs("div",{className:"flex justify-end gap-3",children:[jsx("button",{onClick:s,className:"rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50",children:"Cancel"}),jsx("button",{onClick:l,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700",children:"Save"})]})]})})};var Wd=({defaultColor:e="#096B76",onConfirm:o,onCancel:t})=>{let[a,r]=useState(e),s=useRef(null);useEffect(()=>{let c=d=>{d.key==="Escape"&&t();};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t]);let n=c=>{c.preventDefault(),o(a);},i=(c,d,m)=>{m/=100;let f=d*Math.min(m,1-m)/100,h=x=>{let p=(x+c/30)%12,v=m-f*Math.max(Math.min(p-3,9-p,1),-1);return Math.round(255*v).toString(16).padStart(2,"0")};return `#${h(0)}${h(8)}${h(4)}`},l=jsx("div",{className:"pointer-events-none fixed inset-0 z-100 flex items-center justify-center",onMouseDown:c=>c.stopPropagation(),onMouseUp:c=>c.stopPropagation(),onMouseMove:c=>c.stopPropagation(),onTouchStart:c=>c.stopPropagation(),onTouchMove:c=>c.stopPropagation(),onTouchEnd:c=>c.stopPropagation(),children:jsxs("div",{ref:s,className:"pointer-events-auto max-h-[90vh] w-96 max-w-[90vw] overflow-y-auto rounded-xl border border-gray-200 bg-white p-6 shadow-2xl",onClick:c=>c.stopPropagation(),children:[jsxs("div",{className:"mb-4 flex items-center justify-between",children:[jsx("h3",{className:"text-lg font-semibold text-gray-800",children:"Change Shape Color"}),jsx("button",{onClick:t,className:"rounded-lg p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600",children:jsx(X,{size:20,weight:"bold"})})]}),jsxs("form",{onSubmit:n,children:[jsxs("div",{className:"space-y-4",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx("div",{className:"h-16 w-16 rounded-lg border-2 border-gray-300 shadow-sm",style:{backgroundColor:a}}),jsxs("div",{className:"flex-1",children:[jsx("label",{className:"mb-1 block text-xs font-semibold text-gray-500",children:"HEX COLOR"}),jsx("input",{type:"text",value:a,onChange:c=>r(c.target.value),className:"w-full rounded-lg border border-gray-300 px-3 py-2 font-mono text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-200 focus:outline-none",placeholder:"#000000"})]})]}),jsxs("div",{children:[jsx("label",{className:"mb-1 block text-xs font-semibold text-gray-500",children:"COLOR PICKER"}),jsx("input",{type:"color",value:a,onChange:c=>r(c.target.value),className:"h-12 w-full cursor-pointer rounded-lg border border-gray-300"})]}),jsxs("div",{children:[jsx("label",{className:"mb-1 block text-xs font-semibold text-gray-500",children:"HUE SLIDER"}),jsx("input",{type:"range",min:"0",max:"360",defaultValue:"180",onChange:c=>{let d=parseInt(c.target.value),m=i(d,100,50);r(m);},className:"h-3 w-full cursor-pointer appearance-none rounded-full",style:{background:"linear-gradient(to right, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%)"}})]}),jsxs("div",{children:[jsx("label",{className:"mb-2 block text-xs font-semibold text-gray-500",children:"PRESET COLORS"}),jsx("div",{className:"grid grid-cols-8 gap-2",children:["#FF6B6B","#4ECDC4","#45B7D1","#FFA07A","#98D8C8","#F7DC6F","#BB8FCE","#85C1E2","#096B76","#2C3E50","#E74C3C","#3498DB","#2ECC71","#F39C12","#9B59B6","#1ABC9C"].map(c=>jsx("button",{type:"button",onClick:()=>r(c),className:`h-8 w-8 rounded-lg border-2 transition-all hover:scale-110 ${a.toUpperCase()===c.toUpperCase()?"border-blue-500 ring-2 ring-blue-200":"border-gray-300"}`,style:{backgroundColor:c},title:c},c))})]})]}),jsxs("div",{className:"mt-6 flex gap-3",children:[jsx("button",{type:"button",onClick:t,className:"flex-1 rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50",children:"Cancel"}),jsx("button",{type:"submit",className:"flex-1 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:"Apply Color"})]})]})]})});return createPortal(l,document.body)};var kh=({imageSrc:e,onCrop:o})=>{let[t]=_d(e),a=useRef(null),r=useRef(null),s=useRef(null),n=useMemo(()=>{if(!t)return {width:600,height:400};let h=Math.min(600/t.width,400/t.height);return {width:t.width*h,height:t.height*h}},[t]),i=useMemo(()=>{let m=n.width*.5,f=n.height*.5,h=(n.width-m)/2,x=(n.height-f)/2;return {x:h,y:x,width:m,height:f}},[n]),[u,l]=useState(i);useEffect(()=>{l(i);},[i]),useEffect(()=>{s.current&&r.current&&(s.current.nodes([r.current]),s.current.getLayer()?.batchDraw());},[u]),useEffect(()=>{o(u.x,u.y,u.width,u.height);},[u,o]);let c=()=>{let m=r.current;if(!m)return;let f=m.scaleX(),h=m.scaleY();m.scaleX(1),m.scaleY(1),l({x:m.x(),y:m.y(),width:Math.max(20,m.width()*f),height:Math.max(20,m.height()*h)});},d=()=>{let m=r.current;m&&l({x:m.x(),y:m.y(),width:m.width(),height:m.height()});};return jsx(Stage,{width:n.width,height:n.height,className:"border border-gray-300",children:jsxs(Layer,{children:[jsx(Image$1,{ref:a,image:t,width:n.width,height:n.height}),jsx(Rect,{x:0,y:0,width:n.width,height:n.height,fill:"rgba(0, 0, 0, 0.5)",globalCompositeOperation:"source-over"}),jsx(Rect,{x:u.x,y:u.y,width:u.width,height:u.height,globalCompositeOperation:"destination-out"}),jsx(Rect,{ref:r,x:u.x,y:u.y,width:u.width,height:u.height,stroke:"#4A90E2",strokeWidth:2,draggable:true,onDragEnd:d,onTransformEnd:c,dragBoundFunc:m=>{let f=Math.max(0,Math.min(m.x,n.width-u.width)),h=Math.max(0,Math.min(m.y,n.height-u.height));return {x:f,y:h}}}),jsx(Transformer,{ref:s,borderStroke:"#4A90E2",borderStrokeWidth:2,anchorFill:"#fff",anchorStroke:"#4A90E2",anchorStrokeWidth:2,anchorSize:10,anchorCornerRadius:2,rotateEnabled:false,keepRatio:false,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(m,f)=>f.width<20||f.height<20||f.x<0||f.y<0||f.x+f.width>n.width||f.y+f.height>n.height?m:f})]})})},jd=({imageSrc:e,onConfirm:o,onCancel:t})=>{let a=useRef(null),[r,s]=useState({x:0,y:0,width:0,height:0}),[n]=_d(e);return useEffect(()=>{let c=d=>{d.key==="Escape"&&t();};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t]),createPortal(jsx("div",{className:"bg-opacity-50 pointer-events-none fixed inset-0 z-100 flex items-center justify-center bg-black",onMouseDown:c=>c.stopPropagation(),onMouseUp:c=>c.stopPropagation(),onMouseMove:c=>c.stopPropagation(),onTouchStart:c=>c.stopPropagation(),onTouchMove:c=>c.stopPropagation(),onTouchEnd:c=>c.stopPropagation(),children:jsxs("div",{ref:a,className:"pointer-events-auto max-h-[90vh] w-auto max-w-[90vw] overflow-y-auto rounded-xl border border-gray-200 bg-white p-6 shadow-2xl",onClick:c=>c.stopPropagation(),children:[jsxs("div",{className:"mb-4 flex items-center justify-between",children:[jsx("h3",{className:"text-lg font-semibold text-gray-800",children:"Crop Image"}),jsx("button",{onClick:t,className:"rounded-lg p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600",children:jsx(X,{size:20,weight:"bold"})})]}),jsx("div",{className:"mb-4 text-sm text-gray-600",children:"Drag the corners to resize the crop area, or drag the rectangle to move it."}),jsx("div",{className:"mb-6",children:jsx(kh,{imageSrc:e,onCrop:(c,d,m,f)=>{s({x:c,y:d,width:m,height:f});}})}),jsxs("div",{className:"flex gap-3",children:[jsx("button",{type:"button",onClick:t,className:"flex-1 rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50",children:"Cancel"}),jsxs("button",{type:"button",onClick:()=>{if(!n)return;let m=Math.min(600/n.width,400/n.height),f=r.x/m,h=r.y/m,x=r.width/m,p=r.height/m,v=document.createElement("canvas");v.width=x,v.height=p;let g=v.getContext("2d");if(!g)return;g.drawImage(n,f,h,x,p,0,0,x,p);let b=v.toDataURL("image/png");o(b);},className:"flex flex-1 items-center justify-center gap-2 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:[jsx(Check,{size:16,weight:"bold"}),"Crop Image"]})]})]})}),document.body)};var Jo=({onClose:e,stageRef:o,onRecordingComplete:t,directDrawingCanvasRef:a})=>{let[r,s]=useState(false),[n,i]=useState(null),[u,l]=useState(0),[c,d]=useState(true),m=useRef(null),f=useRef([]),h=useRef(null),x=useRef(null),p=useRef(null),v=useRef(null),g=useRef(null),b=useRef(null);useEffect(()=>()=>{p.current&&cancelAnimationFrame(p.current),h.current&&clearInterval(h.current),x.current&&x.current.getTracks().forEach(L=>L.stop());},[]);let y=async()=>{try{let L,P=null;if(o?.current){console.log("Creating recording canvas from Konva stage...");let R=o.current.getLayers();console.log("Konva layers:",R.length),R.forEach((z,X)=>{let _=z.getChildren();console.log(`Layer ${X} children count:`,_.length);});let H=document.createElement("canvas");H.width=o.current.width(),H.height=o.current.height();let N=H.getContext("2d",{willReadFrequently:!1});if(!N){console.error("Could not get recording canvas context"),alert("Failed to create recording canvas.");return}console.log("Recording canvas created, dimensions:",H.width,"x",H.height),g.current=H;let te=()=>{if(N.clearRect(0,0,H.width,H.height),R.forEach(z=>{let X=z.getCanvas()._canvas;X&&N.drawImage(X,0,0);}),a?.current){let z=a.current;N.drawImage(z,0,0);}};b.current=te,o.current.draw(),te(),await new Promise(z=>setTimeout(z,100)),console.log("Creating captureStream..."),L=H.captureStream(30),console.log("Canvas stream created, tracks:",L.getTracks().length);let G=L.getVideoTracks()[0];G&&console.log("Video track:",G.label,"state:",G.readyState);let oe=0,D=()=>{te(),o?.current&&(o.current.getLayers().forEach(X=>{X.batchDraw();}),oe++,oe%60===0&&console.log("Drawing frame:",oe)),p.current=requestAnimationFrame(D);};D();}else {console.error("Stage ref not provided"),alert("Stage reference not available.");return}if(c)try{P=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0}});}catch(R){console.warn("Microphone access denied:",R);}let A=[...L.getVideoTracks()];P&&A.push(...P.getAudioTracks());let U=new MediaStream(A);x.current=U;let F="video/webm";MediaRecorder.isTypeSupported("video/webm;codecs=vp9,opus")?F="video/webm;codecs=vp9,opus":MediaRecorder.isTypeSupported("video/webm;codecs=vp8,opus")?F="video/webm;codecs=vp8,opus":MediaRecorder.isTypeSupported("video/webm;codecs=vp9")?F="video/webm;codecs=vp9":MediaRecorder.isTypeSupported("video/webm;codecs=vp8")&&(F="video/webm;codecs=vp8"),console.log("Using mimeType:",F);let E=new MediaRecorder(U,{mimeType:F,videoBitsPerSecond:25e5});m.current=E,f.current=[],E.ondataavailable=R=>{console.log("Data available, size:",R.data.size),R.data.size>0&&f.current.push(R.data);},E.onstop=()=>{console.log("Recording stopped, chunks:",f.current.length);let R=new Blob(f.current,{type:F});console.log("Final blob size:",R.size),o?.current&&b.current&&g.current&&(o.current.draw(),o.current.getLayers().forEach(N=>{N.batchDraw();}),b.current(),v.current=g.current.toDataURL("image/jpeg",.8),console.log("Final canvas thumbnail captured, length:",v.current.length)),U.getTracks().forEach(H=>H.stop()),h.current&&clearInterval(h.current),p.current&&(cancelAnimationFrame(p.current),p.current=null),i(R);},E.onerror=R=>{console.error("MediaRecorder error:",R);},console.log("Starting recording..."),E.start(1e3),s(!0),l(0),h.current=setInterval(()=>{l(R=>R+1);},1e3);}catch(L){console.error("Error starting screen recording:",L),alert("Failed to start recording. Please ensure you granted permission.");}},S=()=>{m.current&&r&&(console.log("Stopping recording, state:",m.current.state),m.current.state!=="inactive"&&(m.current.requestData(),setTimeout(()=>{m.current&&m.current.state!=="inactive"&&m.current.stop();},100)),s(false));},I=()=>{if(n){let L=URL.createObjectURL(n),P=document.createElement("a");P.href=L,P.download=`screen-recording-${Date.now()}.webm`,document.body.appendChild(P),P.click(),document.body.removeChild(P),URL.revokeObjectURL(L);}},C=L=>{let P=Math.floor(L/60),A=L%60;return `${P.toString().padStart(2,"0")}:${A.toString().padStart(2,"0")}`};return r?jsxs("div",{className:"fixed top-4 left-1/2 z-102 flex -translate-x-1/2 items-center gap-4 rounded-full border border-gray-200 bg-white px-6 py-3 shadow-2xl",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("div",{className:"h-3 w-3 animate-pulse rounded-full bg-red-600"}),jsx("span",{className:"font-mono text-lg font-semibold text-gray-900",children:C(u)})]}),jsx("div",{className:"h-6 w-px bg-gray-300"}),jsx("span",{className:"text-sm text-gray-600",children:"Recording canvas..."}),jsxs("button",{onClick:S,className:"ml-2 flex items-center gap-2 rounded-full bg-red-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-red-700",children:[jsx(Stop,{className:"h-4 w-4",weight:"fill"}),"Stop"]})]}):jsx("div",{className:"fixed inset-0 z-102 flex items-center justify-center bg-black/50",children:jsxs("div",{className:"w-full max-w-md rounded-lg bg-white p-6 shadow-2xl",children:[jsxs("div",{className:"mb-2 flex items-center justify-between",children:[jsx("h2",{className:"text-xl font-bold text-[#000000CC]",children:"Screen Recording"}),jsx("button",{onClick:e,className:"rounded-lg p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600",children:jsx(X,{className:"h-5 w-5 text-[#00000099]"})})]}),jsxs("div",{className:"mb-6",children:[!n&&jsxs("div",{className:"text-start",children:[jsx("p",{className:"mb-4 text-base text-[#00000099]",children:"Record your canvas with voice narration. Everything you draw, type, or add will be captured automatically."}),jsxs("div",{className:"mx-auto mb-4 flex w-full flex-col items-center justify-between gap-4 px-2",children:[jsx("button",{onClick:()=>d(!c),className:`flex w-full cursor-pointer items-center justify-center gap-2 rounded-lg px-6 py-4 text-lg font-semibold transition-colors ${c?"text-primary border-[#096B76] bg-[#EBF6F7]":"border-gray-300 bg-[#F5F5F5] text-[#00000099]"}`,children:c?jsxs(Fragment,{children:[jsx(Microphone,{className:"h-5 w-5",weight:"fill"}),"Microphone On"]}):jsxs(Fragment,{children:[jsx(MicrophoneSlash,{className:"h-5 w-5",weight:"fill"}),"Microphone Off"]})}),jsxs("button",{onClick:y,className:"bg-primary hover:bg-primary/92 flex w-full cursor-pointer items-center justify-center gap-2 rounded-lg px-6 py-4 text-center text-lg font-semibold text-white transition-colors",children:[jsx(Record,{className:"h-5 w-5",weight:"fill"}),"Start Recording"]})]})]}),n&&jsxs("div",{className:"space-y-4",children:[jsx("div",{className:"overflow-hidden rounded-lg bg-gray-900",children:jsx("video",{src:URL.createObjectURL(n),controls:true,className:"w-full",style:{maxHeight:"300px"}})}),jsxs("p",{className:"text-center text-sm text-gray-600",children:["Recording saved! Duration: ",C(u)]}),jsxs("div",{className:"flex flex-col gap-2",children:[jsx("button",{onClick:()=>{t&&n&&v.current&&(t(n,v.current),e());},className:"flex items-center justify-center gap-2 rounded-lg bg-green-600 px-6 py-3 text-white transition-colors hover:bg-green-700",children:"Add to Canvas"}),jsxs("div",{className:"flex gap-2",children:[jsxs("button",{onClick:I,className:"flex flex-1 items-center justify-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-white transition-colors hover:bg-blue-700",children:[jsx(Download,{className:"h-5 w-5"}),"Download"]}),jsx("button",{onClick:()=>{i(null),l(0);},className:"flex-1 rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50",children:"Re-record"})]})]})]})]}),jsx("div",{className:"rounded-lg border border-[#A7B7D6] bg-blue-50 p-3",children:jsxs("p",{className:"text-start text-sm text-blue-900",children:[jsx("strong",{children:"Tip:"})," The canvas will be recorded automatically. The modal will disappear during recording so you can freely draw and edit."]})})]})})};var Xd=({elementType:e,existingAudio:o,onSave:t,onDelete:a,onClose:r})=>{let[s,n]=useState(false),[i,u]=useState(null),[l,c]=useState(false),[d,m]=useState(0),f=useRef(null),h=useRef([]),x=useRef(null),p=useRef(null);useEffect(()=>{o&&!i&&fetch(o).then(L=>L.blob()).then(L=>u(L)).catch(L=>console.error("Error loading audio:",L));},[o,i]);let v=async()=>{try{let L=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0}}),P=new MediaRecorder(L);f.current=P,h.current=[],P.ondataavailable=A=>{A.data.size>0&&h.current.push(A.data);},P.onstop=()=>{let A=new Blob(h.current,{type:"audio/webm"});u(A),L.getTracks().forEach(U=>U.stop()),x.current&&clearInterval(x.current);},P.start(),n(!0),m(0),x.current=setInterval(()=>{m(A=>A+1);},1e3);}catch(L){console.error("Error starting audio recording:",L),alert("Failed to start recording. Please allow microphone access.");}},g=()=>{f.current&&s&&(f.current.stop(),n(false));},b=()=>{if(i){let L=URL.createObjectURL(i),P=new Audio(L);p.current=P,P.onended=()=>{c(false),URL.revokeObjectURL(L);},P.play(),c(true);}},y=()=>{p.current&&(p.current.pause(),p.current.currentTime=0,c(false));},S=async()=>{if(i){let L=new FileReader;L.onloadend=()=>{let P=L.result;t(P),r();},L.readAsDataURL(i);}},I=()=>{u(null),a();},C=L=>{let P=Math.floor(L/60),A=L%60;return `${P.toString().padStart(2,"0")}:${A.toString().padStart(2,"0")}`};return s?jsxs("div",{className:"fixed top-4 left-1/2 z-103 flex -translate-x-1/2 items-center gap-4 rounded-full border border-gray-200 bg-white px-6 py-3 shadow-2xl",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("div",{className:"h-3 w-3 animate-pulse rounded-full bg-red-600"}),jsx("span",{className:"font-mono text-lg font-semibold text-gray-900",children:C(d)})]}),jsx("div",{className:"h-6 w-px bg-gray-300"}),jsx("span",{className:"text-sm text-gray-600",children:"Recording audio..."}),jsxs("button",{onClick:g,className:"ml-2 flex items-center gap-2 rounded-full bg-red-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-red-700",children:[jsx(Stop,{className:"h-4 w-4",weight:"fill"}),"Stop"]})]}):jsx("div",{className:"fixed inset-0 z-103 flex items-center justify-center bg-black/50",children:jsxs("div",{className:"w-full max-w-sm rounded-lg bg-white p-6 shadow-2xl",children:[jsxs("div",{className:"mb-6",children:[jsxs("h3",{className:"text-lg font-semibold text-gray-900",children:["Record Audio for"," ",e.charAt(0).toUpperCase()+e.slice(1).replace(/([A-Z])/g," $1")]}),jsx("p",{className:"text-sm text-gray-600",children:"Record a voice note for this element"})]}),jsxs("div",{className:"flex flex-col gap-4",children:[!i&&jsx("div",{className:"text-center",children:jsxs("button",{onClick:v,className:"bg-primary hover:bg-primary/90 flex w-full items-center justify-center gap-2 rounded-lg px-6 py-3 font-semibold text-white transition-colors hover:cursor-pointer",children:[jsx(Microphone,{className:"h-5 w-5",weight:"fill"}),"Start Recording"]})}),i&&jsxs("div",{className:"space-y-3",children:[jsxs("div",{className:"flex items-center justify-center gap-3",children:[jsxs("button",{onClick:l?y:b,className:"flex items-center gap-2 rounded-lg bg-blue-600 px-6 py-3 text-white transition-colors hover:bg-blue-700",children:[jsx(Play,{className:"h-5 w-5",weight:"fill"}),l?"Playing...":"Play Audio"]}),jsx("button",{onClick:I,className:"flex items-center gap-2 rounded-lg border border-red-300 bg-white px-4 py-3 text-red-600 transition-colors hover:bg-red-50",children:jsx(Trash,{className:"h-5 w-5"})})]}),jsx("button",{onClick:S,className:"w-full rounded-lg bg-green-600 px-6 py-3 text-white transition-colors hover:bg-green-700",children:"Save Audio"})]}),jsx("button",{onClick:r,className:"w-full rounded-lg bg-[#0000000A] p-3 text-base font-semibold text-[#00000099] transition-colors hover:cursor-pointer hover:bg-[#0000001A]",children:"Cancel"})]})]})})};var St=({audioData:e,x:o,y:t,width:a})=>{let[r,s]=useState(false),n=useRef(null);return jsx("button",{onClick:u=>{if(u.stopPropagation(),r&&n.current)n.current.pause(),n.current.currentTime=0,s(false);else {let l=new Audio(e);n.current=l,l.onended=()=>{s(false);},l.onerror=()=>{console.error("Error playing audio"),s(false);},l.play(),s(true);}},className:`absolute flex items-center justify-center rounded-full shadow-lg transition-all hover:scale-110 ${r?"bg-green-500 hover:bg-green-600":"bg-blue-500 hover:bg-blue-600"}`,style:{left:`${o+a-35}px`,top:`${t+5}px`,width:"30px",height:"30px",zIndex:99},title:r?"Stop Audio":"Play Audio",children:r?jsx(SpeakerSimpleSlash,{className:"h-4 w-4 text-white",weight:"fill"}):jsx(SpeakerHigh,{className:"h-4 w-4 text-white",weight:"fill"})})};var Zd=({selectedElementId:e,onClose:o,onSelectElement:t})=>{let a=xe(),r=ee(ge),s=useMemo(()=>{if(!r)return [];let x=[];return r.images?.forEach(p=>{x.push({id:p.id,type:"image",name:"Image",timestamp:p.timestamp||0});}),r.videos?.forEach(p=>{x.push({id:p.id,type:"video",name:"Video",timestamp:p.timestamp||0});}),r.shapes?.forEach(p=>{x.push({id:p.id,type:"shape",name:`${p.type} Shape`,timestamp:p.timestamp||0});}),r.texts?.forEach(p=>{x.push({id:p.id,type:"text",name:p.text.substring(0,20)+(p.text.length>20?"...":""),timestamp:p.timestamp||0});}),r.flashcards?.forEach(p=>{x.push({id:p.id,type:"flashcard",name:`Flashcard (${p.images.length} images)`,timestamp:p.timestamp||0});}),r.photoFrames?.forEach(p=>{x.push({id:p.id,type:"photoFrame",name:"Photo Frame",timestamp:p.timestamp||0});}),r.multipleChoices?.forEach(p=>{x.push({id:p.id,type:"mcq",name:"Multiple Choice",timestamp:p.timestamp||0});}),r.trueFalses?.forEach(p=>{x.push({id:p.id,type:"trueFalse",name:"True/False",timestamp:p.timestamp||0});}),r.shortAnswers?.forEach(p=>{x.push({id:p.id,type:"shortAnswer",name:"Short Answer",timestamp:p.timestamp||0});}),r.LongAnswer?.forEach(p=>{x.push({id:p.id,type:"longAnswer",name:"Long Answer",timestamp:p.timestamp||0});}),r.fillInTheBlanks?.forEach(p=>{x.push({id:p.id,type:"fillInTheBlanks",name:"Fill in the Blanks",timestamp:p.timestamp||0});}),r.lines?.forEach(p=>{p.id&&x.push({id:p.id,type:"line",name:"Drawn Line",timestamp:p.timestamp||0});}),x.sort((p,v)=>v.timestamp-p.timestamp)},[r]),[n,i]=useState(s),[u,l]=useState(false);useEffect(()=>{u||i(s);},[s]);let c=x=>{let p="h-5 w-5";switch(x){case "image":return jsx(Image$3,{className:p});case "video":return jsx(VideoCamera,{className:p});case "shape":return jsx(Shapes$1,{className:p});case "text":return jsx(TextT,{className:p});case "flashcard":return jsx(Cards$1,{className:p});case "photoFrame":return jsx(FrameCorners,{className:p});case "line":return jsx("span",{className:p,children:"\u270F\uFE0F"});default:return jsx(Question,{className:p})}},d=x=>{if(x===0)return;let p=n[x],v=n[x-1];a(Uo({id:p.id,type:p.type,newTimestamp:v.timestamp+1}));},m=x=>{if(x===n.length-1)return;let p=n[x],v=n[x+1];a(Uo({id:p.id,type:p.type,newTimestamp:v.timestamp-1}));},f=x=>{l(true),i(x);},h=()=>{l(false);let x=Date.now();n.forEach((p,v)=>{let g=x-v;a(Uo({id:p.id,type:p.type,newTimestamp:g}));});};return jsxs(Fragment,{children:[jsx("div",{className:"fixed inset-0 z-9998 bg-black/30",onClick:o}),jsxs("div",{className:"fixed top-1/2 left-1/2 z-9999 w-96 -translate-x-1/2 -translate-y-1/2 rounded-lg border border-gray-200 bg-white shadow-2xl",children:[jsxs("div",{className:"flex items-center justify-between border-b border-gray-200 p-4",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx(Stack$1,{className:"h-5 w-5 text-gray-700",weight:"bold"}),jsx("h3",{className:"font-semibold text-gray-900",children:"Layers"})]}),jsx("button",{onClick:o,className:"rounded-lg p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600",children:jsx(X$1,{className:"h-5 w-5"})})]}),jsx("div",{className:"max-h-96 overflow-y-auto p-2",children:n.length===0?jsx("div",{className:"p-8 text-center text-sm text-gray-500",children:"No elements on this slide"}):jsx(Reorder.Group,{axis:"y",values:n,onReorder:f,className:"space-y-1",children:n.map((x,p)=>{let v=x.id===e;return jsxs(Reorder.Item,{value:x,onDragEnd:h,className:`flex cursor-grab items-center gap-2 rounded-lg p-2 transition-colors active:cursor-grabbing ${v?"border border-blue-200 bg-blue-50":"border border-transparent hover:bg-gray-50"}`,whileDrag:{scale:1.02,boxShadow:"0 8px 20px rgba(0,0,0,0.15)",backgroundColor:"white",zIndex:50},children:[jsx("div",{className:"text-gray-400",children:jsx(DotsSixVertical,{className:"h-4 w-4",weight:"bold"})}),jsxs("div",{onClick:()=>t(x.id,x.type),className:"flex flex-1 cursor-pointer items-center gap-2",children:[jsx("div",{className:`${v?"text-blue-600":"text-gray-600"}`,children:c(x.type)}),jsx("span",{className:`text-sm ${v?"font-medium text-blue-900":"text-gray-700"}`,children:x.name})]}),jsxs("div",{className:"flex gap-1",children:[jsx("button",{onClick:g=>{g.stopPropagation(),d(p);},disabled:p===0,className:"rounded p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-30",title:"Move up (forward)",children:jsx(ArrowUp,{className:"h-4 w-4"})}),jsx("button",{onClick:g=>{g.stopPropagation(),m(p);},disabled:p===n.length-1,className:"rounded p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-30",title:"Move down (backward)",children:jsx(ArrowDown,{className:"h-4 w-4"})})]})]},x.id)})})}),jsx("div",{className:"border-t border-gray-200 p-3 text-xs text-gray-500",children:jsx("p",{children:"Drag to reorder \u2022 Top layers appear above bottom layers"})})]})]})};var Qd=memo(({multipleChoice:e,handleMcqTransform:o,mcqRefs:t,handleDragEnd:a,onContextMenu:r})=>{let s=useSelector(G=>G.toolbar.selectedTool),n=s==="pen"||s==="eraser",[i,u]=useState(new Set),[l,c]=useState(false),[d,m]=useState(null),f=useRef(null);useEffect(()=>{let G=f.current;if(G)return t.current.set(e.id,G),()=>{t.current.delete(e.id);}},[e.id]);let h=new Set(e.data.responseOptions.correctIndex),x=h.size>1,p=G=>{l||u(x?oe=>{let D=new Set(oe);return D.has(G)?D.delete(G):D.add(G),D}:new Set([G]));},v=()=>{i.size>0&&c(true);},g=()=>{c(false),u(new Set);},b=i.size===h.size&&Array.from(i).every(G=>h.has(G)),y=Array.from(i).filter(G=>h.has(G)),S=x&&y.length>0&&!b,I=()=>b?"\u2713 Correct! Great job! \u{1F389}":S?`\u26A0 Partially correct (${y.length}/${h.size})`:"\u2717 Try again!",C=()=>b?{bg:"#dcfce7",text:"#166534"}:S?{bg:"#fef3c7",text:"#92400e"}:{bg:"#fee2e2",text:"#991b1b"},L=55,P=8,A=24,U=60,F=60,E=x&&!l?25:0,R=e.data.feedbackMode==="practice"?48:0,H=12,N=U+E+(l?F:0),te=e.data.responseOptions.options.length*(L+P),q=N+te+H+R+A;return jsxs(Group,{ref:f,name:"mcq-element",draggable:!n,listening:!n,x:e.x,y:e.y,rotation:e.rotation,width:e.width,height:e.height,...n?{}:{onDragEnd:a,onContextMenu:G=>{let oe=f.current?.getStage()?.getPointerPosition();if(oe){let D={x:e.x,y:e.y,width:e.width,height:e.height};if(oe.x>=D.x&&oe.x<=D.x+D.width&&oe.y>=D.y&&oe.y<=D.y+D.height){let z=G.evt;r(z,e.id,"mcq");}}}},children:[jsx(Rect,{fill:"white",stroke:"#e5e7eb",strokeWidth:2,cornerRadius:12,height:q,width:e.width,onTransformEnd:G=>o(e.id,G)}),jsx(Text,{x:A+8,y:A,text:e.data.question,fontSize:20,fontStyle:"bold",fill:"#111827",width:e.width-A*2,listening:false}),x&&!l&&e.data.feedbackMode==="practice"?jsx(Text,{x:A,y:A+35,text:`Select ${h.size} answers (${i.size}/${h.size} selected)`,fontSize:14,fill:"#6b7280",width:e.width-A*2,listening:false}):null,l&&e.data.feedbackMode==="practice"?jsxs(Fragment,{children:[jsx(Rect,{x:A+24,y:U+E,width:e.width-A*2-40,height:F-20,fill:C().bg,cornerRadius:8}),jsx(Text,{x:A,y:U+E,width:e.width-A*2,height:F-20,text:I(),fontSize:16,fontStyle:"bold",fill:C().text,align:"center",verticalAlign:"middle",listening:false})]}):null,e.data.responseOptions.options.map((G,oe)=>{let D=h.has(oe),z=i.has(oe),X=N+oe*(L+P),_="#e5e7eb",Y="#ffffff",Z="#111827";return l&&D?(_="#22c55e",Y="#dcfce7",Z="#1B9D2C"):l&&z&&!D?(_="#ef4444",Y="#fee2e2",Z="#ef4444"):z&&(_="#096B76",Y="#ECFFF8",Z="#096B76"),jsxs(Group,{children:[jsx(Rect,{x:A+12,y:X+(L-20)/2,width:20,height:20,fill:z?"#096B76":"white",stroke:z?"#096B76":"#d1d5db",strokeWidth:2,cornerRadius:x?4:10,listening:false}),z&&jsx(Text,{x:A+12,y:X+(L-20)/2,width:20,height:20,text:"\u2713",fontSize:14,fill:"white",align:"center",verticalAlign:"middle",listening:false}),jsx(Rect,{x:A+44,y:X,width:e.width-A*2-60,height:L,fill:Y,stroke:_,strokeWidth:2,cornerRadius:8,onClick:Q=>{Q.cancelBubble=true,p(oe);},onTap:Q=>{Q.cancelBubble=true,p(oe);}}),jsx(Text,{x:A+60,y:X,width:e.width-A*2-80,height:L,text:G,fontSize:16,fill:Z,verticalAlign:"middle",listening:false})]},oe)}),e.data.feedbackMode==="practice"&&jsxs(Group,{y:N+e.data.responseOptions.options.length*(L+P)+12,children:[jsxs(Group,{onMouseDown:G=>{G.cancelBubble=true,m("check");},onMouseUp:G=>{G.cancelBubble=true,m(null),v();},onMouseLeave:G=>{G.cancelBubble=true,m(null);},onTouchStart:G=>{G.cancelBubble=true,m("check");},onTouchEnd:G=>{G.cancelBubble=true,m(null),v();},scaleX:d==="check"?.95:1,scaleY:d==="check"?.95:1,children:[jsx(Rect,{x:A+14,width:(e.width-A*2-24)/(l?2:1),height:48,fill:i.size===0||l?"#9ca3af":"#096B76",cornerRadius:8,onClick:G=>G.cancelBubble=true,onTap:G=>G.cancelBubble=true}),jsx(Text,{x:A+14,width:(e.width-A*2-24)/(l?2:1),height:48,text:l?"Submitted":"Check Work",fontSize:16,fontStyle:"bold",fill:"white",align:"center",verticalAlign:"middle",listening:false})]}),l&&jsxs(Group,{x:(e.width-A*2)/2+8,onMouseDown:()=>m("reset"),onMouseUp:()=>{m(null),g();},onMouseLeave:()=>m(null),onTouchStart:()=>m("reset"),onTouchEnd:()=>{m(null),g();},scaleX:d==="reset"?.95:1,scaleY:d==="reset"?.95:1,children:[jsx(Rect,{x:A,width:(e.width-A*2-8)/2,height:48,fill:"#ef4444",cornerRadius:8,onClick:G=>G.cancelBubble=true,onTap:G=>G.cancelBubble=true}),jsx(Text,{x:A,width:(e.width-A*2-8)/2,height:48,text:"Reset",fontSize:16,fontStyle:"bold",fill:"white",align:"center",verticalAlign:"middle",listening:false})]})]})]})});Qd.displayName="MultipleChoice";var eu=Qd;var wi=({multipleChoice:e,onContextMenu:o,handleMcqTransform:t})=>{let a=useDispatch(),r=useSelector(D=>D.toolbar.selectedTool),s=r==="pen"||r==="eraser",[n,i]=useState(false),[u,l]=useState(new Set),[c,d]=useState(false),[m,f]=useState(false),[h,x]=useState(0),p=340,v=100,g=window.innerWidth*.4,b=window.innerHeight*.5,y=p+20,S=v+60,I=g-40,C=b-300,L=useRef(null),P=D=>{a(oa({id:e.id,x:D.target.x(),y:D.target.y()}));},A=D=>{let z=D.target,X=z.x(),_=z.y(),Y=window.innerWidth*.2,Q=X+Y>y&&X<y+I&&_+50>S&&_<S+C;i(Q);},U=(D,z)=>{let X=z.target,_=X.x(),Y=X.y(),Z=window.innerWidth*.2,pe=_+Z>y&&_<y+I&&Y+50>S&&Y<S+C;l(pe?we=>new Set(we).add(D):we=>{let De=new Set(we);return De.delete(D),De}),i(false);},F=()=>{d(true);},E=()=>{d(false),l(new Set),x(D=>D+1);},R=new Set(e.data.responseOptions.correctIndex),H=u.size===R.size&&Array.from(u).every(D=>R.has(D)),N=Array.from(u).filter(D=>R.has(D)),te=N.length>0&&!H,q=()=>H?"\u2713 Correct! Great job!":te?`\u26A0 Partially correct (${N.length}/${R.size})`:"\u2717 Try again!",G=()=>H?{bg:"#dcfce7",text:"#166534"}:te?{bg:"#fef3c7",text:"#92400e"}:{bg:"#fee2e2",text:"#991b1b"},oe=()=>c?H?"#4CAF50":te?"#f59e0b":"#ef4444":n?"#4CAF50":"#075560";return jsxs(Group,{ref:L,name:"mcq-element",width:g,height:b,draggable:!s,listening:!s,...s?{}:{onContextMenu:D=>{D.evt.preventDefault(),o(D.evt,e.id,"mcq");}},children:[jsxs(Group,{x:p,y:v,rotation:e.rotation,onDragEnd:P,children:[jsx(Rect,{fill:"white",stroke:n?"#4CAF50":"#e5e7eb",strokeWidth:n?4:2,cornerRadius:12,height:e.data.feedbackMode==="practice"?b-100:b-50,width:g,shadowColor:n?"#4CAF50":"transparent",shadowBlur:n?20:0,shadowOpacity:.5}),jsx(Text,{x:20,y:20,width:g-40,text:e.data.question,fontSize:20,fontStyle:"bold",fill:"#111827",align:"center",verticalAlign:"middle"}),jsx(Rect,{x:20,y:80,width:I,height:C,fill:"#EBF6F7",stroke:oe(),strokeWidth:3,dash:[10,10],cornerRadius:8}),c&&jsxs(Fragment,{children:[jsx(Rect,{x:23,y:C+18,width:I-5,height:60,fill:G().bg,cornerRadius:8}),jsx(Text,{x:20,y:C+20,width:I,height:60,text:q(),fontSize:18,fontStyle:"bold",fill:G().text,align:"center",verticalAlign:"middle"})]}),u.size===0&&!c&&jsx(Text,{x:20,y:60,width:I,height:C-60,text:R.size>1?`Drop ${R.size} Correct Answers Here`:"Drop Here",fontSize:28,fontStyle:"bold",fill:"#075560",align:"center",verticalAlign:"middle"}),e.data.feedbackMode==="practice"?jsxs(Group,{x:20,y:c?b-200:b-160,children:[jsxs(Group,{onMouseDown:()=>{f(true),F();},onMouseUp:()=>f(false),onMouseLeave:()=>f(false),onTouchStart:()=>{f(true),F();},onTouchEnd:()=>f(false),scaleX:m?.95:1,scaleY:m?.95:1,children:[jsx(Rect,{fill:"#075560",stroke:"#e5e7eb",strokeWidth:2,cornerRadius:8,height:40,width:I}),jsx(Text,{text:"Check Work",fontSize:18,fontStyle:"bold",fill:"white",width:I,height:40,align:"center",verticalAlign:"middle",listening:false})]}),c&&jsxs(Group,{y:50,onMouseDown:E,onTouchStart:E,children:[jsx(Rect,{fill:"#dc2626",stroke:"#e5e7eb",strokeWidth:2,cornerRadius:8,height:40,width:I}),jsx(Text,{text:"Reset",fontSize:18,fontStyle:"bold",fill:"white",width:I,height:40,align:"center",verticalAlign:"middle",listening:false})]})]}):null]}),e.data.responseOptions.options.map((D,z)=>{let X=z%2,_=Math.floor(z/2),Y=window.innerWidth*.2,Z=50,Q=10,pe=u.has(z),we=R.has(z),De=c&&pe,Me="transparent";return De?Me=we?"#4CAF50":"#ef4444":pe&&(Me="#4CAF50"),jsxs(Group,{x:340+X*(Y+Q),y:v+b-80+_*(Z+Q),draggable:!c,onDragMove:A,onDragEnd:Ue=>U(z,Ue),opacity:c&&!pe?.5:1,children:[jsx(Rect,{width:Y-20,height:Z,fill:"white",stroke:Me,strokeWidth:4,cornerRadius:8,shadowBlur:20,shadowColor:"gray",shadowOpacity:.5}),jsx(Text,{width:Y-20,height:Z,text:D,fontSize:18,fontStyle:"bold",fill:"#096B76",align:"center",verticalAlign:"middle",listening:false})]},`${z}-${h}`)})]})};wi.displayName="MultipleChoiceDragAndDrop";var tu=({multipleChoice:e,handleMcqTransform:o,handleSelect:t,mcqRefs:a,handleDragEnd:r,onContextMenu:s})=>jsx(Fragment,{children:e.map(n=>n.data.responseType==="classic"?jsx(eu,{multipleChoice:n,handleMcqTransform:o,handleSelect:t,mcqRefs:a,handleDragEnd:i=>r(i,n.id),onContextMenu:s},n.id):jsx(wi,{multipleChoice:n,handleMcqTransform:o,handleSelect:t,mcqRefs:a,onContextMenu:s},n.id))});var au=memo(({trueFalse:e,handleTrueFalseTransform:o,handleSelect:t,trueFalseRefs:a,onContextMenu:r,handleDragEnd:s})=>{let n=useSelector(N=>N.toolbar.selectedTool),i=n==="pen"||n==="eraser",[u,l]=useState(null),[c,d]=useState(false),[m,f]=useState(null),h=useRef(null);useEffect(()=>{let N=h.current;if(N)return a.current.set(e.id,N),()=>{a.current.delete(e.id);}},[e.id]);let x=()=>{u!==null&&d(true);},p=()=>{d(false),l(null);},v=e.data.responseOptions.correctAnswer,g=u===v,b=N=>{c||l(N);},y=()=>g?"\u2713 Correct! Great job! \u{1F389}":"\u2717 Try again!",S=()=>g?{bg:"#dcfce7",text:"#166534"}:{bg:"#fee2e2",text:"#991b1b"},I=70,C=12,L=24,P=60,A=60,U=e.data.feedbackMode==="practice"?48:0,F=12,E=P+(c?A:0),R=2*(I+C),H=E+R+F+U+L;return jsxs(Group,{ref:h,name:"trueFalse-element",draggable:!i,listening:!i,x:e.x,y:e.y,rotation:e.rotation,width:e.width,height:e.height,...i?{}:{onDragEnd:N=>s(N,e.id),onClick:N=>t(e.id),onTap:N=>t(e.id),onContextMenu:N=>{let te=h.current?.getStage()?.getPointerPosition();if(te){let q={x:e.x,y:e.y,width:e.width,height:e.height};if(te.x>=q.x&&te.x<=q.x+q.width&&te.y>=q.y&&te.y<=q.y+q.height){let G=N.evt;r(G,e.id,"trueFalse");}}}},children:[jsx(Rect,{fill:"white",stroke:"#e5e7eb",strokeWidth:2,cornerRadius:12,height:H-20,width:e.width,onTransformEnd:N=>o(e.id,N)}),jsx(Text,{x:L,y:L,text:e.data.question,fontSize:20,fontStyle:"bold",fill:"#111827",width:e.width-L*2,listening:false}),c&&e.data.feedbackMode==="practice"?jsxs(Fragment,{children:[jsx(Rect,{x:L,y:P,width:e.width-L*2,height:A-10,fill:S().bg,cornerRadius:8}),jsx(Text,{x:L,y:P,width:e.width-L*2,height:A-10,text:y(),fontSize:16,fontStyle:"bold",fill:S().text,align:"center",verticalAlign:"middle",listening:false})]}):null,jsx(Group,{children:[{label:"True",value:true},{label:"False",value:false}].map((N,te)=>{let q=v===N.value,G=u===N.value,oe=(e.width-L*3)/2,D=L+te*(oe+L),z=E,X=N.value===true,_=X?"#10b981":"#ef4444",Y="#ffffff",Z="#ffffff",Q="#e5e7eb";return c&&(q?(Z=X?"#f0fdf4":"#fef2f2",Q=X?"#86efac":"#fecaca"):G&&!q&&(Z="#fee2e2",Q="#ef4444")),G&&!c&&(Q="#096B76",Z="#ecfeff"),jsxs(Group,{children:[jsx(Rect,{x:D,y:z,width:oe,height:I+50,fill:Z,stroke:Q,strokeWidth:2,cornerRadius:12,onClick:pe=>{pe.cancelBubble=true,b(N.value);},onTap:pe=>{pe.cancelBubble=true,b(N.value);}}),jsx(Circle,{x:D+oe/2,y:z+40,radius:28,fill:_,listening:false}),X?jsx(Text,{x:D+oe/2-14,y:z+40-14,width:28,height:28,text:"\u2713",fontSize:32,fontStyle:"bold",fill:Y,align:"center",verticalAlign:"middle",listening:false}):jsx(Text,{x:D+oe/2-14,y:z+40-14,width:28,height:28,text:"\u2717",fontSize:28,fontStyle:"bold",fill:Y,align:"center",verticalAlign:"middle",listening:false}),jsx(Text,{x:D,y:z+85,width:oe,height:30,text:N.label,fontSize:18,fontStyle:"bold",fill:"#111827",align:"center",verticalAlign:"middle",listening:false})]},N.label)})}),e.data.feedbackMode==="practice"&&jsxs(Group,{y:E+2*(I+C),children:[jsxs(Group,{onMouseDown:N=>{N.cancelBubble=true,f("check");},onMouseUp:N=>{N.cancelBubble=true,f(null),x();},onMouseLeave:N=>{N.cancelBubble=true,f(null);},onTouchStart:N=>{N.cancelBubble=true,f("check");},onTouchEnd:N=>{N.cancelBubble=true,f(null),x();},scaleX:m==="check"?.95:1,scaleY:m==="check"?.95:1,children:[jsx(Rect,{x:L,width:(e.width-L*2-8)/(c?2:1),height:48,fill:u===null||c?"#9ca3af":"#096B76",cornerRadius:8,onClick:N=>N.cancelBubble=true,onTap:N=>N.cancelBubble=true}),jsx(Text,{x:L,width:(e.width-L*2-8)/(c?2:1),height:48,text:c?"Submitted":"Check Work",fontSize:16,fontStyle:"bold",fill:"white",align:"center",verticalAlign:"middle",listening:false})]}),c&&jsxs(Group,{x:(e.width-L*2)/2+8,onMouseDown:()=>f("reset"),onMouseUp:()=>{f(null),p();},onMouseLeave:()=>f(null),onTouchStart:()=>f("reset"),onTouchEnd:()=>{f(null),p();},scaleX:m==="reset"?.95:1,scaleY:m==="reset"?.95:1,children:[jsx(Rect,{x:L,width:(e.width-L*2-8)/2,height:48,fill:"#ef4444",cornerRadius:8,onClick:N=>N.cancelBubble=true,onTap:N=>N.cancelBubble=true}),jsx(Text,{x:L,width:(e.width-L*2-8)/2,height:48,text:"Reset",fontSize:16,fontStyle:"bold",fill:"white",align:"center",verticalAlign:"middle",listening:false})]})]})]})});au.displayName="TrueFalse";var ou=au;var Sg="#FFFFFF",Ii=({trueFalse:e,onContextMenu:o,handleTrueFalseTransform:t})=>{let a=useDispatch(),r=useSelector(_=>_.toolbar.selectedTool),s=r==="pen"||r==="eraser",[n,i]=useState(false),[u,l]=useState(null),[c,d]=useState(false),[m,f]=useState(false),[h,x]=useState(0),[p,v]=useState(false),g=340,b=100,y=window.innerWidth*.4,S=window.innerHeight*.5,I=y-40,C=S-300,L=20,P=60,A=I,U=C,F=y*.2-40,E=50,R=useRef(null),H=_=>{a(ra({id:e.id,x:_.target.x(),y:_.target.y()}));},N=_=>{let Y=_.target,Z=Y.x(),Q=Y.y(),pe=Math.max(0,Math.min(Z+F,L+A)-Math.max(Z,L)),we=Math.max(0,Math.min(Q+E,P+U)-Math.max(Q,P)),De=pe*we,Me=F*E;i(De/Me>=.5);},te=(_,Y)=>{let Z=Y.target,Q=Z.x(),pe=Z.y(),we=Math.max(0,Math.min(Q+F,L+A)-Math.max(Q,L)),De=Math.max(0,Math.min(pe+E,P+U)-Math.max(pe,P)),Me=we*De,Ue=F*E;if(Me/Ue>=.5)l(_);else return;i(false);},q=()=>{d(true);},G=()=>{d(false),l(null),x(_=>_+1);},oe=e.data.responseOptions.correctAnswer,D=u===oe,z=()=>D?"\u2713 Correct! Great job!":"\u2717 Try again!",X=()=>D?{bg:"#dcfce7",text:"#166534"}:{bg:"#fee2e2",text:"#991b1b"};return jsx(Group,{ref:R,name:"trueFalse-element",width:y,height:S,draggable:!s,listening:!s,...s?{}:{onContextMenu:_=>{_.evt.preventDefault(),o(_.evt,e.id,"trueFalse");}},children:jsxs(Group,{x:g,y:b,rotation:e.rotation,onDragEnd:H,children:[jsx(Rect,{fill:"white",stroke:n?"#4CAF50":"#e5e7eb",strokeWidth:n?4:2,cornerRadius:12,height:c?S:e.data.feedbackMode==="practice"?S-50:S-100,width:y,shadowColor:n?"#4CAF50":"transparent",shadowBlur:n?20:0,shadowOpacity:.5}),jsx(Text,{x:20,y:20,width:y-40,text:e.data.question,fontSize:20,fontStyle:"bold",fill:"#111827",align:"center",verticalAlign:"middle"}),jsx(Rect,{x:20,y:60,width:I,height:C,fill:"transparent",stroke:n?"#4CAF50":"#075560",strokeWidth:3,dash:[10,10],cornerRadius:8}),c&&jsxs(Fragment,{children:[jsx(Rect,{x:20,y:60,width:I,height:60,fill:X().bg,cornerRadius:8}),jsx(Text,{x:20,y:60,width:I,height:60,text:z(),fontSize:18,fontStyle:"bold",fill:X().text,align:"center",verticalAlign:"middle"})]}),u===null&&!c&&jsx(Text,{x:20,y:60,width:I,height:C-60,text:"Drop Your Answer Here",fontSize:28,fontStyle:"bold",fill:"#075560",align:"center",verticalAlign:"middle"}),e.data.feedbackMode==="practice"?jsxs(Group,{x:20,y:S-100,children:[jsxs(Group,{onMouseDown:()=>{u!==null&&(f(true),q());},onMouseUp:()=>f(false),onMouseLeave:()=>f(false),onTouchStart:()=>{u!==null&&(f(true),q());},onTouchEnd:()=>f(false),scaleX:m?.95:1,scaleY:m?.95:1,children:[jsx(Rect,{fill:u===null?"#9ca3af":"#075560",stroke:"#e5e7eb",strokeWidth:2,cornerRadius:8,height:40,width:I}),jsx(Text,{text:"Check Work",fontSize:18,fontStyle:"bold",fill:"white",width:I,height:40,align:"center",verticalAlign:"middle",listening:false})]}),c&&jsxs(Group,{y:50,onMouseDown:G,onTouchStart:G,children:[jsx(Rect,{fill:"#dc2626",stroke:"#e5e7eb",strokeWidth:2,cornerRadius:8,height:40,width:I}),jsx(Text,{text:"Reset",fontSize:18,fontStyle:"bold",fill:"white",width:I,height:40,align:"center",verticalAlign:"middle",listening:false})]})]}):null,[{value:true,label:"True"},{value:false,label:"False"}].map((_,Y)=>{let Z=window.innerWidth*.2,Q=50,pe=10,we=u===_.value,De=oe===_.value,Me=c&&we,Ue="transparent";return Me?Ue=De?"#4CAF50":"#ef4444":we&&(Ue="#4CAF50"),jsxs(Group,{x:16+Y*(Z+pe),y:b+S-300,draggable:!c,onDragMove:N,onDragEnd:re=>te(_.value,re),opacity:c&&!we?.5:1,children:[jsx(Rect,{width:Z-40,height:Q,fill:"#075560",stroke:Ue,strokeWidth:4,cornerRadius:8}),jsx(Text,{width:Z-40,height:Q,text:_.label,fontSize:18,fontStyle:"bold",fill:Sg,align:"center",verticalAlign:"middle",listening:false})]},`${_.value}-${h}`)})]})})};Ii.displayName="TrueFalseDragAndDrop";var ru=({trueFalses:e,handleTrueFalseTransform:o,handleSelect:t,trueFalseRefs:a,handleDragEnd:r,onContextMenu:s})=>jsx(Fragment,{children:e.map(n=>n.data.responseType==="classic"?jsx(ou,{trueFalse:n,handleTrueFalseTransform:o,handleSelect:t,trueFalseRefs:a,onContextMenu:s,handleDragEnd:r},n.id):jsx(Ii,{trueFalse:n,handleTrueFalseTransform:o,handleSelect:t,trueFalseRefs:a,onContextMenu:s},n.id))});var da=new WeakMap,fo=new WeakMap,or={current:[]},ki=false,ar=0,tr=new Set,gs=new Map;function su(e){let o=Array.from(e).sort((t,a)=>t instanceof Ft&&t.options.deps.includes(a)?1:a instanceof Ft&&a.options.deps.includes(t)?-1:0);for(let t of o){if(or.current.includes(t))continue;or.current.push(t),t.recompute();let a=fo.get(t);if(a)for(let r of a){let s=da.get(r);s&&su(s);}}}function kg(e){let o={prevVal:e.prevState,currentVal:e.state};for(let t of e.listeners)t(o);}function Mg(e){let o={prevVal:e.prevState,currentVal:e.state};for(let t of e.listeners)t(o);}function xs(e){if(ar>0&&!gs.has(e)&&gs.set(e,e.prevState),tr.add(e),!(ar>0)&&!ki)try{for(ki=!0;tr.size>0;){let o=Array.from(tr);tr.clear();for(let t of o){let a=gs.get(t)??t.prevState;t.prevState=a,kg(t);}for(let t of o){let a=da.get(t);a&&(or.current.push(t),su(a));}for(let t of o){let a=da.get(t);if(a)for(let r of a)Mg(r);}}}finally{ki=false,or.current=[],gs.clear();}}function ft(e){ar++;try{e();}finally{if(ar--,ar===0){let o=tr.values().next().value;o&&xs(o);}}}function nu(e){return typeof e=="function"}var zt=class{constructor(o,t){this.listeners=new Set,this.subscribe=a=>{var r,s;this.listeners.add(a);let n=(s=(r=this.options)==null?void 0:r.onSubscribe)==null?void 0:s.call(r,a,this);return ()=>{this.listeners.delete(a),n?.();}},this.prevState=o,this.state=o,this.options=t;}setState(o){var t,a,r;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(o):nu(o)?this.state=o(this.prevState):this.state=o,(r=(a=this.options)==null?void 0:a.onUpdate)==null||r.call(a),xs(this);}};var Ft=class e{constructor(o){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{let t=this.options.deps.length,a=new Array(t),r=new Array(t);for(let s=0;s<t;s++){let n=this.options.deps[s];a[s]=n.prevState,r[s]=n.state;}return this.lastSeenDepValues=r,{prevDepVals:a,currDepVals:r,prevVal:this.prevState??void 0}},this.recompute=()=>{var t,a;this.prevState=this.state;let r=this.getDepVals();this.state=this.options.fn(r),(a=(t=this.options).onUpdate)==null||a.call(t);},this.checkIfRecalculationNeededDeeply=()=>{for(let s of this.options.deps)s instanceof e&&s.checkIfRecalculationNeededDeeply();let t=false,a=this.lastSeenDepValues,{currDepVals:r}=this.getDepVals();for(let s=0;s<r.length;s++)if(r[s]!==a[s]){t=true;break}t&&this.recompute();},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(let t of this._subscriptions)t();}),this.subscribe=t=>{var a,r;this.listeners.add(t);let s=(r=(a=this.options).onSubscribe)==null?void 0:r.call(a,t,this);return ()=>{this.listeners.delete(t),s?.();}},this.options=o,this.state=o.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals});}registerOnGraph(o=this.options.deps){for(let t of o)if(t instanceof e)t.registerOnGraph(),this.registerOnGraph(t.options.deps);else if(t instanceof zt){let a=da.get(t);a||(a=new Set,da.set(t,a)),a.add(this);let r=fo.get(this);r||(r=new Set,fo.set(this,r)),r.add(t);}}unregisterFromGraph(o=this.options.deps){for(let t of o)if(t instanceof e)this.unregisterFromGraph(t.options.deps);else if(t instanceof zt){let a=da.get(t);a&&a.delete(this);let r=fo.get(this);r&&r.delete(t);}}};function Tg(e){return typeof e=="function"}function Mi(e,...o){return Tg(e)?e(...o):e}function iu(e){return e||(typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"")}var ua,rt,et,rr,ca,Ba,$t,mo,sr,bs,nr,po,Oa=class{constructor({pluginId:o,debug:t=false,enabled:a=true,reconnectEveryMs:r=1e3}){Te(this,ua,true);Te(this,rt);Te(this,et);Te(this,rr);Te(this,ca);Te(this,Ba);Te(this,$t);Te(this,mo);Te(this,sr,0);Te(this,bs,5);Te(this,nr,()=>{this.debugLog("Connected to event bus"),ke(this,Ba,true),this.debugLog("Emitting queued events",K(this,ca)),K(this,ca).forEach(o=>this.emitEventToBus(o)),ke(this,ca,[]),this.stopConnectLoop(),K(this,et).call(this).removeEventListener("tanstack-connect-success",K(this,nr));});Te(this,po,()=>{if(K(this,et).call(this).addEventListener("tanstack-connect-success",K(this,nr)),K(this,sr)<K(this,bs)){Vl(this,sr)._++,this.dispatchCustomEvent("tanstack-connect",{});return}K(this,et).call(this).removeEventListener("tanstack-connect",K(this,po)),this.debugLog("Max retries reached, giving up on connection"),this.stopConnectLoop();});ke(this,rt,o),ke(this,ua,a),ke(this,et,this.getGlobalTarget),ke(this,rr,t),this.debugLog(" Initializing event subscription for plugin",K(this,rt)),ke(this,ca,[]),ke(this,Ba,false),ke(this,$t,null),ke(this,mo,r);}startConnectLoop(){K(this,$t)!==null||K(this,Ba)||(this.debugLog(`Starting connect loop (every ${K(this,mo)}ms)`),ke(this,$t,setInterval(K(this,po),K(this,mo))));}stopConnectLoop(){K(this,$t)!==null&&(clearInterval(K(this,$t)),ke(this,$t,null),this.debugLog("Stopped connect loop"));}debugLog(...o){K(this,rr)&&console.log(`\u{1F334} [tanstack-devtools:${K(this,rt)}-plugin]`,...o);}getGlobalTarget(){if(typeof globalThis<"u"&&globalThis.__TANSTACK_EVENT_TARGET__)return this.debugLog("Using global event target"),globalThis.__TANSTACK_EVENT_TARGET__;if(typeof window<"u"&&typeof window.addEventListener<"u")return this.debugLog("Using window as event target"),window;let o=typeof EventTarget<"u"?new EventTarget:void 0;return typeof o>"u"||typeof o.addEventListener>"u"?(this.debugLog("No event mechanism available, running in non-web environment"),{addEventListener:()=>{},removeEventListener:()=>{},dispatchEvent:()=>false}):(this.debugLog("Using new EventTarget as fallback"),o)}getPluginId(){return K(this,rt)}dispatchCustomEventShim(o,t){try{let a=new Event(o,{detail:t});K(this,et).call(this).dispatchEvent(a);}catch{this.debugLog("Failed to dispatch shim event");}}dispatchCustomEvent(o,t){try{K(this,et).call(this).dispatchEvent(new CustomEvent(o,{detail:t}));}catch{this.dispatchCustomEventShim(o,t);}}emitEventToBus(o){this.debugLog("Emitting event to client bus",o),this.dispatchCustomEvent("tanstack-dispatch-event",o);}emit(o,t){if(!K(this,ua)){this.debugLog("Event bus client is disabled, not emitting event",o,t);return}if(!K(this,Ba)){this.debugLog("Bus not available, will be pushed as soon as connected"),K(this,ca).push({type:`${K(this,rt)}:${o}`,payload:t,pluginId:K(this,rt)}),typeof CustomEvent<"u"&&(K(this,po).call(this),this.startConnectLoop());return}return this.emitEventToBus({type:`${K(this,rt)}:${o}`,payload:t,pluginId:K(this,rt)})}on(o,t){let a=`${K(this,rt)}:${o}`;if(!K(this,ua))return this.debugLog("Event bus client is disabled, not registering event",a),()=>{};let r=s=>{this.debugLog("Received event from bus",s.detail),t(s.detail);};return K(this,et).call(this).addEventListener(a,r),this.debugLog("Registered event to bus",a),()=>{K(this,et).call(this).removeEventListener(a,r);}}onAll(o){if(!K(this,ua))return this.debugLog("Event bus client is disabled, not registering event"),()=>{};let t=a=>{let r=a.detail;o(r);};return K(this,et).call(this).addEventListener("tanstack-devtools-global",t),()=>K(this,et).call(this).removeEventListener("tanstack-devtools-global",t)}onAllPluginEvents(o){if(!K(this,ua))return this.debugLog("Event bus client is disabled, not registering event"),()=>{};let t=a=>{let r=a.detail;K(this,rt)&&r.pluginId!==K(this,rt)||o(r);};return K(this,et).call(this).addEventListener("tanstack-devtools-global",t),()=>K(this,et).call(this).removeEventListener("tanstack-devtools-global",t)}};ua=new WeakMap,rt=new WeakMap,et=new WeakMap,rr=new WeakMap,ca=new WeakMap,Ba=new WeakMap,$t=new WeakMap,mo=new WeakMap,sr=new WeakMap,bs=new WeakMap,nr=new WeakMap,po=new WeakMap;var Ti=class extends Oa{constructor(o){super({pluginId:"pacer",debug:o?.debug});}},lu=(e,o)=>{Ai.emit(e,o);},Ai=new Ti;function du(){return {executionCount:0,isPending:false,lastArgs:void 0,lastExecutionTime:0,nextExecutionTime:0,status:"idle",maybeExecuteCount:0}}var Ag={enabled:true,leading:true,trailing:true,wait:0},fa,mt,Na,Va,qa,ho,vs=class{constructor(o,t){Te(this,fa);Te(this,mt);Te(this,Na);Te(this,Va);Te(this,qa);Te(this,ho);this.fn=o,this.store=new zt(du()),this.setOptions=a=>{this.options={...this.options,...a},K(this,Na).call(this)||this.cancel();},ke(this,mt,a=>{this.store.setState(r=>{let s={...r,...a},{isPending:n}=s;return {...s,status:K(this,Na).call(this)?n?"pending":"idle":"disabled"}}),lu("Throttler",this);}),ke(this,Na,()=>!!Mi(this.options.enabled,this)),ke(this,Va,()=>Mi(this.options.wait,this)),this.maybeExecute=(...a)=>{K(this,mt).call(this,{maybeExecuteCount:this.store.state.maybeExecuteCount+1});let r=Date.now(),s=r-this.store.state.lastExecutionTime,n=K(this,Va).call(this);if(this.options.leading&&s>=n)K(this,qa).call(this,...a);else if(K(this,mt).call(this,{lastArgs:a}),!K(this,fa)&&this.options.trailing){let i=this.store.state.lastExecutionTime?r-this.store.state.lastExecutionTime:0,u=n-i;K(this,mt).call(this,{isPending:true}),ke(this,fa,setTimeout(()=>{let{lastArgs:l}=this.store.state;l!==void 0&&K(this,qa).call(this,...l);},u));}},ke(this,qa,(...a)=>{if(!K(this,Na).call(this))return;this.fn(...a);let r=Date.now(),s=r+K(this,Va).call(this);K(this,ho).call(this),K(this,mt).call(this,{executionCount:this.store.state.executionCount+1,lastExecutionTime:r,nextExecutionTime:s,isPending:false,lastArgs:void 0}),this.options.onExecute?.(a,this),setTimeout(()=>{this.store.state.isPending||K(this,mt).call(this,{nextExecutionTime:void 0});},K(this,Va).call(this));}),this.flush=()=>{this.store.state.isPending&&this.store.state.lastArgs&&K(this,qa).call(this,...this.store.state.lastArgs);},ke(this,ho,()=>{K(this,fa)&&(clearTimeout(K(this,fa)),ke(this,fa,void 0));}),this.cancel=()=>{K(this,ho).call(this),K(this,mt).call(this,{lastArgs:void 0,isPending:false});},this.reset=()=>{K(this,mt).call(this,du());},this.key=iu(t.key),this.options={...Ag,...t},K(this,mt).call(this,this.options.initialState??{}),Ai.on("d-Throttler",a=>{a.payload.key===this.key&&(K(this,mt).call(this,a.payload.store.state),this.setOptions(a.payload.options));});}};fa=new WeakMap,mt=new WeakMap,Na=new WeakMap,Va=new WeakMap,qa=new WeakMap,ho=new WeakMap;function Pi(e,o){return new vs(e,o).maybeExecute}function ma(e,o){return typeof e=="function"?e(o):e}function pa(e,o){return Ss(o).reduce((a,r)=>{if(a===null)return null;if(typeof a<"u")return a[r]},e)}function go(e,o,t){let a=Ss(o);function r(s){if(!a.length)return ma(t,s);let n=a.shift();if(typeof n=="string"||typeof n=="number"&&!Array.isArray(s))return typeof s=="object"?(s===null&&(s={}),{...s,[n]:r(s[n])}):{[n]:r()};if(Array.isArray(s)&&typeof n=="number"){let i=s.slice(0,n);return [...i.length?i:new Array(n),r(s[n]),...s.slice(n+1)]}return [...new Array(n),r()]}return r(e)}function Ri(e,o){let t=Ss(o);function a(r){if(!r)return;if(t.length===1){let n=t[0];if(Array.isArray(r)&&typeof n=="number")return r.filter((l,c)=>c!==n);let{[n]:i,...u}=r;return u}let s=t.shift();if(typeof s=="string"&&typeof r=="object")return {...r,[s]:a(r[s])};if(typeof s=="number"&&Array.isArray(r)){if(s>=r.length)return r;let n=r.slice(0,s);return [...n.length?n:new Array(s),a(r[s]),...r.slice(s+1)]}throw new Error("It seems we have created an infinite loop in deleteBy. ")}return a(e)}var Pg=/^(\d+)$/gm,Dg=/\.(\d+)(?=\.)/gm,Rg=/^(\d+)\./gm,Fg=/\.(\d+$)/gm,Eg=/\.{2,}/gm,Di="__int__",ys=`${Di}$1`;function Ss(e){if(Array.isArray(e))return [...e];if(typeof e!="string")throw new Error("Path must be a string.");return e.replace(/(^\[)|]/gm,"").replace(/\[/g,".").replace(Pg,ys).replace(Dg,`.${ys}.`).replace(Rg,`${ys}.`).replace(Fg,`.${ys}`).replace(Eg,".").split(".").map(o=>{if(o.startsWith(Di)){let t=o.substring(Di.length),a=parseInt(t,10);return String(a)===t?a:t}return o})}function Fi(e){return !(Array.isArray(e)&&e.length===0)}function xo(e,o){let t=a=>a.validators.filter(Boolean).map(r=>({cause:r.cause,validate:r.fn}));return o.validationLogic({form:o.form,validators:o.validators,event:{type:e,async:false},runValidation:t})}function bo(e,o){let{asyncDebounceMs:t}=o,{onBlurAsyncDebounceMs:a,onChangeAsyncDebounceMs:r,onDynamicAsyncDebounceMs:s}=o.validators||{},n=t??0,i=u=>u.validators.filter(Boolean).map(l=>{let c=l?.cause||e,d=n;switch(c){case "change":d=r??n;break;case "blur":d=a??n;break;case "dynamic":d=s??n;break;case "submit":d=0;break}return e==="submit"&&(d=0),{cause:c,validate:l.fn,debounceMs:d}});return o.validationLogic({form:o.form,validators:o.validators,event:{type:e,async:true},runValidation:i})}var ir=e=>!!e&&typeof e=="object"&&"fields"in e;function ha(e,o){if(Object.is(e,o))return true;if(typeof e!="object"||e===null||typeof o!="object"||o===null)return false;if(e instanceof Date&&o instanceof Date)return e.getTime()===o.getTime();if(e instanceof Map&&o instanceof Map){if(e.size!==o.size)return false;for(let[r,s]of e)if(!o.has(r)||!Object.is(s,o.get(r)))return false;return true}if(e instanceof Set&&o instanceof Set){if(e.size!==o.size)return false;for(let r of e)if(!o.has(r))return false;return true}let t=Object.keys(e),a=Object.keys(o);if(t.length!==a.length)return false;for(let r of t)if(!a.includes(r)||!ha(e[r],o[r]))return false;return true}var Is=({newFormValidatorError:e,isPreviousErrorFromFormValidator:o,previousErrorValue:t})=>e?{newErrorValue:e,newSource:"form"}:o?{newErrorValue:void 0,newSource:void 0}:t?{newErrorValue:t,newSource:"field"}:{newErrorValue:void 0,newSource:void 0},Cs=({formLevelError:e,fieldLevelError:o})=>o?{newErrorValue:o,newSource:"field"}:e?{newErrorValue:e,newSource:"form"}:{newErrorValue:void 0,newSource:void 0};function Ge(e,o){return e==null?o:{...e,...o}}var Ua=256,Ls=[],ws;for(;Ua--;)Ls[Ua]=(Ua+256).toString(16).substring(1);function Ei(){let e=0,o,t="";if(!ws||Ua+16>256){for(ws=new Array(256),e=256;e--;)ws[e]=256*Math.random()|0;e=0,Ua=0;}for(;e<16;e++)o=ws[Ua+e],e===6?t+=Ls[o&15|64]:e===8?t+=Ls[o&63|128]:t+=Ls[o],e&1&&e>1&&e<11&&(t+="-");return Ua++,t}var ga=e=>{if(!e.validators)return e.runValidation({validators:[],form:e.form});let o=e.event.async,t=o?void 0:{fn:e.validators.onMount,cause:"mount"},a={fn:o?e.validators.onChangeAsync:e.validators.onChange,cause:"change"},r={fn:o?e.validators.onBlurAsync:e.validators.onBlur,cause:"blur"},s={fn:o?e.validators.onSubmitAsync:e.validators.onSubmit,cause:"submit"},n=o?void 0:{fn:()=>{},cause:"server"};switch(e.event.type){case "mount":return e.runValidation({validators:[t],form:e.form});case "submit":return e.runValidation({validators:[a,r,s,n],form:e.form});case "server":return e.runValidation({validators:[],form:e.form});case "blur":return e.runValidation({validators:[r,n],form:e.form});case "change":return e.runValidation({validators:[a,n],form:e.form});default:throw new Error(`Unknown validation event type: ${e.event.type}`)}};function Bg(e,o){let t=new Map;for(let a of e){let r=a.path??[],s=o,n="";for(let i=0;i<r.length;i++){let u=r[i];if(u===void 0)continue;let l=typeof u=="object"?u.key:u,c=Number(l);Array.isArray(s)&&!Number.isNaN(c)?n+=`[${c}]`:n+=(i>0?".":"")+String(l),typeof s=="object"&&s!==null?s=s[l]:s=void 0;}t.set(n,(t.get(n)??[]).concat(a));}return Object.fromEntries(t)}var uu=(e,o)=>{let t=Bg(e,o);return {form:t,fields:t}},xa={validate({value:e,validationSource:o},t){let a=t["~standard"].validate(e);if(a instanceof Promise)throw new Error("async function passed to sync validator");if(a.issues)return o==="field"?a.issues:uu(a.issues,e)},async validateAsync({value:e,validationSource:o},t){let a=await t["~standard"].validate(e);if(a.issues)return o==="field"?a.issues:uu(a.issues,e)}},ks=e=>!!e&&"~standard"in e;var vo={isValidating:false,isTouched:false,isBlurred:false,isDirty:false,isPristine:true,isValid:true,isDefaultValue:true,errors:[],errorMap:{},errorSourceMap:{}};function lr(e){function o(d,m,f,h){let x=a(d,m,f,h);({insert:()=>i(x,d,m),remove:()=>u(x),swap:()=>h!==void 0&&c(x,d,m,h),move:()=>h!==void 0&&l(x,d,m,h)})[f]();}function t(d,m){return `${d}[${m}]`}function a(d,m,f,h){let x=[t(d,m)];if(f==="swap")x.push(t(d,h));else if(f==="move"){let[p,v]=[Math.min(m,h),Math.max(m,h)];for(let g=p;g<=v;g++)x.push(t(d,g));}else {let p=e.getFieldValue(d),v=Array.isArray(p)?p.length:0;for(let g=m+1;g<v;g++)x.push(t(d,g));}return Object.keys(e.fieldInfo).filter(p=>x.some(v=>p.startsWith(v)))}function r(d,m){return d.replace(/\[(\d+)\]/,(f,h)=>{let x=parseInt(h,10);return `[${m==="up"?x+1:Math.max(0,x-1)}]`})}function s(d,m){(m==="up"?d:[...d].reverse()).forEach(h=>{let x=r(h.toString(),m),p=e.getFieldMeta(x);p?e.setFieldMeta(h,p):e.setFieldMeta(h,n());});}let n=()=>vo,i=(d,m,f)=>{s(d,"down"),d.forEach(h=>{h.toString().startsWith(t(m,f))&&e.setFieldMeta(h,n());});},u=d=>{s(d,"up");},l=(d,m,f,h)=>{let x=new Map(Object.keys(e.fieldInfo).filter(p=>p.startsWith(t(m,f))).map(p=>[p,e.getFieldMeta(p)]));s(d,f<h?"up":"down"),Object.keys(e.fieldInfo).filter(p=>p.startsWith(t(m,h))).forEach(p=>{let v=p.replace(t(m,h),t(m,f)),g=x.get(v);g&&e.setFieldMeta(p,g);});},c=(d,m,f,h)=>{d.forEach(x=>{if(!x.toString().startsWith(t(m,f)))return;let p=x.toString().replace(t(m,f),t(m,h)),[v,g]=[e.getFieldMeta(x),e.getFieldMeta(p)];v&&e.setFieldMeta(p,v),g&&e.setFieldMeta(x,g);});};return {handleArrayFieldMetaShift:o}}var Bi=class extends Oa{constructor(){super({pluginId:"form-devtools"});}},pt=new Bi;function Oi(e){return {values:e.values??{},errorMap:e.errorMap??{},fieldMetaBase:e.fieldMetaBase??{},isSubmitted:e.isSubmitted??false,isSubmitting:e.isSubmitting??false,isValidating:e.isValidating??false,submissionAttempts:e.submissionAttempts??0,isSubmitSuccessful:e.isSubmitSuccessful??false,validationMetaMap:e.validationMetaMap??{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}}}var ur=class{constructor(o){this.options={},this.fieldInfo={},this.prevTransformArray=[],this.mount=()=>{let a=this.fieldMetaDerived.mount(),r=this.store.mount(),s=()=>{a(),r(),pt.emit("form-unmounted",{id:this._formId});};this.options.listeners?.onMount?.({formApi:this});let{onMount:n}=this.options.validators||{};return pt.emit("form-api",{id:this._formId,state:this.store.state,options:this.options}),n&&this.validateSync("mount"),s},this.update=a=>{if(!a)return;let r=this.options;this.options=a;let s=!!a.transform?.deps?.some((u,l)=>u!==this.prevTransformArray[l]),n=a.defaultValues&&!ha(a.defaultValues,r.defaultValues)&&!this.state.isTouched,i=!ha(a.defaultState,r.defaultState)&&!this.state.isTouched;!n&&!i&&!s||(ft(()=>{this.baseStore.setState(()=>Oi(Object.assign({},this.state,i?a.defaultState:{},n?{values:a.defaultValues}:{},s?{_force_re_eval:!this.state._force_re_eval}:{})));}),pt.emit("form-api",{id:this._formId,state:this.store.state,options:this.options}));},this.reset=(a,r)=>{let{fieldMeta:s}=this.state,n=this.resetFieldMeta(s);a&&!r?.keepDefaultValues&&(this.options={...this.options,defaultValues:a}),this.baseStore.setState(()=>Oi({...this.options.defaultState,values:a??this.options.defaultValues??this.options.defaultState?.values,fieldMetaBase:n}));},this.validateAllFields=async a=>{let r=[];return ft(()=>{Object.values(this.fieldInfo).forEach(n=>{if(!n.instance)return;let i=n.instance;r.push(Promise.resolve().then(()=>i.validate(a,{skipFormValidation:!0}))),n.instance.state.meta.isTouched||n.instance.setMeta(u=>({...u,isTouched:!0}));});}),(await Promise.all(r)).flat()},this.validateArrayFieldsStartingFrom=async(a,r,s)=>{let n=this.getFieldValue(a),i=Array.isArray(n)?Math.max(n.length-1,0):null,u=[`${a}[${r}]`];for(let m=r+1;m<=(i??0);m++)u.push(`${a}[${m}]`);let l=Object.keys(this.fieldInfo).filter(m=>u.some(f=>m.startsWith(f))),c=[];return ft(()=>{l.forEach(m=>{c.push(Promise.resolve().then(()=>this.validateField(m,s)));});}),(await Promise.all(c)).flat()},this.validateField=(a,r)=>{let s=this.fieldInfo[a]?.instance;return s?(s.state.meta.isTouched||s.setMeta(n=>({...n,isTouched:true})),s.validate(r)):[]},this.validateSync=a=>{let r=xo(a,{...this.options,form:this,validationLogic:this.options.validationLogic||ga}),s=false,n={};return ft(()=>{for(let l of r){if(!l.validate)continue;let c=this.runValidator({validate:l.validate,value:{value:this.state.values,formApi:this,validationSource:"form"},type:"validate"}),{formError:d,fieldErrors:m}=Ms(c),f=dr(l.cause);for(let h of Object.keys(this.state.fieldMeta)){if(this.baseStore.state.fieldMetaBase[h]===void 0)continue;let x=this.getFieldMeta(h);if(!x)continue;let{errorMap:p,errorSourceMap:v}=x,g=m?.[h],{newErrorValue:b,newSource:y}=Is({newFormValidatorError:g,isPreviousErrorFromFormValidator:v?.[f]==="form",previousErrorValue:p?.[f]});y==="form"&&(n[h]={...n[h],[f]:g}),p?.[f]!==b&&this.setFieldMeta(h,S=>({...S,errorMap:{...S.errorMap,[f]:b},errorSourceMap:{...S.errorSourceMap,[f]:y}}));}this.state.errorMap?.[f]!==d&&this.baseStore.setState(h=>({...h,errorMap:{...h.errorMap,[f]:d}})),(d||m)&&(s=!0);}let i=dr("submit");this.state.errorMap?.[i]&&a!=="submit"&&!s&&this.baseStore.setState(l=>({...l,errorMap:{...l.errorMap,[i]:void 0}}));let u=dr("server");this.state.errorMap?.[u]&&a!=="server"&&!s&&this.baseStore.setState(l=>({...l,errorMap:{...l.errorMap,[u]:void 0}}));}),{hasErrored:s,fieldsErrorMap:n}},this.validateAsync=async a=>{let r=bo(a,{...this.options,form:this,validationLogic:this.options.validationLogic||ga});this.state.isFormValidating||this.baseStore.setState(l=>({...l,isFormValidating:true}));let s=[],n;for(let l of r){if(!l.validate)continue;let c=dr(l.cause);this.state.validationMetaMap[c]?.lastAbortController.abort();let m=new AbortController;this.state.validationMetaMap[c]={lastAbortController:m},s.push(new Promise(async f=>{let h;try{h=await new Promise((g,b)=>{setTimeout(async()=>{if(m.signal.aborted)return g(void 0);try{g(await this.runValidator({validate:l.validate,value:{value:this.state.values,formApi:this,validationSource:"form",signal:m.signal},type:"validateAsync"}));}catch(y){b(y);}},l.debounceMs);});}catch(g){h=g;}let{formError:x,fieldErrors:p}=Ms(h);p&&(n=n?{...n,...p}:p);let v=dr(l.cause);for(let g of Object.keys(this.state.fieldMeta)){if(this.baseStore.state.fieldMetaBase[g]===void 0)continue;let b=this.getFieldMeta(g);if(!b)continue;let{errorMap:y,errorSourceMap:S}=b,I=n?.[g],{newErrorValue:C,newSource:L}=Is({newFormValidatorError:I,isPreviousErrorFromFormValidator:S?.[v]==="form",previousErrorValue:y?.[v]});y?.[v]!==C&&this.setFieldMeta(g,P=>({...P,errorMap:{...P.errorMap,[v]:C},errorSourceMap:{...P.errorSourceMap,[v]:L}}));}this.baseStore.setState(g=>({...g,errorMap:{...g.errorMap,[v]:x}})),f(n?{fieldErrors:n,errorMapKey:v}:void 0);}));}let i=[],u={};if(s.length){i=await Promise.all(s);for(let l of i)if(l?.fieldErrors){let{errorMapKey:c}=l;for(let[d,m]of Object.entries(l.fieldErrors)){let h={...u[d]||{},[c]:m};u[d]=h;}}}return this.baseStore.setState(l=>({...l,isFormValidating:false})),u},this.validate=a=>{let{hasErrored:r,fieldsErrorMap:s}=this.validateSync(a);return r&&!this.options.asyncAlways?s:this.validateAsync(a)},this.getFieldValue=a=>pa(this.state.values,a),this.getFieldMeta=a=>this.state.fieldMeta[a],this.getFieldInfo=a=>{var r;return (r=this.fieldInfo)[a]||(r[a]={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}})},this.setFieldMeta=(a,r)=>{this.baseStore.setState(s=>({...s,fieldMetaBase:{...s.fieldMetaBase,[a]:ma(r,s.fieldMetaBase[a])}}));},this.resetFieldMeta=a=>Object.keys(a).reduce((r,s)=>{let n=s;return r[n]=vo,r},{}),this.setFieldValue=(a,r,s)=>{let n=s?.dontUpdateMeta??false,i=s?.dontRunListeners??false,u=s?.dontValidate??false;ft(()=>{n||this.setFieldMeta(a,l=>({...l,isTouched:!0,isDirty:!0,errorMap:{...l?.errorMap,onMount:void 0}})),this.baseStore.setState(l=>({...l,values:go(l.values,a,r)}));}),i||this.getFieldInfo(a).instance?.triggerOnChangeListener(),u||this.validateField(a,"change");},this.deleteField=a=>{let s=[...Object.keys(this.fieldInfo).filter(n=>{let i=a.toString();return n!==i&&n.startsWith(i)}),a];this.baseStore.setState(n=>{let i={...n};return s.forEach(u=>{i.values=Ri(i.values,u),delete this.fieldInfo[u],delete i.fieldMetaBase[u];}),i});},this.pushFieldValue=(a,r,s)=>{this.setFieldValue(a,n=>[...Array.isArray(n)?n:[],r],s);},this.insertFieldValue=async(a,r,s,n)=>{this.setFieldValue(a,u=>[...u.slice(0,r),s,...u.slice(r)],Ge(n,{dontValidate:true}));let i=n?.dontValidate??false;i||await this.validateField(a,"change"),lr(this).handleArrayFieldMetaShift(a,r,"insert"),i||await this.validateArrayFieldsStartingFrom(a,r,"change");},this.replaceFieldValue=async(a,r,s,n)=>{this.setFieldValue(a,u=>u.map((l,c)=>c===r?s:l),Ge(n,{dontValidate:true})),(n?.dontValidate??false)||(await this.validateField(a,"change"),await this.validateArrayFieldsStartingFrom(a,r,"change"));},this.removeFieldValue=async(a,r,s)=>{let n=this.getFieldValue(a),i=Array.isArray(n)?Math.max(n.length-1,0):null;if(this.setFieldValue(a,l=>l.filter((c,d)=>d!==r),Ge(s,{dontValidate:true})),lr(this).handleArrayFieldMetaShift(a,r,"remove"),i!==null){let l=`${a}[${i}]`;this.deleteField(l);}(s?.dontValidate??false)||(await this.validateField(a,"change"),await this.validateArrayFieldsStartingFrom(a,r,"change"));},this.swapFieldValues=(a,r,s,n)=>{this.setFieldValue(a,u=>{let l=u[r],c=u[s];return go(go(u,`${r}`,c),`${s}`,l)},Ge(n,{dontValidate:true})),lr(this).handleArrayFieldMetaShift(a,r,"swap",s),(n?.dontValidate??false)||(this.validateField(a,"change"),this.validateField(`${a}[${r}]`,"change"),this.validateField(`${a}[${s}]`,"change"));},this.moveFieldValues=(a,r,s,n)=>{this.setFieldValue(a,u=>{let l=[...u];return l.splice(s,0,l.splice(r,1)[0]),l},Ge(n,{dontValidate:true})),lr(this).handleArrayFieldMetaShift(a,r,"move",s),(n?.dontValidate??false)||(this.validateField(a,"change"),this.validateField(`${a}[${r}]`,"change"),this.validateField(`${a}[${s}]`,"change"));},this.clearFieldValues=(a,r)=>{let s=this.getFieldValue(a),n=Array.isArray(s)?Math.max(s.length-1,0):null;if(this.setFieldValue(a,[],Ge(r,{dontValidate:true})),n!==null)for(let u=0;u<=n;u++){let l=`${a}[${u}]`;this.deleteField(l);}(r?.dontValidate??false)||this.validateField(a,"change");},this.resetField=a=>{this.baseStore.setState(r=>({...r,fieldMetaBase:{...r.fieldMetaBase,[a]:vo},values:this.options.defaultValues?go(r.values,a,pa(this.options.defaultValues,a)):r.values}));},this.getAllErrors=()=>({form:{errors:this.state.errors,errorMap:this.state.errorMap},fields:Object.entries(this.state.fieldMeta).reduce((a,[r,s])=>(Object.keys(s).length&&s.errors.length&&(a[r]={errors:s.errors,errorMap:s.errorMap}),a),{})}),this.parseValuesWithSchema=a=>xa.validate({value:this.state.values,validationSource:"form"},a),this.parseValuesWithSchemaAsync=a=>xa.validateAsync({value:this.state.values,validationSource:"form"},a),this.timeoutIds={validations:{},listeners:{},formListeners:{}},this._formId=o?.formId??Ei(),this._devtoolsSubmissionOverride=false,this.baseStore=new zt(Oi({...o?.defaultState,values:o?.defaultValues??o?.defaultState?.values})),this.fieldMetaDerived=new Ft({deps:[this.baseStore],fn:({prevDepVals:a,currDepVals:r,prevVal:s})=>{let n=s,i=a?.[0],u=r[0],l=0,c={};for(let d of Object.keys(u.fieldMetaBase)){let m=u.fieldMetaBase[d],f=i?.fieldMetaBase[d],h=n?.[d],x=pa(u.values,d),p=h?.errors;if(!f||m.errorMap!==f.errorMap){p=Object.values(m.errorMap??{}).filter(S=>S!==void 0);let y=this.getFieldInfo(d)?.instance;y&&!y.options.disableErrorFlat&&(p=p?.flat(1));}let v=!Fi(p??[]),g=!m.isDirty,b=ha(x,pa(this.options.defaultValues,d))||ha(x,this.getFieldInfo(d)?.instance?.options.defaultValue);if(h&&h.isPristine===g&&h.isValid===v&&h.isDefaultValue===b&&h.errors===p&&m===f){c[d]=h,l++;continue}c[d]={...m,errors:p,isPristine:g,isValid:v,isDefaultValue:b};}return Object.keys(u.fieldMetaBase).length&&n&&l===Object.keys(u.fieldMetaBase).length?n:c}}),this.store=new Ft({deps:[this.baseStore,this.fieldMetaDerived],fn:({prevDepVals:a,currDepVals:r,prevVal:s})=>{let n=s,i=a?.[0],u=r[0],l=r[1],c=Object.values(l).filter(Boolean),d=c.some(R=>R.isValidating),m=c.every(R=>R.isValid),f=c.some(R=>R.isTouched),h=c.some(R=>R.isBlurred),x=c.every(R=>R.isDefaultValue),p=f&&u.errorMap?.onMount,v=c.some(R=>R.isDirty),g=!v,b=!!(u.errorMap?.onMount||c.some(R=>R?.errorMap?.onMount)),y=!!d,S=n?.errors??[];(!i||u.errorMap!==i.errorMap)&&(S=Object.values(u.errorMap).reduce((R,H)=>H===void 0?R:H&&ir(H)?(R.push(H.form),R):(R.push(H),R),[]));let I=S.length===0,C=m&&I,L=this.options.canSubmitWhenInvalid??false,P=u.submissionAttempts===0&&!f&&!b||!y&&!u.isSubmitting&&C||L,A=u.errorMap;if(p&&(S=S.filter(R=>R!==u.errorMap.onMount),A=Object.assign(A,{onMount:void 0})),n&&i&&n.errorMap===A&&n.fieldMeta===this.fieldMetaDerived.state&&n.errors===S&&n.isFieldsValidating===d&&n.isFieldsValid===m&&n.isFormValid===I&&n.isValid===C&&n.canSubmit===P&&n.isTouched===f&&n.isBlurred===h&&n.isPristine===g&&n.isDefaultValue===x&&n.isDirty===v&&ha(i,u))return n;let U={...u,errorMap:A,fieldMeta:this.fieldMetaDerived.state,errors:S,isFieldsValidating:d,isFieldsValid:m,isFormValid:I,isValid:C,canSubmit:P,isTouched:f,isBlurred:h,isPristine:g,isDefaultValue:x,isDirty:v},F=this.options.transform?.deps??[];if(F.length!==this.prevTransformArray.length||F.some((R,H)=>R!==this.prevTransformArray[H])){let R=Object.assign({},this,{state:U});this.options.transform?.fn(R),U=R.state,this.prevTransformArray=F;}return U}}),this.handleSubmit=this.handleSubmit.bind(this),this.update(o||{});let t=Pi(a=>pt.emit("form-state",{id:this._formId,state:a}),{wait:300});this.store.subscribe(()=>{t(this.store.state);}),pt.on("request-form-state",a=>{a.payload.id===this._formId&&pt.emit("form-api",{id:this._formId,state:this.store.state,options:this.options});}),pt.on("request-form-reset",a=>{a.payload.id===this._formId&&this.reset();}),pt.on("request-form-force-submit",a=>{a.payload.id===this._formId&&(this._devtoolsSubmissionOverride=true,this.handleSubmit(),this._devtoolsSubmissionOverride=false);});}get state(){return this.store.state}get formId(){return this._formId}runValidator(o){return ks(o.validate)?xa[o.type](o.value,o.validate):o.validate(o.value)}async handleSubmit(o){this.baseStore.setState(r=>({...r,isSubmitted:false,submissionAttempts:r.submissionAttempts+1,isSubmitSuccessful:false})),ft(()=>{Object.values(this.fieldInfo).forEach(r=>{r.instance&&(r.instance.state.meta.isTouched||r.instance.setMeta(s=>({...s,isTouched:!0})));});});let t=o??this.options.onSubmitMeta;if(!this.state.canSubmit&&!this._devtoolsSubmissionOverride){this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:t});return}this.baseStore.setState(r=>({...r,isSubmitting:true}));let a=()=>{this.baseStore.setState(r=>({...r,isSubmitting:false}));};if(await this.validateAllFields("submit"),!this.state.isFieldsValid){a(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:t}),pt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:false,stage:"validateAllFields",errors:Object.values(this.state.fieldMeta).map(r=>r.errors).flat()});return}if(await this.validate("submit"),!this.state.isValid){a(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:t}),pt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:false,stage:"validate",errors:this.state.errors});return}ft(()=>{Object.values(this.fieldInfo).forEach(r=>{r.instance?.options.listeners?.onSubmit?.({value:r.instance.state.value,fieldApi:r.instance});});}),this.options.listeners?.onSubmit?.({formApi:this,meta:t});try{await this.options.onSubmit?.({value:this.state.values,formApi:this,meta:t}),ft(()=>{this.baseStore.setState(r=>({...r,isSubmitted:!0,isSubmitSuccessful:!0})),pt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!0}),a();});}catch(r){throw this.baseStore.setState(s=>({...s,isSubmitSuccessful:false})),pt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:false,stage:"inflight",onError:r}),a(),r}}setErrorMap(o){ft(()=>{Object.entries(o).forEach(([t,a])=>{let r=t;if(ir(a)){let{formError:s,fieldErrors:n}=Ms(a);for(let i of Object.keys(this.fieldInfo))this.getFieldMeta(i)&&this.setFieldMeta(i,l=>({...l,errorMap:{...l.errorMap,[r]:n?.[i]},errorSourceMap:{...l.errorSourceMap,[r]:"form"}}));this.baseStore.setState(i=>({...i,errorMap:{...i.errorMap,[r]:s}}));}else this.baseStore.setState(s=>({...s,errorMap:{...s.errorMap,[r]:a}}));});});}};function Ms(e){if(e){if(ir(e)){let o=Ms(e.form).formError,t=e.fields;return {formError:o,fieldErrors:t}}return {formError:e}}return {formError:void 0}}function dr(e){switch(e){case "submit":return "onSubmit";case "blur":return "onBlur";case "mount":return "onMount";case "server":return "onServer";case "dynamic":return "onDynamic";case "change":default:return "onChange"}}var cr=class{constructor(o){this.options={},this.mount=()=>{let t=this.store.mount();this.options.defaultValue!==void 0&&this.form.setFieldValue(this.name,this.options.defaultValue,{dontUpdateMeta:true});let a=this.getInfo();a.instance=this,this.update(this.options);let{onMount:r}=this.options.validators||{};if(r){let s=this.runValidator({validate:r,value:{value:this.state.value,fieldApi:this,validationSource:"field"},type:"validate"});s&&this.setMeta(n=>({...n,errorMap:{...n?.errorMap,onMount:s},errorSourceMap:{...n?.errorSourceMap,onMount:"field"}}));}return this.options.listeners?.onMount?.({value:this.state.value,fieldApi:this}),t},this.update=t=>{this.options=t;let a=this.name!==t.name;if(this.name=t.name,this.state.value===void 0){let r=pa(t.form.options.defaultValues,t.name),s=t.defaultValue??r;a?this.setValue(n=>n||s,{dontUpdateMeta:true}):s!==void 0&&this.setValue(s,{dontUpdateMeta:true});}this.form.getFieldMeta(this.name)===void 0&&this.setMeta(this.state.meta);},this.getValue=()=>this.form.getFieldValue(this.name),this.setValue=(t,a)=>{this.form.setFieldValue(this.name,t,Ge(a,{dontRunListeners:true,dontValidate:true})),a?.dontRunListeners||this.triggerOnChangeListener(),a?.dontValidate||this.validate("change");},this.getMeta=()=>this.store.state.meta,this.setMeta=t=>this.form.setFieldMeta(this.name,t),this.getInfo=()=>this.form.getFieldInfo(this.name),this.pushValue=(t,a)=>{this.form.pushFieldValue(this.name,t,Ge(a,{dontRunListeners:true})),a?.dontRunListeners||this.triggerOnChangeListener();},this.insertValue=(t,a,r)=>{this.form.insertFieldValue(this.name,t,a,Ge(r,{dontRunListeners:true})),r?.dontRunListeners||this.triggerOnChangeListener();},this.replaceValue=(t,a,r)=>{this.form.replaceFieldValue(this.name,t,a,Ge(r,{dontRunListeners:true})),r?.dontRunListeners||this.triggerOnChangeListener();},this.removeValue=(t,a)=>{this.form.removeFieldValue(this.name,t,Ge(a,{dontRunListeners:true})),a?.dontRunListeners||this.triggerOnChangeListener();},this.swapValues=(t,a,r)=>{this.form.swapFieldValues(this.name,t,a,Ge(r,{dontRunListeners:true})),r?.dontRunListeners||this.triggerOnChangeListener();},this.moveValue=(t,a,r)=>{this.form.moveFieldValues(this.name,t,a,Ge(r,{dontRunListeners:true})),r?.dontRunListeners||this.triggerOnChangeListener();},this.clearValues=t=>{this.form.clearFieldValues(this.name,Ge(t,{dontRunListeners:true})),t?.dontRunListeners||this.triggerOnChangeListener();},this.getLinkedFields=t=>{let a=Object.values(this.form.fieldInfo),r=[];for(let s of a){if(!s.instance)continue;let{onChangeListenTo:n,onBlurListenTo:i}=s.instance.options.validators||{};t==="change"&&n?.includes(this.name)&&r.push(s.instance),t==="blur"&&i?.includes(this.name)&&r.push(s.instance);}return r},this.validateSync=(t,a)=>{let r=xo(t,{...this.options,form:this.form,validationLogic:this.form.options.validationLogic||ga}),n=this.getLinkedFields(t).reduce((l,c)=>{let d=xo(t,{...c.options,form:c.form,validationLogic:c.form.options.validationLogic||ga});return d.forEach(m=>{m.field=c;}),l.concat(d)},[]),i=false;ft(()=>{let l=(c,d)=>{let m=Ts(d.cause),f=d.validate?cu(c.runValidator({validate:d.validate,value:{value:c.store.state.value,validationSource:"field",fieldApi:c},type:"validate"})):void 0,h=a[m],{newErrorValue:x,newSource:p}=Cs({formLevelError:h,fieldLevelError:f});c.state.meta.errorMap?.[m]!==x&&c.setMeta(v=>({...v,errorMap:{...v.errorMap,[m]:x},errorSourceMap:{...v.errorSourceMap,[m]:p}})),x&&(i=!0);};for(let c of r)l(this,c);for(let c of n)c.validate&&l(c.field,c);});let u=Ts("submit");return this.state.meta.errorMap?.[u]&&t!=="submit"&&!i&&this.setMeta(l=>({...l,errorMap:{...l.errorMap,[u]:void 0},errorSourceMap:{...l.errorSourceMap,[u]:void 0}})),{hasErrored:i}},this.validateAsync=async(t,a)=>{let r=bo(t,{...this.options,form:this.form,validationLogic:this.form.options.validationLogic||ga}),s=await a,n=this.getLinkedFields(t),i=n.reduce((m,f)=>{let h=bo(t,{...f.options,form:f.form,validationLogic:f.form.options.validationLogic||ga});return h.forEach(x=>{x.field=f;}),m.concat(h)},[]);this.state.meta.isValidating||this.setMeta(m=>({...m,isValidating:true}));for(let m of n)m.setMeta(f=>({...f,isValidating:true}));let u=[],l=[],c=(m,f,h)=>{let x=Ts(f.cause);m.getInfo().validationMetaMap[x]?.lastAbortController.abort();let v=new AbortController;this.getInfo().validationMetaMap[x]={lastAbortController:v},h.push(new Promise(async g=>{let b;try{b=await new Promise((L,P)=>{this.timeoutIds.validations[f.cause]&&clearTimeout(this.timeoutIds.validations[f.cause]),this.timeoutIds.validations[f.cause]=setTimeout(async()=>{if(v.signal.aborted)return L(void 0);try{L(await this.runValidator({validate:f.validate,value:{value:m.store.state.value,fieldApi:m,signal:v.signal,validationSource:"field"},type:"validateAsync"}));}catch(A){P(A);}},f.debounceMs);});}catch(L){b=L;}if(v.signal.aborted)return g(void 0);let y=cu(b),S=s[this.name]?.[x],{newErrorValue:I,newSource:C}=Cs({formLevelError:S,fieldLevelError:y});m.setMeta(L=>({...L,errorMap:{...L?.errorMap,[x]:I},errorSourceMap:{...L.errorSourceMap,[x]:C}})),g(I);}));};for(let m of r)m.validate&&c(this,m,u);for(let m of i)m.validate&&c(m.field,m,l);let d=[];(u.length||l.length)&&(d=await Promise.all(u),await Promise.all(l)),this.setMeta(m=>({...m,isValidating:false}));for(let m of n)m.setMeta(f=>({...f,isValidating:false}));return d.filter(Boolean)},this.validate=(t,a)=>{if(!this.state.meta.isTouched)return [];let{fieldsErrorMap:r}=a?.skipFormValidation?{fieldsErrorMap:{}}:this.form.validateSync(t),{hasErrored:s}=this.validateSync(t,r[this.name]??{});if(s&&!this.options.asyncAlways)return this.getInfo().validationMetaMap[Ts(t)]?.lastAbortController.abort(),this.state.meta.errors;let n=a?.skipFormValidation?Promise.resolve({}):this.form.validateAsync(t);return this.validateAsync(t,n)},this.handleChange=t=>{this.setValue(t);},this.handleBlur=()=>{this.state.meta.isTouched||this.setMeta(a=>({...a,isTouched:true})),this.state.meta.isBlurred||this.setMeta(a=>({...a,isBlurred:true})),this.validate("blur"),this.triggerOnBlurListener();},this.parseValueWithSchema=t=>xa.validate({value:this.state.value,validationSource:"field"},t),this.parseValueWithSchemaAsync=t=>xa.validateAsync({value:this.state.value,validationSource:"field"},t),this.form=o.form,this.name=o.name,this.timeoutIds={validations:{},listeners:{},formListeners:{}},this.store=new Ft({deps:[this.form.store],fn:()=>{let t=this.form.getFieldValue(this.name),a=this.form.getFieldMeta(this.name)??{...vo,...o.defaultMeta};return {value:t,meta:a}}}),this.options=o;}get state(){return this.store.state}runValidator(o){return ks(o.validate)?xa[o.type](o.value,o.validate):o.validate(o.value)}setErrorMap(o){this.setMeta(t=>({...t,errorMap:{...t.errorMap,...o}}));}triggerOnBlurListener(){let o=this.form.options.listeners?.onBlurDebounceMs;o&&o>0?(this.timeoutIds.formListeners.blur&&clearTimeout(this.timeoutIds.formListeners.blur),this.timeoutIds.formListeners.blur=setTimeout(()=>{this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this});},o)):this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this});let t=this.options.listeners?.onBlurDebounceMs;t&&t>0?(this.timeoutIds.listeners.blur&&clearTimeout(this.timeoutIds.listeners.blur),this.timeoutIds.listeners.blur=setTimeout(()=>{this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this});},t)):this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this});}triggerOnChangeListener(){let o=this.form.options.listeners?.onChangeDebounceMs;o&&o>0?(this.timeoutIds.formListeners.change&&clearTimeout(this.timeoutIds.formListeners.change),this.timeoutIds.formListeners.change=setTimeout(()=>{this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this});},o)):this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this});let t=this.options.listeners?.onChangeDebounceMs;t&&t>0?(this.timeoutIds.listeners.change&&clearTimeout(this.timeoutIds.listeners.change),this.timeoutIds.listeners.change=setTimeout(()=>{this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this});},t)):this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this});}};function cu(e){if(e)return e}function Ts(e){switch(e){case "submit":return "onSubmit";case "blur":return "onBlur";case "mount":return "onMount";case "server":return "onServer";case "dynamic":return "onDynamic";case "change":default:return "onChange"}}function As(e,o=t=>t){return useSyncExternalStoreWithSelector(e.subscribe,()=>e.state,()=>e.state,o,Ng)}function Ng(e,o){if(Object.is(e,o))return true;if(typeof e!="object"||e===null||typeof o!="object"||o===null)return false;if(e instanceof Map&&o instanceof Map){if(e.size!==o.size)return false;for(let[a,r]of e)if(!o.has(a)||!Object.is(r,o.get(a)))return false;return true}if(e instanceof Set&&o instanceof Set){if(e.size!==o.size)return false;for(let a of e)if(!o.has(a))return false;return true}if(e instanceof Date&&o instanceof Date)return e.getTime()===o.getTime();let t=fu(e);if(t.length!==fu(o).length)return false;for(let a=0;a<t.length;a++)if(!Object.prototype.hasOwnProperty.call(o,t[a])||!Object.is(e[t[a]],o[t[a]]))return false;return true}function fu(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}var yo=typeof window<"u"?useLayoutEffect:useEffect;function Gg(e){let[o]=useState(()=>{let a=new cr({...e,form:e.form,name:e.name});return a.Field=Ni,a});return yo(o.mount,[o]),yo(()=>{o.update(e);}),As(o.store,e.mode==="array"?t=>[t.meta,Object.keys(t.value??[]).length]:void 0),o}var Ni=(({children:e,...o})=>{let t=Gg(o),a=useMemo(()=>ma(e,t),[e,t,t.state.value,t.state.meta]);return jsx(Fragment,{children:a})});function jg({form:e,selector:o,children:t}){let a=As(e.store,o);return ma(t,a)}function Vi(e){let o=useId(),[t]=useState(()=>{let a=new ur({...e,formId:o}),r=a;return r.Field=function(n){return jsx(Ni,{...n,form:a})},r.Subscribe=function(n){return jsx(jg,{form:a,selector:n.selector,children:n.children})},r});return yo(t.mount,[]),yo(()=>{t.update(e);}),t}function qi({field:e}){return jsxs(Fragment,{children:[e.state.meta.isTouched&&!e.state.meta.isValid?jsx("em",{children:e.state.meta.errors.join(", ")}):null,e.state.meta.isValidating?"Validating...":null]})}var ox=({editElement:e})=>{let o=useDispatch(),t=useSelector(ge),a=useRef(null),r=!!e,s=e?.data.questionType||t?.activityType||"multiple-choice",[n,i]=useState(s),u=Vi({defaultValues:{questionType:s,responseType:e?.data.responseType||"classic",feedbackMode:e?.data.feedbackMode||"practice",question:e?.data.question||"",responseOptions:{options:e?.data.responseOptions.options||["","","",""],correctIndex:e?.data.questionType==="multiple-choice"?e.data.responseOptions.correctIndex||[]:[],correctAnswer:e?.data.questionType==="true-false"?e.data.responseOptions.correctAnswer:false,correctShortAnswer:(e?.data.questionType==="short-answer"||e?.data.questionType==="fill-in-the-blank")&&e.data.responseOptions.correctShortAnswer||"",correctLongAnswer:e?.data.questionType==="long-answer"&&e.data.responseOptions.correctLongAnswer||""}},onSubmit:async({value:d})=>{if(d.questionType==="true-false"){let m={id:r?e.id:v4(),data:{questionType:d.questionType,responseType:d.responseType,feedbackMode:d.feedbackMode,question:d.question,responseOptions:{options:d.responseOptions.options,correctAnswer:d.responseOptions.correctAnswer??false}},x:r?e.x:500,y:r?e.y:200,width:r?e.width:400,height:r?e.height:300,rotation:r?e.rotation:0};o(r?ra(m):En(m));}else if(d.questionType==="multiple-choice"){let m={id:r?e.id:v4(),data:{questionType:d.questionType,responseType:d.responseType,feedbackMode:d.feedbackMode,question:d.question,responseOptions:{options:d.responseOptions.options,correctIndex:d.responseOptions.correctIndex??[]}},x:r?e.x:500,y:r?e.y:200,width:r?e.width:575,height:r?e.height:400,rotation:r?e.rotation:0};o(r?oa(m):Rn(m));}else if(d.questionType==="short-answer"){let m={id:r?e.id:v4(),data:{questionType:d.questionType,responseType:d.responseType,feedbackMode:d.feedbackMode,question:d.question,responseOptions:{options:d.responseOptions.options,correctShortAnswer:d.responseOptions.correctShortAnswer??""}},x:r?e.x:500,y:r?e.y:200,width:r?e.width:400,height:r?e.height:400,rotation:r?e.rotation:0};o(r?Oo(m):On(m));}else if(d.questionType==="fill-in-the-blank"){let m={id:r?e.id:v4(),data:{questionType:d.questionType,responseType:d.responseType,feedbackMode:d.feedbackMode,question:d.question,responseOptions:{options:d.responseOptions.options,correctShortAnswer:d.responseOptions.correctShortAnswer??""}},x:r?e.x:500,y:r?e.y:200,width:r?e.width:400,height:r?e.height:400,rotation:r?e.rotation:0};o(r?Vo(m):Un(m));}else if(d.questionType==="long-answer"){let m={id:r?e.id:v4(),data:{questionType:d.questionType,responseType:d.responseType,feedbackMode:d.feedbackMode,question:d.question,responseOptions:{options:d.responseOptions.options,correctLongAnswer:d.responseOptions.correctLongAnswer??""}},x:r?e.x:500,y:r?e.y:200,width:r?e.width:400,height:r?e.height:400,rotation:r?e.rotation:0};o(r?No(m):Vn(m));}o(sa(false));}}),l=()=>{o(sa(false));},c=jsx("div",{className:"fixed inset-0 z-106 flex w-full flex-col items-center justify-center gap-6 rounded-lg bg-black/50 p-6 shadow-lg",children:jsx("div",{ref:a,className:"scrollbar-hide h-fit max-h-[calc(100vh-240px)] w-full max-w-xl overflow-y-auto rounded-lg bg-white p-4",children:jsxs("form",{className:"relative flex h-fit max-h-[calc(100vh-100px)] w-full flex-col gap-1 rounded-lg bg-white p-4",onSubmit:d=>{d.preventDefault(),d.stopPropagation(),u.handleSubmit();},children:[jsxs("div",{className:"flex items-center justify-between pb-4",children:[jsxs("div",{className:"flex flex-col gap-1",children:[jsx("h2",{className:"text-2xl font-bold text-[#000000CC]",children:r?"Edit Question":"Create Question"}),jsx("p",{className:"font-semibold text-[#00000099]",children:"Design a new question for your lesson slide."})]}),jsx("button",{type:"button",className:"absolute top-2 right-2 flex h-8 w-8 items-center justify-center rounded bg-red-500 hover:cursor-pointer hover:bg-red-600",onClick:()=>{l();},children:jsx("span",{className:"text-xl text-white",children:"\u2715"})})]}),jsxs("div",{className:"mb-4 flex justify-between gap-6",children:[jsx(u.Field,{name:"questionType",children:d=>jsxs("div",{className:"flex w-full flex-col gap-2",children:[jsx("label",{htmlFor:d.name,className:"text-sm font-semibold text-[#00000066] uppercase",children:"Question Type"}),jsxs("div",{className:"relative",children:[jsxs("select",{id:d.name,name:d.name,value:d.state.value,onBlur:d.handleBlur,onChange:m=>{d.handleChange(m.target.value),i(m.target.value);},disabled:r,className:`outline-primary/50 w-full appearance-none rounded-lg border border-gray-300 px-4 py-3 pr-10 font-semibold text-[#000000CC] ${r?"cursor-not-allowed bg-gray-100 opacity-60":"bg-white"}`,children:[jsx("option",{value:"multiple-choice",children:"Multiple Choice"}),jsx("option",{value:"true-false",children:"True/False"}),jsx("option",{value:"short-answer",children:"Short Answer"}),jsx("option",{value:"fill-in-the-blank",children:"Fill in the blank"}),jsx("option",{value:"long-answer",children:"Long Answer"})]}),jsx("div",{className:"pointer-events-none absolute top-1/2 right-3 -translate-y-1/2",children:jsx("svg",{className:"h-5 w-5 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]}),r&&jsx("p",{className:"text-xs text-gray-500 italic",children:"Question type cannot be changed when editing"}),jsx(qi,{field:d})]})}),n&&!["short-answer","fill-in-the-blank","long-answer"].includes(n)&&jsx(u.Field,{name:"responseType",children:d=>jsxs("div",{className:"flex w-full flex-col gap-2",children:[jsx("label",{htmlFor:d.name,className:"text-sm font-semibold text-[#00000066] uppercase",children:"Response Type"}),jsxs("div",{className:"relative",children:[jsxs("select",{id:d.name,name:d.name,value:d.state.value,onBlur:d.handleBlur,onChange:m=>d.handleChange(m.target.value),className:"outline-primary/50 w-full appearance-none rounded-lg border border-gray-300 bg-white px-4 py-3 pr-10 font-semibold text-[#000000CC]",children:[jsx("option",{value:"classic",children:"Classic"}),jsx("option",{value:"drag-and-drop",children:"Drag and Drop"})]}),jsx("div",{className:"pointer-events-none absolute top-1/2 right-3 -translate-y-1/2",children:jsx("svg",{className:"h-5 w-5 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]}),jsx(qi,{field:d})]})})]}),jsx(u.Field,{name:"feedbackMode",children:d=>jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[jsxs("div",{className:`flex w-full items-center gap-2 rounded-lg bg-gray-100 p-1.5 ${n==="long-answer"?"cursor-not-allowed opacity-60":""}`,children:[jsxs("button",{type:"button",disabled:n==="long-answer",onClick:()=>d.handleChange("practice"),className:`flex w-full items-center gap-2 rounded-lg px-4 py-2 text-base font-medium transition-all ${d.state.value==="practice"?"text-primary bg-white":"text-gray-500"} `,children:[jsx(ScribbleLoop,{weight:"fill",size:16}),"Practice Mode"]}),jsxs("button",{type:"button",disabled:n==="long-answer",onClick:()=>d.handleChange("test"),className:`flex w-full items-center gap-2 rounded-lg px-4 py-2 text-base font-medium transition-all ${d.state.value==="test"?"text-primary bg-white":"text-gray-500"} `,children:[jsx(Exam,{weight:"fill",size:16}),"Assessment Mode"]})]}),n==="long-answer"&&jsx("p",{className:"text-xs text-gray-500 italic",children:"Long answer questions are only available in Assessment Mode"}),jsx(qi,{field:d})]})}),jsx(u.Field,{name:"question",validators:{onChange:({value:d})=>d?void 0:"A question is required"},children:d=>jsxs("div",{className:"mb-6 flex flex-col gap-2",children:[jsx("label",{htmlFor:d.name,className:"text-sm font-semibold text-[#00000066] uppercase",children:"Question"}),jsx("div",{className:"relative",children:jsx("input",{className:"outline-primary/50 w-full resize-none rounded-lg border border-gray-300 bg-white px-4 py-3 text-gray-900",value:d.state.value,onChange:m=>d.handleChange(m.target.value),onBlur:d.handleBlur,placeholder:"Enter Your Question"})}),d.state.meta.errors.length>0&&jsx("span",{className:"text-sm font-semibold text-red-500",children:d.state.meta.errors.join(", ")})]})}),n==="true-false"&&jsx(u.Field,{name:"responseOptions.correctAnswer",children:d=>{let m=d.state.value;return jsxs("div",{className:"mb-6 flex flex-col gap-2",children:[jsx("label",{className:"text-base font-semibold text-[#00000066] uppercase",children:"Set Correct Answer"}),jsxs("div",{className:"flex gap-4",children:[jsxs("button",{type:"button",onClick:()=>d.handleChange(true),className:`relative flex flex-1 flex-col items-center justify-center rounded-xl border px-6 py-5 transition-all ${m===true?"border-green-500 bg-green-50":"border-[#096B76] bg-white hover:border-gray-400"}`,children:[jsx(CheckCircle,{weight:"fill",color:"#45B389",size:52}),jsx("span",{className:"mt-2 text-lg font-semibold text-black",children:"True"}),m===true&&jsx("span",{className:"absolute top-2 right-2 rounded-full bg-green-600 px-3 py-0.5 text-xs font-medium text-white",children:"Correct"})]}),jsxs("button",{type:"button",onClick:()=>d.handleChange(false),className:`relative flex flex-1 flex-col items-center justify-center rounded-xl border px-6 py-5 transition-all ${m===false?"border-green-500 bg-green-50":"border-[#096B76] bg-white hover:border-gray-400"}`,children:[jsx(XCircle,{weight:"fill",color:"#EE5454",size:52}),jsx("span",{className:"mt-2 text-lg font-semibold text-black",children:"False"}),m===false&&jsx("span",{className:"absolute top-2 right-2 rounded-full bg-green-600 px-3 py-0.5 text-xs font-medium text-white",children:"Correct"})]})]}),jsx("p",{className:"text-sm font-semibold text-gray-500",children:"Select the correct answer for this true/false question"})]})}}),n==="multiple-choice"&&jsx(u.Field,{name:"responseOptions",validators:{onChange:({value:d})=>{if(d.options.filter(f=>!f.trim()).length>0)return "All options must have text";if(!d.correctIndex||d.correctIndex.length===0)return "Please select at least one correct answer"}},children:d=>{let m=(p,v)=>{let g=[...d.state.value.options];g[p]=v,d.handleChange({...d.state.value,options:g});},f=()=>{if(d.state.value.options.length>=6){alert("Maximum 6 options allowed");return}d.handleChange({...d.state.value,options:[...d.state.value.options,""]});},h=p=>{if(d.state.value.options.length<=2){alert("Minimum 2 options required");return}let v=d.state.value.options.filter((b,y)=>y!==p),g=d.state.value.correctIndex?.filter(b=>b!==p).map(b=>b>p?b-1:b);d.handleChange({...d.state.value,options:v,correctIndex:g});},x=p=>{let v=d.state.value.correctIndex||[];if(v.includes(p))d.handleChange({...d.state.value,correctIndex:v.filter(b=>b!==p)});else {if(v.length>=6){alert("Maximum 6 correct answers allowed");return}d.handleChange({...d.state.value,correctIndex:[...v,p]});}};return jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[jsx("div",{className:"flex items-center justify-between",children:jsxs("label",{htmlFor:d.name,className:"mb-2 text-base font-semibold text-gray-900",children:["Answer Options",jsx("span",{className:"text-[#00000066]",children:" (At least 2 options required)"})]})}),jsx("div",{className:"mb-4 flex flex-col gap-3",children:d.state.value.options.map((p,v)=>{let g=!p.trim(),b=d.state.value.correctIndex?.includes(v),y=d.state.meta.isTouched&&g;return jsxs("div",{className:"flex w-full items-center gap-3 px-1",children:[jsx("button",{type:"button",onClick:()=>x(v),className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors ${b?"border-green-500 bg-green-500":"border-gray-300 hover:border-green-500"}`,children:b&&jsx("svg",{className:"h-3 w-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M5 13l4 4L19 7"})})}),jsx("div",{className:`w-full rounded-lg border-2 px-4 py-3 transition-colors ${y?"border-red-500 bg-red-50":b?"border-green-500 bg-green-50":"border-gray-300 bg-white"}`,children:jsx("input",{type:"text",placeholder:`Option ${v+1}`,value:p,onChange:S=>m(v,S.target.value),onBlur:d.handleBlur,className:"w-full flex-1 border-none bg-transparent text-gray-900 placeholder:text-gray-400 focus:outline-none"})}),d.state.value.options.length>2&&jsx("button",{type:"button",onClick:()=>h(v),className:"text-[#00000066] transition-colors hover:cursor-pointer hover:text-red-600",children:jsx(Trash,{weight:"fill",size:24})})]},v)})}),jsx("button",{type:"button",onClick:f,disabled:d.state.value.options.length>=6,className:"mx-2 cursor-pointer rounded-lg border border-dashed border-[#00000033] px-3 py-3 text-lg font-semibold text-[#00000066] disabled:cursor-not-allowed",children:"+ Add Option"}),d.state.value.correctIndex.length===0||d.state.meta.errors.length>0?jsx("span",{className:"px-2 text-base font-semibold text-red-500",children:d.state.meta.errors.join(", ")}):jsxs("div",{className:"flex w-fit items-center gap-1 rounded-lg bg-[#F2FFF4] px-2 py-1 text-[#1B9D2C]",children:[jsx(CheckCircle,{weight:"fill"}),jsx("p",{className:"",children:"Correct answer selected"})]})]})}}),(n==="short-answer"||n==="fill-in-the-blank")&&jsx(u.Field,{name:"responseOptions.correctShortAnswer",children:d=>jsxs("div",{className:"mb-6 flex flex-col gap-2",children:[jsx("label",{htmlFor:d.name,className:"text-sm font-semibold text-gray-900",children:"Correct Short Answer"}),jsx("input",{type:"text",placeholder:"Type the expected correct answer...",value:d.state.value,onChange:m=>{d.handleChange(m.target.value);},className:"outline-primary/50 w-full rounded-lg border-2 border-gray-300 bg-white p-3 text-gray-900 transition-colors"}),jsx("p",{className:"text-sm font-semibold text-gray-500",children:"Learners must write this answer exactly (case-insensitive)."}),d.state.meta.errors.length>0&&jsx("span",{className:"text-sm font-semibold text-red-500",children:d.state.meta.errors.join(", ")})]})}),n==="long-answer"&&jsx(u.Field,{name:"responseOptions.correctLongAnswer",children:d=>jsxs("div",{className:"mb-6 flex flex-col gap-2",children:[jsx("label",{htmlFor:d.name,className:"text-sm font-semibold text-gray-900",children:"Expected Long Answer (Optional)"}),jsx("textarea",{placeholder:"Type the expected answer or key points...",value:d.state.value,onChange:m=>{d.handleChange(m.target.value);},rows:6,className:"outline-primary/50 w-full rounded-lg border-2 border-gray-300 bg-white p-3 text-gray-900 transition-colors"}),jsx("p",{className:"text-sm font-semibold text-gray-500",children:"This will be used as a reference answer for manual grading."}),d.state.meta.errors.length>0&&jsx("span",{className:"text-sm font-semibold text-red-500",children:d.state.meta.errors.join(", ")})]})}),jsx(u.Subscribe,{selector:d=>[d.canSubmit,d.isSubmitting],children:([d,m])=>jsx("button",{type:"submit",disabled:!d,className:"mt-2 mb-4 w-full rounded-lg bg-[#096B76] px-6 py-3 font-semibold text-white transition-colors hover:bg-[#075862] disabled:cursor-not-allowed disabled:opacity-50",children:m?"Saving...":r?"Update Question":"Save Question"})})]})})});return createPortal(c,document.body)},hu=ox;var gu=({text:e,position:o})=>{let t=xe(),a=l=>{t(ue()),t(wt({id:e.id,fontSize:Math.max(12,Math.min(72,e.fontSize+l))}));},r=l=>{t(ue()),t(wt({id:e.id,fill:l}));},s=()=>{t(ue()),t(wt({id:e.id,fontWeight:e.fontWeight==="bold"?"normal":"bold"}));},n=()=>{t(ue()),t(wt({id:e.id,fontStyle:e.fontStyle==="italic"?"normal":"italic"}));},i=()=>{t(ue()),t(wt({id:e.id,textDecoration:e.textDecoration==="underline"?"":"underline"}));},u=l=>{t(ue()),t(wt({id:e.id,fontFamily:l}));};return jsxs("div",{className:"fixed z-1001 flex items-center gap-1 rounded-lg border border-gray-200 bg-white p-2 shadow-2xl",style:{left:`${o.x}px`,top:`${o.y-60}px`,transform:"translateX(-50%)"},onClick:l=>l.stopPropagation(),children:[jsxs("select",{value:e.fontFamily,onChange:l=>u(l.target.value),className:"rounded border border-gray-300 bg-white px-2 py-1 text-xs hover:bg-gray-50",children:[jsx("option",{value:"Arial",children:"Arial"}),jsx("option",{value:"Helvetica",children:"Helvetica"}),jsx("option",{value:"Times New Roman",children:"Times"}),jsx("option",{value:"Courier New",children:"Courier"}),jsx("option",{value:"Georgia",children:"Georgia"}),jsx("option",{value:"Verdana",children:"Verdana"}),jsx("option",{value:"Comic Sans MS",children:"Comic Sans"})]}),jsxs("div",{className:"ml-1 flex items-center gap-0.5 border-l border-gray-200 pl-1",children:[jsx("button",{onClick:()=>a(-2),className:"flex h-7 w-7 items-center justify-center rounded text-sm font-bold hover:bg-gray-100",title:"Decrease font size",children:"\u2212"}),jsx("span",{className:"w-8 text-center text-xs font-medium",children:Math.round(e.fontSize)}),jsx("button",{onClick:()=>a(2),className:"flex h-7 w-7 items-center justify-center rounded text-sm font-bold hover:bg-gray-100",title:"Increase font size",children:"+"})]}),jsxs("div",{className:"ml-1 flex items-center gap-0.5 border-l border-gray-200 pl-1",children:[jsx("button",{onClick:s,className:`flex h-7 w-7 items-center justify-center rounded transition-colors ${e.fontWeight==="bold"?"bg-blue-100 text-blue-600":"text-gray-700 hover:bg-gray-100"}`,title:"Bold",children:jsx(TextB,{size:16,weight:"bold"})}),jsx("button",{onClick:n,className:`flex h-7 w-7 items-center justify-center rounded transition-colors ${e.fontStyle==="italic"?"bg-blue-100 text-blue-600":"text-gray-700 hover:bg-gray-100"}`,title:"Italic",children:jsx(TextItalic,{size:16,weight:"bold"})}),jsx("button",{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded transition-colors ${e.textDecoration==="underline"?"bg-blue-100 text-blue-600":"text-gray-700 hover:bg-gray-100"}`,title:"Underline",children:jsx(TextUnderline,{size:16,weight:"bold"})})]}),jsx("div",{className:"ml-1 border-l border-gray-200 pl-1",children:jsx("div",{className:"relative",children:jsx("input",{type:"color",value:e.fill,onChange:l=>r(l.target.value),className:"h-7 w-7 cursor-pointer rounded border border-gray-300",title:"Text color",style:{padding:"2px"}})})})]})};var bu=({text:e,editingValue:o,onEditingChange:t,onFinish:a,position:r,scale:s,textareaRef:n})=>{let i=useRef(null),u=useMemo(()=>({fontSize:`${e.fontSize*s}px`,fontFamily:e.fontFamily,fontStyle:e.fontStyle,fontWeight:e.fontWeight==="bold"?"bold":"normal",textDecoration:e.textDecoration,color:e.fill,border:"2px solid #4A90E2",outline:"none",padding:"5px",background:"white",resize:"none",overflow:"hidden",width:"auto",minWidth:"200px",minHeight:"50px",lineHeight:"1.2",transform:`rotate(${e.rotation}deg)`,transformOrigin:"top left",whiteSpace:"pre",overflowWrap:"normal",boxSizing:"border-box"}),[e.fontSize,e.fontFamily,e.fontStyle,e.fontWeight,e.textDecoration,e.fill,e.rotation,s]),l=useCallback(c=>{c.style.height="auto",c.style.height=`${c.scrollHeight}px`;let d=document.createElement("span");d.style.font=window.getComputedStyle(c).font,d.style.fontSize=c.style.fontSize,d.style.fontFamily=c.style.fontFamily,d.style.fontWeight=c.style.fontWeight,d.style.fontStyle=c.style.fontStyle,d.style.visibility="hidden",d.style.position="absolute",d.style.whiteSpace="pre";let m=c.value.split(`
|
|
4
4
|
`),f=0;document.body.appendChild(d);for(let x of m){d.textContent=x||" ";let p=d.offsetWidth;p>f&&(f=p);}document.body.removeChild(d);let h=10;c.style.width=`${Math.max(200,f+h+20)}px`;},[]);return useEffect(()=>{let c=i.current;c&&(c.style.fontSize=`${e.fontSize*s}px`,c.style.fontFamily=e.fontFamily,c.style.fontStyle=e.fontStyle,c.style.fontWeight=e.fontWeight==="bold"?"bold":"normal",c.style.textDecoration=e.textDecoration,c.style.color=e.fill,l(c));},[o,e.fontSize,e.fontFamily,e.fontStyle,e.fontWeight,e.textDecoration,e.fill,s,l]),jsx("div",{style:{position:"absolute",top:`${r.top}px`,left:`${r.left}px`,zIndex:1e3},children:jsx("textarea",{ref:c=>{if(i.current=c,n.current=c,c){c.focus();let d=c.value.length;c.setSelectionRange(d,d),l(c);}},value:o,onChange:c=>{t(c.target.value);},onKeyDown:c=>{c.key==="Escape"&&a();},style:u},`${e.fontWeight}-${e.fontStyle}-${e.textDecoration}-${e.fontSize}-${e.fontFamily}`)})};var vu=memo(({shortAnswer:e,handleSelect:o,handleTransform:t,saRefs:a,onContextMenu:r,handleDragEnd:s})=>{let n=useSelector(E=>E.toolbar.selectedTool),i=n==="pen"||n==="eraser",u=useRef(null),[l,c]=useState(""),[d,m]=useState(false),[f,h]=useState(null);useEffect(()=>{let E=u.current;if(E)return a.current.set(e.id,E),()=>{a.current.delete(e.id);}},[e.id,a]);let x=e.data.responseOptions.correctShortAnswer?.trim().toLowerCase()||"",p=d&&l.trim().toLowerCase()===x,v=()=>{m(false),c("");},g=()=>p?"\u2713 Correct! \u{1F389}":"\u2717 Try again!",b=()=>p?{bg:"#dcfce7",text:"#166534"}:{bg:"#fee2e2",text:"#991b1b"},y=24,S=60,I=d?50:0,C=50,L=12,P=e.data.feedbackMode==="practice"?48:0,A=12,U=30,F=S+I+U+C+L+A+P+y;return jsxs(Group,{ref:u,draggable:!i,listening:!i,x:e.x,y:e.y,rotation:e.rotation,width:e.width,height:e.height,name:"sa-element",...i?{}:{onDragEnd:s,onClick:()=>o(e.id),onTap:()=>o(e.id),onContextMenu:E=>{let R=u.current?.getStage()?.getPointerPosition();if(!R)return;let H={x:e.x,y:e.y,width:e.width,height:e.height};R.x>=H.x&&R.x<=H.x+H.width&&R.y>=H.y&&R.y<=H.y+H.height&&r(E.evt,e.id,"shortAnswer");}},children:[jsx(Rect,{fill:"white",stroke:"#e5e7eb",strokeWidth:2,cornerRadius:12,width:e.width,height:F,onTransformEnd:E=>t(e.id,E)}),jsx(Text,{text:e.data.question,x:y,y,fontSize:20,fontStyle:"bold",fill:"#111827",width:e.width-y*2,listening:false}),d&&jsxs(Fragment,{children:[jsx(Rect,{x:y,y:S,width:e.width-y*2,height:I,fill:b().bg,cornerRadius:8}),jsx(Text,{x:y,y:S,width:e.width-y*2,height:I,text:g(),fontSize:16,fontStyle:"bold",fill:b().text,align:"center",verticalAlign:"middle",listening:false})]}),jsx(Text,{text:"Answer:",x:y,y:S+I+L,fontSize:14,fill:"#6b7280",width:e.width-y*2,listening:false}),jsx(Rect,{x:y,y:S+I+U,width:e.width-y*2,height:C,fill:"#ffffff",stroke:p?"#22c55e":d?"#ef4444":"#d1d5db",strokeWidth:2,cornerRadius:8}),jsx(Html,{divProps:{style:{position:"absolute",top:`${S+I+U}px`,left:`${y}px`,width:`${e.width-y*2}px`,height:`${C}px`,pointerEvents:d?"none":"auto"}},children:jsx("input",{type:"text",value:l,onChange:E=>c(E.target.value),disabled:d,placeholder:"Type your answer...",className:"h-full w-full border-0 bg-white px-3 text-gray-900 focus:outline-none",style:{fontSize:"16px",pointerEvents:d?"none":"auto"}})}),e.data.feedbackMode==="practice"&&jsxs(Group,{y:S+I+U+C+L+A,children:[!d&&jsxs(Group,{onMouseDown:E=>{E.cancelBubble=true,h("check");},onMouseUp:E=>{E.cancelBubble=true,h(null),l.length>0&&m(true);},onMouseLeave:E=>{E.cancelBubble=true,h(null);},onTouchStart:E=>{E.cancelBubble=true,h("check");},onTouchEnd:E=>{E.cancelBubble=true,h(null),l.length>0&&m(true);},scaleX:f==="check"?.95:1,scaleY:f==="check"?.95:1,children:[jsx(Rect,{x:y,width:e.width-y*2,height:48,fill:l.length===0?"#9ca3af":"#096B76",cornerRadius:8,onClick:E=>E.cancelBubble=true,onTap:E=>E.cancelBubble=true}),jsx(Text,{x:y,width:e.width-y*2,height:48,text:"Check",fontSize:16,fontStyle:"bold",fill:"white",align:"center",verticalAlign:"middle",listening:false})]}),d&&jsxs(Group,{onMouseDown:()=>h("reset"),onMouseUp:()=>{h(null),v();},onMouseLeave:()=>h(null),onTouchStart:()=>h("reset"),onTouchEnd:()=>{h(null),v();},scaleX:f==="reset"?.95:1,scaleY:f==="reset"?.95:1,children:[jsx(Rect,{x:y,width:e.width-y*2,height:48,fill:"#ef4444",cornerRadius:8,onClick:E=>E.cancelBubble=true,onTap:E=>E.cancelBubble=true}),jsx(Text,{x:y,width:e.width-y*2,height:48,text:"Reset",fontSize:16,fontStyle:"bold",fill:"white",align:"center",verticalAlign:"middle",listening:false})]})]})]})});vu.displayName="ShortAnswer";var yu=vu;var Lu=({shortAnswers:e,handleSelect:o,handleTransform:t,saRefs:a,onContextMenu:r,handleDragEnd:s})=>jsx(Fragment,{children:e.map(n=>jsx(yu,{shortAnswer:n,handleSelect:o,handleTransform:t,saRefs:a,onContextMenu:r,handleDragEnd:i=>s(i,n.id)},n.id))});var Su=e=>{let o=useDispatch(),a=useSelector(ge)?.fillInTheBlanks||[],r=useRef(new Map),s=useCallback((n,i)=>{let u=n.target;o(Vo({id:i,x:u.x(),y:u.y()})),e?.();},[o,e]);return {fillInTheBlanks:a,fibRefs:r,handleFillInTheBlanksDragEnd:s}};var Iu=memo(({fillInTheBlank:e,handleSelect:o,handleTransform:t,handleDragEnd:a,onContextMenu:r})=>{let s=useSelector(F=>F.toolbar.selectedTool),n=s==="pen"||s==="eraser",i=useRef(null),[u,l]=useState(""),[c,d]=useState(false),[m,f]=useState(null);useEffect(()=>{if(i.current)return ()=>{}},[e.id]);let h=e.data.responseOptions.correctShortAnswer?.trim().toLowerCase()||"",x=c&&u.trim().toLowerCase()===h,p=()=>{d(false),l("");},v=()=>x?"\u2713 Correct! \u{1F389}":"\u2717 Try again!",g=()=>x?{bg:"#dcfce7",text:"#166534"}:{bg:"#fee2e2",text:"#991b1b"},b=24,y=80,S=c?50:0,I=45,C=8,L=20,P=e.data.feedbackMode==="practice"?48:0,A=12,U=y+S+C+L+C+A+P+b;return jsxs(Group,{ref:i,draggable:!n,listening:!n,x:e.x,y:e.y,rotation:e.rotation,width:e.width,height:e.height,name:"fib-element",...n?{}:{onDragEnd:F=>a(F,e.id),onClick:()=>o(e.id),onTap:()=>o(e.id),onContextMenu:F=>{let E=i.current?.getStage()?.getPointerPosition();if(!E||!r)return;let R={x:e.x,y:e.y,width:e.width,height:e.height};E.x>=R.x&&E.x<=R.x+R.width&&E.y>=R.y&&E.y<=R.y+R.height&&r(F.evt,e.id,"fillInTheBlanks");}},children:[jsx(Rect,{fill:"white",stroke:"#e5e7eb",strokeWidth:2,cornerRadius:12,width:e.width,height:U,onTransformEnd:F=>t(e.id,F)}),jsx(Text,{text:e.data.question,x:b,y:b,fontSize:20,fontStyle:"bold",fill:"#111827",width:e.width-b*2-200,listening:false}),jsx(Rect,{x:e.width-b-180,y:b+10,width:180,height:I,fill:"#ffffff",stroke:x?"#22c55e":c?"#ef4444":"#096B76",strokeWidth:2,cornerRadius:8}),jsx(Html,{divProps:{style:{position:"absolute",top:`${b+10}px`,left:`${e.width-b-180}px`,width:"180px",height:`${I}px`,pointerEvents:c?"none":"auto"}},children:jsx("input",{type:"text",value:u,onChange:F=>l(F.target.value),disabled:c,placeholder:"__________",className:"h-full w-full border-0 bg-white px-2 text-center text-gray-900 focus:outline-none",style:{fontSize:"14px",pointerEvents:c?"none":"auto"}})}),c&&jsxs(Fragment,{children:[jsx(Rect,{x:b,y,width:e.width-b*2,height:S,fill:g().bg,cornerRadius:8}),jsx(Text,{x:b,y,width:e.width-b*2,height:S,text:v(),fontSize:16,fontStyle:"bold",fill:g().text,align:"center",verticalAlign:"middle",listening:false})]}),jsx(Text,{text:"\u26A0\uFE0F Answer is case sensitive",x:b,y:y+S+C,fontSize:10,fontStyle:"italic",fill:"#6b7280",width:e.width-b*2,listening:false}),e.data.feedbackMode==="practice"&&jsxs(Group,{y:y+S+C+L+C+A,children:[!c&&jsxs(Group,{onMouseDown:F=>{F.cancelBubble=true,f("check");},onMouseUp:F=>{F.cancelBubble=true,f(null),u.length>0&&d(true);},onMouseLeave:F=>{F.cancelBubble=true,f(null);},onTouchStart:F=>{F.cancelBubble=true,f("check");},onTouchEnd:F=>{F.cancelBubble=true,f(null),u.length>0&&d(true);},scaleX:m==="check"?.95:1,scaleY:m==="check"?.95:1,children:[jsx(Rect,{x:b,width:e.width-b*2,height:48,fill:u.length===0?"#9ca3af":"#096B76",cornerRadius:8,onClick:F=>F.cancelBubble=true,onTap:F=>F.cancelBubble=true}),jsx(Text,{x:b,width:e.width-b*2,height:48,text:"Check",fontSize:16,fontStyle:"bold",fill:"white",align:"center",verticalAlign:"middle",listening:false})]}),c&&jsxs(Group,{onMouseDown:()=>f("reset"),onMouseUp:()=>{f(null),p();},onMouseLeave:()=>f(null),onTouchStart:()=>f("reset"),onTouchEnd:()=>{f(null),p();},scaleX:m==="reset"?.95:1,scaleY:m==="reset"?.95:1,children:[jsx(Rect,{x:b,width:e.width-b*2,height:48,fill:"#ef4444",cornerRadius:8,onClick:F=>F.cancelBubble=true,onTap:F=>F.cancelBubble=true}),jsx(Text,{x:b,width:e.width-b*2,height:48,text:"Reset",fontSize:16,fontStyle:"bold",fill:"white",align:"center",verticalAlign:"middle",listening:false})]})]})]})});Iu.displayName="FillInTheBlanks";var Cu=Iu;var Mu=({fillInTheBlanks:e,handleSelect:o,handleTransform:t,onContextMenu:a,handleDragEnd:r})=>jsx(Fragment,{children:e.map(s=>jsx(Cu,{fillInTheBlank:s,handleSelect:o,handleTransform:t,onContextMenu:a,handleDragEnd:r},s.id))});var Ki=memo(({longAnswer:e,handleSelect:o,handleTransform:t,saRefs:a,onContextMenu:r,handleDragEnd:s})=>{let n=useSelector(E=>E.toolbar.selectedTool),i=n==="pen"||n==="eraser",u=useRef(null),[l,c]=useState(""),[d,m]=useState(false),[f,h]=useState(null);useEffect(()=>{let E=u.current;if(E)return a.current.set(e.id,E),()=>{a.current.delete(e.id);}},[e.id,a]);let x=e.data.responseOptions.correctLongAnswer?.trim().toLowerCase()||"",p=d&&l.trim().toLowerCase()===x,v=()=>{m(false),c("");},g=()=>p?"\u2713 Correct! \u{1F389}":"\u2717 Needs review - this is a long answer question",b=()=>p?{bg:"#dcfce7",text:"#166534"}:{bg:"#fef3c7",text:"#92400e"},y=24,S=60,I=d?60:0,C=120,L=12,P=48,A=12,U=30,F=S+I+U+C+L+A+P+y;return jsxs(Group,{ref:u,draggable:!i,listening:!i,x:e.x,y:e.y,rotation:e.rotation,width:e.width,height:e.height,name:"la-element",...i?{}:{onDragEnd:s,onClick:()=>o(e.id),onTap:()=>o(e.id),onContextMenu:E=>{let R=u.current?.getStage()?.getPointerPosition();if(!R||!r)return;let H={x:e.x,y:e.y,width:e.width,height:e.height};R.x>=H.x&&R.x<=H.x+H.width&&R.y>=H.y&&R.y<=H.y+H.height&&r(E.evt,e.id,"longAnswer");}},children:[jsx(Rect,{fill:"white",stroke:"#e5e7eb",strokeWidth:2,cornerRadius:12,width:e.width,height:F,onTransformEnd:E=>t(e.id,E)}),jsx(Text,{text:e.data.question,x:y,y,fontSize:20,fontStyle:"bold",fill:"#111827",width:e.width-y*2,listening:false}),d&&jsxs(Fragment,{children:[jsx(Rect,{x:y,y:S,width:e.width-y*2,height:I,fill:b().bg,cornerRadius:8}),jsx(Text,{x:y,y:S,width:e.width-y*2,height:I,text:g(),fontSize:14,fontStyle:"bold",fill:b().text,align:"center",verticalAlign:"middle",listening:false})]}),jsx(Text,{text:"Answer (Extended response):",x:y,y:S+I+L,fontSize:14,fill:"#6b7280",width:e.width-y*2,listening:false}),jsx(Rect,{x:y,y:S+I+U,width:e.width-y*2,height:C,fill:"#ffffff",stroke:"#d1d5db",strokeWidth:2,cornerRadius:8}),jsx(Html,{divProps:{style:{position:"absolute",top:`${S+I+U}px`,left:`${y}px`,width:`${e.width-y*2}px`,height:`${C}px`,pointerEvents:d?"none":"auto"}},children:jsx("textarea",{value:l,onChange:E=>c(E.target.value),disabled:d,placeholder:`Type your extended answer here...\r
|
|
5
5
|
\r
|