@skyux/core 13.0.0 → 13.1.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.
@@ -4134,31 +4134,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImpor
4134
4134
  * Trims whitespace in each text node that is a direct descendent of the current element.
4135
4135
  */
4136
4136
  class SkyTrimDirective {
4137
- #elRef;
4137
+ #el;
4138
4138
  #obs;
4139
4139
  constructor(elRef, mutationObs) {
4140
- this.#elRef = elRef;
4140
+ this.#el = elRef.nativeElement;
4141
4141
  this.#obs = mutationObs.create((mutations) => {
4142
- const nodes = [];
4143
- // Only trim white space inside direct descendants of the current element.
4144
- for (const mutation of mutations) {
4145
- if (mutation.target.parentNode === elRef.nativeElement) {
4146
- nodes.push(mutation.target);
4147
- }
4142
+ if (mutations.some((mutation) => mutation.target === this.#el.firstChild ||
4143
+ mutation.target === this.#el.lastChild)) {
4144
+ this.#trimNodes();
4148
4145
  }
4149
- this.#trim(nodes);
4150
4146
  });
4151
4147
  this.#observe();
4152
4148
  }
4153
4149
  ngOnInit() {
4154
- const el = this.#elRef.nativeElement;
4155
- this.#trim(Array.from(el.childNodes));
4150
+ this.#trimNodes();
4156
4151
  }
4157
4152
  ngOnDestroy() {
4158
4153
  this.#disconnect();
4159
4154
  }
4160
4155
  #observe() {
4161
- this.#obs.observe(this.#elRef.nativeElement, {
4156
+ this.#obs.observe(this.#el, {
4162
4157
  characterData: true,
4163
4158
  subtree: true,
4164
4159
  });
@@ -4166,20 +4161,32 @@ class SkyTrimDirective {
4166
4161
  #disconnect() {
4167
4162
  this.#obs.disconnect();
4168
4163
  }
4169
- #trim(nodes) {
4170
- // Suspend the MutationObserver so altering the text content of each node
4171
- // doesn't retrigger the observe callback.
4172
- this.#disconnect();
4173
- for (const node of nodes) {
4174
- if (node.nodeType === Node.TEXT_NODE && node.textContent) {
4175
- const textContent = node.textContent;
4176
- const textContentTrimmed = textContent.trim();
4164
+ #trimNodes() {
4165
+ const el = this.#el;
4166
+ if (el.hasChildNodes()) {
4167
+ // Suspend the MutationObserver so altering the text content of each node
4168
+ // doesn't retrigger the observe callback.
4169
+ this.#disconnect();
4170
+ if (el.firstChild === el.lastChild) {
4171
+ this.#trimNode(el.firstChild, 'trim');
4172
+ }
4173
+ else {
4174
+ this.#trimNode(el.firstChild, 'trimStart');
4175
+ this.#trimNode(el.lastChild, 'trimEnd');
4176
+ }
4177
+ this.#observe();
4178
+ }
4179
+ }
4180
+ #trimNode(node, trimMethod) {
4181
+ if (node?.nodeType === Node.TEXT_NODE) {
4182
+ const textContent = node.textContent;
4183
+ if (textContent) {
4184
+ const textContentTrimmed = textContent[trimMethod]();
4177
4185
  if (textContent !== textContentTrimmed) {
4178
4186
  node.textContent = textContentTrimmed;
4179
4187
  }
4180
4188
  }
4181
4189
  }
4182
- this.#observe();
4183
4190
  }
4184
4191
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: SkyTrimDirective, deps: [{ token: i0.ElementRef }, { token: SkyMutationObserverService }], target: i0.ɵɵFactoryTarget.Directive }); }
4185
4192
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.0", type: SkyTrimDirective, isStandalone: false, selector: "[skyTrim]", ngImport: i0 }); }
@@ -4738,7 +4745,7 @@ class Version {
4738
4745
  /**
4739
4746
  * Represents the version of @skyux/core.
4740
4747
  */
4741
- const VERSION = new Version('13.0.0');
4748
+ const VERSION = new Version('13.1.0');
4742
4749
 
4743
4750
  /**
4744
4751
  * Generated bundle index. Do not edit.