# Magnify

A paper poster with one huge letter printed on it, and a magnifying glass over it. Up close the letter is not solid ink: it is rows of tiny characters, and the lens shows them. The glass carries its own copy of the poster at the zoom you set, kept exactly under the lens as it moves, so the magnification is real rather than a blurred scale. Move the pointer to inspect and click to push the zoom further. On arrival the outline traces itself, the ink floods in and the glass drops into place. The lens tilts with its speed, floats a little at rest and lifts its shadow while held.

<demo-magnify>



</demo-magnify>

## Installation

```bash
npx shadcn-vue@latest add "https://nxui.geoql.in/r/magnify.json"
```

## Usage

```vue
<script setup lang="ts">
  import { computed } from 'vue';
  import Magnify from '~/components/ui/magnify/Magnify.vue';

  const colorMode = useColorMode();
  const theme = computed(() => (colorMode.value === 'dark' ? 'dark' : 'light'));

  function onZoomChange(zoomed: boolean) {
    console.log(zoomed);
  }
</script>

<template>
  <Magnify
    glyph="A"
    micro="a"
    :zoom="2.6"
    :zoom-max="4.2"
    :lens-radius="50"
    :theme="theme"
    @zoom-change="onZoomChange"
  />
</template>
```

The poster is drawn in a fixed 500 × 680 space and scaled to its width, so `lens-radius` and the lens position are in poster units. The letter uses your site font at weight 700.

## Props

<table>
<thead>
  <tr>
    <th>
      Prop
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        theme
      </code>
    </td>
    
    <td>
      <code>
        'light' | 'dark'
      </code>
    </td>
    
    <td>
      <code>
        'light'
      </code>
    </td>
    
    <td>
      Cream paper with black ink, or graphite with cream.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        glyph
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'A'
      </code>
    </td>
    
    <td>
      The big letter on the poster (up to two characters).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        micro
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'a'
      </code>
    </td>
    
    <td>
      The tiny characters the letter is printed from.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        zoom
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        2.6
      </code>
    </td>
    
    <td>
      Magnification at rest.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        zoom-max
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        4.2
      </code>
    </td>
    
    <td>
      Magnification after a click or Enter.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        lens-radius
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        50
      </code>
    </td>
    
    <td>
      The glass radius in poster units (the poster is 500 wide).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        size
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        380
      </code>
    </td>
    
    <td>
      The poster width in px. It never grows past its container.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        intro
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      The outline trace and the lens dropping in on arrival.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hint
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      The "Move to inspect · Click to zoom" line under the poster.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        class
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      Extra classes for the root element.
    </td>
  </tr>
</tbody>
</table>

## Events

<table>
<thead>
  <tr>
    <th>
      Event
    </th>
    
    <th>
      Payload
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        zoom-change
      </code>
    </td>
    
    <td>
      <code>
        (zoomed: boolean)
      </code>
    </td>
    
    <td>
      Fires when the zoom toggles.
    </td>
  </tr>
</tbody>
</table>

## Exposed

<table>
<thead>
  <tr>
    <th>
      Method
    </th>
    
    <th>
      Signature
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        moveTo
      </code>
    </td>
    
    <td>
      <code>
        (x: number, y: number)
      </code>
    </td>
    
    <td>
      Move the lens to a point in poster units.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        setZoomed
      </code>
    </td>
    
    <td>
      <code>
        (zoomed: boolean)
      </code>
    </td>
    
    <td>
      Set the zoom state.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        toggleZoom
      </code>
    </td>
    
    <td>
      <code>
        ()
      </code>
    </td>
    
    <td>
      Toggle between <code>
        zoom
      </code>
      
       and <code>
        zoom-max
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        rest
      </code>
    </td>
    
    <td>
      <code>
        ()
      </code>
    </td>
    
    <td>
      Put the lens back at rest and drop the zoom.
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- The poster is one focusable `role="img"` with a label that names the letter, the micro characters and the controls.
- Arrow keys move the lens 10 poster units (Shift for 30). Enter or Space toggles the zoom. Escape puts the lens back at rest.
- A visible focus ring shows on keyboard focus.
- With reduced motion the intro is skipped, the lens does not tilt or float, and the theme switches without a cross-fade.

Ported from [Magnify](https://pinui.xyz/components/magnify) by Pin UI, MIT licence.
