Original
The next big tiny art movement. Make something worth checking out.
<script type="module" src="https://esm.sh/inputism/element"></script>
<inputism-image src="cat.jpg" density="32" mark="checked"></inputism-image>
A small set of examples using the web component.
<inputism-image src="cat.jpg" density="32" mark="checked"></inputism-image>
<inputism-image src="cat.jpg" density="32" mark="indeterminate"></inputism-image>
<inputism-image src="cat.jpg" density="32" mark="background"></inputism-image>
This example uses an external image with anonymous CORS enabled.
<inputism-image
crossorigin="anonymous"
src="https://images.pexels.com/photos/34574310/pexels-photo-34574310.jpeg"
density="32"
mark="checked"
></inputism-image>
Pass an encoded image data URL directly through
src or assign it from JavaScript.
<!-- The full base64 value is shortened here. -->
<inputism-image
src="data:image/jpeg;base64,BASE64_IMAGE_DATA"
density="32"
mark="checked"
></inputism-image>
// The encoded image can also be assigned from JavaScript.
const encodedImage = "data:image/jpeg;base64,BASE64_IMAGE_DATA";
const element = document.querySelector("inputism-image");
element?.setAttribute("src", encodedImage);
The component applies role="img" to its internal
grid. Use label like an alt value to
name that image.
<inputism-image
src="cat2.jpg"
density="32"
mark="checked"
label="A tabby cat lying on a patterned rug"
></inputism-image>
Add loading="lazy" to wait until the component
approaches the viewport before decoding its source.
<inputism-image
src="cat4.jpg"
loading="lazy"
density="32"
mark="checked"
></inputism-image>
Render the grid as ordinary HTML with styles embedded directly in the generated elements.
import { createInputismImageFromUrl } from "inputism/source";
import { renderInputismHtml } from "inputism/html";
const image = await createInputismImageFromUrl("cat.jpg", {
density: 32,
});
const container = document.querySelector(".raw-html-output");
if (container) {
renderInputismHtml(container, image, {
mark: "checked",
inlineStyles: true,
});
}
Listen for inputism-error and decide how your
application presents it.
const image = document.querySelector("inputism-image");
image?.addEventListener("inputism-error", (event) => {
const error = (event as CustomEvent<unknown>).detail;
console.error("Inputism could not load the image", error);
});
Waiting for the component to emit inputism-error…
Add Inputism to a TypeScript project.
npm install inputism
pnpm add inputism
yarn add inputism
Sources provide pixels, the core creates the image model, and renderers display it.
inputism/element registers the preferred
<inputism-image> web component.
createInputismImage(rgbaImage, options) creates a
complete image model.
createInputismImageFromUrl(source, options) loads a
browser image source and creates the model.
createInputismLayout(width, height, options) creates
the stable cell layout.
createInputismColors(rgbaImage, layout) samples RGB
colors for that layout.
renderInputismHtml(container, image, options) creates
raw HTML, with optional inline styles.