UNPKG

astro

Version:

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

7 lines (6 loc) • 5.36 kB
/** * This file is prebuilt from packages/astro/src/runtime/server/astro-island.ts * Do not edit this directly, but instead edit that file and rerun the prebuild * to generate this file. */ export default `(function(){function e(t){"@babel/helpers - typeof";return e=typeof Symbol==\`function\`&&typeof Symbol.iterator==\`symbol\`?function(e){return typeof e}:function(e){return e&&typeof Symbol==\`function\`&&e.constructor===Symbol&&e!==Symbol.prototype?\`symbol\`:typeof e},e(t)}function t(t,n){if(e(t)!=\`object\`||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var i=r.call(t,n||\`default\`);if(e(i)!=\`object\`)return i;throw TypeError(\`@@toPrimitive must return a primitive value.\`)}return(n===\`string\`?String:Number)(t)}function n(n){var r=t(n,\`string\`);return e(r)==\`symbol\`?r:r+\`\`}function r(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let i=/* @__PURE__ */ new Set([\`__proto__\`,\`constructor\`,\`prototype\`]);{let e={0:e=>a(e),1:e=>n(e),2:e=>new RegExp(e),3:e=>new Date(e),4:e=>new Map(n(e)),5:e=>new Set(n(e)),6:e=>BigInt(e),7:e=>new URL(e),8:e=>new Uint8Array(e),9:e=>new Uint16Array(e),10:e=>new Uint32Array(e),11:e=>1/0*e},t=t=>{let[n,r]=t;return n in e?e[n](r):void 0},n=e=>e.map(t),a=e=>typeof e!=\`object\`||!e?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n)]));class o extends HTMLElement{constructor(...e){super(...e),r(this,\`Component\`,void 0),r(this,\`hydrator\`,void 0),r(this,\`hydrate\`,async()=>{var e;if(!this.hydrator||!this.isConnected)return;let t=(e=this.parentElement)==null?void 0:e.closest(\`astro-island[ssr]\`);if(t){t.addEventListener(\`astro:hydrate\`,this.hydrate,{once:!0});return}let n=this.querySelectorAll(\`astro-slot\`),r={},i=this.querySelectorAll(\`template[data-astro-template]\`);for(let e of i){let t=e.closest(this.tagName);t!=null&&t.isSameNode(this)&&(r[e.getAttribute(\`data-astro-template\`)||\`default\`]=e.innerHTML,e.remove())}for(let e of n){let t=e.closest(this.tagName);t!=null&&t.isSameNode(this)&&(r[e.getAttribute(\`name\`)||\`default\`]=e.innerHTML)}let o;try{o=this.hasAttribute(\`props\`)?a(JSON.parse(this.getAttribute(\`props\`))):{}}catch(e){let t=this.getAttribute(\`component-url\`)||\`<unknown>\`,n=this.getAttribute(\`component-export\`);throw n&&(t+=\` (export \${n})\`),console.error(\`[hydrate] Error parsing props for component \${t}\`,this.getAttribute(\`props\`),e),e}let s,c=this.hydrator(this);s=performance.now(),await c(this.Component,o,r,{client:this.getAttribute(\`client\`)}),s&&this.setAttribute(\`client-render-time\`,(performance.now()-s).toString()),this.removeAttribute(\`ssr\`),this.dispatchEvent(new CustomEvent(\`astro:hydrate\`))}),r(this,\`unmount\`,()=>{this.isConnected||this.dispatchEvent(new CustomEvent(\`astro:unmount\`))})}disconnectedCallback(){document.removeEventListener(\`astro:after-swap\`,this.unmount),document.addEventListener(\`astro:after-swap\`,this.unmount,{once:!0})}connectedCallback(){if(!this.hasAttribute(\`await-children\`)||document.readyState===\`interactive\`||document.readyState===\`complete\`)this.childrenConnectedCallback();else{let e=()=>{document.removeEventListener(\`DOMContentLoaded\`,e),t.disconnect(),this.childrenConnectedCallback()},t=new MutationObserver(()=>{var t;((t=this.lastChild)==null?void 0:t.nodeType)===Node.COMMENT_NODE&&this.lastChild.nodeValue===\`astro:end\`&&(this.lastChild.remove(),e())});t.observe(this,{childList:!0}),document.addEventListener(\`DOMContentLoaded\`,e)}}async childrenConnectedCallback(){let e=this.getAttribute(\`before-hydration-url\`);e&&await import(e),this.start()}getRetryImportUrl(e){let t=new URL(e,document.baseURI);return t.searchParams.set(\`astro-retry\`,Date.now().toString()),t.toString()}async importWithRetry(e){try{return await import(e)}catch(t){return await new Promise(e=>setTimeout(e,1e3)),import(this.getRetryImportUrl(e))}}handleHydrationError(e){let t=this.getAttribute(\`component-url\`),n=new CustomEvent(\`astro:hydration-error\`,{cancelable:!0,bubbles:!0,composed:!0,detail:{error:e,componentUrl:t}});this.dispatchEvent(n)&&console.error(\`[astro-island] Error hydrating \${t}\`,e)}async start(){let e=JSON.parse(this.getAttribute(\`opts\`)),t=this.getAttribute(\`client\`);if(Astro[t]===void 0)window.addEventListener(\`astro:\${t}\`,()=>this.start(),{once:!0});else try{await Astro[t](async()=>{let e=this.getAttribute(\`renderer-url\`);try{let[t,{default:n}]=await Promise.all([this.importWithRetry(this.getAttribute(\`component-url\`)),e?this.importWithRetry(e):Promise.resolve({default:()=>()=>{}})]),r=this.getAttribute(\`component-export\`)||\`default\`;if(r.includes(\`.\`)){this.Component=t;for(let e of r.split(\`.\`)){if(i.has(e)||!this.Component||typeof this.Component!=\`object\`&&typeof this.Component!=\`function\`||!Object.hasOwn(this.Component,e))throw Error(\`Invalid component export path: \${r}\`);this.Component=this.Component[e]}}else{if(i.has(r))throw Error(\`Invalid component export path: \${r}\`);this.Component=t[r]}return this.hydrator=n,this.hydrate}catch(e){return this.handleHydrationError(e),()=>{}}},e,this)}catch(e){this.handleHydrationError(e)}}attributeChangedCallback(){this.hydrate()}}r(o,\`observedAttributes\`,[\`props\`]),customElements.get(\`astro-island\`)||customElements.define(\`astro-island\`,o)}})();`;