UNPKG

@liascript/exporter

Version:
2 lines (1 loc) 7.98 kB
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("1jVc2",(function(i,s){t(i.exports,"Connector",(function(){return c}));var n=e("jXXgq"),r=e("ayIBF"),o=e("5aa3i");class c extends n.Connector{scanForAPI(t){let e=0;try{for(;null==t.API_1484_11&&null!=t.parent&&t.parent!=t;){if(e++,e>500)return null;t=t.parent}return t.API_1484_11}catch(t){l("scanForAPI =>",t.message)}return null}getAPI(t){let e=null;return null!=t.parent&&t.parent!=t&&(e=this.scanForAPI(t.parent)),null==e&&null!=t.opener&&(e=this.scanForAPI(t.opener)),e}initSettings(t,e=!1){return r.Settings.init(t,!1,this.setSettings)}setSettings(t){this.active&&this.scorm?this.write("cmi.suspend_data",JSON.stringify(t)):l('cannot write to "cmi.suspend_data"')}getSettings(){let t="";try{var e;t=(null===(e=this.scorm)||void 0===e?void 0:e.GetValue("cmi.suspend_data"))||null}catch(t){l("cannot write settings to cmi.suspend_data")}let i=null;if("string"==typeof t){try{i=JSON.parse(t)}catch(t){l("getSettings =>",t)}i||(i=r.Settings.data),window.innerWidth<=768&&(i.table_of_contents=!1)}return i}init(){if(this.scorm){a("Initialize ",this.scorm.Initialize(""));let t=this.scorm.GetValue("cmi.mode")||"undefined";this.active="normal"===t||"undefined"===t,l('Running in "'+t+'" mode, results will '+(this.active?"":"NOT")+" be stored!"),this.active&&(this.scaled_passing_score=o.jsonParse(this.scorm.GetValue("cmi.scaled_passing_score")),this.scaled_passing_score||(this.scaled_passing_score=window.MASTERY_SCORE||null),null===this.scorm.GetValue("cmi.completion_status")&&this.write("cmi.completion_status","incomplete"),a("open location ..."),this.location=o.jsonParse(this.scorm.GetValue("cmi.location")),a("... ",this.location)),null===this.location&&this.slide(0);const e=this.countInteractions();if(!this.active||0!==e&&null!==e){let t=0;t=this.initSecond("quiz",t),t=this.initSecond("survey",t),t=this.initSecond("task",t)}else{let t=0;t=this.initFirst("quiz",t),t=this.initFirst("survey",t),t=this.initFirst("task",t)}window.SCORE=0,this.score()}}initFirst(t,e){for(let i=0;i<this.db[t].length;i++){this.id[t].push([]);for(let s=0;s<this.db[t][i].length;s++)this.setInteraction(e,`${t}:${i}-${s}`),this.id[t][i].push(e),e++}return e}countInteractions(){if(!this.scorm)return null;return parseInt(this.scorm.GetValue("cmi.interactions._count"))||null}initSecond(t,e){for(let i=0;i<this.db[t].length;i++){this.id[t].push([]);for(let s=0;s<this.db[t][i].length;s++){let n=this.getInteraction(e);n&&(this.db[t][i][s]=n),this.id[t][i].push(e),e++}}return e}open(t,e,i){if(null!==this.location){const t=this.location;setTimeout((function(){window.LIA.goto(t)}),500)}}load(t){switch(t.table){case"quiz":case"survey":case"task":return a("loading ",t.table,t.id,this.db[t.table][t.id]),this.db[t.table][t.id]}}store(t){if(this.active)switch(t.table){case"quiz":this.storeHelper(t),this.score();break;case"survey":case"task":this.storeHelper(t)}}storeHelper(t){for(let e=0;e<this.db[t.table][t.id].length;e++)o.neq(t.data[e],this.db[t.table][t.id][e])&&(this.updateInteraction(this.id[t.table][t.id][e],t.data[e]),this.db[t.table][t.id][e]=t.data[e],"quiz"==t.table&&this.updateQuiz(this.id[t.table][t.id][e],t.data[e]))}score(){if(!this.active||!this.scaled_passing_score)return;let t=0,e=0,i=0,s=0;for(let n=0;n<this.db.quiz.length;n++)for(let r=0;r<this.db.quiz[n].length;r++)switch(s=this.db.quiz[n][r].score,t+=s,this.db.quiz[n][r].solved){case 1:e+=s;case-1:i+=s}const n=0===e?0:e/t;this.write("cmi.score.min","0"),this.write("cmi.score.max",JSON.stringify(t)),this.write("cmi.score.scaled",JSON.stringify(n)),this.write("cmi.score.raw",JSON.stringify(e)),n>=this.scaled_passing_score?(this.write("cmi.success_status","passed"),this.write("cmi.completion_status","completed")):i+e===t?(this.write("cmi.success_status","failed"),this.write("cmi.completion_status","completed")):this.write("cmi.completion_status","incomplete"),window.SCORE=n}write(t,e){if(this.scorm&&this.active){if(a("write: ",t,e),"false"===this.scorm.SetValue(t,e)){l("error occurred for",t,e);let i=this.scorm.GetLastError();l("GetLastError:",i),i?(l("GetErrorString:",this.scorm.GetErrorString(i)),l("GetDiagnostic:",this.scorm.GetDiagnostic(i))):l("GetDiagnostic:",this.scorm.GetDiagnostic(""))}this.scorm.Commit("")}}slide(t){this.location=t,this.write("cmi.location",JSON.stringify(t))}setInteraction(t,e){this.write(`cmi.interactions.${t}.id`,e),this.write(`cmi.interactions.${t}.type`,"long-fill-in")}updateQuiz(t,e){if(this.active)switch(e.solved){case 0:e.trial>0&&this.write(`cmi.interactions.${t}.result`,"incorrect");break;case 1:this.write(`cmi.interactions.${t}.result`,"correct");break;case-1:this.write(`cmi.interactions.${t}.result`,"neutral")}}updateInteraction(t,e){this.write(`cmi.interactions.${t}.learner_response`,o.encodeJSON(e))}getInteraction(t){try{if(this.scorm){let e=this.scorm.GetValue(`cmi.interactions.${t}.learner_response`);if(""!==e)return o.decodeJSON(e)}}catch(t){l("getInteraction => ",t)}return null}constructor(){super(),this.active=!1,this.scaled_passing_score=null,this.db={quiz:[],survey:[],task:[]},this.id={quiz:[],survey:[],task:[]};let t=this.getAPI(window);if(t){a("successfully opened API"),this.scorm=t,a("loading quizzes ...");try{this.db.quiz=window.config_.quiz||[[]],a(" ... done")}catch(t){l("... failed",t)}a("loading surveys ...");try{this.db.survey=window.config_.survey||[[]],a(" ... done")}catch(t){l("... failed",t)}a("loading tasks ...");try{this.db.task=window.config_.task||[[]],a(" ... done")}catch(t){l("... failed",t)}this.init()}else l("Could not find API")}}function a(...t){console.log("SCORM2004: ",...t)}function l(...t){console.log("SCORM2004: ",...t)}})),e.register("jXXgq",(function(i,s){t(i.exports,"Connector",(function(){return o}));var n=e("3MPaZ"),r=e("ayIBF");class o{hasIndex(){return!1}storage(){return new n.LiaStorage}initSettings(t,e=!1){return r.Settings.init(t,e,this.setSettings)}setSettings(t){r.Settings.update(t)}getSettings(){let t="";try{t=localStorage.getItem(r.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=r.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("5aa3i",(function(e,i){t(e.exports,"encodeJSON",(function(){return o})),t(e.exports,"decodeJSON",(function(){return c})),t(e.exports,"jsonParse",(function(){return a})),t(e.exports,"neq",(function(){return l}));const s={SingleChoice:"sc",MultipleChoice:"mc",Text:"tx",Select:"st",Matrix:"mx",Generic:"gn",error_msg:"err"},n=Object.entries(s).reduce(((t,[e,i])=>(t[i]=e,t)),{});function r(t,e){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))return t.map((t=>r(t,e)));const i={};for(const[s,n]of Object.entries(t))i[e[s]||s]=r(n,e);return i}function o(t){return JSON.stringify(r(t,s))}function c(t){return r(JSON.parse(t),n)}function a(t){try{return JSON.parse(t)}catch(t){}return null}function l(t,e){return JSON.stringify(t)!=JSON.stringify(e)}}));