Environments
Global companion
A global pet floats above the page and uses viewport coordinates.
import { createPet } from '@flowscape-ui/mimimo';
import { mochi } from '@flowscape-ui/mimimo-pet-mochi';
// Call after your container mounts.
export function mountCompanion(container: HTMLElement) {
const lifetime = new AbortController();
const pet = createPet({
character: mochi,
anchor: 'bottom-right',
});
pet.addReaction('click', 'happy');
pet.say('Hello, friend!');
return () => {
lifetime.abort();
pet.destroy();
};
}
// Keep the returned cleanup and call it when the view is removed.'use client';
import { useEffect, useRef } from 'react';
import { createPet } from '@flowscape-ui/mimimo';
import { mochi } from '@flowscape-ui/mimimo-pet-mochi';
export default function Companion() {
const host = useRef<HTMLDivElement>(null);
useEffect(() => {
const container = host.current;
if (!container) return;
const lifetime = new AbortController();
const pet = createPet({
character: mochi,
anchor: 'bottom-right',
});
pet.addReaction('click', 'happy');
pet.say('Hello, friend!');
return () => {
lifetime.abort();
pet.destroy();
};
}, []);
return <div ref={host} style={{ height: 360, position: 'relative' }} />;
}<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { createPet } from '@flowscape-ui/mimimo';
import { mochi } from '@flowscape-ui/mimimo-pet-mochi';
const host = ref<HTMLElement | null>(null);
let cleanup: (() => void) | undefined;
onMounted(() => {
const container = host.value;
if (!container) return;
const lifetime = new AbortController();
const pet = createPet({
character: mochi,
anchor: 'bottom-right',
});
pet.addReaction('click', 'happy');
pet.say('Hello, friend!');
cleanup = () => {
lifetime.abort();
pet.destroy();
};
});
onBeforeUnmount(() => cleanup?.());
</script>
<template>
<div ref="host" style="height: 360px; position: relative" />
</template>Modern browsers use the top layer to keep the pet interactive above ordinary elements, popovers and modal dialogs. Browsers without the Popover API use a z-index fallback, which cannot cover native modal dialogs.
Local companion
Drag the pet, or focus it and use arrow keys. Reduced motion follows your system settings.
Pass a container to keep the companion inside its client rectangle.
<div id="pet-home" style="height: 360px"></div>import { createPet } from '@flowscape-ui/mimimo';
import { mochi } from '@flowscape-ui/mimimo-pet-mochi';
// Call after your container mounts.
export function mountCompanion(container: HTMLElement) {
const lifetime = new AbortController();
const pet = createPet({
character: mochi,
container,
anchor: 'center',
});
pet.addReaction('click', 'happy');
pet.say('Hello, friend!');
return () => {
lifetime.abort();
pet.destroy();
};
}
// Keep the returned cleanup and call it when the view is removed.'use client';
import { useEffect, useRef } from 'react';
import { createPet } from '@flowscape-ui/mimimo';
import { mochi } from '@flowscape-ui/mimimo-pet-mochi';
export default function Companion() {
const host = useRef<HTMLDivElement>(null);
useEffect(() => {
const container = host.current;
if (!container) return;
const lifetime = new AbortController();
const pet = createPet({
character: mochi,
container,
anchor: 'center',
});
pet.addReaction('click', 'happy');
pet.say('Hello, friend!');
return () => {
lifetime.abort();
pet.destroy();
};
}, []);
return <div ref={host} style={{ height: 360, position: 'relative' }} />;
}<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { createPet } from '@flowscape-ui/mimimo';
import { mochi } from '@flowscape-ui/mimimo-pet-mochi';
const host = ref<HTMLElement | null>(null);
let cleanup: (() => void) | undefined;
onMounted(() => {
const container = host.value;
if (!container) return;
const lifetime = new AbortController();
const pet = createPet({
character: mochi,
container,
anchor: 'center',
});
pet.addReaction('click', 'happy');
pet.say('Hello, friend!');
cleanup = () => {
lifetime.abort();
pet.destroy();
};
});
onBeforeUnmount(() => cleanup?.());
</script>
<template>
<div ref="host" style="height: 360px; position: relative" />
</template>The companion follows the container while scrolling. Dragging and programmatic positions are constrained to its bounds. The artwork and panels are clipped, including when the container is partially outside the viewport.
Local pets live inside their container's stacking context, above its ordinary content. They do not enter the browser's top layer or cover unrelated navigation, popovers or modal dialogs. Mimimo temporarily adds positioning and isolation when needed, restoring its changes after the last local pet is destroyed.
Coordinates are in unscaled CSS pixels. CSS-scaled containers are not supported. Style the host through pet.element, CSS variables and shadow parts.
Cleanup
Call pet.destroy() when your component unmounts, before removing its container. This releases media, observers, listeners and pending work.