All files / app/services/db/text text.service.ts

100% Statements 130/130
100% Branches 69/69
100% Functions 59/59
100% Lines 130/130

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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819                                          1x                   402x 402x 402x 402x 402x                     126x     126x   114x                           184x 184x 758x   184x   169x                           96x                           206x                               180x 60x               120x                                   156x 52x 35x                     104x         292x       292x                                   153x   141x                   153x 18x   141x                           153x                               244x 82x               162x                                   154x 52x 52x 119x     31x                     102x         281x       281x                                 151x   145x                           151x         9x 9x 18x   9x     145x                           151x                               30x                   37x 37x   54x     54x           37x                                   33x 11x 11x                     22x         57x       57x                                                     30x   24x                           30x       9x   24x                         24x   30x                               30x                                   33x 11x 11x 22x 22x     11x                     22x         57x       57x                                                   30x   24x                           30x 30x         9x 9x 18x   9x     24x 48x   24x                           24x     30x                               63x                   22x 22x 39x 35x   4x 4x     17x                                   66x 22x 17x                     44x         121x       121x                                                         66x 3x       63x   57x                           63x         12x 12x 24x   12x     57x                           46x 46x 96x 42x   54x     42x     63x                                                       36x 36x   36x 99x 99x     36x      
import { Inject, Injectable } from '@angular/core';
import { DatasourceService } from '../datasource/datasource.service';
import { Languages } from 'src/app/enums/languages';
import { HttpParams } from '@angular/common/http';
import { Observable, catchError, concat, map, of, skip } from 'rxjs';
import { LanguageService } from '../../language/language.service';
import { PreloaderService } from '../../preloader/preloader.service';
import { Paragraph } from 'src/app/components/classes/paragraph/paragraph';
import { StringDto } from 'src/app/interfaces/StringDto';
import { Preloaders } from '../../preloader/preloaders/preloaders';
import { ifFirst } from 'src/app/operators/ifFirst';
import { ParagraphDecoderService } from '../../paragraphdecoder/paragraph-decoder.service';
import { ListStringDto } from 'src/app/interfaces/ListStringDto';
import { SelectorSplitParam } from 'src/app/interfaces/SelectorSplitParam';
import { ENV } from 'src/environments/injectionToken/environment-provider';
import { IEnvironment } from 'src/environments/interface/ienvironment';
 
/** Text service. */
@Injectable({
  providedIn: 'root',
})
export class TextService {
  /**
   * Text service constructor
   *
   * @param dataSource The {@link DatasourceService}
   * @param langageService The {@link LanguageService}
   * @param preloaderService The {@link PreloaderService}
   * @param paragraphDecoderService The {@link ParagraphDecoderService}
   */
  constructor(
    private dataSource: DatasourceService,
    private langageService: LanguageService,
    private preloaderService: PreloaderService,
    private paragraphDecoderService: ParagraphDecoderService,
    @Inject(ENV) private environment: IEnvironment
  ) {}
 
  /**
   * Get text for a selector in a language
   *
   * @param selector The selector
   * @param language The language
   * @returns An observable of the text
   */
  private getText(selector: string, language: Languages): Observable<string> {
    const params = new HttpParams()
      .set('selector', selector)
      .set('language', Languages[language]);
    return this.dataSource
      ?.get<StringDto>('text', params)
      ?.pipe(map((c) => c.message));
  }
 
  /**
   * Get texts for multiple selectors in a language
   *
   * @param selectors The selectors
   * @param language The language
   * @returns An observable of the texts
   */
  private getMultiText(
    selectors: string[],
    language: Languages
  ): Observable<string[]> {
    let params = new HttpParams().set('language', Languages[language]);
    for (const selector of selectors) {
      params = params.append('selectors', selector);
    }
    return this.dataSource
      ?.get<ListStringDto>('multi-text', params)
      ?.pipe(map((dto) => dto.messages));
  }
 
  /**
   * Get a text for a selector. Uses {@link getText} and the
   * {@link LanguageService} to get the current language. Notifies the
   * {@link Preloaders} that a text is loading, as well as when the text is
   * loaded.
   *
   * @param selector The selector
   * @param preloader The preloader to notify
   * @returns An observable of the text
   */
  get(selector: string, preloader = Preloaders.TEXTS): Observable<string> {
    return this.getTextInLanguage(
      selector,
      this.langageService.current(),
      preloader
    );
  }
 
  /**
   * Formats a string for preloader messages
   *
   * @param s The string
   * @returns The message
   */
  private formateStringToMessage(s: string) {
    return s.length > 10 ? s.slice(0, 10) + '...' : s;
  }
 
  /**
   * Preloader message on load for getTextInLanguage.
   *
   * @param selector The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getTextInLanguageToLoadMessage(
    selector: string,
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    if (!this.environment.production && this.environment.fullLoadingMessages)
      return (
        'Loading text - ' +
        selector +
        ' - in ' +
        Languages[language] +
        ' - ' +
        preloader
      );
    return 'Loading text...';
  }
 
  /**
   * Preloader message on loaded for getTextInLanguage.
   *
   * @param text The text
   * @param selector The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getTextInLanguageLoadedMessage(
    text: string,
    selector: string,
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    if (!this.environment.production && this.environment.fullLoadingMessages) {
      const extrait = this.formateStringToMessage(text);
      return (
        'Text Loaded - ' +
        selector +
        ' - in ' +
        Languages[language] +
        ' : ' +
        extrait +
        ' - ' +
        preloader
      );
    }
    return 'Loading text...';
  }
 
  /** Whether or not the preloader messages should display the preloader total. */
  private getTextInLanguageMessageWithPreloaderTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
  /** Whether or not the preloader messages should display the entire total. */
  private getTextInLanguageMessageWithTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
 
  /**
   * Get a text for a selector in a language. Uses {@link getText}. Only useful
   * when then language isn't the language set by the {@link LanguageService}
   * (for that, see {@link get}) Notifies the {@link Preloaders} that a text is
   * loading, as well as when the text is loaded.
   *
   * @param selector The selector
   * @param preloader The preloader to notify
   * @returns An observable of the text
   */
  getTextInLanguage(
    selector: string,
    language: Languages,
    preloader = Preloaders.TEXTS
  ): Observable<string> {
    const initLoad = of('').pipe(
      ifFirst(() => {
        this.preloaderService.toLoad(
          preloader,
          1,
          this.getTextInLanguageToLoadMessage(selector, language, preloader),
          this.getTextInLanguageMessageWithPreloaderTot(),
          this.getTextInLanguageMessageWithTot()
        );
      }),
      skip(1)
    );
    const getTextRes = this.getText(selector, language)?.pipe(
      catchError(() => ['error']),
      ifFirst((text: string) => {
        this.preloaderService.loaded(
          preloader,
          1,
          this.getTextInLanguageLoadedMessage(
            text,
            selector,
            language,
            preloader
          ),
          this.getTextInLanguageMessageWithPreloaderTot(),
          this.getTextInLanguageMessageWithTot()
        );
      })
    );
    return concat(initLoad, getTextRes);
  }
 
  /**
   * Preloader message on load for getMulti.
   *
   * @param selector The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getMultiToLoadMessage(
    selectors: string[],
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    if (!this.environment.production && this.environment.fullLoadingMessages)
      return (
        'Loading text - ' +
        selectors +
        ' - in ' +
        Languages[language] +
        ' - ' +
        preloader
      );
    return 'Loading text...';
  }
 
  /**
   * Preloader message on loaded for getTextInLanguage.
   *
   * @param texts The texts
   * @param selector The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getMultiLoadedMessage(
    texts: string[],
    selectors: string[],
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    if (!this.environment.production && this.environment.fullLoadingMessages) {
      const extraits = [];
      for (const text of texts) {
        extraits.push(this.formateStringToMessage(text));
      }
 
      return (
        'Text Loaded - ' +
        selectors +
        ' - in ' +
        Languages[language] +
        ' : ' +
        extraits +
        ' - ' +
        preloader
      );
    }
    return 'Loading text...';
  }
 
  /** Whether or not the preloader messages should display the preloader total. */
  private getMultiMessageWithPreloaderTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
  /** Whether or not the preloader messages should display the entire total. */
  private getMultiMessageWithTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
 
  /**
   * Get a text for multiple selectors. Uses {@link getMultiText} and the
   * {@link LanguageService} to get the current language. Notifies the
   * {@link Preloaders} that a text is loading, as well as when the text is
   * loaded.
   *
   * @param selectors The selectors
   * @param preloader The preloader to notify
   * @returns An observable of the texts
   */
  getMulti(
    selectors: string[],
    preloader = Preloaders.TEXTS
  ): Observable<string[]> {
    const initLoad = of(['']).pipe(
      ifFirst(() => {
        this.preloaderService.toLoad(
          preloader,
          1,
          this.getMultiToLoadMessage(
            selectors,
            this.langageService.current(),
            preloader
          ),
          this.getMultiMessageWithPreloaderTot(),
          this.getMultiMessageWithTot()
        );
      }),
      skip(1)
    );
    const getTextRes = this.getMultiText(
      selectors,
      this.langageService.current()
    )?.pipe(
      catchError(() => {
        const res: string[] = [];
        selectors.forEach(() => {
          res.push('error');
        });
        return of(res);
      }),
      ifFirst((res: string[]) => {
        this.preloaderService.loaded(
          preloader,
          1,
          this.getMultiLoadedMessage(
            res,
            selectors,
            this.langageService.current(),
            preloader
          ),
          this.getMultiMessageWithPreloaderTot(),
          this.getMultiMessageWithTot()
        );
      })
    );
    return concat(initLoad, getTextRes);
  }
 
  /**
   * Preloader message on load for getSplit.
   *
   * @param selector The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getSplitToLoadMessage(
    selector: string,
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    return this.getTextInLanguageToLoadMessage(selector, language, preloader);
  }
 
  /**
   * Formats a set of paragraphs for preloader messages
   *
   * @param paragraphs The paragraphs
   * @returns The message
   */
  private formatParagraphsToMessage(paragraphs: Paragraph[]) {
    const extraits = [];
    for (const paragraph of paragraphs) {
      const shortFirstSubPar =
        paragraph.els.length > 1
          ? paragraph.els[0].content + '...'
          : paragraph.els[0].content;
      extraits.push(
        paragraph.els[0].content.length > 10
          ? paragraph.els[0].content.slice(0, 10) + '...'
          : shortFirstSubPar
      );
    }
    return extraits;
  }
 
  /**
   * Preloader message on loaded for getTextInLanguage.
   *
   * @param paragraphs The paragraphs
   * @param selector The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getSplitLoadedMessage(
    paragraphs: Paragraph[],
    selector: string,
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    if (!this.environment.production && this.environment.fullLoadingMessages) {
      const extraits = this.formatParagraphsToMessage(paragraphs);
      return (
        'Text Loaded - ' +
        selector +
        ' - in ' +
        Languages[language] +
        ' : ' +
        extraits +
        ' - ' +
        preloader
      );
    }
    return 'Loading text...';
  }
 
  /** Whether or not the preloader messages should display the preloader total. */
  private getSplitMessageWithPreloaderTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
  /** Whether or not the preloader messages should display the entire total. */
  private getSplitMessageWithTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
 
  /**
   * Get a string for a selector, but splits the result to get an array of
   * {@link Paragraph} using the {@link ParagraphDecoderService}.
   *
   * In the text, use `[[]]` to create new paragraph, use `[[br]]` to create a
   * `<br>` element, use `[[a_asset, link/to/asset.jpg]]` to create an `<a>`
   * with href to assets/link/to/asset.jpg (see
   * {@link TextSubParagraphComponent}), use `[[, some text]]` to create
   * `<strong><em>some text</em></strong>`
   *
   * Do note that those elements are designed with the existence of code
   * injection in mind and/or malicious content in mind. For instance, `<a\>`
   * links are designed to be always prefixed by the asset folder path and hence
   * avoid any kind of attacks and injection of link to another domain (or even
   * the same domain but with an unexpected path).
   *
   * @param selector The selector
   * @param preloader The preloader to notify
   * @returns An observable of the {@link Paragraph}.
   */
  getSplit(
    selector: string,
    preloader = Preloaders.TEXTS
  ): Observable<Paragraph[]> {
    const initLoad = of([]).pipe(
      ifFirst(() => {
        this.preloaderService.toLoad(
          preloader,
          1,
          this.getSplitToLoadMessage(
            selector,
            this.langageService.current(),
            preloader
          ),
          this.getSplitMessageWithPreloaderTot(),
          this.getSplitMessageWithTot()
        );
      }),
      skip(1)
    );
    const getTextRes = this.getText(
      selector,
      this.langageService.current()
    )?.pipe(
      catchError(() => ['error']),
      ifFirst((s: string) => {
        this.preloaderService.loaded(
          preloader,
          1,
          this.getSplitLoadedMessage(
            this.paragraphDecoderService.decode(s),
            selector,
            this.langageService.current(),
            preloader
          ),
          this.getSplitMessageWithPreloaderTot(),
          this.getSplitMessageWithTot()
        );
      }),
      map((s) => this.paragraphDecoderService.decode(s))
    );
    return concat(initLoad, getTextRes);
  }
 
  /**
   * Preloader message on load for getMultiAllSplot.
   *
   * @param selector The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getMultiAllSplitToLoadMessage(
    selectors: string[],
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    return this.getMultiToLoadMessage(selectors, language, preloader);
  }
 
  /**
   * Preloader message on loaded for getTextInLanguage.
   *
   * @param paragraphsSet The paragraphs
   * @param selectors The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getMultiAllSplitLoadedMessage(
    paragraphsSet: Paragraph[][],
    selectors: string[],
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    if (!this.environment.production && this.environment.fullLoadingMessages) {
      const extraits = [];
      for (const paragraphs of paragraphsSet) {
        const extraitPar = this.formatParagraphsToMessage(paragraphs);
        extraits.push(extraitPar);
      }
 
      return (
        'Text Loaded - ' +
        selectors +
        ' - in ' +
        Languages[language] +
        ' : ' +
        extraits +
        ' - ' +
        preloader
      );
    }
    return 'Loading text...';
  }
 
  /** Whether or not the preloader messages should display the preloader total. */
  private getMultiAllSplitMessageWithPreloaderTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
  /** Whether or not the preloader messages should display the entire total. */
  private getMultiAllSplitMessageWithTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
  /**
   * Get strings for multiple selectors, but splits the result to get an array
   * of {@link Paragraph} using the {@link ParagraphDecoderService}.
   *
   * In the text, use `[[]]` to create new paragraph, use `[[br]]` to create a
   * `<br>` element, use `[[a_asset, link/to/asset.jpg]]` to create an `<a>`
   * with href to assets/link/to/asset.jpg (see
   * {@link TextSubParagraphComponent}), use `[[, some text]]` to create
   * `<strong><em>some text</em></strong>`
   *
   * Do note that those elements are designed with the existence of code
   * injection in mind and/or malicious content in mind. For instance, `<a\>`
   * links are designed to be always prefixed by the asset folder path and hence
   * avoid any kind of attacks and injection of link to another domain (or even
   * the same domain but with an unexpected path).
   *
   * @param selectors The selectors
   * @param preloader The preloader to notify
   * @returns An observable of the {@link Paragraph}.
   */
  getMultiAllSplit(
    selectors: string[],
    preloader = Preloaders.TEXTS
  ): Observable<Paragraph[][]> {
    const initLoad = of([[]]).pipe(
      ifFirst(() => {
        this.preloaderService.toLoad(
          preloader,
          1,
          this.getMultiAllSplitToLoadMessage(
            selectors,
            this.langageService.current(),
            preloader
          ),
          this.getMultiAllSplitMessageWithPreloaderTot(),
          this.getMultiAllSplitMessageWithTot()
        );
      }),
      skip(1)
    );
    const res: Paragraph[][] = [];
    const getTextRes = this.getMultiText(
      selectors,
      this.langageService.current()
    )?.pipe(
      catchError(() => {
        const res: string[] = [];
        selectors.forEach(() => {
          res.push('error');
        });
        return [res];
      }),
      ifFirst((s: string[]) => {
        s.forEach((t) => {
          res.push(this.paragraphDecoderService.decode(t));
        });
        this.preloaderService.loaded(
          preloader,
          1,
          this.getMultiAllSplitLoadedMessage(
            res,
            selectors,
            this.langageService.current(),
            preloader
          ),
          this.getMultiAllSplitMessageWithPreloaderTot(),
          this.getMultiAllSplitMessageWithTot()
        );
      }),
      map(() => {
        return res;
      })
    );
    return concat(initLoad, getTextRes);
  }
 
  /**
   * Preloader message on load for getMultiSomeBoolean.
   *
   * @param selector The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getMultiSomeBooleanSplitToLoadMessage(
    selectors: string[],
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    return this.getMultiToLoadMessage(selectors, language, preloader);
  }
 
  /**
   * Formats a set of paragraphs and strings for preloader messages
   *
   * @param resultSet The set of paragraphs and strings
   * @returns The message
   */
  private formateParagraphStringToMessage(resultSet: (Paragraph[] | string)[]) {
    const extraits = [];
    for (const result of resultSet) {
      if (typeof result === 'string') {
        extraits.push(this.formateStringToMessage(result));
      } else {
        const extraitsPar = this.formatParagraphsToMessage(result);
        extraits.push(extraitsPar);
      }
    }
    return extraits;
  }
 
  /**
   * Preloader message on loaded for getTextInLanguage.
   *
   * @param resultSet The paragraphs
   * @param selectors The selector
   * @param language The language
   * @param preloaded The {@link Preloaders}
   * @returns The message
   */
  private getMultiSomeBooleanSplitLoadedMessage(
    resultSet: (Paragraph[] | string)[],
    selectors: string[],
    language: Languages,
    preloader = Preloaders.TEXTS
  ): string {
    if (!this.environment.production && this.environment.fullLoadingMessages) {
      const extraits = this.formateParagraphStringToMessage(resultSet);
      return (
        'Text Loaded - ' +
        selectors +
        ' - in ' +
        Languages[language] +
        ' : ' +
        extraits +
        ' - ' +
        preloader
      );
    }
    return 'Loading text...';
  }
 
  /** Whether or not the preloader messages should display the preloader total. */
  private getMultiSomeBooleanSplitMessageWithPreloaderTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
  /** Whether or not the preloader messages should display the entire total. */
  private getMultiSomeBooleanSplitMessageWithTot(): boolean {
    return !this.environment.production && this.environment.fullLoadingMessages;
  }
 
  /**
   * Get strings for multiple selectors, but splits the result for some of them
   * to get an array of {@link Paragraph} using the
   * {@link ParagraphDecoderService}.
   *
   * In the text, use `[[]]` to create new paragraph, use `[[br]]` to create a
   * `<br>` element, use `[[a_asset, link/to/asset.jpg]]` to create an `<a>`
   * with href to assets/link/to/asset.jpg (see
   * {@link TextSubParagraphComponent}), use `[[, some text]]` to create
   * `<strong><em>some text</em></strong>`
   *
   * Do note that those elements are designed with the existence of code
   * injection in mind and/or malicious content in mind. For instance, `<a\>`
   * links are designed to be always prefixed by the asset folder path and hence
   * avoid any kind of attacks and injection of link to another domain (or even
   * the same domain but with an unexpected path).
   *
   * @param selectors The selectors
   * @param preloader The preloader to notify
   * @returns An observable of the {@link Paragraph}.
   */
  private getMultiSomeBooleanSplit(
    selectors: string[],
    isSplit: boolean[],
    preloader = Preloaders.TEXTS
  ): Observable<(Paragraph[] | string)[]> {
    if (selectors.length != isSplit.length) {
      throw new Error(
        'Invalid parameters for getMultiSomeBooleanSplit - arrays should be of the same length'
      );
    }
    const initLoad = of(['']).pipe(
      ifFirst(() => {
        this.preloaderService.toLoad(
          preloader,
          1,
          this.getMultiSomeBooleanSplitToLoadMessage(
            selectors,
            this.langageService.current(),
            preloader
          ),
          this.getMultiSomeBooleanSplitMessageWithPreloaderTot(),
          this.getMultiSomeBooleanSplitMessageWithTot()
        );
      }),
      skip(1)
    );
    const getTextRes = this.getMultiText(
      selectors,
      this.langageService.current()
    )?.pipe(
      catchError(() => {
        const res: string[] = [];
        selectors.forEach(() => {
          res.push('error');
        });
        return [res];
      }),
      ifFirst((res: (Paragraph[] | string)[]) => {
        this.preloaderService.loaded(
          preloader,
          1,
          this.getMultiSomeBooleanSplitLoadedMessage(
            res,
            selectors,
            this.langageService.current(),
            preloader
          ),
          this.getMultiSomeBooleanSplitMessageWithPreloaderTot(),
          this.getMultiSomeBooleanSplitMessageWithTot()
        );
      }),
      map((output) => {
        const res: (Paragraph[] | string)[] = [];
        output.forEach((s, i) => {
          if (isSplit[i]) {
            res.push(this.paragraphDecoderService.decode(s));
          } else {
            res.push(s);
          }
        });
        return res;
      })
    );
    return concat(initLoad, getTextRes);
  }
 
  /**
   * Get strings for multiple selectors, but splits the result for some of them
   * to get an array of {@link Paragraph} using the
   * {@link ParagraphDecoderService}. Uses {@link getMultiSomeBooleanSplit}
   *
   * In the text, use `[[]]` to create new paragraph, use `[[br]]` to create a
   * `<br>` element, use `[[a_asset, link/to/asset.jpg]]` to create an `<a>`
   * with href to assets/link/to/asset.jpg (see
   * {@link TextSubParagraphComponent}), use `[[, some text]]` to create
   * `<strong><em>some text</em></strong>`
   *
   * Do note that those elements are designed with the existence of code
   * injection in mind and/or malicious content in mind. For instance, `<a\>`
   * links are designed to be always prefixed by the asset folder path and hence
   * avoid any kind of attacks and injection of link to another domain (or even
   * the same domain but with an unexpected path).
   *
   * @param selectors The selectors
   * @param preloader The preloader to notify
   * @returns An observable of the {@link Paragraph}.
   */
  getMultiSomeSplit(
    selectorsSplits: SelectorSplitParam[],
    preloader = Preloaders.TEXTS
  ): Observable<(Paragraph[] | string)[]> {
    const selectors: string[] = [];
    const isSplit: boolean[] = [];
 
    selectorsSplits.forEach((ss) => {
      selectors.push(ss.selector);
      isSplit.push(ss.isSplit);
    });
 
    return this.getMultiSomeBooleanSplit(selectors, isSplit, preloader);
  }
}