@alicloud/console-os-browser-vm 1.4.20 → 1.4.21
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/package.json +1 -1
- package/dist/index.js +0 -1
- package/es/Context.js +0 -170
- package/es/Document.js +0 -111
- package/es/Elements.js +0 -70
- package/es/History.js +0 -49
- package/es/Location.js +0 -51
- package/es/Window.js +0 -87
- package/es/events.js +0 -34
- package/es/index.js +0 -99
- package/es/utils/HTMLScriptElement.js +0 -46
- package/es/utils/common.js +0 -9
- package/es/utils/credentials.js +0 -3
- package/es/utils/injectScriptCallBack.js +0 -38
- package/es/utils/isSSR.js +0 -3
- package/es/utils/not-implemented.js +0 -3
- package/lib/Context.js +0 -180
- package/lib/Document.js +0 -114
- package/lib/Elements.js +0 -82
- package/lib/History.js +0 -59
- package/lib/Location.js +0 -60
- package/lib/Window.js +0 -97
- package/lib/events.js +0 -52
- package/lib/index.js +0 -113
- package/lib/utils/HTMLScriptElement.js +0 -64
- package/lib/utils/common.js +0 -18
- package/lib/utils/credentials.js +0 -12
- package/lib/utils/injectScriptCallBack.js +0 -48
- package/lib/utils/isSSR.js +0 -12
- package/lib/utils/not-implemented.js +0 -12
package/package.json
CHANGED
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.aliOSBrowserVM=e():t.aliOSBrowserVM=e()}(window,function(){return n=[function(t,e,n){t.exports=n(2)},function(t,e,n){t.exports=n(3)},function(e,t,n){e=function(a){"use strict";var u,t=Object.prototype,s=t.hasOwnProperty,e="function"==typeof Symbol?Symbol:{},r=e.iterator||"@@iterator",n=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(t){i=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var o,i,a,c,e=e&&e.prototype instanceof v?e:v,e=Object.create(e.prototype),r=new _(r||[]);return e._invoke=(o=t,i=n,a=r,c=f,function(t,e){if(c===h)throw new Error("Generator is already running");if(c===d){if("throw"===t)throw e;return j()}for(a.method=t,a.arg=e;;){var n=a.delegate;if(n){n=function t(e,n){var r=e.iterator[n.method];if(r===u){if(n.delegate=null,"throw"===n.method){if(e.iterator.return&&(n.method="return",n.arg=u,t(e,n),"throw"===n.method))return y;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}r=l(r,e.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,y;r=r.arg;if(!r)return n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,y;{if(!r.done)return r;n[e.resultName]=r.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=u)}n.delegate=null;return y}(n,a);if(n){if(n===y)continue;return n}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(c===f)throw c=d,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);c=h;n=l(o,i,a);if("normal"===n.type){if(c=a.done?d:p,n.arg!==y)return{value:n.arg,done:a.done}}else"throw"===n.type&&(c=d,a.method="throw",a.arg=n.arg)}}),e}function l(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}a.wrap=c;var f="suspendedStart",p="suspendedYield",h="executing",d="completed",y={};function v(){}function m(){}function w(){}var e={},b=(i(e,r,function(){return this}),Object.getPrototypeOf),b=b&&b(b(L([]))),g=(b&&b!==t&&s.call(b,r)&&(e=b),w.prototype=v.prototype=Object.create(e));function O(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function x(a,c){var e;this._invoke=function(n,r){function t(){return new c(function(t,e){!function e(t,n,r,o){var i,t=l(a[t],a,n);if("throw"!==t.type)return i=t.arg,n=i.value,n&&"object"==typeof n&&s.call(n,"__await")?c.resolve(n.__await).then(function(t){e("next",t,r,o)},function(t){e("throw",t,r,o)}):c.resolve(n).then(function(t){i.value=t,r(i)},function(t){return e("throw",t,r,o)});o(t.arg)}(n,r,t,e)})}return e=e?e.then(t,t):t()}}function S(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,this),this.reset(!0)}function L(e){if(e){var n,t=e[r];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return n=-1,t=function t(){for(;++n<e.length;)if(s.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=u,t.done=!0,t},t.next=t}return{next:j}}function j(){return{value:u,done:!0}}return m.prototype=w,i(g,"constructor",w),i(w,"constructor",m),m.displayName=i(w,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,i(t,o,"GeneratorFunction")),t.prototype=Object.create(g),t},a.awrap=function(t){return{__await:t}},O(x.prototype),i(x.prototype,n,function(){return this}),a.AsyncIterator=x,a.async=function(t,e,n,r,o){void 0===o&&(o=Promise);var i=new x(c(t,e,n,r),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},O(g),i(g,o,"Generator"),i(g,r,function(){return this}),i(g,"toString",function(){return"[object Generator]"}),a.keys=function(n){var t,r=[];for(t in n)r.push(t);return r.reverse(),function t(){for(;r.length;){var e=r.pop();if(e in n)return t.value=e,t.done=!1,t}return t.done=!0,t}},a.values=L,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=u,this.done=!1,this.delegate=null,this.method="next",this.arg=u,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&s.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=u)},stop:function(){this.done=!0;var t=this.tryEntries[0],t=t.completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var r=this;function t(t,e){return i.type="throw",i.arg=n,r.next=t,e&&(r.method="next",r.arg=u),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=s.call(o,"catchLoc"),c=s.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;0<=n;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),E(n),y}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n,r,o=this.tryEntries[e];if(o.tryLoc===t)return n=o.completion,"throw"===n.type&&(r=n.arg,E(o)),r}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:L(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=u),y}},a}(e.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}},function(I,t,e){"use strict";function a(t,e,n){e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n}function u(t,e,n,r,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void n(t)}c.done?e(u):Promise.resolve(u).then(r,o)}function o(c){return function(){var t=this,a=arguments;return new Promise(function(e,n){var r=c.apply(t,a);function o(t){u(r,e,n,o,i,"next",t)}function i(t){u(r,e,n,o,i,"throw",t)}o(void 0)})}}e.r(t),e.d(t,"createContext",function(){return G}),e.d(t,"removeContext",function(){return B}),e.d(t,"evalScripts",function(){return D});var t=e(0),c=e.n(t);function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function l(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(t){var e;try{e=new URL(t)}catch(t){return}return t=e.searchParams,t?t.get("callback")||t.get("cb"):null}function n(){return"undefined"==typeof document}var f=function(t){setTimeout(function(){var e,n;t.src&&(e=t.ownerContext.window,n=s(t.src),n&&"function"==typeof e[n]&&(window[n]=function(){var t=e[n].apply(e,arguments);return window[n]=null,t}))},0)};if(!n()&&"function"==typeof window.Element)for(var i=0,p=["appendChild","insertBefore","append"];i<p.length;i++){var h=p[i],d=window.Element.prototype[h];window.Element.prototype[h]=function(i,a){return function(n){if(n&&n._evalScriptInSandbox&&n.ownerContext&&"SCRIPT"===n.nodeName&&n.src&&-1===n.ownerContext.allowResources.indexOf(n.src)&&!s(n.src))return n.ownerContext.loadScripts(n.src).then(function(){var t=n._listenerMap.get("load"),t=(t&&t.forEach(function(t){t()}),new Event("load"));n.onload&&n.onload(t)}).catch(function(e){console.error(e);var t=n._listenerMap.get("error");t&&t.forEach(function(t){t(e)}),n.onerror&&n.onerror(e)});n&&"SCRIPT"===n.nodeName&&n.ownerContext&&f(n),n&&n.scriptText&&n.ownerContext.evalScript(n.scriptText);for(var t=arguments.length,e=new Array(1<t?t-1:0),r=1;r<t;r++)e[r-1]=arguments[r];var o=("append"===a&&void 0===n?[]:[n]).concat(e);try{return i.call.apply(i,[this].concat(l(o)))}catch(t){return i.apply(this,o)}}}(d,h)}function y(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function v(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function m(t,e,n){return e&&v(t.prototype,e),n&&v(t,n),t}var w=n()?function(){}:window.addEventListener,b=n()?function(){}:window.removeEventListener,g=["webkitmouseforcedown","webkitmouseforcewillbegin","visibilitychange","error","mousemove","mousedown","mouseup","touchcancel","touchend","touchstart","auxclick","dblclick","pointercancel","pointerdown","pointerup","dragend","dragstart","drop","compositionend","compositionstart","keydown","keypress","keyup","input","textInput","close","cancel","copy","cut","paste","click","change","contextmenu","reset","submit","resize","scroll","foucs","blur"];function O(t){t=t.prototype&&t.prototype.constructor===t&&1<Object.getOwnPropertyNames(t.prototype).length||/^class\b/.test(t.toString());return t}function x(t){t=0===t.name.indexOf("bound ")&&!t.hasOwnProperty("prototype");return t}function S(e){var o,i,a,c;e._listenerMap=new Map,e.addEventListener=(o=e,i=e.addEventListener,function(t,e,n){var r=o._listenerMap.get(t)||[];return o._listenerMap.set(t,[].concat(l(r),[e])),i.apply(o,[t,e,n])}),e.removeEventListener=(a=e,c=e.removeEventListener,function(t,e,n){var r=a._listenerMap.get(t);return r&&r.length&&-1!==r.indexOf(e)&&r.splice(r.indexOf(e),1),c.apply(a,[t,e,n])}),e._evalScriptInSandbox||(j.forEach(function(t){Object.defineProperty(e,t,{get:function(){return this.scriptText||""},set:function(t){this.scriptText=t,e.parentNode&&this.ownerContext.evalScript&&e.ownerContext.evalScript(t.toString())},enumerable:!1})}),e._evalScriptInSandbox=!0)}var E=["setTimeout","setInterval","clearInterval","clearTimeout"],_=["requestAnimationFrame","webkitRequestAnimationFrame","mozRequestAnimationFrame","oRequestAnimationFrame","msRequestAnimationFrame","cancelAnimationFrame","webkitCancelAnimationFrame","mozCancelAnimationFrame","oCancelAnimationFrame","msCancelAnimationFrame"],e=m(function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},c=1<arguments.length?arguments[1]:void 0,n=2<arguments.length?arguments[2]:void 0,u=(y(this,t),[].concat(_,l(e.externals||[]))),s={};return E.forEach(function(t){u.includes(t)||(s[t]=n.contentWindow[t].bind(n.contentWindow))}),new Proxy(n.contentWindow,{set:function(t,e,n){return t[e]=n,s[e]=n,!0},get:function(t,e){if(u.includes(e)){var n=window[e];if("function"!=typeof n||x(n)||O(n))return n;var r,o=n.bind(window);for(r in n)o[r]=n[r];return o}switch(e){case"document":return c.document;case"location":return c.location;case"history":return c.history;case"__CONSOLE_OS_GLOBAL_VARS_":return s;case"addEventListener":return a=c,function(t,e,n){var r=a._listenerMap.get(t)||[];return a._listenerMap.set(t,[].concat(l(r),[e])),-1===g.indexOf(t)?a.baseFrame.addEventListener.apply(a.baseFrame.contentWindow,[t,e,n]):w.apply(window,[t,e,n])};case"removeEventListener":return i=c,function(t,e,n){var r=i._listenerMap.get(t);return r&&r.length&&-1!==r.indexOf(e)&&r.splice(r.indexOf(e),1),-1===g.indexOf(t)?i.baseFrame.removeEventListener.apply(i.baseFrame.contentWindow,[t,e,n]):b.apply(window,[t,e,n])}}var i,a;if(s[e])return s[e];e=t[e];return"function"!=typeof e||x(e)||O(e)?e:e.bind&&e.bind(t)}})}),L=e,j=["innerHTML","text","innerText"];function P(t,e){var n,r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return A(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?A(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length)return r&&(t=r),n=0,e=function(){},{s:e,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,a=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return i=t.done,t},e:function(t){a=!0,o=t},f:function(){try{i||null==r.return||r.return()}finally{if(a)throw o}}}}function A(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var t=m(function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=1<arguments.length?arguments[1]:void 0,o=(y(this,t),[]);return new Proxy(document,{set:function(t,e,n){return"cookie"===e?document.cookie=n:t[e]=n,!0},get:function(r,t){switch(t){case"body":return n.body;case"location":return n.location;case"defaultView":return n.window;case"write":case"writeln":return function(){};case"createElement":return function(){var t=(t=document).createElement.apply(t,arguments);return t.ownerContext=n,t.appId=e.id,"SCRIPT"!==t.tagName||e.enableScriptEscape||S(t),t};case"addEventListener":return function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return o.push(e),r.addEventListener.apply(r,e)};case"removeEventListeners":return function(){var t,e=P(o);try{for(e.s();!(t=e.n()).done;){var n=t.value;r.removeEventListener.apply(r,l(n))}}catch(t){e.e(t)}finally{e.f()}}}return"function"==typeof r[t]?r[t].bind&&r[t].bind(r):r[t]}})}),k=t,e=m(function t(r){return y(this,t),new Proxy({},{set:function(t,e,n){return"href"!==e&&(r[e]=n),!0},get:function(t,e){switch(e){case"reload":return function(){return window.location.reload()};case"replace":return function(){};case"toString":return function(){try{return r.toString()}catch(t){return r.href}}}return"function"==typeof r[e]?r[e].bind&&r[e].bind(t):r[e]}})}),C=e,t=m(function t(e,o){if(y(this,t),!e)return o.history;function i(){o.postMessage({type:"".concat(e,":history-change"),data:JSON.parse(JSON.stringify(o.location))},"*")}try{var a=o.history.pushState,c=o.history.replaceState;return o.history.pushState=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=a.apply(o.history,[].concat(e));return i(),r},o.history.replaceState=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=c.apply(o.history,[].concat(e));return i(),r},o.history}catch(t){return}}),R=t;function F(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}function T(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?F(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):F(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var e=function(){function r(t,e){y(this,r),this.location=new C(e.contentWindow.location),this.history=new R(t.id,e.contentWindow),this.window=new L(t,this,e,location),this.allowResources=t.allowResources||[];var n=t.body;t.disableBody?n=document.body:t.body||(n=document.createElement("body"),document.documentElement.appendChild(n)),this.body=n,this.document=new k(T({enableScriptEscape:!0},t),this,e,location),this.baseFrame=e,this._listenerMap=new Map,this.window.__IS_CONSOLE_OS_CONTEXT__=!0}var e,n;return m(r,[{key:"loadScripts",value:(n=o(c.a.mark(function t(n){var r;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(n,{credentials:(e=n,e.includes("console.aliyun.com")?"include":"omit")});case 2:return r=t.sent,t.next=5,r.text();case 5:r=t.sent,this.evalScript(r,n);case 7:case"end":return t.stop()}var e},t,this)})),function(t){return n.apply(this,arguments)})},{key:"evalScript",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",t=new Function("\n return function ({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) {\n try {\n ".concat(t,"\n }\n catch(e) {\n console.log(e)\n }\n }\n }//@ sourceMappingURL=").concat(e));t().call(this.window,T({},this))}},{key:"updateBody",value:function(t){!t&&this.body||(this.body=t)}},{key:"remove",value:function(){this.document.removeEventListeners(),this.baseFrame&&(this.baseFrame.parentNode?this.baseFrame.parentNode.removeChild(this.baseFrame):this.baseFrame.setAttribute("src","about:blank"))}}],[{key:"create",value:function(r){var o=this;return new Promise(function(t){var e=document.createElement("iframe"),n=(e.setAttribute("src",r.url||"/api.json"),e.style.cssText="position: absolute; top: -20000px; width: 1px; height: 1px;",r.id&&e.setAttribute("data-id",r.id),(null==(n=document.documentElement)?void 0:n.getElementsByTagName("body")[0])||document.body);if(n.appendChild(e),"about:blank"===r.url)return t(new o(r,e));e.onload=function(){t(new o(r,e))}})}},{key:"remove",value:(e=o(c.a.mark(function t(e){return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e.remove&&e.remove();case 1:case"end":return t.stop()}},t)})),function(t){return e.apply(this,arguments)})}]),r}(),M=e;function N(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}var G=function(){var t=o(c.a.mark(function t(){var e,n=arguments;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=0<n.length&&void 0!==n[0]?n[0]:{},t.next=3,M.create(e);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t)}));return function(){return t.apply(this,arguments)}}(),B=function(){var e=o(c.a.mark(function t(e){return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,M.remove(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t)}));return function(t){return e.apply(this,arguments)}}(),D=function(){var e=o(c.a.mark(function t(e){var n,r,o,i=arguments;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=1<i.length&&void 0!==i[1]?i[1]:{},t.next=3,M.create(n);case 3:return r=t.sent,o=new Function("\n return function({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) { \n ".concat(e,"\n }\n }//@sourceURL=").concat(n.name)),t.abrupt("return",o(function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?N(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):N(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({},r)));case 6:case"end":return t.stop()}},t)}));return function(t){return e.apply(this,arguments)}}()}],r={},o.m=n,o.c=r,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="/",o(o.s=1);function o(t){if(r[t])return r[t].exports;var e=r[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}var n,r});
|
package/es/Context.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
-
|
|
7
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
-
|
|
9
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Context
|
|
13
|
-
* @lastModified 2019086
|
|
14
|
-
* @forwardCompatibleTo 2019086
|
|
15
|
-
* @createAt 2019086
|
|
16
|
-
*/
|
|
17
|
-
import Window from './Window';
|
|
18
|
-
import Document from './Document';
|
|
19
|
-
import Location from './Location';
|
|
20
|
-
import History from './History';
|
|
21
|
-
import { getFetchCredentials } from './utils/credentials';
|
|
22
|
-
|
|
23
|
-
var Context = /*#__PURE__*/function () {
|
|
24
|
-
function Context(conf, frame) {
|
|
25
|
-
_classCallCheck(this, Context);
|
|
26
|
-
|
|
27
|
-
this.location = new Location(frame.contentWindow.location);
|
|
28
|
-
this.history = new History(conf.id, frame.contentWindow);
|
|
29
|
-
this.window = new Window(conf, this, frame, location);
|
|
30
|
-
this.allowResources = conf.allowResources || [];
|
|
31
|
-
var body = conf.body;
|
|
32
|
-
|
|
33
|
-
if (conf.disableBody) {
|
|
34
|
-
body = document.body;
|
|
35
|
-
} else if (!conf.body) {
|
|
36
|
-
body = document.createElement('body');
|
|
37
|
-
document.documentElement.appendChild(body);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
this.body = body;
|
|
41
|
-
this.document = new Document(_objectSpread({
|
|
42
|
-
enableScriptEscape: true
|
|
43
|
-
}, conf), this, frame, location);
|
|
44
|
-
this.baseFrame = frame;
|
|
45
|
-
this._listenerMap = new Map();
|
|
46
|
-
this.window.__IS_CONSOLE_OS_CONTEXT__ = true;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_createClass(Context, [{
|
|
50
|
-
key: "loadScripts",
|
|
51
|
-
value: function () {
|
|
52
|
-
var _loadScripts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url) {
|
|
53
|
-
var resp, code;
|
|
54
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
55
|
-
while (1) {
|
|
56
|
-
switch (_context.prev = _context.next) {
|
|
57
|
-
case 0:
|
|
58
|
-
_context.next = 2;
|
|
59
|
-
return fetch(url, {
|
|
60
|
-
credentials: getFetchCredentials(url)
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
case 2:
|
|
64
|
-
resp = _context.sent;
|
|
65
|
-
_context.next = 5;
|
|
66
|
-
return resp.text();
|
|
67
|
-
|
|
68
|
-
case 5:
|
|
69
|
-
code = _context.sent;
|
|
70
|
-
this.evalScript(code, url);
|
|
71
|
-
|
|
72
|
-
case 7:
|
|
73
|
-
case "end":
|
|
74
|
-
return _context.stop();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}, _callee, this);
|
|
78
|
-
}));
|
|
79
|
-
|
|
80
|
-
function loadScripts(_x) {
|
|
81
|
-
return _loadScripts.apply(this, arguments);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return loadScripts;
|
|
85
|
-
}()
|
|
86
|
-
}, {
|
|
87
|
-
key: "evalScript",
|
|
88
|
-
value: function evalScript(code) {
|
|
89
|
-
var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
90
|
-
// eslint-disable-next-line no-new-func
|
|
91
|
-
var resolver = new Function("\n return function ({window, location, history, document}){ \n with(window.__CONSOLE_OS_GLOBAL_VARS_) {\n try {\n ".concat(code, "\n }\n catch(e) {\n console.log(e)\n }\n }\n }//@ sourceMappingURL=").concat(url));
|
|
92
|
-
resolver().call(this.window, _objectSpread({}, this));
|
|
93
|
-
}
|
|
94
|
-
}, {
|
|
95
|
-
key: "updateBody",
|
|
96
|
-
value: function updateBody(dom) {
|
|
97
|
-
if (!dom && this.body) return;
|
|
98
|
-
this.body = dom;
|
|
99
|
-
}
|
|
100
|
-
}, {
|
|
101
|
-
key: "remove",
|
|
102
|
-
value: function remove() {
|
|
103
|
-
this.document.removeEventListeners();
|
|
104
|
-
|
|
105
|
-
if (this.baseFrame) {
|
|
106
|
-
if (this.baseFrame.parentNode) {
|
|
107
|
-
this.baseFrame.parentNode.removeChild(this.baseFrame);
|
|
108
|
-
} else {
|
|
109
|
-
this.baseFrame.setAttribute('src', 'about:blank');
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}], [{
|
|
114
|
-
key: "create",
|
|
115
|
-
value: function create(conf) {
|
|
116
|
-
var _this = this;
|
|
117
|
-
|
|
118
|
-
return new Promise(function (resolve) {
|
|
119
|
-
var _document$documentEle;
|
|
120
|
-
|
|
121
|
-
var iframe = document.createElement('iframe'); // TODO: change src to a reasonable value.
|
|
122
|
-
|
|
123
|
-
iframe.setAttribute('src', conf.url ? conf.url : '/api.json');
|
|
124
|
-
iframe.style.cssText = 'position: absolute; top: -20000px; width: 1px; height: 1px;';
|
|
125
|
-
if (conf.id) iframe.setAttribute('data-id', conf.id); // body will be hijacked in sandbox, so get body from html
|
|
126
|
-
|
|
127
|
-
var topBody = ((_document$documentEle = document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.getElementsByTagName('body')[0]) || document.body;
|
|
128
|
-
topBody.appendChild(iframe); // the onload will no trigger when src is about:blank
|
|
129
|
-
|
|
130
|
-
if (conf.url === 'about:blank') {
|
|
131
|
-
return resolve(new _this(conf, iframe));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
iframe.onload = function () {
|
|
135
|
-
resolve(new _this(conf, iframe));
|
|
136
|
-
};
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}, {
|
|
140
|
-
key: "remove",
|
|
141
|
-
value: function () {
|
|
142
|
-
var _remove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(context) {
|
|
143
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
144
|
-
while (1) {
|
|
145
|
-
switch (_context2.prev = _context2.next) {
|
|
146
|
-
case 0:
|
|
147
|
-
if (context.remove) {
|
|
148
|
-
context.remove();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
case 1:
|
|
152
|
-
case "end":
|
|
153
|
-
return _context2.stop();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}, _callee2);
|
|
157
|
-
}));
|
|
158
|
-
|
|
159
|
-
function remove(_x2) {
|
|
160
|
-
return _remove.apply(this, arguments);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return remove;
|
|
164
|
-
}()
|
|
165
|
-
}]);
|
|
166
|
-
|
|
167
|
-
return Context;
|
|
168
|
-
}();
|
|
169
|
-
|
|
170
|
-
export default Context;
|
package/es/Document.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
-
|
|
5
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
|
-
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Document.js
|
|
13
|
-
* @lastModified 2019085
|
|
14
|
-
* @forwardCompatibleTo 2019085
|
|
15
|
-
* @createAt 2019085
|
|
16
|
-
*/
|
|
17
|
-
import { injectHTMLScriptElement } from './utils/HTMLScriptElement';
|
|
18
|
-
|
|
19
|
-
var Document = /*#__PURE__*/_createClass(function Document() {
|
|
20
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
21
|
-
var context = arguments.length > 1 ? arguments[1] : undefined;
|
|
22
|
-
var frame = arguments.length > 2 ? arguments[2] : undefined;
|
|
23
|
-
|
|
24
|
-
_classCallCheck(this, Document);
|
|
25
|
-
|
|
26
|
-
var eventListeners = [];
|
|
27
|
-
return new Proxy(document, {
|
|
28
|
-
set: function set(target, name, value) {
|
|
29
|
-
switch (name) {
|
|
30
|
-
case 'cookie':
|
|
31
|
-
document.cookie = value;
|
|
32
|
-
break;
|
|
33
|
-
|
|
34
|
-
default:
|
|
35
|
-
target[name] = value;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return true;
|
|
39
|
-
},
|
|
40
|
-
get: function get(target, name) {
|
|
41
|
-
switch (name) {
|
|
42
|
-
case 'body':
|
|
43
|
-
return context.body;
|
|
44
|
-
|
|
45
|
-
case 'location':
|
|
46
|
-
return context.location;
|
|
47
|
-
|
|
48
|
-
case 'defaultView':
|
|
49
|
-
return context.window;
|
|
50
|
-
|
|
51
|
-
case 'write':
|
|
52
|
-
case 'writeln':
|
|
53
|
-
return function () {};
|
|
54
|
-
|
|
55
|
-
case 'createElement':
|
|
56
|
-
return function () {
|
|
57
|
-
var _document;
|
|
58
|
-
|
|
59
|
-
var el = (_document = document).createElement.apply(_document, arguments);
|
|
60
|
-
|
|
61
|
-
el.ownerContext = context;
|
|
62
|
-
el.appId = options.id; // 对于 script 标签如果开启防逃逸,就直接 hack script 标签
|
|
63
|
-
|
|
64
|
-
if (el.tagName === 'SCRIPT' && !options.enableScriptEscape) {
|
|
65
|
-
injectHTMLScriptElement(el);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return el;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
case 'addEventListener':
|
|
72
|
-
return function () {
|
|
73
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
74
|
-
args[_key] = arguments[_key];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
eventListeners.push(args);
|
|
78
|
-
return target.addEventListener.apply(target, args);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
case 'removeEventListeners':
|
|
82
|
-
return function () {
|
|
83
|
-
var _iterator = _createForOfIteratorHelper(eventListeners),
|
|
84
|
-
_step;
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
88
|
-
var args = _step.value;
|
|
89
|
-
target.removeEventListener.apply(target, _toConsumableArray(args));
|
|
90
|
-
}
|
|
91
|
-
} catch (err) {
|
|
92
|
-
_iterator.e(err);
|
|
93
|
-
} finally {
|
|
94
|
-
_iterator.f();
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
default:
|
|
99
|
-
} // TODO: hijack document.getElementsByTagName('body')
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (typeof target[name] === 'function') {
|
|
103
|
-
return target[name].bind && target[name].bind(target);
|
|
104
|
-
} else {
|
|
105
|
-
return target[name];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
export default Document;
|
package/es/Elements.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import injectScriptCallBack, { getJsonCallback } from './utils/injectScriptCallBack';
|
|
3
|
-
import { isSSR } from './utils/isSSR';
|
|
4
|
-
|
|
5
|
-
var makeElInjector = function makeElInjector(originMethod, methodName) {
|
|
6
|
-
return function (el) {
|
|
7
|
-
// 如果不在 BrowserVM 的白名单内,尝试通过 context 的 load script 通过 xhr 获取脚本内容,并在沙箱中执行
|
|
8
|
-
if (el && el._evalScriptInSandbox && el.ownerContext && el.nodeName === 'SCRIPT' && el.src && el.ownerContext.allowResources.indexOf(el.src) === -1 && !getJsonCallback(el.src)) {
|
|
9
|
-
return el.ownerContext.loadScripts(el.src).then(function () {
|
|
10
|
-
var fns = el._listenerMap.get('load');
|
|
11
|
-
|
|
12
|
-
if (fns) {
|
|
13
|
-
fns.forEach(function (fn) {
|
|
14
|
-
fn();
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var e = new Event('load');
|
|
19
|
-
el.onload && el.onload(e);
|
|
20
|
-
}).catch(function (e) {
|
|
21
|
-
console.error(e);
|
|
22
|
-
|
|
23
|
-
var fns = el._listenerMap.get('error');
|
|
24
|
-
|
|
25
|
-
if (fns) {
|
|
26
|
-
fns.forEach(function (fn) {
|
|
27
|
-
fn(e);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
el.onerror && el.onerror(e);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (el && el.nodeName === 'SCRIPT' && el.ownerContext) {
|
|
36
|
-
injectScriptCallBack(el);
|
|
37
|
-
} // 如果有 scriptText, 证明在 append 之前被设置了 text
|
|
38
|
-
// 所以直接执行这个 script
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (el && el.scriptText) {
|
|
42
|
-
el.ownerContext.evalScript(el.scriptText);
|
|
43
|
-
} // fix: babel 会把 fn.call 转义成 fn.call.apply 造成 chrome 50 的几个版本报错
|
|
44
|
-
// 这里 尝试 try catch 如果报错 直接调用 fn.apply
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
48
|
-
args[_key - 1] = arguments[_key];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var methodArgs = methodName === 'append' && el === undefined // 修复 append 的过程中 append() 为一个没参数的状态。应为 append 的函数签名为 append(param1, param2, /* ... ,*/ paramN)
|
|
52
|
-
? [].concat(args) : [el].concat(args);
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
return originMethod.call.apply(originMethod, [this].concat(_toConsumableArray(methodArgs)));
|
|
56
|
-
} catch (_unused) {
|
|
57
|
-
return originMethod.apply(this, methodArgs);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
if (!isSSR() && typeof window.Element === 'function') {
|
|
63
|
-
var mountElementMethods = ['appendChild', 'insertBefore', 'append'];
|
|
64
|
-
|
|
65
|
-
for (var _i = 0, _mountElementMethods = mountElementMethods; _i < _mountElementMethods.length; _i++) {
|
|
66
|
-
var method = _mountElementMethods[_i];
|
|
67
|
-
var originMethod = window.Element.prototype[method];
|
|
68
|
-
window.Element.prototype[method] = makeElInjector(originMethod, method);
|
|
69
|
-
}
|
|
70
|
-
}
|
package/es/History.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
-
|
|
4
|
-
var History = /*#__PURE__*/_createClass(function History(id, frame) {
|
|
5
|
-
_classCallCheck(this, History);
|
|
6
|
-
|
|
7
|
-
if (!id) {
|
|
8
|
-
return frame.history;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
var postMessage = function postMessage() {
|
|
12
|
-
frame.postMessage({
|
|
13
|
-
type: "".concat(id, ":history-change"),
|
|
14
|
-
data: JSON.parse(JSON.stringify(frame.location))
|
|
15
|
-
}, '*');
|
|
16
|
-
}; // throw error when iframe src is about:blank
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
var originalPushStatus = frame.history.pushState;
|
|
21
|
-
var originalReplaceStatus = frame.history.replaceState;
|
|
22
|
-
|
|
23
|
-
frame.history.pushState = function () {
|
|
24
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
25
|
-
args[_key] = arguments[_key];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var returnValue = originalPushStatus.apply(frame.history, [].concat(args));
|
|
29
|
-
postMessage();
|
|
30
|
-
return returnValue;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
frame.history.replaceState = function () {
|
|
34
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
35
|
-
args[_key2] = arguments[_key2];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var returnValue = originalReplaceStatus.apply(frame.history, [].concat(args));
|
|
39
|
-
postMessage();
|
|
40
|
-
return returnValue;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return frame.history;
|
|
44
|
-
} catch (e) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
export default History;
|
package/es/Location.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
-
|
|
4
|
-
var Location = /*#__PURE__*/_createClass(function Location(location) {
|
|
5
|
-
_classCallCheck(this, Location);
|
|
6
|
-
|
|
7
|
-
return new Proxy({}, {
|
|
8
|
-
set: function set(target, name, value) {
|
|
9
|
-
switch (name) {
|
|
10
|
-
case 'href':
|
|
11
|
-
break;
|
|
12
|
-
|
|
13
|
-
default:
|
|
14
|
-
location[name] = value;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return true;
|
|
18
|
-
},
|
|
19
|
-
get: function get(target, name) {
|
|
20
|
-
switch (name) {
|
|
21
|
-
case 'reload':
|
|
22
|
-
return function () {
|
|
23
|
-
return window.location.reload();
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
case 'replace':
|
|
27
|
-
return function () {};
|
|
28
|
-
|
|
29
|
-
case 'toString':
|
|
30
|
-
return function () {
|
|
31
|
-
try {
|
|
32
|
-
return location.toString();
|
|
33
|
-
} catch (e) {
|
|
34
|
-
return location.href;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
default:
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (typeof location[name] === 'function') {
|
|
43
|
-
return location[name].bind && location[name].bind(target);
|
|
44
|
-
} else {
|
|
45
|
-
return location[name];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export default Location;
|
package/es/Window.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Window.js
|
|
7
|
-
*/
|
|
8
|
-
import { addEventListener, removeEventListener } from './events';
|
|
9
|
-
import { isConstructable, isBoundedFunction } from './utils/common';
|
|
10
|
-
var globalFnName = ['setTimeout', 'setInterval', 'clearInterval', 'clearTimeout'];
|
|
11
|
-
var defaultExternals = ['requestAnimationFrame', 'webkitRequestAnimationFrame', 'mozRequestAnimationFrame', 'oRequestAnimationFrame', 'msRequestAnimationFrame', 'cancelAnimationFrame', 'webkitCancelAnimationFrame', 'mozCancelAnimationFrame', 'oCancelAnimationFrame', 'msCancelAnimationFrame'];
|
|
12
|
-
|
|
13
|
-
var Window = /*#__PURE__*/_createClass(function Window() {
|
|
14
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
15
|
-
var context = arguments.length > 1 ? arguments[1] : undefined;
|
|
16
|
-
var frame = arguments.length > 2 ? arguments[2] : undefined;
|
|
17
|
-
|
|
18
|
-
_classCallCheck(this, Window);
|
|
19
|
-
|
|
20
|
-
var externals = [].concat(defaultExternals, _toConsumableArray(options.externals || []));
|
|
21
|
-
var __CONSOLE_OS_GLOBAL_VARS_ = {};
|
|
22
|
-
globalFnName.forEach(function (name) {
|
|
23
|
-
if (externals.includes(name)) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
__CONSOLE_OS_GLOBAL_VARS_[name] = frame.contentWindow[name].bind(frame.contentWindow);
|
|
28
|
-
});
|
|
29
|
-
return new Proxy(frame.contentWindow, {
|
|
30
|
-
set: function set(target, name, value) {
|
|
31
|
-
target[name] = value;
|
|
32
|
-
__CONSOLE_OS_GLOBAL_VARS_[name] = value;
|
|
33
|
-
return true;
|
|
34
|
-
},
|
|
35
|
-
get: function get(target, name) {
|
|
36
|
-
if (externals.includes(name)) {
|
|
37
|
-
var windowValue = window[name];
|
|
38
|
-
|
|
39
|
-
if (typeof windowValue === 'function' && !isBoundedFunction(windowValue) && !isConstructable(windowValue)) {
|
|
40
|
-
var bindFn = windowValue.bind(window);
|
|
41
|
-
|
|
42
|
-
for (var key in windowValue) {
|
|
43
|
-
bindFn[key] = windowValue[key];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return bindFn;
|
|
47
|
-
} else {
|
|
48
|
-
return windowValue;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
switch (name) {
|
|
53
|
-
case 'document':
|
|
54
|
-
return context.document;
|
|
55
|
-
|
|
56
|
-
case 'location':
|
|
57
|
-
return context.location;
|
|
58
|
-
|
|
59
|
-
case 'history':
|
|
60
|
-
return context.history;
|
|
61
|
-
|
|
62
|
-
case '__CONSOLE_OS_GLOBAL_VARS_':
|
|
63
|
-
return __CONSOLE_OS_GLOBAL_VARS_;
|
|
64
|
-
|
|
65
|
-
case 'addEventListener':
|
|
66
|
-
return addEventListener(context);
|
|
67
|
-
|
|
68
|
-
case 'removeEventListener':
|
|
69
|
-
return removeEventListener(context);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (__CONSOLE_OS_GLOBAL_VARS_[name]) {
|
|
73
|
-
return __CONSOLE_OS_GLOBAL_VARS_[name];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
var value = target[name];
|
|
77
|
-
|
|
78
|
-
if (typeof value === 'function' && !isBoundedFunction(value) && !isConstructable(value)) {
|
|
79
|
-
return value.bind && value.bind(target);
|
|
80
|
-
} else {
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
export default Window;
|
package/es/events.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import { isSSR } from './utils/isSSR';
|
|
3
|
-
var rawAddEventListener = !isSSR() ? window.addEventListener : function () {};
|
|
4
|
-
var rawRemoveEventListener = !isSSR() ? window.removeEventListener : function () {};
|
|
5
|
-
;
|
|
6
|
-
export var domEventsListeningTo = ['webkitmouseforcedown', 'webkitmouseforcewillbegin', 'visibilitychange', 'error', 'mousemove', 'mousedown', 'mouseup', 'touchcancel', 'touchend', 'touchstart', 'auxclick', 'dblclick', 'pointercancel', 'pointerdown', 'pointerup', 'dragend', 'dragstart', 'drop', 'compositionend', 'compositionstart', 'keydown', 'keypress', 'keyup', 'input', 'textInput', 'close', 'cancel', 'copy', 'cut', 'paste', 'click', 'change', 'contextmenu', 'reset', 'submit', 'resize', 'scroll', 'foucs', 'blur'];
|
|
7
|
-
export var addEventListener = function addEventListener(context) {
|
|
8
|
-
return function (type, listener, options) {
|
|
9
|
-
var listeners = context._listenerMap.get(type) || [];
|
|
10
|
-
|
|
11
|
-
context._listenerMap.set(type, [].concat(_toConsumableArray(listeners), [listener]));
|
|
12
|
-
|
|
13
|
-
if (domEventsListeningTo.indexOf(type) === -1) {
|
|
14
|
-
return context.baseFrame.addEventListener.apply(context.baseFrame.contentWindow, [type, listener, options]);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return rawAddEventListener.apply(window, [type, listener, options]);
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export var removeEventListener = function removeEventListener(context) {
|
|
21
|
-
return function (type, listener, options) {
|
|
22
|
-
var storedTypeListeners = context._listenerMap.get(type);
|
|
23
|
-
|
|
24
|
-
if (storedTypeListeners && storedTypeListeners.length && storedTypeListeners.indexOf(listener) !== -1) {
|
|
25
|
-
storedTypeListeners.splice(storedTypeListeners.indexOf(listener), 1);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (domEventsListeningTo.indexOf(type) === -1) {
|
|
29
|
-
return context.baseFrame.removeEventListener.apply(context.baseFrame.contentWindow, [type, listener, options]);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return rawRemoveEventListener.apply(window, [type, listener, options]);
|
|
33
|
-
};
|
|
34
|
-
};
|