UNPKG

ll-package

Version:

2 lines (1 loc) 1.09 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../hooks/setting.js");function d(e,t){const{target:n="__blank",noopener:r=!0,noreferrer:i=!0}=t||{},o=[];r&&o.push("noopener=yes"),i&&o.push("noreferrer=yes"),window.open(e,n,o.join(","))}function w({url:e,target:t="_blank",fileName:n}){if(!e)return!1;const r=f.useGlobSetting(),i=window.navigator.userAgent.toLowerCase().indexOf("chrome")>-1,o=window.navigator.userAgent.toLowerCase().indexOf("safari")>-1,c=window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1;if(e.indexOf("http")<0&&e.indexOf("data:image/png;base64")<0&&(e=r.apiUrl+e),e=e+(n?"&name="+n:""),/(iP)/g.test(window.navigator.userAgent))return console.error("Your browser does not support download!"),!1;if(i||o||c){const s=document.createElement("a");if(s.href=e,s.download=n||"",document.createEvent){const a=document.createEvent("MouseEvents");return a.initEvent("click",!0,!0),s.dispatchEvent(a),!0}}return e.indexOf("?")===-1&&(e+="?download"),d(e,{target:t}),!0}exports.downloadByUrl=w;exports.openWindow=d;