@phun-ky/arclace 0.3.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +90 -14
- package/dist/arclace.d.ts +2 -1
- package/dist/arclace.js +334 -304
- package/dist/arclace.js.map +1 -1
- package/dist/arclace.umd.cjs +1 -1
- package/dist/arclace.umd.cjs.map +1 -1
- package/dist/style.css +18 -6
- package/package.json +6 -3
- package/src/Connection.ts +57 -6
- package/src/style.css +18 -6
package/dist/arclace.umd.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arclace.umd.cjs","sources":["../src/errors.ts","../src/utils/geometry.ts","../src/utils/id.ts","../src/utils/validate.ts","../src/utils/paths.ts","../src/utils/svg.ts","../src/Connection.ts","../src/utils/measure.ts","../src/utils/resolve-element.ts","../src/utils/sides.ts","../src/Arclace.ts"],"sourcesContent":["/**\n * Thrown when Arclace can't do what was asked, for example when a selector\n * matches nothing, an id is taken, or the instance has been destroyed.\n *\n * Arguments of the wrong type throw a `TypeError`, and values out of range a\n * `RangeError`, instead. When another error is behind the failure, such as\n * an invalid selector, it is the `cause`.\n *\n * @example\n * ```ts\n * try {\n * arclace.connect('#a', '#b', { id: 'a-to-b' });\n * arclace.connect('#b', '#c', { id: 'a-to-b' }); // the id is taken\n * } catch (error) {\n * if (error instanceof ArclaceError) console.warn(error.message);\n * }\n * ```\n */\nexport class ArclaceError extends Error {\n override name = 'ArclaceError';\n\n constructor(message: string, options?: ErrorOptions) {\n super(`arclace: ${message}`, options);\n }\n}\n","import type {\n ArcPointInterface,\n ArcRectInterface,\n ArcSideType\n} from '../types';\n\n/**\n * Unit vectors pointing away from each side of a box.\n */\nexport const NORMALS: Readonly<\n Record<ArcSideType, Readonly<ArcPointInterface>>\n> = Object.freeze({\n top: Object.freeze({ x: 0, y: -1 }),\n right: Object.freeze({ x: 1, y: 0 }),\n bottom: Object.freeze({ x: 0, y: 1 }),\n left: Object.freeze({ x: -1, y: 0 })\n});\n\nexport const OPPOSITE: Readonly<Record<ArcSideType, ArcSideType>> =\n Object.freeze({\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right'\n });\n\nexport const isHorizontalSide = (side: ArcSideType): boolean =>\n side === 'left' || side === 'right';\n\nexport const center = (rect: ArcRectInterface): ArcPointInterface => ({\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2\n});\n\nexport const add = (\n a: ArcPointInterface,\n b: ArcPointInterface,\n factor = 1\n): ArcPointInterface => ({ x: a.x + b.x * factor, y: a.y + b.y * factor });\n\n/**\n * Euclidean distance between two points.\n *\n * @example\n * ```ts\n * distance({ x: 0, y: 0 }, { x: 3, y: 4 }); // 5\n * ```\n */\nexport const distance = (a: ArcPointInterface, b: ArcPointInterface): number =>\n Math.hypot(b.x - a.x, b.y - a.y);\n\n/**\n * Rounds to two decimals to keep path data short.\n */\nexport const round = (value: number): number => Math.round(value * 100) / 100;\n\n/**\n * Formats a point for use in SVG path data.\n */\nexport const fmt = (point: ArcPointInterface): string =>\n `${round(point.x)} ${round(point.y)}`;\n","/**\n * Generates a unique ID consisting of an underscore followed by a random alphanumeric string.\n *\n * @returns {string} - A unique ID.\n *\n * @example\n * ```ts\n * // Generate a unique ID\n * const id = uniqueID();\n * console.log(id); // Example output: \"_abc123def\"\n * ```\n */\nexport const uniqueID = (): string =>\n '_' + Math.random().toString(36).substring(2, 11);\n","import type {\n ArcArrowType,\n ArcConnectionOptionsType,\n ArcOptionsType,\n ArcPathType,\n ArcPointInterface,\n ArcSideOptionType,\n ArcSideType\n} from '../types';\n\nexport const SIDES: readonly ArcSideType[] = Object.freeze([\n 'top',\n 'right',\n 'bottom',\n 'left'\n]);\n\nexport const SIDE_OPTIONS: readonly ArcSideOptionType[] = Object.freeze([\n ...SIDES,\n 'auto'\n]);\n\nexport const PATH_TYPES: readonly ArcPathType[] = Object.freeze([\n 'bezier',\n 'straight',\n 'orthogonal'\n]);\n\nexport const ARROWS: readonly ArcArrowType[] = Object.freeze([\n 'none',\n 'start',\n 'end',\n 'both'\n]);\n\n/**\n * A short description of a value for an error message, which never calls\n * the value's own `toString`.\n */\nconst show = (value: unknown): string => {\n if (typeof value === 'string') return JSON.stringify(value);\n\n if (\n value === null ||\n value === undefined ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n )\n return String(value);\n\n if (Array.isArray(value)) return 'an array';\n\n return typeof value === 'object' ? 'an object' : `a ${typeof value}`;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a plain object (not `null` or an\n * array).\n */\nexport const assertObject = (value: unknown, name: string): void => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError(\n `arclace: ${name} must be an object, not ${show(value)}`\n );\n }\n};\n\n/**\n * Throws a `TypeError` unless `value` is a string, and a `RangeError` unless\n * it is one of `allowed`.\n */\nexport const assertOneOf = <T extends string>(\n value: unknown,\n allowed: readonly T[],\n name: string\n): T => {\n const list = allowed.map((item) => `\"${item}\"`).join(', ');\n\n if (typeof value !== 'string') {\n throw new TypeError(\n `arclace: ${name} must be one of ${list}, not ${show(value)}`\n );\n }\n\n if (!allowed.includes(value as T)) {\n throw new RangeError(\n `arclace: ${name} must be one of ${list}, not ${show(value)}`\n );\n }\n\n return value as T;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a finite number, and a `RangeError`\n * when it is below `min`.\n */\nexport const assertNumber = (\n value: unknown,\n name: string,\n min?: number\n): number => {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new TypeError(\n `arclace: ${name} must be a finite number, not ${show(value)}`\n );\n }\n\n if (min !== undefined && value < min) {\n throw new RangeError(\n `arclace: ${name} must be ${min} or more, not ${show(value)}`\n );\n }\n\n return value;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a boolean.\n */\nexport const assertBoolean = (value: unknown, name: string): boolean => {\n if (typeof value !== 'boolean') {\n throw new TypeError(\n `arclace: ${name} must be true or false, not ${show(value)}`\n );\n }\n\n return value;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a string, or, with `nonEmpty`, a\n * string with at least one character.\n */\nexport const assertString = (\n value: unknown,\n name: string,\n nonEmpty = false\n): string => {\n if (typeof value !== 'string' || (nonEmpty && value === '')) {\n throw new TypeError(\n `arclace: ${name} must be a ${nonEmpty ? 'non-empty ' : ''}string, not ${show(value)}`\n );\n }\n\n return value;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a point with finite `x` and `y`.\n */\nexport const assertPoint = (\n value: unknown,\n name: string\n): ArcPointInterface => {\n assertObject(value, name);\n\n const { x, y } = value as Record<string, unknown>;\n\n assertNumber(x, `${name}.x`);\n assertNumber(y, `${name}.y`);\n\n return value as ArcPointInterface;\n};\n\n// How each connection option is checked. Keys that aren't listed are ignored.\nconst CONNECTION_OPTION_CHECKS: Readonly<\n Record<\n keyof ArcConnectionOptionsType,\n (value: unknown, name: string) => unknown\n >\n> = Object.freeze({\n id: (value, name) => assertString(value, name, true),\n type: (value, name) => assertOneOf(value, PATH_TYPES, name),\n startSide: (value, name) => assertOneOf(value, SIDE_OPTIONS, name),\n endSide: (value, name) => assertOneOf(value, SIDE_OPTIONS, name),\n arrow: (value, name) => assertOneOf(value, ARROWS, name),\n label: assertString,\n color: assertString,\n className: assertString,\n strokeWidth: (value, name) => assertNumber(value, name, 0),\n dashed: assertBoolean,\n animated: assertBoolean,\n anchors: assertBoolean,\n gap: (value, name) => assertNumber(value, name),\n spread: assertBoolean,\n spacing: (value, name) => assertNumber(value, name, 0),\n curvature: (value, name) => assertNumber(value, name),\n radius: (value, name) => assertNumber(value, name, 0),\n offset: (value, name) => assertNumber(value, name, 0)\n});\n\n/**\n * Checks every known connection option that is set. `undefined` means \"use\n * the default\" and is always allowed; unknown keys are ignored.\n *\n * @throws {TypeError} When `options` isn't an object, or an option has the\n * wrong type.\n * @throws {RangeError} When an option is out of range.\n */\nexport const validateConnectionOptions = (\n options: unknown,\n name = 'options'\n): ArcConnectionOptionsType => {\n assertObject(options, name);\n\n for (const [key, check] of Object.entries(CONNECTION_OPTION_CHECKS)) {\n const value = Object.hasOwn(options as object, key)\n ? (options as Record<string, unknown>)[key]\n : undefined;\n\n if (value !== undefined) check(value, `${name}.${key}`);\n }\n\n return options as ArcConnectionOptionsType;\n};\n\n/**\n * Checks the options of an instance, including its connection defaults.\n */\nexport const validateOptions = (options: unknown): ArcOptionsType => {\n assertObject(options, 'options');\n\n const { autoUpdate, className, defaults } = options as Record<\n string,\n unknown\n >;\n\n if (\n autoUpdate !== undefined &&\n typeof autoUpdate !== 'boolean' &&\n autoUpdate !== 'frame'\n ) {\n throw new RangeError(\n `arclace: options.autoUpdate must be true, false or \"frame\", not ${show(autoUpdate)}`\n );\n }\n\n if (className !== undefined) assertString(className, 'options.className');\n\n if (defaults !== undefined) {\n validateConnectionOptions(defaults, 'options.defaults');\n\n // Every connection would get the same id, so only the first could be made\n if ((defaults as ArcConnectionOptionsType).id !== undefined) {\n throw new TypeError(\n 'arclace: options.defaults cannot set an id; ids belong to single connections'\n );\n }\n }\n\n return options as ArcOptionsType;\n};\n","import type { ArcPointInterface, ArcSideType } from '../types';\n\nimport {\n add,\n distance,\n fmt,\n isHorizontalSide,\n NORMALS,\n OPPOSITE\n} from './geometry';\nimport { assertNumber, assertOneOf, assertPoint, SIDES } from './validate';\n\nexport type ArcPathResultType = {\n /**\n * SVG path data.\n */\n d: string;\n\n /**\n * The middle of the path, used to place labels.\n */\n labelPoint: ArcPointInterface;\n};\n\n/**\n * Normalizes a distance to a range from 0 to 1, based on max distance.\n *\n * @param distance - The actual distance.\n * @param maxDistance - The distance treated as 100% (1.0).\n * @returns Normalized value between 0 and 1.\n */\nexport const normalizeDistance = (\n distance: number,\n maxDistance: number = 1000\n): number => Math.min(distance / maxDistance, 1);\n\n/**\n * Maps a normalized value [0, 1] to a value between min and max.\n *\n * @param norm - Normalized value (0 to 1).\n * @param min - Minimum output value.\n * @param max - Maximum output value.\n * @returns Value between min and max.\n */\nexport const lerp = (norm: number, min: number, max: number): number =>\n min + (max - min) * norm;\n\n/**\n * Calculates a curve multiplier based on distance. Short lines get a\n * relatively larger bulge than long lines.\n *\n * @param distance - Distance between points.\n * @param min - Minimum multiplier.\n * @param max - Maximum multiplier.\n * @param maxDistance - Distance at which max multiplier is used.\n * @returns A multiplier between min and max.\n */\nexport const curveMultiplierFromDistance = (\n distance: number,\n min: number = 1.1,\n max: number = 3.5,\n maxDistance: number = 1000\n): number => lerp(normalizeDistance(distance, maxDistance), min, max);\n\n/**\n * Checks the ends of a path, so a bad side or point fails with a clear error\n * instead of path data with `NaN` in it.\n */\nconst checkEnds = (\n start: unknown,\n startSide: unknown,\n end: unknown,\n endSide: unknown\n): void => {\n assertPoint(start, 'start');\n assertOneOf(startSide, SIDES, 'startSide');\n assertPoint(end, 'end');\n assertOneOf(endSide, SIDES, 'endSide');\n};\n\n/**\n * A straight line between two points.\n *\n * @throws {TypeError} When a point doesn't have finite `x` and `y`.\n * @example\n * ```ts\n * straightPath({ x: 0, y: 0 }, { x: 100, y: 0 }).d; // 'M 0 0 L 100 0'\n * ```\n */\nexport const straightPath = (\n start: ArcPointInterface,\n end: ArcPointInterface\n): ArcPathResultType => {\n assertPoint(start, 'start');\n assertPoint(end, 'end');\n\n return {\n d: `M ${fmt(start)} L ${fmt(end)}`,\n labelPoint: { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 }\n };\n};\n\n/**\n * A cubic bezier curve that leaves `start` and arrives at `end`\n * perpendicular to their sides.\n *\n * @throws {TypeError} When a point or `curvature` isn't finite.\n * @throws {RangeError} When a side isn't `top`, `right`, `bottom` or `left`.\n * @example\n * ```ts\n * bezierPath({ x: 0, y: 0 }, 'right', { x: 200, y: 100 }, 'left').d;\n * ```\n */\nexport const bezierPath = (\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType,\n curvature = 1\n): ArcPathResultType => {\n checkEnds(start, startSide, end, endSide);\n assertNumber(curvature, 'curvature');\n\n const length = distance(start, end);\n const bulge = (length / curveMultiplierFromDistance(length)) * curvature;\n const c1 = add(start, NORMALS[startSide], bulge);\n const c2 = add(end, NORMALS[endSide], bulge);\n\n return {\n d: `M ${fmt(start)} C ${fmt(c1)}, ${fmt(c2)}, ${fmt(end)}`,\n // Point on the curve at t = 0.5\n labelPoint: {\n x: (start.x + 3 * c1.x + 3 * c2.x + end.x) / 8,\n y: (start.y + 3 * c1.y + 3 * c2.y + end.y) / 8\n }\n };\n};\n\n/**\n * Removes repeated points and points in the middle of a straight segment.\n */\nexport const simplifyPolyline = (\n points: ArcPointInterface[]\n): ArcPointInterface[] => {\n const unique = points.filter(\n (point, i) => i === 0 || distance(point, points[i - 1]) > 0.01\n );\n\n return unique.filter((point, i) => {\n if (i === 0 || i === unique.length - 1) return true;\n\n const prev = unique[i - 1];\n const next = unique[i + 1];\n const cross =\n (point.x - prev.x) * (next.y - prev.y) -\n (point.y - prev.y) * (next.x - prev.x);\n\n return Math.abs(cross) > 0.01;\n });\n};\n\n/**\n * Turns a polyline into path data, rounding each corner with a quadratic\n * curve. The radius shrinks on short segments so corners never overlap.\n */\nexport const roundedPolyline = (\n points: ArcPointInterface[],\n radius: number\n): string => {\n if (points.length === 0) return '';\n\n const towards = (\n from: ArcPointInterface,\n to: ArcPointInterface,\n length: number\n ): ArcPointInterface => {\n const total = distance(from, to);\n\n return {\n x: from.x + ((to.x - from.x) / total) * length,\n y: from.y + ((to.y - from.y) / total) * length\n };\n };\n const segments = [`M ${fmt(points[0])}`];\n\n for (let i = 1; i < points.length - 1; i++) {\n const prev = points[i - 1];\n const corner = points[i];\n const next = points[i + 1];\n const r = Math.min(\n radius,\n distance(prev, corner) / 2,\n distance(corner, next) / 2\n );\n\n if (r <= 0) {\n segments.push(`L ${fmt(corner)}`);\n continue;\n }\n\n segments.push(\n `L ${fmt(towards(corner, prev, r))}`,\n `Q ${fmt(corner)}, ${fmt(towards(corner, next, r))}`\n );\n }\n\n if (points.length > 1) segments.push(`L ${fmt(points[points.length - 1])}`);\n\n return segments.join(' ');\n};\n\n/**\n * The point halfway along a polyline.\n */\nexport const polylineMidpoint = (\n points: ArcPointInterface[]\n): ArcPointInterface => {\n const lengths = points.slice(1).map((point, i) => distance(points[i], point));\n\n let remaining = lengths.reduce((sum, length) => sum + length, 0) / 2;\n\n for (let i = 0; i < lengths.length; i++) {\n if (remaining <= lengths[i] && lengths[i] > 0) {\n const t = remaining / lengths[i];\n\n return {\n x: points[i].x + (points[i + 1].x - points[i].x) * t,\n y: points[i].y + (points[i + 1].y - points[i].y) * t\n };\n }\n\n remaining -= lengths[i];\n }\n\n return { ...points[0] };\n};\n\n// Swapping x and y turns vertical sides into horizontal ones, so only the\n// horizontal case has to be routed by hand.\nconst SWAPPED_SIDE: Readonly<Record<ArcSideType, ArcSideType>> = Object.freeze({\n top: 'left',\n bottom: 'right',\n left: 'top',\n right: 'bottom'\n});\nconst swap = (point: ArcPointInterface): ArcPointInterface => ({\n x: point.y,\n y: point.x\n});\n\n/**\n * Routes a line from `start` to `end` using only horizontal and vertical\n * segments. The line leaves and arrives perpendicular to the given sides,\n * travelling at least `offset` pixels straight out before turning back.\n *\n * @returns The corner points of the route, including `start` and `end`.\n */\nexport const routeOrthogonal = (\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType,\n offset = 20\n): ArcPointInterface[] => {\n if (!isHorizontalSide(startSide)) {\n return routeOrthogonal(\n swap(start),\n SWAPPED_SIDE[startSide],\n swap(end),\n SWAPPED_SIDE[endSide],\n offset\n ).map(swap);\n }\n\n const n1 = NORMALS[startSide];\n const n2 = NORMALS[endSide];\n const s1 = add(start, n1, offset);\n const s2 = add(end, n2, offset);\n\n if (isHorizontalSide(endSide)) {\n if (endSide === OPPOSITE[startSide]) {\n // Facing each other with room in between: turn halfway\n if ((s2.x - s1.x) * n1.x >= 0) {\n const midX = (start.x + end.x) / 2;\n\n return [start, { x: midX, y: start.y }, { x: midX, y: end.y }, end];\n }\n\n // Facing away from each other: step out, cross over halfway, step in\n const midY = (s1.y + s2.y) / 2;\n\n return [start, s1, { x: s1.x, y: midY }, { x: s2.x, y: midY }, s2, end];\n }\n\n // Same side: go around the outside of both\n const x = n1.x > 0 ? Math.max(s1.x, s2.x) : Math.min(s1.x, s2.x);\n\n return [start, { x, y: start.y }, { x, y: end.y }, end];\n }\n\n // One horizontal and one vertical side: a single corner if it lies in\n // front of both sides, otherwise step out of both and meet\n const corner = { x: end.x, y: start.y };\n\n if ((corner.x - start.x) * n1.x > 0 && (corner.y - end.y) * n2.y > 0) {\n return [start, corner, end];\n }\n\n return [start, s1, { x: s1.x, y: s2.y }, s2, end];\n};\n\n/**\n * An orthogonal line with rounded corners.\n *\n * @throws {TypeError} When a point, `radius` or `offset` isn't finite.\n * @throws {RangeError} When a side isn't `top`, `right`, `bottom` or `left`,\n * or `radius` or `offset` is negative.\n * @example\n * ```ts\n * orthogonalPath({ x: 0, y: 0 }, 'right', { x: 200, y: 100 }, 'left', {\n * radius: 8,\n * offset: 20\n * }).d;\n * ```\n */\nexport const orthogonalPath = (\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType,\n { radius = 8, offset = 20 }: { radius?: number; offset?: number } = {}\n): ArcPathResultType => {\n checkEnds(start, startSide, end, endSide);\n assertNumber(radius, 'radius', 0);\n assertNumber(offset, 'offset', 0);\n\n const points = simplifyPolyline(\n routeOrthogonal(start, startSide, end, endSide, offset)\n );\n\n return {\n d: roundedPolyline(points, radius),\n labelPoint: polylineMidpoint(points)\n };\n};\n","export const SVG_NS = 'http://www.w3.org/2000/svg';\n\n/**\n * Creates an SVG element with the given attributes.\n *\n * @example\n * ```ts\n * const path = createSVGElement('path', { fill: 'none' });\n * ```\n */\nexport const createSVGElement = <K extends keyof SVGElementTagNameMap>(\n tagName: K,\n attributes: Record<string, string | number> = {}\n): SVGElementTagNameMap[K] => {\n const el = document.createElementNS(SVG_NS, tagName);\n\n setAttributes(el, attributes);\n\n return el;\n};\n\n/**\n * Sets attributes on an element. `null` and `undefined` values remove the\n * attribute.\n */\nexport const setAttributes = (\n el: Element,\n attributes: Record<string, string | number | null | undefined>\n): void => {\n for (const [name, value] of Object.entries(attributes)) {\n if (value === null || value === undefined) el.removeAttribute(name);\n else el.setAttribute(name, String(value));\n }\n};\n","import type { Arclace } from './Arclace';\nimport { ArclaceError } from './errors';\nimport type {\n ArcConnectionOptionsType,\n ArcGeometryType,\n ArcPointInterface,\n ArcSideType\n} from './types';\nimport { add, distance, NORMALS } from './utils/geometry';\nimport { uniqueID } from './utils/id';\nimport {\n bezierPath,\n type ArcPathResultType,\n orthogonalPath,\n straightPath\n} from './utils/paths';\nimport { createSVGElement, setAttributes } from './utils/svg';\nimport { validateConnectionOptions } from './utils/validate';\n\n/**\n * Connection options with every default filled in. `label`, `color` and\n * `className` have no default.\n */\nexport type ArcResolvedConnectionOptionsType = Required<\n Omit<ArcConnectionOptionsType, 'id' | 'label' | 'color' | 'className'>\n> &\n Pick<ArcConnectionOptionsType, 'label' | 'color' | 'className'> & {\n id: string;\n };\n\n/**\n * Options every connection falls back to. Frozen: set your own defaults with\n * the `defaults` option of {@link Arclace} instead.\n */\nexport const DEFAULT_CONNECTION_OPTIONS: Readonly<\n Required<\n Omit<ArcConnectionOptionsType, 'id' | 'label' | 'color' | 'className'>\n >\n> = Object.freeze({\n type: 'bezier',\n startSide: 'auto',\n endSide: 'auto',\n arrow: 'none',\n strokeWidth: 2,\n dashed: false,\n animated: false,\n anchors: false,\n gap: 0,\n spread: true,\n spacing: 16,\n curvature: 1,\n radius: 8,\n offset: 20\n});\n\n/**\n * Drops options set to `undefined`, so they fall back to the defaults instead\n * of replacing them.\n */\nconst definedOnly = (\n options: ArcConnectionOptionsType\n): ArcConnectionOptionsType =>\n Object.fromEntries(\n Object.entries(options).filter(([, value]) => value !== undefined)\n );\n// Arrow length in multiples of the stroke width\nconst ARROW_SIZE = 4;\n\ntype ArcConnectionParamsType = {\n id: string;\n startElement: Element;\n endElement: Element;\n options: ArcConnectionOptionsType;\n defaults?: ArcConnectionOptionsType;\n owner: Arclace;\n};\n\n/**\n * A line between two elements. Created with {@link Arclace.connect} or\n * {@link Arclace.connectAll}, not with `new`.\n *\n * Each connection renders as:\n *\n * ```html\n * <g class=\"arc-connection arc-bezier\">\n * <marker class=\"arc-marker\">…</marker> <!-- when `arrow` is set -->\n * <path class=\"arc-path\" />\n * <text class=\"arc-label\">…</text> <!-- when `label` is set -->\n * <circle class=\"arc-anchor arc-anchor-start\" /> <!-- when `anchors` is set -->\n * <circle class=\"arc-anchor arc-anchor-end\" />\n * </g>\n * ```\n *\n * The line, arrows and anchors use `currentColor`, so setting `color` on\n * `.arc-connection` colors all of them.\n */\nexport class Connection {\n readonly id: string;\n readonly startElement: Element;\n readonly endElement: Element;\n\n /**\n * The `<g>` element holding everything this connection draws.\n */\n readonly element: SVGGElement;\n\n /**\n * The `<path>` element of the line.\n */\n readonly path: SVGPathElement;\n\n #geometry: ArcGeometryType | null = null;\n #removed = false;\n #owner: Arclace;\n #options: ArcConnectionOptionsType;\n #defaults: ArcConnectionOptionsType;\n #marker: SVGMarkerElement | null = null;\n #label: SVGTextElement | null = null;\n #anchors: [SVGCircleElement, SVGCircleElement] | null = null;\n\n private constructor(params: ArcConnectionParamsType) {\n const {\n id,\n startElement,\n endElement,\n options,\n defaults = {},\n owner\n } = params;\n\n this.id = id;\n this.startElement = startElement;\n this.endElement = endElement;\n this.#owner = owner;\n this.#options = { ...options };\n this.#defaults = defaults;\n this.element = createSVGElement('g', { 'data-arc-id': id });\n this.path = createSVGElement('path', {\n class: 'arc-path',\n fill: 'none',\n stroke: 'currentColor'\n });\n this.element.appendChild(this.path);\n this.#applyOptions();\n }\n\n /**\n * Creates a connection for its owner. Options must already be validated.\n *\n * @internal\n */\n static _create(params: ArcConnectionParamsType): Connection {\n return new Connection(params);\n }\n\n /**\n * The geometry from the last update, or `null` when the connection is\n * hidden because one of its elements is not rendered.\n */\n get geometry(): Readonly<ArcGeometryType> | null {\n return this.#geometry;\n }\n\n /**\n * The connection's options merged with the instance defaults.\n */\n get options(): Readonly<ArcResolvedConnectionOptionsType> {\n return {\n ...DEFAULT_CONNECTION_OPTIONS,\n ...definedOnly(this.#defaults),\n ...definedOnly(this.#options),\n id: this.id\n };\n }\n\n /**\n * Changes options and redraws.\n *\n * @example\n * ```ts\n * connection.setOptions({ type: 'orthogonal', arrow: 'end' });\n * ```\n * @throws {TypeError} When an option has the wrong type, or `id` is set.\n * @throws {RangeError} When an option is out of range.\n * @throws {ArclaceError} When the connection has been removed.\n */\n setOptions(options: Omit<ArcConnectionOptionsType, 'id'>): this {\n if (this.#removed) {\n throw new ArclaceError(`connection \"${this.id}\" has been removed`);\n }\n\n validateConnectionOptions(options);\n\n if ((options as ArcConnectionOptionsType).id !== undefined) {\n throw new TypeError('arclace: setOptions() cannot change the id');\n }\n\n this.#options = { ...this.#options, ...options };\n this.#applyOptions();\n this.#owner.update();\n\n return this;\n }\n\n /**\n * Redraws every connection of the owning instance.\n */\n update(): void {\n this.#owner.update();\n }\n\n /**\n * Removes this connection.\n */\n remove(): void {\n this.#owner.disconnect(this);\n }\n\n /**\n * Draws the connection between two attachment points.\n *\n * @internal\n */\n _draw(\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType\n ): void {\n const { arrow, strokeWidth } = this.options;\n const arrowLength = ARROW_SIZE * strokeWidth;\n // Shorten the line so arrow tips, not the line's end caps, touch the\n // elements\n const pathStart =\n arrow === 'start' || arrow === 'both'\n ? this.#pullBack(start, startSide, end, arrowLength)\n : start;\n const pathEnd =\n arrow === 'end' || arrow === 'both'\n ? this.#pullBack(end, endSide, start, arrowLength)\n : end;\n const { d, labelPoint } = this.#buildPath(\n pathStart,\n startSide,\n pathEnd,\n endSide\n );\n\n this.#geometry = Object.freeze({\n start,\n end,\n startSide,\n endSide,\n labelPoint,\n d\n });\n\n this.element.removeAttribute('display');\n setAttributes(this.element, {\n 'data-start-side': startSide,\n 'data-end-side': endSide\n });\n this.path.setAttribute('d', d);\n\n if (this.#label) setAttributes(this.#label, { ...labelPoint });\n\n if (this.#anchors) {\n setAttributes(this.#anchors[0], { cx: start.x, cy: start.y });\n setAttributes(this.#anchors[1], { cx: end.x, cy: end.y });\n }\n }\n\n /**\n * Hides the connection.\n *\n * @internal\n */\n _hide(): void {\n this.#geometry = null;\n this.element.setAttribute('display', 'none');\n }\n\n /**\n * Removes the connection's elements from the overlay.\n *\n * @internal\n */\n _dispose(): void {\n this.#removed = true;\n this.element.remove();\n }\n\n #buildPath(\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType\n ): ArcPathResultType {\n const { type, curvature, radius, offset } = this.options;\n\n if (type === 'straight') return straightPath(start, end);\n\n if (type === 'orthogonal') {\n return orthogonalPath(start, startSide, end, endSide, {\n radius,\n offset\n });\n }\n\n return bezierPath(start, startSide, end, endSide, curvature);\n }\n\n #pullBack(\n point: ArcPointInterface,\n side: ArcSideType,\n other: ArcPointInterface,\n length: number\n ): ArcPointInterface {\n const total = distance(point, other);\n const amount = Math.min(length, total / 3);\n\n if (this.options.type !== 'straight') {\n return add(point, NORMALS[side], amount);\n }\n\n if (total === 0) return point;\n\n return {\n x: point.x + ((other.x - point.x) / total) * amount,\n y: point.y + ((other.y - point.y) / total) * amount\n };\n }\n\n #applyOptions(): void {\n const {\n type,\n arrow,\n label,\n color,\n strokeWidth,\n dashed,\n animated,\n anchors,\n className\n } = this.options;\n const classes = ['arc-connection', `arc-${type}`];\n\n if (dashed || animated) classes.push('arc-dashed');\n\n if (animated) classes.push('arc-animated');\n\n if (className) classes.push(...className.split(/\\s+/).filter(Boolean));\n\n setAttributes(this.element, {\n class: classes.join(' '),\n 'data-type': type\n });\n // Inline so it wins over the stylesheet's --arc-color\n this.element.style.color = color ?? '';\n\n setAttributes(this.path, {\n 'stroke-width': strokeWidth,\n 'stroke-dasharray': dashed || animated ? '6 6' : null\n });\n\n this.#applyArrow(arrow);\n this.#applyLabel(label);\n this.#applyAnchors(anchors, strokeWidth);\n }\n\n #applyArrow(arrow: ArcResolvedConnectionOptionsType['arrow']): void {\n if (arrow === 'none') {\n this.#marker?.remove();\n this.#marker = null;\n setAttributes(this.path, { 'marker-start': null, 'marker-end': null });\n\n return;\n }\n\n if (!this.#marker) {\n // The marker lives inside the connection's group so it inherits the\n // group's color\n this.#marker = createSVGElement('marker', {\n id: `arc-arrow-${uniqueID()}`,\n class: 'arc-marker',\n viewBox: '0 0 10 10',\n refX: 0,\n refY: 5,\n markerWidth: ARROW_SIZE,\n markerHeight: ARROW_SIZE,\n markerUnits: 'strokeWidth',\n orient: 'auto-start-reverse'\n });\n this.#marker.appendChild(\n createSVGElement('path', {\n d: 'M 0 0 L 10 5 L 0 10 z',\n fill: 'currentColor'\n })\n );\n this.element.insertBefore(this.#marker, this.path);\n }\n\n const url = `url(#${this.#marker.id})`;\n\n setAttributes(this.path, {\n 'marker-start': arrow === 'start' || arrow === 'both' ? url : null,\n 'marker-end': arrow === 'end' || arrow === 'both' ? url : null\n });\n }\n\n #applyLabel(label: string | undefined): void {\n if (!label) {\n this.#label?.remove();\n this.#label = null;\n\n return;\n }\n\n if (!this.#label) {\n this.#label = createSVGElement('text', {\n class: 'arc-label',\n fill: 'currentColor',\n 'text-anchor': 'middle',\n 'dominant-baseline': 'central'\n });\n this.path.after(this.#label);\n\n if (this.#geometry)\n setAttributes(this.#label, { ...this.#geometry.labelPoint });\n }\n\n this.#label.textContent = label;\n }\n\n #applyAnchors(anchors: boolean, strokeWidth: number): void {\n if (!anchors) {\n this.#anchors?.forEach((anchor) => anchor.remove());\n this.#anchors = null;\n\n return;\n }\n\n if (!this.#anchors) {\n this.#anchors = [\n createSVGElement('circle', { class: 'arc-anchor arc-anchor-start' }),\n createSVGElement('circle', { class: 'arc-anchor arc-anchor-end' })\n ];\n this.element.append(...this.#anchors);\n }\n\n this.#anchors.forEach((anchor) =>\n setAttributes(anchor, { r: strokeWidth + 2, fill: 'currentColor' })\n );\n }\n}\n","import type { ArcRectInterface } from '../types';\n\n/**\n * Where the SVG overlay is on screen, and how much it is scaled by CSS\n * transforms on its ancestors.\n */\nexport type ArcOriginType = {\n left: number;\n top: number;\n scaleX: number;\n scaleY: number;\n};\n\n/**\n * Measures the overlay so screen coordinates can be converted to coordinates\n * inside it. Because the overlay is measured directly, this works no matter\n * how the container is positioned, scrolled or scaled.\n */\nexport const getOrigin = (svg: SVGSVGElement): ArcOriginType => {\n const rect = svg.getBoundingClientRect();\n const { clientWidth, clientHeight } = svg;\n\n return {\n left: rect.left,\n top: rect.top,\n scaleX: clientWidth > 0 && rect.width > 0 ? rect.width / clientWidth : 1,\n scaleY: clientHeight > 0 && rect.height > 0 ? rect.height / clientHeight : 1\n };\n};\n\n/**\n * Measures an element in the overlay's coordinate system.\n *\n * @example\n * ```ts\n * const rect = getLocalRect(element, getOrigin(svg));\n * ```\n */\nexport const getLocalRect = (\n el: Element,\n origin: ArcOriginType\n): ArcRectInterface => {\n const rect = el.getBoundingClientRect();\n const left = (rect.left - origin.left) / origin.scaleX;\n const top = (rect.top - origin.top) / origin.scaleY;\n const width = rect.width / origin.scaleX;\n const height = rect.height / origin.scaleY;\n\n return {\n left,\n top,\n width,\n height,\n right: left + width,\n bottom: top + height\n };\n};\n\n/**\n * Whether an element is in the document and has a layout box, i.e. is not\n * `display: none`.\n */\nexport const isRendered = (el: Element): boolean =>\n el.isConnected && el.getClientRects().length > 0;\n","import { ArclaceError } from '../errors';\n\n/**\n * Runs `document.querySelector`, turning an invalid selector into an\n * {@link ArclaceError} with the browser's `SyntaxError` as the cause.\n */\nexport const querySelector = (\n selector: string,\n name = 'element'\n): Element | null => {\n try {\n return document.querySelector(selector);\n } catch (error) {\n throw new ArclaceError(`${name} \"${selector}\" is not a valid selector`, {\n cause: error\n });\n }\n};\n\n/**\n * Resolves an element or a CSS selector to an element.\n *\n * @throws {TypeError} When the target is neither an element nor a string.\n * @throws {ArclaceError} When the selector is invalid or matches nothing.\n * @example\n * ```ts\n * const el = resolveElement('#box-1');\n * ```\n */\nexport const resolveElement = (target: unknown, name = 'element'): Element => {\n if (typeof target === 'string') {\n const el = querySelector(target, name);\n\n if (!el) throw new ArclaceError(`no ${name} matches \"${target}\"`);\n\n return el;\n }\n\n if (!(target instanceof Element)) {\n throw new TypeError(\n `arclace: ${name} must be an Element or a selector string`\n );\n }\n\n return target;\n};\n","import type {\n ArcPointInterface,\n ArcRectInterface,\n ArcSideOptionType,\n ArcSideType\n} from '../types';\n\nimport { add, center, NORMALS, OPPOSITE } from './geometry';\n\n/**\n * Picks the side of `from` that faces `to`.\n *\n * Boxes that are further apart horizontally than vertically connect\n * left/right, otherwise top/bottom.\n *\n * @example\n * ```ts\n * facingSide(\n * { left: 0, top: 0, right: 100, bottom: 50, width: 100, height: 50 },\n * { left: 300, top: 0, right: 400, bottom: 50, width: 100, height: 50 }\n * ); // 'right'\n * ```\n */\nexport const facingSide = (\n from: ArcRectInterface,\n to: ArcRectInterface\n): ArcSideType => {\n const a = center(from);\n const b = center(to);\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n // Positive when the boxes are separated on that axis, negative when they overlap\n const gapX = Math.max(to.left - from.right, from.left - to.right);\n const gapY = Math.max(to.top - from.bottom, from.top - to.bottom);\n const horizontal = gapX === gapY ? Math.abs(dx) >= Math.abs(dy) : gapX > gapY;\n\n if (horizontal) return dx >= 0 ? 'right' : 'left';\n\n return dy >= 0 ? 'bottom' : 'top';\n};\n\n/**\n * Resolves `'auto'` sides for a connection between two boxes.\n *\n * @example\n * ```ts\n * resolveSides(startRect, endRect, 'auto', 'auto');\n * // { startSide: 'right', endSide: 'left' }\n * ```\n */\nexport const resolveSides = (\n startRect: ArcRectInterface,\n endRect: ArcRectInterface,\n startSide: ArcSideOptionType = 'auto',\n endSide: ArcSideOptionType = 'auto'\n): { startSide: ArcSideType; endSide: ArcSideType } => ({\n startSide: startSide === 'auto' ? facingSide(startRect, endRect) : startSide,\n endSide:\n endSide === 'auto' ? OPPOSITE[facingSide(startRect, endRect)] : endSide\n});\n\n/**\n * Returns the point on a side of a box where a line attaches.\n *\n * When `count` lines share the side, they are spread around the middle of the\n * side, `spacing` pixels apart, shrinking to fit the side if needed. `gap`\n * moves the point away from the box.\n *\n * @example\n * ```ts\n * // The second of three lines on the top side\n * getAnchorPoint(rect, 'top', { index: 1, count: 3 });\n * ```\n */\nexport const getAnchorPoint = (\n rect: ArcRectInterface,\n side: ArcSideType,\n {\n index = 0,\n count = 1,\n spacing = 16,\n gap = 0\n }: { index?: number; count?: number; spacing?: number; gap?: number } = {}\n): ArcPointInterface => {\n const length = side === 'top' || side === 'bottom' ? rect.width : rect.height;\n const step = count > 1 ? Math.min(spacing, length / count) : 0;\n const shift = (index - (count - 1) / 2) * step;\n const { x: cx, y: cy } = center(rect);\n\n let point: ArcPointInterface;\n\n switch (side) {\n case 'top':\n point = { x: cx + shift, y: rect.top };\n break;\n case 'bottom':\n point = { x: cx + shift, y: rect.bottom };\n break;\n case 'left':\n point = { x: rect.left, y: cy + shift };\n break;\n case 'right':\n point = { x: rect.right, y: cy + shift };\n break;\n }\n\n return add(point, NORMALS[side], gap);\n};\n","import { Connection } from './Connection';\nimport { ArclaceError } from './errors';\nimport type {\n ArcConnectionDefinitionType,\n ArcConnectionOptionsType,\n ArcElementTargetType,\n ArcOptionsType,\n ArcRectInterface,\n ArcSideType\n} from './types';\nimport { center, isHorizontalSide } from './utils/geometry';\nimport { uniqueID } from './utils/id';\nimport { getLocalRect, getOrigin, isRendered } from './utils/measure';\nimport { querySelector, resolveElement } from './utils/resolve-element';\nimport { getAnchorPoint, resolveSides } from './utils/sides';\nimport { createSVGElement } from './utils/svg';\nimport {\n assertObject,\n validateConnectionOptions,\n validateOptions\n} from './utils/validate';\n\ntype ArcLayoutItemType = {\n connection: Connection;\n startRect: ArcRectInterface;\n endRect: ArcRectInterface;\n startSide: ArcSideType;\n endSide: ArcSideType;\n startSlot: { index: number; count: number };\n endSlot: { index: number; count: number };\n};\n\n// A connection that has been checked and can be added\ntype ArcPreparedConnectionType = {\n id: string;\n startElement: Element;\n endElement: Element;\n options: ArcConnectionOptionsType;\n};\n\ntype ArcSlotEntryType = {\n slot: { index: number; count: number };\n // Position of the other end along the side, used to avoid crossing lines\n key: number;\n};\n\nconst nextFrame = (callback: () => void): number =>\n typeof requestAnimationFrame === 'function'\n ? requestAnimationFrame(callback)\n : (setTimeout(callback, 16) as unknown as number);\nconst cancelFrame = (handle: number): void => {\n if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(handle);\n else clearTimeout(handle);\n};\n\n/**\n * Draws and maintains SVG lines between DOM elements.\n *\n * An instance adds one `<svg class=\"arc-svg\">` overlay to its container and\n * draws every connection into it.\n *\n * @example\n * ```ts\n * import { Arclace } from '@phun-ky/arclace';\n *\n * const arclace = new Arclace({ container: '#diagram' });\n *\n * arclace.connect('#a', '#b', { arrow: 'end', label: 'depends on' });\n * ```\n */\nexport class Arclace {\n /**\n * The element the overlay was added to.\n */\n readonly container: HTMLElement;\n\n /**\n * The SVG overlay all lines are drawn in.\n */\n readonly svg: SVGSVGElement;\n\n #options: ArcOptionsType;\n #connections = new Map<string, Connection>();\n #frame = 0;\n #loop = 0;\n #destroyed = false;\n #resizeObserver: ResizeObserver | null = null;\n #mutationObserver: MutationObserver | null = null;\n #originalPosition: string | null = null;\n\n /**\n * @throws {TypeError} When an option has the wrong type.\n * @throws {RangeError} When an option is out of range.\n * @throws {ArclaceError} When there is no DOM, or the container can't be\n * found.\n */\n constructor(options: ArcOptionsType = {}) {\n if (typeof document === 'undefined') {\n throw new ArclaceError('a DOM is required');\n }\n\n this.#options = validateOptions(options);\n this.container = (\n options.container\n ? resolveElement(options.container, 'container')\n : document.body\n ) as HTMLElement;\n\n // The overlay is positioned absolutely, so the container has to be its\n // containing block for it to scroll and clip with the container\n if (\n this.container !== document.body &&\n getComputedStyle(this.container).position === 'static'\n ) {\n this.#originalPosition = this.container.style.position;\n this.container.style.position = 'relative';\n }\n\n this.svg = createSVGElement('svg', {\n class: ['arc-svg', options.className].filter(Boolean).join(' '),\n 'aria-hidden': 'true'\n });\n Object.assign(this.svg.style, {\n position: 'absolute',\n top: '0',\n left: '0',\n width: '100%',\n height: '100%',\n overflow: 'visible',\n pointerEvents: 'none'\n });\n this.container.prepend(this.svg);\n this.#startAutoUpdate();\n }\n\n /**\n * All current connections, in the order they were made.\n */\n get connections(): Connection[] {\n return [...this.#connections.values()];\n }\n\n /**\n * Connects two elements and draws the line right away.\n *\n * @param startElement - The element (or selector) the line starts at.\n * @param endElement - The element (or selector) the line ends at.\n * @param options - Options for this connection, merged over the instance defaults.\n * @throws {TypeError} When an element or an option has the wrong type.\n * @throws {RangeError} When an option is out of range.\n * @throws {ArclaceError} When an element can't be found, the id is taken\n * or the instance has been destroyed. Nothing is added.\n * @example\n * ```ts\n * const connection = arclace.connect(a, b, { type: 'orthogonal', arrow: 'end' });\n * ```\n */\n connect(\n startElement: ArcElementTargetType,\n endElement: ArcElementTargetType,\n options: ArcConnectionOptionsType = {}\n ): Connection {\n const connection = this.#add(\n this.#prepare(startElement, endElement, options, 'options')\n );\n\n this.update();\n\n return connection;\n }\n\n /**\n * Connects many pairs of elements and draws them in one go. Every\n * definition is checked first, so either all of them are added or none.\n *\n * @throws {TypeError} When `definitions` isn't an array, or an element or\n * an option has the wrong type.\n * @throws {RangeError} When an option is out of range.\n * @throws {ArclaceError} When an element can't be found, an id is taken or\n * repeated, or the instance has been destroyed.\n * @example\n * ```ts\n * arclace.connectAll([\n * { startElement: '#a', endElement: '#b' },\n * { startElement: '#a', endElement: '#c', dashed: true }\n * ]);\n * ```\n */\n connectAll(definitions: ArcConnectionDefinitionType[]): Connection[] {\n if (!Array.isArray(definitions)) {\n throw new TypeError(\n 'arclace: connectAll() needs an array of definitions'\n );\n }\n\n const ids = new Set<string>();\n const prepared = definitions.map((definition, index) => {\n const name = `definitions[${index}]`;\n\n assertObject(definition, name);\n\n const { startElement, endElement, ...options } = definition;\n const connection = this.#prepare(startElement, endElement, options, name);\n\n if (ids.has(connection.id)) {\n throw new ArclaceError(\n `${name}.id \"${connection.id}\" is used more than once`\n );\n }\n\n ids.add(connection.id);\n\n return connection;\n });\n const connections = prepared.map((connection) => this.#add(connection));\n\n this.update();\n\n return connections;\n }\n\n /**\n * Returns the connection with the given id.\n */\n get(id: string): Connection | undefined {\n return this.#connections.get(id);\n }\n\n /**\n * Returns every connection that starts or ends at an element. A selector\n * that matches nothing returns an empty array.\n *\n * @throws {TypeError} When the target is neither an element nor a string.\n * @throws {ArclaceError} When the selector is invalid.\n */\n find(target: ArcElementTargetType): Connection[] {\n const el =\n typeof target === 'string'\n ? querySelector(target)\n : resolveElement(target);\n\n if (!el) return [];\n\n return this.connections.filter(\n (connection) =>\n connection.startElement === el || connection.endElement === el\n );\n }\n\n /**\n * Removes connections.\n *\n * @param target - A connection, a connection id, or an element (or\n * selector) whose connections should all be removed. Targets that match\n * nothing, and `null` or `undefined`, are ignored.\n * @throws {TypeError} When the target is another kind of value.\n * @throws {ArclaceError} When a string is neither an id nor a valid\n * selector.\n * @example\n * ```ts\n * arclace.disconnect(connection);\n * arclace.disconnect('my-connection-id');\n * arclace.disconnect(document.querySelector('#a'));\n * ```\n */\n disconnect(target: Connection | string | Element): void {\n let removed: Connection[];\n\n if (target === null || target === undefined) return;\n\n if (target instanceof Connection) {\n removed = [target];\n } else if (typeof target === 'string' && this.#connections.has(target)) {\n removed = [this.#connections.get(target)!];\n } else if (typeof target === 'string' || target instanceof Element) {\n removed = this.find(target);\n } else {\n throw new TypeError(\n 'arclace: disconnect() needs a connection, an id, an element or a selector'\n );\n }\n\n for (const connection of removed) {\n if (this.#connections.get(connection.id) !== connection) continue;\n\n this.#connections.delete(connection.id);\n connection._dispose();\n this.#unobserve(connection.startElement);\n this.#unobserve(connection.endElement);\n }\n\n if (removed.length > 0) this.update();\n }\n\n /**\n * Removes every connection.\n */\n clear(): void {\n for (const connection of this.#connections.values()) {\n connection._dispose();\n }\n\n this.#connections.clear();\n this.#resizeObserver?.disconnect();\n\n if (this.#resizeObserver) this.#resizeObserver.observe(this.container);\n }\n\n /**\n * Remeasures every element and redraws every connection. Called\n * automatically when `autoUpdate` is on; call it yourself after moving\n * elements in ways the page can't observe.\n */\n update(): void {\n if (this.#destroyed) return;\n\n if (this.#frame) {\n cancelFrame(this.#frame);\n this.#frame = 0;\n }\n\n // Measure everything first, then write, so the browser only lays out once\n const origin = getOrigin(this.svg);\n const items: ArcLayoutItemType[] = [];\n const slots = new Map<Element, Record<ArcSideType, ArcSlotEntryType[]>>();\n const addToSlot = (\n el: Element,\n side: ArcSideType,\n otherRect: ArcRectInterface\n ): { index: number; count: number } => {\n const slot = { index: 0, count: 1 };\n const other = center(otherRect);\n\n if (!slots.has(el)) {\n slots.set(el, { top: [], right: [], bottom: [], left: [] });\n }\n\n slots.get(el)![side].push({\n slot,\n key: isHorizontalSide(side) ? other.y : other.x\n });\n\n return slot;\n };\n\n for (const connection of this.#connections.values()) {\n const { startElement, endElement } = connection;\n\n if (!isRendered(startElement) || !isRendered(endElement)) {\n connection._hide();\n continue;\n }\n\n const { spread, startSide, endSide } = connection.options;\n const startRect = getLocalRect(startElement, origin);\n const endRect = getLocalRect(endElement, origin);\n const sides = resolveSides(startRect, endRect, startSide, endSide);\n const solo = { index: 0, count: 1 };\n\n items.push({\n connection,\n startRect,\n endRect,\n ...sides,\n startSlot: spread\n ? addToSlot(startElement, sides.startSide, endRect)\n : solo,\n endSlot: spread\n ? addToSlot(endElement, sides.endSide, startRect)\n : { ...solo }\n });\n }\n\n for (const sides of slots.values()) {\n for (const entries of Object.values(sides)) {\n entries\n .sort((a, b) => a.key - b.key)\n .forEach((entry, index) => {\n entry.slot.index = index;\n entry.slot.count = entries.length;\n });\n }\n }\n\n for (const item of items) {\n const { connection, startRect, endRect, startSide, endSide } = item;\n const { spacing, gap } = connection.options;\n\n connection._draw(\n getAnchorPoint(startRect, startSide, {\n ...item.startSlot,\n spacing,\n gap\n }),\n startSide,\n getAnchorPoint(endRect, endSide, { ...item.endSlot, spacing, gap }),\n endSide\n );\n }\n }\n\n /**\n * Removes every connection and the overlay, and stops listening for\n * changes. The instance can't be used afterwards.\n */\n destroy(): void {\n if (this.#destroyed) return;\n\n this.clear();\n this.#destroyed = true;\n\n if (this.#frame) cancelFrame(this.#frame);\n\n if (this.#loop) cancelFrame(this.#loop);\n\n window.removeEventListener('resize', this.#scheduleUpdate);\n document.removeEventListener('scroll', this.#scheduleUpdate, {\n capture: true\n });\n this.#resizeObserver?.disconnect();\n this.#mutationObserver?.disconnect();\n this.svg.remove();\n\n if (this.#originalPosition !== null) {\n this.container.style.position = this.#originalPosition;\n }\n }\n\n /**\n * Checks a connection without adding anything, so a bad option can't leave\n * a connection behind that breaks every later update.\n */\n #prepare(\n startTarget: unknown,\n endTarget: unknown,\n options: unknown,\n name: string\n ): ArcPreparedConnectionType {\n if (this.#destroyed) {\n throw new ArclaceError('this instance has been destroyed');\n }\n\n validateConnectionOptions(options, name);\n\n const startElement = resolveElement(startTarget, 'startElement');\n const endElement = resolveElement(endTarget, 'endElement');\n const valid = options as ArcConnectionOptionsType;\n const id = valid.id ?? `arc-${uniqueID()}`;\n\n if (this.#connections.has(id)) {\n throw new ArclaceError(`a connection with id \"${id}\" exists`);\n }\n\n return { id, startElement, endElement, options: valid };\n }\n\n #add({\n id,\n startElement,\n endElement,\n options\n }: ArcPreparedConnectionType): Connection {\n const connection = Connection._create({\n id,\n startElement,\n endElement,\n options,\n defaults: this.#options.defaults,\n owner: this\n });\n\n this.#connections.set(id, connection);\n this.svg.appendChild(connection.element);\n this.#resizeObserver?.observe(startElement);\n this.#resizeObserver?.observe(endElement);\n\n return connection;\n }\n\n #unobserve(el: Element): void {\n if (!this.#resizeObserver || el === this.container) return;\n\n const inUse = this.connections.some(\n (connection) =>\n connection.startElement === el || connection.endElement === el\n );\n\n if (!inUse) this.#resizeObserver.unobserve(el);\n }\n\n #scheduleUpdate = (): void => {\n if (this.#frame || this.#destroyed) return;\n\n this.#frame = nextFrame(() => {\n this.#frame = 0;\n this.update();\n });\n };\n\n #startAutoUpdate(): void {\n const { autoUpdate = true } = this.#options;\n\n if (autoUpdate === false) return;\n\n if (autoUpdate === 'frame') {\n const loop = (): void => {\n this.update();\n this.#loop = nextFrame(loop);\n };\n\n this.#loop = nextFrame(loop);\n\n return;\n }\n\n window.addEventListener('resize', this.#scheduleUpdate);\n // Capture scroll events from any scrolling element, not just the page\n document.addEventListener('scroll', this.#scheduleUpdate, {\n capture: true,\n passive: true\n });\n\n if (typeof ResizeObserver !== 'undefined') {\n this.#resizeObserver = new ResizeObserver(this.#scheduleUpdate);\n this.#resizeObserver.observe(this.container);\n }\n\n if (typeof MutationObserver !== 'undefined') {\n this.#mutationObserver = new MutationObserver((records) => {\n // Ignore the changes we make to the overlay ourselves\n if (records.some((record) => !this.svg.contains(record.target))) {\n this.#scheduleUpdate();\n }\n });\n this.#mutationObserver.observe(this.container, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ['style', 'class', 'hidden']\n });\n }\n\n document.fonts?.ready.then(this.#scheduleUpdate);\n }\n}\n\n/**\n * Creates a {@link Arclace} instance and connects the given pairs.\n *\n * @example\n * ```ts\n * import { createConnections } from '@phun-ky/arclace';\n *\n * const arclace = createConnections(\n * [\n * { startElement: '#a', endElement: '#b' },\n * { startElement: '#b', endElement: '#c', arrow: 'end' }\n * ],\n * { defaults: { type: 'orthogonal' } }\n * );\n * ```\n */\nexport const createConnections = (\n definitions: ArcConnectionDefinitionType[],\n options?: ArcOptionsType\n): Arclace => {\n const arclace = new Arclace(options);\n\n try {\n arclace.connectAll(definitions);\n } catch (error) {\n // Don't leave an overlay and its listeners behind\n arclace.destroy();\n throw error;\n }\n\n return arclace;\n};\n"],"names":["ArclaceError","message","options","__publicField","NORMALS","OPPOSITE","isHorizontalSide","side","center","rect","add","a","b","factor","distance","round","value","fmt","point","uniqueID","SIDES","SIDE_OPTIONS","PATH_TYPES","ARROWS","show","assertObject","name","assertOneOf","allowed","list","item","assertNumber","min","assertBoolean","assertString","nonEmpty","assertPoint","x","y","CONNECTION_OPTION_CHECKS","validateConnectionOptions","key","check","validateOptions","autoUpdate","className","defaults","normalizeDistance","maxDistance","lerp","norm","max","curveMultiplierFromDistance","checkEnds","start","startSide","end","endSide","straightPath","bezierPath","curvature","length","bulge","c1","c2","simplifyPolyline","points","unique","i","prev","next","cross","roundedPolyline","radius","towards","from","to","total","segments","corner","r","polylineMidpoint","lengths","remaining","sum","t","SWAPPED_SIDE","swap","routeOrthogonal","offset","n1","n2","s1","s2","midX","midY","orthogonalPath","SVG_NS","createSVGElement","tagName","attributes","el","setAttributes","DEFAULT_CONNECTION_OPTIONS","definedOnly","ARROW_SIZE","_Connection","params","__privateAdd","_Connection_instances","_geometry","_removed","_owner","_options","_defaults","_marker","_label","_anchors","id","startElement","endElement","owner","__privateSet","__privateMethod","applyOptions_fn","__privateGet","arrow","strokeWidth","arrowLength","pathStart","pullBack_fn","pathEnd","d","labelPoint","buildPath_fn","type","other","amount","label","color","dashed","animated","anchors","classes","applyArrow_fn","applyLabel_fn","applyAnchors_fn","_a","url","anchor","Connection","getOrigin","svg","clientWidth","clientHeight","getLocalRect","origin","left","top","width","height","isRendered","querySelector","selector","error","resolveElement","target","facingSide","dx","dy","gapX","gapY","resolveSides","startRect","endRect","getAnchorPoint","index","count","spacing","gap","step","shift","cx","cy","nextFrame","callback","cancelFrame","handle","Arclace","_Arclace_instances","_connections","_frame","_loop","_destroyed","_resizeObserver","_mutationObserver","_originalPosition","_scheduleUpdate","startAutoUpdate_fn","connection","add_fn","prepare_fn","definitions","ids","connections","definition","removed","unobserve_fn","items","slots","addToSlot","otherRect","slot","spread","sides","solo","entries","entry","_b","startTarget","endTarget","valid","loop","records","record","createConnections","arclace"],"mappings":"40BAkBO,MAAMA,UAAqB,KAAM,CAGtC,YAAYC,EAAiBC,EAAwB,CACnD,MAAM,YAA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Q,KAAMC,GAAW,CAAC,KAAK,IAAI,SAASA,EAAO,MAAM,CAAC,GAC5DnG,EAAA,KAAKwE,GAAL,UAEJ,CAAC,GACDxE,EAAA,KAAKsE,GAAkB,QAAQ,KAAK,UAAW,CAC7C,QAAS,GACT,UAAW,GACX,WAAY,GACZ,gBAAiB,CAAC,QAAS,QAAS,QAAQ,CAAA,CAC7C,IAGHhD,EAAA,SAAS,QAAT,MAAAA,EAAgB,MAAM,KAAKtB,EAAA,KAAKwE,IAClC,EAmBK,MAAM4B,GAAoB,CAC/BvB,EACAxM,IACY,CACZ,MAAMgO,EAAU,IAAItC,GAAQ1L,CAAO,EAEnC,GAAI,CACFgO,EAAQ,WAAWxB,CAAW,CAChC,OAAStC,EAAO,CAEd,MAAA8D,EAAQ,QAAA,EACF9D,CACR,CAEA,OAAO8D,CACT"}
|
|
1
|
+
{"version":3,"file":"arclace.umd.cjs","sources":["../src/errors.ts","../src/utils/geometry.ts","../src/utils/id.ts","../src/utils/validate.ts","../src/utils/paths.ts","../src/utils/svg.ts","../src/Connection.ts","../src/utils/measure.ts","../src/utils/resolve-element.ts","../src/utils/sides.ts","../src/Arclace.ts"],"sourcesContent":["/**\n * Thrown when Arclace can't do what was asked, for example when a selector\n * matches nothing, an id is taken, or the instance has been destroyed.\n *\n * Arguments of the wrong type throw a `TypeError`, and values out of range a\n * `RangeError`, instead. When another error is behind the failure, such as\n * an invalid selector, it is the `cause`.\n *\n * @example\n * ```ts\n * try {\n * arclace.connect('#a', '#b', { id: 'a-to-b' });\n * arclace.connect('#b', '#c', { id: 'a-to-b' }); // the id is taken\n * } catch (error) {\n * if (error instanceof ArclaceError) console.warn(error.message);\n * }\n * ```\n */\nexport class ArclaceError extends Error {\n override name = 'ArclaceError';\n\n constructor(message: string, options?: ErrorOptions) {\n super(`arclace: ${message}`, options);\n }\n}\n","import type {\n ArcPointInterface,\n ArcRectInterface,\n ArcSideType\n} from '../types';\n\n/**\n * Unit vectors pointing away from each side of a box.\n */\nexport const NORMALS: Readonly<\n Record<ArcSideType, Readonly<ArcPointInterface>>\n> = Object.freeze({\n top: Object.freeze({ x: 0, y: -1 }),\n right: Object.freeze({ x: 1, y: 0 }),\n bottom: Object.freeze({ x: 0, y: 1 }),\n left: Object.freeze({ x: -1, y: 0 })\n});\n\nexport const OPPOSITE: Readonly<Record<ArcSideType, ArcSideType>> =\n Object.freeze({\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right'\n });\n\nexport const isHorizontalSide = (side: ArcSideType): boolean =>\n side === 'left' || side === 'right';\n\nexport const center = (rect: ArcRectInterface): ArcPointInterface => ({\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2\n});\n\nexport const add = (\n a: ArcPointInterface,\n b: ArcPointInterface,\n factor = 1\n): ArcPointInterface => ({ x: a.x + b.x * factor, y: a.y + b.y * factor });\n\n/**\n * Euclidean distance between two points.\n *\n * @example\n * ```ts\n * distance({ x: 0, y: 0 }, { x: 3, y: 4 }); // 5\n * ```\n */\nexport const distance = (a: ArcPointInterface, b: ArcPointInterface): number =>\n Math.hypot(b.x - a.x, b.y - a.y);\n\n/**\n * Rounds to two decimals to keep path data short.\n */\nexport const round = (value: number): number => Math.round(value * 100) / 100;\n\n/**\n * Formats a point for use in SVG path data.\n */\nexport const fmt = (point: ArcPointInterface): string =>\n `${round(point.x)} ${round(point.y)}`;\n","/**\n * Generates a unique ID consisting of an underscore followed by a random alphanumeric string.\n *\n * @returns {string} - A unique ID.\n *\n * @example\n * ```ts\n * // Generate a unique ID\n * const id = uniqueID();\n * console.log(id); // Example output: \"_abc123def\"\n * ```\n */\nexport const uniqueID = (): string =>\n '_' + Math.random().toString(36).substring(2, 11);\n","import type {\n ArcArrowType,\n ArcConnectionOptionsType,\n ArcOptionsType,\n ArcPathType,\n ArcPointInterface,\n ArcSideOptionType,\n ArcSideType\n} from '../types';\n\nexport const SIDES: readonly ArcSideType[] = Object.freeze([\n 'top',\n 'right',\n 'bottom',\n 'left'\n]);\n\nexport const SIDE_OPTIONS: readonly ArcSideOptionType[] = Object.freeze([\n ...SIDES,\n 'auto'\n]);\n\nexport const PATH_TYPES: readonly ArcPathType[] = Object.freeze([\n 'bezier',\n 'straight',\n 'orthogonal'\n]);\n\nexport const ARROWS: readonly ArcArrowType[] = Object.freeze([\n 'none',\n 'start',\n 'end',\n 'both'\n]);\n\n/**\n * A short description of a value for an error message, which never calls\n * the value's own `toString`.\n */\nconst show = (value: unknown): string => {\n if (typeof value === 'string') return JSON.stringify(value);\n\n if (\n value === null ||\n value === undefined ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n )\n return String(value);\n\n if (Array.isArray(value)) return 'an array';\n\n return typeof value === 'object' ? 'an object' : `a ${typeof value}`;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a plain object (not `null` or an\n * array).\n */\nexport const assertObject = (value: unknown, name: string): void => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError(\n `arclace: ${name} must be an object, not ${show(value)}`\n );\n }\n};\n\n/**\n * Throws a `TypeError` unless `value` is a string, and a `RangeError` unless\n * it is one of `allowed`.\n */\nexport const assertOneOf = <T extends string>(\n value: unknown,\n allowed: readonly T[],\n name: string\n): T => {\n const list = allowed.map((item) => `\"${item}\"`).join(', ');\n\n if (typeof value !== 'string') {\n throw new TypeError(\n `arclace: ${name} must be one of ${list}, not ${show(value)}`\n );\n }\n\n if (!allowed.includes(value as T)) {\n throw new RangeError(\n `arclace: ${name} must be one of ${list}, not ${show(value)}`\n );\n }\n\n return value as T;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a finite number, and a `RangeError`\n * when it is below `min`.\n */\nexport const assertNumber = (\n value: unknown,\n name: string,\n min?: number\n): number => {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new TypeError(\n `arclace: ${name} must be a finite number, not ${show(value)}`\n );\n }\n\n if (min !== undefined && value < min) {\n throw new RangeError(\n `arclace: ${name} must be ${min} or more, not ${show(value)}`\n );\n }\n\n return value;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a boolean.\n */\nexport const assertBoolean = (value: unknown, name: string): boolean => {\n if (typeof value !== 'boolean') {\n throw new TypeError(\n `arclace: ${name} must be true or false, not ${show(value)}`\n );\n }\n\n return value;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a string, or, with `nonEmpty`, a\n * string with at least one character.\n */\nexport const assertString = (\n value: unknown,\n name: string,\n nonEmpty = false\n): string => {\n if (typeof value !== 'string' || (nonEmpty && value === '')) {\n throw new TypeError(\n `arclace: ${name} must be a ${nonEmpty ? 'non-empty ' : ''}string, not ${show(value)}`\n );\n }\n\n return value;\n};\n\n/**\n * Throws a `TypeError` unless `value` is a point with finite `x` and `y`.\n */\nexport const assertPoint = (\n value: unknown,\n name: string\n): ArcPointInterface => {\n assertObject(value, name);\n\n const { x, y } = value as Record<string, unknown>;\n\n assertNumber(x, `${name}.x`);\n assertNumber(y, `${name}.y`);\n\n return value as ArcPointInterface;\n};\n\n// How each connection option is checked. Keys that aren't listed are ignored.\nconst CONNECTION_OPTION_CHECKS: Readonly<\n Record<\n keyof ArcConnectionOptionsType,\n (value: unknown, name: string) => unknown\n >\n> = Object.freeze({\n id: (value, name) => assertString(value, name, true),\n type: (value, name) => assertOneOf(value, PATH_TYPES, name),\n startSide: (value, name) => assertOneOf(value, SIDE_OPTIONS, name),\n endSide: (value, name) => assertOneOf(value, SIDE_OPTIONS, name),\n arrow: (value, name) => assertOneOf(value, ARROWS, name),\n label: assertString,\n color: assertString,\n className: assertString,\n strokeWidth: (value, name) => assertNumber(value, name, 0),\n dashed: assertBoolean,\n animated: assertBoolean,\n anchors: assertBoolean,\n gap: (value, name) => assertNumber(value, name),\n spread: assertBoolean,\n spacing: (value, name) => assertNumber(value, name, 0),\n curvature: (value, name) => assertNumber(value, name),\n radius: (value, name) => assertNumber(value, name, 0),\n offset: (value, name) => assertNumber(value, name, 0)\n});\n\n/**\n * Checks every known connection option that is set. `undefined` means \"use\n * the default\" and is always allowed; unknown keys are ignored.\n *\n * @throws {TypeError} When `options` isn't an object, or an option has the\n * wrong type.\n * @throws {RangeError} When an option is out of range.\n */\nexport const validateConnectionOptions = (\n options: unknown,\n name = 'options'\n): ArcConnectionOptionsType => {\n assertObject(options, name);\n\n for (const [key, check] of Object.entries(CONNECTION_OPTION_CHECKS)) {\n const value = Object.hasOwn(options as object, key)\n ? (options as Record<string, unknown>)[key]\n : undefined;\n\n if (value !== undefined) check(value, `${name}.${key}`);\n }\n\n return options as ArcConnectionOptionsType;\n};\n\n/**\n * Checks the options of an instance, including its connection defaults.\n */\nexport const validateOptions = (options: unknown): ArcOptionsType => {\n assertObject(options, 'options');\n\n const { autoUpdate, className, defaults } = options as Record<\n string,\n unknown\n >;\n\n if (\n autoUpdate !== undefined &&\n typeof autoUpdate !== 'boolean' &&\n autoUpdate !== 'frame'\n ) {\n throw new RangeError(\n `arclace: options.autoUpdate must be true, false or \"frame\", not ${show(autoUpdate)}`\n );\n }\n\n if (className !== undefined) assertString(className, 'options.className');\n\n if (defaults !== undefined) {\n validateConnectionOptions(defaults, 'options.defaults');\n\n // Every connection would get the same id, so only the first could be made\n if ((defaults as ArcConnectionOptionsType).id !== undefined) {\n throw new TypeError(\n 'arclace: options.defaults cannot set an id; ids belong to single connections'\n );\n }\n }\n\n return options as ArcOptionsType;\n};\n","import type { ArcPointInterface, ArcSideType } from '../types';\n\nimport {\n add,\n distance,\n fmt,\n isHorizontalSide,\n NORMALS,\n OPPOSITE\n} from './geometry';\nimport { assertNumber, assertOneOf, assertPoint, SIDES } from './validate';\n\nexport type ArcPathResultType = {\n /**\n * SVG path data.\n */\n d: string;\n\n /**\n * The middle of the path, used to place labels.\n */\n labelPoint: ArcPointInterface;\n};\n\n/**\n * Normalizes a distance to a range from 0 to 1, based on max distance.\n *\n * @param distance - The actual distance.\n * @param maxDistance - The distance treated as 100% (1.0).\n * @returns Normalized value between 0 and 1.\n */\nexport const normalizeDistance = (\n distance: number,\n maxDistance: number = 1000\n): number => Math.min(distance / maxDistance, 1);\n\n/**\n * Maps a normalized value [0, 1] to a value between min and max.\n *\n * @param norm - Normalized value (0 to 1).\n * @param min - Minimum output value.\n * @param max - Maximum output value.\n * @returns Value between min and max.\n */\nexport const lerp = (norm: number, min: number, max: number): number =>\n min + (max - min) * norm;\n\n/**\n * Calculates a curve multiplier based on distance. Short lines get a\n * relatively larger bulge than long lines.\n *\n * @param distance - Distance between points.\n * @param min - Minimum multiplier.\n * @param max - Maximum multiplier.\n * @param maxDistance - Distance at which max multiplier is used.\n * @returns A multiplier between min and max.\n */\nexport const curveMultiplierFromDistance = (\n distance: number,\n min: number = 1.1,\n max: number = 3.5,\n maxDistance: number = 1000\n): number => lerp(normalizeDistance(distance, maxDistance), min, max);\n\n/**\n * Checks the ends of a path, so a bad side or point fails with a clear error\n * instead of path data with `NaN` in it.\n */\nconst checkEnds = (\n start: unknown,\n startSide: unknown,\n end: unknown,\n endSide: unknown\n): void => {\n assertPoint(start, 'start');\n assertOneOf(startSide, SIDES, 'startSide');\n assertPoint(end, 'end');\n assertOneOf(endSide, SIDES, 'endSide');\n};\n\n/**\n * A straight line between two points.\n *\n * @throws {TypeError} When a point doesn't have finite `x` and `y`.\n * @example\n * ```ts\n * straightPath({ x: 0, y: 0 }, { x: 100, y: 0 }).d; // 'M 0 0 L 100 0'\n * ```\n */\nexport const straightPath = (\n start: ArcPointInterface,\n end: ArcPointInterface\n): ArcPathResultType => {\n assertPoint(start, 'start');\n assertPoint(end, 'end');\n\n return {\n d: `M ${fmt(start)} L ${fmt(end)}`,\n labelPoint: { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 }\n };\n};\n\n/**\n * A cubic bezier curve that leaves `start` and arrives at `end`\n * perpendicular to their sides.\n *\n * @throws {TypeError} When a point or `curvature` isn't finite.\n * @throws {RangeError} When a side isn't `top`, `right`, `bottom` or `left`.\n * @example\n * ```ts\n * bezierPath({ x: 0, y: 0 }, 'right', { x: 200, y: 100 }, 'left').d;\n * ```\n */\nexport const bezierPath = (\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType,\n curvature = 1\n): ArcPathResultType => {\n checkEnds(start, startSide, end, endSide);\n assertNumber(curvature, 'curvature');\n\n const length = distance(start, end);\n const bulge = (length / curveMultiplierFromDistance(length)) * curvature;\n const c1 = add(start, NORMALS[startSide], bulge);\n const c2 = add(end, NORMALS[endSide], bulge);\n\n return {\n d: `M ${fmt(start)} C ${fmt(c1)}, ${fmt(c2)}, ${fmt(end)}`,\n // Point on the curve at t = 0.5\n labelPoint: {\n x: (start.x + 3 * c1.x + 3 * c2.x + end.x) / 8,\n y: (start.y + 3 * c1.y + 3 * c2.y + end.y) / 8\n }\n };\n};\n\n/**\n * Removes repeated points and points in the middle of a straight segment.\n */\nexport const simplifyPolyline = (\n points: ArcPointInterface[]\n): ArcPointInterface[] => {\n const unique = points.filter(\n (point, i) => i === 0 || distance(point, points[i - 1]) > 0.01\n );\n\n return unique.filter((point, i) => {\n if (i === 0 || i === unique.length - 1) return true;\n\n const prev = unique[i - 1];\n const next = unique[i + 1];\n const cross =\n (point.x - prev.x) * (next.y - prev.y) -\n (point.y - prev.y) * (next.x - prev.x);\n\n return Math.abs(cross) > 0.01;\n });\n};\n\n/**\n * Turns a polyline into path data, rounding each corner with a quadratic\n * curve. The radius shrinks on short segments so corners never overlap.\n */\nexport const roundedPolyline = (\n points: ArcPointInterface[],\n radius: number\n): string => {\n if (points.length === 0) return '';\n\n const towards = (\n from: ArcPointInterface,\n to: ArcPointInterface,\n length: number\n ): ArcPointInterface => {\n const total = distance(from, to);\n\n return {\n x: from.x + ((to.x - from.x) / total) * length,\n y: from.y + ((to.y - from.y) / total) * length\n };\n };\n const segments = [`M ${fmt(points[0])}`];\n\n for (let i = 1; i < points.length - 1; i++) {\n const prev = points[i - 1];\n const corner = points[i];\n const next = points[i + 1];\n const r = Math.min(\n radius,\n distance(prev, corner) / 2,\n distance(corner, next) / 2\n );\n\n if (r <= 0) {\n segments.push(`L ${fmt(corner)}`);\n continue;\n }\n\n segments.push(\n `L ${fmt(towards(corner, prev, r))}`,\n `Q ${fmt(corner)}, ${fmt(towards(corner, next, r))}`\n );\n }\n\n if (points.length > 1) segments.push(`L ${fmt(points[points.length - 1])}`);\n\n return segments.join(' ');\n};\n\n/**\n * The point halfway along a polyline.\n */\nexport const polylineMidpoint = (\n points: ArcPointInterface[]\n): ArcPointInterface => {\n const lengths = points.slice(1).map((point, i) => distance(points[i], point));\n\n let remaining = lengths.reduce((sum, length) => sum + length, 0) / 2;\n\n for (let i = 0; i < lengths.length; i++) {\n if (remaining <= lengths[i] && lengths[i] > 0) {\n const t = remaining / lengths[i];\n\n return {\n x: points[i].x + (points[i + 1].x - points[i].x) * t,\n y: points[i].y + (points[i + 1].y - points[i].y) * t\n };\n }\n\n remaining -= lengths[i];\n }\n\n return { ...points[0] };\n};\n\n// Swapping x and y turns vertical sides into horizontal ones, so only the\n// horizontal case has to be routed by hand.\nconst SWAPPED_SIDE: Readonly<Record<ArcSideType, ArcSideType>> = Object.freeze({\n top: 'left',\n bottom: 'right',\n left: 'top',\n right: 'bottom'\n});\nconst swap = (point: ArcPointInterface): ArcPointInterface => ({\n x: point.y,\n y: point.x\n});\n\n/**\n * Routes a line from `start` to `end` using only horizontal and vertical\n * segments. The line leaves and arrives perpendicular to the given sides,\n * travelling at least `offset` pixels straight out before turning back.\n *\n * @returns The corner points of the route, including `start` and `end`.\n */\nexport const routeOrthogonal = (\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType,\n offset = 20\n): ArcPointInterface[] => {\n if (!isHorizontalSide(startSide)) {\n return routeOrthogonal(\n swap(start),\n SWAPPED_SIDE[startSide],\n swap(end),\n SWAPPED_SIDE[endSide],\n offset\n ).map(swap);\n }\n\n const n1 = NORMALS[startSide];\n const n2 = NORMALS[endSide];\n const s1 = add(start, n1, offset);\n const s2 = add(end, n2, offset);\n\n if (isHorizontalSide(endSide)) {\n if (endSide === OPPOSITE[startSide]) {\n // Facing each other with room in between: turn halfway\n if ((s2.x - s1.x) * n1.x >= 0) {\n const midX = (start.x + end.x) / 2;\n\n return [start, { x: midX, y: start.y }, { x: midX, y: end.y }, end];\n }\n\n // Facing away from each other: step out, cross over halfway, step in\n const midY = (s1.y + s2.y) / 2;\n\n return [start, s1, { x: s1.x, y: midY }, { x: s2.x, y: midY }, s2, end];\n }\n\n // Same side: go around the outside of both\n const x = n1.x > 0 ? Math.max(s1.x, s2.x) : Math.min(s1.x, s2.x);\n\n return [start, { x, y: start.y }, { x, y: end.y }, end];\n }\n\n // One horizontal and one vertical side: a single corner if it lies in\n // front of both sides, otherwise step out of both and meet\n const corner = { x: end.x, y: start.y };\n\n if ((corner.x - start.x) * n1.x > 0 && (corner.y - end.y) * n2.y > 0) {\n return [start, corner, end];\n }\n\n return [start, s1, { x: s1.x, y: s2.y }, s2, end];\n};\n\n/**\n * An orthogonal line with rounded corners.\n *\n * @throws {TypeError} When a point, `radius` or `offset` isn't finite.\n * @throws {RangeError} When a side isn't `top`, `right`, `bottom` or `left`,\n * or `radius` or `offset` is negative.\n * @example\n * ```ts\n * orthogonalPath({ x: 0, y: 0 }, 'right', { x: 200, y: 100 }, 'left', {\n * radius: 8,\n * offset: 20\n * }).d;\n * ```\n */\nexport const orthogonalPath = (\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType,\n { radius = 8, offset = 20 }: { radius?: number; offset?: number } = {}\n): ArcPathResultType => {\n checkEnds(start, startSide, end, endSide);\n assertNumber(radius, 'radius', 0);\n assertNumber(offset, 'offset', 0);\n\n const points = simplifyPolyline(\n routeOrthogonal(start, startSide, end, endSide, offset)\n );\n\n return {\n d: roundedPolyline(points, radius),\n labelPoint: polylineMidpoint(points)\n };\n};\n","export const SVG_NS = 'http://www.w3.org/2000/svg';\n\n/**\n * Creates an SVG element with the given attributes.\n *\n * @example\n * ```ts\n * const path = createSVGElement('path', { fill: 'none' });\n * ```\n */\nexport const createSVGElement = <K extends keyof SVGElementTagNameMap>(\n tagName: K,\n attributes: Record<string, string | number> = {}\n): SVGElementTagNameMap[K] => {\n const el = document.createElementNS(SVG_NS, tagName);\n\n setAttributes(el, attributes);\n\n return el;\n};\n\n/**\n * Sets attributes on an element. `null` and `undefined` values remove the\n * attribute.\n */\nexport const setAttributes = (\n el: Element,\n attributes: Record<string, string | number | null | undefined>\n): void => {\n for (const [name, value] of Object.entries(attributes)) {\n if (value === null || value === undefined) el.removeAttribute(name);\n else el.setAttribute(name, String(value));\n }\n};\n","import type { Arclace } from './Arclace';\nimport { ArclaceError } from './errors';\nimport type {\n ArcConnectionOptionsType,\n ArcGeometryType,\n ArcPointInterface,\n ArcSideType\n} from './types';\nimport { add, distance, NORMALS } from './utils/geometry';\nimport { uniqueID } from './utils/id';\nimport {\n bezierPath,\n type ArcPathResultType,\n orthogonalPath,\n straightPath\n} from './utils/paths';\nimport { createSVGElement, setAttributes } from './utils/svg';\nimport { validateConnectionOptions } from './utils/validate';\n\n/**\n * Connection options with every default filled in. `label`, `color` and\n * `className` have no default.\n */\nexport type ArcResolvedConnectionOptionsType = Required<\n Omit<ArcConnectionOptionsType, 'id' | 'label' | 'color' | 'className'>\n> &\n Pick<ArcConnectionOptionsType, 'label' | 'color' | 'className'> & {\n id: string;\n };\n\n/**\n * Options every connection falls back to. Frozen: set your own defaults with\n * the `defaults` option of {@link Arclace} instead.\n */\nexport const DEFAULT_CONNECTION_OPTIONS: Readonly<\n Required<\n Omit<ArcConnectionOptionsType, 'id' | 'label' | 'color' | 'className'>\n >\n> = Object.freeze({\n type: 'bezier',\n startSide: 'auto',\n endSide: 'auto',\n arrow: 'none',\n strokeWidth: 2,\n dashed: false,\n animated: false,\n anchors: false,\n gap: 0,\n spread: true,\n spacing: 16,\n curvature: 1,\n radius: 8,\n offset: 20\n});\n\n/**\n * Drops options set to `undefined`, so they fall back to the defaults instead\n * of replacing them.\n */\nconst definedOnly = (\n options: ArcConnectionOptionsType\n): ArcConnectionOptionsType =>\n Object.fromEntries(\n Object.entries(options).filter(([, value]) => value !== undefined)\n );\n// Arrow length in multiples of the stroke width\nconst ARROW_SIZE = 4;\n\ntype ArcConnectionParamsType = {\n id: string;\n startElement: Element;\n endElement: Element;\n options: ArcConnectionOptionsType;\n defaults?: ArcConnectionOptionsType;\n owner: Arclace;\n};\n\n/**\n * A line between two elements. Created with {@link Arclace.connect} or\n * {@link Arclace.connectAll}, not with `new`.\n *\n * Each connection renders as:\n *\n * ```html\n * <g class=\"arc-connection arc-bezier\">\n * <marker class=\"arc-marker\">…</marker> <!-- when `arrow` is set -->\n * <path class=\"arc-path\" />\n * <rect class=\"arc-label-bg\" /> <!-- when `label` is set -->\n * <text class=\"arc-label\">…</text>\n * <circle class=\"arc-anchor arc-anchor-start\" /> <!-- when `anchors` is set -->\n * <circle class=\"arc-anchor arc-anchor-end\" />\n * </g>\n * ```\n *\n * The line, arrows and anchors use `currentColor`, so setting `color` on\n * `.arc-connection` colors all of them.\n */\nexport class Connection {\n readonly id: string;\n readonly startElement: Element;\n readonly endElement: Element;\n\n /**\n * The `<g>` element holding everything this connection draws.\n */\n readonly element: SVGGElement;\n\n /**\n * The `<path>` element of the line.\n */\n readonly path: SVGPathElement;\n\n #geometry: ArcGeometryType | null = null;\n #removed = false;\n #owner: Arclace;\n #options: ArcConnectionOptionsType;\n #defaults: ArcConnectionOptionsType;\n #marker: SVGMarkerElement | null = null;\n #label: SVGTextElement | null = null;\n #labelBg: SVGRectElement | null = null;\n // The background's box relative to the label's anchor point, measured once\n // per label\n #labelBox: { x: number; y: number; width: number; height: number } | null =\n null;\n #anchors: [SVGCircleElement, SVGCircleElement] | null = null;\n\n private constructor(params: ArcConnectionParamsType) {\n const {\n id,\n startElement,\n endElement,\n options,\n defaults = {},\n owner\n } = params;\n\n this.id = id;\n this.startElement = startElement;\n this.endElement = endElement;\n this.#owner = owner;\n this.#options = { ...options };\n this.#defaults = defaults;\n this.element = createSVGElement('g', { 'data-arc-id': id });\n this.path = createSVGElement('path', {\n class: 'arc-path',\n fill: 'none',\n stroke: 'currentColor'\n });\n this.element.appendChild(this.path);\n this.#applyOptions();\n }\n\n /**\n * Creates a connection for its owner. Options must already be validated.\n *\n * @internal\n */\n static _create(params: ArcConnectionParamsType): Connection {\n return new Connection(params);\n }\n\n /**\n * The geometry from the last update, or `null` when the connection is\n * hidden because one of its elements is not rendered.\n */\n get geometry(): Readonly<ArcGeometryType> | null {\n return this.#geometry;\n }\n\n /**\n * The connection's options merged with the instance defaults.\n */\n get options(): Readonly<ArcResolvedConnectionOptionsType> {\n return {\n ...DEFAULT_CONNECTION_OPTIONS,\n ...definedOnly(this.#defaults),\n ...definedOnly(this.#options),\n id: this.id\n };\n }\n\n /**\n * Changes options and redraws.\n *\n * @example\n * ```ts\n * connection.setOptions({ type: 'orthogonal', arrow: 'end' });\n * ```\n * @throws {TypeError} When an option has the wrong type, or `id` is set.\n * @throws {RangeError} When an option is out of range.\n * @throws {ArclaceError} When the connection has been removed.\n */\n setOptions(options: Omit<ArcConnectionOptionsType, 'id'>): this {\n if (this.#removed) {\n throw new ArclaceError(`connection \"${this.id}\" has been removed`);\n }\n\n validateConnectionOptions(options);\n\n if ((options as ArcConnectionOptionsType).id !== undefined) {\n throw new TypeError('arclace: setOptions() cannot change the id');\n }\n\n this.#options = { ...this.#options, ...options };\n this.#applyOptions();\n this.#owner.update();\n\n return this;\n }\n\n /**\n * Redraws every connection of the owning instance.\n */\n update(): void {\n this.#owner.update();\n }\n\n /**\n * Removes this connection.\n */\n remove(): void {\n this.#owner.disconnect(this);\n }\n\n /**\n * Draws the connection between two attachment points.\n *\n * @internal\n */\n _draw(\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType\n ): void {\n const { arrow, strokeWidth } = this.options;\n const arrowLength = ARROW_SIZE * strokeWidth;\n // Shorten the line so arrow tips, not the line's end caps, touch the\n // elements\n const pathStart =\n arrow === 'start' || arrow === 'both'\n ? this.#pullBack(start, startSide, end, arrowLength)\n : start;\n const pathEnd =\n arrow === 'end' || arrow === 'both'\n ? this.#pullBack(end, endSide, start, arrowLength)\n : end;\n const { d, labelPoint } = this.#buildPath(\n pathStart,\n startSide,\n pathEnd,\n endSide\n );\n\n this.#geometry = Object.freeze({\n start,\n end,\n startSide,\n endSide,\n labelPoint,\n d\n });\n\n this.element.removeAttribute('display');\n setAttributes(this.element, {\n 'data-start-side': startSide,\n 'data-end-side': endSide\n });\n this.path.setAttribute('d', d);\n\n if (this.#label) this.#placeLabel(labelPoint);\n\n if (this.#anchors) {\n setAttributes(this.#anchors[0], { cx: start.x, cy: start.y });\n setAttributes(this.#anchors[1], { cx: end.x, cy: end.y });\n }\n }\n\n /**\n * Hides the connection.\n *\n * @internal\n */\n _hide(): void {\n this.#geometry = null;\n this.element.setAttribute('display', 'none');\n }\n\n /**\n * Removes the connection's elements from the overlay.\n *\n * @internal\n */\n _dispose(): void {\n this.#removed = true;\n this.element.remove();\n }\n\n #buildPath(\n start: ArcPointInterface,\n startSide: ArcSideType,\n end: ArcPointInterface,\n endSide: ArcSideType\n ): ArcPathResultType {\n const { type, curvature, radius, offset } = this.options;\n\n if (type === 'straight') return straightPath(start, end);\n\n if (type === 'orthogonal') {\n return orthogonalPath(start, startSide, end, endSide, {\n radius,\n offset\n });\n }\n\n return bezierPath(start, startSide, end, endSide, curvature);\n }\n\n #pullBack(\n point: ArcPointInterface,\n side: ArcSideType,\n other: ArcPointInterface,\n length: number\n ): ArcPointInterface {\n const total = distance(point, other);\n const amount = Math.min(length, total / 3);\n\n if (this.options.type !== 'straight') {\n return add(point, NORMALS[side], amount);\n }\n\n if (total === 0) return point;\n\n return {\n x: point.x + ((other.x - point.x) / total) * amount,\n y: point.y + ((other.y - point.y) / total) * amount\n };\n }\n\n #applyOptions(): void {\n const {\n type,\n arrow,\n label,\n color,\n strokeWidth,\n dashed,\n animated,\n anchors,\n className\n } = this.options;\n const classes = ['arc-connection', `arc-${type}`];\n\n if (dashed || animated) classes.push('arc-dashed');\n\n if (animated) classes.push('arc-animated');\n\n if (className) classes.push(...className.split(/\\s+/).filter(Boolean));\n\n setAttributes(this.element, {\n class: classes.join(' '),\n 'data-type': type\n });\n // Inline so it wins over the stylesheet's --arc-color\n this.element.style.color = color ?? '';\n\n setAttributes(this.path, {\n 'stroke-width': strokeWidth,\n 'stroke-dasharray': dashed || animated ? '6 6' : null\n });\n\n this.#applyArrow(arrow);\n this.#applyLabel(label);\n this.#applyAnchors(anchors, strokeWidth);\n }\n\n #applyArrow(arrow: ArcResolvedConnectionOptionsType['arrow']): void {\n if (arrow === 'none') {\n this.#marker?.remove();\n this.#marker = null;\n setAttributes(this.path, { 'marker-start': null, 'marker-end': null });\n\n return;\n }\n\n if (!this.#marker) {\n // The marker lives inside the connection's group so it inherits the\n // group's color\n this.#marker = createSVGElement('marker', {\n id: `arc-arrow-${uniqueID()}`,\n class: 'arc-marker',\n viewBox: '0 0 10 10',\n refX: 0,\n refY: 5,\n markerWidth: ARROW_SIZE,\n markerHeight: ARROW_SIZE,\n markerUnits: 'strokeWidth',\n orient: 'auto-start-reverse'\n });\n this.#marker.appendChild(\n createSVGElement('path', {\n d: 'M 0 0 L 10 5 L 0 10 z',\n fill: 'currentColor'\n })\n );\n this.element.insertBefore(this.#marker, this.path);\n }\n\n const url = `url(#${this.#marker.id})`;\n\n setAttributes(this.path, {\n 'marker-start': arrow === 'start' || arrow === 'both' ? url : null,\n 'marker-end': arrow === 'end' || arrow === 'both' ? url : null\n });\n }\n\n #placeLabel(point: ArcPointInterface): void {\n setAttributes(this.#label!, { ...point });\n\n // shortcut: measured once per label change, so a font or padding change\n // from CSS alone needs a setOptions() call to resize the background\n // getBBox is missing where there is no layout, such as jsdom\n if (!this.#labelBox?.width && typeof this.#label!.getBBox === 'function') {\n const { x, y, width, height } = this.#label!.getBBox();\n // CSS padding doesn't apply to SVG, but its computed value is in px,\n // so the stylesheet sets it on the background and it is read here\n const style = getComputedStyle(this.#labelBg!);\n const [top, right, bottom, left] = [\n style.paddingTop,\n style.paddingRight,\n style.paddingBottom,\n style.paddingLeft\n ].map((value) => parseFloat(value) || 0);\n\n this.#labelBox = {\n x: x - point.x - left,\n y: y - point.y - top,\n width: width + left + right,\n height: height + top + bottom\n };\n }\n\n if (!this.#labelBox) return;\n\n setAttributes(this.#labelBg!, {\n x: point.x + this.#labelBox.x,\n y: point.y + this.#labelBox.y,\n width: this.#labelBox.width,\n height: this.#labelBox.height\n });\n }\n\n #applyLabel(label: string | undefined): void {\n this.#labelBox = null;\n\n if (!label) {\n this.#label?.remove();\n this.#labelBg?.remove();\n this.#label = null;\n this.#labelBg = null;\n\n return;\n }\n\n if (!this.#label) {\n this.#label = createSVGElement('text', {\n class: 'arc-label',\n fill: 'currentColor',\n 'text-anchor': 'middle',\n 'dominant-baseline': 'central'\n });\n // Invisible without the stylesheet, which fills it\n this.#labelBg = createSVGElement('rect', {\n class: 'arc-label-bg',\n fill: 'none',\n rx: 4\n });\n this.path.after(this.#labelBg, this.#label);\n }\n\n this.#label.textContent = label;\n\n if (this.#geometry) this.#placeLabel(this.#geometry.labelPoint);\n }\n\n #applyAnchors(anchors: boolean, strokeWidth: number): void {\n if (!anchors) {\n this.#anchors?.forEach((anchor) => anchor.remove());\n this.#anchors = null;\n\n return;\n }\n\n if (!this.#anchors) {\n this.#anchors = [\n createSVGElement('circle', { class: 'arc-anchor arc-anchor-start' }),\n createSVGElement('circle', { class: 'arc-anchor arc-anchor-end' })\n ];\n this.element.append(...this.#anchors);\n }\n\n this.#anchors.forEach((anchor) =>\n setAttributes(anchor, { r: strokeWidth + 2, fill: 'currentColor' })\n );\n }\n}\n","import type { ArcRectInterface } from '../types';\n\n/**\n * Where the SVG overlay is on screen, and how much it is scaled by CSS\n * transforms on its ancestors.\n */\nexport type ArcOriginType = {\n left: number;\n top: number;\n scaleX: number;\n scaleY: number;\n};\n\n/**\n * Measures the overlay so screen coordinates can be converted to coordinates\n * inside it. Because the overlay is measured directly, this works no matter\n * how the container is positioned, scrolled or scaled.\n */\nexport const getOrigin = (svg: SVGSVGElement): ArcOriginType => {\n const rect = svg.getBoundingClientRect();\n const { clientWidth, clientHeight } = svg;\n\n return {\n left: rect.left,\n top: rect.top,\n scaleX: clientWidth > 0 && rect.width > 0 ? rect.width / clientWidth : 1,\n scaleY: clientHeight > 0 && rect.height > 0 ? rect.height / clientHeight : 1\n };\n};\n\n/**\n * Measures an element in the overlay's coordinate system.\n *\n * @example\n * ```ts\n * const rect = getLocalRect(element, getOrigin(svg));\n * ```\n */\nexport const getLocalRect = (\n el: Element,\n origin: ArcOriginType\n): ArcRectInterface => {\n const rect = el.getBoundingClientRect();\n const left = (rect.left - origin.left) / origin.scaleX;\n const top = (rect.top - origin.top) / origin.scaleY;\n const width = rect.width / origin.scaleX;\n const height = rect.height / origin.scaleY;\n\n return {\n left,\n top,\n width,\n height,\n right: left + width,\n bottom: top + height\n };\n};\n\n/**\n * Whether an element is in the document and has a layout box, i.e. is not\n * `display: none`.\n */\nexport const isRendered = (el: Element): boolean =>\n el.isConnected && el.getClientRects().length > 0;\n","import { ArclaceError } from '../errors';\n\n/**\n * Runs `document.querySelector`, turning an invalid selector into an\n * {@link ArclaceError} with the browser's `SyntaxError` as the cause.\n */\nexport const querySelector = (\n selector: string,\n name = 'element'\n): Element | null => {\n try {\n return document.querySelector(selector);\n } catch (error) {\n throw new ArclaceError(`${name} \"${selector}\" is not a valid selector`, {\n cause: error\n });\n }\n};\n\n/**\n * Resolves an element or a CSS selector to an element.\n *\n * @throws {TypeError} When the target is neither an element nor a string.\n * @throws {ArclaceError} When the selector is invalid or matches nothing.\n * @example\n * ```ts\n * const el = resolveElement('#box-1');\n * ```\n */\nexport const resolveElement = (target: unknown, name = 'element'): Element => {\n if (typeof target === 'string') {\n const el = querySelector(target, name);\n\n if (!el) throw new ArclaceError(`no ${name} matches \"${target}\"`);\n\n return el;\n }\n\n if (!(target instanceof Element)) {\n throw new TypeError(\n `arclace: ${name} must be an Element or a selector string`\n );\n }\n\n return target;\n};\n","import type {\n ArcPointInterface,\n ArcRectInterface,\n ArcSideOptionType,\n ArcSideType\n} from '../types';\n\nimport { add, center, NORMALS, OPPOSITE } from './geometry';\n\n/**\n * Picks the side of `from` that faces `to`.\n *\n * Boxes that are further apart horizontally than vertically connect\n * left/right, otherwise top/bottom.\n *\n * @example\n * ```ts\n * facingSide(\n * { left: 0, top: 0, right: 100, bottom: 50, width: 100, height: 50 },\n * { left: 300, top: 0, right: 400, bottom: 50, width: 100, height: 50 }\n * ); // 'right'\n * ```\n */\nexport const facingSide = (\n from: ArcRectInterface,\n to: ArcRectInterface\n): ArcSideType => {\n const a = center(from);\n const b = center(to);\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n // Positive when the boxes are separated on that axis, negative when they overlap\n const gapX = Math.max(to.left - from.right, from.left - to.right);\n const gapY = Math.max(to.top - from.bottom, from.top - to.bottom);\n const horizontal = gapX === gapY ? Math.abs(dx) >= Math.abs(dy) : gapX > gapY;\n\n if (horizontal) return dx >= 0 ? 'right' : 'left';\n\n return dy >= 0 ? 'bottom' : 'top';\n};\n\n/**\n * Resolves `'auto'` sides for a connection between two boxes.\n *\n * @example\n * ```ts\n * resolveSides(startRect, endRect, 'auto', 'auto');\n * // { startSide: 'right', endSide: 'left' }\n * ```\n */\nexport const resolveSides = (\n startRect: ArcRectInterface,\n endRect: ArcRectInterface,\n startSide: ArcSideOptionType = 'auto',\n endSide: ArcSideOptionType = 'auto'\n): { startSide: ArcSideType; endSide: ArcSideType } => ({\n startSide: startSide === 'auto' ? facingSide(startRect, endRect) : startSide,\n endSide:\n endSide === 'auto' ? OPPOSITE[facingSide(startRect, endRect)] : endSide\n});\n\n/**\n * Returns the point on a side of a box where a line attaches.\n *\n * When `count` lines share the side, they are spread around the middle of the\n * side, `spacing` pixels apart, shrinking to fit the side if needed. `gap`\n * moves the point away from the box.\n *\n * @example\n * ```ts\n * // The second of three lines on the top side\n * getAnchorPoint(rect, 'top', { index: 1, count: 3 });\n * ```\n */\nexport const getAnchorPoint = (\n rect: ArcRectInterface,\n side: ArcSideType,\n {\n index = 0,\n count = 1,\n spacing = 16,\n gap = 0\n }: { index?: number; count?: number; spacing?: number; gap?: number } = {}\n): ArcPointInterface => {\n const length = side === 'top' || side === 'bottom' ? rect.width : rect.height;\n const step = count > 1 ? Math.min(spacing, length / count) : 0;\n const shift = (index - (count - 1) / 2) * step;\n const { x: cx, y: cy } = center(rect);\n\n let point: ArcPointInterface;\n\n switch (side) {\n case 'top':\n point = { x: cx + shift, y: rect.top };\n break;\n case 'bottom':\n point = { x: cx + shift, y: rect.bottom };\n break;\n case 'left':\n point = { x: rect.left, y: cy + shift };\n break;\n case 'right':\n point = { x: rect.right, y: cy + shift };\n break;\n }\n\n return add(point, NORMALS[side], gap);\n};\n","import { Connection } from './Connection';\nimport { ArclaceError } from './errors';\nimport type {\n ArcConnectionDefinitionType,\n ArcConnectionOptionsType,\n ArcElementTargetType,\n ArcOptionsType,\n ArcRectInterface,\n ArcSideType\n} from './types';\nimport { center, isHorizontalSide } from './utils/geometry';\nimport { uniqueID } from './utils/id';\nimport { getLocalRect, getOrigin, isRendered } from './utils/measure';\nimport { querySelector, resolveElement } from './utils/resolve-element';\nimport { getAnchorPoint, resolveSides } from './utils/sides';\nimport { createSVGElement } from './utils/svg';\nimport {\n assertObject,\n validateConnectionOptions,\n validateOptions\n} from './utils/validate';\n\ntype ArcLayoutItemType = {\n connection: Connection;\n startRect: ArcRectInterface;\n endRect: ArcRectInterface;\n startSide: ArcSideType;\n endSide: ArcSideType;\n startSlot: { index: number; count: number };\n endSlot: { index: number; count: number };\n};\n\n// A connection that has been checked and can be added\ntype ArcPreparedConnectionType = {\n id: string;\n startElement: Element;\n endElement: Element;\n options: ArcConnectionOptionsType;\n};\n\ntype ArcSlotEntryType = {\n slot: { index: number; count: number };\n // Position of the other end along the side, used to avoid crossing lines\n key: number;\n};\n\nconst nextFrame = (callback: () => void): number =>\n typeof requestAnimationFrame === 'function'\n ? requestAnimationFrame(callback)\n : (setTimeout(callback, 16) as unknown as number);\nconst cancelFrame = (handle: number): void => {\n if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(handle);\n else clearTimeout(handle);\n};\n\n/**\n * Draws and maintains SVG lines between DOM elements.\n *\n * An instance adds one `<svg class=\"arc-svg\">` overlay to its container and\n * draws every connection into it.\n *\n * @example\n * ```ts\n * import { Arclace } from '@phun-ky/arclace';\n *\n * const arclace = new Arclace({ container: '#diagram' });\n *\n * arclace.connect('#a', '#b', { arrow: 'end', label: 'depends on' });\n * ```\n */\nexport class Arclace {\n /**\n * The element the overlay was added to.\n */\n readonly container: HTMLElement;\n\n /**\n * The SVG overlay all lines are drawn in.\n */\n readonly svg: SVGSVGElement;\n\n #options: ArcOptionsType;\n #connections = new Map<string, Connection>();\n #frame = 0;\n #loop = 0;\n #destroyed = false;\n #resizeObserver: ResizeObserver | null = null;\n #mutationObserver: MutationObserver | null = null;\n #originalPosition: string | null = null;\n\n /**\n * @throws {TypeError} When an option has the wrong type.\n * @throws {RangeError} When an option is out of range.\n * @throws {ArclaceError} When there is no DOM, or the container can't be\n * found.\n */\n constructor(options: ArcOptionsType = {}) {\n if (typeof document === 'undefined') {\n throw new ArclaceError('a DOM is required');\n }\n\n this.#options = validateOptions(options);\n this.container = (\n options.container\n ? resolveElement(options.container, 'container')\n : document.body\n ) as HTMLElement;\n\n // The overlay is positioned absolutely, so the container has to be its\n // containing block for it to scroll and clip with the container\n if (\n this.container !== document.body &&\n getComputedStyle(this.container).position === 'static'\n ) {\n this.#originalPosition = this.container.style.position;\n this.container.style.position = 'relative';\n }\n\n this.svg = createSVGElement('svg', {\n class: ['arc-svg', options.className].filter(Boolean).join(' '),\n 'aria-hidden': 'true'\n });\n Object.assign(this.svg.style, {\n position: 'absolute',\n top: '0',\n left: '0',\n width: '100%',\n height: '100%',\n overflow: 'visible',\n pointerEvents: 'none'\n });\n this.container.prepend(this.svg);\n this.#startAutoUpdate();\n }\n\n /**\n * All current connections, in the order they were made.\n */\n get connections(): Connection[] {\n return [...this.#connections.values()];\n }\n\n /**\n * Connects two elements and draws the line right away.\n *\n * @param startElement - The element (or selector) the line starts at.\n * @param endElement - The element (or selector) the line ends at.\n * @param options - Options for this connection, merged over the instance defaults.\n * @throws {TypeError} When an element or an option has the wrong type.\n * @throws {RangeError} When an option is out of range.\n * @throws {ArclaceError} When an element can't be found, the id is taken\n * or the instance has been destroyed. Nothing is added.\n * @example\n * ```ts\n * const connection = arclace.connect(a, b, { type: 'orthogonal', arrow: 'end' });\n * ```\n */\n connect(\n startElement: ArcElementTargetType,\n endElement: ArcElementTargetType,\n options: ArcConnectionOptionsType = {}\n ): Connection {\n const connection = this.#add(\n this.#prepare(startElement, endElement, options, 'options')\n );\n\n this.update();\n\n return connection;\n }\n\n /**\n * Connects many pairs of elements and draws them in one go. Every\n * definition is checked first, so either all of them are added or none.\n *\n * @throws {TypeError} When `definitions` isn't an array, or an element or\n * an option has the wrong type.\n * @throws {RangeError} When an option is out of range.\n * @throws {ArclaceError} When an element can't be found, an id is taken or\n * repeated, or the instance has been destroyed.\n * @example\n * ```ts\n * arclace.connectAll([\n * { startElement: '#a', endElement: '#b' },\n * { startElement: '#a', endElement: '#c', dashed: true }\n * ]);\n * ```\n */\n connectAll(definitions: ArcConnectionDefinitionType[]): Connection[] {\n if (!Array.isArray(definitions)) {\n throw new TypeError(\n 'arclace: connectAll() needs an array of definitions'\n );\n }\n\n const ids = new Set<string>();\n const prepared = definitions.map((definition, index) => {\n const name = `definitions[${index}]`;\n\n assertObject(definition, name);\n\n const { startElement, endElement, ...options } = definition;\n const connection = this.#prepare(startElement, endElement, options, name);\n\n if (ids.has(connection.id)) {\n throw new ArclaceError(\n `${name}.id \"${connection.id}\" is used more than once`\n );\n }\n\n ids.add(connection.id);\n\n return connection;\n });\n const connections = prepared.map((connection) => this.#add(connection));\n\n this.update();\n\n return connections;\n }\n\n /**\n * Returns the connection with the given id.\n */\n get(id: string): Connection | undefined {\n return this.#connections.get(id);\n }\n\n /**\n * Returns every connection that starts or ends at an element. A selector\n * that matches nothing returns an empty array.\n *\n * @throws {TypeError} When the target is neither an element nor a string.\n * @throws {ArclaceError} When the selector is invalid.\n */\n find(target: ArcElementTargetType): Connection[] {\n const el =\n typeof target === 'string'\n ? querySelector(target)\n : resolveElement(target);\n\n if (!el) return [];\n\n return this.connections.filter(\n (connection) =>\n connection.startElement === el || connection.endElement === el\n );\n }\n\n /**\n * Removes connections.\n *\n * @param target - A connection, a connection id, or an element (or\n * selector) whose connections should all be removed. Targets that match\n * nothing, and `null` or `undefined`, are ignored.\n * @throws {TypeError} When the target is another kind of value.\n * @throws {ArclaceError} When a string is neither an id nor a valid\n * selector.\n * @example\n * ```ts\n * arclace.disconnect(connection);\n * arclace.disconnect('my-connection-id');\n * arclace.disconnect(document.querySelector('#a'));\n * ```\n */\n disconnect(target: Connection | string | Element): void {\n let removed: Connection[];\n\n if (target === null || target === undefined) return;\n\n if (target instanceof Connection) {\n removed = [target];\n } else if (typeof target === 'string' && this.#connections.has(target)) {\n removed = [this.#connections.get(target)!];\n } else if (typeof target === 'string' || target instanceof Element) {\n removed = this.find(target);\n } else {\n throw new TypeError(\n 'arclace: disconnect() needs a connection, an id, an element or a selector'\n );\n }\n\n for (const connection of removed) {\n if (this.#connections.get(connection.id) !== connection) continue;\n\n this.#connections.delete(connection.id);\n connection._dispose();\n this.#unobserve(connection.startElement);\n this.#unobserve(connection.endElement);\n }\n\n if (removed.length > 0) this.update();\n }\n\n /**\n * Removes every connection.\n */\n clear(): void {\n for (const connection of this.#connections.values()) {\n connection._dispose();\n }\n\n this.#connections.clear();\n this.#resizeObserver?.disconnect();\n\n if (this.#resizeObserver) this.#resizeObserver.observe(this.container);\n }\n\n /**\n * Remeasures every element and redraws every connection. Called\n * automatically when `autoUpdate` is on; call it yourself after moving\n * elements in ways the page can't observe.\n */\n update(): void {\n if (this.#destroyed) return;\n\n if (this.#frame) {\n cancelFrame(this.#frame);\n this.#frame = 0;\n }\n\n // Measure everything first, then write, so the browser only lays out once\n const origin = getOrigin(this.svg);\n const items: ArcLayoutItemType[] = [];\n const slots = new Map<Element, Record<ArcSideType, ArcSlotEntryType[]>>();\n const addToSlot = (\n el: Element,\n side: ArcSideType,\n otherRect: ArcRectInterface\n ): { index: number; count: number } => {\n const slot = { index: 0, count: 1 };\n const other = center(otherRect);\n\n if (!slots.has(el)) {\n slots.set(el, { top: [], right: [], bottom: [], left: [] });\n }\n\n slots.get(el)![side].push({\n slot,\n key: isHorizontalSide(side) ? other.y : other.x\n });\n\n return slot;\n };\n\n for (const connection of this.#connections.values()) {\n const { startElement, endElement } = connection;\n\n if (!isRendered(startElement) || !isRendered(endElement)) {\n connection._hide();\n continue;\n }\n\n const { spread, startSide, endSide } = connection.options;\n const startRect = getLocalRect(startElement, origin);\n const endRect = getLocalRect(endElement, origin);\n const sides = resolveSides(startRect, endRect, startSide, endSide);\n const solo = { index: 0, count: 1 };\n\n items.push({\n connection,\n startRect,\n endRect,\n ...sides,\n startSlot: spread\n ? addToSlot(startElement, sides.startSide, endRect)\n : solo,\n endSlot: spread\n ? addToSlot(endElement, sides.endSide, startRect)\n : { ...solo }\n });\n }\n\n for (const sides of slots.values()) {\n for (const entries of Object.values(sides)) {\n entries\n .sort((a, b) => a.key - b.key)\n .forEach((entry, index) => {\n entry.slot.index = index;\n entry.slot.count = entries.length;\n });\n }\n }\n\n for (const item of items) {\n const { connection, startRect, endRect, startSide, endSide } = item;\n const { spacing, gap } = connection.options;\n\n connection._draw(\n getAnchorPoint(startRect, startSide, {\n ...item.startSlot,\n spacing,\n gap\n }),\n startSide,\n getAnchorPoint(endRect, endSide, { ...item.endSlot, spacing, gap }),\n endSide\n );\n }\n }\n\n /**\n * Removes every connection and the overlay, and stops listening for\n * changes. The instance can't be used afterwards.\n */\n destroy(): void {\n if (this.#destroyed) return;\n\n this.clear();\n this.#destroyed = true;\n\n if (this.#frame) cancelFrame(this.#frame);\n\n if (this.#loop) cancelFrame(this.#loop);\n\n window.removeEventListener('resize', this.#scheduleUpdate);\n document.removeEventListener('scroll', this.#scheduleUpdate, {\n capture: true\n });\n this.#resizeObserver?.disconnect();\n this.#mutationObserver?.disconnect();\n this.svg.remove();\n\n if (this.#originalPosition !== null) {\n this.container.style.position = this.#originalPosition;\n }\n }\n\n /**\n * Checks a connection without adding anything, so a bad option can't leave\n * a connection behind that breaks every later update.\n */\n #prepare(\n startTarget: unknown,\n endTarget: unknown,\n options: unknown,\n name: string\n ): ArcPreparedConnectionType {\n if (this.#destroyed) {\n throw new ArclaceError('this instance has been destroyed');\n }\n\n validateConnectionOptions(options, name);\n\n const startElement = resolveElement(startTarget, 'startElement');\n const endElement = resolveElement(endTarget, 'endElement');\n const valid = options as ArcConnectionOptionsType;\n const id = valid.id ?? `arc-${uniqueID()}`;\n\n if (this.#connections.has(id)) {\n throw new ArclaceError(`a connection with id \"${id}\" exists`);\n }\n\n return { id, startElement, endElement, options: valid };\n }\n\n #add({\n id,\n startElement,\n endElement,\n options\n }: ArcPreparedConnectionType): Connection {\n const connection = Connection._create({\n id,\n startElement,\n endElement,\n options,\n defaults: this.#options.defaults,\n owner: this\n });\n\n this.#connections.set(id, connection);\n this.svg.appendChild(connection.element);\n this.#resizeObserver?.observe(startElement);\n this.#resizeObserver?.observe(endElement);\n\n return connection;\n }\n\n #unobserve(el: Element): void {\n if (!this.#resizeObserver || el === this.container) return;\n\n const inUse = this.connections.some(\n (connection) =>\n connection.startElement === el || connection.endElement === el\n );\n\n if (!inUse) this.#resizeObserver.unobserve(el);\n }\n\n #scheduleUpdate = (): void => {\n if (this.#frame || this.#destroyed) return;\n\n this.#frame = nextFrame(() => {\n this.#frame = 0;\n this.update();\n });\n };\n\n #startAutoUpdate(): void {\n const { autoUpdate = true } = this.#options;\n\n if (autoUpdate === false) return;\n\n if (autoUpdate === 'frame') {\n const loop = (): void => {\n this.update();\n this.#loop = nextFrame(loop);\n };\n\n this.#loop = nextFrame(loop);\n\n return;\n }\n\n window.addEventListener('resize', this.#scheduleUpdate);\n // Capture scroll events from any scrolling element, not just the page\n document.addEventListener('scroll', this.#scheduleUpdate, {\n capture: true,\n passive: true\n });\n\n if (typeof ResizeObserver !== 'undefined') {\n this.#resizeObserver = new ResizeObserver(this.#scheduleUpdate);\n this.#resizeObserver.observe(this.container);\n }\n\n if (typeof MutationObserver !== 'undefined') {\n this.#mutationObserver = new MutationObserver((records) => {\n // Ignore the changes we make to the overlay ourselves\n if (records.some((record) => !this.svg.contains(record.target))) {\n this.#scheduleUpdate();\n }\n });\n this.#mutationObserver.observe(this.container, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ['style', 'class', 'hidden']\n });\n }\n\n document.fonts?.ready.then(this.#scheduleUpdate);\n }\n}\n\n/**\n * Creates a {@link Arclace} instance and connects the given pairs.\n *\n * @example\n * ```ts\n * import { createConnections } from '@phun-ky/arclace';\n *\n * const arclace = createConnections(\n * [\n * { startElement: '#a', endElement: '#b' },\n * { startElement: '#b', endElement: '#c', arrow: 'end' }\n * ],\n * { defaults: { type: 'orthogonal' } }\n * );\n * ```\n */\nexport const createConnections = (\n definitions: ArcConnectionDefinitionType[],\n options?: ArcOptionsType\n): Arclace => {\n const arclace = new Arclace(options);\n\n try {\n arclace.connectAll(definitions);\n } catch (error) {\n // Don't leave an overlay and its listeners behind\n arclace.destroy();\n throw error;\n }\n\n return arclace;\n};\n"],"names":["ArclaceError","message","options","__publicField","NORMALS","OPPOSITE","isHorizontalSide","side","center","rect","add","a","b","factor","distance","round","value","fmt","point","uniqueID","SIDES","SIDE_OPTIONS","PATH_TYPES","ARROWS","show","assertObject","name","assertOneOf","allowed","list","item","assertNumber","min","assertBoolean","assertString","nonEmpty","assertPoint","x","y","CONNECTION_OPTION_CHECKS","validateConnectionOptions","key","check","validateOptions","autoUpdate","className","defaults","normalizeDistance","maxDistance","lerp","norm","max","curveMultiplierFromDistance","checkEnds","start","startSide","end","endSide","straightPath","bezierPath","curvature","length","bulge","c1","c2","simplifyPolyline","points","unique","i","prev","next","cross","roundedPolyline","radius","towards","from","to","total","segments","corner","r","polylineMidpoint","lengths","remaining","sum","t","SWAPPED_SIDE","swap","routeOrthogonal","offset","n1","n2","s1","s2","midX","midY","orthogonalPath","SVG_NS","createSVGElement","tagName","attributes","el","setAttributes","DEFAULT_CONNECTION_OPTIONS","definedOnly","ARROW_SIZE","_Connection","params","__privateAdd","_Connection_instances","_geometry","_removed","_owner","_options","_defaults","_marker","_label","_labelBg","_labelBox","_anchors","id","startElement","endElement","owner","__privateSet","__privateMethod","applyOptions_fn","__privateGet","arrow","strokeWidth","arrowLength","pathStart","pullBack_fn","pathEnd","d","labelPoint","buildPath_fn","placeLabel_fn","type","other","amount","label","color","dashed","animated","anchors","classes","applyArrow_fn","applyLabel_fn","applyAnchors_fn","_a","url","width","height","style","top","right","bottom","left","_b","anchor","Connection","getOrigin","svg","clientWidth","clientHeight","getLocalRect","origin","isRendered","querySelector","selector","error","resolveElement","target","facingSide","dx","dy","gapX","gapY","resolveSides","startRect","endRect","getAnchorPoint","index","count","spacing","gap","step","shift","cx","cy","nextFrame","callback","cancelFrame","handle","Arclace","_Arclace_instances","_connections","_frame","_loop","_destroyed","_resizeObserver","_mutationObserver","_originalPosition","_scheduleUpdate","startAutoUpdate_fn","connection","add_fn","prepare_fn","definitions","ids","connections","definition","removed","unobserve_fn","items","slots","addToSlot","otherRect","slot","spread","sides","solo","entries","entry","startTarget","endTarget","valid","loop","records","record","createConnections","arclace"],"mappings":"m1BAkBO,MAAMA,UAAqB,KAAM,CAGtC,YAAYC,EAAiBC,EAAwB,CACnD,MAAM,YAAYD,CAAO,GAAIC,CAAO,EAH7BC,EAAA,YAAO,eAIhB,CACF,CCfO,MAAMC,EAET,OAAO,OAAO,CAChB,IAAK,OAAO,OAAO,CAAE,EAAG,EAAG,EAAG,GAAI,EAClC,MAAO,OAAO,OAAO,CAAE,EAAG,EAAG,EAAG,EAAG,EACnC,OAAQ,OAAO,OAAO,C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,QAAT,MAAAA,EAAgB,MAAM,KAAKvB,EAAA,KAAK6E,IAClC,EAmBK,MAAM2B,GAAoB,CAC/BtB,EACA/M,IACY,CACZ,MAAMsO,EAAU,IAAIrC,GAAQjM,CAAO,EAEnC,GAAI,CACFsO,EAAQ,WAAWvB,CAAW,CAChC,OAAStC,EAAO,CAEd,MAAA6D,EAAQ,QAAA,EACF7D,CACR,CAEA,OAAO6D,CACT"}
|
package/dist/style.css
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Optional styles for @phun-ky/arclace.
|
|
3
3
|
*
|
|
4
|
-
* Lines work without this file. It adds
|
|
4
|
+
* Lines work without this file. It adds label backgrounds, hollow anchors and
|
|
5
5
|
* the dash animation, and exposes custom properties for theming:
|
|
6
6
|
*
|
|
7
7
|
* --arc-color line, arrow and anchor color
|
|
8
8
|
* --arc-label-color label text color
|
|
9
|
-
* --arc-label-
|
|
9
|
+
* --arc-label-bg background behind labels, so lines don't cross them
|
|
10
|
+
* (defaults to --arc-label-halo, then #fff)
|
|
11
|
+
* --arc-label-border outline of the label background
|
|
12
|
+
* --arc-label-radius corner radius of the label background
|
|
13
|
+
* --arc-label-padding space around the text inside the background, in
|
|
14
|
+
* lengths (px, em, rem), not percentages
|
|
10
15
|
* --arc-label-size label font size
|
|
11
16
|
* --arc-anchor-fill inside of anchor dots
|
|
12
17
|
*/
|
|
@@ -23,10 +28,17 @@
|
|
|
23
28
|
.arc-label {
|
|
24
29
|
fill: var(--arc-label-color, currentColor);
|
|
25
30
|
font-size: var(--arc-label-size, 12px);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.arc-label-bg {
|
|
34
|
+
fill: var(--arc-label-bg, var(--arc-label-halo, #fff));
|
|
35
|
+
stroke: var(--arc-label-border, none);
|
|
36
|
+
stroke-width: 1px;
|
|
37
|
+
rx: var(--arc-label-radius, 4px);
|
|
38
|
+
/* Read by Arclace to size the background; SVG itself ignores padding */
|
|
39
|
+
padding: var(--arc-label-padding, 3px 6px);
|
|
40
|
+
/* So em padding is relative to the label's text */
|
|
41
|
+
font-size: var(--arc-label-size, 12px);
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
.arc-anchor {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phun-ky/arclace",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Draw SVG lines between DOM elements. Framework agnostic, zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"connect",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"node": ">=22.12.0"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
|
+
"banners": "node scripts/banners/render.mjs",
|
|
61
62
|
"bestpractices:url": "node scripts/bestpractices-url.mjs",
|
|
62
63
|
"build": "rm -rf dts && vite build && tsc -p tsconfig.build.json && rollup -c",
|
|
63
64
|
"check:bestpractices": "node scripts/check-bestpractices.mjs",
|
|
@@ -71,14 +72,16 @@
|
|
|
71
72
|
"docs:build": "vitepress build docs",
|
|
72
73
|
"docs:preview": "vitepress preview docs",
|
|
73
74
|
"lint": "eslint .",
|
|
75
|
+
"logo": "node scripts/render-logo.mjs",
|
|
74
76
|
"prepare": "git config core.hooksPath .githooks || true",
|
|
75
77
|
"prepublishOnly": "npm run build",
|
|
76
78
|
"preview": "vite preview",
|
|
77
79
|
"release": "release-it",
|
|
78
|
-
"release:dry-run": ".github/scripts/
|
|
80
|
+
"release:dry-run": ".github/scripts/release-dry-run.sh",
|
|
79
81
|
"test": "node --import tsx --import global-jsdom/register --test --no-warnings 'src/**/__tests__/**/*.spec.ts'",
|
|
80
82
|
"pretest:ci": "rm -rf coverage && mkdir -p coverage",
|
|
81
83
|
"test:ci": "node --import tsx --import global-jsdom/register --test --no-warnings --experimental-test-coverage --test-coverage-include='src/**/*.ts' --test-coverage-exclude='src/**/__tests__/**' --test-coverage-exclude='src/types.ts' --test-coverage-lines=99 --test-coverage-functions=100 --test-coverage-branches=95 --test-reporter=cobertura --test-reporter-destination=coverage/cobertura-coverage.xml --test-reporter=spec --test-reporter-destination=stdout 'src/**/__tests__/**/*.spec.ts'",
|
|
84
|
+
"test:hooks": "node --test scripts/__tests__/commit-msg.test.mjs",
|
|
82
85
|
"typecheck": "tsc --noEmit"
|
|
83
86
|
},
|
|
84
87
|
"devDependencies": {
|
|
@@ -103,7 +106,7 @@
|
|
|
103
106
|
"typedoc": "^0.28.20",
|
|
104
107
|
"typedoc-plugin-markdown": "^4.14.1",
|
|
105
108
|
"typedoc-vitepress-theme": "^1.1.4",
|
|
106
|
-
"typescript": "~
|
|
109
|
+
"typescript": "~6.0.3",
|
|
107
110
|
"vite": "^6.2.0",
|
|
108
111
|
"vitepress": "^1.6.4"
|
|
109
112
|
},
|
package/src/Connection.ts
CHANGED
|
@@ -85,7 +85,8 @@ type ArcConnectionParamsType = {
|
|
|
85
85
|
* <g class="arc-connection arc-bezier">
|
|
86
86
|
* <marker class="arc-marker">…</marker> <!-- when `arrow` is set -->
|
|
87
87
|
* <path class="arc-path" />
|
|
88
|
-
* <
|
|
88
|
+
* <rect class="arc-label-bg" /> <!-- when `label` is set -->
|
|
89
|
+
* <text class="arc-label">…</text>
|
|
89
90
|
* <circle class="arc-anchor arc-anchor-start" /> <!-- when `anchors` is set -->
|
|
90
91
|
* <circle class="arc-anchor arc-anchor-end" />
|
|
91
92
|
* </g>
|
|
@@ -116,6 +117,11 @@ export class Connection {
|
|
|
116
117
|
#defaults: ArcConnectionOptionsType;
|
|
117
118
|
#marker: SVGMarkerElement | null = null;
|
|
118
119
|
#label: SVGTextElement | null = null;
|
|
120
|
+
#labelBg: SVGRectElement | null = null;
|
|
121
|
+
// The background's box relative to the label's anchor point, measured once
|
|
122
|
+
// per label
|
|
123
|
+
#labelBox: { x: number; y: number; width: number; height: number } | null =
|
|
124
|
+
null;
|
|
119
125
|
#anchors: [SVGCircleElement, SVGCircleElement] | null = null;
|
|
120
126
|
|
|
121
127
|
private constructor(params: ArcConnectionParamsType) {
|
|
@@ -262,7 +268,7 @@ export class Connection {
|
|
|
262
268
|
});
|
|
263
269
|
this.path.setAttribute('d', d);
|
|
264
270
|
|
|
265
|
-
if (this.#label)
|
|
271
|
+
if (this.#label) this.#placeLabel(labelPoint);
|
|
266
272
|
|
|
267
273
|
if (this.#anchors) {
|
|
268
274
|
setAttributes(this.#anchors[0], { cx: start.x, cy: start.y });
|
|
@@ -408,10 +414,50 @@ export class Connection {
|
|
|
408
414
|
});
|
|
409
415
|
}
|
|
410
416
|
|
|
417
|
+
#placeLabel(point: ArcPointInterface): void {
|
|
418
|
+
setAttributes(this.#label!, { ...point });
|
|
419
|
+
|
|
420
|
+
// shortcut: measured once per label change, so a font or padding change
|
|
421
|
+
// from CSS alone needs a setOptions() call to resize the background
|
|
422
|
+
// getBBox is missing where there is no layout, such as jsdom
|
|
423
|
+
if (!this.#labelBox?.width && typeof this.#label!.getBBox === 'function') {
|
|
424
|
+
const { x, y, width, height } = this.#label!.getBBox();
|
|
425
|
+
// CSS padding doesn't apply to SVG, but its computed value is in px,
|
|
426
|
+
// so the stylesheet sets it on the background and it is read here
|
|
427
|
+
const style = getComputedStyle(this.#labelBg!);
|
|
428
|
+
const [top, right, bottom, left] = [
|
|
429
|
+
style.paddingTop,
|
|
430
|
+
style.paddingRight,
|
|
431
|
+
style.paddingBottom,
|
|
432
|
+
style.paddingLeft
|
|
433
|
+
].map((value) => parseFloat(value) || 0);
|
|
434
|
+
|
|
435
|
+
this.#labelBox = {
|
|
436
|
+
x: x - point.x - left,
|
|
437
|
+
y: y - point.y - top,
|
|
438
|
+
width: width + left + right,
|
|
439
|
+
height: height + top + bottom
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (!this.#labelBox) return;
|
|
444
|
+
|
|
445
|
+
setAttributes(this.#labelBg!, {
|
|
446
|
+
x: point.x + this.#labelBox.x,
|
|
447
|
+
y: point.y + this.#labelBox.y,
|
|
448
|
+
width: this.#labelBox.width,
|
|
449
|
+
height: this.#labelBox.height
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
411
453
|
#applyLabel(label: string | undefined): void {
|
|
454
|
+
this.#labelBox = null;
|
|
455
|
+
|
|
412
456
|
if (!label) {
|
|
413
457
|
this.#label?.remove();
|
|
458
|
+
this.#labelBg?.remove();
|
|
414
459
|
this.#label = null;
|
|
460
|
+
this.#labelBg = null;
|
|
415
461
|
|
|
416
462
|
return;
|
|
417
463
|
}
|
|
@@ -423,13 +469,18 @@ export class Connection {
|
|
|
423
469
|
'text-anchor': 'middle',
|
|
424
470
|
'dominant-baseline': 'central'
|
|
425
471
|
});
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
472
|
+
// Invisible without the stylesheet, which fills it
|
|
473
|
+
this.#labelBg = createSVGElement('rect', {
|
|
474
|
+
class: 'arc-label-bg',
|
|
475
|
+
fill: 'none',
|
|
476
|
+
rx: 4
|
|
477
|
+
});
|
|
478
|
+
this.path.after(this.#labelBg, this.#label);
|
|
430
479
|
}
|
|
431
480
|
|
|
432
481
|
this.#label.textContent = label;
|
|
482
|
+
|
|
483
|
+
if (this.#geometry) this.#placeLabel(this.#geometry.labelPoint);
|
|
433
484
|
}
|
|
434
485
|
|
|
435
486
|
#applyAnchors(anchors: boolean, strokeWidth: number): void {
|