import { defineToolbarApp } from 'astro/toolbar'; import { icon } from "../assets/bag-of-tricks"; import imgSrc from '../assets/chamber.png'; const DTB_TOKEN = 'vtbot-inspection-chamber'; const VTBAG_REOPEN = '#vtbag-ui-reopen'; export default defineToolbarApp({ init(canvas, app) { createVtbotWindow(); document.addEventListener('astro:after-swap', createVtbotWindow); app.addEventListener('placement-updated', (evt) => { const windowElement = canvas.querySelector('astro-dev-toolbar-window'); windowElement && (windowElement.placement = evt instanceof CustomEvent && evt.detail.placement); }); function createVtbotWindow() { const astroWindow = document.createElement('astro-dev-toolbar-window'); astroWindow.insertAdjacentHTML('beforeend', `

The Bag of Tricks for Astro's View Transitions

The Bag offers reusable components, tips & tricks plus detailed info about Astro's view transitions and the View Transition API in general.

Visit The Bag's Website and star the Github project to support this work.

The Inspection Chamber

Reopen the Inspection Chamber

Put your view transitions through their paces!


If you see this text, bad things happened. If you got here in a web-container, like e.g. Stackblitz, try to open the preview of your project in a new tab. If this does not help, please file a bug report with the related errors from the browser's console.

You notice a little sign near the Inspection Chamber's power button:

Out of Order `); canvas.append(astroWindow); } app.onToggled((options) => { if (options.state) { const me = document.querySelector('astro-dev-toolbar')! .shadowRoot!.querySelector('astro-dev-toolbar-app-canvas[data-app-id="vtbot"]')! .shadowRoot!; const status = me.querySelector('#inspection-chamber-status')!; const button = me.querySelector('#inspection-chamber-button')!; if (!document.startViewTransition) { status.textContent = 'Your browser does not support view transitions.'; button.textContent = 'Out of Order'; button.disabled = true; } else if (top!.document.querySelector(VTBAG_REOPEN)) { // better: check for sessionStorage status.textContent = 'The Chamber is currently in standby mode.'; button.textContent = 'Reactivate'; button.addEventListener('click', () => { top!.sessionStorage.removeItem('vtbag-ui-standby'); top!.location.reload(); }); } else if (top!.document.querySelector('body > #vtbag-main-frame') && top!.sessionStorage.getItem(DTB_TOKEN) !== 'true') { status.innerHTML = 'This page has an <InspectionChamber /> component.'; button.textContent = 'Switch to standby mode'; button.addEventListener('click', () => { top!.sessionStorage.setItem('vtbag-ui-standby', 'true'); top!.location.reload(); }); } else if (top!.sessionStorage.getItem(DTB_TOKEN) === 'true') { status.textContent = 'Chamber was activated via Dev Toolbar.'; button.textContent = 'Turn off'; button.addEventListener('click', () => { top!.sessionStorage.removeItem(DTB_TOKEN); top!.location.reload(); }); } else { status.textContent = 'There is an Inspection Chamber here.'; button.textContent = 'Power up'; button.addEventListener('click', () => { top!.sessionStorage.removeItem('vtbag-ui-closed'); // ?? top!.sessionStorage.setItem(DTB_TOKEN, 'true'); top!.location.reload(); }); } } }); } });