const defaultEnvName = "ar"; export default class Environment { constructor(options = {}) { this.name = options.name ? options.name : defaultEnvName; this.defaultOptions = { paragraphs: { T1: true, T2: true, T3: true, T4: true, quote: true }, characters: [ { label: "mot", styles: [ { "label": "étranger", "class": "foreign" }, { "label": "accronyme", "class": "acronym" } ] }, { label: "nom", styles: [ { "label": "Auteur - Citation", "class": "author-quotation" }, { "label": "Auteur - Œuvre", "class": "author-work" }, { "label": "Marque", "class": "brand" }, { "label": "Nom propre", "class": "proper-noun" } ] }, { label: "numéral", styles: [ { "label": "siècle", "class": "century" }, { "label": "date", "class": "date" } ] }, { label: "typo", styles: [ { "label": "indice", "class": "subscript" }, { "label": "exposant", "class": "superscript" } ] } ], }; this.setOptions({ ...this.defaultOptions, ...options, }) } setOptions(options) { this.options = { ...this.options, ...options, } } hasParagraphOption(optionKey) { return this.options.paragraphs[optionKey] | false; } getCharacterOptions() { return this.options.characters; } static async loadEnvironment(envName) { if (envName === defaultEnvName) return new Environment(); else return Environment.loadEnvironmentFromJSONFile('/dedediteur/env/' + envName + '.json') } static async loadEnvironmentFromJSONFile(filePath) { let res = await fetch(filePath); let json = await res.json(); return Environment.loadEnvironmentFromJSON(json); } static loadEnvironmentFromJSON(json) { return new Environment(json); } }