@genart-dev/core

中文文档
0.12.1发布于 2026/10/28MITTypeScriptESM + CJS近 30 天下载 2446

Renderer adapters, skill registry, and runtime interfaces for genart.dev

原始使用文档
文档目录16 节
  1. Install
  2. Usage
  3. Renderer Adapters
  4. RendererRegistry
  5. Skill Registry
  6. Composition Skills (6)
  7. Color Skills (6)
  8. API Reference
  9. Interfaces
  10. Classes
  11. Factory Functions
  12. Utilities
  13. Re-exports from @genart-dev/format
  14. Related Packages
  15. Support
  16. License

@genart-dev/core

Renderer adapters, skill registry, and runtime interfaces for genart.dev — a generative art platform with an MCP server, desktop app, and IDE extensions.

Re-exports everything from @genart-dev/format so consumers get the full format API without a separate import.

Install

npm install @genart-dev/core

Usage

import {
  createDefaultRegistry,
  createDefaultSkillRegistry,
  parseGenart,
  resolvePreset,
} from "@genart-dev/core";

// Set up renderer registry with all 5 adapters
const renderers = createDefaultRegistry();

// Parse a .genart file and resolve its renderer
const sketch = parseGenart(JSON.parse(fileContents));
const adapter = renderers.resolve(sketch.renderer.type); // → P5RendererAdapter

// Validate an algorithm for a specific renderer
const result = adapter.validate(sketch.algorithm);
if (!result.valid) {
  console.error(result.errors);
}

// Generate standalone HTML (embeds algorithm + CDN runtime)
const html = adapter.generateStandaloneHTML(sketch);

// Browse design knowledge skills
const skills = createDefaultSkillRegistry();
skills.list("composition"); // → 6 composition skills
skills.list("color");       // → 6 color skills

Renderer Adapters

Five pluggable rendering engines, each implementing the RendererAdapter interface:

AdapterTypeLanguageRuntimeAlgorithm Signature
P5RendererAdapterp5JavaScriptp5.js 1.xfunction sketch(p, state)
Canvas2DRendererAdaptercanvas2dJavaScriptNativefunction sketch(ctx, state)
ThreeRendererAdapterthreeJavaScriptThree.jsfunction sketch(THREE, state, container)
GLSLRendererAdapterglslGLSLWebGL2Fragment shader source
SVGRendererAdaptersvgJavaScriptNativefunction sketch(state)
import { P5RendererAdapter } from "@genart-dev/core";

const p5 = new P5RendererAdapter();

// Validate algorithm source
p5.validate(algorithm);

// Compile for execution
const compiled = await p5.compile(algorithm);

// Create a live instance (browser context)
const instance = p5.createInstance(compiled, sketch.state, sketch.canvas);
instance.mount(document.getElementById("canvas"));
instance.updateState(newState);
instance.captureFrame({ format: "png" }); // → data URL

// Generate standalone HTML with embedded CDN runtime
const html = p5.generateStandaloneHTML(sketch);

// Get starter template for new sketches
const template = p5.getAlgorithmTemplate();

RendererRegistry

import { createDefaultRegistry, RendererRegistry } from "@genart-dev/core";

// Pre-loaded with all 5 adapters
const registry = createDefaultRegistry();

registry.resolve("p5");      // → P5RendererAdapter
registry.resolve("glsl");    // → GLSLRendererAdapter
registry.list();             // → ["p5", "canvas2d", "three", "glsl", "svg"]
registry.getDefault();       // → P5RendererAdapter
registry.has("three");       // → true

Skill Registry

11 built-in design knowledge skills grounded in classical design theory — composition principles (Arnheim, Wong) and color theory (Albers, Itten). Each skill includes theory text, key principles, academic references, and optional renderer-specific algorithm examples.

Composition Skills (6)

IDComplexitySource
golden-ratioIntermediate1:1.618 proportions, spiral layouts
rule-of-thirdsBeginner3x3 grid, power points, dynamic balance
visual-weightIntermediateSize, value, saturation, position balance
gestalt-groupingIntermediateProximity, similarity, closure, continuity
figure-groundBeginnerPositive forms vs. negative space
rhythm-movementAdvancedRepetition, variation, progression, flow

Color Skills (6)

IDComplexitySource
color-harmonyBeginnerComplementary, analogous, triadic, split-complementary
simultaneous-contrastAdvancedAlbers' adjacent color perception shifts
color-temperatureBeginnerWarm (advances) vs. cool (recedes)
itten-contrastsAdvancedItten's 7 contrast types
value-structureIntermediateLights, mid-tones, darks; tonal keys
palette-generationIntermediateAlgorithmic OKLCH color space generation
import { createDefaultSkillRegistry } from "@genart-dev/core";

const skills = createDefaultSkillRegistry();

const skill = skills.resolve("golden-ratio");
skill.theory;              // Markdown theory text
skill.principles;          // Key design principles
skill.references;          // Academic citations
skill.suggestedParameters; // Example ParamDefs for this technique
skill.examples?.p5;        // p5.js algorithm example

API Reference

Interfaces

InterfaceDescription
RendererAdapterContract for rendering engines — validate, compile, mount, capture, export
SketchInstanceLive sketch — mount/unmount, updateState, pause/resume, captureFrame
SkillDefinitionDesign knowledge skill — theory, principles, references, examples
SkillReferenceAcademic citation (title, author, year)
ValidationResultAlgorithm validation result (valid + errors[])
RuntimeDependencyCDN dependency for standalone HTML export (name, version, cdnUrl)
CaptureOptionsScreenshot options (format, quality, scale)
CompiledAlgorithmOpaque compiled algorithm handle

Classes

ClassDescription
RendererRegistryRegister and resolve renderer adapters by type
SkillRegistryRegister and resolve design knowledge skills

Factory Functions

FunctionDescription
createDefaultRegistry()Registry pre-loaded with all 5 renderer adapters
createDefaultSkillRegistry()Registry pre-loaded with all 11 skills

Utilities

FunctionDescription
hexToVec3(hex)Convert "#rrggbb" to [r, g, b] floats in [0, 1] — for GLSL uniforms

Re-exports from @genart-dev/format

All types and functions from @genart-dev/format are re-exported: parseGenart, serializeGenart, parseWorkspace, serializeWorkspace, convertLegacySketch, CANVAS_PRESETS, resolvePreset, SketchDefinition, WorkspaceDefinition, ParamDef, ColorDef, and more. See the format README for the full list.

PackagePurpose
@genart-dev/formatFile format types, parsers, presets (dependency)
@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/core 共发布 31 个版本,首次发布于 2026/02/23;过去 12 个月发布了 31 个版本。

版本发布日期距今
0.12.1latest2026/10/2819 天前
0.12.02026/10/2720 天前
0.11.12026/03/297 个月前
0.11.02026/03/287 个月前
0.10.02026/03/237 个月前
0.9.02026/03/197 个月前

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

@genart-dev/core 是什么?

Renderer adapters, skill registry, and runtime interfaces for genart.dev

如何安装 @genart-dev/core?

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

@genart-dev/core 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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