UNPKG

circuit-bricks

Version:

A modular, Lego-style SVG circuit component system for React (ALPHA - Not for production use)

72 lines (70 loc) 2.62 kB
import { battery_default, capacitor_default, diode_default, ground_default, ic_default, led_default, resistor_default, switch_default, transistor_npn_default, voltage_source_default } from "./ic-DjodI3kT.mjs"; //#region src/registry/server.ts const serverComponentRegistry = {}; /** * Initialize the server-side registry with built-in components */ function initializeServerRegistry() { if (Object.keys(serverComponentRegistry).length > 0) return; const components = [ resistor_default, capacitor_default, ground_default, switch_default, battery_default, voltage_source_default, diode_default, transistor_npn_default, led_default, ic_default ]; for (const schema of components) try { if (schema && schema.id && schema.name && schema.category) serverComponentRegistry[schema.id] = schema; else console.warn(`Invalid component schema ${schema.id}: missing required fields`); } catch (error) { console.warn(`Failed to register component ${schema.id}:`, error); } } /** * Register a component schema in the server-side registry */ function registerServerComponent(schema) { initializeServerRegistry(); if (!schema || !schema.id || !schema.name || !schema.category) throw new Error(`Invalid component schema: missing required fields (id, name, category)`); if (serverComponentRegistry[schema.id]) console.warn(`Component with ID ${schema.id} already exists in server registry. Overwriting.`); serverComponentRegistry[schema.id] = schema; } /** * Get a component schema from the server-side registry by ID */ function getServerComponentSchema(id) { initializeServerRegistry(); return serverComponentRegistry[id]; } /** * Get all component schemas in the server-side registry */ function getAllServerComponents() { initializeServerRegistry(); return Object.values(serverComponentRegistry); } /** * Get component schemas by category from the server-side registry */ function getServerComponentsByCategory(category) { initializeServerRegistry(); return Object.values(serverComponentRegistry).filter((schema) => schema.category === category); } /** * Get all unique categories from the server-side registry */ function getServerCategories() { initializeServerRegistry(); const allComponents = getAllServerComponents(); const categories = [...new Set(allComponents.map((schema) => schema.category))]; return categories.sort(); } var server_default = serverComponentRegistry; //#endregion export { getAllServerComponents, getServerCategories, getServerComponentSchema, getServerComponentsByCategory, registerServerComponent, server_default }; //# sourceMappingURL=server-Cvg4Ggu4.mjs.map