Web Components
The Aircada Web Component package registers the <air-viewer> custom element for embedding interactive 3D scenes into Shopify, WooCommerce, Magento, and static HTML pages without React or bundler dependencies.
<air-viewer> Web Component & PostMessage Bridge | Aircada Docs#
Encapsulated Custom Element Architecture
AirViewerElement registers <air-viewer> via customElements.define('air-viewer', AirViewerElement) with Open Shadow DOM encapsulation and native Declarative Shadow DOM (DSD) support. Host storefront stylesheets cannot bleed into 3D overlays, HUD controls, option drawers, or initial loading indicators.
Viewport GPU Hibernation
When lazy or unload-when-hidden is enabled, an IntersectionObserver monitors the host element bounds. Scrolling <air-viewer> out of the viewport suspends active WebGL/WebGPU rendering and releases idle GPU buffers so multi-viewer product pages stay under mobile VRAM ceilings.
Bidirectional PostMessage Bridge
AircadaEmbedder and airStudioBridge exchange typed CommandTypeIn and CommandTypeOut messages between the host page and the viewer runtime. Hosts push option updates or camera commands and listen for onSetupComplete, onReady, onOptionChanged, onPriceChanged, and onSnapshotCaptured, using explicit domain whitelists instead of wildcard targetOrigin values in production.
| Name | Kind | Purpose |
|---|---|---|
| smart-id | Attribute (string) | Identifies the published Aircada 3D project to hydrate. |
| lazy | Attribute (boolean) | Defers engine initialization until the element enters the viewport. |
| unload-when-hidden | Attribute (boolean) | Disposes GPU resources when the element leaves the viewport. |
| devPort | Attribute (number) | Connects to a local CLI dev server port during development. |
| onOptionChanged / onPriceChanged | Outbound Event | Notifies the host storefront when selections or prices update. |
| onSnapshotCaptured | Outbound Event | Delivers rendered 3D proof image payloads for cart attachment. |
<air-viewer
smart-id="your-project-smart-id"
lazy
unload-when-hidden
></air-viewer>
<script type="module">
const viewer = document.querySelector("air-viewer");
window.addEventListener("message", (event) => {
if (event.data?.type === "onPriceChanged") {
console.log("Updated price:", event.data.payload);
}
});
</script>