UNPKG

@plattar/plattar-ar-adapter

Version:

Plattar AR Adapter for interfacing with Google & Apple WebAR

132 lines (131 loc) 4.34 kB
import { LauncherAR } from "../../ar/launcher-ar"; import { DecodedConfiguratorState } from "../../util/configurator-state"; import type PlattarEmbed from "../plattar-embed"; export declare enum ControllerState { None = 0, Renderer = 1, QRCode = 2 } export interface QRCodeOptions { readonly color: string; readonly qrType: string; readonly shorten: boolean; readonly margin: number; readonly detached: boolean; readonly url?: string | null; } /** * All Plattar Controllers are derived from the same interface */ export declare abstract class PlattarController { /** * Default QR Code rendering options */ protected _GetDefaultQROptions(opt?: QRCodeOptions | undefined | null): QRCodeOptions; private readonly _parent; protected _state: ControllerState; protected _element: HTMLElement | null; protected _prevQROpt: any; private _selectVariationObserver; private _selectVariationIDObserver; private _selectVariationSKUObserver; constructor(parent: PlattarEmbed); /** * Generates a brand new Configurator State from the provided SceneID or inputted Configurator State */ protected createConfiguratorState(): Promise<DecodedConfiguratorState>; /** * Generates and returns a new instance of the ConfiguratorState for this node */ abstract getConfiguratorState(): Promise<DecodedConfiguratorState>; /** * Called by the parent when a HTML Attribute has changed and the controller * requires an update */ abstract onAttributesUpdated(attributeName: string): Promise<void>; /** * Start the underlying Plattar Renderer for this Controller */ abstract startRenderer(): Promise<HTMLElement>; /** * Setup messenger observers to detect variation changes and apply to the internal * configuration state */ protected setupMessengerObservers(viewer: any, configState: DecodedConfiguratorState): void; /** * Remove all pre-existing observers */ protected removeMessengerObservers(): void; /** * Initialise and start AR mode if available */ startAR(): Promise<void>; /** * Start Rendering a QR Code with the provided options * @param options (optional) - The QR Code Options */ abstract startViewerQRCode(options: QRCodeOptions | undefined | null): Promise<HTMLElement>; /** * Decide which QR Code to render according to the qr-type attribute * @param options * @returns */ startQRCode(options: QRCodeOptions): Promise<HTMLElement>; /** * Displays a QR Code that sends the user direct to AR * @param options * @returns */ startARQRCode(options: QRCodeOptions): Promise<HTMLElement>; /** * Initialise and return a launcher that can be used to start AR */ abstract initAR(): Promise<LauncherAR>; /** * Removes the currently active renderer view from the DOM */ removeRenderer(): boolean; /** * Get the underlying renderer component (if any) */ abstract get element(): HTMLElement | null; /** * Returns the Parent Instance */ get parent(): PlattarEmbed; /** * Returns the specified attribute from the parent * @param attribute - The name of the attribute * @returns - The attribute value or null */ getAttribute(attribute: string): string | null; /** * Returns the specified attribute from the parent as a boolean * @param attribute - The name of the attribute * @returns - The attribute value */ getBooleanAttribute(attribute: string): boolean; /** * Sets a particular attribute into the HTML DOM * * @param attribute - The name of the attribute * @param value - The value of the attribute */ setAttribute(attribute: string, value: string): void; /** * Removes a particular attribute from HTML DOM * * @param attribute - The name of the attribute */ removeAttribute(attribute: string): void; /** * Appends the provided element into the shadow-root of the parent element * @param element - The element to append */ append(element: HTMLElement): void; /** * * @param element */ removeChild(element: HTMLElement): void; }