# LasMind Vision – Accessibility Widget for Any Website

A drop-in accessibility menu for any website, by [LasMind](https://lasmind.com/tools/lasmind-vision). It is the same preference menu as the LasMind website and the LasMind Vision browser extension, because all three run on [`@lasmind/website-accessibility-core`](https://www.npmjs.com/package/@lasmind/website-accessibility-core).

- Colour blind filter for protanopia, deuteranopia and tritanopia, plus greyscale, with a strength slider
- Text size, high contrast, link underlines, text spacing, reduced motion, strong focus indicators
- Read aloud: click any text to hear it (text to speech). Tech words can be explained in simple English, with Hindi and Tamil in beta when the device has that voice
- Spoken guide: short spoken instructions when the menu opens
- Settings are saved in the visitor's browser (`localStorage`). Nothing is sent anywhere

The colour vision test is not part of this package. It lives at [lasmind.com/tools/color-blind-test](https://lasmind.com/tools/color-blind-test).

## Install

```bash
npm install @lasmind/website-accessibility
```

It is plug and play: the button and the menu bring their own styles (inside a shadow root), so you add no CSS and your site's CSS cannot break them.

```ts
import { init } from "@lasmind/website-accessibility";

init(); // floating button in the bottom-right corner
```

### Next.js (App Router) / React

The widget touches `document`, so start it in an effect from a client component:

```tsx
"use client";
import { useEffect, useRef } from "react";

export default function AccessibilityButton() {
  const slot = useRef<HTMLSpanElement>(null);
  useEffect(() => {
    let destroy: (() => void) | undefined;
    let cancelled = false;
    void import("@lasmind/website-accessibility").then(({ init }) => {
      if (cancelled || !slot.current) return;
      // A 36px button inside your header; the menu still opens as a side drawer.
      destroy = init({ placement: "inline", size: "sm", container: slot.current }).destroy;
    });
    return () => {
      cancelled = true;
      destroy?.();
    };
  }, []);
  return <span ref={slot} />;
}
```

Leave out `placement`, `size` and `container` for the floating corner button.

### Your own button

```ts
const a11y = init({ trigger: false });
document.querySelector("#my-a11y-button")!.addEventListener("click", () => a11y.toggle());
```

Focus goes back to your button when the menu closes (Escape, the close button or `close()`). Set `aria-haspopup="dialog"` on your button.

### Web component

```ts
import { defineElement } from "@lasmind/website-accessibility";

defineElement();
```

```html
<lasmind-a11y side="left"></lasmind-a11y>
<lasmind-a11y placement="inline" size="sm"></lasmind-a11y>
```

Attributes: `side`, `placement`, `size`, `trigger="off"`, `label`, `check-url`, `storage-key`, `credit="off"`, `update-check`. The element's handle is `element.widget`.

### Without a build step

```html
<script src="https://cdn.jsdelivr.net/npm/@lasmind/website-accessibility@0.2.3/dist/website-accessibility.min.js" data-auto defer></script>
```

Script-tag options: `data-side="left"`, `data-size="sm"`, `data-update-check`. Without `data-auto`, use `<lasmind-a11y>` or `window.LasmindA11y.init({...})`.

## Options

| Option | Default | |
| --- | --- | --- |
| `side` | `"right"` | Corner for the floating button, and the side the menu opens on: `"left"` or `"right"` |
| `placement` | `"floating"` | `"floating"`: fixed corner button. `"inline"`: a normal element inside `container` (for headers and toolbars). The menu is always a fixed side drawer, mounted in its own shadow host on `document.body`, so a sticky header with `backdrop-filter`, `transform`, `filter`, `contain` or `will-change` cannot clip it. |
| `size` | `"md"` | Button size: `"md"` (52px) or `"sm"` (36px) |
| `trigger` | `true` | `false` hides the built-in button; open the menu with `toggle()` / `open()` from your own button |
| `label` | `"Accessibility options"` | Accessible name of the built-in button |
| `checkUrl` | LasMind colour check | Where "Take the colour check" goes. Default `https://lasmind.com/tools/color-blind-test` in a new tab. An http(s) URL opens in a new tab; a path like `"/eye-test"` opens on your site. Web component: `check-url`. |
| `onOpenCheck` | none | `(event) => void`, called when a visitor starts the colour check. Call `event.preventDefault()` to handle it yourself (for example `router.push`). |
| `storageKey` | `"lasmind-a11y-settings"` | `localStorage` key for saved settings. The old default `"lasmind-a11y-widget"` is read once and copied over. |
| `container` | `document.body` | Element the widget is added to |
| `showCredit` | `true` | Show the "Powered by LasMind" link |
| `updateCheck` | `false` | Check for a newer version of this package once a day (see below). Web component: `update-check` attribute. Script tag: `data-update-check`. |

`init()` returns `{ open, close, toggle, isOpen, element, portal, getSettings, setSettings, destroy }`. `element` is the trigger's shadow host (inside `container`); `portal` is the drawer's shadow host (`[data-lasmind-a11y-portal]`, always on `document.body`, removed by `destroy()`). The installed version is exported as `VERSION` and shown at the bottom of the menu.

### Theming the button

Set CSS variables on the container (or any ancestor), or style the exposed parts. No CSS injection needed.

```css
.site-header {
  --lm-a11y-trigger-bg: transparent;
  --lm-a11y-trigger-ink: currentColor;
  --lm-a11y-trigger-border: transparent;
  --lm-a11y-trigger-size: 36px;      /* any size */
  --lm-a11y-trigger-radius: 8px;
  --lm-a11y-trigger-shadow: none;
}
[data-lasmind-a11y-ui]::part(trigger):hover { background: #f1f5f9; }
```

Parts: `trigger`, `trigger-dot` (the "on" dot) and `frame` (the menu wrapper). The menu itself keeps the LasMind design.

`ensurePanelStyles` is still exported for older workarounds. From 0.2.2 the widget adds the menu styles itself and the call does nothing, so you can delete it.

### Update check (opt-in)

With `updateCheck: true`, the widget asks `lasmind.com` for the latest published version at most once every 24 hours (cached in `localStorage`). The request is an anonymous GET with no settings or personal data. If a newer version exists:

- it is logged once to the browser console, with the npm link;
- on `localhost` only, the menu also shows a "Version x.y.z is available" card, which can be dismissed. Your visitors never see it.

To update, run `npm install @lasmind/website-accessibility@latest`, or change the version in your CDN link.

## Good to know

- This is a visitor preference menu. It helps people adjust your pages. It does not make a website WCAG or ADA compliant. Build to [WCAG 2.2](https://www.w3.org/WAI/fundamentals/accessibility-intro/) as well.
- If a visitor has the LasMind Vision extension, it marks the page and the widget leaves colour correction to it, so colours are never corrected twice.
- The colour vision screening is not part of the widget. Results are health data; if you build it with `@lasmind/website-accessibility-core/screening`, cover it in your privacy policy and say it is a screening, not a diagnosis.

## License

- **Versions 0.2.0 and earlier: MIT**, by [LasMind Technologies](https://lasmind.com). Those MIT rights are permanent.
- **Version 0.3.0 onward: LasMind Commercial License.** Free for personal, non-commercial use. Commercial or production use by an organization needs a license.

Full terms: <https://lasmind.com/license>. For a commercial license, talk to sales at <https://lasmind.com/contact-us?interest=lasmind-vision-license#enquiry> or [info@lasmind.com](mailto:info@lasmind.com).
