@liascript/exporter
Version:
A generic exporter for LiaScript
1 lines • 26.4 kB
JavaScript
function t(t,e,i,s){Object.defineProperty(t,e,{get:i,set:s,enumerable:!0,configurable:!0})}var e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;e.register("9p1wx",(function(i,s){t(i.exports,"Connector",(function(){return l}));var o=e("2Xs1f"),n=e("jXXgq"),r=e("fZWR0"),a=e("iKFEu");class l extends n.Connector{generateUUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}))}handleUnload(){if(!this.active||!this.lrs)return;const t=r.formatDuration(this.getTotalDuration());let e;if(this.completionSent)e=r.generateTerminatedStatement(this.actor,this.courseId,this.courseTitle,t,this.registration);else{const i=this.totalSlides>0?this.visitedSlides.size/this.totalSlides:0;e=r.generateSuspendedStatement(this.actor,this.courseId,this.courseTitle,t,this.lastVisitedSlide,i,this.registration)}if(navigator.sendBeacon&&this.lrs.endpoint){const t={"Content-Type":"application/json","X-Experience-API-Version":"1.0.3"};this.lrs.auth&&(t.Authorization=this.lrs.auth),navigator.sendBeacon(this.lrs.endpoint,JSON.stringify([e]))}else this.lrs.sendStatement(e)}async restoreState(){if(this.lrs){this.debug&&console.log("Attempting to restore state from LRS...");try{var t;const R={agent:JSON.stringify(this.actor),activity:this.courseId,related_activities:!0,limit:1e3};this.registration&&(R.registration=this.registration),this.debug&&console.log("LRS query parameters:",R);const A=await this.lrs.getStatements(R);if(this.debug&&console.log("LRS response:",A),!A||!A.statements)return void(this.debug&&console.log("No statements found in LRS response"));this.debug&&console.log("Processing",A.statements.length,"statements...");const q={},L={},D={};let O=null,E=null;for(const t of A.statements){if("http://adlnet.gov/expapi/verbs/experienced"===t.verb.id){var e,i;const s=null===(e=t.object.definition)||void 0===e||null===(i=e.extensions)||void 0===i?void 0:i["http://liascript.github.io/extensions/slideId"];if(void 0!==s){this.visitedSlides.add(s);const e=new Date(t.timestamp).getTime();(!O||new Date(O.timestamp).getTime()<e)&&(O=t),this.debug&&console.log("Restored slide visit:",s)}}if("http://adlnet.gov/expapi/verbs/answered"===t.verb.id){var s,o,n,r,a,l;const e=null===(s=t.object.definition)||void 0===s||null===(o=s.extensions)||void 0===o?void 0:o["http://liascript.github.io/extensions/slideId"],i=null===(n=t.object.definition)||void 0===n||null===(r=n.extensions)||void 0===r?void 0:r["http://liascript.github.io/extensions/quizIndex"],c=null===(a=t.object.definition)||void 0===a||null===(l=a.extensions)||void 0===l?void 0:l["http://liascript.github.io/extensions/surveyIndex"];if(void 0!==e&&void 0!==i){const s=`${e}-${i}`,o=new Date(t.timestamp).getTime();(!q[s]||new Date(q[s].timestamp).getTime()<o)&&(q[s]=t)}else if(void 0!==e&&void 0!==c){const i=`${e}-${c}`,s=new Date(t.timestamp).getTime();(!L[i]||new Date(L[i].timestamp).getTime()<s)&&(L[i]=t)}}if("http://adlnet.gov/expapi/verbs/interacted"===t.verb.id){var c,d,h,u;const e=null===(c=t.object.definition)||void 0===c||null===(d=c.extensions)||void 0===d?void 0:d["http://liascript.github.io/extensions/slideId"],i=null===(h=t.object.definition)||void 0===h||null===(u=h.extensions)||void 0===u?void 0:u["http://liascript.github.io/extensions/taskIndex"];if(void 0!==e&&void 0!==i){const s=`${e}-${i}`,o=new Date(t.timestamp).getTime();(!D[s]||new Date(D[s].timestamp).getTime()<o)&&(D[s]=t)}}if("http://adlnet.gov/expapi/verbs/completed"===t.verb.id&&(this.completionSent=!0,this.debug&&console.log("Found completion statement")),"http://adlnet.gov/expapi/verbs/progressed"===t.verb.id||"http://adlnet.gov/expapi/verbs/suspended"===t.verb.id||"http://adlnet.gov/expapi/verbs/completed"===t.verb.id){const e=new Date(t.timestamp).getTime();(!E||new Date(E.timestamp).getTime()<e)&&(E=t)}}var p,g;if(O)this.lastVisitedSlide=(null===(p=O.object.definition)||void 0===p||null===(g=p.extensions)||void 0===g?void 0:g["http://liascript.github.io/extensions/slideId"])||0,this.debug&&console.log("Last visited slide:",this.lastVisitedSlide);for(const t in q){var S,m,v,f,b,x;const e=q[t],i=null===(S=e.object.definition)||void 0===S||null===(m=S.extensions)||void 0===m?void 0:m["http://liascript.github.io/extensions/slideId"],s=null===(v=e.object.definition)||void 0===v||null===(f=v.extensions)||void 0===f?void 0:f["http://liascript.github.io/extensions/quizIndex"];this.quizStates[i]||(this.quizStates[i]={});const o=e.result||{},n=o.extensions||{},r=n["http://liascript.github.io/extensions/trial"]||0;let a=0;!0===o.success?a=1:!1===o.success&&(a=!0===o.completion?-1:0);const l={solved:a,state:n["http://liascript.github.io/extensions/state"]||[],trial:r,hint:n["http://liascript.github.io/extensions/hint"]||0,error_msg:"",score:(null===(b=o.score)||void 0===b?void 0:b.raw)||0};o.response&&(l.input=o.response),this.quizStates[i][s]=l,this.debug&&console.log(`Restored quiz state: slide ${i}, quiz ${s}`,l),void 0!==(null===(x=o.score)||void 0===x?void 0:x.raw)&&(o.success&&(this.totalScore+=o.score.raw),void 0!==o.score.max&&(this.maxScore+=o.score.max))}for(const t in L){var y,w,T,I;const e=L[t],i=null===(y=e.object.definition)||void 0===y||null===(w=y.extensions)||void 0===w?void 0:w["http://liascript.github.io/extensions/slideId"],s=null===(T=e.object.definition)||void 0===T||null===(I=T.extensions)||void 0===I?void 0:I["http://liascript.github.io/extensions/surveyIndex"];this.surveyStates[i]||(this.surveyStates[i]={});const o=e.result||{},n=o.extensions||{},r={submitted:o.completion||!1,state:n["http://liascript.github.io/extensions/state"]||{}};this.surveyStates[i][s]=r,this.debug&&console.log(`Restored survey state: slide ${i}, survey ${s}`,r)}for(const t in D){var z,j,$,k;const e=D[t],i=null===(z=e.object.definition)||void 0===z||null===(j=z.extensions)||void 0===j?void 0:j["http://liascript.github.io/extensions/slideId"],s=null===($=e.object.definition)||void 0===$||null===(k=$.extensions)||void 0===k?void 0:k["http://liascript.github.io/extensions/taskIndex"];this.taskStates[i]||(this.taskStates[i]={});const o=e.result||{},n=(o.extensions||{})["http://liascript.github.io/extensions/state"]||[];this.taskStates[i][s]=n,this.debug&&console.log(`Restored task state: slide ${i}, task ${s}`,n)}(null==E||null===(t=E.result)||void 0===t?void 0:t.duration)&&(this.accumulatedTime=this.parseDuration(E.result.duration),this.debug&&console.log("Restored accumulated time:",this.accumulatedTime,"ms (",Math.round(this.accumulatedTime/1e3),"seconds)")),this.debug&&console.log("State restoration complete:",{visitedSlides:this.visitedSlides.size,lastVisitedSlide:this.lastVisitedSlide,quizStates:Object.keys(this.quizStates).length,surveyStates:Object.keys(this.surveyStates).length,taskStates:Object.keys(this.taskStates).length,totalScore:this.totalScore,maxScore:this.maxScore,completionSent:this.completionSent,accumulatedTime:this.accumulatedTime})}catch(t){throw console.error("Error restoring state from LRS:",t),t}}}parseDuration(t){const e=t.match(/PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?/);if(!e)return 0;return 1e3*(3600*parseInt(e[1]||"0",10)+60*parseInt(e[2]||"0",10)+parseFloat(e[3]||"0"))}getTotalDuration(){return this.accumulatedTime+(Date.now()-this.startTime)}checkCompletion(){if(0===this.totalSlides)return!1;let t=0,e=0;for(const i in this.quizStates)for(const s in this.quizStates[i]){e++;0!==this.quizStates[i][s].solved&&t++}let i=0,s=0;for(const t in this.surveyStates)for(const e in this.surveyStates[t]){s++;!0===this.surveyStates[t][e].submitted&&i++}const o=this.totalSlides+e+s,n=this.visitedSlides.size+t+i;if(this.debug&&console.log("Completion check:",{visitedSlides:this.visitedSlides.size,totalSlides:this.totalSlides,completedQuizzes:t,totalQuizzes:e,completedSurveys:i,totalSurveys:s,completedItems:n,totalItems:o,progressThreshold:this.progressThreshold}),0===o)return!1;return n/o>=this.progressThreshold}sendCompletionIfNeeded(){if(!this.active||!this.lrs)return;let t=0,e=0,i=0,s=0;for(const o in this.quizStates)for(const n in this.quizStates[o]){const r=this.quizStates[o][n];switch(s=r.score||0,t+=s,r.solved){case 1:e+=s;break;case-1:i+=s}}const o=0===e?0:e/t;window.SCORE=o,this.debug&&console.log("Checking completion...",{totalSlides:this.totalSlides,visitedSlides:this.visitedSlides.size,maxScore:t,totalScore:e,quizStates:Object.keys(this.quizStates).length,completionSent:this.completionSent});const n=r.formatDuration(this.getTotalDuration()),a=this.totalSlides>0?this.visitedSlides.size/this.totalSlides:0,l=this.checkCompletion();let c;if(null==this.masteryScore)c=void 0;else{const s=i+e===t&&t>0;c=o>=this.masteryScore||0===t||(s?o>=this.masteryScore:void 0)}this.debug&&console.log("Success calculation:",{masteryScore:this.masteryScore,score:o,solved:e,finished:i,total:t,allQuizzesCompleted:i+e===t,success:c});const d=r.generateProgressedStatement(this.actor,this.courseId,this.courseTitle,a,this.registration,n,e,t,l,c);if(this.lrs.sendStatement(d).then((()=>{this.debug&&console.log(`Sent progressed statement: ${100*a}% complete, score: ${e}/${t}, completion: ${l}, success: ${c}`)})).catch((t=>{console.error("Failed to send progressed statement:",t)})),l&&!this.completionSent){const i=r.generateCompletedStatement(this.actor,this.courseId,this.courseTitle,c,e,t,n,this.registration);this.lrs.sendStatement(i).then((t=>{this.debug&&console.log("Sent completed statement, ID:",t),this.completionSent=!0})).catch((t=>{console.error("Failed to send completed statement:",t)}))}}async open(t,e,i){var s;if(!this.active||!this.lrs)return;this.startTime=Date.now(),this.lastActivityTime=this.startTime,this.completionSent=!1;const o=window;(null===(s=o.config_)||void 0===s?void 0:s.totalSlides)?(this.totalSlides=o.config_.totalSlides,this.debug&&console.log("Total slides in course:",this.totalSlides)):this.debug&&console.warn("Could not get total slides - config_.totalSlides not available");const n=r.generateInitializedStatement(this.actor,this.courseId,this.courseTitle,this.registration);this.lrs.sendStatement(n).then((t=>{this.debug&&console.log("Sent initialized statement, ID:",t)})).catch((t=>{console.error("Failed to send initialized statement:",t)})),void 0!==i&&this.slide(i),this.completionSent||this.sendCompletionIfNeeded()}slide(t){if(!this.active||!this.lrs)return;this.lastActivityTime=Date.now(),this.visitedSlides.add(t),this.lastVisitedSlide=t;let e=`Slide ${t}`;const i=window;i.LIA&&i.LIA.course&&i.LIA.course.slides[t]&&(e=i.LIA.course.slides[t].title||e);const s=r.formatDuration(this.getTotalDuration()),o=r.generateExperiencedStatement(this.actor,this.courseId,this.courseTitle,t,e,this.registration,s);this.lrs.sendStatement(o).then((t=>{this.debug&&console.log("Sent experienced statement, ID:",t),this.sendCompletionIfNeeded()})).catch((t=>{console.error("Failed to send experienced statement:",t)}))}async load(t){await this.stateRestored;const{table:e,id:i}=t;if("quiz"===e&&this.quizStates[i]){const t=[];for(const e in this.quizStates[i])t[parseInt(e)]=this.quizStates[i][e];return this.debug&&console.log(`Load quiz[${i}]:`,t.length,"items"),t}if("survey"===e&&this.surveyStates[i]){const t=[];for(const e in this.surveyStates[i])t[parseInt(e)]=this.surveyStates[i][e];return this.debug&&console.log(`Load survey[${i}]:`,t.length,"items"),t}if("task"===e&&this.taskStates[i]){const t=[];for(const e in this.taskStates[i])t[parseInt(e)]=this.taskStates[i][e];return this.debug&&console.log(`Load task[${i}]:`,t.length,"items"),t}}store(t){if(!this.active||!this.lrs||!t.data)return;this.lastActivityTime=Date.now();const{table:e,id:i,data:s}=t;return"quiz"===e?(this.quizStates[i]||(this.quizStates[i]={}),void s.forEach(((t,e)=>{if(!t)return;this.quizStates[i][e]=t,console.warn("Storing quiz:",i,e,t),void 0!==t.score&&(1===t.solved&&(this.totalScore+=t.score),this.maxScore+=t.score);const s=t.state&&"object"==typeof t.state&&Object.keys(t.state)[0]||"unknown",o=r.generateAnsweredStatement(this.actor,this.courseId,this.courseTitle,i,e,s,t.input||t.answer||"",1===t.solved||-1!==t.solved&&null,t.score||1,t.score||1,t,this.registration);this.lrs.sendStatement(o).then((()=>{this.debug&&console.log(`Sent answer: slide ${i}, quiz ${e}`),this.sendCompletionIfNeeded()})).catch((t=>console.error("Failed to send answered statement:",t)))}))):"survey"===e?(this.surveyStates[i]||(this.surveyStates[i]={}),void s.forEach(((t,e)=>{if(!t)return;this.surveyStates[i][e]=t;const s=r.generateAnsweredStatement(this.actor,this.courseId,this.courseTitle,i,e,"Survey",JSON.stringify(t.state),t.submitted,0,0,t,this.registration,e,!0);this.lrs.sendStatement(s).then((()=>{this.debug&&console.log(`Sent survey answer: slide ${i}, survey ${e}`)})).catch((t=>console.error("Failed to send survey statement:",t)))}))):"task"===e?(this.taskStates[i]||(this.taskStates[i]={}),void s.forEach(((t,e)=>{if(!t)return;this.taskStates[i][e]=t;const s=r.generateTaskStatement(this.actor,this.courseId,this.courseTitle,i,e,t,this.registration);this.lrs.sendStatement(s).then((()=>{this.debug&&console.log(`Sent task interaction: slide ${i}, task ${e}`)})).catch((t=>console.error("Failed to send task statement:",t)))}))):void 0}update(t,e){super.update(t,e),this.store(t)}reset(t,e){this.totalScore=0,this.maxScore=0,this.visitedSlides.clear(),this.lastVisitedSlide=0,this.quizStates={},this.surveyStates={},this.taskStates={},this.startTime=Date.now(),this.lastActivityTime=this.startTime,this.accumulatedTime=0,this.completionSent=!1,super.reset(t,e)}constructor(t={}){super(),(0,o.default)(this,"progressThreshold",0),(0,o.default)(this,"masteryScore",0),window.SCORE=0,this.active=!1,this.debug=t.debug||!1,this.totalScore=0,this.maxScore=0,this.visitedSlides=new Set,this.lastVisitedSlide=0,this.totalSlides=0,this.quizStates={},this.surveyStates={},this.taskStates={},this.startTime=Date.now(),this.lastActivityTime=this.startTime,this.accumulatedTime=0,this.completionSent=!1,this.registration=t.registration||this.generateUUID(),this.actor=t.actor||{objectType:"Agent",name:"Anonymous",mbox:"mailto:anonymous@example.com"},this.courseId=t.courseId||window.location.href,this.courseTitle=t.courseTitle||document.title||"LiaScript Course";try{const o=window;if(o.config_){var e,i,s,n;this.debug&&console.log("Initializing structures from config...",JSON.stringify(o.config_)),this.progressThreshold=null!==(i=null!==(e=o.config_.progressThreshold)&&void 0!==e?e:t.progressThreshold)&&void 0!==i?i:.9,this.masteryScore=null!==(n=null!==(s=o.config_.masteryThreshold)&&void 0!==s?s:t.masteryThreshold)&&void 0!==n?n:.8,this.debug&&console.log("Loaded thresholds:",{progressThreshold:this.progressThreshold,masteryScore:this.masteryScore});(o.config_.quiz||[[]]).forEach(((t,e)=>{(null==t?void 0:t.length)>0&&(this.quizStates[e]={},t.forEach(((t,i)=>{this.quizStates[e][i]=t})))}));(o.config_.survey||[[]]).forEach(((t,e)=>{(null==t?void 0:t.length)>0&&(this.surveyStates[e]={},t.forEach(((t,i)=>{this.surveyStates[e][i]=t})))}));(o.config_.task||[[]]).forEach(((t,e)=>{(null==t?void 0:t.length)>0&&(this.taskStates[e]={},t.forEach(((t,i)=>{this.taskStates[e][i]=t})))})),this.debug&&console.log("Initialized structures from config:",{quizzes:Object.keys(this.quizStates).length,surveys:Object.keys(this.surveyStates).length,tasks:Object.keys(this.taskStates).length})}else{var r,l;this.progressThreshold=null!==(r=t.progressThreshold)&&void 0!==r?r:.9,this.masteryScore=null!==(l=t.masteryThreshold)&&void 0!==l?l:.8}}catch(t){this.debug&&console.warn("Could not load config:",t)}if(t.endpoint)try{this.lrs=new a.LRSConnection(t.endpoint,t.auth||"","1.0.3",this.debug),this.active=!0,this.debug&&console.log("xAPI connector initialized with LRS endpoint:",t.endpoint),window.addEventListener("beforeunload",this.handleUnload.bind(this)),this.stateRestored=this.restoreState().catch((t=>(this.debug&&console.warn("Could not restore state from LRS:",t),Promise.resolve())))}catch(t){console.error("Failed to initialize LRS connection:",t),this.lrs=null}else console.warn("No LRS endpoint provided, xAPI tracking will be disabled"),this.lrs=null,this.stateRestored=Promise.resolve()}}})),e.register("jXXgq",(function(i,s){t(i.exports,"Connector",(function(){return r}));var o=e("3MPaZ"),n=e("ayIBF");class r{hasIndex(){return!1}storage(){return new o.LiaStorage}initSettings(t,e=!1){return n.Settings.init(t,e,this.setSettings)}setSettings(t){n.Settings.update(t)}getSettings(){let t="";try{t=localStorage.getItem(n.Settings.PORT)}catch(t){console.warn("cannot write to localStorage")}let e=null;if("string"==typeof t){try{e=JSON.parse(t)}catch(t){console.warn("getSettings =>",t)}e||(e=n.Settings.data),window.innerWidth<=768&&(e.table_of_contents=!1)}return e}open(t,e,i){}load(t){}store(t){}update(t,e){}slide(t){}getIndex(){}deleteFromIndex(t){}async storeToIndex(t){}restoreFromIndex(t,e){}reset(t,e){this.initSettings(null,!0)}async getFromIndex(t){return null}async addMisc(t,e,i,s){console.log("addMisc not implemented")}async getMisc(t,e,i){console.log("getMisc not implemented")}constructor(){}}})),e.register("3MPaZ",(function(e,i){t(e.exports,"LiaStorage",(function(){return s}));class s{getItems(t=[]){"string"==typeof t&&(t=[t]);let e={};for(let i=0;i<t.length;i++){let s=localStorage.getItem(t[i]);e[t[i]]=s?JSON.parse(s):s}return e}setItems(t){this._setLocal(t)}_setLocal(t){if("object"==typeof t)for(const[e,i]of Object.entries(t))localStorage.setItem(e,JSON.stringify(i))}constructor(){}}})),e.register("fZWR0",(function(i,s){t(i.exports,"generateInitializedStatement",(function(){return a})),t(i.exports,"generateExperiencedStatement",(function(){return l})),t(i.exports,"generateAnsweredStatement",(function(){return c})),t(i.exports,"generateTaskStatement",(function(){return d})),t(i.exports,"generateCompletedStatement",(function(){return h})),t(i.exports,"generateProgressedStatement",(function(){return u})),t(i.exports,"generateTerminatedStatement",(function(){return p})),t(i.exports,"generateSuspendedStatement",(function(){return g})),t(i.exports,"formatDuration",(function(){return S}));var o=e("dM3DM");function n(t,e){return{id:t,objectType:"Activity",definition:{type:"http://adlnet.gov/expapi/activities/course",name:{"en-US":e}}}}function r(t,e){return e&&(t.context=t.context||{},t.context.registration=e),t}function a(t,e,i,s){return r({actor:t,verb:{id:"http://adlnet.gov/expapi/verbs/initialized",display:{"en-US":"initialized"}},object:n(e,i),result:{completion:!1},timestamp:(new Date).toISOString()},s)}function l(t,e,i,s,o,a,l){const c={actor:t,verb:{id:"http://adlnet.gov/expapi/verbs/experienced",display:{"en-US":"experienced"}},object:{id:`${e}/slides/${s}`,objectType:"Activity",definition:{type:"http://adlnet.gov/expapi/activities/module",name:{"en-US":o||`Slide ${s}`},extensions:{"http://liascript.github.io/extensions/slideId":s}}},context:{contextActivities:{parent:[n(e,i)]}},timestamp:(new Date).toISOString()};return l&&(c.result={duration:l}),r(c,a)}function c(t,e,i,s,n,r,a,l,c,d,h,u,p,g=!1){const S=g?p:n,m={actor:t,verb:{id:"http://adlnet.gov/expapi/verbs/answered",display:{"en-US":"answered"}},object:{id:`${e}/slides/${s}/${g?"survey":"quiz"}/${S}`,objectType:"Activity",definition:{type:g?"http://adlnet.gov/expapi/activities/survey":"http://adlnet.gov/expapi/activities/question",name:{"en-US":g?`Slide ${s} - Survey ${S}`:"unknown"!==r?`Slide ${s} - ${r} ${n}`:`Slide ${s} - Quiz ${n}`},description:{"en-US":g?"Survey Question":"unknown"!==r?`${r} Question`:"Quiz Question"},extensions:(0,o.default)({"http://liascript.github.io/extensions/slideId":s},g?{"http://liascript.github.io/extensions/surveyIndex":S}:{"http://liascript.github.io/extensions/quizIndex":n})}},result:{success:l,completion:!g||l,response:JSON.stringify(a),score:{scaled:d>0?c/d:0,raw:c,min:0,max:d}},context:{contextActivities:{parent:[{id:`${e}/slides/${s}`,objectType:"Activity",definition:{type:"http://adlnet.gov/expapi/activities/module"}}],grouping:[{id:e,objectType:"Activity",definition:{type:"http://adlnet.gov/expapi/activities/course",name:{"en-US":i}}}]}},timestamp:(new Date).toISOString()};return u&&(m.context.registration=u),(h||g)&&(m.result.extensions={"http://liascript.github.io/extensions/state":g?h.state||{}:(null==h?void 0:h.state)||[]},!g&&h&&(m.result.extensions["http://liascript.github.io/extensions/trial"]=h.trial||0,m.result.extensions["http://liascript.github.io/extensions/hint"]=h.hint||0)),m}function d(t,e,i,s,o,n,r){const a=n.filter((t=>t)).length,l=n.length,c=l>0?a/l:0,d={actor:t,verb:{id:"http://adlnet.gov/expapi/verbs/interacted",display:{"en-US":"interacted"}},object:{id:`${e}/slides/${s}/task/${o}`,objectType:"Activity",definition:{type:"http://adlnet.gov/expapi/activities/task",name:{"en-US":`Slide ${s} - Task ${o}`},description:{"en-US":"Task List"},extensions:{"http://liascript.github.io/extensions/slideId":s,"http://liascript.github.io/extensions/taskIndex":o}}},result:{completion:1===c,score:{scaled:c,raw:a,min:0,max:l},extensions:{"http://liascript.github.io/extensions/state":n}},context:{contextActivities:{parent:[{id:`${e}/slides/${s}`,objectType:"Activity",definition:{type:"http://adlnet.gov/expapi/activities/module"}}],grouping:[{id:e,objectType:"Activity",definition:{type:"http://adlnet.gov/expapi/activities/course",name:{"en-US":i}}}]}},timestamp:(new Date).toISOString()};return r&&(d.context.registration=r),d}function h(t,e,i,s,o,a,l,c){const d={actor:t,verb:{id:"http://adlnet.gov/expapi/verbs/completed",display:{"en-US":"completed"}},object:n(e,i),result:{completion:!0,score:{scaled:a>0?o/a:0,raw:o,min:0,max:a},duration:l},timestamp:(new Date).toISOString()};return void 0!==s&&(d.result.success=s),r(d,c)}function u(t,e,i,s,o,a,l,c,d,h){const u={actor:t,verb:{id:"http://adlnet.gov/expapi/verbs/progressed",display:{"en-US":"progressed"}},object:n(e,i),result:{completion:void 0!==d?d:s>=1,score:{scaled:s,raw:Math.round(100*s),min:0,max:100},extensions:{"http://liascript.github.io/extensions/progress":s,"http://liascript.github.io/extensions/progressPercent":Math.round(100*s)}},timestamp:(new Date).toISOString()};return void 0!==h&&(u.result.success=h),a&&(u.result.duration=a),void 0!==c&&c>0&&(u.result.score={scaled:l/c,raw:l,min:0,max:c}),r(u,o)}function p(t,e,i,s,o){return r({actor:t,verb:{id:"http://adlnet.gov/expapi/verbs/terminated",display:{"en-US":"terminated"}},object:n(e,i),result:{duration:s},timestamp:(new Date).toISOString()},o)}function g(t,e,i,s,o,a,l){return r({actor:t,verb:{id:"http://adlnet.gov/expapi/verbs/suspended",display:{"en-US":"suspended"}},object:n(e,i),result:{completion:!1,duration:s,extensions:{"http://liascript.github.io/extensions/lastSlide":o,"http://liascript.github.io/extensions/progress":a,"http://liascript.github.io/extensions/progressPercent":Math.round(100*a)}},timestamp:(new Date).toISOString()},l)}function S(t){const e=Math.floor(t/1e3),i=Math.floor(e/3600),s=Math.floor(e%3600/60),o=e%60;let n="PT";return i>0&&(n+=`${i}H`),s>0&&(n+=`${s}M`),(o>0||0===i&&0===s)&&(n+=`${o}S`),n}})),e.register("iKFEu",(function(e,i){t(e.exports,"LRSConnection",(function(){return s}));class s{async sendStatement(t){try{this.debug&&console.log("Sending statement to LRS:",JSON.stringify(t,null,2));const e=this.ensureStringReferences(t);if(!this.validateStatement(e))return console.error("Invalid statement structure:",e),null;const i=await fetch(this.endpoint+"statements",{method:"POST",headers:{"Content-Type":"application/json","X-Experience-API-Version":this.version,Authorization:this.auth},body:JSON.stringify(e)});if(!i.ok)return console.error("LRS error:",i.status,await i.text()),null;const s=await i.json();return this.debug&&console.log("LRS response:",s),Array.isArray(s)&&s.length>0?s[0]:s&&"object"==typeof s&&s.id||null}catch(t){return console.error("Error sending statement to LRS:",t),null}}async sendStatements(t){try{this.debug&&console.log("Sending statements to LRS:",JSON.stringify(t,null,2));const e=t.map((t=>this.ensureStringReferences(t))),i=await fetch(this.endpoint+"statements",{method:"POST",headers:{"Content-Type":"application/json","X-Experience-API-Version":this.version,Authorization:this.auth},body:JSON.stringify(e)});if(!i.ok)return console.error("LRS error:",i.status,await i.text()),[];const s=await i.json();return this.debug&&console.log("LRS response:",s),Array.isArray(s)?s:[]}catch(t){return console.error("Error sending statements to LRS:",t),[]}}async getStatements(t={}){try{const e=new URLSearchParams;for(const[i,s]of Object.entries(t))null!=s&&("object"==typeof s?e.append(i,JSON.stringify(s)):e.append(i,String(s)));const i=`${this.endpoint}statements${e.toString()?`?${e.toString()}`:""}`;this.debug&&console.log("Getting statements from LRS:",i);const s=await fetch(i,{method:"GET",headers:{"X-Experience-API-Version":this.version,Authorization:this.auth}});if(!s.ok)return console.error("LRS error:",s.status,await s.text()),null;const o=await s.json();return this.debug&&console.log("LRS response:",o),o}catch(t){return console.error("Error getting statements from LRS:",t),null}}async testConnection(){try{let t=this.endpoint;t.includes("api/v2/statements")?t=t.replace("api/v2/statements","api/v2/about"):t.endsWith("/statements")&&(t=t.replace("/statements","/about"));return(await fetch(t,{method:"GET",headers:{"X-Experience-API-Version":this.version,Authorization:this.auth}})).ok}catch(t){return console.error("Error testing LRS connection:",t),!1}}ensureStringReferences(t){if(null==t)return t;if("object"==typeof t){if(Array.isArray(t))return t.map((t=>this.ensureStringReferences(t)));{const e={};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=this.ensureStringReferences(t[i]));return e}}return"function"==typeof t?t.toString():t}validateStatement(t){return!!t&&(!(!t.actor||"object"!=typeof t.actor)&&(!(!t.verb||"object"!=typeof t.verb||!t.verb.id||"string"!=typeof t.verb.id)&&!(!t.object||"object"!=typeof t.object||!t.object.id||"string"!=typeof t.object.id)))}constructor(t,e,i="1.0.3",s=!1){this.endpoint=t.endsWith("/")?t:t+"/",this.endpoint.endsWith("statements/")&&(this.endpoint=this.endpoint.slice(0,-11)),this.auth=e,this.version=i,this.debug=s,this.debug&&console.log("LRS endpoint configured as:",this.endpoint)}}}));