@mathstack/viz 2.3.0 → 2.3.1

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.
@@ -13,7 +13,7 @@ import { TemplatePortal } from '@angular/cdk/portal';
13
13
  import saveAs from 'file-saver';
14
14
  import unparse from 'papaparse';
15
15
  import polylabel from 'polylabel';
16
- import * as domToImage from 'html-to-image';
16
+ import { snapdom } from '@zumer/snapdom';
17
17
 
18
18
  class Marks {
19
19
  ngOnChanges(changes) {
@@ -8276,7 +8276,6 @@ var VicImage;
8276
8276
  })(VicImage || (VicImage = {}));
8277
8277
 
8278
8278
  const DEFAULT$8 = {
8279
- fontEmbedCSS: undefined,
8280
8279
  backgroundColor: '#fff',
8281
8280
  quality: 1,
8282
8281
  };
@@ -8303,46 +8302,27 @@ class VicSvgImageConfig {
8303
8302
  }
8304
8303
 
8305
8304
  class VicImageDownloadService {
8306
- constructor() {
8307
- this.domToImage = domToImage;
8308
- }
8309
- /**
8310
- * @param imageConfig
8311
- * @returns fontEmbedCSS -- scans stylesheets for font files and base64 encodes them,
8312
- * reuse this value in imageConfig for subsequent downloads to avoid
8313
- * re-encoding fonts (slight performance boost)
8314
- */
8315
8305
  async downloadImage(imageConfig) {
8316
- let dataUrl;
8317
- if (imageConfig.fontEmbedCSS === undefined) {
8318
- imageConfig.fontEmbedCSS = await domToImage.getFontEmbedCSS(imageConfig.containerNode);
8319
- }
8320
- const sizedImageConfig = {
8321
- ...imageConfig,
8322
- width: imageConfig.containerNode.scrollWidth,
8323
- height: imageConfig.containerNode.scrollHeight,
8306
+ const options = {
8307
+ fast: true,
8308
+ filterMode: 'remove',
8309
+ filter: (domNode) => {
8310
+ if (getComputedStyle(domNode).display === 'none') {
8311
+ return false;
8312
+ }
8313
+ return imageConfig.filter ? imageConfig.filter(domNode) : true;
8314
+ },
8315
+ backgroundColor: imageConfig.backgroundColor,
8324
8316
  };
8325
- switch (imageConfig.imageType) {
8326
- case VicImage.jpeg:
8327
- dataUrl = await this.domToImage.toJpeg(imageConfig.containerNode, sizedImageConfig);
8328
- break;
8329
- case VicImage.png:
8330
- dataUrl = await this.domToImage.toPng(imageConfig.containerNode, sizedImageConfig);
8331
- break;
8332
- case VicImage.svg:
8333
- dataUrl = await this.domToImage.toSvg(imageConfig.containerNode, sizedImageConfig);
8334
- break;
8335
- default:
8336
- break;
8337
- }
8338
- this.createLinkAndClick(dataUrl, `${imageConfig.fileName}.${imageConfig.imageType}`);
8339
- return imageConfig.fontEmbedCSS;
8340
- }
8341
- createLinkAndClick(dataUrl, fileName) {
8342
- const link = document.createElement('a');
8343
- link.download = fileName;
8344
- link.href = dataUrl;
8345
- link.click();
8317
+ if (!imageConfig.backgroundColor) {
8318
+ delete options.backgroundColor;
8319
+ }
8320
+ const result = await snapdom(imageConfig.containerNode, options);
8321
+ await result.download({
8322
+ format: imageConfig.imageType,
8323
+ filename: imageConfig.fileName,
8324
+ quality: imageConfig.quality,
8325
+ });
8346
8326
  }
8347
8327
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: VicImageDownloadService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
8348
8328
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: VicImageDownloadService, providedIn: 'root' }); }