@d3plus/export 3.1.1 → 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 +1 -1
- package/es/index.js +2 -0
- package/es/index.js.map +1 -0
- package/es/src/saveElement.js +2 -0
- package/es/src/saveElement.js.map +1 -0
- package/package.json +1 -1
- package/umd/d3plus-export.full.js +1 -1
- package/umd/d3plus-export.full.min.js +1 -1
- package/umd/d3plus-export.js +1 -1
- package/umd/d3plus-export.min.js +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Live examples can be found on [d3plus.org](https://d3plus.org/), which includes
|
|
|
40
40
|
|
|
41
41
|
> **saveElement**(`elem`: `HTMLElement`, `options?`: `SaveElementOptions`, `renderOptions?`: `SaveElementRenderOptions`): `void`
|
|
42
42
|
|
|
43
|
-
Defined in: [saveElement.ts:36](https://github.com/d3plus/d3plus/blob/
|
|
43
|
+
Defined in: [saveElement.ts:36](https://github.com/d3plus/d3plus/blob/35025276b7e98271b21e2a83ec03c1025ea4cb11/packages/export/src/saveElement.ts#L36)
|
|
44
44
|
|
|
45
45
|
Downloads an HTML Element as a bitmap PNG image.
|
|
46
46
|
|
package/es/index.js
CHANGED
package/es/index.js.map
ADDED
|
@@ -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"}
|
package/es/src/saveElement.js
CHANGED
|
@@ -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
package/umd/d3plus-export.js
CHANGED
package/umd/d3plus-export.min.js
CHANGED