@inweb/viewer-visualize
Version:
JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS
77 lines (71 loc) • 3.43 kB
text/typescript
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
// All rights reserved.
//
// This software and its documentation and related materials are owned by
// the Alliance. The software may only be incorporated into application
// programs owned by members of the Alliance, subject to a signed
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable
// trade secrets of the Alliance and its suppliers. The software is also
// protected by copyright law and international treaty provisions. Application
// programs incorporating this software must include the following statement
// with their copyright notices:
//
// This application incorporates Open Design Alliance software pursuant to a
// license agreement with Open Design Alliance.
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
// All rights reserved.
//
// By use of this software, its documentation or related materials, you
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
import { IComponentsRegistry, componentsRegistry } from "@inweb/viewer-core";
import { RenderLoopComponent } from "./RenderLoopComponent";
import { ResizeCanvasComponent } from "./ResizeCanvasComponent";
import { ZoomWheelComponent } from "./ZoomWheelComponent";
import { GestureManagerComponent } from "./GestureManagerComponent";
/**
* Viewer components registry. Use this registry to register custom components.
*
* To implement custom component:
*
* 1. Define a component class implements {@link IComponent}.
* 2. Define a constructor with a `viewer` parameter and add mouse event listeners for the specified viewer.
* 3. Define the component logic in the event listeners. For example, listen for the `mousedown` event and
* select objects when the left mouse button is pressed.
* 4. Override {@link IComponent.dispose} and remove mouse event listeners from the viewer.
* 5. Register component provider in the components registry by calling the
* {@link components.registerComponent}.
*
* @example Implementing a custom component.
*
* ```javascript
* import { IComponent, components, Viewer } from "@inweb/viewer-visualize";
*
* class MyComponent implements IComponent {
* protected viewer: Viewer;
*
* constructor(viewer: Viewer) {
* this.viewer = viewer;
* this.viewer.addEventListener("mousedown", this.onMouseDown);
* }
*
* override dispose() {
* this.viewer.removeEventListener("mousedown", this.onMouseDown);
* }
*
* onMouseDown = (event: PointerEvent) => {
* // place custom logic here
* };
* }
*
* components.registerComponent( "MyComponent", (viewer): IComponent => new MyComponent(viewer));
* ```
*/
export const components: IComponentsRegistry = componentsRegistry("visualizejs");
// build-in components
components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
components.registerComponent("ZoomWheelComponent", (viewer) => new ZoomWheelComponent(viewer));
components.registerComponent("GestureManagerComponent", (viewer) => new GestureManagerComponent(viewer));