lineadraw
v0.5.0
Published
Type definitions and marketplace tooling for Linea blocks and commands
Readme
lineadraw
Type definitions and marketplace tooling for Linea
blocks and commands — the one devDependency a block/command repository
needs. Zero runtime: your modules import types from "lineadraw", and the
Linea editor provides the real implementation when it runs them.
- Typings —
lineadraw.d.tsmakesimport { defineBlock } from "lineadraw"andimport { … } from "lineadraw/helpers"type-check in any editor/CI, with parameter types inferred into yourdrawfunction. - CLI —
lineadraw manifest | check | initturns any repository into a Linea marketplace: a git repo the editor can browse and install blocks/commands from.
Quick start
Scaffold a fresh marketplace repository:
npm create lineadraw my-blocksOr add the structure to an existing project:
npm i -D lineadraw
npx lineadraw initEither way you get blocks/ and commands/ folders, a tsconfig.json
wired to the typings, a sample block, a CI workflow, and a generated
catalog (.lineadraw/marketplace.json) — the repo is addable in the
editor from the first push.
Writing a block
A block is one module with a single defineBlock default export:
typed parameters in, geometry out.
// blocks/surface.block.ts
import { defineBlock } from "lineadraw";
export default defineBlock({
// The id is the block's identity everywhere: @<collection>/<slug>.
// Re-publishing the same id updates installed copies in place.
id: "@my-blocks/surface",
name: "Surface",
version: "1.0.0",
params: [
{ name: "kind", type: "enum", default: "rock", options: ["rock", "ground"] },
],
place: ["Start point", "End point"], // one point pick per label, in order
draw: ({ params, inputs: [start, end] }) => {
params.kind; // "rock" | "ground" — inferred from the params table
return [{ type: "line", a: start, b: end }];
},
});Notable optional members: place may instead be an interactive
({ params, pickPoint, pickObject }) function run once at insertion;
dependencies lists ids of blocks your draw emits instances of (installs
pull them along); paramVisibility({ params }) hides property rows;
previewInputs curates the inputs used for thumbnails. Units are
millimeters, Y-up, angles in radians CCW.
Writing a command
A command is a macro with a single defineCommand default export. Its
whole run is one undo step; Esc during a pick reverts cleanly.
// commands/circle-here.cmd.ts
import { defineCommand } from "lineadraw";
export default defineCommand({
id: "@my-blocks/circle-here",
name: "Circle here",
run: async ({ document, pickPoint, prompt, showToast }) => {
const center = await pickPoint("Center point");
const r = await prompt("Radius");
document.add([{ type: "circle", center, radius: Number.parseFloat(r) }]);
showToast("Done", "success");
},
});Imports are limited to "lineadraw" and "lineadraw/helpers" (geometry
helpers) — the editor resolves both when executing your module.
The CLI
lineadraw manifest Validate all modules and write .lineadraw/marketplace.json
lineadraw check Validate without writing; fail if the committed manifest is stale
lineadraw init Add the marketplace structure to the current npm projectThe manifest is deterministic (repo-relative paths, no git metadata), so
check is a byte-for-byte diff — the included CI workflow runs it on every
push and PR. With @lineadraw/sdk installed as a devDependency,
manifest/check additionally dry-run every block and render
thumbnails; without it the CLI still fully works.
Collection name and owner come from your package.json:
{ "lineadraw": { "marketplaceName": "My blocks", "marketplaceOwner": "Me" } }Using a marketplace in the editor
In the editor: Library → Marketplace tab → +
and enter owner/repo (or owner/repo@branch). For a private repository,
create a fine-grained personal access token with read-only Contents access
to just that repository and paste it in the add dialog — it is stored only
on that device. Installing embeds the module (and its declared dependency
closure) in the document, so drawings keep working offline and travel with
the file.
Ecosystem
- Linea editor — the browser CAD app that runs these modules.
lineadraw/lineadraw— the public collection: real blocks/commands to learn from, agent skill, and guides.@lineadraw/sdk— headless Node API over the same kernel (open/edit/render/export.lineadocuments; also powers the CLI's block dry-runs).@lineadraw/mcp— MCP server with the full editor as an in-chat app.
