# inkable

> Provides inkable attribute and ink-stroke element for inking applications

Latest version **0.0.21** (published 2024-06-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install inkable
pnpm add inkable
yarn add inkable
bun add inkable
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.21 |
| Published | 2024-06-16 |
| First published | 2022-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | tbuckley |
| Maintainers | tbuckley89 |

## Links

- npm: https://www.npmjs.com/package/inkable
- npm.io page: https://npm.io/package/inkable

## Dependencies (3)

- [lit](https://npm.io/package/lit.md) ^2.0.2
- [mathjs](https://npm.io/package/mathjs.md) ^10.1.0
- [ml-matrix](https://npm.io/package/ml-matrix.md) ^6.8.2

## Recent versions

- 0.0.21 (latest) — 2024-06-16
- 0.0.20 — 2024-04-14
- 0.0.19 — 2024-02-15
- 0.0.18 — 2024-01-22
- 0.0.17 — 2024-01-16
- 0.0.16 — 2024-01-15
- 0.0.15 — 2023-12-22
- 0.0.14 — 2023-12-07
- 0.0.13 — 2022-10-12
- 0.0.12 — 2022-10-12
- 0.0.11 — 2022-10-12
- 0.0.10 — 2022-06-17
- 0.0.9 — 2022-06-17
- 0.0.8 — 2022-06-10
- 0.0.7 — 2022-06-09
- … 6 more at https://npm.io/package/inkable/versions

## README

# inkable

A library for creating inking apps.

## Installation

```bash
npm install inkable
npm install --save-dev inkable
```

## Usage

```html
<script type="module">
  import 'inkable';
</script>

<ink-stroke></ink-stroke>
```

## `inkable` attribute

Allow users to ink on any element. It listens for pointer events and generates strokes, firing events.

_Note: in order to render with low latency on Chromebooks, it creates a transparent overlay. In certain situations, strokes may appear on top of objects while writing and then snap below them when finished._

```html
<div inkable tool="pen" inkable-color="#ff0000" inkable-weight="1"></div>
```

### Import

```js
import 'inkable';
```

### Attributes

- `inkable-tool` (default: `pen`) - `pen`, `eraser`, `none`
- `inkable-color` [pen-only] (default: `#000000`) - a hex string
- `inkable-opacity` [pen-only] (default: `1`) - a number 0-1
- `inkable-weight` [pen-only] (default: `2`) - number of pixels wide the stroke should be at maximum

### Events

- `stroke-start` - Fired during `pointerdown` to indicate the `inkable` will start interpreting the input as a stroke. `e.preventDefault()` will cancel rendering. `Event.detail` contains the `pointerId` and `pointerType` from the corresponding PointerEvent.
- `stroke` - Fired when a stroke is completed. `Event.detail.stroke` is an `<ink-stroke>`. By default, it will append the stroke to the `inkable` element. `e.preventDefault()` will stop it from being automatically added.
- `erase` (bubbles) - Fired on an element that has been hit be the eraser tool and is about to be removed from the DOM. By default, only InkStroke may be erased. Add `eraseable="true"` to other elements to allow them to be erased. If `eraseable` is not set on an element, it defaults to its nearest ancestor's value (if one exists). `e.preventDefault()` will stop the element from being removed from the DOM.

## `<ink-stroke>`

A single stroke as an HTML Element. Implements `FreeformMixin` for transforming.

### Import

```js
import 'inkable/dist/src/ink-stroke.js';
```

### Attributes

- `points` - an array of `{x,y,p?,t?}` objects. `p` is an optional pressure 0-1.0, and `t` is an optional timestamp.
- `color` - a hex string or valid CSS color.
- `weight` - number of pixels wide the stroke should be at maximum.

## `<ink-canvas>`

A canvas for absolutely positioned elements, including `<ink-stroke>`. Handles pan/zoom events. Implements `FreeformMixin` for transforming.

### Import

```js
import 'inkable/dist/src/ink-canvas.js';
```

### Attributes

- `contain` - by default, the InkCanvas itself will move as the user pans/zooms it. Set `contain="true"` to instead pan/zoom the InkCanvas's contents. _(Note: just adding `contain` will have no effect, must set `contain="true"`)_
- `width` - if not contained, the width of the InkCanvas
- `height` - if not contained, the height of the InkCanvas

### Methods

- `animateProps({transform?, width?, height?}, options)` - similar to HTMLElement.animate(), but animates the properties of the InkCanvas. Returns a promise that resolves when the animation is complete.

### Events

- `transform-start` - Fired at the start of a transform. `Event.detail` includes information about the transform (`initial` matrix, `transform` matrix, `center` point, and `final` matrix), `pointerType` (same as PointerEvent: mouse, touch, pen), and `transformType` (idle, pan, pinch-zoom). `e.preventDefault()` will skip the transform. _(Note: expect transformType states to change)_
- `transform-change` - Fired before setting this element's transform to the event's `final` transform. Same properties as `transform-start`. `e.preventDefault()` will skip setting `final`, or `final` can be modified. See `canvas-plugins/` for examples of ways to modify the event.
- `transform-end` - Fired at the start of a transform. Same properties as `transform-start`.

## `FreeformMixin`

### Properties

- `transform` - a `Transform` object representing a transform on the stroke (see ml-matrix on npm).
- `rotation` - rotation in degrees (default `0`)
- `scaleFactor` - scale factor (default `1.0`)
- `translation` - translation in pixels (default `{x:0,y: 0}`)

### Methods

- `transform(Transform)` - apply a transform to the element
- `rotateBy(degrees)` - rotate the element by `degrees` (clockwise in screen-space)
- `scaleBy(factor)` - scale the element by `factor`
- `translateBy({x,y})` - translate the element by `x` and `y`

## Demoing with Storybook

To run a local instance of Storybook for your component, run

```bash
npm run storybook
```

To build a production version of Storybook, run

```bash
npm run storybook:build
```

## Linting and formatting

To scan the project for linting and formatting errors, run

```bash
npm run lint
```

To automatically fix linting and formatting errors, run

```bash
npm run format
```

Ensure all imports have .js by searching & replacing:

- Search: `^import (.*) from '(\.(?:(?!js).)+)';$`
- Replace: `import $1 from '$2.js';`

## Testing with Web Test Runner

To execute a single test run:

```bash
npm run test
```

To run the tests in interactive watch mode run:

```bash
npm run test:watch
```

---
_Source: https://npm.io/package/inkable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
