var PAGES=["pageInfos","pageSource","pageMfd1","pageMfd2"],pagePos=[0,0,0,0,0],ANIMATION_INTERVAL=25,FEEDBACK_DURATION=500,PAGE_TRANSITION=500,SWIPE_DELAY=250,SWIPE_DIST=100,pageIndex=0,touchStartX=-1,touchStartY=-1,touchStartTime=-1;function displayCheck(a){let b=document.getElementById(a);b.setAttribute("class","mu check");setTimeout(()=>b.setAttribute("class","mu"),FEEDBACK_DURATION)}
function doDisplay(){let a=source.Mocodo.load(document.getElementById("source").value+"\n"),b=getOptionValue("mfd1");document.getElementById("mfd1title").innerHTML=b;let c=getOptionValue("mfd2");document.getElementById("mfd2title").innerHTML=c;if(null!=a){let d=transform.DiagramToMLD.transform(a);transform.DiagramToUML.transform(a);document.getElementById("mfd1").innerHTML=generateContent(a,d,b);document.getElementById("mfd2").innerHTML=generateContent(a,d,c)}else document.getElementById("mfd1").innerHTML=
"",document.getElementById("mfd2").innerHTML=""}function download(a,b){let c=document.createElement("a");c.setAttribute("href",b);c.setAttribute("download",a);c.style.display="none";document.getElementById("body").appendChild(c);c.click();document.getElementById("body").removeChild(c)}
function generateContent(a,b,c){let d="";if("MCD"==c||"Tables"==c||"UML"==c.substr(0,3))d="MCD"==c?schema.MCDToSVG.generateSVG(a).toString():"UML-Domaine"==c?schema.UMLToSVG.generateSVG(a,!1,!0).toString():"UML-Classes"==c?schema.UMLToSVG.generateSVG(a,!0,!0).toString():"UML-API"==c?schema.UMLToSVG.generateSVG(a,!0,!1).toString():schema.MLDToSVG.generateSVG(b,!0).toString();else if("MR-EN"==c)d="<pre>"+b.toString(!1)+"</pre>";else if("MR-Univ"==c)d="<pre>"+b.toString(!0)+"</pre>",d=d.replaceAll("\u001b[4m",
'<span style="text-decoration:underline">'),d=d.replaceAll("\u001b[1m",'<span style="font-weight:bold">'),d=d.replaceAll("\u001b[0m","</span>");else if("MLD"==c)d=schema.MLDToSVG.generateSVG(b,!1).toString();else if("SQL-MariaDB"==c||"SQL-PostgreSQL"==c||"SQL-Sqlite"==c){a=null;switch(c){case "SQL-MariaDB":a=database.DBMariaDB.generateSQL(b);break;case "SQL-PostgreSQL":a=database.DBPostgreSQL.generateSQL(b);break;case "SQL-Sqlite":a=database.DBSqlite.generateSQL(b)}c="";for(var e of a.split("\n"))c=
0==e.indexOf("CREATE")?c+e.replaceAll(", ",",\n    ").replace(" ("," (\n    ").replace(");","\n);\n\n"):c+(e+"\n\n");c=c.substring(0,c.length-3);d="<pre>"+c+"</pre>"}else if("Haxe"==c||"Java"==c||"PHP"==c||"Python"==c){e=null;switch(c){case "Haxe":e=code.HaxeCode.generate(a);break;case "Java":e=code.JavaCode.generate(a);break;case "PHP":e=code.PhpCode.generate(a);break;case "Python":e=code.PythonCode.generate(a)}d="<div>";for(let f in e.h)d+="<h3>"+f+"</h3><pre>"+e.h[f].replace(/</g,"&lt;")+"</pre>";
d+="</div>"}return d}function getContent(a,b=!1){a=document.getElementById(a);"TEXTAREA"==a.nodeName.toUpperCase()?b=a.value:"SVG"==a.firstChild.nodeName.toUpperCase()?b=a.innerHTML:"PRE"==a.firstChild.nodeName.toUpperCase()?b?(b=a.firstChild.innerHTML,b=b.replaceAll('<span style="text-decoration:underline">',"\u001b[4m"),b=b.replaceAll('<span style="font-weight:bold">',"\u001b[1m"),b=b.replaceAll("</span>","\u001b[0m")):b=a.innerHTML:b=b?a.firstChild.innerText:a.firstChild.innerHTML;return b}
function getFilename(a,b){let c=document.getElementById(a);"TEXTAREA"==c.nodeName.toUpperCase()?-1==b.indexOf(".")&&(b+=".dbc"):"PRE"==c.firstChild.nodeName.toUpperCase()?-1!=getOptionValue(a).indexOf("SQL")?b.endsWith(".sql")||(b+=".sql"):-1==b.indexOf(".")&&(b+=".txt"):"SVG"==c.firstChild.nodeName.toUpperCase()?b.endsWith(".svg")||(b+=".svg"):"DIV"==c.firstChild.nodeName.toUpperCase()&&(b.endsWith(".zip")||(b+=".zip"));return b}
function getMimeType(a){let b="text/plain",c=document.getElementById(a);0!=c.childNodes.length&&"SVG"==c.firstChild.nodeName.toUpperCase()?b="image/svg+xml":-1!=getOptionValue(a).indexOf("SQL")&&(b="application/sql");return b}function getOptionValue(a){let b="";a=document.getElementsByName(a);for(let c=0;c<a.length;c++)if(a[c].checked){b=a[c].value;break}return b}
function loadExample(a,b,c){let d="";"evaluation"==a?d=":\nPersonne: id [COUNTER], nom, prenom\n/XT\\ Personne - \u00c9tudiant, Professeur\n\n\u00c9tudiant: classe\n:\nProfesseur: mati\u00e8re\n\n\u00c9valuation, 0N \u00c9tudiant, 0N Devoir: note [FLOAT]\n:\n\u00c9valuer, 0N> Professeur, 11 \u00c9valuation\n\nDevoir: id [COUNTER], dateDevoir [DATE], titre":"facturation"==a?d="Commande: idCommande [COUNTER], dateCommande [DATE]\nCommander, 0N Client, 11 Commande\nClient: idClient [COUNTER], nom, pr\u00e9nom, rue, ville, code postal [CHAR(5)]\n\nComprendre, 0N Commande, _11 LigneCommande\n:\nParrainer, 0N> [parrain] Client, 01 Client\n\nLigneCommande: noLigne [INT], qte [INT], prixAchat [FLOAT]\nConcerner, 11 LigneCommande, 0N> Produit\nProduit: r\u00e9f\u00e9rence [CHAR(4)], libell\u00e9, prixCatalogue [FLOAT]":
"bibliotheque"==a?d="Oeuvre: id [COUNTER], titre, resume [TEXT]\nEtreDisponible, _11 Exemplaire, 0N Oeuvre\nExemplaire: no [INT], dateAchat [DATE]\n\nRevue: frequenceParution [INT]\nLivre: dateParution, isbn\nConcerner, 11 Emprunt, 0N Exemplaire\n\nAbonne: id [COUNTER], nom, prenom\nEffectuer, 11 Emprunt, 0N Abonne\nEmprunt: id [COUNTER], dateEmprunt [DATE], dateRetour [DATE]\n\n/X\\ Oeuvre - Revue, Livre":"filepile"==a&&(d="File:\nPile: -_elements [Array<T>]\n\nElement: +_valeur [T]\nSuivre, 01 Element, +01> [suivant] Element\n\nAvoirPourTete, 01 File, o-01> [tete] Element\nAvoirPourQueue, 01 File, o-01> [queue] Element\n\nFile(): (), estVide() [Bool], taille() [Int], enfiler(o [T]), defiler() [T]\nPile(): estVide() [Bool], taille() [Int], empiler(o [T]), depiler() [T]");
document.getElementById("source").value=d;setOptionValue("mfd1",b);setOptionValue("mfd2",c);doDisplay();on_page_change(1)}function loadFile(a){let b=new FileReader;b.onloadend=function(){document.getElementById("source").value=b.result;on_view_change(1);doDisplay()};b.readAsText(a,"utf-8")}
function on_body_load(){function a(){setTimeout(function(){window.innerWidth<window.innerHeight?(document.getElementById("body").removeEventListener("touchstart",on_pointerdown),document.getElementById("body").removeEventListener("touchmove",on_pointermove),document.getElementById("body").removeEventListener("touchend",on_pointerup),document.getElementById("body").removeEventListener("wheel",on_wheel)):(document.getElementById("body").addEventListener("touchstart",on_pointerdown),document.getElementById("body").addEventListener("touchmove",
on_pointermove),document.getElementById("body").addEventListener("touchend",on_pointerup),document.getElementById("body").addEventListener("wheel",on_wheel))},300)}let b=new URLSearchParams(window.location.search),c=window.location.search.substring(1);b.has("mfd1")&&setOptionValue("mfd1",b.get("mfd1"));b.has("mfd2")&&setOptionValue("mfd2",b.get("mfd2"));b.has("source")?document.getElementById("source").value=b.get("source"):""!=c&&(document.getElementById("source").value=decodeURI(c));doDisplay();
window.onorientationchange=a;a();""!=document.getElementById("source").value&&on_view_change(1)}
function on_copy(a){function b(){let c=document.getElementById(a),d=null;d="TEXTAREA"==c.nodeName.toUpperCase()||"SVG"==c.firstChild.nodeName.toUpperCase()?new ClipboardItem({["text/plain"]:new Blob([getContent(a)],{type:"text/plain"})}):new ClipboardItem({["text/plain"]:new Blob([getContent(a,!0)],{type:"text/plain"}),["text/html"]:new Blob([getContent(a)],{type:"text/html"})});navigator.clipboard.write([d]).then(function(){displayCheck(a+"Copy")},function(e){console.log(e)})}navigator.permissions.query({name:"clipboard-write"}).then(c=>
{"granted"!=c.state&&"prompt"!=c.state||b()},c=>{b()})}function on_download(a){let b=prompt("Nom du fichier :","");if(null!=b&&""!=b)if(b=getFilename(a,b),"TEXTAREA"!=document.getElementById(a).nodeName.toUpperCase()&&"DIV"==document.getElementById(a).firstChild.nodeName.toUpperCase()){let c=b.substring(0,b.length-4);download(b,"data:application/zip;base64,"+JsZip.zip(a,c))}else download(b,"data:"+getMimeType(a)+";charset=utf-8,"+encodeURIComponent(getContent(a,!0)))}
function on_drag_file(a){a.stopPropagation();a.preventDefault();a.dataTransfer.dropEffect="copy"}function on_drop_file(a){a.stopPropagation();a.preventDefault();1==a.dataTransfer.files.length&&loadFile(a.dataTransfer.files.item(0))}function on_page_change(a){a=pageIndex+1*a;-1<a&&a<PAGES.length-1&&on_view_change(a)}
function on_pointerdown(a){touchStartX=a.changedTouches[0].pageX;touchStartY=a.changedTouches[0].pageY;touchStartTime=(new Date).getTime();for(a=0;a<PAGES.length;a++)pagePos[a]=document.getElementById(PAGES[a]).getBoundingClientRect().left}
function on_pointermove(a){let b=a.target;for(;"pageContent"!=b.getAttribute("class")&&null!=b.parentNode;)b=b.parentNode;let c=touchStartX-a.changedTouches[0].pageX;a=touchStartY-a.changedTouches[0].pageY;if(1==b.clientWidth-b.scrollWidth&&Math.abs(c)>Math.abs(a))for(i=0;i<PAGES.length;i++)document.getElementById(PAGES[i]).style.left=pagePos[i]-c+"px"}
function on_pointerup(a){let b=touchStartX-a.changedTouches[0].pageX,c=(new Date).getTime()-touchStartTime,d=Math.round(c/Math.abs(b)*(window.innerWidth/2-Math.abs(b)));Math.abs(b)>SWIPE_DIST&&c<SWIPE_DELAY?(0<b&&pageIndex!=PAGES.length-2?on_view_change(pageIndex+1,d):0>b&&0!=pageIndex?on_view_change(pageIndex-1,d):on_view_change(pageIndex,PAGE_TRANSITION/2),a.preventDefault()):on_view_change(pageIndex,PAGE_TRANSITION/2);touchStartX=-1}
function on_select_file(a){1==a.files.length&&loadFile(a.files.item(0))}function on_share(){var a=encodeURI(document.getElementById("source").value);a="?mfd1="+getOptionValue("mfd1")+"&mfd2="+getOptionValue("mfd2")+"&source="+a;window.history.replaceState({},document.title,a);navigator.clipboard.writeText(document.URL+a);displayCheck("sourceShare")}
function on_source_change(){""!=window.location.search&&window.history.replaceState({},document.title,window.location.href.substring(0,window.location.href.length-window.location.search.length));doDisplay()}function on_fullscreen(a){window.open(URL.createObjectURL(new Blob([document.getElementById(a).innerHTML],{type:getMimeType(a)+";charset=utf-8"})))}
function on_view_change(a,b=PAGE_TRANSITION){for(let c=0;c<PAGES.length;c++){let d=document.getElementById(PAGES[c]);d.style.transition="left "+b+"ms";d.style.left=50*(c-a)+"%"}pageIndex=a;setTimeout(function(){0==pageIndex?(document.getElementById("prev1").style.visibility="hidden",document.getElementById("next1").style.visibility="visible"):(document.getElementById("prev1").style.visibility="visible",document.getElementById("next1").style.visibility="hidden");1==pageIndex?(document.getElementById("prev2").style.visibility=
"hidden",document.getElementById("next2").style.visibility="visible"):(document.getElementById("prev2").style.visibility="visible",document.getElementById("next2").style.visibility="hidden")},b)}function on_wheel(a){a.shiftKey&&(0<a.deltaY&&pageIndex!=PAGES.length-2?on_view_change(pageIndex+1):0>a.deltaY&&0!=pageIndex&&on_view_change(pageIndex-1))}function setOptionValue(a,b){a=document.getElementsByName(a);for(let c=0;c<a.length;c++)a[c].checked=a[c].value==b?!0:!1};
