taxtank-core 2.0.65 → 2.0.66

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.
@@ -20652,11 +20652,12 @@ class PdfFromDomElementService {
20652
20652
  merge(options, fileSettings);
20653
20653
  }
20654
20654
  // HTML container in which the exported DOM elements will be placed
20655
- // const htmlWrapper: HTMLElement = document.createElement('div');
20656
20655
  const iframe = document.getElementById('iframe-pdf-export');
20657
20656
  const idoc = iframe.contentDocument;
20658
20657
  const htmlWrapper = idoc.getElementById('pdf-export');
20659
20658
  htmlWrapper.innerHTML = '';
20659
+ const scopeTokens = this.collectScopeTokens(elements);
20660
+ this.syncComponentStyles(idoc, scopeTokens);
20660
20661
  elements.forEach((element) => {
20661
20662
  htmlWrapper.append(element.cloneNode(true));
20662
20663
  });
@@ -20672,6 +20673,42 @@ class PdfFromDomElementService {
20672
20673
  .outputPdf('blob')
20673
20674
  .then((blob) => new File([blob], filename, { type: 'application/pdf' })));
20674
20675
  }
20676
+ collectScopeTokens(elements) {
20677
+ const scopes = new Set();
20678
+ const grabFromElement = (el) => {
20679
+ Array.from(el.attributes).forEach(attr => {
20680
+ const name = attr.name;
20681
+ if (name.startsWith('_ngcontent-') || name.startsWith('_nghost-')) {
20682
+ scopes.add(name);
20683
+ }
20684
+ });
20685
+ };
20686
+ elements.forEach(el => {
20687
+ grabFromElement(el);
20688
+ el.querySelectorAll('*').forEach(child => grabFromElement(child));
20689
+ });
20690
+ return Array.from(scopes);
20691
+ }
20692
+ syncComponentStyles(idoc, scopeTokens) {
20693
+ idoc.head
20694
+ .querySelectorAll('style[data-pdf-component-style="1"]')
20695
+ .forEach(el => el.remove());
20696
+ if (!scopeTokens.length) {
20697
+ return;
20698
+ }
20699
+ const parentDoc = document;
20700
+ const styleTags = parentDoc.head.querySelectorAll('style');
20701
+ styleTags.forEach(styleEl => {
20702
+ const cssText = styleEl.textContent || '';
20703
+ const matchesScope = scopeTokens.some(token => cssText.includes(token));
20704
+ if (!matchesScope) {
20705
+ return;
20706
+ }
20707
+ const clone = styleEl.cloneNode(true);
20708
+ clone.setAttribute('data-pdf-component-style', '1');
20709
+ idoc.head.appendChild(clone);
20710
+ });
20711
+ }
20675
20712
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.10", ngImport: i0, type: PdfFromDomElementService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
20676
20713
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.10", ngImport: i0, type: PdfFromDomElementService, providedIn: 'root' }); }
20677
20714
  }