editorial-conventions.service.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { Injectable } from '@angular/core';
  2. import { AttributesMap } from 'ng-dynamic-component';
  3. import { AppConfig } from '../app.config';
  4. import { EditorialConvention, EditorialConventionLayouts } from '../models/evt-models';
  5. // List of handled editorial convention
  6. export type EditorialConventionDefaults = 'addition' | 'additionAbove' | 'additionBelow' | 'additionInline' | 'additionLeft' | 'additionRight' |
  7. 'damage' | 'deletion' | 'sicCrux' | 'surplus';
  8. @Injectable({
  9. providedIn: 'root',
  10. })
  11. export class EditorialConventionsService {
  12. defaultLayouts: { [T in EditorialConventionDefaults]: Partial<EditorialConventionLayouts> } = {
  13. addition: {
  14. diplomatic: {
  15. style: {
  16. 'background-color': '#bdecb6',
  17. },
  18. },
  19. },
  20. additionAbove: {
  21. interpretative: {
  22. pre: '\\',
  23. post: '/',
  24. },
  25. diplomatic: {
  26. style: {
  27. 'vertical-align': 'super',
  28. 'font-size': '.7rem',
  29. 'background-color': '#bdecb6',
  30. },
  31. },
  32. },
  33. additionBelow: {
  34. interpretative: {
  35. pre: '/',
  36. post: '\\',
  37. },
  38. diplomatic: {
  39. style: {
  40. 'vertical-align': 'bottom',
  41. 'font-size': '.7rem',
  42. 'background-color': '#bdecb6',
  43. },
  44. },
  45. },
  46. additionInline: {
  47. interpretative: {
  48. pre: '|',
  49. post: '|',
  50. },
  51. diplomatic: {
  52. style: {
  53. 'background-color': '#bdecb6',
  54. },
  55. },
  56. },
  57. additionLeft: {
  58. interpretative: {
  59. post: '| |',
  60. style: {
  61. 'margin-right': '-0.3rem',
  62. },
  63. },
  64. diplomatic: {
  65. style: {
  66. 'margin-left': '-1rem',
  67. 'background-color': '#bdecb6',
  68. },
  69. },
  70. },
  71. additionRight: {
  72. interpretative: {
  73. pre: '| |',
  74. style: {
  75. 'margin-left': '-0.3rem',
  76. },
  77. },
  78. diplomatic: {
  79. style: {
  80. 'background-color': '#bdecb6',
  81. },
  82. },
  83. },
  84. damage: {
  85. diplomatic: {
  86. style: {
  87. 'background-color': 'rgba(193, 193, 193, 0.7)',
  88. },
  89. },
  90. },
  91. deletion: {
  92. diplomatic: {
  93. style: {
  94. 'background-color': '#fdd3d1',
  95. 'text-decoration': 'line-through',
  96. },
  97. },
  98. interpretative: {
  99. pre: '[[',
  100. post: ']]',
  101. },
  102. },
  103. sicCrux: {
  104. diplomatic: {
  105. pre: '&dagger;',
  106. post: '&dagger;',
  107. },
  108. interpretative: {
  109. pre: '&dagger;',
  110. post: '&dagger;',
  111. },
  112. critical: {
  113. pre: '&dagger;',
  114. post: '&dagger;',
  115. },
  116. },
  117. surplus: {
  118. diplomatic: {
  119. pre: '{',
  120. post: '}',
  121. style: {
  122. 'background-color': '#f6b26a',
  123. },
  124. },
  125. },
  126. };
  127. getLayouts(name: string, attributes: AttributesMap, defaultsKey: EditorialConventionDefaults) {
  128. const defaultKeys = this.defaultLayouts[defaultsKey];
  129. let layouts: Partial<EditorialConventionLayouts> = defaultKeys;
  130. const externalLayouts = this._getExternalConfigs().find(c => {
  131. return c.element === name &&
  132. (!attributes || Object.keys(attributes).concat(Object.keys(c.attributes)).every(k => attributes[k] === c.attributes[k]));
  133. })?.layouts ?? undefined;
  134. if (externalLayouts) {
  135. Object.keys(externalLayouts).forEach(editionLevel => {
  136. layouts = {
  137. ...defaultKeys || {},
  138. [editionLevel]: {
  139. ...defaultKeys ? defaultKeys[editionLevel] : {},
  140. ...externalLayouts[editionLevel],
  141. },
  142. };
  143. });
  144. }
  145. return layouts;
  146. }
  147. private _getExternalConfigs(): EditorialConvention[] {
  148. const customs = AppConfig.evtSettings.editorialConventions;
  149. return Object.keys(customs).map((key) => ({
  150. element: customs[key].markup?.element ?? key,
  151. attributes: customs[key].markup?.attributes ?? {},
  152. layouts: customs[key].layouts ?? {},
  153. }));
  154. }
  155. }