UNPKG

@cnvx/nodal

Version:

A Svelte 5 library for creating interactive node diagrams with customizable connections and layouts

51 lines (50 loc) 1.75 kB
import BaseEdge from "./BaseEdge.svelte"; import { SvelteMap } from "svelte/reactivity"; import { type Vector2 } from "./diagram-lib.js"; import type { HTMLAttributes } from "svelte/elements"; import type { Writable } from "svelte/store"; import { getNodeAnchorFast } from "./layout-utils.js"; import type { ComponentProps } from "svelte"; type PathGenParams = { pathGen?: "bezier"; curvature?: number; offset?: Vector2; } | { pathGen: "smoothstep"; borderRadius?: number; center?: Vector2; }; export type SurfaceEdgeParams<C extends typeof BaseEdge = typeof BaseEdge> = { component?: C | [C, Omit<ComponentProps<C>, "d" | "edge">]; sourceAnchor?: Vector2; targetAnchor?: Vector2; svgPathAttributes?: HTMLAttributes<SVGPathElement>; } & PathGenParams; export interface PrecalculatedEdge { x1: number; y1: number; x2: number; y2: number; } export type SurfaceEdge = { source: string | HTMLElement | string[] | HTMLElement[]; target: string | HTMLElement | string[] | HTMLElement[]; precalculated?: PrecalculatedEdge; } & SurfaceEdgeParams; type $$ComponentProps = { hostElement: Element; edges: SvelteMap<string, SurfaceEdge>; width?: Writable<number>; height?: Writable<number>; svgAttributes?: HTMLAttributes<SVGElement>; getNodeAnchor?: typeof getNodeAnchorFast; fadeInDuration?: number; }; declare const Surface: import("svelte").Component<$$ComponentProps, { width: Writable<number> | undefined; height: Writable<number> | undefined; edges: SvelteMap<string, SurfaceEdge>; getNodes: (input: string | HTMLElement | string[] | HTMLElement[]) => HTMLElement[]; }, "">; type Surface = ReturnType<typeof Surface>; export default Surface;