# Rixl Media SDK for Lit and JavaScript

Web components for Rixl images, adaptive HLS video playback, and infinite media feeds. Use `@rixl/media-lit` in Lit, vanilla JavaScript, or any application that supports custom elements.

[Documentation](https://developers.rixl.com/en/sdk/media-lit) · [npm](https://www.npmjs.com/package/@rixl/media-lit) · [Dashboard](https://dash.rixl.com)

## What you get

- `<rixl-video>`: HLS playback, captions, quality selection, fullscreen, and picture-in-picture.
- `<rixl-image>`: lazy loading and ThumbHash placeholders when available.
- `<rixl-feed>`: vertical media feeds with pagination, looping, and automatic advancement.
- Typed element properties and DOM events.
- Included styles inside shadow DOM, with no Tailwind CSS setup.

These are the UI components used by the Rixl React, Vue, Svelte, Angular, and Astro adapters.

## Install

```sh
npm install @rixl/media-lit
```

Lit 3 is included as a dependency. Use an ES-module-aware build tool and a browser with custom-element and shadow-DOM support.

## Quick start: vanilla TypeScript

Connect before adding media elements to the document:

```ts
import "@rixl/media-lit/video";
import {connect} from "@rixl/media-lit/core";

await connect({
  baseUrl: "https://api.rixl.com",
  apiKey: "YOUR_PUBLIC_API_KEY",
});

const video = document.createElement("rixl-video");
video.videoId = "YOUR_VIDEO_ID";
video.muted = true;
video.style.cssText = "display:block;width:100%;aspect-ratio:16/9";
document.body.append(video);
```

Use credentials intended for browser access. Reuse the connection if your application already authenticates the shared `@rixl/sdk` client.

## Attributes and properties

For declarative markup added after connecting, use the media ID attributes:

```html
<rixl-video video-id="YOUR_VIDEO_ID" muted></rixl-video>
<rixl-image image-id="YOUR_IMAGE_ID" alt="Mountain lake at sunrise"></rixl-image>
<rixl-feed feed-id="YOUR_FEED_ID" muted></rixl-feed>
```

Import `/image` and `/feed` before using those tags. The regular HTML `id` attribute identifies the DOM element; `image-id` and `video-id` select Rixl media.

| Element        | ID attribute | JavaScript property |
| -------------- | ------------ | ------------------- |
| `<rixl-image>` | `image-id`   | `imageId`           |
| `<rixl-video>` | `video-id`   | `videoId`           |
| `<rixl-feed>`  | `feed-id`    | `feedId`            |

Boolean attributes follow HTML presence semantics: `muted="false"` still enables mute. Set a boolean property to `false` in JavaScript or omit the attribute. Property-only options such as `volume` are set in JavaScript.

## Use in a Lit template

After initializing the SDK, render with Lit's property bindings:

```ts
import {html} from "lit";
import "@rixl/media-lit/video";

export const player = (videoId: string) => html`
  <rixl-video .videoId=${videoId} .muted=${true} .volume=${0.7} style="display:block;width:100%;aspect-ratio:16/9"></rixl-video>
`;
```

## Events

```ts
import "@rixl/media-lit/video";

const video = document.querySelector("rixl-video");
video?.addEventListener("paused-change", (event) => {
  if (event instanceof CustomEvent) console.log(event.detail.paused);
});
video?.addEventListener("rixl-analytics", (event) => {
  if (event instanceof CustomEvent) console.log(event.detail.event);
});
```

Video state events include `paused-change` and `loading-change`; Feed emits `mute-change` and `current-index-change`. Image's `loading-change` detail is a boolean; Video's detail is `{loading: boolean}`.

## Styling and rendering

Use normal CSS to size and position the hosts. Give images and videos an explicit height or aspect ratio, and feeds a height. The components include their internal styles in shadow DOM; application selectors do not reach internal controls.

Media contents render in the browser. For a documented server-rendering integration, use the [React](https://www.npmjs.com/package/@rixl/media-react) or [Astro](https://www.npmjs.com/package/@rixl/media-astro) adapter; both render hosts on the server and initialize media in the browser.

## Imports

| Import                  | Purpose                                     |
| ----------------------- | ------------------------------------------- |
| `@rixl/media-lit/image` | Register and export `RixlImage`             |
| `@rixl/media-lit/video` | Register and export `RixlVideo`             |
| `@rixl/media-lit/feed`  | Register and export `RixlFeed`              |
| `@rixl/media-lit/core`  | Headless APIs, stores, utilities, and types |
| `@rixl/media-lit`       | All top-level media components              |

Each component subpath registers its tag automatically. An image-only subpath import excludes video, feed, and HLS code.
