@codesandbox/sandpack-client
Version:
<img style="width:100%" src="https://user-images.githubusercontent.com/4838076/143581035-ebee5ba2-9cb1-4fe8-a05b-2f44bd69bb4b.gif" alt="Component toolkit for live running code editing experiences" />
1 lines • 8.51 kB
JavaScript
!function(e){function t(t){for(var o,a,c=t[0],i=t[1],d=t[2],u=0,p=[];u<c.length;u++)a=c[u],Object.prototype.hasOwnProperty.call(s,a)&&s[a]&&p.push(s[a][0]),s[a]=0;for(o in i)Object.prototype.hasOwnProperty.call(i,o)&&(e[o]=i[o]);for(l&&l(t);p.length;)p.shift()();return r.push.apply(r,d||[]),n()}function n(){for(var e,t=0;t<r.length;t++){for(var n=r[t],o=!0,c=1;c<n.length;c++){var i=n[c];0!==s[i]&&(o=!1)}o&&(r.splice(t--,1),e=a(a.s=n[0]))}return e}var o={},s={"sandbox-startup":0},r=[];function a(t){if(o[t])return o[t].exports;var n=o[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.e=function(e){var t=[],n=s[e];if(0!==n)if(n)t.push(n[2]);else{var o=new Promise((function(t,o){n=s[e]=[t,o]}));t.push(n[2]=o);var r,c=document.createElement("script");c.charset="utf-8",c.timeout=120,a.nc&&c.setAttribute("nonce",a.nc),c.src=function(e){return a.p+"static/js/"+({}[e]||e)+"."+{4:"a87895b63",5:"029c574e1"}[e]+".chunk.js"}(e);var i=new Error;r=function(t){c.onerror=c.onload=null,clearTimeout(d);var n=s[e];if(0!==n){if(n){var o=t&&("load"===t.type?"missing":t.type),r=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+o+": "+r+")",i.name="ChunkLoadError",i.type=o,i.request=r,n[1](i)}s[e]=void 0}};var d=setTimeout((function(){r({type:"timeout",target:c})}),12e4);c.onerror=c.onload=r,document.head.appendChild(c)}return Promise.all(t)},a.m=e,a.c=o,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)a.d(n,o,function(t){return e[t]}.bind(null,o));return n},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="/",a.oe=function(e){throw console.error(e),e};var c=this.csbJsonP=this.csbJsonP||[],i=c.push.bind(c);c.push=t,c=c.slice();for(var d=0;d<c.length;d++)t(c[d]);var l=i;r.push(["./src/sandbox/startup.ts","vendors~sandbox-startup","default~sandbox~sandbox-startup"]),n()}({"../sandbox-hooks/console/index.js":function(e,t,n){var o,s,r;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self&&self,s=[t,n("../../node_modules/@babel/runtime/helpers/asyncToGenerator.js"),n("../codesandbox-api/dist/codesandbox.es5.js"),n("../../node_modules/console-feed/lib/Hook/index.js"),n("../../node_modules/console-feed/lib/Transform/index.js")],void 0===(r="function"==typeof(o=function(e,t,o,s,r){"use strict";var a=n("../../node_modules/@babel/runtime/helpers/interopRequireDefault.js");Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(){return(0,s.default)(window.console,function(){var e=(0,t.default)((function*(e){yield o.iframeHandshake,(0,o.dispatch)({type:"console",log:e})}));return function(t){return e.apply(this,arguments)}}()),(0,o.listen)((function(e,t){if(t&&"evaluate"===e.type){let t=null,n=!1;try{if(e.command&&"{"===e.command.charAt(0))try{const t="(".concat(e.command,")");new Function(t),e.command=t}catch(e){}t=(0,eval)(e.command)}catch(e){t=e,n=!0}try{(0,o.dispatch)({type:"eval-result",error:n,result:(0,r.Encode)(t)})}catch(e){console.error(e)}}}))},t=a(t),s=a(s);const c=window.top!==window.self,i=window.location.host.endsWith("csb.app")||window.location.host.endsWith("csb.dev");c&&i&&(function(){const e=document.createElement("script");e.src="https://codesandbox.io/p/preview-protocol.js",e.async=!0,e.defer=!0,(document.head||document.documentElement).prepend(e)}(),function(){const e=document.createElement("script");e.src="https://codesandbox.io/p/chrome-devtool/protocol/index.js",e.onload=()=>{const e=window.chobitsu;e&&(window.addEventListener("message",t=>{const n=t.data,o=n.type,s=n.data;"FROM_DEVTOOL"===o&&e.sendRawMessage(s)}),e.setOnMessage(e=>{e.includes('"id":"tmp')||window.parent.postMessage({type:"TO_DEVTOOL",data:e},"*")}),e.sendRawMessage('{"id":5,"method":"Runtime.enable","params":{}}'))},(document.head||document.documentElement).prepend(e)}())})?o.apply(t,s):o)||(e.exports=r)},"../sandbox-hooks/screenshot.js":function(e,t,n){var o,s,r;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self&&self,s=[t,n("../codesandbox-api/dist/codesandbox.es5.js")],void 0===(r="function"==typeof(o=function(e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(){let e;(0,t.listen)(o=>{"take-screenshot"===o.type?Promise.all([n.e(5),n.e(4)]).then(n.t.bind(null,"../sandbox-hooks/html2canvas-lib/index.js",7)).then(e=>{(0,e.default)(document.documentElement,{useCORS:e=>!(o.data.isPrivateSandbox||!e),proxy:"https://h2c-proxy.csb.dev/",logging:!1,allowTaint:!1}).then(e=>{const n=document.createElement("canvas"),o=document.documentElement.scrollLeft,s=document.documentElement.scrollTop;n.width=e.width-o,n.height=e.height-s,n.getContext("2d").drawImage(e,o,s,n.width,n.height,0,0,n.width,n.height),(0,t.dispatch)({type:"screenshot-generated",screenshot:n.toDataURL()})})}):"show-screenshot-cursor"===o.type?(e=document.documentElement.style.cursor,document.documentElement.style.cursor='url(\'data:image/svg+xml;utf8,<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M0 8C0 3.58172 3.58172 0 8 0C12.4183 0 16 3.58172 16 8C16 12.4183 12.4183 16 8 16H0V8Z" fill="%23FF3B30"/></svg>\'), auto'):"hide-screenshot-cursor"===o.type&&(document.documentElement.style.cursor=e)}),window.addEventListener("keydown",e=>{"s"===e.key&&e.shiftKey&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),(0,t.dispatch)({type:"screenshot-requested-from-preview"}))})}})?o.apply(t,s):o)||(e.exports=r)},"../sandbox-hooks/url-listeners.js":function(e,t,n){var o,s,r;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self&&self,s=[t,n("../codesandbox-api/dist/codesandbox.es5.js")],void 0===(r="function"==typeof(o=function(e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(){return Object.assign(window.history,{go(e){const t=s+e;if(t>=0&&t<=o.length-1){s=t;const e=o[s],c=e.url,i=e.state,d=document.location.href;n.replaceState.call(window.history,i,"",c);const l=document.location.href;a(l),window.dispatchEvent(new PopStateEvent("popstate",{state:i})),-1!==l.indexOf("#")&&(r=!0,window.dispatchEvent(new HashChangeEvent("hashchange",{oldURL:d,newURL:l})))}},back(){window.history.go(-1)},forward(){window.history.go(1)},pushState(e,t,o){n.replaceState.call(window.history,e,t,o),c(o,e),a(document.location.href)},replaceState(e,t,r){n.replaceState.call(window.history,e,t,r),o[s]={state:e,url:r},a(document.location.href)}}),Object.defineProperties(window.history,{length:{get:()=>o.length,configurable:!0},state:{get:()=>o[s].state,configurable:!0}}),window.addEventListener("hashchange",()=>{r?r=!1:(c(i(document.location),null),a(document.location.href))}),c(i(document.location),null),setTimeout(()=>{a(document.location.href)}),(0,t.listen)((function(e,t){t&&("urlback"===e.type?history.back():"urlforward"===e.type?history.forward():"refresh"===e.type&&document.location.reload())}))};const n=window.history.__proto__,o=[];let s=-1,r=!1;function a(e){(0,t.dispatch)({type:"urlchange",url:e,back:s>0,forward:s<o.length-1})}function c(e,t){o.splice(s+1),o.push({url:e,state:t}),s=o.length-1}function i(e){return"".concat(e.pathname).concat(e.hash)}})?o.apply(t,s):o)||(e.exports=r)},"./src/sandbox/startup.ts":function(e,t,n){"use strict";n.r(t);var o=n("../../node_modules/worker-loader/dist/cjs.js?publicPath=/&name=babel-transpiler.[hash:8].worker.js!./src/sandbox/eval/transpilers/babel/worker/index.ts"),s=n.n(o),r=n("../sandbox-hooks/console/index.js"),a=n.n(r),c=n("../sandbox-hooks/url-listeners.js"),i=n.n(c),d=n("../sandbox-hooks/screenshot.js"),l=n.n(d),u=n("../sandbox-hooks/preview-secret.js"),p=n("../codesandbox-api/dist/codesandbox.es5.js");!function(e){const t=document.createElement("link");t.href=e,t.rel="prefetch",t.as="script",document.head.appendChild(t)}("".concat("","/static/js/babel.").concat("7.21.8",".min.js")),globalThis.babelworkers=[s()()],p.isStandalone||(i()(),a()(),Object(u.listenForPreviewSecret)(),l()())}});