@genart-dev/format

中文文档
0.7.0发布于 2026/03/19MITTypeScriptESM + CJS零依赖近 30 天下载 2129

File format types, parsers, and canvas presets for the .genart format

原始使用文档
文档目录13 节
  1. Install
  2. Usage
  3. The .genart Format
  4. Renderers
  5. The .genart-workspace Format
  6. Canvas Presets
  7. API Reference
  8. Types
  9. Functions
  10. Specification Fixtures
  11. Related Packages
  12. Support
  13. License

@genart-dev/format

File format types, parsers, and canvas presets for the .genart and .genart-workspace formats.

Part of genart.dev — a generative art platform with an MCP server, desktop app, and IDE extensions.

Install

npm install @genart-dev/format

Zero dependencies.

Usage

import {
  parseGenart,
  serializeGenart,
  parseWorkspace,
  serializeWorkspace,
  CANVAS_PRESETS,
  resolvePreset,
  convertLegacySketch,
} from "@genart-dev/format";

// Parse and validate a .genart file
const sketch = parseGenart(JSON.parse(fileContents));

// Serialize back to formatted JSON
const json = serializeGenart(sketch);

// Parse a .genart-workspace file
const workspace = parseWorkspace(JSON.parse(workspaceContents));

// Resolve a canvas preset to dimensions
const { width, height } = resolvePreset("square-1200"); // → 1200×1200

// Convert a legacy .js sketch file to .genart
const converted = convertLegacySketch(legacyJsSource);

The .genart Format

Each .genart file is a single JSON document — one self-contained, shareable sketch:

{
  "genart": "1.1",
  "id": "orchestrated-opposition",
  "title": "Orchestrated Opposition",
  "created": "2025-01-15T10:30:00Z",
  "modified": "2025-01-15T12:00:00Z",
  "renderer": { "type": "p5", "version": "1.x" },
  "canvas": { "preset": "square-1200", "width": 1200, "height": 1200 },
  "parameters": [
    { "key": "margin", "label": "Margin", "min": 30, "max": 120, "step": 5, "default": 60 }
  ],
  "colors": [
    { "key": "color1", "label": "Primary", "default": "#1a1a1a" }
  ],
  "state": {
    "seed": 12345,
    "params": { "margin": 60 },
    "colorPalette": ["#1a1a1a"]
  },
  "algorithm": "function sketch(p, state) { ... }"
}

Required fields: genart, id, title, created, modified, renderer, canvas, parameters, colors, state, algorithm

Optional fields: subtitle, agent, model, skills, philosophy, tabs, themes, snapshots

Renderers

The renderer.type field specifies which engine executes the algorithm:

TypeAlgorithm LanguageRuntime
p5JavaScript (p5.js instance mode)p5.js
threeJavaScript (Three.js scene builder)Three.js
glslGLSL (fragment shader)WebGL2
canvas2dJavaScript (Canvas 2D API)Native
svgJavaScript (SVG generator)Native

For v1.0 files without a renderer field, the parser defaults to { "type": "p5" }.

The .genart-workspace Format

Multiple sketches coexist on an infinite canvas. A .genart-workspace file is the spatial layout manifest:

{
  "genart-workspace": "1.0",
  "id": "typography-explorations",
  "title": "Typography Explorations",
  "created": "2025-01-15T10:30:00Z",
  "modified": "2025-01-15T12:00:00Z",
  "viewport": { "x": 0, "y": 0, "zoom": 0.5 },
  "sketches": [
    { "file": "orchestrated-opposition.genart", "position": { "x": 0, "y": 0 } },
    { "file": "cadenced-fields.genart", "position": { "x": 1400, "y": 0 } }
  ]
}

Individual .genart files remain the portable, shareable unit. The workspace is lightweight spatial metadata — file references and canvas positions.

Canvas Presets

18 built-in presets across 5 categories:

CategoryPresets
Square600, 1200, 2400, 4096
LandscapeHD 1920×1080, 2K, Ultrawide 21:9, 4K UHD
PortraitPhone 390×844, Tablet 768×1024, Poster 2400×3600
Print (300 DPI)A4, A3, US Letter
SocialInstagram 1080², Twitter/X 1200×675, Open Graph 1200×630

API Reference

Types

TypeDescription
SketchDefinitionComplete .genart file structure
WorkspaceDefinitionComplete .genart-workspace file structure
RendererType"p5" | "three" | "glsl" | "canvas2d" | "svg"
RendererSpecRenderer engine + optional version constraint
CanvasSpecWidth, height, pixel density, optional preset
CanvasPresetNamed preset (id, label, category, width, height)
ParamDefNumeric parameter definition (key, label, min, max, step, default)
ColorDefColor slot definition (key, label, default hex)
ThemeDefNamed color palette (name + colors array)
TabDefParameter grouping tab (id, label)
SketchStateRuntime state (seed, params, colorPalette)
SnapshotSaved state snapshot with optional thumbnail
WorkspaceSketchRefSketch reference with canvas position
WorkspaceGroupNamed group of sketches

Functions

FunctionDescription
parseGenart(json)Parse and validate a .genart JSON object
serializeGenart(sketch)Serialize a SketchDefinition to formatted JSON
parseWorkspace(json)Parse and validate a .genart-workspace JSON object
serializeWorkspace(workspace)Serialize a WorkspaceDefinition to formatted JSON
convertLegacySketch(source)Convert a legacy .js sketch file to SketchDefinition
extractLegacyInfo(source)Extract metadata from a legacy sketch without full conversion
resolvePreset(preset)Look up { width, height } for a preset ID
CANVAS_PRESETSArray of all 18 built-in canvas presets

Specification Fixtures

The specs/ directory contains concrete examples of valid and invalid .genart and .genart-workspace files. See specs/README.md for the full listing.

PackagePurpose
@genart-dev/coreRenderer adapters + skill registry (depends on format)
@genart-dev/mcp-server33-tool MCP server + CLI (depends on core)

Support

Questions, bugs, or feedback — [email protected] or open an issue.

License

MIT

版本与发布记录

@genart-dev/format 共发布 15 个版本,首次发布于 2026/02/23;过去 12 个月发布了 15 个版本。

版本发布日期距今
0.7.0latest2026/03/197 个月前
0.6.12026/03/178 个月前
0.6.02026/03/168 个月前
0.5.42026/03/158 个月前
0.5.32026/03/118 个月前
0.5.22026/03/098 个月前

关于 @genart-dev/format 的常见问题

@genart-dev/format 是什么?

File format types, parsers, and canvas presets for the .genart format

如何安装 @genart-dev/format?

在项目目录运行 npm install @genart-dev/format,或使用 pnpm add / yarn add / bun add。

@genart-dev/format 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@genart-dev/format 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@genart-dev/format 可以商用吗?

@genart-dev/format 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@genart-dev/format 的下载量有多少?

根据 npm 官方下载统计,@genart-dev/format 在 2026/10/16 – 2026/11/14 这 30 天内被下载 2,129 次,日均约 71 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@genart-dev/format 还在维护吗?

最新版本 0.7.0 发布于 2026/03/19(7 个月前);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/02/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。