All files / lib typography-settings.service.ts

84.81% Statements 67/79
85.71% Branches 6/7
50% Functions 5/10
84.81% Lines 67/79

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 801x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x       1x 1x     1x 1x 1327x 1327x 1327x 1x 1x 3x   3x 3x 3x 3x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import { Injectable } from '@angular/core';
 
export type SettingValue = number | 'default';
 
/**
 * Service to control various typography settings. Currently the following are supported
 * - line-height
 * - letter-spacing
 * - word-spacing
 * - paragraph-spacing
 */
@Injectable({ providedIn: 'root' })
export class GefaTypographySettingsService {
  /**
   * Set a custom line-height relative to the font-size of the rendered text
   */
  set lineHeight(value: SettingValue) {
    this.updateProperty('--gc-setting-typography-line-height', value, '');
    this._lineSpacing = value;
  }
 
  get lineHeight(): SettingValue {
    return this._lineSpacing;
  }
 
  /**
   * Set a letter spacing relative to the font-size of the rendered text
   */
  set letterSpacing(value: SettingValue) {
    this.updateProperty('--gc-setting-typography-letter-spacing', value);
    this._letterSpacing = value;
  }
 
  get letterSpacing(): SettingValue {
    return this._letterSpacing;
  }
 
  /**
   * set a word spacing relative to the font-size of the rendered text
   */
  set wordSpacing(value: SettingValue) {
    this.updateProperty('--gc-setting-typography-word-spacing', value);
    this._wordSpacing = value;
  }
 
  get wordSpacing() {
    return this._wordSpacing;
  }
 
  /**
   * set a paragraph spacing relative to the font-size of the rendered text
   */
  set paragraphSpacing(value: SettingValue) {
    this.updateProperty('--gc-setting-typography-paragraph-spacing', value);
    this._paragraphSpacing = value;
  }
 
  get paragraphSpacing() {
    return this._paragraphSpacing;
  }
 
  private _lineSpacing: SettingValue = 'default';
  private _letterSpacing: SettingValue = 'default';
  private _wordSpacing: SettingValue = 'default';
  private _paragraphSpacing: SettingValue = 'default';
 
  private updateProperty(name: string, value: SettingValue, units = 'em') {
    if (value === 'default') {
      document.body.style.removeProperty(name);
    } else {
      document.body.style.setProperty(name, `${value.toString()}${units}`);
    }
  }
}