ng-zorro-antd-core-highlight.mjs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import * as i0 from '@angular/core';
  2. import { Pipe, NgModule } from '@angular/core';
  3. /**
  4. * Use of this source code is governed by an MIT-style license that can be
  5. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  6. */
  7. // Regular Expressions for parsing tags and attributes
  8. const SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  9. // ! to ~ is the ASCII range.
  10. const NON_ALPHANUMERIC_REGEXP = /([^#-~ |!])/g;
  11. /**
  12. * Escapes all potentially dangerous characters, so that the
  13. * resulting string can be safely inserted into attribute or
  14. * element text.
  15. */
  16. function encodeEntities(value) {
  17. return value
  18. .replace(/&/g, '&')
  19. .replace(SURROGATE_PAIR_REGEXP, (match) => {
  20. const hi = match.charCodeAt(0);
  21. const low = match.charCodeAt(1);
  22. return `&#${(hi - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000};`;
  23. })
  24. .replace(NON_ALPHANUMERIC_REGEXP, (match) => `&#${match.charCodeAt(0)};`)
  25. .replace(/</g, '&lt;')
  26. .replace(/>/g, '&gt;');
  27. }
  28. class NzHighlightPipe {
  29. UNIQUE_WRAPPERS = ['##==-open_tag-==##', '##==-close_tag-==##'];
  30. transform(value, highlightValue, flags, klass) {
  31. if (!highlightValue) {
  32. return value;
  33. }
  34. // Escapes regex keyword to interpret these characters literally
  35. const searchValue = new RegExp(highlightValue.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$&'), flags);
  36. const wrapValue = value.replace(searchValue, `${this.UNIQUE_WRAPPERS[0]}$&${this.UNIQUE_WRAPPERS[1]}`);
  37. return encodeEntities(wrapValue)
  38. .replace(new RegExp(this.UNIQUE_WRAPPERS[0], 'g'), klass ? `<span class="${klass}">` : '<span>')
  39. .replace(new RegExp(this.UNIQUE_WRAPPERS[1], 'g'), '</span>');
  40. }
  41. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzHighlightPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
  42. static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzHighlightPipe, isStandalone: true, name: "nzHighlight" });
  43. }
  44. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzHighlightPipe, decorators: [{
  45. type: Pipe,
  46. args: [{
  47. name: 'nzHighlight',
  48. pure: true
  49. }]
  50. }] });
  51. /**
  52. * Use of this source code is governed by an MIT-style license that can be
  53. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  54. */
  55. class NzHighlightModule {
  56. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzHighlightModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  57. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzHighlightModule, imports: [NzHighlightPipe], exports: [NzHighlightPipe] });
  58. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzHighlightModule });
  59. }
  60. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzHighlightModule, decorators: [{
  61. type: NgModule,
  62. args: [{
  63. imports: [NzHighlightPipe],
  64. exports: [NzHighlightPipe]
  65. }]
  66. }] });
  67. /**
  68. * Use of this source code is governed by an MIT-style license that can be
  69. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  70. */
  71. /**
  72. * Generated bundle index. Do not edit.
  73. */
  74. export { NzHighlightModule, NzHighlightPipe };
  75. //# sourceMappingURL=ng-zorro-antd-core-highlight.mjs.map