123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import { Injectable } from '@angular/core';
- import { AttributesMap } from 'ng-dynamic-component';
- import { AppConfig } from '../app.config';
- import { EditorialConvention, EditorialConventionLayouts } from '../models/evt-models';
- // List of handled editorial convention
- export type EditorialConventionDefaults = 'addition' | 'additionAbove' | 'additionBelow' | 'additionInline' | 'additionLeft' | 'additionRight' |
- 'damage' | 'deletion' | 'sicCrux' | 'surplus';
- @Injectable({
- providedIn: 'root',
- })
- export class EditorialConventionsService {
- defaultLayouts: { [T in EditorialConventionDefaults]: Partial<EditorialConventionLayouts> } = {
- addition: {
- diplomatic: {
- style: {
- 'background-color': '#bdecb6',
- },
- },
- },
- additionAbove: {
- interpretative: {
- pre: '\\',
- post: '/',
- },
- diplomatic: {
- style: {
- 'vertical-align': 'super',
- 'font-size': '.7rem',
- 'background-color': '#bdecb6',
- },
- },
- },
- additionBelow: {
- interpretative: {
- pre: '/',
- post: '\\',
- },
- diplomatic: {
- style: {
- 'vertical-align': 'bottom',
- 'font-size': '.7rem',
- 'background-color': '#bdecb6',
- },
- },
- },
- additionInline: {
- interpretative: {
- pre: '|',
- post: '|',
- },
- diplomatic: {
- style: {
- 'background-color': '#bdecb6',
- },
- },
- },
- additionLeft: {
- interpretative: {
- post: '| |',
- style: {
- 'margin-right': '-0.3rem',
- },
- },
- diplomatic: {
- style: {
- 'margin-left': '-1rem',
- 'background-color': '#bdecb6',
- },
- },
- },
- additionRight: {
- interpretative: {
- pre: '| |',
- style: {
- 'margin-left': '-0.3rem',
- },
- },
- diplomatic: {
- style: {
- 'background-color': '#bdecb6',
- },
- },
- },
- damage: {
- diplomatic: {
- style: {
- 'background-color': 'rgba(193, 193, 193, 0.7)',
- },
- },
- },
- deletion: {
- diplomatic: {
- style: {
- 'background-color': '#fdd3d1',
- 'text-decoration': 'line-through',
- },
- },
- interpretative: {
- pre: '[[',
- post: ']]',
- },
- },
- sicCrux: {
- diplomatic: {
- pre: '†',
- post: '†',
- },
- interpretative: {
- pre: '†',
- post: '†',
- },
- critical: {
- pre: '†',
- post: '†',
- },
- },
- surplus: {
- diplomatic: {
- pre: '{',
- post: '}',
- style: {
- 'background-color': '#f6b26a',
- },
- },
- },
- };
- getLayouts(name: string, attributes: AttributesMap, defaultsKey: EditorialConventionDefaults) {
- const defaultKeys = this.defaultLayouts[defaultsKey];
- let layouts: Partial<EditorialConventionLayouts> = defaultKeys;
- const externalLayouts = this._getExternalConfigs().find(c => {
- return c.element === name &&
- (!attributes || Object.keys(attributes).concat(Object.keys(c.attributes)).every(k => attributes[k] === c.attributes[k]));
- })?.layouts ?? undefined;
- if (externalLayouts) {
- Object.keys(externalLayouts).forEach(editionLevel => {
- layouts = {
- ...defaultKeys || {},
- [editionLevel]: {
- ...defaultKeys ? defaultKeys[editionLevel] : {},
- ...externalLayouts[editionLevel],
- },
- };
- });
- }
- return layouts;
- }
- private _getExternalConfigs(): EditorialConvention[] {
- const customs = AppConfig.evtSettings.editorialConventions;
- return Object.keys(customs).map((key) => ({
- element: customs[key].markup?.element ?? key,
- attributes: customs[key].markup?.attributes ?? {},
- layouts: customs[key].layouts ?? {},
- }));
- }
- }
|