0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 13:43:03 -05:00
penpot-exporter-figma-plugin/plugin-src/RemoteComponents.ts
2024-06-26 08:11:57 +02:00

39 lines
959 B
TypeScript

export class RemoteComponentsLibrary {
private components: Map<string, ComponentNode | ComponentSetNode> = new Map();
private queue: string[] = [];
public register(id: string, component: ComponentNode | ComponentSetNode) {
if (!this.components.has(id)) {
this.queue.push(id);
}
this.components.set(id, component);
}
public get(id: string): ComponentNode | ComponentSetNode | undefined {
return this.components.get(id);
}
public has(id: string): boolean {
return this.components.has(id);
}
public next(): ComponentNode | ComponentSetNode {
const lastKey = this.queue.pop();
if (!lastKey) throw new Error('No components to pop');
const component = this.components.get(lastKey);
if (!component) throw new Error('Component not found');
return component;
}
public remaining(): number {
return this.queue.length;
}
public total(): number {
return this.components.size;
}
}