circuit-bricks
Version:
A modular, Lego-style SVG circuit component system for React (ALPHA - Not for production use)
113 lines (110 loc) • 3.52 kB
JavaScript
"use client";
;
const require_ic = require('./ic-DFHJiT6Z.cjs');
//#region src/registry/components/index.ts
const registerBuiltInComponents = () => {
registerComponent(require_ic.resistor_default);
registerComponent(require_ic.capacitor_default);
registerComponent(require_ic.ground_default);
registerComponent(require_ic.switch_default);
registerComponent(require_ic.battery_default);
registerComponent(require_ic.voltage_source_default);
registerComponent(require_ic.diode_default);
registerComponent(require_ic.transistor_npn_default);
registerComponent(require_ic.led_default);
registerComponent(require_ic.ic_default);
};
var components_default = registerBuiltInComponents;
//#endregion
//#region src/registry/index.ts
const componentRegistry = {};
/**
* Register a component schema in the registry
*
* This function adds a new component schema to the registry or updates an existing one.
* Custom components can be registered to extend the library with new circuit elements.
*
* @param {ComponentSchema} schema - The component schema to register
*
* @example
* // Register a custom LED component
* registerComponent({
* id: 'custom-led',
* name: 'Custom LED',
* category: 'output',
* description: 'A light-emitting diode with customizable color',
* defaultWidth: 30,
* defaultHeight: 20,
* ports: [
* { id: 'anode', x: 0, y: 10, type: 'input' },
* { id: 'cathode', x: 30, y: 10, type: 'output' }
* ],
* properties: [
* { id: 'color', name: 'Color', type: 'color', default: '#ff0000' }
* ],
* svgPath: `<circle cx="15" cy="10" r="8" fill="currentColor" />`
* });
*/
function registerComponent(schema) {
const validationResult = require_ic.validateComponentSchema(schema);
if (!validationResult.success) throw new Error(`Invalid component schema: ${validationResult.error}`);
if (componentRegistry[schema.id]) console.warn(`Component with ID ${schema.id} already exists in registry. Overwriting.`);
componentRegistry[schema.id] = schema;
}
/**
* Get a component schema from the registry by ID
*
* Retrieves a component's schema definition by its unique identifier.
* Returns undefined if no component with the specified ID exists.
*
* @param {string} id - The unique identifier of the component
* @returns {ComponentSchema | undefined} The component schema or undefined if not found
*
* @example
* const resistorSchema = getComponentSchema('resistor');
* if (resistorSchema) {
* console.log(`Resistor has ${resistorSchema.ports.length} ports`);
* }
*/
function getComponentSchema(id) {
return componentRegistry[id];
}
/**
* Get all component schemas in the registry
*/
function getAllComponents() {
return Object.values(componentRegistry);
}
/**
* Get component schemas by category
*/
function getComponentsByCategory(category) {
return Object.values(componentRegistry).filter((schema) => schema.category === category);
}
components_default();
//#endregion
Object.defineProperty(exports, 'getAllComponents', {
enumerable: true,
get: function () {
return getAllComponents;
}
});
Object.defineProperty(exports, 'getComponentSchema', {
enumerable: true,
get: function () {
return getComponentSchema;
}
});
Object.defineProperty(exports, 'getComponentsByCategory', {
enumerable: true,
get: function () {
return getComponentsByCategory;
}
});
Object.defineProperty(exports, 'registerComponent', {
enumerable: true,
get: function () {
return registerComponent;
}
});
//# sourceMappingURL=registry-arxDMc33.cjs.map