|
| 1 | +import {Component, Input} from '@angular/core'; |
| 2 | +import {DomSanitizer} from '@angular/platform-browser'; |
| 3 | + |
| 4 | +@Component({ |
| 5 | + selector: 'watermark', |
| 6 | + styleUrls: ['watermark.component.scss'], |
| 7 | + template: ` |
| 8 | + <div [style.background]="backgroundImage"> |
| 9 | + </div> |
| 10 | + `, |
| 11 | +}) |
| 12 | +export class WatermarkComponent { |
| 13 | + @Input() title = '@angular/layout'; |
| 14 | + @Input() message = 'Layout with FlexBox + CSS Grid'; |
| 15 | + |
| 16 | + constructor(private _sanitizer: DomSanitizer) { |
| 17 | + } |
| 18 | + |
| 19 | + /* tslint:disable:max-line-length */ |
| 20 | + get backgroundImage() { |
| 21 | + const rawSVG = ` |
| 22 | + <svg id="diagonalWatermark" |
| 23 | + width="100%" height="100%" |
| 24 | + xmlns="http://www.w3.org/2000/svg" |
| 25 | + xmlns:xlink="http://www.w3.org/1999/xlink" > |
| 26 | + <style type="text/css"> |
| 27 | + text { |
| 28 | + fill: currentColor; |
| 29 | + font-family: Avenir, Arial, Helvetica, sans-serif; |
| 30 | + opacity: 0.25; |
| 31 | + } |
| 32 | + </style> |
| 33 | + <defs> |
| 34 | + <pattern id="titlePattern" patternUnits="userSpaceOnUse" width="350" height="150"> |
| 35 | + <text y="30" font-size="30" id="title"> |
| 36 | + ${this.title} |
| 37 | + </text> |
| 38 | + </pattern> |
| 39 | + <pattern xlink:href="#titlePattern"> |
| 40 | + <text y="60" x="0" font-size="16" id="message" width="350" height="150"> |
| 41 | + ${this.message} |
| 42 | + </text> |
| 43 | + </pattern> |
| 44 | + <pattern id="combo" xlink:href="#titlePattern" patternTransform="rotate(-30)"> |
| 45 | + <use xlink:href="#title"/> |
| 46 | + <use xlink:href="#message"/> |
| 47 | + </pattern> |
| 48 | + </defs> |
| 49 | + <rect width="100%" height="100%" fill="url(#combo)"/> |
| 50 | + </svg> |
| 51 | + `; |
| 52 | + const bkgrndImageUrl = `data:image/svg+xml;base64,${window.btoa(rawSVG)}`; |
| 53 | + |
| 54 | + return this._sanitizer.bypassSecurityTrustStyle(`url('${bkgrndImageUrl}') repeat-y`); |
| 55 | + } |
| 56 | +} |
0 commit comments