import select_default from "../../../../d3-selection/src/select.js";
import pointer_default from "../../../../d3-selection/src/pointer.js";
import drag_default from "../../../../d3-drag/src/drag.js";
import value_default from "../../../../d3-interpolate/src/value.js";
import zoom_default$1 from "../../../../d3-interpolate/src/zoom.js";
import transform, { identity } from "../../../../d3-zoom/src/transform.js";
import zoom_default from "../../../../d3-zoom/src/zoom.js";
import "../../../../d3-zoom/src/index.js";
var errorMessages = {
	error001: () => "[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",
	error002: () => "It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",
	error003: (e) => `Node type "${e}" not found. Using fallback type "default".`,
	error004: () => "The React Flow parent container needs a width and a height to render the graph.",
	error005: () => "Only child nodes can use a parent extent.",
	error006: () => "Can't create edge. An edge needs a source and a target.",
	error007: (e) => `The old edge with id=${e} does not exist.`,
	error009: (e) => `Marker type "${e}" doesn't exist.`,
	error008: (e, { id: s, sourceHandle: c, targetHandle: l }) => `Couldn't create edge for ${e} handle id: "${e === "source" ? c : l}", edge id: ${s}.`,
	error010: () => "Handle: No node id found. Make sure to only use a Handle inside a custom Node.",
	error011: (e) => `Edge type "${e}" not found. Using fallback type "default".`,
	error012: (e) => `Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,
	error013: (e = "react") => `It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,
	error014: () => "useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",
	error015: () => "It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."
}, infiniteExtent = [[-Infinity, -Infinity], [Infinity, Infinity]], elementSelectionKeys = [
	"Enter",
	" ",
	"Escape"
], defaultAriaLabelConfig = {
	"node.a11yDescription.default": "Press enter or space to select a node. Press delete to remove it and escape to cancel.",
	"node.a11yDescription.keyboardDisabled": "Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.",
	"node.a11yDescription.ariaLiveMessage": ({ direction: e, x: s, y: c }) => `Moved selected node ${e}. New position, x: ${s}, y: ${c}`,
	"edge.a11yDescription.default": "Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.",
	"controls.ariaLabel": "Control Panel",
	"controls.zoomIn.ariaLabel": "Zoom In",
	"controls.zoomOut.ariaLabel": "Zoom Out",
	"controls.fitView.ariaLabel": "Fit View",
	"controls.interactive.ariaLabel": "Toggle Interactivity",
	"minimap.ariaLabel": "Mini Map",
	"handle.ariaLabel": "Handle"
}, ConnectionMode;
(function(e) {
	e.Strict = "strict", e.Loose = "loose";
})(ConnectionMode ||= {});
var PanOnScrollMode;
(function(e) {
	e.Free = "free", e.Vertical = "vertical", e.Horizontal = "horizontal";
})(PanOnScrollMode ||= {});
var SelectionMode;
(function(e) {
	e.Partial = "partial", e.Full = "full";
})(SelectionMode ||= {});
var initialConnection = {
	inProgress: !1,
	isValid: null,
	from: null,
	fromHandle: null,
	fromPosition: null,
	fromNode: null,
	to: null,
	toHandle: null,
	toPosition: null,
	toNode: null,
	pointer: null
}, ConnectionLineType;
(function(e) {
	e.Bezier = "default", e.Straight = "straight", e.Step = "step", e.SmoothStep = "smoothstep", e.SimpleBezier = "simplebezier";
})(ConnectionLineType ||= {});
var MarkerType;
(function(e) {
	e.Arrow = "arrow", e.ArrowClosed = "arrowclosed";
})(MarkerType ||= {});
var Position;
(function(e) {
	e.Left = "left", e.Top = "top", e.Right = "right", e.Bottom = "bottom";
})(Position ||= {});
var oppositePosition = {
	[Position.Left]: Position.Right,
	[Position.Right]: Position.Left,
	[Position.Top]: Position.Bottom,
	[Position.Bottom]: Position.Top
};
function getConnectionStatus(e) {
	return e === null ? null : e ? "valid" : "invalid";
}
var isEdgeBase = (e) => "id" in e && "source" in e && "target" in e, isNodeBase = (e) => "id" in e && "position" in e && !("source" in e) && !("target" in e), isInternalNodeBase = (e) => "id" in e && "internals" in e && !("source" in e) && !("target" in e), getNodePositionWithOrigin = (e, s = [0, 0]) => {
	let { width: c, height: l } = getNodeDimensions(e), u = e.origin ?? s, d = c * u[0], f = l * u[1];
	return {
		x: e.position.x - d,
		y: e.position.y - f
	};
}, getNodesBounds = (e, s = { nodeOrigin: [0, 0] }) => (process.env.NODE_ENV === "development" && !s.nodeLookup && console.warn("Please use `getNodesBounds` from `useReactFlow`/`useSvelteFlow` hook to ensure correct values for sub flows. If not possible, you have to provide a nodeLookup to support sub flows."), e.length === 0 ? {
	x: 0,
	y: 0,
	width: 0,
	height: 0
} : boxToRect(e.reduce((e, c) => {
	let l = typeof c == "string", u = !s.nodeLookup && !l ? c : void 0;
	return s.nodeLookup && (u = l ? s.nodeLookup.get(c) : isInternalNodeBase(c) ? c : s.nodeLookup.get(c.id)), getBoundsOfBoxes(e, u ? nodeToBox(u, s.nodeOrigin) : {
		x: 0,
		y: 0,
		x2: 0,
		y2: 0
	});
}, {
	x: Infinity,
	y: Infinity,
	x2: -Infinity,
	y2: -Infinity
}))), getInternalNodesBounds = (e, s = {}) => {
	let c = {
		x: Infinity,
		y: Infinity,
		x2: -Infinity,
		y2: -Infinity
	}, l = !1;
	return e.forEach((e) => {
		(s.filter === void 0 || s.filter(e)) && (c = getBoundsOfBoxes(c, nodeToBox(e)), l = !0);
	}), l ? boxToRect(c) : {
		x: 0,
		y: 0,
		width: 0,
		height: 0
	};
}, getNodesInside = (e, s, [c, l, u] = [
	0,
	0,
	1
], d = !1, f = !1) => {
	let p = {
		...pointToRendererPoint(s, [
			c,
			l,
			u
		]),
		width: s.width / u,
		height: s.height / u
	}, m = [];
	for (let s of e.values()) {
		let { measured: e, selectable: c = !0, hidden: l = !1 } = s;
		if (f && !c || l) continue;
		let u = e.width ?? s.width ?? s.initialWidth ?? null, h = e.height ?? s.height ?? s.initialHeight ?? null, g = getOverlappingArea(p, nodeToRect(s)), _ = (u ?? 0) * (h ?? 0), v = d && g > 0;
		(!s.internals.handleBounds || v || g >= _ || s.dragging) && m.push(s);
	}
	return m;
}, getConnectedEdges = (e, s) => {
	let c = /* @__PURE__ */ new Set();
	return e.forEach((e) => {
		c.add(e.id);
	}), s.filter((e) => c.has(e.source) || c.has(e.target));
};
function getFitViewNodes(e, s) {
	let c = /* @__PURE__ */ new Map(), l = s?.nodes ? new Set(s.nodes.map((e) => e.id)) : null;
	return e.forEach((e) => {
		e.measured.width && e.measured.height && (s?.includeHiddenNodes || !e.hidden) && (!l || l.has(e.id)) && c.set(e.id, e);
	}), c;
}
async function fitViewport({ nodes: e, width: s, height: c, panZoom: l, minZoom: u, maxZoom: d }, f) {
	if (e.size === 0) return Promise.resolve(!0);
	let p = getViewportForBounds(getInternalNodesBounds(getFitViewNodes(e, f)), s, c, f?.minZoom ?? u, f?.maxZoom ?? d, f?.padding ?? .1);
	return await l.setViewport(p, {
		duration: f?.duration,
		ease: f?.ease,
		interpolate: f?.interpolate
	}), Promise.resolve(!0);
}
function calculateNodePosition({ nodeId: e, nextPosition: s, nodeLookup: c, nodeOrigin: l = [0, 0], nodeExtent: u, onError: d }) {
	let f = c.get(e), p = f.parentId ? c.get(f.parentId) : void 0, { x: h, y: g } = p ? p.internals.positionAbsolute : {
		x: 0,
		y: 0
	}, _ = f.origin ?? l, v = f.extent || u;
	if (f.extent === "parent" && !f.expandParent) if (!p) d?.("005", errorMessages.error005());
	else {
		let e = p.measured.width, s = p.measured.height;
		e && s && (v = [[h, g], [h + e, g + s]]);
	}
	else p && isCoordinateExtent(f.extent) && (v = [[f.extent[0][0] + h, f.extent[0][1] + g], [f.extent[1][0] + h, f.extent[1][1] + g]]);
	let y = isCoordinateExtent(v) ? clampPosition(s, v, f.measured) : s;
	return (f.measured.width === void 0 || f.measured.height === void 0) && d?.("015", errorMessages.error015()), {
		position: {
			x: y.x - h + (f.measured.width ?? 0) * _[0],
			y: y.y - g + (f.measured.height ?? 0) * _[1]
		},
		positionAbsolute: y
	};
}
async function getElementsToRemove({ nodesToRemove: e = [], edgesToRemove: s = [], nodes: c, edges: l, onBeforeDelete: u }) {
	let d = new Set(e.map((e) => e.id)), f = [];
	for (let e of c) {
		if (e.deletable === !1) continue;
		let s = d.has(e.id), c = !s && e.parentId && f.find((s) => s.id === e.parentId);
		(s || c) && f.push(e);
	}
	let p = new Set(s.map((e) => e.id)), m = l.filter((e) => e.deletable !== !1), h = getConnectedEdges(f, m);
	for (let e of m) p.has(e.id) && !h.find((s) => s.id === e.id) && h.push(e);
	if (!u) return {
		edges: h,
		nodes: f
	};
	let g = await u({
		nodes: f,
		edges: h
	});
	return typeof g == "boolean" ? g ? {
		edges: h,
		nodes: f
	} : {
		edges: [],
		nodes: []
	} : g;
}
var clamp = (e, s = 0, c = 1) => Math.min(Math.max(e, s), c), clampPosition = (e = {
	x: 0,
	y: 0
}, s, c) => ({
	x: clamp(e.x, s[0][0], s[1][0] - (c?.width ?? 0)),
	y: clamp(e.y, s[0][1], s[1][1] - (c?.height ?? 0))
});
function clampPositionToParent(e, s, c) {
	let { width: l, height: u } = getNodeDimensions(c), { x: d, y: f } = c.internals.positionAbsolute;
	return clampPosition(e, [[d, f], [d + l, f + u]], s);
}
var calcAutoPanVelocity = (e, s, c) => e < s ? clamp(Math.abs(e - s), 1, s) / s : e > c ? -clamp(Math.abs(e - c), 1, s) / s : 0, calcAutoPan = (e, s, c = 15, l = 40) => [calcAutoPanVelocity(e.x, l, s.width - l) * c, calcAutoPanVelocity(e.y, l, s.height - l) * c], getBoundsOfBoxes = (e, s) => ({
	x: Math.min(e.x, s.x),
	y: Math.min(e.y, s.y),
	x2: Math.max(e.x2, s.x2),
	y2: Math.max(e.y2, s.y2)
}), rectToBox = ({ x: e, y: s, width: c, height: l }) => ({
	x: e,
	y: s,
	x2: e + c,
	y2: s + l
}), boxToRect = ({ x: e, y: s, x2: c, y2: l }) => ({
	x: e,
	y: s,
	width: c - e,
	height: l - s
}), nodeToRect = (e, s = [0, 0]) => {
	let { x: c, y: l } = isInternalNodeBase(e) ? e.internals.positionAbsolute : getNodePositionWithOrigin(e, s);
	return {
		x: c,
		y: l,
		width: e.measured?.width ?? e.width ?? e.initialWidth ?? 0,
		height: e.measured?.height ?? e.height ?? e.initialHeight ?? 0
	};
}, nodeToBox = (e, s = [0, 0]) => {
	let { x: c, y: l } = isInternalNodeBase(e) ? e.internals.positionAbsolute : getNodePositionWithOrigin(e, s);
	return {
		x: c,
		y: l,
		x2: c + (e.measured?.width ?? e.width ?? e.initialWidth ?? 0),
		y2: l + (e.measured?.height ?? e.height ?? e.initialHeight ?? 0)
	};
}, getBoundsOfRects = (e, s) => boxToRect(getBoundsOfBoxes(rectToBox(e), rectToBox(s))), getOverlappingArea = (e, s) => {
	let c = Math.max(0, Math.min(e.x + e.width, s.x + s.width) - Math.max(e.x, s.x)), l = Math.max(0, Math.min(e.y + e.height, s.y + s.height) - Math.max(e.y, s.y));
	return Math.ceil(c * l);
}, isRectObject = (e) => isNumeric(e.width) && isNumeric(e.height) && isNumeric(e.x) && isNumeric(e.y), isNumeric = (e) => !isNaN(e) && isFinite(e), devWarn = (e, s) => {
	process.env.NODE_ENV === "development" && console.warn(`[React Flow]: ${s} Help: https://reactflow.dev/error#${e}`);
}, snapPosition = (e, s = [1, 1]) => ({
	x: s[0] * Math.round(e.x / s[0]),
	y: s[1] * Math.round(e.y / s[1])
}), pointToRendererPoint = ({ x: e, y: s }, [c, l, u], d = !1, f = [1, 1]) => {
	let p = {
		x: (e - c) / u,
		y: (s - l) / u
	};
	return d ? snapPosition(p, f) : p;
}, rendererPointToPoint = ({ x: e, y: s }, [c, l, u]) => ({
	x: e * u + c,
	y: s * u + l
});
function parsePadding(e, s) {
	if (typeof e == "number") return Math.floor((s - s / (1 + e)) * .5);
	if (typeof e == "string" && e.endsWith("px")) {
		let s = parseFloat(e);
		if (!Number.isNaN(s)) return Math.floor(s);
	}
	if (typeof e == "string" && e.endsWith("%")) {
		let c = parseFloat(e);
		if (!Number.isNaN(c)) return Math.floor(s * c * .01);
	}
	return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`), 0;
}
function parsePaddings(e, s, c) {
	if (typeof e == "string" || typeof e == "number") {
		let l = parsePadding(e, c), u = parsePadding(e, s);
		return {
			top: l,
			right: u,
			bottom: l,
			left: u,
			x: u * 2,
			y: l * 2
		};
	}
	if (typeof e == "object") {
		let l = parsePadding(e.top ?? e.y ?? 0, c), u = parsePadding(e.bottom ?? e.y ?? 0, c), d = parsePadding(e.left ?? e.x ?? 0, s), f = parsePadding(e.right ?? e.x ?? 0, s);
		return {
			top: l,
			right: f,
			bottom: u,
			left: d,
			x: d + f,
			y: l + u
		};
	}
	return {
		top: 0,
		right: 0,
		bottom: 0,
		left: 0,
		x: 0,
		y: 0
	};
}
function calculateAppliedPaddings(e, s, c, l, u, d) {
	let { x: f, y: p } = rendererPointToPoint(e, [
		s,
		c,
		l
	]), { x: m, y: h } = rendererPointToPoint({
		x: e.x + e.width,
		y: e.y + e.height
	}, [
		s,
		c,
		l
	]), g = u - m, _ = d - h;
	return {
		left: Math.floor(f),
		top: Math.floor(p),
		right: Math.floor(g),
		bottom: Math.floor(_)
	};
}
var getViewportForBounds = (e, s, c, l, u, d) => {
	let f = parsePaddings(d, s, c), p = (s - f.x) / e.width, m = (c - f.y) / e.height, h = clamp(Math.min(p, m), l, u), g = e.x + e.width / 2, _ = e.y + e.height / 2, v = s / 2 - g * h, y = c / 2 - _ * h, b = calculateAppliedPaddings(e, v, y, h, s, c), x = {
		left: Math.min(b.left - f.left, 0),
		top: Math.min(b.top - f.top, 0),
		right: Math.min(b.right - f.right, 0),
		bottom: Math.min(b.bottom - f.bottom, 0)
	};
	return {
		x: v - x.left + x.right,
		y: y - x.top + x.bottom,
		zoom: h
	};
}, isMacOs = () => typeof navigator < "u" && navigator?.userAgent?.indexOf("Mac") >= 0;
function isCoordinateExtent(e) {
	return e != null && e !== "parent";
}
function getNodeDimensions(e) {
	return {
		width: e.measured?.width ?? e.width ?? e.initialWidth ?? 0,
		height: e.measured?.height ?? e.height ?? e.initialHeight ?? 0
	};
}
function nodeHasDimensions(e) {
	return (e.measured?.width ?? e.width ?? e.initialWidth) !== void 0 && (e.measured?.height ?? e.height ?? e.initialHeight) !== void 0;
}
function evaluateAbsolutePosition(e, s = {
	width: 0,
	height: 0
}, c, l, u) {
	let d = { ...e }, f = l.get(c);
	if (f) {
		let e = f.origin || u;
		d.x += f.internals.positionAbsolute.x - (s.width ?? 0) * e[0], d.y += f.internals.positionAbsolute.y - (s.height ?? 0) * e[1];
	}
	return d;
}
function areSetsEqual(e, s) {
	if (e.size !== s.size) return !1;
	for (let c of e) if (!s.has(c)) return !1;
	return !0;
}
function withResolvers() {
	let e, s;
	return {
		promise: new Promise((c, l) => {
			e = c, s = l;
		}),
		resolve: e,
		reject: s
	};
}
function mergeAriaLabelConfig(e) {
	return {
		...defaultAriaLabelConfig,
		...e || {}
	};
}
function getPointerPosition(e, { snapGrid: s = [0, 0], snapToGrid: c = !1, transform: l, containerBounds: u }) {
	let { x: d, y: f } = getEventPosition(e), p = pointToRendererPoint({
		x: d - (u?.left ?? 0),
		y: f - (u?.top ?? 0)
	}, l), { x: m, y: h } = c ? snapPosition(p, s) : p;
	return {
		xSnapped: m,
		ySnapped: h,
		...p
	};
}
var getDimensions = (e) => ({
	width: e.offsetWidth,
	height: e.offsetHeight
}), getHostForElement = (e) => e?.getRootNode?.() || window?.document, inputTags = [
	"INPUT",
	"SELECT",
	"TEXTAREA"
];
function isInputDOMNode(e) {
	let s = e.composedPath?.()?.[0] || e.target;
	return s?.nodeType === 1 ? inputTags.includes(s.nodeName) || s.hasAttribute("contenteditable") || !!s.closest(".nokey") : !1;
}
var isMouseEvent = (e) => "clientX" in e, getEventPosition = (e, s) => {
	let c = isMouseEvent(e), l = c ? e.clientX : e.touches?.[0].clientX, u = c ? e.clientY : e.touches?.[0].clientY;
	return {
		x: l - (s?.left ?? 0),
		y: u - (s?.top ?? 0)
	};
}, getHandleBounds = (e, s, c, l, u) => {
	let d = s.querySelectorAll(`.${e}`);
	return !d || !d.length ? null : Array.from(d).map((s) => {
		let d = s.getBoundingClientRect();
		return {
			id: s.getAttribute("data-handleid"),
			type: e,
			nodeId: u,
			position: s.getAttribute("data-handlepos"),
			x: (d.left - c.left) / l,
			y: (d.top - c.top) / l,
			...getDimensions(s)
		};
	});
};
function getBezierEdgeCenter({ sourceX: e, sourceY: s, targetX: c, targetY: l, sourceControlX: u, sourceControlY: d, targetControlX: f, targetControlY: p }) {
	let m = e * .125 + u * .375 + f * .375 + c * .125, h = s * .125 + d * .375 + p * .375 + l * .125;
	return [
		m,
		h,
		Math.abs(m - e),
		Math.abs(h - s)
	];
}
function calculateControlOffset(e, s) {
	return e >= 0 ? .5 * e : s * 25 * Math.sqrt(-e);
}
function getControlWithCurvature({ pos: e, x1: s, y1: c, x2: l, y2: u, c: d }) {
	switch (e) {
		case Position.Left: return [s - calculateControlOffset(s - l, d), c];
		case Position.Right: return [s + calculateControlOffset(l - s, d), c];
		case Position.Top: return [s, c - calculateControlOffset(c - u, d)];
		case Position.Bottom: return [s, c + calculateControlOffset(u - c, d)];
	}
}
function getBezierPath({ sourceX: e, sourceY: s, sourcePosition: c = Position.Bottom, targetX: l, targetY: u, targetPosition: d = Position.Top, curvature: f = .25 }) {
	let [p, m] = getControlWithCurvature({
		pos: c,
		x1: e,
		y1: s,
		x2: l,
		y2: u,
		c: f
	}), [h, g] = getControlWithCurvature({
		pos: d,
		x1: l,
		y1: u,
		x2: e,
		y2: s,
		c: f
	}), [_, v, y, b] = getBezierEdgeCenter({
		sourceX: e,
		sourceY: s,
		targetX: l,
		targetY: u,
		sourceControlX: p,
		sourceControlY: m,
		targetControlX: h,
		targetControlY: g
	});
	return [
		`M${e},${s} C${p},${m} ${h},${g} ${l},${u}`,
		_,
		v,
		y,
		b
	];
}
function getEdgeCenter({ sourceX: e, sourceY: s, targetX: c, targetY: l }) {
	let u = Math.abs(c - e) / 2, d = c < e ? c + u : c - u, f = Math.abs(l - s) / 2;
	return [
		d,
		l < s ? l + f : l - f,
		u,
		f
	];
}
function getElevatedEdgeZIndex({ sourceNode: e, targetNode: s, selected: c = !1, zIndex: l = 0, elevateOnSelect: u = !1, zIndexMode: d = "basic" }) {
	return d === "manual" ? l : (u && c ? l + 1e3 : l) + Math.max(e.parentId || u && e.selected ? e.internals.z : 0, s.parentId || u && s.selected ? s.internals.z : 0);
}
function isEdgeVisible({ sourceNode: e, targetNode: s, width: c, height: l, transform: u }) {
	let d = getBoundsOfBoxes(nodeToBox(e), nodeToBox(s));
	return d.x === d.x2 && (d.x2 += 1), d.y === d.y2 && (d.y2 += 1), getOverlappingArea({
		x: -u[0] / u[2],
		y: -u[1] / u[2],
		width: c / u[2],
		height: l / u[2]
	}, boxToRect(d)) > 0;
}
var getEdgeId = ({ source: e, sourceHandle: s, target: c, targetHandle: l }) => `xy-edge__${e}${s || ""}-${c}${l || ""}`, connectionExists = (e, s) => s.some((s) => s.source === e.source && s.target === e.target && (s.sourceHandle === e.sourceHandle || !s.sourceHandle && !e.sourceHandle) && (s.targetHandle === e.targetHandle || !s.targetHandle && !e.targetHandle)), addEdge = (e, s, c = {}) => {
	if (!e.source || !e.target) return devWarn("006", errorMessages.error006()), s;
	let l = c.getEdgeId || getEdgeId, u;
	return u = isEdgeBase(e) ? { ...e } : {
		...e,
		id: l(e)
	}, connectionExists(u, s) ? s : (u.sourceHandle === null && delete u.sourceHandle, u.targetHandle === null && delete u.targetHandle, s.concat(u));
};
function getStraightPath({ sourceX: e, sourceY: s, targetX: c, targetY: l }) {
	let [u, d, f, p] = getEdgeCenter({
		sourceX: e,
		sourceY: s,
		targetX: c,
		targetY: l
	});
	return [
		`M ${e},${s}L ${c},${l}`,
		u,
		d,
		f,
		p
	];
}
var handleDirections = {
	[Position.Left]: {
		x: -1,
		y: 0
	},
	[Position.Right]: {
		x: 1,
		y: 0
	},
	[Position.Top]: {
		x: 0,
		y: -1
	},
	[Position.Bottom]: {
		x: 0,
		y: 1
	}
}, getDirection = ({ source: e, sourcePosition: s = Position.Bottom, target: c }) => s === Position.Left || s === Position.Right ? e.x < c.x ? {
	x: 1,
	y: 0
} : {
	x: -1,
	y: 0
} : e.y < c.y ? {
	x: 0,
	y: 1
} : {
	x: 0,
	y: -1
}, distance = (e, s) => Math.sqrt((s.x - e.x) ** 2 + (s.y - e.y) ** 2);
function getPoints({ source: e, sourcePosition: s = Position.Bottom, target: c, targetPosition: l = Position.Top, center: u, offset: d, stepPosition: f }) {
	let p = handleDirections[s], m = handleDirections[l], h = {
		x: e.x + p.x * d,
		y: e.y + p.y * d
	}, g = {
		x: c.x + m.x * d,
		y: c.y + m.y * d
	}, _ = getDirection({
		source: h,
		sourcePosition: s,
		target: g
	}), v = _.x === 0 ? "y" : "x", y = _[v], b = [], x, S, C = {
		x: 0,
		y: 0
	}, T = {
		x: 0,
		y: 0
	}, [, , E, D] = getEdgeCenter({
		sourceX: e.x,
		sourceY: e.y,
		targetX: c.x,
		targetY: c.y
	});
	if (p[v] * m[v] === -1) {
		v === "x" ? (x = u.x ?? h.x + (g.x - h.x) * f, S = u.y ?? (h.y + g.y) / 2) : (x = u.x ?? (h.x + g.x) / 2, S = u.y ?? h.y + (g.y - h.y) * f);
		let e = [{
			x,
			y: h.y
		}, {
			x,
			y: g.y
		}], s = [{
			x: h.x,
			y: S
		}, {
			x: g.x,
			y: S
		}];
		b = p[v] === y ? v === "x" ? e : s : v === "x" ? s : e;
	} else {
		let u = [{
			x: h.x,
			y: g.y
		}], f = [{
			x: g.x,
			y: h.y
		}];
		if (b = v === "x" ? p.x === y ? f : u : p.y === y ? u : f, s === l) {
			let s = Math.abs(e[v] - c[v]);
			if (s <= d) {
				let l = Math.min(d - 1, d - s);
				p[v] === y ? C[v] = (h[v] > e[v] ? -1 : 1) * l : T[v] = (g[v] > c[v] ? -1 : 1) * l;
			}
		}
		if (s !== l) {
			let e = v === "x" ? "y" : "x", s = p[v] === m[e], c = h[e] > g[e], l = h[e] < g[e];
			(p[v] === 1 && (!s && c || s && l) || p[v] !== 1 && (!s && l || s && c)) && (b = v === "x" ? u : f);
		}
		let _ = {
			x: h.x + C.x,
			y: h.y + C.y
		}, w = {
			x: g.x + T.x,
			y: g.y + T.y
		};
		Math.max(Math.abs(_.x - b[0].x), Math.abs(w.x - b[0].x)) >= Math.max(Math.abs(_.y - b[0].y), Math.abs(w.y - b[0].y)) ? (x = (_.x + w.x) / 2, S = b[0].y) : (x = b[0].x, S = (_.y + w.y) / 2);
	}
	return [
		[
			e,
			{
				x: h.x + C.x,
				y: h.y + C.y
			},
			...b,
			{
				x: g.x + T.x,
				y: g.y + T.y
			},
			c
		],
		x,
		S,
		E,
		D
	];
}
function getBend(e, s, c, l) {
	let u = Math.min(distance(e, s) / 2, distance(s, c) / 2, l), { x: d, y: f } = s;
	if (e.x === d && d === c.x || e.y === f && f === c.y) return `L${d} ${f}`;
	if (e.y === f) {
		let s = e.x < c.x ? -1 : 1, l = e.y < c.y ? 1 : -1;
		return `L ${d + u * s},${f}Q ${d},${f} ${d},${f + u * l}`;
	}
	let p = e.x < c.x ? 1 : -1;
	return `L ${d},${f + u * (e.y < c.y ? -1 : 1)}Q ${d},${f} ${d + u * p},${f}`;
}
function getSmoothStepPath({ sourceX: e, sourceY: s, sourcePosition: c = Position.Bottom, targetX: l, targetY: u, targetPosition: d = Position.Top, borderRadius: f = 5, centerX: p, centerY: m, offset: h = 20, stepPosition: g = .5 }) {
	let [_, v, y, b, x] = getPoints({
		source: {
			x: e,
			y: s
		},
		sourcePosition: c,
		target: {
			x: l,
			y: u
		},
		targetPosition: d,
		center: {
			x: p,
			y: m
		},
		offset: h,
		stepPosition: g
	});
	return [
		_.reduce((e, s, c) => {
			let l = "";
			return l = c > 0 && c < _.length - 1 ? getBend(_[c - 1], s, _[c + 1], f) : `${c === 0 ? "M" : "L"}${s.x} ${s.y}`, e += l, e;
		}, ""),
		v,
		y,
		b,
		x
	];
}
function isNodeInitialized(e) {
	return e && !!(e.internals.handleBounds || e.handles?.length) && !!(e.measured.width || e.width || e.initialWidth);
}
function getEdgePosition(e) {
	let { sourceNode: s, targetNode: c } = e;
	if (!isNodeInitialized(s) || !isNodeInitialized(c)) return null;
	let l = s.internals.handleBounds || toHandleBounds(s.handles), u = c.internals.handleBounds || toHandleBounds(c.handles), d = getHandle$1(l?.source ?? [], e.sourceHandle), f = getHandle$1(e.connectionMode === ConnectionMode.Strict ? u?.target ?? [] : (u?.target ?? []).concat(u?.source ?? []), e.targetHandle);
	if (!d || !f) return e.onError?.("008", errorMessages.error008(d ? "target" : "source", {
		id: e.id,
		sourceHandle: e.sourceHandle,
		targetHandle: e.targetHandle
	})), null;
	let p = d?.position || Position.Bottom, h = f?.position || Position.Top, g = getHandlePosition(s, d, p), _ = getHandlePosition(c, f, h);
	return {
		sourceX: g.x,
		sourceY: g.y,
		targetX: _.x,
		targetY: _.y,
		sourcePosition: p,
		targetPosition: h
	};
}
function toHandleBounds(e) {
	if (!e) return null;
	let s = [], c = [];
	for (let l of e) l.width = l.width ?? 1, l.height = l.height ?? 1, l.type === "source" ? s.push(l) : l.type === "target" && c.push(l);
	return {
		source: s,
		target: c
	};
}
function getHandlePosition(e, s, c = Position.Left, l = !1) {
	let u = (s?.x ?? 0) + e.internals.positionAbsolute.x, d = (s?.y ?? 0) + e.internals.positionAbsolute.y, { width: f, height: p } = s ?? getNodeDimensions(e);
	if (l) return {
		x: u + f / 2,
		y: d + p / 2
	};
	switch (s?.position ?? c) {
		case Position.Top: return {
			x: u + f / 2,
			y: d
		};
		case Position.Right: return {
			x: u + f,
			y: d + p / 2
		};
		case Position.Bottom: return {
			x: u + f / 2,
			y: d + p
		};
		case Position.Left: return {
			x: u,
			y: d + p / 2
		};
	}
}
function getHandle$1(e, s) {
	return e && (s ? e.find((e) => e.id === s) : e[0]) || null;
}
function getMarkerId(e, s) {
	return e ? typeof e == "string" ? e : `${s ? `${s}__` : ""}${Object.keys(e).sort().map((s) => `${s}=${e[s]}`).join("&")}` : "";
}
function createMarkerIds(e, { id: s, defaultColor: c, defaultMarkerStart: l, defaultMarkerEnd: u }) {
	let d = /* @__PURE__ */ new Set();
	return e.reduce((e, f) => ([f.markerStart || l, f.markerEnd || u].forEach((l) => {
		if (l && typeof l == "object") {
			let u = getMarkerId(l, s);
			d.has(u) || (e.push({
				id: u,
				color: l.color || c,
				...l
			}), d.add(u));
		}
	}), e), []).sort((e, s) => e.id.localeCompare(s.id));
}
var SELECTED_NODE_Z = 1e3, ROOT_PARENT_Z_INCREMENT = 10, defaultOptions = {
	nodeOrigin: [0, 0],
	nodeExtent: infiniteExtent,
	elevateNodesOnSelect: !0,
	zIndexMode: "basic",
	defaults: {}
}, adoptUserNodesDefaultOptions = {
	...defaultOptions,
	checkEquality: !0
};
function mergeObjects(e, s) {
	let c = { ...e };
	for (let e in s) s[e] !== void 0 && (c[e] = s[e]);
	return c;
}
function updateAbsolutePositions(e, s, c) {
	let l = mergeObjects(defaultOptions, c);
	for (let c of e.values()) if (c.parentId) updateChildNode(c, e, s, l);
	else {
		let e = clampPosition(getNodePositionWithOrigin(c, l.nodeOrigin), isCoordinateExtent(c.extent) ? c.extent : l.nodeExtent, getNodeDimensions(c));
		c.internals.positionAbsolute = e;
	}
}
function parseHandles(e, s) {
	if (!e.handles) return e.measured ? s?.internals.handleBounds : void 0;
	let c = [], l = [];
	for (let s of e.handles) {
		let u = {
			id: s.id,
			width: s.width ?? 1,
			height: s.height ?? 1,
			nodeId: e.id,
			x: s.x,
			y: s.y,
			position: s.position,
			type: s.type
		};
		s.type === "source" ? c.push(u) : s.type === "target" && l.push(u);
	}
	return {
		source: c,
		target: l
	};
}
function isManualZIndexMode(e) {
	return e === "manual";
}
function adoptUserNodes(e, s, c, l = {}) {
	let u = mergeObjects(adoptUserNodesDefaultOptions, l), d = { i: 0 }, f = new Map(s), p = u?.elevateNodesOnSelect && !isManualZIndexMode(u.zIndexMode) ? SELECTED_NODE_Z : 0, m = e.length > 0;
	s.clear(), c.clear();
	for (let h of e) {
		let e = f.get(h.id);
		if (u.checkEquality && h === e?.internals.userNode) s.set(h.id, e);
		else {
			let c = clampPosition(getNodePositionWithOrigin(h, u.nodeOrigin), isCoordinateExtent(h.extent) ? h.extent : u.nodeExtent, getNodeDimensions(h));
			e = {
				...u.defaults,
				...h,
				measured: {
					width: h.measured?.width,
					height: h.measured?.height
				},
				internals: {
					positionAbsolute: c,
					handleBounds: parseHandles(h, e),
					z: calculateZ(h, p, u.zIndexMode),
					userNode: h
				}
			}, s.set(h.id, e);
		}
		(e.measured === void 0 || e.measured.width === void 0 || e.measured.height === void 0) && !e.hidden && (m = !1), h.parentId && updateChildNode(e, s, c, l, d);
	}
	return m;
}
function updateParentLookup(e, s) {
	if (!e.parentId) return;
	let c = s.get(e.parentId);
	c ? c.set(e.id, e) : s.set(e.parentId, new Map([[e.id, e]]));
}
function updateChildNode(e, s, c, l, u) {
	let { elevateNodesOnSelect: d, nodeOrigin: f, nodeExtent: p, zIndexMode: m } = mergeObjects(defaultOptions, l), h = e.parentId, g = s.get(h);
	if (!g) {
		console.warn(`Parent node ${h} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);
		return;
	}
	updateParentLookup(e, c), u && !g.parentId && g.internals.rootParentIndex === void 0 && m === "auto" && (g.internals.rootParentIndex = ++u.i, g.internals.z = g.internals.z + u.i * ROOT_PARENT_Z_INCREMENT), u && g.internals.rootParentIndex !== void 0 && (u.i = g.internals.rootParentIndex);
	let { x: _, y: v, z: y } = calculateChildXYZ(e, g, f, p, d && !isManualZIndexMode(m) ? SELECTED_NODE_Z : 0, m), { positionAbsolute: b } = e.internals, x = _ !== b.x || v !== b.y;
	(x || y !== e.internals.z) && s.set(e.id, {
		...e,
		internals: {
			...e.internals,
			positionAbsolute: x ? {
				x: _,
				y: v
			} : b,
			z: y
		}
	});
}
function calculateZ(e, s, c) {
	let l = isNumeric(e.zIndex) ? e.zIndex : 0;
	return isManualZIndexMode(c) ? l : l + (e.selected ? s : 0);
}
function calculateChildXYZ(e, s, c, l, u, d) {
	let { x: f, y: p } = s.internals.positionAbsolute, m = getNodeDimensions(e), h = getNodePositionWithOrigin(e, c), g = isCoordinateExtent(e.extent) ? clampPosition(h, e.extent, m) : h, _ = clampPosition({
		x: f + g.x,
		y: p + g.y
	}, l, m);
	e.extent === "parent" && (_ = clampPositionToParent(_, m, s));
	let v = calculateZ(e, u, d), y = s.internals.z ?? 0;
	return {
		x: _.x,
		y: _.y,
		z: y >= v ? y + 1 : v
	};
}
function handleExpandParent(e, s, c, l = [0, 0]) {
	let u = [], d = /* @__PURE__ */ new Map();
	for (let c of e) {
		let e = s.get(c.parentId);
		if (!e) continue;
		let l = getBoundsOfRects(d.get(c.parentId)?.expandedRect ?? nodeToRect(e), c.rect);
		d.set(c.parentId, {
			expandedRect: l,
			parent: e
		});
	}
	return d.size > 0 && d.forEach(({ expandedRect: s, parent: d }, f) => {
		let p = d.internals.positionAbsolute, m = getNodeDimensions(d), h = d.origin ?? l, g = s.x < p.x ? Math.round(Math.abs(p.x - s.x)) : 0, _ = s.y < p.y ? Math.round(Math.abs(p.y - s.y)) : 0, v = Math.max(m.width, Math.round(s.width)), y = Math.max(m.height, Math.round(s.height)), b = (v - m.width) * h[0], x = (y - m.height) * h[1];
		(g > 0 || _ > 0 || b || x) && (u.push({
			id: f,
			type: "position",
			position: {
				x: d.position.x - g + b,
				y: d.position.y - _ + x
			}
		}), c.get(f)?.forEach((s) => {
			e.some((e) => e.id === s.id) || u.push({
				id: s.id,
				type: "position",
				position: {
					x: s.position.x + g,
					y: s.position.y + _
				}
			});
		})), (m.width < s.width || m.height < s.height || g || _) && u.push({
			id: f,
			type: "dimensions",
			setAttributes: !0,
			dimensions: {
				width: v + (g ? h[0] * g - b : 0),
				height: y + (_ ? h[1] * _ - x : 0)
			}
		});
	}), u;
}
function updateNodeInternals(e, s, c, l, u, d, f) {
	let p = l?.querySelector(".xyflow__viewport"), m = !1;
	if (!p) return {
		changes: [],
		updatedInternals: m
	};
	let h = [], g = window.getComputedStyle(p), { m22: _ } = new window.DOMMatrixReadOnly(g.transform), v = [];
	for (let l of e.values()) {
		let e = s.get(l.id);
		if (!e) continue;
		if (e.hidden) {
			s.set(e.id, {
				...e,
				internals: {
					...e.internals,
					handleBounds: void 0
				}
			}), m = !0;
			continue;
		}
		let p = getDimensions(l.nodeElement), g = e.measured.width !== p.width || e.measured.height !== p.height;
		if (p.width && p.height && (g || !e.internals.handleBounds || l.force)) {
			let y = l.nodeElement.getBoundingClientRect(), b = isCoordinateExtent(e.extent) ? e.extent : d, { positionAbsolute: x } = e.internals;
			e.parentId && e.extent === "parent" ? x = clampPositionToParent(x, p, s.get(e.parentId)) : b && (x = clampPosition(x, b, p));
			let S = {
				...e,
				measured: p,
				internals: {
					...e.internals,
					positionAbsolute: x,
					handleBounds: {
						source: getHandleBounds("source", l.nodeElement, y, _, e.id),
						target: getHandleBounds("target", l.nodeElement, y, _, e.id)
					}
				}
			};
			s.set(e.id, S), e.parentId && updateChildNode(S, s, c, {
				nodeOrigin: u,
				zIndexMode: f
			}), m = !0, g && (h.push({
				id: e.id,
				type: "dimensions",
				dimensions: p
			}), e.expandParent && e.parentId && v.push({
				id: e.id,
				parentId: e.parentId,
				rect: nodeToRect(S, u)
			}));
		}
	}
	if (v.length > 0) {
		let e = handleExpandParent(v, s, c, u);
		h.push(...e);
	}
	return {
		changes: h,
		updatedInternals: m
	};
}
async function panBy({ delta: e, panZoom: s, transform: c, translateExtent: l, width: u, height: d }) {
	if (!s || !e.x && !e.y) return Promise.resolve(!1);
	let f = await s.setViewportConstrained({
		x: c[0] + e.x,
		y: c[1] + e.y,
		zoom: c[2]
	}, [[0, 0], [u, d]], l), p = !!f && (f.x !== c[0] || f.y !== c[1] || f.k !== c[2]);
	return Promise.resolve(p);
}
function addConnectionToLookup(e, s, c, l, u, d) {
	let f = u, p = l.get(f) || /* @__PURE__ */ new Map();
	l.set(f, p.set(c, s)), f = `${u}-${e}`;
	let m = l.get(f) || /* @__PURE__ */ new Map();
	if (l.set(f, m.set(c, s)), d) {
		f = `${u}-${e}-${d}`;
		let p = l.get(f) || /* @__PURE__ */ new Map();
		l.set(f, p.set(c, s));
	}
}
function updateConnectionLookup(e, s, c) {
	e.clear(), s.clear();
	for (let l of c) {
		let { source: c, target: u, sourceHandle: d = null, targetHandle: f = null } = l, p = {
			edgeId: l.id,
			source: c,
			target: u,
			sourceHandle: d,
			targetHandle: f
		}, m = `${c}-${d}--${u}-${f}`;
		addConnectionToLookup("source", p, `${u}-${f}--${c}-${d}`, e, c, d), addConnectionToLookup("target", p, m, e, u, f), s.set(l.id, l);
	}
}
function isParentSelected(e, s) {
	if (!e.parentId) return !1;
	let c = s.get(e.parentId);
	return c ? c.selected ? !0 : isParentSelected(c, s) : !1;
}
function hasSelector(e, s, c) {
	let l = e;
	do {
		if (l?.matches?.(s)) return !0;
		if (l === c) return !1;
		l = l?.parentElement;
	} while (l);
	return !1;
}
function getDragItems(e, s, c, l) {
	let u = /* @__PURE__ */ new Map();
	for (let [d, f] of e) if ((f.selected || f.id === l) && (!f.parentId || !isParentSelected(f, e)) && (f.draggable || s && f.draggable === void 0)) {
		let s = e.get(d);
		s && u.set(d, {
			id: d,
			position: s.position || {
				x: 0,
				y: 0
			},
			distance: {
				x: c.x - s.internals.positionAbsolute.x,
				y: c.y - s.internals.positionAbsolute.y
			},
			extent: s.extent,
			parentId: s.parentId,
			origin: s.origin,
			expandParent: s.expandParent,
			internals: { positionAbsolute: s.internals.positionAbsolute || {
				x: 0,
				y: 0
			} },
			measured: {
				width: s.measured.width ?? 0,
				height: s.measured.height ?? 0
			}
		});
	}
	return u;
}
function getEventHandlerParams({ nodeId: e, dragItems: s, nodeLookup: c, dragging: l = !0 }) {
	let u = [];
	for (let [e, d] of s) {
		let s = c.get(e)?.internals.userNode;
		s && u.push({
			...s,
			position: d.position,
			dragging: l
		});
	}
	if (!e) return [u[0], u];
	let d = c.get(e)?.internals.userNode;
	return [d ? {
		...d,
		position: s.get(e)?.position || d.position,
		dragging: l
	} : u[0], u];
}
function calculateSnapOffset({ dragItems: e, snapGrid: s, x: c, y: l }) {
	let u = e.values().next().value;
	if (!u) return null;
	let d = {
		x: c - u.distance.x,
		y: l - u.distance.y
	}, f = snapPosition(d, s);
	return {
		x: f.x - d.x,
		y: f.y - d.y
	};
}
function XYDrag({ onNodeMouseDown: s, getStoreItems: l, onDragStart: u, onDrag: d, onDragStop: f }) {
	let p = {
		x: null,
		y: null
	}, m = 0, h = /* @__PURE__ */ new Map(), g = !1, _ = {
		x: 0,
		y: 0
	}, v = null, y = !1, b = null, x = !1, S = !1, C = null;
	function w({ noDragClassName: w, handleSelector: T, domNode: E, isSelectable: D, nodeId: O, nodeClickDistance: k = 0 }) {
		b = select_default(E);
		function A({ x: e, y: s }) {
			let { nodeLookup: c, nodeExtent: u, snapGrid: f, snapToGrid: m, nodeOrigin: g, onNodeDrag: _, onSelectionDrag: v, onError: y, updateNodePositions: b } = l();
			p = {
				x: e,
				y: s
			};
			let x = !1, w = h.size > 1, T = w && u ? rectToBox(getInternalNodesBounds(h)) : null, E = w && m ? calculateSnapOffset({
				dragItems: h,
				snapGrid: f,
				x: e,
				y: s
			}) : null;
			for (let [l, d] of h) {
				if (!c.has(l)) continue;
				let p = {
					x: e - d.distance.x,
					y: s - d.distance.y
				};
				m && (p = E ? {
					x: Math.round(p.x + E.x),
					y: Math.round(p.y + E.y)
				} : snapPosition(p, f));
				let h = null;
				if (w && u && !d.extent && T) {
					let { positionAbsolute: e } = d.internals, s = e.x - T.x + u[0][0], c = e.x + d.measured.width - T.x2 + u[1][0], l = e.y - T.y + u[0][1], f = e.y + d.measured.height - T.y2 + u[1][1];
					h = [[s, l], [c, f]];
				}
				let { position: _, positionAbsolute: v } = calculateNodePosition({
					nodeId: l,
					nextPosition: p,
					nodeLookup: c,
					nodeExtent: h || u,
					nodeOrigin: g,
					onError: y
				});
				x = x || d.position.x !== _.x || d.position.y !== _.y, d.position = _, d.internals.positionAbsolute = v;
			}
			if (S ||= x, x && (b(h, !0), C && (d || _ || !O && v))) {
				let [e, s] = getEventHandlerParams({
					nodeId: O,
					dragItems: h,
					nodeLookup: c
				});
				d?.(C, h, e, s), _?.(C, e, s), O || v?.(C, s);
			}
		}
		async function j() {
			if (!v) return;
			let { transform: e, panBy: s, autoPanSpeed: c, autoPanOnNodeDrag: u } = l();
			if (!u) {
				g = !1, cancelAnimationFrame(m);
				return;
			}
			let [d, f] = calcAutoPan(_, v, c);
			(d !== 0 || f !== 0) && (p.x = (p.x ?? 0) - d / e[2], p.y = (p.y ?? 0) - f / e[2], await s({
				x: d,
				y: f
			}) && A(p)), m = requestAnimationFrame(j);
		}
		function N(e) {
			let { nodeLookup: c, multiSelectionActive: d, nodesDraggable: f, transform: m, snapGrid: g, snapToGrid: _, selectNodesOnDrag: b, onNodeDragStart: x, onSelectionDragStart: S, unselectNodesAndEdges: C } = l();
			y = !0, (!b || !D) && !d && O && (c.get(O)?.selected || C()), D && b && O && s?.(O);
			let w = getPointerPosition(e.sourceEvent, {
				transform: m,
				snapGrid: g,
				snapToGrid: _,
				containerBounds: v
			});
			if (p = w, h = getDragItems(c, f, w, O), h.size > 0 && (u || x || !O && S)) {
				let [s, l] = getEventHandlerParams({
					nodeId: O,
					dragItems: h,
					nodeLookup: c
				});
				u?.(e.sourceEvent, h, s, l), x?.(e.sourceEvent, s, l), O || S?.(e.sourceEvent, l);
			}
		}
		let P = drag_default().clickDistance(k).on("start", (e) => {
			let { domNode: s, nodeDragThreshold: c, transform: u, snapGrid: d, snapToGrid: f } = l();
			v = s?.getBoundingClientRect() || null, x = !1, S = !1, C = e.sourceEvent, c === 0 && N(e), p = getPointerPosition(e.sourceEvent, {
				transform: u,
				snapGrid: d,
				snapToGrid: f,
				containerBounds: v
			}), _ = getEventPosition(e.sourceEvent, v);
		}).on("drag", (e) => {
			let { autoPanOnNodeDrag: s, transform: c, snapGrid: u, snapToGrid: d, nodeDragThreshold: f, nodeLookup: m } = l(), b = getPointerPosition(e.sourceEvent, {
				transform: c,
				snapGrid: u,
				snapToGrid: d,
				containerBounds: v
			});
			if (C = e.sourceEvent, (e.sourceEvent.type === "touchmove" && e.sourceEvent.touches.length > 1 || O && !m.has(O)) && (x = !0), !x) {
				if (!g && s && y && (g = !0, j()), !y) {
					let s = getEventPosition(e.sourceEvent, v), c = s.x - _.x, l = s.y - _.y;
					Math.sqrt(c * c + l * l) > f && N(e);
				}
				(p.x !== b.xSnapped || p.y !== b.ySnapped) && h && y && (_ = getEventPosition(e.sourceEvent, v), A(b));
			}
		}).on("end", (e) => {
			if (!(!y || x) && (g = !1, y = !1, cancelAnimationFrame(m), h.size > 0)) {
				let { nodeLookup: s, updateNodePositions: c, onNodeDragStop: u, onSelectionDragStop: d } = l();
				if (S &&= (c(h, !1), !1), f || u || !O && d) {
					let [c, l] = getEventHandlerParams({
						nodeId: O,
						dragItems: h,
						nodeLookup: s,
						dragging: !1
					});
					f?.(e.sourceEvent, h, c, l), u?.(e.sourceEvent, c, l), O || d?.(e.sourceEvent, l);
				}
			}
		}).filter((e) => {
			let s = e.target;
			return !e.button && (!w || !hasSelector(s, `.${w}`, E)) && (!T || hasSelector(s, T, E));
		});
		b.call(P);
	}
	function T() {
		b?.on(".drag", null);
	}
	return {
		update: w,
		destroy: T
	};
}
function getNodesWithinDistance(e, s, c) {
	let l = [], u = {
		x: e.x - c,
		y: e.y - c,
		width: c * 2,
		height: c * 2
	};
	for (let e of s.values()) getOverlappingArea(u, nodeToRect(e)) > 0 && l.push(e);
	return l;
}
var ADDITIONAL_DISTANCE = 250;
function getClosestHandle(e, s, c, l) {
	let u = [], d = Infinity, f = getNodesWithinDistance(e, c, s + ADDITIONAL_DISTANCE);
	for (let c of f) {
		let f = [...c.internals.handleBounds?.source ?? [], ...c.internals.handleBounds?.target ?? []];
		for (let p of f) {
			if (l.nodeId === p.nodeId && l.type === p.type && l.id === p.id) continue;
			let { x: f, y: m } = getHandlePosition(c, p, p.position, !0), h = Math.sqrt((f - e.x) ** 2 + (m - e.y) ** 2);
			h > s || (h < d ? (u = [{
				...p,
				x: f,
				y: m
			}], d = h) : h === d && u.push({
				...p,
				x: f,
				y: m
			}));
		}
	}
	if (!u.length) return null;
	if (u.length > 1) {
		let e = l.type === "source" ? "target" : "source";
		return u.find((s) => s.type === e) ?? u[0];
	}
	return u[0];
}
function getHandle(e, s, c, l, u, d = !1) {
	let f = l.get(e);
	if (!f) return null;
	let p = u === "strict" ? f.internals.handleBounds?.[s] : [...f.internals.handleBounds?.source ?? [], ...f.internals.handleBounds?.target ?? []], m = (c ? p?.find((e) => e.id === c) : p?.[0]) ?? null;
	return m && d ? {
		...m,
		...getHandlePosition(f, m, m.position, !0)
	} : m;
}
function getHandleType(e, s) {
	return e || (s?.classList.contains("target") ? "target" : s?.classList.contains("source") ? "source" : null);
}
function isConnectionValid(e, s) {
	let c = null;
	return s ? c = !0 : e && !s && (c = !1), c;
}
var alwaysValid = () => !0;
function onPointerDown(e, { connectionMode: s, connectionRadius: c, handleId: l, nodeId: u, edgeUpdaterType: d, isTarget: f, domNode: p, nodeLookup: m, lib: h, autoPanOnConnect: g, flowId: _, panBy: v, cancelConnection: y, onConnectStart: b, onConnect: x, onConnectEnd: S, isValidConnection: C = alwaysValid, onReconnectEnd: E, updateConnection: D, getTransform: O, getFromHandle: k, autoPanSpeed: A, dragThreshold: j = 1, handleDomNode: M }) {
	let N = getHostForElement(e.target), P = 0, F, { x: I, y: L } = getEventPosition(e), R = getHandleType(d, M), z = p?.getBoundingClientRect(), B = !1;
	if (!z || !R) return;
	let V = getHandle(u, R, l, m, s);
	if (!V) return;
	let H = getEventPosition(e, z), U = !1, W = null, G = !1, K = null;
	function q() {
		if (!g || !z) return;
		let [e, s] = calcAutoPan(H, z, A);
		v({
			x: e,
			y: s
		}), P = requestAnimationFrame(q);
	}
	let J = {
		...V,
		nodeId: u,
		type: R,
		position: V.position
	}, Y = m.get(u), X = {
		inProgress: !0,
		isValid: null,
		from: getHandlePosition(Y, J, Position.Left, !0),
		fromHandle: J,
		fromPosition: J.position,
		fromNode: Y,
		to: H,
		toHandle: null,
		toPosition: oppositePosition[J.position],
		toNode: null,
		pointer: H
	};
	function Z() {
		B = !0, D(X), b?.(e, {
			nodeId: u,
			handleId: l,
			handleType: R
		});
	}
	j === 0 && Z();
	function Q(e) {
		if (!B) {
			let { x: s, y: c } = getEventPosition(e), l = s - I, u = c - L;
			if (!(l * l + u * u > j * j)) return;
			Z();
		}
		if (!k() || !J) {
			$(e);
			return;
		}
		let d = O();
		H = getEventPosition(e, z), F = getClosestHandle(pointToRendererPoint(H, d, !1, [1, 1]), c, m, J), U ||= (q(), !0);
		let p = isValidHandle(e, {
			handle: F,
			connectionMode: s,
			fromNodeId: u,
			fromHandleId: l,
			fromType: f ? "target" : "source",
			isValidConnection: C,
			doc: N,
			lib: h,
			flowId: _,
			nodeLookup: m
		});
		K = p.handleDomNode, W = p.connection, G = isConnectionValid(!!F, p.isValid);
		let g = m.get(u), v = g ? getHandlePosition(g, J, Position.Left, !0) : X.from, y = {
			...X,
			from: v,
			isValid: G,
			to: p.toHandle && G ? rendererPointToPoint({
				x: p.toHandle.x,
				y: p.toHandle.y
			}, d) : H,
			toHandle: p.toHandle,
			toPosition: G && p.toHandle ? p.toHandle.position : oppositePosition[J.position],
			toNode: p.toHandle ? m.get(p.toHandle.nodeId) : null,
			pointer: H
		};
		D(y), X = y;
	}
	function $(e) {
		if (!("touches" in e && e.touches.length > 0)) {
			if (B) {
				(F || K) && W && G && x?.(W);
				let { inProgress: s, ...c } = X, l = {
					...c,
					toPosition: X.toHandle ? X.toPosition : null
				};
				S?.(e, l), d && E?.(e, l);
			}
			y(), cancelAnimationFrame(P), U = !1, G = !1, W = null, K = null, N.removeEventListener("mousemove", Q), N.removeEventListener("mouseup", $), N.removeEventListener("touchmove", Q), N.removeEventListener("touchend", $);
		}
	}
	N.addEventListener("mousemove", Q), N.addEventListener("mouseup", $), N.addEventListener("touchmove", Q), N.addEventListener("touchend", $);
}
function isValidHandle(e, { handle: s, connectionMode: c, fromNodeId: l, fromHandleId: u, fromType: d, doc: f, lib: p, flowId: m, isValidConnection: h = alwaysValid, nodeLookup: g }) {
	let _ = d === "target", y = s ? f.querySelector(`.${p}-flow__handle[data-id="${m}-${s?.nodeId}-${s?.id}-${s?.type}"]`) : null, { x: b, y: x } = getEventPosition(e), S = f.elementFromPoint(b, x), C = S?.classList.contains(`${p}-flow__handle`) ? S : y, w = {
		handleDomNode: C,
		isValid: !1,
		connection: null,
		toHandle: null
	};
	if (C) {
		let e = getHandleType(void 0, C), s = C.getAttribute("data-nodeid"), d = C.getAttribute("data-handleid"), f = C.classList.contains("connectable"), p = C.classList.contains("connectableend");
		if (!s || !e) return w;
		let m = {
			source: _ ? s : l,
			sourceHandle: _ ? d : u,
			target: _ ? l : s,
			targetHandle: _ ? u : d
		};
		w.connection = m, w.isValid = f && p && (c === ConnectionMode.Strict ? _ && e === "source" || !_ && e === "target" : s !== l || d !== u) && h(m), w.toHandle = getHandle(s, e, d, g, c, !0);
	}
	return w;
}
var XYHandle = {
	onPointerDown,
	isValid: isValidHandle
};
function XYMinimap({ domNode: c, panZoom: l, getTransform: u, getViewScale: d }) {
	let f = select_default(c);
	function m({ translateExtent: e, width: s, height: c, zoomStep: m = 1, pannable: h = !0, zoomable: g = !0, inversePan: _ = !1 }) {
		let v = (e) => {
			if (e.sourceEvent.type !== "wheel" || !l) return;
			let s = u(), c = e.sourceEvent.ctrlKey && isMacOs() ? 10 : 1, d = -e.sourceEvent.deltaY * (e.sourceEvent.deltaMode === 1 ? .05 : e.sourceEvent.deltaMode ? 1 : .002) * m, f = s[2] * 2 ** (d * c);
			l.scaleTo(f);
		}, y = [0, 0], b = zoom_default().on("start", (e) => {
			(e.sourceEvent.type === "mousedown" || e.sourceEvent.type === "touchstart") && (y = [e.sourceEvent.clientX ?? e.sourceEvent.touches[0].clientX, e.sourceEvent.clientY ?? e.sourceEvent.touches[0].clientY]);
		}).on("zoom", h ? (f) => {
			let p = u();
			if (f.sourceEvent.type !== "mousemove" && f.sourceEvent.type !== "touchmove" || !l) return;
			let m = [f.sourceEvent.clientX ?? f.sourceEvent.touches[0].clientX, f.sourceEvent.clientY ?? f.sourceEvent.touches[0].clientY], h = [m[0] - y[0], m[1] - y[1]];
			y = m;
			let g = d() * Math.max(p[2], Math.log(p[2])) * (_ ? -1 : 1), v = {
				x: p[0] - h[0] * g,
				y: p[1] - h[1] * g
			}, b = [[0, 0], [s, c]];
			l.setViewportConstrained({
				x: v.x,
				y: v.y,
				zoom: p[2]
			}, b, e);
		} : null).on("zoom.wheel", g ? v : null);
		f.call(b, {});
	}
	function h() {
		f.on("zoom", null);
	}
	return {
		update: m,
		destroy: h,
		pointer: pointer_default
	};
}
var transformToViewport = (e) => ({
	x: e.x,
	y: e.y,
	zoom: e.k
}), viewportToTransform = ({ x: e, y: s, zoom: c }) => identity.translate(e, s).scale(c), isWrappedWithClass = (e, s) => e.target.closest(`.${s}`), isRightClickPan = (e, s) => s === 2 && Array.isArray(e) && e.includes(2), defaultEase = (e) => ((e *= 2) <= 1 ? e * e * e : (e -= 2) * e * e + 2) / 2, getD3Transition = (e, s = 0, c = defaultEase, l = () => {}) => {
	let u = typeof s == "number" && s > 0;
	return u || l(), u ? e.transition().duration(s).ease(c).on("end", l) : e;
}, wheelDelta = (e) => {
	let s = e.ctrlKey && isMacOs() ? 10 : 1;
	return -e.deltaY * (e.deltaMode === 1 ? .05 : e.deltaMode ? 1 : .002) * s;
};
function createPanOnScrollHandler({ zoomPanValues: e, noWheelClassName: c, d3Selection: l, d3Zoom: u, panOnScrollMode: d, panOnScrollSpeed: f, zoomOnPinch: p, onPanZoomStart: m, onPanZoom: h, onPanZoomEnd: g }) {
	return (_) => {
		if (isWrappedWithClass(_, c)) return _.ctrlKey && _.preventDefault(), !1;
		_.preventDefault(), _.stopImmediatePropagation();
		let v = l.property("__zoom").k || 1;
		if (_.ctrlKey && p) {
			let e = pointer_default(_), c = v * 2 ** wheelDelta(_);
			u.scaleTo(l, c, e, _);
			return;
		}
		let b = _.deltaMode === 1 ? 20 : 1, x = d === PanOnScrollMode.Vertical ? 0 : _.deltaX * b, S = d === PanOnScrollMode.Horizontal ? 0 : _.deltaY * b;
		!isMacOs() && _.shiftKey && d !== PanOnScrollMode.Vertical && (x = _.deltaY * b, S = 0), u.translateBy(l, -(x / v) * f, -(S / v) * f, { internal: !0 });
		let C = transformToViewport(l.property("__zoom"));
		clearTimeout(e.panScrollTimeout), e.isPanScrolling ? (h?.(_, C), e.panScrollTimeout = setTimeout(() => {
			g?.(_, C), e.isPanScrolling = !1;
		}, 150)) : (e.isPanScrolling = !0, m?.(_, C));
	};
}
function createZoomOnScrollHandler({ noWheelClassName: e, preventScrolling: s, d3ZoomHandler: c }) {
	return function(l, u) {
		let d = l.type === "wheel", f = !s && d && !l.ctrlKey, p = isWrappedWithClass(l, e);
		if (l.ctrlKey && d && p && l.preventDefault(), f || p) return null;
		l.preventDefault(), c.call(this, l, u);
	};
}
function createPanZoomStartHandler({ zoomPanValues: e, onDraggingChange: s, onPanZoomStart: c }) {
	return (l) => {
		if (l.sourceEvent?.internal) return;
		let u = transformToViewport(l.transform);
		e.mouseButton = l.sourceEvent?.button || 0, e.isZoomingOrPanning = !0, e.prevViewport = u, l.sourceEvent?.type === "mousedown" && s(!0), c && c?.(l.sourceEvent, u);
	};
}
function createPanZoomHandler({ zoomPanValues: e, panOnDrag: s, onPaneContextMenu: c, onTransformChange: l, onPanZoom: u }) {
	return (d) => {
		e.usedRightMouseButton = !!(c && isRightClickPan(s, e.mouseButton ?? 0)), d.sourceEvent?.sync || l([
			d.transform.x,
			d.transform.y,
			d.transform.k
		]), u && !d.sourceEvent?.internal && u?.(d.sourceEvent, transformToViewport(d.transform));
	};
}
function createPanZoomEndHandler({ zoomPanValues: e, panOnDrag: s, panOnScroll: c, onDraggingChange: l, onPanZoomEnd: u, onPaneContextMenu: d }) {
	return (f) => {
		if (!f.sourceEvent?.internal && (e.isZoomingOrPanning = !1, d && isRightClickPan(s, e.mouseButton ?? 0) && !e.usedRightMouseButton && f.sourceEvent && d(f.sourceEvent), e.usedRightMouseButton = !1, l(!1), u)) {
			let s = transformToViewport(f.transform);
			e.prevViewport = s, clearTimeout(e.timerId), e.timerId = setTimeout(() => {
				u?.(f.sourceEvent, s);
			}, c ? 150 : 0);
		}
	};
}
function createFilter({ zoomActivationKeyPressed: e, zoomOnScroll: s, zoomOnPinch: c, panOnDrag: l, panOnScroll: u, zoomOnDoubleClick: d, userSelectionActive: f, noWheelClassName: p, noPanClassName: m, lib: h, connectionInProgress: g }) {
	return (_) => {
		let v = e || s, y = c && _.ctrlKey, b = _.type === "wheel";
		if (_.button === 1 && _.type === "mousedown" && (isWrappedWithClass(_, `${h}-flow__node`) || isWrappedWithClass(_, `${h}-flow__edge`))) return !0;
		if (!l && !v && !u && !d && !c || f || g && !b || isWrappedWithClass(_, p) && b || isWrappedWithClass(_, m) && (!b || u && b && !e) || !c && _.ctrlKey && b) return !1;
		if (!c && _.type === "touchstart" && _.touches?.length > 1) return _.preventDefault(), !1;
		if (!v && !u && !y && b || !l && (_.type === "mousedown" || _.type === "touchstart") || Array.isArray(l) && !l.includes(_.button) && _.type === "mousedown") return !1;
		let x = Array.isArray(l) && l.includes(_.button) || !_.button || _.button <= 1;
		return (!_.ctrlKey || b) && x;
	};
}
function XYPanZoom({ domNode: s, minZoom: c, maxZoom: f, translateExtent: m, viewport: h, onPanZoom: g, onPanZoomStart: _, onPanZoomEnd: v, onDraggingChange: y }) {
	let b = {
		isZoomingOrPanning: !1,
		usedRightMouseButton: !1,
		prevViewport: {
			x: 0,
			y: 0,
			zoom: 0
		},
		mouseButton: 0,
		timerId: void 0,
		panScrollTimeout: void 0,
		isPanScrolling: !1
	}, x = s.getBoundingClientRect(), S = zoom_default().scaleExtent([c, f]).translateExtent(m), C = select_default(s).call(S);
	k({
		x: h.x,
		y: h.y,
		zoom: clamp(h.zoom, c, f)
	}, [[0, 0], [x.width, x.height]], m);
	let w = C.on("wheel.zoom"), T = C.on("dblclick.zoom");
	S.wheelDelta(wheelDelta);
	function E(e, s) {
		return C ? new Promise((c) => {
			S?.interpolate(s?.interpolate === "linear" ? value_default : zoom_default$1).transform(getD3Transition(C, s?.duration, s?.ease, () => c(!0)), e);
		}) : Promise.resolve(!1);
	}
	function D({ noWheelClassName: e, noPanClassName: s, onPaneContextMenu: c, userSelectionActive: l, panOnScroll: u, panOnDrag: d, panOnScrollMode: f, panOnScrollSpeed: p, preventScrolling: m, zoomOnPinch: h, zoomOnScroll: x, zoomOnDoubleClick: E, zoomActivationKeyPressed: D, lib: k, onTransformChange: A, connectionInProgress: j, paneClickDistance: M, selectionOnDrag: N }) {
		l && !b.isZoomingOrPanning && O();
		let P = u && !D && !l;
		S.clickDistance(N ? Infinity : !isNumeric(M) || M < 0 ? 0 : M);
		let F = P ? createPanOnScrollHandler({
			zoomPanValues: b,
			noWheelClassName: e,
			d3Selection: C,
			d3Zoom: S,
			panOnScrollMode: f,
			panOnScrollSpeed: p,
			zoomOnPinch: h,
			onPanZoomStart: _,
			onPanZoom: g,
			onPanZoomEnd: v
		}) : createZoomOnScrollHandler({
			noWheelClassName: e,
			preventScrolling: m,
			d3ZoomHandler: w
		});
		if (C.on("wheel.zoom", F, { passive: !1 }), !l) {
			let e = createPanZoomStartHandler({
				zoomPanValues: b,
				onDraggingChange: y,
				onPanZoomStart: _
			});
			S.on("start", e);
			let s = createPanZoomHandler({
				zoomPanValues: b,
				panOnDrag: d,
				onPaneContextMenu: !!c,
				onPanZoom: g,
				onTransformChange: A
			});
			S.on("zoom", s);
			let l = createPanZoomEndHandler({
				zoomPanValues: b,
				panOnDrag: d,
				panOnScroll: u,
				onPaneContextMenu: c,
				onPanZoomEnd: v,
				onDraggingChange: y
			});
			S.on("end", l);
		}
		let I = createFilter({
			zoomActivationKeyPressed: D,
			panOnDrag: d,
			zoomOnScroll: x,
			panOnScroll: u,
			zoomOnDoubleClick: E,
			zoomOnPinch: h,
			userSelectionActive: l,
			noPanClassName: s,
			noWheelClassName: e,
			lib: k,
			connectionInProgress: j
		});
		S.filter(I), E ? C.on("dblclick.zoom", T) : C.on("dblclick.zoom", null);
	}
	function O() {
		S.on("zoom", null);
	}
	async function k(e, s, c) {
		let l = viewportToTransform(e), u = S?.constrain()(l, s, c);
		return u && await E(u), new Promise((e) => e(u));
	}
	async function A(e, s) {
		let c = viewportToTransform(e);
		return await E(c, s), new Promise((e) => e(c));
	}
	function j(e) {
		if (C) {
			let s = viewportToTransform(e), c = C.property("__zoom");
			(c.k !== e.zoom || c.x !== e.x || c.y !== e.y) && S?.transform(C, s, null, { sync: !0 });
		}
	}
	function M() {
		let e = C ? transform(C.node()) : {
			x: 0,
			y: 0,
			k: 1
		};
		return {
			x: e.x,
			y: e.y,
			zoom: e.k
		};
	}
	function N(e, s) {
		return C ? new Promise((c) => {
			S?.interpolate(s?.interpolate === "linear" ? value_default : zoom_default$1).scaleTo(getD3Transition(C, s?.duration, s?.ease, () => c(!0)), e);
		}) : Promise.resolve(!1);
	}
	function P(e, s) {
		return C ? new Promise((c) => {
			S?.interpolate(s?.interpolate === "linear" ? value_default : zoom_default$1).scaleBy(getD3Transition(C, s?.duration, s?.ease, () => c(!0)), e);
		}) : Promise.resolve(!1);
	}
	function F(e) {
		S?.scaleExtent(e);
	}
	function I(e) {
		S?.translateExtent(e);
	}
	function L(e) {
		let s = !isNumeric(e) || e < 0 ? 0 : e;
		S?.clickDistance(s);
	}
	return {
		update: D,
		destroy: O,
		setViewport: A,
		setViewportConstrained: k,
		getViewport: M,
		scaleTo: N,
		scaleBy: P,
		setScaleExtent: F,
		setTranslateExtent: I,
		syncViewport: j,
		setClickDistance: L
	};
}
var ResizeControlVariant;
(function(e) {
	e.Line = "line", e.Handle = "handle";
})(ResizeControlVariant ||= {});
function getResizeDirection({ width: e, prevWidth: s, height: c, prevHeight: l, affectsX: u, affectsY: d }) {
	let f = e - s, p = c - l, m = [f > 0 ? 1 : f < 0 ? -1 : 0, p > 0 ? 1 : p < 0 ? -1 : 0];
	return f && u && (m[0] *= -1), p && d && (m[1] *= -1), m;
}
function getControlDirection(e) {
	return {
		isHorizontal: e.includes("right") || e.includes("left"),
		isVertical: e.includes("bottom") || e.includes("top"),
		affectsX: e.includes("left"),
		affectsY: e.includes("top")
	};
}
function getLowerExtentClamp(e, s) {
	return Math.max(0, s - e);
}
function getUpperExtentClamp(e, s) {
	return Math.max(0, e - s);
}
function getSizeClamp(e, s, c) {
	return Math.max(0, s - e, e - c);
}
function xor(e, s) {
	return e ? !s : s;
}
function getDimensionsAfterResize(e, s, c, l, u, d, f, p) {
	let { affectsX: m, affectsY: h } = s, { isHorizontal: g, isVertical: _ } = s, v = g && _, { xSnapped: y, ySnapped: b } = c, { minWidth: x, maxWidth: S, minHeight: C, maxHeight: w } = l, { x: T, y: E, width: D, height: O, aspectRatio: k } = e, A = Math.floor(g ? y - e.pointerX : 0), j = Math.floor(_ ? b - e.pointerY : 0), M = D + (m ? -A : A), N = O + (h ? -j : j), P = -d[0] * D, F = -d[1] * O, I = getSizeClamp(M, x, S), L = getSizeClamp(N, C, w);
	if (f) {
		let e = 0, s = 0;
		m && A < 0 ? e = getLowerExtentClamp(T + A + P, f[0][0]) : !m && A > 0 && (e = getUpperExtentClamp(T + M + P, f[1][0])), h && j < 0 ? s = getLowerExtentClamp(E + j + F, f[0][1]) : !h && j > 0 && (s = getUpperExtentClamp(E + N + F, f[1][1])), I = Math.max(I, e), L = Math.max(L, s);
	}
	if (p) {
		let e = 0, s = 0;
		m && A > 0 ? e = getUpperExtentClamp(T + A, p[0][0]) : !m && A < 0 && (e = getLowerExtentClamp(T + M, p[1][0])), h && j > 0 ? s = getUpperExtentClamp(E + j, p[0][1]) : !h && j < 0 && (s = getLowerExtentClamp(E + N, p[1][1])), I = Math.max(I, e), L = Math.max(L, s);
	}
	if (u) {
		if (g) {
			let e = getSizeClamp(M / k, C, w) * k;
			if (I = Math.max(I, e), f) {
				let e = 0;
				e = !m && !h || m && !h && v ? getUpperExtentClamp(E + F + M / k, f[1][1]) * k : getLowerExtentClamp(E + F + (m ? A : -A) / k, f[0][1]) * k, I = Math.max(I, e);
			}
			if (p) {
				let e = 0;
				e = !m && !h || m && !h && v ? getLowerExtentClamp(E + M / k, p[1][1]) * k : getUpperExtentClamp(E + (m ? A : -A) / k, p[0][1]) * k, I = Math.max(I, e);
			}
		}
		if (_) {
			let e = getSizeClamp(N * k, x, S) / k;
			if (L = Math.max(L, e), f) {
				let e = 0;
				e = !m && !h || h && !m && v ? getUpperExtentClamp(T + N * k + P, f[1][0]) / k : getLowerExtentClamp(T + (h ? j : -j) * k + P, f[0][0]) / k, L = Math.max(L, e);
			}
			if (p) {
				let e = 0;
				e = !m && !h || h && !m && v ? getLowerExtentClamp(T + N * k, p[1][0]) / k : getUpperExtentClamp(T + (h ? j : -j) * k, p[0][0]) / k, L = Math.max(L, e);
			}
		}
	}
	j += j < 0 ? L : -L, A += A < 0 ? I : -I, u && (v ? M > N * k ? j = (xor(m, h) ? -A : A) / k : A = (xor(m, h) ? -j : j) * k : g ? (j = A / k, h = m) : (A = j * k, m = h));
	let R = m ? T + A : T, z = h ? E + j : E;
	return {
		width: D + (m ? -A : A),
		height: O + (h ? -j : j),
		x: d[0] * A * (m ? -1 : 1) + R,
		y: d[1] * j * (h ? -1 : 1) + z
	};
}
var initPrevValues = {
	width: 0,
	height: 0,
	x: 0,
	y: 0
}, initStartValues = {
	...initPrevValues,
	pointerX: 0,
	pointerY: 0,
	aspectRatio: 1
};
function nodeToParentExtent(e) {
	return [[0, 0], [e.measured.width, e.measured.height]];
}
function nodeToChildExtent(e, s, c) {
	let l = s.position.x + e.position.x, u = s.position.y + e.position.y, d = e.measured.width ?? 0, f = e.measured.height ?? 0, p = c[0] * d, m = c[1] * f;
	return [[l - p, u - m], [l + d - p, u + f - m]];
}
function XYResizer({ domNode: s, nodeId: l, getStoreItems: u, onChange: d, onEnd: f }) {
	let p = select_default(s), m = {
		controlDirection: getControlDirection("bottom-right"),
		boundaries: {
			minWidth: 0,
			minHeight: 0,
			maxWidth: Number.MAX_VALUE,
			maxHeight: Number.MAX_VALUE
		},
		resizeDirection: void 0,
		keepAspectRatio: !1
	};
	function h({ controlPosition: e, boundaries: s, keepAspectRatio: h, resizeDirection: g, onResizeStart: _, onResize: v, onResizeEnd: y, shouldResize: b }) {
		let x = { ...initPrevValues }, S = { ...initStartValues };
		m = {
			boundaries: s,
			resizeDirection: g,
			keepAspectRatio: h,
			controlDirection: getControlDirection(e)
		};
		let C, w = null, T = [], E, D, O, k = !1, A = drag_default().on("start", (e) => {
			let { nodeLookup: s, transform: c, snapGrid: d, snapToGrid: f, nodeOrigin: p, paneDomNode: m } = u();
			if (C = s.get(l), !C) return;
			w = m?.getBoundingClientRect() ?? null;
			let { xSnapped: h, ySnapped: g } = getPointerPosition(e.sourceEvent, {
				transform: c,
				snapGrid: d,
				snapToGrid: f,
				containerBounds: w
			});
			x = {
				width: C.measured.width ?? 0,
				height: C.measured.height ?? 0,
				x: C.position.x ?? 0,
				y: C.position.y ?? 0
			}, S = {
				...x,
				pointerX: h,
				pointerY: g,
				aspectRatio: x.width / x.height
			}, E = void 0, C.parentId && (C.extent === "parent" || C.expandParent) && (E = s.get(C.parentId), D = E && C.extent === "parent" ? nodeToParentExtent(E) : void 0), T = [], O = void 0;
			for (let [e, c] of s) if (c.parentId === l && (T.push({
				id: e,
				position: { ...c.position },
				extent: c.extent
			}), c.extent === "parent" || c.expandParent)) {
				let e = nodeToChildExtent(c, C, c.origin ?? p);
				O = O ? [[Math.min(e[0][0], O[0][0]), Math.min(e[0][1], O[0][1])], [Math.max(e[1][0], O[1][0]), Math.max(e[1][1], O[1][1])]] : e;
			}
			_?.(e, { ...x });
		}).on("drag", (e) => {
			let { transform: s, snapGrid: c, snapToGrid: l, nodeOrigin: f } = u(), p = getPointerPosition(e.sourceEvent, {
				transform: s,
				snapGrid: c,
				snapToGrid: l,
				containerBounds: w
			}), h = [];
			if (!C) return;
			let { x: g, y: _, width: y, height: A } = x, j = {}, M = C.origin ?? f, { width: N, height: P, x: F, y: I } = getDimensionsAfterResize(S, m.controlDirection, p, m.boundaries, m.keepAspectRatio, M, D, O), L = N !== y, R = P !== A, z = F !== g && L, B = I !== _ && R;
			if (!z && !B && !L && !R) return;
			if ((z || B || M[0] === 1 || M[1] === 1) && (j.x = z ? F : x.x, j.y = B ? I : x.y, x.x = j.x, x.y = j.y, T.length > 0)) {
				let e = F - g, s = I - _;
				for (let c of T) c.position = {
					x: c.position.x - e + M[0] * (N - y),
					y: c.position.y - s + M[1] * (P - A)
				}, h.push(c);
			}
			if ((L || R) && (j.width = L && (!m.resizeDirection || m.resizeDirection === "horizontal") ? N : x.width, j.height = R && (!m.resizeDirection || m.resizeDirection === "vertical") ? P : x.height, x.width = j.width, x.height = j.height), E && C.expandParent) {
				let e = M[0] * (j.width ?? 0);
				j.x && j.x < e && (x.x = e, S.x -= j.x - e);
				let s = M[1] * (j.height ?? 0);
				j.y && j.y < s && (x.y = s, S.y -= j.y - s);
			}
			let V = getResizeDirection({
				width: x.width,
				prevWidth: y,
				height: x.height,
				prevHeight: A,
				affectsX: m.controlDirection.affectsX,
				affectsY: m.controlDirection.affectsY
			}), H = {
				...x,
				direction: V
			};
			b?.(e, H) !== !1 && (k = !0, v?.(e, H), d(j, h));
		}).on("end", (e) => {
			k &&= (y?.(e, { ...x }), f?.({ ...x }), !1);
		});
		p.call(A);
	}
	function g() {
		p.on(".drag", null);
	}
	return {
		update: h,
		destroy: g
	};
}
export { ConnectionLineType, ConnectionMode, MarkerType, PanOnScrollMode, Position, ResizeControlVariant, SelectionMode, XYDrag, XYHandle, XYMinimap, XYPanZoom, XYResizer, addEdge, adoptUserNodes, areSetsEqual, calculateNodePosition, createMarkerIds, defaultAriaLabelConfig, devWarn, elementSelectionKeys, errorMessages, evaluateAbsolutePosition, fitViewport, getBezierEdgeCenter, getBezierPath, getBoundsOfRects, getConnectedEdges, getConnectionStatus, getDimensions, getEdgeCenter, getEdgePosition, getElementsToRemove, getElevatedEdgeZIndex, getEventPosition, getHandlePosition, getHostForElement, getInternalNodesBounds, getMarkerId, getNodeDimensions, getNodesBounds, getNodesInside, getOverlappingArea, getSmoothStepPath, getStraightPath, getViewportForBounds, handleExpandParent, infiniteExtent, initialConnection, isEdgeBase, isEdgeVisible, isInputDOMNode, isMacOs, isMouseEvent, isNodeBase, isNumeric, isRectObject, mergeAriaLabelConfig, nodeHasDimensions, nodeToRect, panBy, pointToRendererPoint, rendererPointToPoint, snapPosition, updateAbsolutePositions, updateConnectionLookup, updateNodeInternals, withResolvers };
