@volo/ngx-lepton-x.core 4.3.0-rc.3 → 4.3.0-rc.4

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.
@@ -205,29 +205,34 @@ class StyleService {
205
205
  this.initialized$ = new BehaviorSubject(false);
206
206
  }
207
207
  async initStyles(direction) {
208
+ const cssExtension = direction === 'rtl' ? '.rtl' : '';
208
209
  for (const style of this.initialStyles) {
210
+ const href = `${style.bundleName}${cssExtension}.css`;
211
+ const selector = `
212
+ link[rel="stylesheet"][href$="${href}"],
213
+ link[rel="stylesheet"]#${style.bundleName}
214
+ `;
215
+ const isAlreadyLoaded = !!this.document.querySelector(selector);
216
+ if (isAlreadyLoaded) {
217
+ continue;
218
+ }
209
219
  await this.loadStyle(style, direction);
210
220
  }
211
221
  this.initialized$.next(true);
212
222
  }
213
223
  async loadStyle(style, direction) {
214
- return new Promise((resolve, reject) => {
215
- const linkElem = this.createLinkElem(style, direction, resolve);
216
- //TODO: find a better way for understand style laaded by angular json
217
- const appStyles = document.querySelector('link[rel="stylesheet"][href*="styles"]');
218
- if (appStyles) {
219
- if (this.lastInjectedStyle && this.lastInjectedStyle.isConnected) {
220
- this.lastInjectedStyle.insertAdjacentElement('afterend', linkElem);
221
- }
222
- else {
223
- appStyles.insertAdjacentElement('beforebegin', linkElem);
224
- }
224
+ return new Promise((resolve) => {
225
+ const linkElement = this.createLinkElem(style, direction, resolve);
226
+ const styleLinks = Array.from(this.document.head.querySelectorAll('link[rel="stylesheet"]'));
227
+ const lastStyleLink = styleLinks[styleLinks.length - 1];
228
+ if (lastStyleLink) {
229
+ lastStyleLink.insertAdjacentElement('afterend', linkElement);
225
230
  }
226
231
  else {
227
- this.document.head.appendChild(linkElem);
232
+ this.document.head.appendChild(linkElement);
228
233
  }
229
- this.lastInjectedStyle = linkElem;
230
- return Promise.resolve(linkElem);
234
+ this.lastInjectedStyle = linkElement;
235
+ resolve(linkElement);
231
236
  });
232
237
  }
233
238
  async replaceStyle(style, direction) {