UNPKG

@liascript/exporter

Version:
2 lines (1 loc) 8.47 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("1FNwj",(function(i,s){t(i.exports,"Connector",(function(){return a}));var n=e("jXXgq"),o=e("ayIBF"),r=e("5aa3i"),c=e("fVQ47");class a extends n.Connector{init(){if(this.scorm){let t=this.scorm.LMSGetValue("cmi.core.lesson_mode")||"unknown";this.active="normal"===t||"unknown"===t,u('Running in "'+t+'" mode, results will'+(this.active?" ":" NOT ")+"be stored!"),l("open location ..."),this.location=r.jsonParse(this.scorm.LMSGetValue("cmi.core.lesson_location")),l("... ",this.location||0),null===this.location&&this.slide(0);let e=0;0===this.countObjectives()&&this.active?(l("seeding values ..."),e=this.initFirst("quiz",e),e=this.initFirst("survey",e),e=this.initFirst("task",e),l("... done")):(l("restoring values ..."),e=this.initSecond("quiz",e),e=this.initSecond("survey",e),e=this.initSecond("task",e),l("... done")),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.setObjective(e,this.db[t][i][s]),this.id[t][i].push(e),e++}return e}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.getObjective(e);n&&(this.db[t][i][s]=n),this.id[t][i].push(e),e++}}return e}score(){var t;if(!this.active||!this.score)return;let e=0,i=0,s=0,n=0;for(let t=0;t<this.db.quiz.length;t++)for(let o=0;o<this.db.quiz[t].length;o++)switch(n=this.db.quiz[t][o].score,e+=n,this.db.quiz[t][o].solved){case 1:i+=n;case-1:s+=n}const o=0===i?0:i/e;this.write("cmi.core.score.min","0"),this.write("cmi.core.score.max","100"),this.write("cmi.core.score.raw",function(t){const e=t.toFixed(4),[i,s]=e.toString().split(".");return`${i}.${s.padEnd(10,"0")}`}(100*o));let c=r.jsonParse((null===(t=this.scorm)||void 0===t?void 0:t.LMSGetValue("cmi.student_data.mastery_score"))||"null");null==c?this.write("cmi.core.lesson_status","not attempted"):o>=c/100?this.write("cmi.core.lesson_status","passed"):s+i===e?this.write("cmi.core.lesson_status","failed"):this.write("cmi.core.lesson_status","incomplete"),window.SCORE=o}open(t,e,i){if(null!==this.location){const t=this.location;setTimeout((function(){window.LIA.goto(t)}),500)}}slide(t){this.location=t,this.scorm&&this.active&&(this.scorm.LMSSetValue("cmi.core.lesson_location",JSON.stringify(t)),this.scorm.LMSCommit(""))}countObjectives(){return this.scorm?parseInt(this.scorm.LMSGetValue("cmi.objectives._count"))||0:null}initSettings(t,e=!1){return o.Settings.init(t,!1,this.setSettings)}setSettings(t){this.write("cmi.suspend_data",JSON.stringify(t))}getSettings(){let t="";try{var e;t=(null===(e=this.scorm)||void 0===e?void 0:e.LMSGetValue("cmi.suspend_data"))||null}catch(t){u("cannot read settings from cmi.suspend_data")}let i=null;if("string"==typeof t){try{i=JSON.parse(t)}catch(t){u("getSettings =>",t)}i||(i=o.Settings.data),window.innerWidth<=768&&(i.table_of_contents=!1)}return i}write(t,e){if(this.scorm){this.escape&&(e=e.replace(/"/g,'\\"'));try{this.scorm.LMSSetValue(t,e),this.scorm.LMSCommit("")}catch(i){if(u("Failed to write =>",t,e),u("Message:",i.message),void 0===this.escape){e=e.replace(/"/g,'\\"');try{this.scorm.LMSSetValue(t,e),this.scorm.LMSCommit(""),this.escape=!0}catch(t){this.escape=!1}}}}else u("could not write",t,e)}getObjective(t){let e;try{if(this.scorm&&(e=this.scorm.LMSGetValue(`cmi.objectives.${t}.id`),e))return r.decodeJSON(e)}catch(i){u("getObjective =>",i,`cmi.objectives.${t}.id`,e)}return null}setObjective(t,e){const i=r.encodeJSON(e);i.length>255&&u(`cmi.objectives.${t}.id`,"Content exceeds 256Bytes!"),this.write(`cmi.objectives.${t}.id`,i)}load(t){switch(t.table){case"quiz":case"survey":case"task":return l("loading ",t.table,t.id,this.db[t.table][t.id]),this.db[t.table][t.id]}}store(t){if(this.active)switch(u("store",t),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++)r.neq(t.data[e],this.db[t.table][t.id][e])&&(this.setObjective(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]))}updateQuiz(t,e){if(this.active)switch(e.solved){case 0:e.trial>0&&this.write(`cmi.objectives.${t}.status`,"failed");break;case 1:this.write(`cmi.objectives.${t}.status`,"completed");break;case-1:this.write(`cmi.objectives.${t}.status`,"incomplete")}}constructor(){var t;if(super(),this.active=!1,this.db={quiz:[],survey:[],task:[]},this.id={quiz:[],survey:[],task:[]},console.warn("Hello, this is LiaScript from within a SCORM 1.2 package. You should definitely try out the SCORM 2004 exporter, since this one cannot be used to store states or any kind of progress. The only thing that is stores, is currently the user location...\n\nIF YOU ARE AN ELABORATE AND EXPERIENCED SCORM DEVELOPER?\n========================================================\n\nAnd you want to help us, to extend this service, please contact us via LiaScript@web.de\n\nHave fun ;-)"),window.API||window.top&&window.top.API?this.scorm=window.API||(null===(t=window.top)||void 0===t?void 0:t.API):this.scorm=(0,c.getAPI)(),this.scorm){l("successfully opened API"),l("LMSInitialize",this.scorm.LMSInitialize("")),l("loading quizzes ...");try{this.db.quiz=window.config_.quiz||[[]],l(" ... done")}catch(t){u("... failed",t)}l("loading surveys ...");try{this.db.survey=window.config_.survey||[[]],l(" ... done")}catch(t){u("... failed",t)}l("loading tasks ...");try{this.db.task=window.config_.task||[[]],l(" ... done")}catch(t){u("... failed",t)}this.init()}}}function l(...t){console.log("SCORM1.2: ",...t)}function u(...t){console.log("SCORM1.2: ",...t)}})),e.register("jXXgq",(function(i,s){t(i.exports,"Connector",(function(){return r}));var n=e("3MPaZ"),o=e("ayIBF");class r{hasIndex(){return!1}storage(){return new n.LiaStorage}initSettings(t,e=!1){return o.Settings.init(t,e,this.setSettings)}setSettings(t){o.Settings.update(t)}getSettings(){let t="";try{t=localStorage.getItem(o.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=o.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 r})),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 o(t,e){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))return t.map((t=>o(t,e)));const i={};for(const[s,n]of Object.entries(t))i[e[s]||s]=o(n,e);return i}function r(t){return JSON.stringify(o(t,s))}function c(t){return o(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)}})),e.register("fVQ47",(function(e,i){t(e.exports,"getAPI",(function(){return o}));var s=0;function n(t){for(;null==t.API&&null!=t.parent&&t.parent!=t;){if(++s>7)return alert("Error finding API -- too deeply nested."),null;t=t.parent}return t.API}function o(){var t=n(window);return null==t&&null!=window.opener&&void 0!==window.opener&&(t=n(window.opener)),null==t&&alert("Unable to find the SCORM1.2 API adapter"),t}}));