// Copyright (c) 2026 The elk-go Authors.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0.
//
// SPDX-License-Identifier: EPL-2.0

package elk

import (
	
	
	
	

	
	
	
)

// Layout computes layout in place. Like elkjs, it preserves the input graph's
// element and slice order and adds computed shape and edge-route fields.
func ( *Graph) error {
	,  := defaultRegistries()
	 := core.NewCodec()
	,  := .Import()
	if  != nil {
		return fmt.Errorf("import ELK graph: %w", )
	}
	if  := core.NewEngine(, ).Layout();  != nil {
		return fmt.Errorf("layout ELK graph: %w", )
	}
	if  := .TransferLayout();  != nil {
		return fmt.Errorf("export ELK layout: %w", )
	}
	return nil
}

// LayoutJSON is the byte-oriented equivalent of Layout.
func ( []byte) ([]byte, error) {
	 := json.NewDecoder(bytes.NewReader())
	.UseNumber()
	var  graphjson.Graph
	if  := .Decode(&);  != nil {
		return nil, fmt.Errorf("decode ELK graph: %w", )
	}
	var  any
	if  := .Decode(&);  != io.EOF {
		if  == nil {
			return nil, fmt.Errorf("decode ELK graph: unexpected trailing JSON value")
		}
		return nil, fmt.Errorf("decode ELK graph: %w", )
	}
	if  := Layout(&);  != nil {
		return nil, 
	}
	,  := json.Marshal(&)
	if  != nil {
		return nil, fmt.Errorf("encode ELK graph: %w", )
	}
	return , nil
}

// defaultRegistries is the single integration point for native providers.
// Algorithm packages register D2's eleven ELK.js 0.12.0 provider IDs and the
// official option metadata here. The executable compatibility contract is
// D2's documented profile, not every expert option combination.
func defaultRegistries() (*core.OptionRegistry, *core.AlgorithmRegistry) {
	 := core.NewOptionRegistry()
	builtins.RegisterOptions()
	 := core.NewAlgorithmRegistry()
	if  := builtins.Register();  != nil {
		panic()
	}
	return , 
}