Frameworks

The package uses custom elements, but framework rules for object properties and DOM events differ. React 18 requires the supplied adapters; React 19 can handle native custom elements, yet the same adapters provide a consistent typed interface. Vue requires compiler configuration. Choose a browser-only boundary when the application also renders on a server.

Use the React components in versions 18 and 19

mosaicary/react exports typed catalogue blocks and the converter; mosaicary/react/viewer exports the two 3D viewers. Importing either entry registers its elements. Pass objects as skin, build, item or words, and use callbacks such as onPick, onRead, onConvert and onError where supported. className, styles and boolean flags are forwarded correctly. A component ref points to the underlying element, so the converter ref exposes take(file).

import { useRef, useState } from 'react';
import type { Skin } from 'mosaicary';
import { MosaicaryCatalog, MosaicaryBuildConverter } from 'mosaicary/react';
import { MosaicarySkin } from 'mosaicary/react/viewer';
import type { MosaicaryBuildConverter as Converter } from 'mosaicary/catalog';

export function Wardrobe() {
  const [skin, setSkin] = useState<Skin | null>(null);
  const converter = useRef<Converter>(null);
  return (
    <>
      <MosaicaryCatalog
        kinds="skins"
        size="64"
        selected={skin?.id}
        onPick={(event) => {
          if (event.detail.kind === 'skins') setSkin(event.detail.item);
        }}
      />
      {skin && <MosaicarySkin skin={skin} still style={{ height: 360 }} />}
      <MosaicaryBuildConverter ref={converter} />
    </>
  );
}
// converter.current?.take(file)

Configure Vue custom elements

Pass isMosaicaryElement from mosaicary/vue to Vue’s compilerOptions.isCustomElement; otherwise Vue attempts to resolve each tag as a Vue component. Import the registration modules in browser code. Use property binding such as :skin="skin" for objects and @mosaicary-pick for the native event. The event argument is a CustomEvent, with resource data inside detail, rather than the resource object itself.

// vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { isMosaicaryElement } from 'mosaicary/vue';
export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: { isCustomElement: isMosaicaryElement },
      },
    }),
  ],
});
<script setup>
import { ref } from 'vue';
import 'mosaicary/catalog/define';
import 'mosaicary/viewer/define';
const skin = ref(null);
function picked(event) {
  if (event.detail.kind === 'skins') skin.value = event.detail.item;
}
</script>
<template>
  <mosaicary-catalog kinds="skins" @mosaicary-pick="picked" />
  <mosaicary-skin v-if="skin" :skin="skin" style="height: 360px" />
</template>

Use native elements with Svelte and Angular

Svelte can render the registered tags and listen to their native custom events. Assign object properties on the element reference when framework syntax or version makes binding ambiguous, and remove manual listeners during cleanup. Angular templates require CUSTOM_ELEMENTS_SCHEMA in the component or module that contains the tags. Use Angular property and event bindings for objects and mosaicary-pick. The schema permits custom elements; it does not register them or replace their TypeScript definitions.

// Angular component metadata:
import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
@Component({
  standalone: true,
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: '<mosaicary-catalog></mosaicary-catalog>',
})
export class CataloguePage {}

Keep registration outside server rendering

/define and the React adapter entries access browser custom-element registration during import. Do not import them at a server module’s top level. A browser effect can dynamically import /define, then create the element and assign its properties. In Next.js, use a client boundary; React adapter modules should additionally be loaded through a client-only dynamic component with server rendering disabled. The use client directive alone is not a general exemption from server evaluation.

'use client';
import { useEffect } from 'react';
export default function BrowserCatalogue() {
  useEffect(() => {
    void import('mosaicary/catalog/define');
  }, []);
  return <div id="catalogue-host" />;
}
// Create and configure the element after the import resolves.
// For React wrappers in Next.js, use a client-only dynamic component
// (ssr:false), because the wrapper import itself registers elements.

Use the supplied TypeScript declarations

Registration imports carry element and global event declarations. document.querySelector knows registered literal tag names, and native addEventListener recognizes the package’s typed CustomEvents. Check detail.kind before accessing kind-specific resource fields. React adapters provide JSX prop types, avoiding a handwritten intrinsic-element declaration for React 18. Vue declarations do not replace the compiler setting above. Server rendering in Next.js, browser-specific engines and platform packaging still require validation in the consuming application.