@committed/graph
Advanced tools
Comparing version 3.3.0 to 4.0.0
@@ -1,16 +0,23 @@ | ||
import { ModelAttributeSet, ModelAttributeTypes, ModelEdge, ModelGraphData, ModelNode } from './types'; | ||
import { Edge, MetadataTypes, ModelEdge, ModelGraphData, ModelNode, Node } from './types'; | ||
export declare class ContentModel { | ||
readonly nodes: Record<string, ModelNode>; | ||
readonly edges: Record<string, ModelEdge>; | ||
readonly nodes: Record<string, Node>; | ||
readonly edges: Record<string, Edge>; | ||
private static toNode; | ||
static toEdge(modelEdge: ModelEdge): Edge; | ||
static fromRaw(data: ModelGraphData): ContentModel; | ||
static createEmpty(): ContentModel; | ||
constructor(nodes: Record<string, ModelNode>, edges: Record<string, ModelEdge>); | ||
constructor(nodes: Record<string, Node>, edges: Record<string, Edge>); | ||
validate(): void; | ||
containsNode(id: string): boolean; | ||
containsEdge(id: string): boolean; | ||
getNode(id: string): ModelNode | undefined; | ||
getNode(id: string): Node | undefined; | ||
private getExistingNode; | ||
getEdgesLinkedToNode(nodeId: string): ModelEdge[]; | ||
addNode(node: Partial<ModelNode>): ContentModel; | ||
getEdgesLinkedToNode(nodeId: string): Edge[]; | ||
addNode(modelNode: ModelNode): ContentModel; | ||
editNode(node: ModelNode): ContentModel; | ||
/** | ||
* @deprecated use addNodeMetadata | ||
*/ | ||
addNodeAttribute<V>(id: string, attributeName: string, attributeValue: V): ContentModel; | ||
addNodeMetadata<V>(id: string, key: string, value: V): ContentModel; | ||
/** | ||
@@ -22,22 +29,44 @@ * Remove node and associated edges | ||
private removeOrphanNode; | ||
/** | ||
* @deprecated use editNodeMetadata | ||
*/ | ||
editNodeAttribute<V>(id: string, attributeName: string, attributeValue: V): ContentModel; | ||
editNodeMetadata<V>(id: string, key: string, value: V): ContentModel; | ||
/** | ||
* @deprecated use removeNodeMetadata | ||
*/ | ||
removeNodeAttribute(id: string, attributeName: string): ContentModel; | ||
addEdge(edge: Omit<ModelEdge, 'id' | 'attributes'> & { | ||
id?: string; | ||
attributes?: ModelAttributeSet; | ||
}): ContentModel; | ||
checkEdgeNodes(edge: Omit<ModelEdge, 'id' | 'attributes'> & { | ||
id?: string; | ||
attributes?: ModelAttributeSet; | ||
}): void; | ||
getEdge(id: string): ModelEdge | undefined; | ||
removeNodeMetadata(id: string, key: string): ContentModel; | ||
addEdge(modelEdge: ModelEdge): ContentModel; | ||
checkEdgeNodes(edge: ModelEdge): void; | ||
getEdge(id: string): Edge | undefined; | ||
private getExistingEdge; | ||
editEdge(edge: ModelEdge): ContentModel; | ||
/** | ||
* @deprecated use addEdgeMetadata | ||
*/ | ||
addEdgeAttribute<V>(id: string, attributeName: string, attributeValue: V): ContentModel; | ||
addEdgeMetadata<V>(id: string, key: string, value: V): ContentModel; | ||
/** | ||
* @deprecated use editEdgeMetadata | ||
*/ | ||
editEdgeAttribute<V>(id: string, attributeName: string, attributeValue: V): ContentModel; | ||
editEdgeMetadata<V>(id: string, key: string, value: V): ContentModel; | ||
/** | ||
* @deprecated use removeEdgeMetadata | ||
*/ | ||
removeEdgeAttribute(id: string, attributeName: string): ContentModel; | ||
removeEdgeMetadata(id: string, attributeName: string): ContentModel; | ||
removeEdge(id: string): ContentModel; | ||
private getAttributes; | ||
getNodeAttributes(): ModelAttributeTypes; | ||
getEdgeAttributes(): ModelAttributeTypes; | ||
private getMetadataSets; | ||
/** | ||
* @deprecated use getNodeMetadataSets | ||
*/ | ||
getNodeAttributes(): MetadataTypes; | ||
getNodeMetadataTypes(): MetadataTypes; | ||
/** | ||
* @deprecated use getEdgeMetadataSets | ||
*/ | ||
getEdgeAttributes(): MetadataTypes; | ||
getEdgeMetadataTypes(): MetadataTypes; | ||
} |
import { ContentModel } from '../ContentModel'; | ||
import { GraphModel } from '../GraphModel'; | ||
import { ModelNode } from '../types'; | ||
export declare const randomNode: (model: ContentModel) => ModelNode | undefined; | ||
export declare const addRandomNode: (model: GraphModel, count?: number, options?: Partial<ModelNode> | (() => Partial<ModelNode>)) => GraphModel; | ||
import { Node } from '../types'; | ||
export declare const randomNode: (model: ContentModel) => Node | undefined; | ||
export declare const addRandomNode: (model: GraphModel, count?: number, options?: Partial<Node> | (() => Partial<Node>)) => GraphModel; | ||
export declare const randomGraph: (nodes?: number, edges?: number) => GraphModel; | ||
@@ -7,0 +7,0 @@ export declare const addRandomNodeShapes: (model: GraphModel, count?: number) => GraphModel; |
@@ -1,2 +0,2 @@ | ||
import { DecoratedEdge, DecoratedNode, DecorationFunction, EdgeDecoration, EdgeDecorationFunction, EdgeDecorator, ModelEdge, ModelNode, NodeDecoration, NodeDecorationFunction, NodeDecorator } from './types'; | ||
import { DecoratedEdge, DecoratedNode, DecorationFunction, Edge, EdgeDecoration, EdgeDecorationFunction, EdgeDecorator, Node, NodeDecoration, NodeDecorationFunction, NodeDecorator } from './types'; | ||
export declare class DecoratorModel { | ||
@@ -36,10 +36,10 @@ private readonly nodeDecorators; | ||
* Adds a function to the given nodes that provides the decoration overrides for the node | ||
* @param modelNodes to be decorated | ||
* @param nodes to be decorated | ||
*/ | ||
getDecoratedNodes(modelNodes: ModelNode[]): DecoratedNode[]; | ||
getDecoratedNodes(nodes: Node[]): DecoratedNode[]; | ||
/** | ||
* Adds a function to the given edges that provides the decoration overrides for the edge | ||
* @param modelEdges to be decorated | ||
* @param edges to be decorated | ||
*/ | ||
getDecoratedEdges(modelEdges: ModelEdge[]): DecoratedEdge[]; | ||
getDecoratedEdges(edges: Edge[]): DecoratedEdge[]; | ||
/** Does the decorator already exist in the model. === equality is used */ | ||
@@ -46,0 +46,0 @@ isNodeDecoratorSet(decorator: NodeDecorator): boolean; |
import { ContentModel } from 'graph'; | ||
import { EdgeDecorator, ModelEdge, ModelNode, NodeDecorator } from '../types'; | ||
import { Edge, EdgeDecorator, Node, NodeDecorator } from '../types'; | ||
declare type Range = [min: number, max: number]; | ||
@@ -10,13 +10,13 @@ interface NumericMapping<T> { | ||
*/ | ||
export declare const sizeNodeBy: (mapping: NumericMapping<ModelNode>, range?: Range) => NodeDecorator; | ||
export declare const sizeNodeBy: (mapping: NumericMapping<Node>, range?: Range) => NodeDecorator; | ||
/** | ||
* Wraps a function from edges to numbers to map it to the size of the node | ||
*/ | ||
export declare const sizeEdgeBy: (mapping: NumericMapping<ModelEdge>, range?: Range) => EdgeDecorator; | ||
export declare const sizeEdgeBy: (mapping: NumericMapping<Edge>, range?: Range) => EdgeDecorator; | ||
/** | ||
* | ||
* Creates a decorator to size the nodes by an attribute value | ||
* Creates a decorator to size the nodes by a metadata value | ||
* | ||
* @param contentModel the current content model | ||
* @param attributeId the id of the attribute | ||
* @param key the key of the metadata | ||
* @param min optional minimum size | ||
@@ -26,9 +26,9 @@ * @param max optional minimum size | ||
*/ | ||
export declare const sizeNodeByAttribute: (contentModel: ContentModel, attributeId: string, range?: Range) => NodeDecorator; | ||
export declare const sizeNodeByMetadata: (contentModel: ContentModel, key: string, range?: Range) => NodeDecorator; | ||
/** | ||
* | ||
* Creates a decorator to size the edges by an attribute value | ||
* Creates a decorator to size the edges by a metadata value | ||
* | ||
* @param contentModel the current content model | ||
* @param attributeId the id of the attribute | ||
* @param key the key of the metadata | ||
* @param min optional minimum size | ||
@@ -38,3 +38,3 @@ * @param max optional minimum size | ||
*/ | ||
export declare const sizeEdgeByAttribute: (contentModel: ContentModel, attributeId: string, range?: Range) => EdgeDecorator; | ||
export declare const sizeEdgeByMetadata: (contentModel: ContentModel, key: string, range?: Range) => EdgeDecorator; | ||
export {}; |
@@ -1,7 +0,7 @@ | ||
import { ModelEdge, ModelNode } from '../types'; | ||
export declare const node1: ModelNode; | ||
export declare const node2: ModelNode; | ||
export declare const node3: ModelNode; | ||
export declare const edge1: ModelEdge; | ||
export declare const edge2: ModelEdge; | ||
export declare const edge3: ModelEdge; | ||
import { Edge, Node } from '../types'; | ||
export declare const node1: Node; | ||
export declare const node2: Node; | ||
export declare const node3: Node; | ||
export declare const edge1: Edge; | ||
export declare const edge2: Edge; | ||
export declare const edge3: Edge; |
@@ -5,3 +5,3 @@ import { ContentModel } from './ContentModel'; | ||
import { SelectionModel } from './SelectionModel'; | ||
import { DecoratedEdge, DecoratedNode, GraphCommand, ModelAttributeTypes } from './types'; | ||
import { DecoratedEdge, DecoratedNode, GraphCommand, MetadataTypes } from './types'; | ||
/** The GraphModel is a declarative, immutable definition of graph state | ||
@@ -12,3 +12,3 @@ | ||
- No requirement for ontology, typing etc | ||
- Attributes | ||
- Metadata | ||
- Decoration (DecoratorModel) | ||
@@ -57,4 +57,4 @@ - May define custom node/edge Decorators based on any property on the node/edge | ||
getEdge(id: string): DecoratedEdge | undefined; | ||
getNodeAttributes(): ModelAttributeTypes; | ||
getEdgeAttributes(): ModelAttributeTypes; | ||
getNodeMetadataTypes(): MetadataTypes; | ||
getEdgeMetadataTypes(): MetadataTypes; | ||
getCurrentLayout(): LayoutModel; | ||
@@ -61,0 +61,0 @@ getSelection(): SelectionModel; |
import { GraphModel } from '../GraphModel'; | ||
export interface ModelItem { | ||
export interface ModelNode extends Partial<NodeDecoration> { | ||
id?: string; | ||
metadata?: Metadata; | ||
} | ||
export interface ModelEdge extends Partial<EdgeDecoration> { | ||
source: string; | ||
target: string; | ||
id?: string; | ||
metadata?: Metadata; | ||
directed?: boolean; | ||
} | ||
export interface Item { | ||
id: string; | ||
attributes: ModelAttributeSet; | ||
metadata: Metadata; | ||
} | ||
export interface ModelNode extends ModelItem, Partial<NodeDecoration> { | ||
export interface Node extends Item, Partial<NodeDecoration> { | ||
} | ||
export interface ModelEdge extends ModelItem, Partial<EdgeDecoration> { | ||
export interface Edge extends Item, Partial<EdgeDecoration> { | ||
source: string; | ||
target: string; | ||
directed: boolean; | ||
} | ||
export declare type ModelAttributeSet = Record<string, ModelAttributeValue>; | ||
export declare type ModelAttributeValue = unknown; | ||
export declare type ModelAttributeTypes = Record<string, Set<string>>; | ||
export declare type Metadata = Record<string, MetadataValue>; | ||
export declare type MetadataValue = unknown; | ||
export declare type MetadataTypes = Record<string, Set<string>>; | ||
export declare type ModelGraphData = { | ||
nodes: Record<string, ModelNode>; | ||
edges: Record<string, ModelEdge>; | ||
nodes: Record<string, Partial<ModelNode>>; | ||
edges: ModelEdge[]; | ||
}; | ||
export declare type GraphData = { | ||
nodes: Record<string, Node>; | ||
edges: Record<string, Edge>; | ||
}; | ||
export interface ItemDecoration { | ||
@@ -35,2 +51,3 @@ label?: string; | ||
style: EdgeStyle; | ||
curve: CurveStyle; | ||
} | ||
@@ -48,14 +65,55 @@ export interface DecorationFunction<T extends ItemDecoration, S = Partial<T>> { | ||
} | ||
export declare type DecoratedNode = ModelNode & NodeDecorationCreator; | ||
export declare type DecoratedEdge = ModelEdge & EdgeDecorationCreator; | ||
export declare type DecoratedNode = Node & NodeDecorationCreator; | ||
export declare type DecoratedEdge = Edge & EdgeDecorationCreator; | ||
export declare type NodeDecorator = { | ||
(node: ModelNode): Partial<NodeDecoration>; | ||
(node: Node): Partial<NodeDecoration>; | ||
id?: string; | ||
}; | ||
export declare type EdgeDecorator = { | ||
(edge: ModelEdge): Partial<EdgeDecoration>; | ||
(edge: Edge): Partial<EdgeDecoration>; | ||
id?: string; | ||
}; | ||
export declare type NodeShape = string; | ||
export declare type EdgeStyle = string; | ||
export declare const NodeShapes: { | ||
readonly rectangle: "Rectangle"; | ||
readonly ellipse: "Ellipse"; | ||
readonly triangle: "Triangle"; | ||
readonly pentagon: "Pentagon"; | ||
readonly hexagon: "Hexagon"; | ||
readonly heptagon: "Heptagon"; | ||
readonly octagon: "Octagon"; | ||
readonly star: "Star"; | ||
readonly barrel: "Barrel"; | ||
readonly diamond: "Diamond"; | ||
readonly vee: "Vee"; | ||
readonly rhomboid: "Rhomboid"; | ||
readonly tag: "Tag"; | ||
readonly 'round-rectangle': "Rounded rectangle"; | ||
readonly 'round-triangle': "Rounded triangle"; | ||
readonly 'round-diamond': "Rounded diamond"; | ||
readonly 'round-pentagon': "Rounded pentagon"; | ||
readonly 'round-hexagon': "Rounded hexagon"; | ||
readonly 'round-heptagon': "Rounded heptagon"; | ||
readonly 'round-octagon': "Rounded octagon"; | ||
readonly 'round-tag': "Rounded tag"; | ||
readonly 'cut-rectangle': "Cut rectangle"; | ||
readonly 'bottom-round-rectangle': "Bottom rounded rectangle"; | ||
readonly 'concave-hexagon': "Concave hexagon"; | ||
}; | ||
export declare type NodeShape = keyof typeof NodeShapes; | ||
export declare const EdgeStyles: { | ||
readonly solid: "Solid"; | ||
readonly dotted: "Dotted"; | ||
readonly dashed: "Dashed"; | ||
}; | ||
export declare type EdgeStyle = keyof typeof EdgeStyles; | ||
export declare const CurveStyles: { | ||
readonly haystack: "Haystack"; | ||
readonly straight: "Straight"; | ||
readonly 'straight-triangle': "Triangle"; | ||
readonly bezier: "Bezier"; | ||
readonly 'unbundled-bezier': "Unbundled-bezier"; | ||
readonly segments: "Segments"; | ||
readonly taxi: "Taxi"; | ||
}; | ||
export declare type CurveStyle = keyof typeof CurveStyles; | ||
export interface CustomGraphLayout { | ||
@@ -66,3 +124,13 @@ name: string; | ||
} | ||
export declare type PresetGraphLayout = 'force-directed' | 'circle' | 'grid' | 'cola' | 'hierarchical' | 'concentric' | 'breadth-first' | 'cose'; | ||
export declare const PresetGraphLayouts: { | ||
readonly 'force-directed': "Force-directed"; | ||
readonly circle: "Circle"; | ||
readonly grid: "Grid"; | ||
readonly cola: "Cola"; | ||
readonly hierarchical: "Hierarchical"; | ||
readonly concentric: "Concentric"; | ||
readonly 'breadth-first': "Breadth-first"; | ||
readonly cose: "Cose"; | ||
}; | ||
export declare type PresetGraphLayout = keyof typeof PresetGraphLayouts; | ||
export declare type GraphLayout = PresetGraphLayout | (string & {}) | CustomGraphLayout; | ||
@@ -69,0 +137,0 @@ export declare function isCustomGraphLayout(layout: GraphLayout | string): layout is CustomGraphLayout; |
@@ -1,2 +0,2 @@ | ||
"use strict";var m=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var R=(r,e,t)=>e in r?m(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var N=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},P=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of F(e))!I.call(r,n)&&n!==t&&m(r,n,{get:()=>e[n],enumerable:!(o=G(e,n))||o.enumerable});return r};var $=r=>P(m({},"__esModule",{value:!0}),r);var p=(r,e,t)=>(R(r,typeof e!="symbol"?e+"":e,t),t);var q={};N(q,{ContentModel:()=>c,DecoratorModel:()=>g,Generator:()=>b,GraphModel:()=>a,LayoutModel:()=>u,SelectionModel:()=>l,isCustomGraphLayout:()=>Y,sizeEdgeBy:()=>L,sizeEdgeByAttribute:()=>W,sizeNodeBy:()=>A,sizeNodeByAttribute:()=>K});module.exports=$(q);var f=require("uuid"),c=class{constructor(e,t){this.nodes=e;this.edges=t;this.nodes=e,this.edges=t}static fromRaw(e){let t=new c(e.nodes,e.edges);return Object.values(t.edges).forEach(o=>t.checkEdgeNodes(o)),t}static createEmpty(){return new c({},{})}containsNode(e){return this.getNode(e)!=null}containsEdge(e){return this.getEdge(e)!=null}getNode(e){return this.nodes[`${e}`]}getExistingNode(e){let t=this.getNode(e);if(t==null)throw new Error(`Node [${e}] does not exist`);return t}getEdgesLinkedToNode(e){return Object.values(this.edges).filter(t=>t.target===e||t.source===e)}addNode(e){if(e.id!=null&&this.containsNode(e.id))throw new Error(`Cannot add node already in graph (${e.id})`);let t={id:e.id??(0,f.v4)(),attributes:e.attributes??{},...e},o={...this.nodes,[t.id]:t};return new c(o,this.edges)}editNode(e){return this.getExistingNode(e.id),new c({...this.nodes,[e.id]:e},this.edges)}addNodeAttribute(e,t,o){let d={...this.getExistingNode(e).attributes,[t]:o},s={...this.getExistingNode(e),attributes:d};return this.editNode(s)}removeNode(e){if(this.getNode(e)==null)return this;let o=this;return this.getEdgesLinkedToNode(e).forEach(n=>{o=o.removeEdge(n.id)}),o.removeOrphanNode(e)}removeOrphanNode(e){let t={...this.nodes};return delete t[`${e}`],new c(t,this.edges)}editNodeAttribute(e,t,o){if(this.getExistingNode(e).attributes[`${t}`]==null)throw new Error(`Node [${e}] does not have attribute ${t}`);return this.addNodeAttribute(e,t,o)}removeNodeAttribute(e,t){let o=this.getExistingNode(e),n={...o.attributes};delete n[`${t}`];let d={...o,attributes:n};return this.editNode(d)}addEdge(e){if(this.checkEdgeNodes(e),e.id!=null&&this.containsEdge(e.id))throw new Error(`Cannot add edge already in graph (${e.id})`);let t={id:e.id??(0,f.v4)(),attributes:e.attributes??{},...e},o={...this.edges,[t.id]:t};return new c(this.nodes,o)}checkEdgeNodes(e){this.getExistingNode(e.source),this.getExistingNode(e.target)}getEdge(e){return this.edges[`${e}`]}getExistingEdge(e){let t=this.getEdge(e);if(t==null)throw new Error(`Edge [${e}] does not exist`);return t}editEdge(e){return this.getExistingEdge(e.id),new c(this.nodes,{...this.edges,[e.id]:e})}addEdgeAttribute(e,t,o){let d={...this.getExistingEdge(e).attributes,[t]:o},s={...this.getExistingEdge(e),attributes:d};return this.editEdge(s)}editEdgeAttribute(e,t,o){if(this.getExistingEdge(e).attributes[`${t}`]==null)throw new Error(`Edge [${e}] does not have attribute ${t}`);return this.addEdgeAttribute(e,t,o)}removeEdgeAttribute(e,t){let o=this.getExistingEdge(e),n={...o.attributes};delete n[`${t}`];let d={...o,attributes:n};return this.editEdge(d)}removeEdge(e){if(this.getEdge(e)==null)return this;let o={...this.edges};return delete o[`${e}`],new c(this.nodes,o)}getAttributes(e){return e.reduce((t,o)=>(Object.entries(o.attributes).forEach(n=>{let d=t[n[0]]??new Set;d.add(typeof n[1]),t[n[0]]=d}),t),{})}getNodeAttributes(){return this.getAttributes(Object.values(this.nodes))}getEdgeAttributes(){return this.getAttributes(Object.values(this.edges))}};var b={};N(b,{addRandomEdge:()=>C,addRandomNode:()=>E,addRandomNodeColors:()=>V,addRandomNodeShapes:()=>Q,randomGraph:()=>k,randomNode:()=>M,removeRandomEdge:()=>Z,removeRandomNode:()=>J});var i=class{constructor(e,t,o,n,d,s){this.nodeDecorators=e;this.nodeDefaults=t;this.edgeDecorators=o;this.edgeDefaults=n;this.nodeLabelsHidden=d;this.edgeLabelsHidden=s;this.nodeDecorators=e,this.nodeDefaults=t,this.edgeDecorators=o,this.edgeDefaults=n,this.nodeLabelsHidden=d,this.edgeLabelsHidden=s}static createDefault(e={}){return new i(e.nodeDecorators??[],e.nodeDefaults??{},e.edgeDecorators??[],e.edgeDefaults??{},e.hideNodeLabels??!1,e.hideEdgeLabels??!1)}getDefaultNodeDecorator(){return()=>({...i.DEFAULT_NODE_DECORATION,strokeColor:"$colors$textSecondary",color:"$colors$brandYellow9",...i.wrapDecorator(this.nodeDefaults)()})}getDefaultEdgeDecorator(){return()=>({...i.DEFAULT_EDGE_DECORATION,color:"$colors$textSecondary",...i.wrapDecorator(this.edgeDefaults)()})}getDecoratedNodes(e){return Object.values(e).map(t=>({getDecorationOverrides:()=>this.getNodeDecorationOverrides(t),...t}))}getDecoratedEdges(e){return Object.values(e).map(t=>({getDecorationOverrides:()=>this.getEdgeDecorationOverrides(t),...t}))}isNodeDecoratorSet(e){return this.isDecoratorSet(e,this.nodeDecorators)}addNodeDecorator(e){return new i(this.addDecorator(e,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeNodeDecorator(e){return new i(this.removeDecorator(e,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}getDecoratorIds(e){return e.map(t=>t.id).filter(t=>t!==void 0)}getNodeDecoratorIds(){return this.getDecoratorIds(this.nodeDecorators)}getEdgeDecoratorIds(){return this.getDecoratorIds(this.edgeDecorators)}getDecoratorById(e,t){return t.find(o=>o.id===e)}removeNodeDecoratorById(e){let t=this.getDecoratorById(e,this.nodeDecorators);return t===void 0?this:new i(this.removeDecorator(t,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeEdgeDecoratorById(e){let t=this.getDecoratorById(e,this.edgeDecorators);return t===void 0?this:new i(this.nodeDecorators,this.nodeDefaults,this.removeDecorator(t,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}toggleNodeDecorator(e){return this.isNodeDecoratorSet(e)?this.removeNodeDecorator(e):this.addNodeDecorator(e)}isEdgeDecoratorSet(e){return this.isDecoratorSet(e,this.edgeDecorators)}addEdgeDecorator(e){return new i(this.nodeDecorators,this.nodeDefaults,this.addDecorator(e,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeEdgeDecorator(e){return new i(this.nodeDecorators,this.nodeDefaults,this.removeDecorator(e,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}toggleEdgeDecorator(e){return this.isEdgeDecoratorSet(e)?this.removeEdgeDecorator(e):this.addEdgeDecorator(e)}hideNodeLabels(e){return new i(this.nodeDecorators,this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,e,this.edgeLabelsHidden)}hideEdgeLabels(e){return new i(this.nodeDecorators,this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,e)}isHideNodeLabels(){return this.nodeLabelsHidden}isHideEdgeLabels(){return this.edgeLabelsHidden}isDecoratorSet(e,t){return t.includes(e)}addDecorator(e,t){return this.isDecoratorSet(e,t)?t:t.concat([e])}removeDecorator(e,t){return this.isDecoratorSet(e,t)?t.filter(o=>o!==e):t}getNodeDecorationOverrides(e){let{id:t,attributes:o,...n}=e,d=Object.assign({},...this.nodeDecorators.map(h=>h(e))),s=this.nodeLabelsHidden?{label:""}:void 0;return{...d,...n,...s}}getEdgeDecorationOverrides(e){let{id:t,attributes:o,source:n,target:d,...s}=e,h=Object.assign({},...this.edgeDecorators.map(O=>O(e))),T=this.edgeLabelsHidden?{label:""}:void 0;return{...h,...s,...T}}static isFunction(e){return typeof e=="function"}static wrapDecorator(e){return i.isFunction(e)?e:()=>e}},g=i;p(g,"DEFAULT_NODE_DECORATION",{shape:"ellipse",color:"#FFc526",size:25,opacity:1,strokeColor:"#3E3E3E",strokeSize:2}),p(g,"DEFAULT_EDGE_DECORATION",{color:"#FF0000",size:2,sourceArrow:!1,targetArrow:!1,opacity:1,style:"solid"}),p(g,"idAsLabelNode",e=>({label:e.id})),p(g,"idAsLabelEdge",e=>({label:e.id}));var u=class{layout;onChange;invalidated;static createDefault(){return new u("force-directed",!0,!0)}constructor(e,t=!0,o=!0){this.layout=e,this.onChange=t,this.invalidated=o}getLayout(){return this.layout}isDirty(){return this.invalidated}isOnChange(){return this.onChange}validate(){return this.invalidated?new u(this.layout,this.onChange,!1):this}invalidate(){return this.invalidated?this:new u(this.layout,this.onChange,!0)}setLayout(e){return new u(e,this.onChange,!0)}setOnChange(e){return new u(this.layout,e,!1)}presetLayout(e){return this.setLayout(e)}customLayout(e){return this.setLayout(e)}};var l=class{static createDefault(){return new l([],[])}nodes;edges;constructor(e,t){this.nodes=new Set(e),this.edges=new Set(t)}addNodes(e){return e.every(t=>this.nodes.has(t))?this:new l([...Array.from(this.nodes),...e],Array.from(this.edges))}removeNodes(e){if(e.every(o=>!this.nodes.has(o)))return this;let t=new Set(Array.from(this.nodes));return e.forEach(o=>t.delete(o)),new l(Array.from(t),Array.from(this.edges))}addEdges(e){return e.every(t=>this.edges.has(t))?this:new l(Array.from(this.nodes),[...Array.from(this.edges),...e])}removeEdges(e){if(e.every(o=>!this.edges.has(o)))return this;let t=new Set(Array.from(this.edges));return e.forEach(o=>t.delete(o)),new l(Array.from(this.nodes),Array.from(t))}};var a=class{contentModel;selectionModel;decoratorModel;layoutModel;commandQueue;constructor(e,t={}){this.contentModel=e,this.decoratorModel=t.decoratorModel??g.createDefault(),this.layoutModel=t.layoutModel??u.createDefault(),this.selectionModel=t.selectionModel??l.createDefault(),this.commandQueue=t.commandQueue??[]}static applyContent(e,t){return new a(t,{...e.getOptions(),selectionModel:a.reconcileSelection(t,e.getSelection())})}static applySelection(e,t){return new a(e.getCurrentContent(),{...e.getOptions(),selectionModel:a.reconcileSelection(e.getCurrentContent(),t)})}static applyLayout(e,t){return new a(e.contentModel,{...e.getOptions(),layoutModel:t,selectionModel:e.getSelection()})}static applyDecoration(e,t){return new a(e.contentModel,{...e.getOptions(),decoratorModel:t})}static createEmpty(){return new a(c.createEmpty())}static createWithContent(e){return new a(e)}getCurrentContent(){return this.contentModel}getDecorators(){return this.decoratorModel}get nodes(){return this.decoratorModel.getDecoratedNodes(Object.values(this.contentModel.nodes))}get edges(){return this.decoratorModel.getDecoratedEdges(Object.values(this.contentModel.edges))}get selectedNodes(){return this.decoratorModel.getDecoratedNodes(Array.from(this.getSelection().nodes).map(e=>this.contentModel.getNode(e)).filter(e=>e!=null).map(e=>e))}get selectedEdges(){return this.decoratorModel.getDecoratedEdges(Array.from(this.getSelection().edges).map(e=>this.contentModel.getEdge(e)).filter(e=>e!=null).map(e=>e))}getNode(e){let t=this.contentModel.getNode(e);return t==null?t:this.decoratorModel.getDecoratedNodes([t])[0]}getEdge(e){let t=this.contentModel.getEdge(e);return t==null?t:this.decoratorModel.getDecoratedEdges([t])[0]}getNodeAttributes(){return this.contentModel.getNodeAttributes()}getEdgeAttributes(){return this.contentModel.getEdgeAttributes()}getCurrentLayout(){return this.layoutModel}getSelection(){return this.selectionModel}getCommands(){return this.commandQueue}pushCommand(e){return new a(this.contentModel,{...this.getOptions(),commandQueue:[...this.commandQueue,e]})}clearCommands(){return this.commandQueue.length===0?this:new a(this.contentModel,{...this.getOptions(),commandQueue:[]})}getOptions(){return{selectionModel:this.selectionModel,decoratorModel:this.decoratorModel,layoutModel:this.layoutModel,commandQueue:this.commandQueue}}static reconcileSelection(e,t){let o=Array.from(t.nodes).filter(d=>e.containsNode(d)),n=Array.from(t.edges).filter(d=>e.containsEdge(d));return new l(o,n)}};var x=["#f94144","#f3722c","#f8961e","#f9c74f","#90be6d","#43aa8b","#577590"];var y=["Ryann","Nolana","Jan","Maryl","Sonja","Lezlie","Alina","Amelina","Jacklyn","Vivi","Doti","Marylinda","Rosa","Joellen","Sorcha","Janet","Mamie","Valentina","Anatola","Sarene","Theressa","Joell","Phebe","Joby","Joscelin","Damara","Bobbie","Flore","Aline","Belvia","Kaitlin","Jemie","Gracie","Bonny","Dorena","Austin","Rachel","Austina","Elga","Dawn","Dionne","Suzi","Monica","Marice","Laurie","Carine","Maryanne","Magdalene","Myranda","Paola","Madelle","Florrie","Evey","Maryjo","Dniren","Marla","Gwynne","Abby","Emili","Cornie","Sherye","Con","Korry","Tomasina","Ashlen","Onida","Elmira","Jada","Ingaberg","Coretta","Jerry","Idelle"];var v=["rectangle","roundrectangle","ellipse","triangle","pentagon","hexagon","heptagon","octagon","star","barrel","diamond","vee","rhomboid","polygon","tag","round-rectangle","round-triangle","round-diamond","round-pentagon","round-hexagon","round-heptagon","round-octagon","round-tag","cut-rectangle","bottom-round-rectangle","concave-hexagon"];var D=r=>r[Math.floor(Math.random()*r.length)],M=r=>{let e=Object.values(r.nodes);if(e.length!==0)return D(e)},H=()=>Math.ceil(Math.random()*100),j=r=>{let e=Object.values(r.edges);if(e.length!==0)return D(e)},B=()=>D(x),z=()=>D(v),E=(r,e=1,t)=>{let o=r.getCurrentContent();for(let n=0;n<e;n++){let d=D(y),s=D(y),h=H();o=o.addNode({label:`${d} ${s}`,...typeof t=="function"?t():t,attributes:{firstName:d,lastName:s,age:h}})}return a.applyContent(r,o)},k=(r=20,e=15)=>C(E(a.createEmpty(),r),e),Q=(r,e=1)=>E(r,e,()=>({shape:z()})),V=(r,e=1)=>E(r,e,()=>({color:B()})),C=(r,e=1)=>{if(r.nodes.length===0)return r;let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=M(t),d=M(t);if(n==null||d==null)return r;t=t.addEdge({source:n.id,target:d.id,targetArrow:!0,label:"edge"})}return a.applyContent(r,t)},J=(r,e=1)=>{let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=M(t);if(n==null)return r;t=t.removeNode(n.id)}return a.applyContent(r,t)},Z=(r,e=1)=>{let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=j(t);if(n==null)return r;t=t.removeEdge(n.id)}return a.applyContent(r,t)};var A=(r,e=[10,200])=>t=>({size:w(...r(t),e)}),L=(r,e=[1,5])=>t=>({size:w(...r(t),e)}),w=(r,e,t)=>{if(r===void 0)return;let[o,n]=e,[d,s]=t;return(r-o)/(n-o)*(s-d)+d};function U(r,e){let t=r.map(d=>parseFloat(d.attributes[e])).filter(d=>!isNaN(d)),o=Math.min(...t),n=Math.max(...t);return[o,n]}function S(r,e){let t=U(r,e);return o=>{let n=parseFloat(o.attributes[e]);return isNaN(n)?[void 0,t]:[n,t]}}var K=(r,e,t)=>A(S(Object.values(r.nodes),e),t),W=(r,e,t)=>L(S(Object.values(r.edges),e),t);function Y(r){return typeof r!="string"} | ||
"use strict";var m=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var P=(r,e,t)=>e in r?m(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var x=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},I=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of R(e))!F.call(r,n)&&n!==t&&m(r,n,{get:()=>e[n],enumerable:!(o=A(e,n))||o.enumerable});return r};var H=r=>I(m({},"__esModule",{value:!0}),r);var D=(r,e,t)=>(P(r,typeof e!="symbol"?e+"":e,t),t);var ee={};x(ee,{ContentModel:()=>d,CurveStyles:()=>V,DecoratorModel:()=>h,EdgeStyles:()=>$,Generator:()=>b,GraphModel:()=>i,LayoutModel:()=>u,NodeShapes:()=>M,PresetGraphLayouts:()=>B,SelectionModel:()=>l,isCustomGraphLayout:()=>j,sizeEdgeBy:()=>w,sizeEdgeByMetadata:()=>_,sizeNodeBy:()=>L,sizeNodeByMetadata:()=>X});module.exports=H(ee);var f=require("uuid"),d=class{constructor(e,t){this.nodes=e;this.edges=t}static toNode(e){return{id:e.id??(0,f.v4)(),metadata:{},...e}}static toEdge(e){return{id:e.id??(0,f.v4)(),directed:!0,metadata:{},...e}}static fromRaw(e){let t=Object.keys(e.nodes).reduce((a,s)=>{let g=d.toNode({...e.nodes[s],id:s});return a[g.id]=g,a},{}),o=e.edges.reduce((a,s)=>{let g=d.toEdge(s);return a[g.id]=g,a},{}),n=new d(t,o);return n.validate(),n}static createEmpty(){return new d({},{})}validate(){Object.values(this.edges).forEach(e=>this.checkEdgeNodes(e))}containsNode(e){return this.getNode(e)!=null}containsEdge(e){return this.getEdge(e)!=null}getNode(e){return this.nodes[`${e}`]}getExistingNode(e){if(e==null)throw new Error("Node id must be given");let t=this.getNode(e);if(t==null)throw new Error(`Node [${e}] does not exist`);return t}getEdgesLinkedToNode(e){return Object.values(this.edges).filter(t=>t.target===e||t.source===e)}addNode(e){if(e.id!=null&&this.containsNode(e.id))throw new Error(`Cannot add node already in graph (${e.id})`);let t=d.toNode(e),o={...this.nodes,[t.id]:t};return new d(o,this.edges)}editNode(e){let t=this.getExistingNode(e.id);return new d({...this.nodes,[t.id]:d.toNode(e)},this.edges)}addNodeAttribute(e,t,o){return this.addNodeMetadata(e,t,o)}addNodeMetadata(e,t,o){let n=this.getExistingNode(e),a={...n.metadata,[t]:o},s={...n,metadata:a};return this.editNode(s)}removeNode(e){if(this.getNode(e)==null)return this;let o=this;return this.getEdgesLinkedToNode(e).forEach(n=>{o=o.removeEdge(n.id)}),o.removeOrphanNode(e)}removeOrphanNode(e){let t={...this.nodes};return delete t[`${e}`],new d(t,this.edges)}editNodeAttribute(e,t,o){return this.editNodeMetadata(e,t,o)}editNodeMetadata(e,t,o){if(this.getExistingNode(e).metadata[`${t}`]==null)throw new Error(`Node [${e}] does not have metadata ${t}`);return this.addNodeMetadata(e,t,o)}removeNodeAttribute(e,t){return this.removeNodeMetadata(e,t)}removeNodeMetadata(e,t){let o=this.getExistingNode(e),n={...o.metadata};delete n[`${t}`];let a={...o,metadata:n};return this.editNode(a)}addEdge(e){if(this.checkEdgeNodes(e),e.id!=null&&this.containsEdge(e.id))throw new Error(`Cannot add edge already in graph (${e.id})`);let t=d.toEdge(e),o={...this.edges,[t.id]:t};return new d(this.nodes,o)}checkEdgeNodes(e){this.getExistingNode(e.source),this.getExistingNode(e.target)}getEdge(e){return this.edges[`${e}`]}getExistingEdge(e){if(e==null)throw new Error("Edge id must be provided");let t=this.getEdge(e);if(t==null)throw new Error(`Edge [${e}] does not exist`);return t}editEdge(e){let t=this.getExistingEdge(e.id);return new d(this.nodes,{...this.edges,[t.id]:d.toEdge(e)})}addEdgeAttribute(e,t,o){return this.addEdgeMetadata(e,t,o)}addEdgeMetadata(e,t,o){let a={...this.getExistingEdge(e).metadata,[t]:o},s={...this.getExistingEdge(e),metadata:a};return this.editEdge(s)}editEdgeAttribute(e,t,o){return this.editEdgeMetadata(e,t,o)}editEdgeMetadata(e,t,o){if(this.getExistingEdge(e).metadata[`${t}`]==null)throw new Error(`Edge [${e}] does not have attribute ${t}`);return this.addEdgeMetadata(e,t,o)}removeEdgeAttribute(e,t){return this.removeEdgeMetadata(e,t)}removeEdgeMetadata(e,t){let o=this.getExistingEdge(e),n={...o.metadata};delete n[`${t}`];let a={...o,metadata:n};return this.editEdge(a)}removeEdge(e){if(this.getEdge(e)==null)return this;let o={...this.edges};return delete o[`${e}`],new d(this.nodes,o)}getMetadataSets(e){return e.reduce((t,o)=>(Object.entries(o.metadata).forEach(n=>{let a=t[n[0]]??new Set;a.add(typeof n[1]),t[n[0]]=a}),t),{})}getNodeAttributes(){return this.getNodeMetadataTypes()}getNodeMetadataTypes(){return this.getMetadataSets(Object.values(this.nodes))}getEdgeAttributes(){return this.getEdgeMetadataTypes()}getEdgeMetadataTypes(){return this.getMetadataSets(Object.values(this.edges))}};var b={};x(b,{addRandomEdge:()=>C,addRandomNode:()=>E,addRandomNodeColors:()=>K,addRandomNodeShapes:()=>U,randomGraph:()=>Z,randomNode:()=>y,removeRandomEdge:()=>Y,removeRandomNode:()=>W});var c=class{constructor(e,t,o,n,a,s){this.nodeDecorators=e;this.nodeDefaults=t;this.edgeDecorators=o;this.edgeDefaults=n;this.nodeLabelsHidden=a;this.edgeLabelsHidden=s;this.nodeDecorators=e,this.nodeDefaults=t,this.edgeDecorators=o,this.edgeDefaults=n,this.nodeLabelsHidden=a,this.edgeLabelsHidden=s}static createDefault(e={}){return new c(e.nodeDecorators??[],e.nodeDefaults??{},e.edgeDecorators??[],e.edgeDefaults??{},e.hideNodeLabels??!1,e.hideEdgeLabels??!1)}getDefaultNodeDecorator(){return()=>({...c.DEFAULT_NODE_DECORATION,strokeColor:"$colors$textSecondary",color:"$colors$brandYellow9",...c.wrapDecorator(this.nodeDefaults)()})}getDefaultEdgeDecorator(){return()=>({...c.DEFAULT_EDGE_DECORATION,color:"$colors$textSecondary",...c.wrapDecorator(this.edgeDefaults)()})}getDecoratedNodes(e){return Object.values(e).map(t=>({getDecorationOverrides:()=>this.getNodeDecorationOverrides(t),...t}))}getDecoratedEdges(e){return Object.values(e).map(t=>({getDecorationOverrides:()=>this.getEdgeDecorationOverrides(t),...t}))}isNodeDecoratorSet(e){return this.isDecoratorSet(e,this.nodeDecorators)}addNodeDecorator(e){return new c(this.addDecorator(e,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeNodeDecorator(e){return new c(this.removeDecorator(e,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}getDecoratorIds(e){return e.map(t=>t.id).filter(t=>t!==void 0)}getNodeDecoratorIds(){return this.getDecoratorIds(this.nodeDecorators)}getEdgeDecoratorIds(){return this.getDecoratorIds(this.edgeDecorators)}getDecoratorById(e,t){return t.find(o=>o.id===e)}removeNodeDecoratorById(e){let t=this.getDecoratorById(e,this.nodeDecorators);return t===void 0?this:new c(this.removeDecorator(t,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeEdgeDecoratorById(e){let t=this.getDecoratorById(e,this.edgeDecorators);return t===void 0?this:new c(this.nodeDecorators,this.nodeDefaults,this.removeDecorator(t,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}toggleNodeDecorator(e){return this.isNodeDecoratorSet(e)?this.removeNodeDecorator(e):this.addNodeDecorator(e)}isEdgeDecoratorSet(e){return this.isDecoratorSet(e,this.edgeDecorators)}addEdgeDecorator(e){return new c(this.nodeDecorators,this.nodeDefaults,this.addDecorator(e,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeEdgeDecorator(e){return new c(this.nodeDecorators,this.nodeDefaults,this.removeDecorator(e,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}toggleEdgeDecorator(e){return this.isEdgeDecoratorSet(e)?this.removeEdgeDecorator(e):this.addEdgeDecorator(e)}hideNodeLabels(e){return new c(this.nodeDecorators,this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,e,this.edgeLabelsHidden)}hideEdgeLabels(e){return new c(this.nodeDecorators,this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,e)}isHideNodeLabels(){return this.nodeLabelsHidden}isHideEdgeLabels(){return this.edgeLabelsHidden}isDecoratorSet(e,t){return t.includes(e)}addDecorator(e,t){return this.isDecoratorSet(e,t)?t:t.concat([e])}removeDecorator(e,t){return this.isDecoratorSet(e,t)?t.filter(o=>o!==e):t}getNodeDecorationOverrides(e){let{id:t,metadata:o,...n}=e,a=Object.assign({},...this.nodeDecorators.map(g=>g(e))),s=this.nodeLabelsHidden?{label:""}:void 0;return{...a,...n,...s}}getEdgeDecorationOverrides(e){let{id:t,metadata:o,source:n,target:a,...s}=e,g=Object.assign({},...this.edgeDecorators.map(O=>O(e))),G=this.edgeLabelsHidden?{label:""}:void 0;return{...g,...s,...G}}static isFunction(e){return typeof e=="function"}static wrapDecorator(e){return c.isFunction(e)?e:()=>e}},h=c;D(h,"DEFAULT_NODE_DECORATION",{shape:"ellipse",color:"#FFc526",size:25,opacity:1,strokeColor:"#3E3E3E",strokeSize:2}),D(h,"DEFAULT_EDGE_DECORATION",{color:"#FF0000",size:2,sourceArrow:!1,targetArrow:!1,opacity:1,style:"solid",curve:"haystack"}),D(h,"idAsLabelNode",e=>({label:e.id})),D(h,"idAsLabelEdge",e=>({label:e.id}));var u=class{layout;onChange;invalidated;static createDefault(){return new u("force-directed",!0,!0)}constructor(e,t=!0,o=!0){this.layout=e,this.onChange=t,this.invalidated=o}getLayout(){return this.layout}isDirty(){return this.invalidated}isOnChange(){return this.onChange}validate(){return this.invalidated?new u(this.layout,this.onChange,!1):this}invalidate(){return this.invalidated?this:new u(this.layout,this.onChange,!0)}setLayout(e){return new u(e,this.onChange,!0)}setOnChange(e){return new u(this.layout,e,!1)}presetLayout(e){return this.setLayout(e)}customLayout(e){return this.setLayout(e)}};var l=class{static createDefault(){return new l([],[])}nodes;edges;constructor(e,t){this.nodes=new Set(e),this.edges=new Set(t)}addNodes(e){return e.every(t=>this.nodes.has(t))?this:new l([...Array.from(this.nodes),...e],Array.from(this.edges))}removeNodes(e){if(e.every(o=>!this.nodes.has(o)))return this;let t=new Set(Array.from(this.nodes));return e.forEach(o=>t.delete(o)),new l(Array.from(t),Array.from(this.edges))}addEdges(e){return e.every(t=>this.edges.has(t))?this:new l(Array.from(this.nodes),[...Array.from(this.edges),...e])}removeEdges(e){if(e.every(o=>!this.edges.has(o)))return this;let t=new Set(Array.from(this.edges));return e.forEach(o=>t.delete(o)),new l(Array.from(this.nodes),Array.from(t))}};var i=class{contentModel;selectionModel;decoratorModel;layoutModel;commandQueue;constructor(e,t={}){this.contentModel=e,this.decoratorModel=t.decoratorModel??h.createDefault(),this.layoutModel=t.layoutModel??u.createDefault(),this.selectionModel=t.selectionModel??l.createDefault(),this.commandQueue=t.commandQueue??[]}static applyContent(e,t){return new i(t,{...e.getOptions(),selectionModel:i.reconcileSelection(t,e.getSelection())})}static applySelection(e,t){return new i(e.getCurrentContent(),{...e.getOptions(),selectionModel:i.reconcileSelection(e.getCurrentContent(),t)})}static applyLayout(e,t){return new i(e.contentModel,{...e.getOptions(),layoutModel:t,selectionModel:e.getSelection()})}static applyDecoration(e,t){return new i(e.contentModel,{...e.getOptions(),decoratorModel:t})}static createEmpty(){return new i(d.createEmpty())}static createWithContent(e){return new i(e)}getCurrentContent(){return this.contentModel}getDecorators(){return this.decoratorModel}get nodes(){return this.decoratorModel.getDecoratedNodes(Object.values(this.contentModel.nodes))}get edges(){return this.decoratorModel.getDecoratedEdges(Object.values(this.contentModel.edges))}get selectedNodes(){return this.decoratorModel.getDecoratedNodes(Array.from(this.getSelection().nodes).map(e=>this.contentModel.getNode(e)).filter(e=>e!=null).map(e=>e))}get selectedEdges(){return this.decoratorModel.getDecoratedEdges(Array.from(this.getSelection().edges).map(e=>this.contentModel.getEdge(e)).filter(e=>e!=null).map(e=>e))}getNode(e){let t=this.contentModel.getNode(e);return t==null?t:this.decoratorModel.getDecoratedNodes([t])[0]}getEdge(e){let t=this.contentModel.getEdge(e);return t==null?t:this.decoratorModel.getDecoratedEdges([t])[0]}getNodeMetadataTypes(){return this.contentModel.getNodeMetadataTypes()}getEdgeMetadataTypes(){return this.contentModel.getEdgeMetadataTypes()}getCurrentLayout(){return this.layoutModel}getSelection(){return this.selectionModel}getCommands(){return this.commandQueue}pushCommand(e){return new i(this.contentModel,{...this.getOptions(),commandQueue:[...this.commandQueue,e]})}clearCommands(){return this.commandQueue.length===0?this:new i(this.contentModel,{...this.getOptions(),commandQueue:[]})}getOptions(){return{selectionModel:this.selectionModel,decoratorModel:this.decoratorModel,layoutModel:this.layoutModel,commandQueue:this.commandQueue}}static reconcileSelection(e,t){let o=Array.from(t.nodes).filter(a=>e.containsNode(a)),n=Array.from(t.edges).filter(a=>e.containsEdge(a));return new l(o,n)}};var M={rectangle:"Rectangle",ellipse:"Ellipse",triangle:"Triangle",pentagon:"Pentagon",hexagon:"Hexagon",heptagon:"Heptagon",octagon:"Octagon",star:"Star",barrel:"Barrel",diamond:"Diamond",vee:"Vee",rhomboid:"Rhomboid",tag:"Tag","round-rectangle":"Rounded rectangle","round-triangle":"Rounded triangle","round-diamond":"Rounded diamond","round-pentagon":"Rounded pentagon","round-hexagon":"Rounded hexagon","round-heptagon":"Rounded heptagon","round-octagon":"Rounded octagon","round-tag":"Rounded tag","cut-rectangle":"Cut rectangle","bottom-round-rectangle":"Bottom rounded rectangle","concave-hexagon":"Concave hexagon"},$={solid:"Solid",dotted:"Dotted",dashed:"Dashed"},V={haystack:"Haystack",straight:"Straight","straight-triangle":"Triangle",bezier:"Bezier","unbundled-bezier":"Unbundled-bezier",segments:"Segments",taxi:"Taxi"},B={"force-directed":"Force-directed",circle:"Circle",grid:"Grid",cola:"Cola",hierarchical:"Hierarchical",concentric:"Concentric","breadth-first":"Breadth-first",cose:"Cose"};function j(r){return typeof r!="string"}var v=["#f94144","#f3722c","#f8961e","#f9c74f","#90be6d","#43aa8b","#577590"];var N=["Ryann","Nolana","Jan","Maryl","Sonja","Lezlie","Alina","Amelina","Jacklyn","Vivi","Doti","Marylinda","Rosa","Joellen","Sorcha","Janet","Mamie","Valentina","Anatola","Sarene","Theressa","Joell","Phebe","Joby","Joscelin","Damara","Bobbie","Flore","Aline","Belvia","Kaitlin","Jemie","Gracie","Bonny","Dorena","Austin","Rachel","Austina","Elga","Dawn","Dionne","Suzi","Monica","Marice","Laurie","Carine","Maryanne","Magdalene","Myranda","Paola","Madelle","Florrie","Evey","Maryjo","Dniren","Marla","Gwynne","Abby","Emili","Cornie","Sherye","Con","Korry","Tomasina","Ashlen","Onida","Elmira","Jada","Ingaberg","Coretta","Jerry","Idelle"];var p=r=>r[Math.floor(Math.random()*r.length)],y=r=>{let e=Object.values(r.nodes);if(e.length!==0)return p(e)},k=()=>Math.ceil(Math.random()*100),z=r=>{let e=Object.values(r.edges);if(e.length!==0)return p(e)},Q=()=>p(v),J=()=>p(Object.keys(M)),E=(r,e=1,t)=>{let o=r.getCurrentContent();for(let n=0;n<e;n++){let a=p(N),s=p(N),g=k();o=o.addNode({label:`${a} ${s}`,...typeof t=="function"?t():t,metadata:{firstName:a,lastName:s,age:g}})}return i.applyContent(r,o)},Z=(r=20,e=15)=>C(E(i.createEmpty(),r),e),U=(r,e=1)=>E(r,e,()=>({shape:J()})),K=(r,e=1)=>E(r,e,()=>({color:Q()})),C=(r,e=1)=>{if(r.nodes.length===0)return r;let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=y(t),a=y(t);if(n==null||a==null)return r;t=t.addEdge({source:n.id,target:a.id,targetArrow:!0,label:"edge"})}return i.applyContent(r,t)},W=(r,e=1)=>{let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=y(t);if(n==null)return r;t=t.removeNode(n.id)}return i.applyContent(r,t)},Y=(r,e=1)=>{let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=z(t);if(n==null)return r;t=t.removeEdge(n.id)}return i.applyContent(r,t)};var L=(r,e=[10,200])=>t=>({size:T(...r(t),e)}),w=(r,e=[1,5])=>t=>({size:T(...r(t),e)}),T=(r,e,t)=>{if(r===void 0)return;let[o,n]=e,[a,s]=t;return(r-o)/(n-o)*(s-a)+a};function q(r,e){let t=r.map(a=>parseFloat(a.metadata[e])).filter(a=>!isNaN(a)),o=Math.min(...t),n=Math.max(...t);return[o,n]}function S(r,e){let t=q(r,e);return o=>{let n=parseFloat(o.metadata[e]);return isNaN(n)?[void 0,t]:[n,t]}}var X=(r,e,t)=>L(S(Object.values(r.nodes),e),t),_=(r,e,t)=>w(S(Object.values(r.edges),e),t); | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
var f=Object.defineProperty;var S=(r,e,t)=>e in r?f(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var T=(r,e)=>{for(var t in e)f(r,t,{get:e[t],enumerable:!0})};var p=(r,e,t)=>(S(r,typeof e!="symbol"?e+"":e,t),t);import{v4 as y}from"uuid";var c=class{constructor(e,t){this.nodes=e;this.edges=t;this.nodes=e,this.edges=t}static fromRaw(e){let t=new c(e.nodes,e.edges);return Object.values(t.edges).forEach(o=>t.checkEdgeNodes(o)),t}static createEmpty(){return new c({},{})}containsNode(e){return this.getNode(e)!=null}containsEdge(e){return this.getEdge(e)!=null}getNode(e){return this.nodes[`${e}`]}getExistingNode(e){let t=this.getNode(e);if(t==null)throw new Error(`Node [${e}] does not exist`);return t}getEdgesLinkedToNode(e){return Object.values(this.edges).filter(t=>t.target===e||t.source===e)}addNode(e){if(e.id!=null&&this.containsNode(e.id))throw new Error(`Cannot add node already in graph (${e.id})`);let t={id:e.id??y(),attributes:e.attributes??{},...e},o={...this.nodes,[t.id]:t};return new c(o,this.edges)}editNode(e){return this.getExistingNode(e.id),new c({...this.nodes,[e.id]:e},this.edges)}addNodeAttribute(e,t,o){let d={...this.getExistingNode(e).attributes,[t]:o},s={...this.getExistingNode(e),attributes:d};return this.editNode(s)}removeNode(e){if(this.getNode(e)==null)return this;let o=this;return this.getEdgesLinkedToNode(e).forEach(n=>{o=o.removeEdge(n.id)}),o.removeOrphanNode(e)}removeOrphanNode(e){let t={...this.nodes};return delete t[`${e}`],new c(t,this.edges)}editNodeAttribute(e,t,o){if(this.getExistingNode(e).attributes[`${t}`]==null)throw new Error(`Node [${e}] does not have attribute ${t}`);return this.addNodeAttribute(e,t,o)}removeNodeAttribute(e,t){let o=this.getExistingNode(e),n={...o.attributes};delete n[`${t}`];let d={...o,attributes:n};return this.editNode(d)}addEdge(e){if(this.checkEdgeNodes(e),e.id!=null&&this.containsEdge(e.id))throw new Error(`Cannot add edge already in graph (${e.id})`);let t={id:e.id??y(),attributes:e.attributes??{},...e},o={...this.edges,[t.id]:t};return new c(this.nodes,o)}checkEdgeNodes(e){this.getExistingNode(e.source),this.getExistingNode(e.target)}getEdge(e){return this.edges[`${e}`]}getExistingEdge(e){let t=this.getEdge(e);if(t==null)throw new Error(`Edge [${e}] does not exist`);return t}editEdge(e){return this.getExistingEdge(e.id),new c(this.nodes,{...this.edges,[e.id]:e})}addEdgeAttribute(e,t,o){let d={...this.getExistingEdge(e).attributes,[t]:o},s={...this.getExistingEdge(e),attributes:d};return this.editEdge(s)}editEdgeAttribute(e,t,o){if(this.getExistingEdge(e).attributes[`${t}`]==null)throw new Error(`Edge [${e}] does not have attribute ${t}`);return this.addEdgeAttribute(e,t,o)}removeEdgeAttribute(e,t){let o=this.getExistingEdge(e),n={...o.attributes};delete n[`${t}`];let d={...o,attributes:n};return this.editEdge(d)}removeEdge(e){if(this.getEdge(e)==null)return this;let o={...this.edges};return delete o[`${e}`],new c(this.nodes,o)}getAttributes(e){return e.reduce((t,o)=>(Object.entries(o.attributes).forEach(n=>{let d=t[n[0]]??new Set;d.add(typeof n[1]),t[n[0]]=d}),t),{})}getNodeAttributes(){return this.getAttributes(Object.values(this.nodes))}getEdgeAttributes(){return this.getAttributes(Object.values(this.edges))}};var v={};T(v,{addRandomEdge:()=>x,addRandomNode:()=>M,addRandomNodeColors:()=>$,addRandomNodeShapes:()=>P,randomGraph:()=>R,randomNode:()=>m,removeRandomEdge:()=>j,removeRandomNode:()=>H});var i=class{constructor(e,t,o,n,d,s){this.nodeDecorators=e;this.nodeDefaults=t;this.edgeDecorators=o;this.edgeDefaults=n;this.nodeLabelsHidden=d;this.edgeLabelsHidden=s;this.nodeDecorators=e,this.nodeDefaults=t,this.edgeDecorators=o,this.edgeDefaults=n,this.nodeLabelsHidden=d,this.edgeLabelsHidden=s}static createDefault(e={}){return new i(e.nodeDecorators??[],e.nodeDefaults??{},e.edgeDecorators??[],e.edgeDefaults??{},e.hideNodeLabels??!1,e.hideEdgeLabels??!1)}getDefaultNodeDecorator(){return()=>({...i.DEFAULT_NODE_DECORATION,strokeColor:"$colors$textSecondary",color:"$colors$brandYellow9",...i.wrapDecorator(this.nodeDefaults)()})}getDefaultEdgeDecorator(){return()=>({...i.DEFAULT_EDGE_DECORATION,color:"$colors$textSecondary",...i.wrapDecorator(this.edgeDefaults)()})}getDecoratedNodes(e){return Object.values(e).map(t=>({getDecorationOverrides:()=>this.getNodeDecorationOverrides(t),...t}))}getDecoratedEdges(e){return Object.values(e).map(t=>({getDecorationOverrides:()=>this.getEdgeDecorationOverrides(t),...t}))}isNodeDecoratorSet(e){return this.isDecoratorSet(e,this.nodeDecorators)}addNodeDecorator(e){return new i(this.addDecorator(e,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeNodeDecorator(e){return new i(this.removeDecorator(e,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}getDecoratorIds(e){return e.map(t=>t.id).filter(t=>t!==void 0)}getNodeDecoratorIds(){return this.getDecoratorIds(this.nodeDecorators)}getEdgeDecoratorIds(){return this.getDecoratorIds(this.edgeDecorators)}getDecoratorById(e,t){return t.find(o=>o.id===e)}removeNodeDecoratorById(e){let t=this.getDecoratorById(e,this.nodeDecorators);return t===void 0?this:new i(this.removeDecorator(t,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeEdgeDecoratorById(e){let t=this.getDecoratorById(e,this.edgeDecorators);return t===void 0?this:new i(this.nodeDecorators,this.nodeDefaults,this.removeDecorator(t,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}toggleNodeDecorator(e){return this.isNodeDecoratorSet(e)?this.removeNodeDecorator(e):this.addNodeDecorator(e)}isEdgeDecoratorSet(e){return this.isDecoratorSet(e,this.edgeDecorators)}addEdgeDecorator(e){return new i(this.nodeDecorators,this.nodeDefaults,this.addDecorator(e,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeEdgeDecorator(e){return new i(this.nodeDecorators,this.nodeDefaults,this.removeDecorator(e,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}toggleEdgeDecorator(e){return this.isEdgeDecoratorSet(e)?this.removeEdgeDecorator(e):this.addEdgeDecorator(e)}hideNodeLabels(e){return new i(this.nodeDecorators,this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,e,this.edgeLabelsHidden)}hideEdgeLabels(e){return new i(this.nodeDecorators,this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,e)}isHideNodeLabels(){return this.nodeLabelsHidden}isHideEdgeLabels(){return this.edgeLabelsHidden}isDecoratorSet(e,t){return t.includes(e)}addDecorator(e,t){return this.isDecoratorSet(e,t)?t:t.concat([e])}removeDecorator(e,t){return this.isDecoratorSet(e,t)?t.filter(o=>o!==e):t}getNodeDecorationOverrides(e){let{id:t,attributes:o,...n}=e,d=Object.assign({},...this.nodeDecorators.map(h=>h(e))),s=this.nodeLabelsHidden?{label:""}:void 0;return{...d,...n,...s}}getEdgeDecorationOverrides(e){let{id:t,attributes:o,source:n,target:d,...s}=e,h=Object.assign({},...this.edgeDecorators.map(w=>w(e))),L=this.edgeLabelsHidden?{label:""}:void 0;return{...h,...s,...L}}static isFunction(e){return typeof e=="function"}static wrapDecorator(e){return i.isFunction(e)?e:()=>e}},g=i;p(g,"DEFAULT_NODE_DECORATION",{shape:"ellipse",color:"#FFc526",size:25,opacity:1,strokeColor:"#3E3E3E",strokeSize:2}),p(g,"DEFAULT_EDGE_DECORATION",{color:"#FF0000",size:2,sourceArrow:!1,targetArrow:!1,opacity:1,style:"solid"}),p(g,"idAsLabelNode",e=>({label:e.id})),p(g,"idAsLabelEdge",e=>({label:e.id}));var u=class{layout;onChange;invalidated;static createDefault(){return new u("force-directed",!0,!0)}constructor(e,t=!0,o=!0){this.layout=e,this.onChange=t,this.invalidated=o}getLayout(){return this.layout}isDirty(){return this.invalidated}isOnChange(){return this.onChange}validate(){return this.invalidated?new u(this.layout,this.onChange,!1):this}invalidate(){return this.invalidated?this:new u(this.layout,this.onChange,!0)}setLayout(e){return new u(e,this.onChange,!0)}setOnChange(e){return new u(this.layout,e,!1)}presetLayout(e){return this.setLayout(e)}customLayout(e){return this.setLayout(e)}};var l=class{static createDefault(){return new l([],[])}nodes;edges;constructor(e,t){this.nodes=new Set(e),this.edges=new Set(t)}addNodes(e){return e.every(t=>this.nodes.has(t))?this:new l([...Array.from(this.nodes),...e],Array.from(this.edges))}removeNodes(e){if(e.every(o=>!this.nodes.has(o)))return this;let t=new Set(Array.from(this.nodes));return e.forEach(o=>t.delete(o)),new l(Array.from(t),Array.from(this.edges))}addEdges(e){return e.every(t=>this.edges.has(t))?this:new l(Array.from(this.nodes),[...Array.from(this.edges),...e])}removeEdges(e){if(e.every(o=>!this.edges.has(o)))return this;let t=new Set(Array.from(this.edges));return e.forEach(o=>t.delete(o)),new l(Array.from(this.nodes),Array.from(t))}};var a=class{contentModel;selectionModel;decoratorModel;layoutModel;commandQueue;constructor(e,t={}){this.contentModel=e,this.decoratorModel=t.decoratorModel??g.createDefault(),this.layoutModel=t.layoutModel??u.createDefault(),this.selectionModel=t.selectionModel??l.createDefault(),this.commandQueue=t.commandQueue??[]}static applyContent(e,t){return new a(t,{...e.getOptions(),selectionModel:a.reconcileSelection(t,e.getSelection())})}static applySelection(e,t){return new a(e.getCurrentContent(),{...e.getOptions(),selectionModel:a.reconcileSelection(e.getCurrentContent(),t)})}static applyLayout(e,t){return new a(e.contentModel,{...e.getOptions(),layoutModel:t,selectionModel:e.getSelection()})}static applyDecoration(e,t){return new a(e.contentModel,{...e.getOptions(),decoratorModel:t})}static createEmpty(){return new a(c.createEmpty())}static createWithContent(e){return new a(e)}getCurrentContent(){return this.contentModel}getDecorators(){return this.decoratorModel}get nodes(){return this.decoratorModel.getDecoratedNodes(Object.values(this.contentModel.nodes))}get edges(){return this.decoratorModel.getDecoratedEdges(Object.values(this.contentModel.edges))}get selectedNodes(){return this.decoratorModel.getDecoratedNodes(Array.from(this.getSelection().nodes).map(e=>this.contentModel.getNode(e)).filter(e=>e!=null).map(e=>e))}get selectedEdges(){return this.decoratorModel.getDecoratedEdges(Array.from(this.getSelection().edges).map(e=>this.contentModel.getEdge(e)).filter(e=>e!=null).map(e=>e))}getNode(e){let t=this.contentModel.getNode(e);return t==null?t:this.decoratorModel.getDecoratedNodes([t])[0]}getEdge(e){let t=this.contentModel.getEdge(e);return t==null?t:this.decoratorModel.getDecoratedEdges([t])[0]}getNodeAttributes(){return this.contentModel.getNodeAttributes()}getEdgeAttributes(){return this.contentModel.getEdgeAttributes()}getCurrentLayout(){return this.layoutModel}getSelection(){return this.selectionModel}getCommands(){return this.commandQueue}pushCommand(e){return new a(this.contentModel,{...this.getOptions(),commandQueue:[...this.commandQueue,e]})}clearCommands(){return this.commandQueue.length===0?this:new a(this.contentModel,{...this.getOptions(),commandQueue:[]})}getOptions(){return{selectionModel:this.selectionModel,decoratorModel:this.decoratorModel,layoutModel:this.layoutModel,commandQueue:this.commandQueue}}static reconcileSelection(e,t){let o=Array.from(t.nodes).filter(d=>e.containsNode(d)),n=Array.from(t.edges).filter(d=>e.containsEdge(d));return new l(o,n)}};var b=["#f94144","#f3722c","#f8961e","#f9c74f","#90be6d","#43aa8b","#577590"];var E=["Ryann","Nolana","Jan","Maryl","Sonja","Lezlie","Alina","Amelina","Jacklyn","Vivi","Doti","Marylinda","Rosa","Joellen","Sorcha","Janet","Mamie","Valentina","Anatola","Sarene","Theressa","Joell","Phebe","Joby","Joscelin","Damara","Bobbie","Flore","Aline","Belvia","Kaitlin","Jemie","Gracie","Bonny","Dorena","Austin","Rachel","Austina","Elga","Dawn","Dionne","Suzi","Monica","Marice","Laurie","Carine","Maryanne","Magdalene","Myranda","Paola","Madelle","Florrie","Evey","Maryjo","Dniren","Marla","Gwynne","Abby","Emili","Cornie","Sherye","Con","Korry","Tomasina","Ashlen","Onida","Elmira","Jada","Ingaberg","Coretta","Jerry","Idelle"];var N=["rectangle","roundrectangle","ellipse","triangle","pentagon","hexagon","heptagon","octagon","star","barrel","diamond","vee","rhomboid","polygon","tag","round-rectangle","round-triangle","round-diamond","round-pentagon","round-hexagon","round-heptagon","round-octagon","round-tag","cut-rectangle","bottom-round-rectangle","concave-hexagon"];var D=r=>r[Math.floor(Math.random()*r.length)],m=r=>{let e=Object.values(r.nodes);if(e.length!==0)return D(e)},O=()=>Math.ceil(Math.random()*100),G=r=>{let e=Object.values(r.edges);if(e.length!==0)return D(e)},F=()=>D(b),I=()=>D(N),M=(r,e=1,t)=>{let o=r.getCurrentContent();for(let n=0;n<e;n++){let d=D(E),s=D(E),h=O();o=o.addNode({label:`${d} ${s}`,...typeof t=="function"?t():t,attributes:{firstName:d,lastName:s,age:h}})}return a.applyContent(r,o)},R=(r=20,e=15)=>x(M(a.createEmpty(),r),e),P=(r,e=1)=>M(r,e,()=>({shape:I()})),$=(r,e=1)=>M(r,e,()=>({color:F()})),x=(r,e=1)=>{if(r.nodes.length===0)return r;let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=m(t),d=m(t);if(n==null||d==null)return r;t=t.addEdge({source:n.id,target:d.id,targetArrow:!0,label:"edge"})}return a.applyContent(r,t)},H=(r,e=1)=>{let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=m(t);if(n==null)return r;t=t.removeNode(n.id)}return a.applyContent(r,t)},j=(r,e=1)=>{let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=G(t);if(n==null)return r;t=t.removeEdge(n.id)}return a.applyContent(r,t)};var B=(r,e=[10,200])=>t=>({size:C(...r(t),e)}),z=(r,e=[1,5])=>t=>({size:C(...r(t),e)}),C=(r,e,t)=>{if(r===void 0)return;let[o,n]=e,[d,s]=t;return(r-o)/(n-o)*(s-d)+d};function k(r,e){let t=r.map(d=>parseFloat(d.attributes[e])).filter(d=>!isNaN(d)),o=Math.min(...t),n=Math.max(...t);return[o,n]}function A(r,e){let t=k(r,e);return o=>{let n=parseFloat(o.attributes[e]);return isNaN(n)?[void 0,t]:[n,t]}}var ce=(r,e,t)=>B(A(Object.values(r.nodes),e),t),le=(r,e,t)=>z(A(Object.values(r.edges),e),t);function ge(r){return typeof r!="string"}export{c as ContentModel,g as DecoratorModel,v as Generator,a as GraphModel,u as LayoutModel,l as SelectionModel,ge as isCustomGraphLayout,z as sizeEdgeBy,le as sizeEdgeByAttribute,B as sizeNodeBy,ce as sizeNodeByAttribute}; | ||
var f=Object.defineProperty;var S=(r,e,t)=>e in r?f(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var G=(r,e)=>{for(var t in e)f(r,t,{get:e[t],enumerable:!0})};var D=(r,e,t)=>(S(r,typeof e!="symbol"?e+"":e,t),t);import{v4 as M}from"uuid";var i=class{constructor(e,t){this.nodes=e;this.edges=t}static toNode(e){return{id:e.id??M(),metadata:{},...e}}static toEdge(e){return{id:e.id??M(),directed:!0,metadata:{},...e}}static fromRaw(e){let t=Object.keys(e.nodes).reduce((a,d)=>{let g=i.toNode({...e.nodes[d],id:d});return a[g.id]=g,a},{}),o=e.edges.reduce((a,d)=>{let g=i.toEdge(d);return a[g.id]=g,a},{}),n=new i(t,o);return n.validate(),n}static createEmpty(){return new i({},{})}validate(){Object.values(this.edges).forEach(e=>this.checkEdgeNodes(e))}containsNode(e){return this.getNode(e)!=null}containsEdge(e){return this.getEdge(e)!=null}getNode(e){return this.nodes[`${e}`]}getExistingNode(e){if(e==null)throw new Error("Node id must be given");let t=this.getNode(e);if(t==null)throw new Error(`Node [${e}] does not exist`);return t}getEdgesLinkedToNode(e){return Object.values(this.edges).filter(t=>t.target===e||t.source===e)}addNode(e){if(e.id!=null&&this.containsNode(e.id))throw new Error(`Cannot add node already in graph (${e.id})`);let t=i.toNode(e),o={...this.nodes,[t.id]:t};return new i(o,this.edges)}editNode(e){let t=this.getExistingNode(e.id);return new i({...this.nodes,[t.id]:i.toNode(e)},this.edges)}addNodeAttribute(e,t,o){return this.addNodeMetadata(e,t,o)}addNodeMetadata(e,t,o){let n=this.getExistingNode(e),a={...n.metadata,[t]:o},d={...n,metadata:a};return this.editNode(d)}removeNode(e){if(this.getNode(e)==null)return this;let o=this;return this.getEdgesLinkedToNode(e).forEach(n=>{o=o.removeEdge(n.id)}),o.removeOrphanNode(e)}removeOrphanNode(e){let t={...this.nodes};return delete t[`${e}`],new i(t,this.edges)}editNodeAttribute(e,t,o){return this.editNodeMetadata(e,t,o)}editNodeMetadata(e,t,o){if(this.getExistingNode(e).metadata[`${t}`]==null)throw new Error(`Node [${e}] does not have metadata ${t}`);return this.addNodeMetadata(e,t,o)}removeNodeAttribute(e,t){return this.removeNodeMetadata(e,t)}removeNodeMetadata(e,t){let o=this.getExistingNode(e),n={...o.metadata};delete n[`${t}`];let a={...o,metadata:n};return this.editNode(a)}addEdge(e){if(this.checkEdgeNodes(e),e.id!=null&&this.containsEdge(e.id))throw new Error(`Cannot add edge already in graph (${e.id})`);let t=i.toEdge(e),o={...this.edges,[t.id]:t};return new i(this.nodes,o)}checkEdgeNodes(e){this.getExistingNode(e.source),this.getExistingNode(e.target)}getEdge(e){return this.edges[`${e}`]}getExistingEdge(e){if(e==null)throw new Error("Edge id must be provided");let t=this.getEdge(e);if(t==null)throw new Error(`Edge [${e}] does not exist`);return t}editEdge(e){let t=this.getExistingEdge(e.id);return new i(this.nodes,{...this.edges,[t.id]:i.toEdge(e)})}addEdgeAttribute(e,t,o){return this.addEdgeMetadata(e,t,o)}addEdgeMetadata(e,t,o){let a={...this.getExistingEdge(e).metadata,[t]:o},d={...this.getExistingEdge(e),metadata:a};return this.editEdge(d)}editEdgeAttribute(e,t,o){return this.editEdgeMetadata(e,t,o)}editEdgeMetadata(e,t,o){if(this.getExistingEdge(e).metadata[`${t}`]==null)throw new Error(`Edge [${e}] does not have attribute ${t}`);return this.addEdgeMetadata(e,t,o)}removeEdgeAttribute(e,t){return this.removeEdgeMetadata(e,t)}removeEdgeMetadata(e,t){let o=this.getExistingEdge(e),n={...o.metadata};delete n[`${t}`];let a={...o,metadata:n};return this.editEdge(a)}removeEdge(e){if(this.getEdge(e)==null)return this;let o={...this.edges};return delete o[`${e}`],new i(this.nodes,o)}getMetadataSets(e){return e.reduce((t,o)=>(Object.entries(o.metadata).forEach(n=>{let a=t[n[0]]??new Set;a.add(typeof n[1]),t[n[0]]=a}),t),{})}getNodeAttributes(){return this.getNodeMetadataTypes()}getNodeMetadataTypes(){return this.getMetadataSets(Object.values(this.nodes))}getEdgeAttributes(){return this.getEdgeMetadataTypes()}getEdgeMetadataTypes(){return this.getMetadataSets(Object.values(this.edges))}};var v={};G(v,{addRandomEdge:()=>x,addRandomNode:()=>y,addRandomNodeColors:()=>H,addRandomNodeShapes:()=>I,randomGraph:()=>P,randomNode:()=>m,removeRandomEdge:()=>V,removeRandomNode:()=>$});var c=class{constructor(e,t,o,n,a,d){this.nodeDecorators=e;this.nodeDefaults=t;this.edgeDecorators=o;this.edgeDefaults=n;this.nodeLabelsHidden=a;this.edgeLabelsHidden=d;this.nodeDecorators=e,this.nodeDefaults=t,this.edgeDecorators=o,this.edgeDefaults=n,this.nodeLabelsHidden=a,this.edgeLabelsHidden=d}static createDefault(e={}){return new c(e.nodeDecorators??[],e.nodeDefaults??{},e.edgeDecorators??[],e.edgeDefaults??{},e.hideNodeLabels??!1,e.hideEdgeLabels??!1)}getDefaultNodeDecorator(){return()=>({...c.DEFAULT_NODE_DECORATION,strokeColor:"$colors$textSecondary",color:"$colors$brandYellow9",...c.wrapDecorator(this.nodeDefaults)()})}getDefaultEdgeDecorator(){return()=>({...c.DEFAULT_EDGE_DECORATION,color:"$colors$textSecondary",...c.wrapDecorator(this.edgeDefaults)()})}getDecoratedNodes(e){return Object.values(e).map(t=>({getDecorationOverrides:()=>this.getNodeDecorationOverrides(t),...t}))}getDecoratedEdges(e){return Object.values(e).map(t=>({getDecorationOverrides:()=>this.getEdgeDecorationOverrides(t),...t}))}isNodeDecoratorSet(e){return this.isDecoratorSet(e,this.nodeDecorators)}addNodeDecorator(e){return new c(this.addDecorator(e,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeNodeDecorator(e){return new c(this.removeDecorator(e,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}getDecoratorIds(e){return e.map(t=>t.id).filter(t=>t!==void 0)}getNodeDecoratorIds(){return this.getDecoratorIds(this.nodeDecorators)}getEdgeDecoratorIds(){return this.getDecoratorIds(this.edgeDecorators)}getDecoratorById(e,t){return t.find(o=>o.id===e)}removeNodeDecoratorById(e){let t=this.getDecoratorById(e,this.nodeDecorators);return t===void 0?this:new c(this.removeDecorator(t,this.nodeDecorators),this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeEdgeDecoratorById(e){let t=this.getDecoratorById(e,this.edgeDecorators);return t===void 0?this:new c(this.nodeDecorators,this.nodeDefaults,this.removeDecorator(t,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}toggleNodeDecorator(e){return this.isNodeDecoratorSet(e)?this.removeNodeDecorator(e):this.addNodeDecorator(e)}isEdgeDecoratorSet(e){return this.isDecoratorSet(e,this.edgeDecorators)}addEdgeDecorator(e){return new c(this.nodeDecorators,this.nodeDefaults,this.addDecorator(e,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}removeEdgeDecorator(e){return new c(this.nodeDecorators,this.nodeDefaults,this.removeDecorator(e,this.edgeDecorators),this.edgeDefaults,this.nodeLabelsHidden,this.edgeLabelsHidden)}toggleEdgeDecorator(e){return this.isEdgeDecoratorSet(e)?this.removeEdgeDecorator(e):this.addEdgeDecorator(e)}hideNodeLabels(e){return new c(this.nodeDecorators,this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,e,this.edgeLabelsHidden)}hideEdgeLabels(e){return new c(this.nodeDecorators,this.nodeDefaults,this.edgeDecorators,this.edgeDefaults,this.nodeLabelsHidden,e)}isHideNodeLabels(){return this.nodeLabelsHidden}isHideEdgeLabels(){return this.edgeLabelsHidden}isDecoratorSet(e,t){return t.includes(e)}addDecorator(e,t){return this.isDecoratorSet(e,t)?t:t.concat([e])}removeDecorator(e,t){return this.isDecoratorSet(e,t)?t.filter(o=>o!==e):t}getNodeDecorationOverrides(e){let{id:t,metadata:o,...n}=e,a=Object.assign({},...this.nodeDecorators.map(g=>g(e))),d=this.nodeLabelsHidden?{label:""}:void 0;return{...a,...n,...d}}getEdgeDecorationOverrides(e){let{id:t,metadata:o,source:n,target:a,...d}=e,g=Object.assign({},...this.edgeDecorators.map(T=>T(e))),w=this.edgeLabelsHidden?{label:""}:void 0;return{...g,...d,...w}}static isFunction(e){return typeof e=="function"}static wrapDecorator(e){return c.isFunction(e)?e:()=>e}},h=c;D(h,"DEFAULT_NODE_DECORATION",{shape:"ellipse",color:"#FFc526",size:25,opacity:1,strokeColor:"#3E3E3E",strokeSize:2}),D(h,"DEFAULT_EDGE_DECORATION",{color:"#FF0000",size:2,sourceArrow:!1,targetArrow:!1,opacity:1,style:"solid",curve:"haystack"}),D(h,"idAsLabelNode",e=>({label:e.id})),D(h,"idAsLabelEdge",e=>({label:e.id}));var u=class{layout;onChange;invalidated;static createDefault(){return new u("force-directed",!0,!0)}constructor(e,t=!0,o=!0){this.layout=e,this.onChange=t,this.invalidated=o}getLayout(){return this.layout}isDirty(){return this.invalidated}isOnChange(){return this.onChange}validate(){return this.invalidated?new u(this.layout,this.onChange,!1):this}invalidate(){return this.invalidated?this:new u(this.layout,this.onChange,!0)}setLayout(e){return new u(e,this.onChange,!0)}setOnChange(e){return new u(this.layout,e,!1)}presetLayout(e){return this.setLayout(e)}customLayout(e){return this.setLayout(e)}};var l=class{static createDefault(){return new l([],[])}nodes;edges;constructor(e,t){this.nodes=new Set(e),this.edges=new Set(t)}addNodes(e){return e.every(t=>this.nodes.has(t))?this:new l([...Array.from(this.nodes),...e],Array.from(this.edges))}removeNodes(e){if(e.every(o=>!this.nodes.has(o)))return this;let t=new Set(Array.from(this.nodes));return e.forEach(o=>t.delete(o)),new l(Array.from(t),Array.from(this.edges))}addEdges(e){return e.every(t=>this.edges.has(t))?this:new l(Array.from(this.nodes),[...Array.from(this.edges),...e])}removeEdges(e){if(e.every(o=>!this.edges.has(o)))return this;let t=new Set(Array.from(this.edges));return e.forEach(o=>t.delete(o)),new l(Array.from(this.nodes),Array.from(t))}};var s=class{contentModel;selectionModel;decoratorModel;layoutModel;commandQueue;constructor(e,t={}){this.contentModel=e,this.decoratorModel=t.decoratorModel??h.createDefault(),this.layoutModel=t.layoutModel??u.createDefault(),this.selectionModel=t.selectionModel??l.createDefault(),this.commandQueue=t.commandQueue??[]}static applyContent(e,t){return new s(t,{...e.getOptions(),selectionModel:s.reconcileSelection(t,e.getSelection())})}static applySelection(e,t){return new s(e.getCurrentContent(),{...e.getOptions(),selectionModel:s.reconcileSelection(e.getCurrentContent(),t)})}static applyLayout(e,t){return new s(e.contentModel,{...e.getOptions(),layoutModel:t,selectionModel:e.getSelection()})}static applyDecoration(e,t){return new s(e.contentModel,{...e.getOptions(),decoratorModel:t})}static createEmpty(){return new s(i.createEmpty())}static createWithContent(e){return new s(e)}getCurrentContent(){return this.contentModel}getDecorators(){return this.decoratorModel}get nodes(){return this.decoratorModel.getDecoratedNodes(Object.values(this.contentModel.nodes))}get edges(){return this.decoratorModel.getDecoratedEdges(Object.values(this.contentModel.edges))}get selectedNodes(){return this.decoratorModel.getDecoratedNodes(Array.from(this.getSelection().nodes).map(e=>this.contentModel.getNode(e)).filter(e=>e!=null).map(e=>e))}get selectedEdges(){return this.decoratorModel.getDecoratedEdges(Array.from(this.getSelection().edges).map(e=>this.contentModel.getEdge(e)).filter(e=>e!=null).map(e=>e))}getNode(e){let t=this.contentModel.getNode(e);return t==null?t:this.decoratorModel.getDecoratedNodes([t])[0]}getEdge(e){let t=this.contentModel.getEdge(e);return t==null?t:this.decoratorModel.getDecoratedEdges([t])[0]}getNodeMetadataTypes(){return this.contentModel.getNodeMetadataTypes()}getEdgeMetadataTypes(){return this.contentModel.getEdgeMetadataTypes()}getCurrentLayout(){return this.layoutModel}getSelection(){return this.selectionModel}getCommands(){return this.commandQueue}pushCommand(e){return new s(this.contentModel,{...this.getOptions(),commandQueue:[...this.commandQueue,e]})}clearCommands(){return this.commandQueue.length===0?this:new s(this.contentModel,{...this.getOptions(),commandQueue:[]})}getOptions(){return{selectionModel:this.selectionModel,decoratorModel:this.decoratorModel,layoutModel:this.layoutModel,commandQueue:this.commandQueue}}static reconcileSelection(e,t){let o=Array.from(t.nodes).filter(a=>e.containsNode(a)),n=Array.from(t.edges).filter(a=>e.containsEdge(a));return new l(o,n)}};var N={rectangle:"Rectangle",ellipse:"Ellipse",triangle:"Triangle",pentagon:"Pentagon",hexagon:"Hexagon",heptagon:"Heptagon",octagon:"Octagon",star:"Star",barrel:"Barrel",diamond:"Diamond",vee:"Vee",rhomboid:"Rhomboid",tag:"Tag","round-rectangle":"Rounded rectangle","round-triangle":"Rounded triangle","round-diamond":"Rounded diamond","round-pentagon":"Rounded pentagon","round-hexagon":"Rounded hexagon","round-heptagon":"Rounded heptagon","round-octagon":"Rounded octagon","round-tag":"Rounded tag","cut-rectangle":"Cut rectangle","bottom-round-rectangle":"Bottom rounded rectangle","concave-hexagon":"Concave hexagon"},te={solid:"Solid",dotted:"Dotted",dashed:"Dashed"},oe={haystack:"Haystack",straight:"Straight","straight-triangle":"Triangle",bezier:"Bezier","unbundled-bezier":"Unbundled-bezier",segments:"Segments",taxi:"Taxi"},re={"force-directed":"Force-directed",circle:"Circle",grid:"Grid",cola:"Cola",hierarchical:"Hierarchical",concentric:"Concentric","breadth-first":"Breadth-first",cose:"Cose"};function ne(r){return typeof r!="string"}var b=["#f94144","#f3722c","#f8961e","#f9c74f","#90be6d","#43aa8b","#577590"];var E=["Ryann","Nolana","Jan","Maryl","Sonja","Lezlie","Alina","Amelina","Jacklyn","Vivi","Doti","Marylinda","Rosa","Joellen","Sorcha","Janet","Mamie","Valentina","Anatola","Sarene","Theressa","Joell","Phebe","Joby","Joscelin","Damara","Bobbie","Flore","Aline","Belvia","Kaitlin","Jemie","Gracie","Bonny","Dorena","Austin","Rachel","Austina","Elga","Dawn","Dionne","Suzi","Monica","Marice","Laurie","Carine","Maryanne","Magdalene","Myranda","Paola","Madelle","Florrie","Evey","Maryjo","Dniren","Marla","Gwynne","Abby","Emili","Cornie","Sherye","Con","Korry","Tomasina","Ashlen","Onida","Elmira","Jada","Ingaberg","Coretta","Jerry","Idelle"];var p=r=>r[Math.floor(Math.random()*r.length)],m=r=>{let e=Object.values(r.nodes);if(e.length!==0)return p(e)},O=()=>Math.ceil(Math.random()*100),A=r=>{let e=Object.values(r.edges);if(e.length!==0)return p(e)},R=()=>p(b),F=()=>p(Object.keys(N)),y=(r,e=1,t)=>{let o=r.getCurrentContent();for(let n=0;n<e;n++){let a=p(E),d=p(E),g=O();o=o.addNode({label:`${a} ${d}`,...typeof t=="function"?t():t,metadata:{firstName:a,lastName:d,age:g}})}return s.applyContent(r,o)},P=(r=20,e=15)=>x(y(s.createEmpty(),r),e),I=(r,e=1)=>y(r,e,()=>({shape:F()})),H=(r,e=1)=>y(r,e,()=>({color:R()})),x=(r,e=1)=>{if(r.nodes.length===0)return r;let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=m(t),a=m(t);if(n==null||a==null)return r;t=t.addEdge({source:n.id,target:a.id,targetArrow:!0,label:"edge"})}return s.applyContent(r,t)},$=(r,e=1)=>{let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=m(t);if(n==null)return r;t=t.removeNode(n.id)}return s.applyContent(r,t)},V=(r,e=1)=>{let t=r.getCurrentContent();for(let o=0;o<e;o++){let n=A(t);if(n==null)return r;t=t.removeEdge(n.id)}return s.applyContent(r,t)};var B=(r,e=[10,200])=>t=>({size:C(...r(t),e)}),j=(r,e=[1,5])=>t=>({size:C(...r(t),e)}),C=(r,e,t)=>{if(r===void 0)return;let[o,n]=e,[a,d]=t;return(r-o)/(n-o)*(d-a)+a};function k(r,e){let t=r.map(a=>parseFloat(a.metadata[e])).filter(a=>!isNaN(a)),o=Math.min(...t),n=Math.max(...t);return[o,n]}function L(r,e){let t=k(r,e);return o=>{let n=parseFloat(o.metadata[e]);return isNaN(n)?[void 0,t]:[n,t]}}var me=(r,e,t)=>B(L(Object.values(r.nodes),e),t),ye=(r,e,t)=>j(L(Object.values(r.edges),e),t);export{i as ContentModel,oe as CurveStyles,h as DecoratorModel,te as EdgeStyles,v as Generator,s as GraphModel,u as LayoutModel,N as NodeShapes,re as PresetGraphLayouts,l as SelectionModel,ne as isCustomGraphLayout,j as sizeEdgeBy,ye as sizeEdgeByMetadata,B as sizeNodeBy,me as sizeNodeByMetadata}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,5 +0,5 @@ | ||
import { ModelNode, ModelEdge, GraphModel } from 'index'; | ||
export declare const node1: ModelNode; | ||
export declare const node2: ModelNode; | ||
export declare const edge1: ModelEdge; | ||
import { Edge, GraphModel, Node } from 'index'; | ||
export declare const node1: Node; | ||
export declare const node2: Node; | ||
export declare const edge1: Edge; | ||
export declare const exampleGraph: GraphModel; |
{ | ||
"name": "@committed/graph", | ||
"version": "3.3.0", | ||
"version": "4.0.0", | ||
"description": "Graph models, types and API", | ||
@@ -5,0 +5,0 @@ "author": "Committed", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
175134
609
27