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AAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;SAC/C;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,OAAO,EACL,eAAe,EAChB,CAAA\",\"sourcesContent\":[\"'use strict'\\n\\nimport { TryAgain } from '../try-again/index'\\n\\ntype options = {\\n  receiver?: string,\\n  timeout?: number,\\n  reportUrl?: string,\\n  dataType?: 'module' | 'json'\\n}\\n\\nconst documentElement = document.documentElement as HTMLHtmlElement\\nconst clearUnsafe = `\\n  function clearUnsafe (proto) {\\n    var props = Object.getOwnPropertyNames(proto)\\n    props.map(function (key) {\\n      try {\\n        proto[key] = null\\n        delete proto[key]\\n      } catch (e) {}\\n    })\\n  }\\n  clearUnsafe(Document.prototype)\\n  clearUnsafe(Function.prototype)\\n  clearUnsafe(Object.prototype)\\n  clearUnsafe(HTMLElement.prototype)\\n  clearUnsafe(Element.prototype)\\n  clearUnsafe(Node.prototype)\\n  clearUnsafe(String.prototype)\\n  clearUnsafe(window)\\n`\\n\\nconst getShadowModule = function (url: string, options: options = { receiver: '', timeout: 30000, dataType: 'module' }) {\\n  return new Promise(function (resolve, reject) {\\n    let { dataType, receiver, timeout } = options\\n    let iframe: HTMLIFrameElement\\n    let tryObj: TryAgain\\n    let timeoutId: any\\n    timeout = timeout || 30000\\n\\n    // 异常尝试\\n    tryObj = new TryAgain(send, { timeout: 3000, polls: 2 })\\n\\n    // abort\\n    function abort () {\\n      clearTimeout(timeoutId)\\n      window.removeEventListener('online', send, false)\\n      iframe.parentElement && documentElement.removeChild(iframe)\\n    }\\n\\n    // over\\n    function over (type: string) {\\n      abort()\\n      tryObj.try()\\n      if (tryObj.polls === 0) {\\n        reject(type)\\n      }\\n    }\\n\\n    function hashSource () {\\n      return (new Array(8 + Math.round(Math.random() * 8))).join(',').split(',').map(() => {\\n        return String.fromCharCode(97 + Math.round(Math.random() * 25))\\n      }).join('')\\n    }\\n\\n    function send () {\\n      let hash = hashSource()\\n      let script = document.createElement('script')\\n      script.src = url\\n      url = script.src\\n      iframe = document.createElement('iframe')\\n      iframe.style.display = 'none'\\n      iframe.csp = `script-src 'unsafe-inline' ${url.split(/\\\\?|\\\\#/)[0]} 'nonce-${hash}'; ${options.reportUrl ? 'report-uri ' + options.reportUrl : ''}`\\n      iframe.src = URL.createObjectURL(new Blob([`\\n        <html>\\n          <head>\\n            <meta http-equiv=\\\"Content-Security-Policy\\\" content=\\\"${iframe.csp}\\\">\\n            <script id=${hash} nonce=${hash} src=\\\"${url}\\\" async></script>\\n            <script nonce=${hash}>\\n              (function () {\\n                var parent = window.parent\\n                var script = document.getElementById('${hash}')\\n                window['${receiver}'] = window['moduleExportsReceiver'] = function (data) {\\n                  window['moduleExportsReceiver'] = function () {}\\n                  parent['on${hash}'] ? parent['on${hash}']({ data: { response: data, src: '${url}', hash: '${hash}' } }) : parent.postMessage({ response: JSON.parse(JSON.stringify(data)), src: '${url}', hash: '${hash}' }, '${location.origin}')\\n                }\\n                script.onerror = window['getModuleError'] = function () {\\n                  window['moduleExportsReceiver'](null)\\n                }\\n                script.onload = window['getModuleLoaded'] = function () {\\n                  var data = Object.keys(window.exports).length ? window.exports : window.module.exports\\n                  window['moduleExportsReceiver'](data)\\n                }\\n                ${dataType === 'json' ? clearUnsafe : ''}\\n              })()\\n              window.module = {\\n                exports: {}\\n              }\\n              window.exports = {}\\n            </script>\\n          <head>\\n        <body>\\n        </body>\\n        </html>\\n      `], { type: 'text/html' }))\\n      if (dataType !== 'module') {\\n        iframe.setAttribute('sandbox', 'allow-scripts')\\n      }\\n      window['on' + hash] = function (data: any): void {\\n        let result = data.data\\n        let response = result ? result.response : ''\\n\\n        // filter message\\n        if (result.src !== url || result.hash !== hash) return\\n\\n        // remove iframe\\n        abort()\\n        delete window['on' + hash]\\n\\n        // resolve | reject\\n        if (response) {\\n          resolve(response)\\n        } else {\\n          reject(result)\\n        }\\n      }\\n      window.addEventListener('message', window['on' + hash], false)\\n\\n      documentElement.appendChild(iframe)\\n    }\\n\\n    // 超时处理\\n    timeoutId = setTimeout(() => {\\n      over('timeout')\\n    }, timeout)\\n    send()\\n\\n    // 断网重连\\n    if (navigator.onLine === false) {\\n      abort()\\n      tryObj.stop()\\n      window.addEventListener('online', send, false)\\n    }\\n  })\\n}\\n\\nexport {\\n  getShadowModule\\n}\\n\"]}","code":"'use strict';\r\nimport { TryAgain } from '../try-again/index';\r\nvar documentElement = document.documentElement;\r\nvar clearUnsafe = \"\\n  function clearUnsafe (proto) {\\n    var props = Object.getOwnPropertyNames(proto)\\n    props.map(function (key) {\\n      try {\\n        proto[key] = null\\n        delete proto[key]\\n      } catch (e) {}\\n    })\\n  }\\n  clearUnsafe(Document.prototype)\\n  clearUnsafe(Function.prototype)\\n  clearUnsafe(Object.prototype)\\n  clearUnsafe(HTMLElement.prototype)\\n  clearUnsafe(Element.prototype)\\n  clearUnsafe(Node.prototype)\\n  clearUnsafe(String.prototype)\\n  clearUnsafe(window)\\n\";\r\nvar getShadowModule = function (url, options) {\r\n    if (options === void 0) { options = { receiver: '', timeout: 30000, dataType: 'module' }; }\r\n    return new Promise(function (resolve, reject) {\r\n        var dataType = options.dataType, receiver = options.receiver, timeout = options.timeout;\r\n        var iframe;\r\n        var tryObj;\r\n        var timeoutId;\r\n        timeout = timeout || 30000;\r\n        // 异常尝试\r\n        tryObj = new TryAgain(send, { timeout: 3000, polls: 2 });\r\n        // abort\r\n        function abort() {\r\n            clearTimeout(timeoutId);\r\n            window.removeEventListener('online', send, false);\r\n            iframe.parentElement && documentElement.removeChild(iframe);\r\n        }\r\n        // over\r\n        function over(type) {\r\n            abort();\r\n            tryObj.try();\r\n            if (tryObj.polls === 0) {\r\n                reject(type);\r\n            }\r\n        }\r\n        function hashSource() {\r\n            return (new Array(8 + Math.round(Math.random() * 8))).join(',').split(',').map(function () {\r\n                return String.fromCharCode(97 + Math.round(Math.random() * 25));\r\n            }).join('');\r\n        }\r\n        function send() {\r\n            var hash = hashSource();\r\n            var script = document.createElement('script');\r\n            script.src = url;\r\n            url = script.src;\r\n            iframe = document.createElement('iframe');\r\n            iframe.style.display = 'none';\r\n            iframe.csp = \"script-src 'unsafe-inline' \" + url.split(/\\?|\\#/)[0] + \" 'nonce-\" + hash + \"'; \" + (options.reportUrl ? 'report-uri ' + options.reportUrl : '');\r\n            iframe.src = URL.createObjectURL(new Blob([\"\\n        <html>\\n          <head>\\n            <meta http-equiv=\\\"Content-Security-Policy\\\" content=\\\"\" + iframe.csp + \"\\\">\\n            <script id=\" + hash + \" nonce=\" + hash + \" src=\\\"\" + url + \"\\\" async></script>\\n            <script nonce=\" + hash + \">\\n              (function () {\\n                var parent = window.parent\\n                var script = document.getElementById('\" + hash + \"')\\n                window['\" + receiver + \"'] = window['moduleExportsReceiver'] = function (data) {\\n                  window['moduleExportsReceiver'] = function () {}\\n                  parent['on\" + hash + \"'] ? parent['on\" + hash + \"']({ data: { response: data, src: '\" + url + \"', hash: '\" + hash + \"' } }) : parent.postMessage({ response: JSON.parse(JSON.stringify(data)), src: '\" + url + \"', hash: '\" + hash + \"' }, '\" + location.origin + \"')\\n                }\\n                script.onerror = window['getModuleError'] = function () {\\n                  window['moduleExportsReceiver'](null)\\n                }\\n                script.onload = window['getModuleLoaded'] = function () {\\n                  var data = Object.keys(window.exports).length ? window.exports : window.module.exports\\n                  window['moduleExportsReceiver'](data)\\n                }\\n                \" + (dataType === 'json' ? clearUnsafe : '') + \"\\n              })()\\n              window.module = {\\n                exports: {}\\n              }\\n              window.exports = {}\\n            </script>\\n          <head>\\n        <body>\\n        </body>\\n        </html>\\n      \"], { type: 'text/html' }));\r\n            if (dataType !== 'module') {\r\n                iframe.setAttribute('sandbox', 'allow-scripts');\r\n            }\r\n            window['on' + hash] = function (data) {\r\n                var result = data.data;\r\n                var response = result ? result.response : '';\r\n                // filter message\r\n                if (result.src !== url || result.hash !== hash)\r\n                    return;\r\n                // remove iframe\r\n                abort();\r\n                delete window['on' + hash];\r\n                // resolve | reject\r\n                if (response) {\r\n                    resolve(response);\r\n                }\r\n                else {\r\n                    reject(result);\r\n                }\r\n            };\r\n            window.addEventListener('message', window['on' + hash], false);\r\n            documentElement.appendChild(iframe);\r\n        }\r\n        // 超时处理\r\n        timeoutId = setTimeout(function () {\r\n            over('timeout');\r\n        }, timeout);\r\n        send();\r\n        // 断网重连\r\n        if (navigator.onLine === false) {\r\n            abort();\r\n            tryObj.stop();\r\n            window.addEventListener('online', send, false);\r\n        }\r\n    });\r\n};\r\nexport { getShadowModule };\r\n//# sourceMappingURL=index.js.map","dts":{"name":"/Users/ioing/libdev/shadow-function/dist/typings/getShadowModule/index.d.ts","writeByteOrderMark":false,"text":"declare type options = {\r\n    receiver?: string;\r\n    timeout?: number;\r\n    reportUrl?: string;\r\n    dataType?: 'module' | 'json';\r\n};\r\ndeclare const getShadowModule: (url: string, options?: options) => Promise<{}>;\r\nexport { getShadowModule };\r\n"}}
