HEX
Server: Apache
System: Linux vps.mmtprep.com 4.18.0-477.21.1.el8_8.x86_64 #1 SMP Thu Aug 10 13:51:50 EDT 2023 x86_64
User: mmtprep (1001)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/mmtprep/public_html/mathzen.mmtprep.com/assets/lists-YefISH3E.js.map
{"version":3,"file":"lists-YefISH3E.js","sources":["../../src/lib/format/lists.ts"],"sourcesContent":["import { getUniqueStringBasedOnTimeStamp } from '../components/time.js'\nimport { context } from '../../modules/context.js'\n\nconst unorderedListTypes: string[] = ['puces', 'carres', 'qcm', 'fleches']\nconst orderedListTypes: string[] = [\n  'nombres',\n  'alpha',\n  'Alpha',\n  'roman',\n  'Roman'\n]\ntype ListStyle =\n  | 'none'\n  | 'puces'\n  | 'carres'\n  | 'qcm'\n  | 'fleches'\n  | 'nombres'\n  | 'alpha'\n  | 'Alpha'\n  | 'roman'\n  | 'Roman'\nexport type DescriptionItem = {\n  /**\n   * Entête de la description\n   */\n  description: string\n  /**\n   * Texte de la description\n   */\n  text: string\n}\n\nexport type List<T> = {\n  /**\n   * Entrée de la liste ou déclaration d'une autre liste\n   */\n  items: (string | DescriptionItem | T)[]\n  /**\n   * Style pour les puces ou les numérotations. Sera ajouté à `class` et traité par `app.css`\n   */\n  style: ListStyle\n  /**\n   * Options (optionnelles) de mise en forme pour la liste à ajouter `class`\n   */\n  classOptions?: string\n  /**\n   * Texte (optionnel) précédent la liste\n   */\n  introduction?: string\n}\n\ninterface NestedList extends List<NestedList> { }\n\n/**\n * Vérifier si le type d'un objet est bien `DescriptionItem`\n * (`typeof` ne fonctionnant pas pour les types maison)\n * @see https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates\n * @param item Objet à controller\n * @returns `true` si l'objet est de type `DescriptionItem`\n */\nexport function isDescriptionItem (\n  item: DescriptionItem | NestedList\n): item is DescriptionItem {\n  return (item as DescriptionItem).description !== undefined\n}\n\n/**\n * Contruit une liste formattée suivant un style à partir d'un tableau de chaînes de caractères comme entrées.\n * @param {NestedList} list Objet décrivant la liste\n * @returns {HTMLUListElement|HTMLOListElement|string} chaîne représentant le code HTML ou LaTeX à afficher suivant la variable `context.isHtml`\n * @author sylvain\n */\nexport function createList (\n  list: NestedList,\n  shift: string = ''\n): HTMLUListElement | HTMLOListElement | string {\n  let theList: HTMLUListElement | HTMLOListElement | string\n  if (context.isHtml) {\n    switch (list.style) {\n      case 'none':\n      case 'puces':\n      case 'carres':\n      case 'qcm':\n      case 'fleches':\n        theList = document.createElement('ul')\n        break\n      case 'nombres':\n      case 'alpha':\n      case 'Alpha':\n      case 'roman':\n      case 'Roman':\n        theList = document.createElement('ol')\n        break\n      default:\n        theList = document.createElement('ul')\n        break\n    }\n    theList.setAttribute('class', list.style + ' ' + list.classOptions)\n\n    for (const item of list.items) {\n      const li: HTMLLIElement = document.createElement('li')\n      if (typeof item === 'string') {\n        li.appendChild(document.createTextNode(item))\n      } else if (isDescriptionItem(item)) {\n        const span = document.createElement('span')\n        span.setAttribute(\n          'id',\n          'list-item-description-' + getUniqueStringBasedOnTimeStamp('i')\n        )\n        const description = document.createTextNode(item.description)\n        const text = document.createTextNode(item.text)\n        span.appendChild(description)\n        li.appendChild(span)\n        li.appendChild(text)\n      } else {\n        if (item.introduction) {\n          li.appendChild(document.createTextNode(item.introduction))\n        }\n        li.appendChild(createList(item) as HTMLUListElement | HTMLOListElement)\n      }\n      theList.appendChild(li)\n    }\n  } else {\n    theList = ''\n    let label: string\n    let openingTag: string = ''\n    let closingTag: string = ''\n    switch (list.style) {\n      case 'none':\n        label = ''\n        openingTag = ''\n        closingTag = ''\n        break\n      case 'puces':\n        label = '$\\\\bullet$'\n        break\n      case 'carres':\n        label = '\\\\tiny$\\\\blacksquare$'\n        break\n      case 'qcm':\n        label = '$\\\\square$'\n        break\n      case 'fleches':\n        label = '\\\\tiny$\\\\blacktriangleright$'\n        break\n\n      case 'nombres':\n        label = '\\\\arabic*.'\n        break\n      case 'alpha':\n        label = '\\\\alph*.'\n        break\n      case 'Alpha':\n        label = '\\\\Alph*.'\n        break\n      case 'roman':\n        label = '\\\\roman*.'\n        break\n      case 'Roman':\n        label = '\\\\Roman*.'\n        break\n    }\n    const lineStart: string = list.style === 'none' ? '' : '\\t\\\\item '\n    const lineEnd: string = list.style === 'none' ? '\\\\par\\n' : '\\n'\n    const lineBreak: string = shift.length === 0 ? '\\n' : ''\n    if (unorderedListTypes.includes(list.style)) {\n      openingTag = lineBreak + shift + '\\\\begin{itemize}'\n      if (label.length !== 0) {\n        openingTag += '[label=' + label + ']' + lineEnd\n      }\n      closingTag = shift + '\\\\end{itemize}' + lineEnd\n    } else if (orderedListTypes.includes(list.style)) {\n      openingTag = lineBreak + shift + '\\\\begin{enumerate}'\n      if (label.length !== 0) {\n        openingTag += '[label=' + label + ']' + lineEnd\n      }\n      closingTag = shift + '\\\\end{enumerate}' + lineEnd\n    }\n    theList += openingTag\n    for (const item of list.items) {\n      if (typeof item === 'string') {\n        theList += shift + lineStart + item + lineEnd\n      } else if (isDescriptionItem(item)) {\n        theList +=\n          shift +\n          '\\\\textbf{' +\n          item.description +\n          '}' +\n          lineStart +\n          item.text +\n          lineEnd\n      } else {\n        if (item.introduction) {\n          theList += shift + lineStart + item.introduction + lineEnd\n          theList += createList(item, shift + '\\t')\n        } else {\n          theList += shift + lineStart\n          theList += '\\n' + createList(item, shift + '\\t')\n        }\n      }\n    }\n    theList += closingTag\n  }\n  return theList\n}\n"],"names":["unorderedListTypes","orderedListTypes","isDescriptionItem","item","createList","list","shift","theList","context","li","span","getUniqueStringBasedOnTimeStamp","description","text","label","openingTag","closingTag","lineStart","lineEnd","lineBreak"],"mappings":"gDAGA,MAAMA,EAA+B,CAAC,QAAS,SAAU,MAAO,SAAS,EACnEC,EAA6B,CACjC,UACA,QACA,QACA,QACA,OACF,EAmDO,SAASC,EACdC,EACyB,CACzB,OAAQA,EAAyB,cAAgB,MACnD,CAQgB,SAAAC,EACdC,EACAC,EAAgB,GAC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