UNPKG

@wordpress/block-library

Version:
1 lines • 2.27 kB
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/file/utils/index.js"],"sourcesContent":["/**\n * Uses a combination of user agent matching and feature detection to determine whether\n * the current browser supports rendering PDFs inline.\n *\n * @return {boolean} Whether or not the browser supports inline PDFs.\n */\nexport const browserSupportsPdfs = () => {\n\t// Use native feature detection if available.\n\tif ( window.navigator.pdfViewerEnabled ) {\n\t\treturn true;\n\t}\n\n\t// Most mobile devices include \"Mobi\" in their UA.\n\tif ( window.navigator.userAgent.indexOf( 'Mobi' ) > -1 ) {\n\t\treturn false;\n\t}\n\n\t// Android tablets are the notable exception.\n\tif ( window.navigator.userAgent.indexOf( 'Android' ) > -1 ) {\n\t\treturn false;\n\t}\n\n\t// iPad pretends to be a Mac.\n\tif (\n\t\twindow.navigator.userAgent.indexOf( 'Macintosh' ) > -1 &&\n\t\twindow.navigator.maxTouchPoints &&\n\t\twindow.navigator.maxTouchPoints > 2\n\t) {\n\t\treturn false;\n\t}\n\n\t// IE only supports PDFs when there's an ActiveX object available for it.\n\tif (\n\t\t!! ( window.ActiveXObject || 'ActiveXObject' in window ) &&\n\t\t! (\n\t\t\tcreateActiveXObject( 'AcroPDF.PDF' ) ||\n\t\t\tcreateActiveXObject( 'PDF.PdfCtrl' )\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\n\treturn true;\n};\n\n/**\n * Helper function for creating ActiveX objects, catching any errors that are thrown\n * when it's generated.\n *\n * @param {string} type The name of the ActiveX object to create.\n * @return {window.ActiveXObject|undefined} The generated ActiveXObject, or null if it failed.\n */\nconst createActiveXObject = ( type ) => {\n\tlet ax;\n\ttry {\n\t\tax = new window.ActiveXObject( type );\n\t} catch {\n\t\tax = undefined;\n\t}\n\treturn ax;\n};\n"],"mappings":";;;;;;;;;;;;AAMA,MAAa,4BAA4B;CAExC,IAAK,OAAO,UAAU,kBACrB,OAAO;CAIR,IAAK,OAAO,UAAU,UAAU,QAAS,MAAO,IAAI,IACnD,OAAO;CAIR,IAAK,OAAO,UAAU,UAAU,QAAS,SAAU,IAAI,IACtD,OAAO;CAIR,IACC,OAAO,UAAU,UAAU,QAAS,WAAY,IAAI,MACpD,OAAO,UAAU,kBACjB,OAAO,UAAU,iBAAiB,GAElC,OAAO;CAIR,IACC,CAAC,EAAI,OAAO,iBAAiB,mBAAmB,WAChD,EACC,oBAAqB,aAAc,KACnC,oBAAqB,aAAc,IAGpC,OAAO;CAGR,OAAO;AACR;;;;;;;;AASA,MAAM,uBAAwB,SAAU;CACvC,IAAI;CACJ,IAAI;EACH,KAAK,IAAI,OAAO,cAAe,IAAK;CACrC,QAAQ;EACP,KAAK,KAAA;CACN;CACA,OAAO;AACR"}