|
- const defaultEnvName = "typobasic";
-
-
- 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,
- ul: true,
- ol: true
- },
-
- characters: [
- {
- label: "Mot",
- styles: [
- {
- "label": "étranger",
- "type": "foreign"
- },
- {
- "label": "accronyme",
- "type": "acronym"
- }
- ]
- },
- //
- {
- label: "nom",
- styles: [
- {
- "label": "Auteur - Citation",
- "type": "author-quotation"
- },
- {
- "label": "Auteur - Œuvre",
- "type": "author-work"
- },
- {
- "label": "Marque",
- "type": "brand"
- },
- {
- "label": "Nom œuvre",
- "type": "work"
- },
- {
- "label": "Nom propre",
- "type": "proper-noun"
- }
- ]
- },
-
- {
- label: "numéral",
- styles: [
- {
- "label": "siècle",
- "type": "century"
- },
- {
- "label": "date",
- "type": "date"
- },
- {
- "label": "chapitre",
- "type": "chapter"
- }
- ]
- },
- {
- label: "typo",
- styles: [
- {
- "label": "emphase",
- "type": "emphasis"
- },
- {
- "label": "indice",
- "type": "subscript"
- },
- {
- "label": "exposant",
- "type": "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;
- }
-
- async getTemplate(){
- let template = await fetch('/dedediteur/env/' + this.name + '/template.html').catch(() => null);
- if(template){
- let html = await template.text();
- return html;
- }
- return null;
-
- }
-
- async getStyleSheetPath(){
- let css = await fetch('/dedediteur/env/' + this.name + '/' + this.name +'.css').catch(() => null);
- if(css)
- return '/dedediteur/env/' + this.name + '/' + this.name +'.css';
- return null
- }
-
-
- static async getEnvironment(envName) {
-
- if (envName === defaultEnvName)
- return new Environment();
- else
- return Environment.getEnvironmentFromJSONFile('/dedediteur/env/' + envName + '/'+envName+ '.json')
-
- }
-
- static async getEnvironmentFromJSONFile(filePath) {
- let res = await fetch(filePath);
- let json = await res.json().catch(() => null);
- return json ? Environment.getEnvironmentFromJSON(json) : null;
-
-
- }
-
- static getEnvironmentFromJSON(json) {
- return new Environment(json);
- }
-
- }
|