@d3plus/export 3.1.0 → 3.1.2

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.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @d3plus/export
2
2
 
3
+ [![NPM version](https://img.shields.io/npm/v/@d3plus/export.svg)](https://www.npmjs.com/package/@d3plus/export)
4
+ [![codecov](https://codecov.io/gh/d3plus/d3plus/graph/badge.svg?flag=export)](https://codecov.io/gh/d3plus/d3plus/flags)
5
+
3
6
  Export methods for transforming and downloading SVG.
4
7
 
5
8
  ## Installing
@@ -37,7 +40,7 @@ Live examples can be found on [d3plus.org](https://d3plus.org/), which includes
37
40
 
38
41
  > **saveElement**(`elem`: `HTMLElement`, `options?`: `SaveElementOptions`, `renderOptions?`: `SaveElementRenderOptions`): `void`
39
42
 
40
- Defined in: [saveElement.ts:36](https://github.com/d3plus/d3plus/blob/e9db3c74352143cd7b6bdc8d0786477ea971eb6d/packages/export/src/saveElement.ts#L36)
43
+ Defined in: [saveElement.ts:36](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/export/src/saveElement.ts#L36)
41
44
 
42
45
  Downloads an HTML Element as a bitmap PNG image.
43
46
 
package/es/index.js CHANGED
@@ -1 +1,3 @@
1
1
  export { default as saveElement } from "./src/saveElement.js";
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["export {default as saveElement} from \"./src/saveElement.js\";\n"],"names":["default","saveElement"],"mappings":"AAAA,SAAQA,WAAWC,WAAW,QAAO,uBAAuB"}
@@ -40,3 +40,5 @@ var defaultOptions = {
40
40
  });
41
41
  }
42
42
  }
43
+
44
+ //# sourceMappingURL=saveElement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/saveElement.ts"],"sourcesContent":["import {toBlob, toSvg} from \"html-to-image\";\nimport {saveAs} from \"file-saver\";\n\nexport interface SaveElementOptions {\n /** Filename for the downloaded file, without the extension. */\n filename?: string;\n /** File type of the saved document. Accepted values are \"png\", \"jpg\", and \"svg\". */\n type?: \"png\" | \"jpg\" | \"svg\";\n /** Function to be invoked after saving is complete. */\n callback?: () => void;\n}\n\nexport interface SaveElementRenderOptions {\n /** Background color for the rendered image. */\n background?: string;\n /** Background color for the rendered image (alias). */\n backgroundColor?: string;\n [key: string]: unknown;\n}\n\nconst defaultOptions: Required<Pick<SaveElementOptions, \"filename\" | \"type\">> =\n {\n filename: \"download\",\n type: \"png\",\n };\n\n/**\n Downloads an HTML Element as a bitmap PNG image.\n @param elem The DOM element or d3 selection to export.\n @param options Additional options to specify.\n @param options .filename = \"download\"] Filename for the downloaded file, without the extension.\n @param options .type = \"png\"] File type of the saved document. Accepted values are `\"png\"` and `\"jpg\"`.\n @param options .callback] Function to be invoked after saving is complete.\n @param renderOptions Custom options to be passed to the html-to-image function.\n*/\nexport default function (\n elem: HTMLElement,\n options: SaveElementOptions = {},\n renderOptions: SaveElementRenderOptions = {},\n): void {\n if (!elem) return;\n const opts = Object.assign({}, defaultOptions, options);\n\n // rename renderOptions.background to backgroundColor for backwards compatibility\n const renderOpts = Object.assign(\n {backgroundColor: renderOptions.background},\n renderOptions,\n );\n\n function finish(blob: Blob): void {\n saveAs(blob, `${opts.filename}.${opts.type}`);\n if (opts.callback) opts.callback();\n }\n\n if (opts.type === \"svg\") {\n toSvg(elem, renderOpts).then((dataUrl: string) => {\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", dataUrl);\n xhr.responseType = \"blob\";\n xhr.onload = () => finish(xhr.response as Blob);\n xhr.send();\n });\n } else {\n toBlob(elem, renderOpts).then((blob: Blob | null) => {\n if (blob) finish(blob);\n });\n }\n}\n"],"names":["toBlob","toSvg","saveAs","defaultOptions","filename","type","elem","options","renderOptions","opts","Object","assign","renderOpts","backgroundColor","background","finish","blob","callback","then","dataUrl","xhr","XMLHttpRequest","open","responseType","onload","response","send"],"mappings":"AAAA,SAAQA,MAAM,EAAEC,KAAK,QAAO,gBAAgB;AAC5C,SAAQC,MAAM,QAAO,aAAa;AAmBlC,IAAMC,iBACJ;IACEC,UAAU;IACVC,MAAM;AACR;AAEF;;;;;;;;AAQA,GACA,eAAe,SACbC,IAAiB;QACjBC,UAAAA,iEAA8B,CAAC,GAC/BC,gBAAAA,iEAA0C,CAAC;IAE3C,IAAI,CAACF,MAAM;IACX,IAAMG,OAAOC,OAAOC,MAAM,CAAC,CAAC,GAAGR,gBAAgBI;IAE/C,iFAAiF;IACjF,IAAMK,aAAaF,OAAOC,MAAM,CAC9B;QAACE,iBAAiBL,cAAcM,UAAU;IAAA,GAC1CN;IAGF,SAASO,OAAOC,IAAU;QACxBd,OAAOc,MAAM,AAAC,GAAmBP,OAAjBA,KAAKL,QAAQ,EAAC,KAAa,OAAVK,KAAKJ,IAAI;QAC1C,IAAII,KAAKQ,QAAQ,EAAER,KAAKQ,QAAQ;IAClC;IAEA,IAAIR,KAAKJ,IAAI,KAAK,OAAO;QACvBJ,MAAMK,MAAMM,YAAYM,IAAI,CAAC,SAACC;YAC5B,IAAMC,MAAM,IAAIC;YAChBD,IAAIE,IAAI,CAAC,OAAOH;YAChBC,IAAIG,YAAY,GAAG;YACnBH,IAAII,MAAM,GAAG;uBAAMT,OAAOK,IAAIK,QAAQ;;YACtCL,IAAIM,IAAI;QACV;IACF,OAAO;QACL1B,OAAOM,MAAMM,YAAYM,IAAI,CAAC,SAACF;YAC7B,IAAIA,MAAMD,OAAOC;QACnB;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d3plus/export",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "Export methods for transforming and downloading SVG.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -43,6 +43,7 @@
43
43
  "build:types": "tsc",
44
44
  "build:umd": "node ../../scripts/build-umd.js",
45
45
  "dev": "node ../../scripts/dev.js",
46
- "test": "eslint index.ts src/**/*.ts && eslint --global=it test && mocha 'test/**/*-test.js'"
46
+ "test": "eslint index.ts src/**/*.ts && eslint --global=it test && mocha 'test/**/*-test.js'",
47
+ "test:coverage": "c8 -r text -r lcov --src src mocha 'test/**/*-test.js'"
47
48
  }
48
49
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- @d3plus/export v3.0.16
2
+ @d3plus/export v3.1.1
3
3
  Export methods for transforming and downloading SVG.
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT
@@ -1,5 +1,5 @@
1
1
  /*
2
- @d3plus/export v3.0.16
2
+ @d3plus/export v3.1.1
3
3
  Export methods for transforming and downloading SVG.
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT
@@ -1,5 +1,5 @@
1
1
  /*
2
- @d3plus/export v3.0.16
2
+ @d3plus/export v3.1.1
3
3
  Export methods for transforming and downloading SVG.
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT
@@ -1,5 +1,5 @@
1
1
  /*
2
- @d3plus/export v3.0.16
2
+ @d3plus/export v3.1.1
3
3
  Export methods for transforming and downloading SVG.
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT