@meistrari/tela-build 1.29.2 → 1.29.3

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.
@@ -786,11 +786,55 @@ function scrollToPage(page: number) {
786
786
  }
787
787
  }
788
788
 
789
- function download(url: string) {
789
+ async function download(url: string) {
790
790
  if (!url)
791
791
  return
792
792
 
793
- window.open(url, '_blank')
793
+ const filename = props.file.fileName || 'download'
794
+
795
+ function triggerAnchor(href: string, revokeAfter?: string) {
796
+ const a = document.createElement('a')
797
+ a.href = href
798
+ a.download = filename
799
+ document.body.appendChild(a)
800
+ a.click()
801
+ document.body.removeChild(a)
802
+ if (revokeAfter) {
803
+ setTimeout(() => URL.revokeObjectURL(revokeAfter), 10_000)
804
+ }
805
+ }
806
+
807
+ if (url.startsWith('data:')) {
808
+ try {
809
+ const response = await fetch(url)
810
+ const blob = await response.blob()
811
+ const blobUrl = URL.createObjectURL(blob)
812
+ triggerAnchor(blobUrl, blobUrl)
813
+ }
814
+ catch {
815
+ triggerAnchor(url)
816
+ }
817
+ return
818
+ }
819
+
820
+ try {
821
+ const response = await fetch(url)
822
+ if (!response.ok)
823
+ throw new Error(`HTTP ${response.status}`)
824
+ const blob = await response.blob()
825
+ const blobUrl = URL.createObjectURL(blob)
826
+ triggerAnchor(blobUrl, blobUrl)
827
+ }
828
+ catch {
829
+ const a = document.createElement('a')
830
+ a.href = url
831
+ a.download = filename
832
+ a.target = '_blank'
833
+ a.rel = 'noopener noreferrer'
834
+ document.body.appendChild(a)
835
+ a.click()
836
+ document.body.removeChild(a)
837
+ }
794
838
  }
795
839
 
796
840
  const isContainerHovered = ref(false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/tela-build",
3
- "version": "1.29.2",
3
+ "version": "1.29.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "app.config.ts",