@skyux/indicators 5.6.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,61 +35,8 @@ export class SkyTextHighlightDirective {
35
35
  this._skyHighlight = [value];
36
36
  }
37
37
  }
38
- ngOnChanges(changes) {
39
- if (changes.skyHighlight && !changes.skyHighlight.firstChange) {
40
- this.highlight();
41
- }
42
- }
43
- ngAfterViewInit() {
44
- const self = this;
45
- this.observer = this.observerService.create((mutations) => {
46
- self.highlight();
47
- });
48
- this.observeDom();
49
- if (this._skyHighlight && this._skyHighlight.length > 0) {
50
- this.highlight();
51
- }
52
- }
53
- ngOnDestroy() {
54
- /* istanbul ignore else */
55
- if (this.observer) {
56
- this.observer.disconnect();
57
- }
58
- }
59
- readyForHighlight(searchText) {
60
- return searchText && searchText.length > 0 && this.el.nativeElement;
61
- }
62
- highlight() {
63
- /* istanbul ignore else */
64
- if (this.observer) {
65
- this.observer.disconnect();
66
- }
67
- const searchText = this._skyHighlight;
68
- if (this.existingHighlight) {
69
- SkyTextHighlightDirective.removeHighlight(this.el);
70
- }
71
- /* istanbul ignore else */
72
- if (this.readyForHighlight(searchText)) {
73
- const node = this.el.nativeElement;
74
- // mark all matched text in the DOM
75
- SkyTextHighlightDirective.markTextNodes(node, searchText);
76
- this.existingHighlight = true;
77
- }
78
- this.observeDom();
79
- }
80
- observeDom() {
81
- /* istanbul ignore else */
82
- if (this.observer) {
83
- const config = {
84
- attributes: false,
85
- childList: true,
86
- characterData: true,
87
- };
88
- this.observer.observe(this.el.nativeElement, config);
89
- }
90
- }
91
38
  static cleanRegex(regex) {
92
- return regex.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
39
+ return regex.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
93
40
  }
94
41
  static markNode(node, searchTerms) {
95
42
  /* istanbul ignore else */
@@ -140,6 +87,58 @@ export class SkyTextHighlightDirective {
140
87
  }
141
88
  }
142
89
  }
90
+ ngOnChanges(changes) {
91
+ if (changes.skyHighlight && !changes.skyHighlight.firstChange) {
92
+ this.highlight();
93
+ }
94
+ }
95
+ ngAfterViewInit() {
96
+ this.observer = this.observerService.create(() => {
97
+ this.highlight();
98
+ });
99
+ this.observeDom();
100
+ if (this._skyHighlight && this._skyHighlight.length > 0) {
101
+ this.highlight();
102
+ }
103
+ }
104
+ ngOnDestroy() {
105
+ /* istanbul ignore else */
106
+ if (this.observer) {
107
+ this.observer.disconnect();
108
+ }
109
+ }
110
+ readyForHighlight(searchText) {
111
+ return searchText && searchText.length > 0 && this.el.nativeElement;
112
+ }
113
+ highlight() {
114
+ /* istanbul ignore else */
115
+ if (this.observer) {
116
+ this.observer.disconnect();
117
+ }
118
+ const searchText = this._skyHighlight;
119
+ if (this.existingHighlight) {
120
+ SkyTextHighlightDirective.removeHighlight(this.el);
121
+ }
122
+ /* istanbul ignore else */
123
+ if (this.readyForHighlight(searchText)) {
124
+ const node = this.el.nativeElement;
125
+ // mark all matched text in the DOM
126
+ SkyTextHighlightDirective.markTextNodes(node, searchText);
127
+ this.existingHighlight = true;
128
+ }
129
+ this.observeDom();
130
+ }
131
+ observeDom() {
132
+ /* istanbul ignore else */
133
+ if (this.observer) {
134
+ const config = {
135
+ attributes: false,
136
+ childList: true,
137
+ characterData: true,
138
+ };
139
+ this.observer.observe(this.el.nativeElement, config);
140
+ }
141
+ }
143
142
  }
144
143
  SkyTextHighlightDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyTextHighlightDirective, deps: [{ token: i0.ElementRef }, { token: i1.MutationObserverService }], target: i0.ɵɵFactoryTarget.Directive });
145
144
  SkyTextHighlightDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyTextHighlightDirective, selector: "[skyHighlight]", inputs: { skyHighlight: "skyHighlight" }, usesOnChanges: true, ngImport: i0 });
@@ -1 +1 @@
1
- {"version":3,"file":"text-highlight.directive.js","sourceRoot":"","sources":["../../../../../../../../libs/components/indicators/src/lib/modules/text-highlight/text-highlight.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,UAAU,EACV,KAAK,GAIN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;;;AAEtD,MAAM,SAAS,GAAG,oBAAoB,CAAC;AAEvC,qEAAqE;AACrE,2DAA2D;AAC3D,WAAW;AACX;;;;GAIG;AAIH,MAAM,OAAO,yBAAyB;IA6BpC,YACU,EAAc,EACd,eAAwC;QADxC,OAAE,GAAF,EAAE,CAAY;QACd,oBAAe,GAAf,eAAe,CAAyB;QAR1C,sBAAiB,GAAG,KAAK,CAAC;IAS/B,CAAC;IA7BJ;;OAEG;IACH,IACW,YAAY,CAAC,KAAwB;QAC9C,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;QACpB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QAExB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACpD,+EAA+E;YAC/E,4CAA4C;YAC5C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACpC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;YAC7B,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,IAAI,CAAC,aAAa,GAAG,CAAC,KAAe,CAAC,CAAC;SACxC;IACH,CAAC;IAaM,WAAW,CAAC,OAAsB;QACvC,IAAI,OAAO,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,EAAE;YAC7D,IAAI,CAAC,SAAS,EAAE,CAAC;SAClB;IACH,CAAC;IAEM,eAAe;QACpB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Y,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;gBAC/C,UAAU,CAAC,SAAS,EAAE,CAAC;aACxB;SACF;IACH,CAAC;;uHArKU,yBAAyB;2GAAzB,yBAAyB;4FAAzB,yBAAyB;kBAHrC,SAAS;mBAAC;oBACT,QAAQ,EAAE,gBAAgB;iBAC3B;uIAQY,YAAY;sBADtB,KAAK","sourcesContent":["import {\n AfterViewInit,\n Directive,\n ElementRef,\n Input,\n OnChanges,\n OnDestroy,\n SimpleChanges,\n} from '@angular/core';\nimport { MutationObserverService } from '@skyux/core';\n\nconst className = 'sky-highlight-mark';\n\n// Need to add the following to classes which contain static methods.\n// See: https://github.com/ng-packagr/ng-packagr/issues/641\n// @dynamic\n/**\n * Highlights all matching text within DOM elements that it is placed on.\n * The directive is only valid for elements that contain content, so you\n * cannot place it on `ng-template`, `ng-content`, or `ng-container` tags.\n */\n@Directive({\n selector: '[skyHighlight]',\n})\nexport class SkyTextHighlightDirective\n implements OnChanges, AfterViewInit, OnDestroy\n{\n /**\n * Specifies the text to highlight.\n */\n @Input()\n public set skyHighlight(value: string | string[]) {\n value = value || [];\n this._skyHighlight = [];\n\n if (Array.isArray(value)) {\n this._skyHighlight = value.filter((item) => !!item);\n // Reorder strings by their length in descending order to avoid missing matches\n // that contain substrings of other matches.\n this._skyHighlight.sort(function (a, b) {\n return b.length - a.length;\n });\n } else {\n this._skyHighlight = [value as string];\n }\n }\n\n private existingHighlight = false;\n\n private observer: MutationObserver;\n\n private _skyHighlight: string[];\n\n constructor(\n private el: ElementRef,\n private observerService: MutationObserverService\n ) {}\n\n public ngOnChanges(changes: SimpleChanges): void {\n if (changes.skyHighlight && !changes.skyHighlight.firstChange) {\n this.highlight();\n }\n }\n\n public ngAfterViewInit(): void {\n const self = this;\n this.observer = this.observerService.create(\n (mutations: MutationRecord[]) => {\n self.highlight();\n }\n );\n\n this.observeDom();\n if (this._skyHighlight && this._skyHighlight.length > 0) {\n this.highlight();\n }\n }\n\n public ngOnDestroy(): void {\n /* istanbul ignore else */\n if (this.observer) {\n this.observer.disconnect();\n }\n }\n\n private readyForHighlight(searchText: string[]): boolean {\n return searchText && searchText.length > 0 && this.el.nativeElement;\n }\n\n private highlight(): void {\n /* istanbul ignore else */\n if (this.observer) {\n this.observer.disconnect();\n }\n\n const searchText = this._skyHighlight;\n\n if (this.existingHighlight) {\n SkyTextHighlightDirective.removeHighlight(this.el);\n }\n\n /* istanbul ignore else */\n if (this.readyForHighlight(searchText)) {\n const node: HTMLElement = this.el.nativeElement;\n\n // mark all matched text in the DOM\n SkyTextHighlightDirective.markTextNodes(node, searchText);\n this.existingHighlight = true;\n }\n\n this.observeDom();\n }\n\n private observeDom(): void {\n /* istanbul ignore else */\n if (this.observer) {\n const config = {\n attributes: false,\n childList: true,\n characterData: true,\n };\n this.observer.observe(this.el.nativeElement, config);\n }\n }\n\n private static cleanRegex(regex: string): string {\n return regex.replace(/[-\\/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n }\n\n private static markNode(node: any, searchTerms: string[]): number {\n /* istanbul ignore else */\n if (searchTerms) {\n const text = node.nodeValue;\n for (let i = 0; i < searchTerms.length; i++) {\n searchTerms[i] = this.cleanRegex(searchTerms[i]);\n }\n const searchRegex = new RegExp(searchTerms.join('|'), 'gi');\n const match = searchRegex.exec(text);\n if (match) {\n // Split apart text node with mark tags in the middle on the search term.\n const matchIndex = match.index;\n\n const middle = node.splitText(matchIndex);\n middle.splitText(searchRegex.lastIndex - matchIndex);\n const middleClone = middle.cloneNode(true);\n\n const markNode = document.createElement('mark');\n markNode.className = className;\n markNode.appendChild(middleClone);\n middle.parentNode.replaceChild(markNode, middle);\n\n return 1;\n }\n }\n return 0;\n }\n\n private static markTextNodes(\n node: HTMLElement,\n searchTerms: string[]\n ): number {\n if (node.nodeType === 3) {\n return SkyTextHighlightDirective.markNode(node, searchTerms);\n } else if (node.nodeType === 1 && node.childNodes) {\n for (let i = 0; i < node.childNodes.length; i++) {\n const childNode = node.childNodes[i] as HTMLElement;\n i += SkyTextHighlightDirective.markTextNodes(childNode, searchTerms);\n }\n }\n\n return 0;\n }\n\n private static removeHighlight(el: ElementRef): void {\n const matchedElements = el.nativeElement.querySelectorAll(\n `mark.${className}`\n ) as NodeList;\n\n /* istanbul ignore else */\n /* sanity check */\n if (matchedElements) {\n for (let i = 0; i < matchedElements.length; i++) {\n const node = matchedElements[i];\n const parentNode = node.parentNode;\n\n parentNode.replaceChild(node.firstChild, node);\n parentNode.normalize();\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"text-highlight.directive.js","sourceRoot":"","sources":["../../../../../../../../libs/components/indicators/src/lib/modules/text-highlight/text-highlight.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,UAAU,EACV,KAAK,GAIN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;;;AAEtD,MAAM,SAAS,GAAG,oBAAoB,CAAC;AAEvC,qEAAqE;AACrE,2DAA2D;AAC3D,WAAW;AACX;;;;GAIG;AAIH,MAAM,OAAO,yBAAyB;IA6BpC,YACU,EAAc,EACd,eAAwC;QADxC,OAAE,GAAF,EAAE,CAAY;QACd,oBAAe,GAAf,eAAe,CAAyB;QAR1C,sBAAiB,GAAG,KAAK,CAAC;IAS/B,CAAC;IA7BJ;;OAEG;IACH,IACW,YAAY,CAAC,KAAwB;QAC9C,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;QACpB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QAExB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACpD,+EAA+E;YAC/E,4CAA4C;YAC5C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACp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,CAAC,CAAC;YAC1D,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;SAC/B;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAEO,UAAU;QAChB,0BAA0B;QAC1B,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,MAAM,MAAM,GAAG;gBACb,UAAU,EAAE,KAAK;gBACjB,SAAS,EAAE,IAAI;gBACf,aAAa,EAAE,IAAI;aACpB,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;SACtD;IACH,CAAC;;uHAlKU,yBAAyB;2GAAzB,yBAAyB;4FAAzB,yBAAyB;kBAHrC,SAAS;mBAAC;oBACT,QAAQ,EAAE,gBAAgB;iBAC3B;uIAQY,YAAY;sBADtB,KAAK","sourcesContent":["import {\n AfterViewInit,\n Directive,\n ElementRef,\n Input,\n OnChanges,\n OnDestroy,\n SimpleChanges,\n} from '@angular/core';\nimport { MutationObserverService } from '@skyux/core';\n\nconst className = 'sky-highlight-mark';\n\n// Need to add the following to classes which contain static methods.\n// See: https://github.com/ng-packagr/ng-packagr/issues/641\n// @dynamic\n/**\n * Highlights all matching text within DOM elements that it is placed on.\n * The directive is only valid for elements that contain content, so you\n * cannot place it on `ng-template`, `ng-content`, or `ng-container` tags.\n */\n@Directive({\n selector: '[skyHighlight]',\n})\nexport class SkyTextHighlightDirective\n implements OnChanges, AfterViewInit, OnDestroy\n{\n /**\n * Specifies the text to highlight.\n */\n @Input()\n public set skyHighlight(value: string | string[]) {\n value = value || [];\n this._skyHighlight = [];\n\n if (Array.isArray(value)) {\n this._skyHighlight = value.filter((item) => !!item);\n // Reorder strings by their length in descending order to avoid missing matches\n // that contain substrings of other matches.\n this._skyHighlight.sort(function (a, b) {\n return b.length - a.length;\n });\n } else {\n this._skyHighlight = [value as string];\n }\n }\n\n private existingHighlight = false;\n\n private observer: MutationObserver;\n\n private _skyHighlight: string[];\n\n constructor(\n private el: ElementRef,\n private observerService: MutationObserverService\n ) {}\n\n private static cleanRegex(regex: string): string {\n return regex.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n }\n\n private static markNode(node: any, searchTerms: string[]): number {\n /* istanbul ignore else */\n if (searchTerms) {\n const text = node.nodeValue;\n for (let i = 0; i < searchTerms.length; i++) {\n searchTerms[i] = this.cleanRegex(searchTerms[i]);\n }\n const searchRegex = new RegExp(searchTerms.join('|'), 'gi');\n const match = searchRegex.exec(text);\n if (match) {\n // Split apart text node with mark tags in the middle on the search term.\n const matchIndex = match.index;\n\n const middle = node.splitText(matchIndex);\n middle.splitText(searchRegex.lastIndex - matchIndex);\n const middleClone = middle.cloneNode(true);\n\n const markNode = document.createElement('mark');\n markNode.className = className;\n markNode.appendChild(middleClone);\n middle.parentNode.replaceChild(markNode, middle);\n\n return 1;\n }\n }\n return 0;\n }\n\n private static markTextNodes(\n node: HTMLElement,\n searchTerms: string[]\n ): number {\n if (node.nodeType === 3) {\n return SkyTextHighlightDirective.markNode(node, searchTerms);\n } else if (node.nodeType === 1 && node.childNodes) {\n for (let i = 0; i < node.childNodes.length; i++) {\n const childNode = node.childNodes[i] as HTMLElement;\n i += SkyTextHighlightDirective.markTextNodes(childNode, searchTerms);\n }\n }\n\n return 0;\n }\n\n private static removeHighlight(el: ElementRef): void {\n const matchedElements = el.nativeElement.querySelectorAll(\n `mark.${className}`\n ) as NodeList;\n\n /* istanbul ignore else */\n /* sanity check */\n if (matchedElements) {\n for (let i = 0; i < matchedElements.length; i++) {\n const node = matchedElements[i];\n const parentNode = node.parentNode;\n\n parentNode.replaceChild(node.firstChild, node);\n parentNode.normalize();\n }\n }\n }\n\n public ngOnChanges(changes: SimpleChanges): void {\n if (changes.skyHighlight && !changes.skyHighlight.firstChange) {\n this.highlight();\n }\n }\n\n public ngAfterViewInit(): void {\n this.observer = this.observerService.create(() => {\n this.highlight();\n });\n\n this.observeDom();\n if (this._skyHighlight && this._skyHighlight.length > 0) {\n this.highlight();\n }\n }\n\n public ngOnDestroy(): void {\n /* istanbul ignore else */\n if (this.observer) {\n this.observer.disconnect();\n }\n }\n\n private readyForHighlight(searchText: string[]): boolean {\n return searchText && searchText.length > 0 && this.el.nativeElement;\n }\n\n private highlight(): void {\n /* istanbul ignore else */\n if (this.observer) {\n this.observer.disconnect();\n }\n\n const searchText = this._skyHighlight;\n\n if (this.existingHighlight) {\n SkyTextHighlightDirective.removeHighlight(this.el);\n }\n\n /* istanbul ignore else */\n if (this.readyForHighlight(searchText)) {\n const node: HTMLElement = this.el.nativeElement;\n\n // mark all matched text in the DOM\n SkyTextHighlightDirective.markTextNodes(node, searchText);\n this.existingHighlight = true;\n }\n\n this.observeDom();\n }\n\n private observeDom(): void {\n /* istanbul ignore else */\n if (this.observer) {\n const config = {\n attributes: false,\n childList: true,\n characterData: true,\n };\n this.observer.observe(this.el.nativeElement, config);\n }\n }\n}\n"]}
@@ -153,7 +153,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
153
153
  /**
154
154
  * NOTICE: DO NOT MODIFY THIS FILE!
155
155
  * The contents of this file were automatically generated by
156
- * the 'ng generate @skyux/i18n:lib-resources-module modules/shared/sky-indicators' schematic.
156
+ * the 'ng generate @skyux/i18n:lib-resources-module lib/modules/shared/sky-indicators' schematic.
157
157
  * To update this file, simply rerun the command.
158
158
  */
159
159
  const RESOURCES = {
@@ -799,61 +799,8 @@ class SkyTextHighlightDirective {
799
799
  this._skyHighlight = [value];
800
800
  }
801
801
  }
802
- ngOnChanges(changes) {
803
- if (changes.skyHighlight && !changes.skyHighlight.firstChange) {
804
- this.highlight();
805
- }
806
- }
807
- ngAfterViewInit() {
808
- const self = this;
809
- this.observer = this.observerService.create((mutations) => {
810
- self.highlight();
811
- });
812
- this.observeDom();
813
- if (this._skyHighlight && this._skyHighlight.length > 0) {
814
- this.highlight();
815
- }
816
- }
817
- ngOnDestroy() {
818
- /* istanbul ignore else */
819
- if (this.observer) {
820
- this.observer.disconnect();
821
- }
822
- }
823
- readyForHighlight(searchText) {
824
- return searchText && searchText.length > 0 && this.el.nativeElement;
825
- }
826
- highlight() {
827
- /* istanbul ignore else */
828
- if (this.observer) {
829
- this.observer.disconnect();
830
- }
831
- const searchText = this._skyHighlight;
832
- if (this.existingHighlight) {
833
- SkyTextHighlightDirective.removeHighlight(this.el);
834
- }
835
- /* istanbul ignore else */
836
- if (this.readyForHighlight(searchText)) {
837
- const node = this.el.nativeElement;
838
- // mark all matched text in the DOM
839
- SkyTextHighlightDirective.markTextNodes(node, searchText);
840
- this.existingHighlight = true;
841
- }
842
- this.observeDom();
843
- }
844
- observeDom() {
845
- /* istanbul ignore else */
846
- if (this.observer) {
847
- const config = {
848
- attributes: false,
849
- childList: true,
850
- characterData: true,
851
- };
852
- this.observer.observe(this.el.nativeElement, config);
853
- }
854
- }
855
802
  static cleanRegex(regex) {
856
- return regex.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
803
+ return regex.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
857
804
  }
858
805
  static markNode(node, searchTerms) {
859
806
  /* istanbul ignore else */
@@ -904,6 +851,58 @@ class SkyTextHighlightDirective {
904
851
  }
905
852
  }
906
853
  }
854
+ ngOnChanges(changes) {
855
+ if (changes.skyHighlight && !changes.skyHighlight.firstChange) {
856
+ this.highlight();
857
+ }
858
+ }
859
+ ngAfterViewInit() {
860
+ this.observer = this.observerService.create(() => {
861
+ this.highlight();
862
+ });
863
+ this.observeDom();
864
+ if (this._skyHighlight && this._skyHighlight.length > 0) {
865
+ this.highlight();
866
+ }
867
+ }
868
+ ngOnDestroy() {
869
+ /* istanbul ignore else */
870
+ if (this.observer) {
871
+ this.observer.disconnect();
872
+ }
873
+ }
874
+ readyForHighlight(searchText) {
875
+ return searchText && searchText.length > 0 && this.el.nativeElement;
876
+ }
877
+ highlight() {
878
+ /* istanbul ignore else */
879
+ if (this.observer) {
880
+ this.observer.disconnect();
881
+ }
882
+ const searchText = this._skyHighlight;
883
+ if (this.existingHighlight) {
884
+ SkyTextHighlightDirective.removeHighlight(this.el);
885
+ }
886
+ /* istanbul ignore else */
887
+ if (this.readyForHighlight(searchText)) {
888
+ const node = this.el.nativeElement;
889
+ // mark all matched text in the DOM
890
+ SkyTextHighlightDirective.markTextNodes(node, searchText);
891
+ this.existingHighlight = true;
892
+ }
893
+ this.observeDom();
894
+ }
895
+ observeDom() {
896
+ /* istanbul ignore else */
897
+ if (this.observer) {
898
+ const config = {
899
+ attributes: false,
900
+ childList: true,
901
+ characterData: true,
902
+ };
903
+ this.observer.observe(this.el.nativeElement, config);
904
+ }
905
+ }
907
906
  }
908
907
  SkyTextHighlightDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyTextHighlightDirective, deps: [{ token: i0.ElementRef }, { token: i1$2.MutationObserverService }], target: i0.ɵɵFactoryTarget.Directive });
909
908
  SkyTextHighlightDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyTextHighlightDirective, selector: "[skyHighlight]", inputs: { skyHighlight: "skyHighlight" }, usesOnChanges: true, ngImport: i0 });