batchutil

package
v0.10.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KnownTopLevelProps = []string{
	"x", "y", "width", "height", "w", "h",
	"color", "fillColor", "bg",
	"fontSize", "fontFamily", "fontStyle", "sz", "ff", "fs",
	"parentId", "pid",
	"cornerRadius", "r",
	"layoutMode", "itemSpacing", "padding", "opacity",
	"text", "imageData", "stroke", "strokeWidth",
}

KnownTopLevelProps are design properties that belong inside "params", not at op root. Exported so validate.go can reference the same list.

Functions

func BuildContext

func BuildContext(steps []StepState) map[string]interface{}

BuildContext creates an interpolation context from completed steps.

func ExpandAllComposites added in v0.10.0

func ExpandAllComposites(ops []map[string]interface{}) ([]map[string]interface{}, error)

ExpandAllComposites processes a batch array, expanding any composite ops.

func ExpandComposite added in v0.10.0

func ExpandComposite(op map[string]interface{}) ([]map[string]interface{}, error)

ExpandComposite expands a single composite op into primitive batch ops. Non-composite commands pass through as single-element slices.

func FixBatchOps added in v0.9.1

func FixBatchOps(data []byte) ([]byte, []string, error)

FixBatchOps applies auto-corrections to common LLM output drift. Returns: fixed JSON bytes, list of human-readable fix descriptions, error. Error is non-nil only if the input cannot be parsed at all.

func InterpolateParams

func InterpolateParams(params map[string]interface{}, steps []StepState) (map[string]interface{}, error)

InterpolateParams resolves placeholders in params using prior step results.

func InterpolateValue

func InterpolateValue(value interface{}, ctx map[string]interface{}) (interface{}, error)

InterpolateValue recursively resolves placeholders in arbitrary JSON-like data.

func IsComposite added in v0.10.0

func IsComposite(command string) bool

IsComposite returns true if command is a composite that needs expansion.

func NormalizeBatchParams added in v0.6.0

func NormalizeBatchParams(command string, params map[string]interface{}) map[string]interface{}

NormalizeBatchParams expands shorthand keys for batch operations. It is intentionally command-aware to avoid key collisions.

func NormalizeCSSProps added in v0.10.5

func NormalizeCSSProps(params map[string]interface{}) map[string]interface{}

NormalizeCSSProps maps CSS-like properties to Figma-native properties. It is called during batch parameter normalization so LLMs can write familiar CSS properties. CSS props are lower priority — they never overwrite Figma-native properties that are already set. The function modifies params in-place AND returns it.

func ResolveTokenAliases added in v0.10.6

func ResolveTokenAliases(ops []map[string]interface{}) (applied int, rootWidth int)

ResolveTokenAliases resolves semantic token aliases (e.g. sz:"hero", padding:"side", w:"content") to numeric values based on the first root frame's canvas size. It mutates ops in place and returns:

  • applied: number of alias replacements made
  • rootWidth: detected root frame width (0 if none found)

func SanitizeStepName added in v0.7.0

func SanitizeStepName(name string) string

SanitizeStepName normalizes a batch step name: lowercase, spaces→underscores, strip non-alphanumeric characters (except _).

func StripJSONComments added in v0.9.1

func StripJSONComments(data []byte) []byte

StripJSONComments removes // line comments and /* block comments */ from JSON-like input. Models occasionally emit JSONC-style comments which are not valid JSON.

func StripMarkdownFences added in v0.9.1

func StripMarkdownFences(data []byte) []byte

StripMarkdownFences removes ```json ... ``` or ``` ... ``` wrappers that models add even when explicitly told not to.

Types

type StepState

type StepState struct {
	Index   int
	Name    string
	Command string
	OK      bool
	Result  interface{}
	Error   string
}

StepState captures the execution state of a prior batch step.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL