inkable v0.0.21
inkable
A library for creating inking apps.
Installation
npm install inkable
npm install --save-dev inkableUsage
<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.
<div inkable tool="pen" inkable-color="#ff0000" inkable-weight="1"></div>Import
import 'inkable';Attributes
inkable-tool(default:pen) -pen,eraser,noneinkable-colorpen-only (default:#000000) - a hex stringinkable-opacitypen-only (default:1) - a number 0-1inkable-weightpen-only (default:2) - number of pixels wide the stroke should be at maximum
Events
stroke-start- Fired duringpointerdownto indicate theinkablewill start interpreting the input as a stroke.e.preventDefault()will cancel rendering.Event.detailcontains thepointerIdandpointerTypefrom the corresponding PointerEvent.stroke- Fired when a stroke is completed.Event.detail.strokeis an<ink-stroke>. By default, it will append the stroke to theinkableelement.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. Adderaseable="true"to other elements to allow them to be erased. Iferaseableis 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
import 'inkable/dist/src/ink-stroke.js';Attributes
points- an array of{x,y,p?,t?}objects.pis an optional pressure 0-1.0, andtis 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
import 'inkable/dist/src/ink-canvas.js';Attributes
contain- by default, the InkCanvas itself will move as the user pans/zooms it. Setcontain="true"to instead pan/zoom the InkCanvas's contents. (Note: just addingcontainwill have no effect, must setcontain="true")width- if not contained, the width of the InkCanvasheight- 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.detailincludes information about the transform (initialmatrix,transformmatrix,centerpoint, andfinalmatrix),pointerType(same as PointerEvent: mouse, touch, pen), andtransformType(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'sfinaltransform. Same properties astransform-start.e.preventDefault()will skip settingfinal, orfinalcan be modified. Seecanvas-plugins/for examples of ways to modify the event.transform-end- Fired at the start of a transform. Same properties astransform-start.
FreeformMixin
Properties
transform- aTransformobject representing a transform on the stroke (see ml-matrix on npm).rotation- rotation in degrees (default0)scaleFactor- scale factor (default1.0)translation- translation in pixels (default{x:0,y: 0})
Methods
transform(Transform)- apply a transform to the elementrotateBy(degrees)- rotate the element bydegrees(clockwise in screen-space)scaleBy(factor)- scale the element byfactortranslateBy({x,y})- translate the element byxandy
Demoing with Storybook
To run a local instance of Storybook for your component, run
npm run storybookTo build a production version of Storybook, run
npm run storybook:buildLinting and formatting
To scan the project for linting and formatting errors, run
npm run lintTo automatically fix linting and formatting errors, run
npm run formatEnsure 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:
npm run testTo run the tests in interactive watch mode run:
npm run test:watch1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago