UNPKG

gojs

Version:

Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams

1,331 lines (1,327 loc) 1.65 MB
/* * Type definitions for GoJS v4.0.1 * Project: https://gojs.net * Definitions by: Northwoods Software <https://github.com/NorthwoodsSoftware> * Definitions: https://github.com/NorthwoodsSoftware/GoJS * Copyright 1998-2026 by Northwoods Software Corporation. * This requires TypeScript v2.8 or later. */ export as namespace go; /** * The ObjectData type is the same as `{ [index: string]: any; }`. * This is to ease writing `someDataObject.anyPropertyName`, * when dealing with arbitrary JavaScript Objects used as model data. * @category Model */ export interface ObjectData { [index: string]: any; } /** * Typed constants for GoJS string-based registries. * These provide autocomplete and compile-time checking for values * that are otherwise plain strings. * * @since 4.0 * @category Constants */ /** * All built-in figure names for {@link Shape.figure}. * Use these constants instead of plain strings for autocomplete and type safety. * * Example: * ```ts * new go.Shape({ figure: go.Figures.RoundedRectangle }) * // equivalent to: * new go.Shape({ figure: "RoundedRectangle" }) * ``` * @since 4.0 * @category Constants */ export declare const Figures: { readonly None: "None"; readonly Rectangle: "Rectangle"; readonly Square: "Square"; readonly RoundedRectangle: "RoundedRectangle"; readonly Border: "Border"; readonly RoundedTopRectangle: "RoundedTopRectangle"; readonly RoundedBottomRectangle: "RoundedBottomRectangle"; readonly RoundedLeftRectangle: "RoundedLeftRectangle"; readonly RoundedRightRectangle: "RoundedRightRectangle"; readonly Ellipse: "Ellipse"; readonly Circle: "Circle"; readonly TriangleRight: "TriangleRight"; readonly TriangleDown: "TriangleDown"; readonly TriangleLeft: "TriangleLeft"; readonly TriangleUp: "TriangleUp"; readonly Triangle: "Triangle"; readonly Diamond: "Diamond"; readonly LineH: "LineH"; readonly LineV: "LineV"; readonly BarH: "BarH"; readonly BarV: "BarV"; readonly MinusLine: "MinusLine"; readonly PlusLine: "PlusLine"; readonly XLine: "XLine"; readonly LineRight: "LineRight"; readonly LineDown: "LineDown"; readonly LineLeft: "LineLeft"; readonly LineUp: "LineUp"; readonly Capsule: "Capsule"; readonly Borders: "Borders"; }; /** * Union type of all built-in figure name strings. * @since 4.0 * @category Constants */ export type FigureName = typeof Figures[keyof typeof Figures]; /** * All built-in arrowhead names for {@link Shape.toArrow} and {@link Shape.fromArrow}. * Use these constants instead of plain strings for autocomplete and type safety. * * Example: * ```ts * new go.Shape({ toArrow: go.Arrowheads.Standard }) * // equivalent to: * new go.Shape({ toArrow: "Standard" }) * ``` * @since 4.0 * @category Constants */ export declare const Arrowheads: { readonly Standard: "Standard"; readonly Backward: "Backward"; readonly Triangle: "Triangle"; readonly BackwardTriangle: "BackwardTriangle"; readonly Boomerang: "Boomerang"; readonly BackwardBoomerang: "BackwardBoomerang"; readonly SidewaysV: "SidewaysV"; readonly BackwardV: "BackwardV"; readonly OpenTriangle: "OpenTriangle"; readonly BackwardOpenTriangle: "BackwardOpenTriangle"; readonly OpenTriangleLine: "OpenTriangleLine"; readonly BackwardOpenTriangleLine: "BackwardOpenTriangleLine"; readonly OpenTriangleTop: "OpenTriangleTop"; readonly BackwardOpenTriangleTop: "BackwardOpenTriangleTop"; readonly OpenTriangleBottom: "OpenTriangleBottom"; readonly BackwardOpenTriangleBottom: "BackwardOpenTriangleBottom"; readonly HalfTriangleTop: "HalfTriangleTop"; readonly BackwardHalfTriangleTop: "BackwardHalfTriangleTop"; readonly HalfTriangleBottom: "HalfTriangleBottom"; readonly BackwardHalfTriangleBottom: "BackwardHalfTriangleBottom"; readonly ForwardSemiCircle: "ForwardSemiCircle"; readonly BackwardSemiCircle: "BackwardSemiCircle"; readonly Feather: "Feather"; readonly BackwardFeather: "BackwardFeather"; readonly DoubleFeathers: "DoubleFeathers"; readonly BackwardDoubleFeathers: "BackwardDoubleFeathers"; readonly TripleFeathers: "TripleFeathers"; readonly BackwardTripleFeathers: "BackwardTripleFeathers"; readonly ForwardSlash: "ForwardSlash"; readonly BackSlash: "BackSlash"; readonly DoubleForwardSlash: "DoubleForwardSlash"; readonly DoubleBackSlash: "DoubleBackSlash"; readonly TripleForwardSlash: "TripleForwardSlash"; readonly TripleBackSlash: "TripleBackSlash"; readonly Fork: "Fork"; readonly BackwardFork: "BackwardFork"; readonly LineFork: "LineFork"; readonly BackwardLineFork: "BackwardLineFork"; readonly CircleFork: "CircleFork"; readonly BackwardCircleFork: "BackwardCircleFork"; readonly CircleLineFork: "CircleLineFork"; readonly BackwardCircleLineFork: "BackwardCircleLineFork"; readonly Circle: "Circle"; readonly Block: "Block"; readonly StretchedDiamond: "StretchedDiamond"; readonly Diamond: "Diamond"; readonly Chevron: "Chevron"; readonly StretchedChevron: "StretchedChevron"; readonly NormalArrow: "NormalArrow"; readonly X: "X"; readonly TailedNormalArrow: "TailedNormalArrow"; readonly DoubleTriangle: "DoubleTriangle"; readonly BigEndArrow: "BigEndArrow"; readonly ConcaveTailArrow: "ConcaveTailArrow"; readonly RoundedTriangle: "RoundedTriangle"; readonly SimpleArrow: "SimpleArrow"; readonly AccelerationArrow: "AccelerationArrow"; readonly BoxArrow: "BoxArrow"; readonly TriangleLine: "TriangleLine"; readonly CircleEndedArrow: "CircleEndedArrow"; readonly DynamicWidthArrow: "DynamicWidthArrow"; readonly EquilibriumArrow: "EquilibriumArrow"; readonly FastForward: "FastForward"; readonly Kite: "Kite"; readonly HalfArrowTop: "HalfArrowTop"; readonly HalfArrowBottom: "HalfArrowBottom"; readonly OpposingDirectionDoubleArrow: "OpposingDirectionDoubleArrow"; readonly PartialDoubleTriangle: "PartialDoubleTriangle"; readonly LineCircle: "LineCircle"; readonly DoubleLineCircle: "DoubleLineCircle"; readonly TripleLineCircle: "TripleLineCircle"; readonly CircleLine: "CircleLine"; readonly DiamondCircle: "DiamondCircle"; readonly PlusCircle: "PlusCircle"; readonly OpenRightTriangleTop: "OpenRightTriangleTop"; readonly OpenRightTriangleBottom: "OpenRightTriangleBottom"; readonly Line: "Line"; readonly DoubleLine: "DoubleLine"; readonly TripleLine: "TripleLine"; readonly PentagonArrow: "PentagonArrow"; }; /** * Union type of all built-in arrowhead name strings. * @since 4.0 * @category Constants */ export type ArrowheadName = typeof Arrowheads[keyof typeof Arrowheads]; /** * All built-in panel layout type names for the Panel constructor and {@link Panel.type}. * Use these constants instead of plain strings for autocomplete and type safety. * * Note: You can also use the static properties on {@link Panel}, e.g. `Panel.Auto`, `Panel.Table`. * * Example: * ```ts * new go.Panel(go.PanelTypes.Table, ...) * // equivalent to: * new go.Panel("Table", ...) * // or: * new go.Panel(go.Panel.Table, ...) * ``` * @since 4.0 * @category Constants */ export declare const PanelTypes: { readonly Position: "Position"; readonly Horizontal: "Horizontal"; readonly Vertical: "Vertical"; readonly Spot: "Spot"; readonly Auto: "Auto"; readonly Table: "Table"; readonly Viewbox: "Viewbox"; readonly TableRow: "TableRow"; readonly TableColumn: "TableColumn"; readonly Link: "Link"; readonly Grid: "Grid"; readonly Graduated: "Graduated"; }; /** * Union type of all built-in panel layout type name strings. * @since 4.0 * @category Constants */ export type PanelTypeName = typeof PanelTypes[keyof typeof PanelTypes]; /** * All standard tool names used with {@link ToolManager.findTool} and {@link ToolManager.replaceTool}. * Use these constants instead of plain strings for autocomplete and type safety. * * Example: * ```ts * myDiagram.toolManager.findTool(go.ToolNames.Dragging) * // equivalent to: * myDiagram.toolManager.findTool("Dragging") * ``` * @since 4.0 * @category Constants */ export declare const ToolNames: { readonly Action: "Action"; readonly Relinking: "Relinking"; readonly LinkReshaping: "LinkReshaping"; readonly Rotating: "Rotating"; readonly Resizing: "Resizing"; readonly Linking: "Linking"; readonly Dragging: "Dragging"; readonly DragSelecting: "DragSelecting"; readonly Panning: "Panning"; readonly ContextMenu: "ContextMenu"; readonly TextEditing: "TextEditing"; readonly ClickCreating: "ClickCreating"; readonly ClickSelecting: "ClickSelecting"; }; /** * Union type of all standard tool name strings. * @since 4.0 * @category Constants */ export type ToolName = typeof ToolNames[keyof typeof ToolNames]; /** * All built-in builder names for {@link GraphObject.build} and {@link GraphObject.make}. * Use these constants instead of plain strings for autocomplete and type safety. * * Example: * ```ts * go.GraphObject.build(go.Builders.Button, { ... }) * // equivalent to: * go.GraphObject.build("Button", { ... }) * ``` * @since 4.0 * @category Constants */ export declare const Builders: { readonly Button: "Button"; readonly TreeExpanderButton: "TreeExpanderButton"; readonly SubGraphExpanderButton: "SubGraphExpanderButton"; readonly ToolTip: "ToolTip"; readonly ContextMenu: "ContextMenu"; readonly ContextMenuButton: "ContextMenuButton"; readonly PanelExpanderButton: "PanelExpanderButton"; readonly CheckBoxButton: "CheckBoxButton"; readonly CheckBox: "CheckBox"; readonly AutoRepeatButton: "AutoRepeatButton"; readonly ToggleSwitch: "ToggleSwitch"; readonly Toggle: "Toggle"; }; /** * Union type of all built-in builder name strings. * @since 4.0 * @category Constants */ export type BuilderName = typeof Builders[keyof typeof Builders]; /** * All standard layer names used as a {@link Part.layerName} or with {@link Diagram.findLayer}. * Use these constants instead of plain strings for autocomplete and type safety. * * Example: * ```ts * myDiagram.findLayer(go.LayerNames.Background) * // equivalent to: * myDiagram.findLayer("Background") * ``` * @since 4.0 * @category Constants */ export declare const LayerNames: { readonly Grid: "Grid"; readonly ViewportBackground: "ViewportBackground"; readonly Background: "Background"; readonly Default: ""; readonly Foreground: "Foreground"; readonly ViewportForeground: "ViewportForeground"; readonly Adornment: "Adornment"; readonly Tool: "Tool"; }; /** * Union type of all standard tool name strings. * @since 4.0 * @category Constants */ export type LayerName = typeof LayerNames[keyof typeof LayerNames]; /** * This interface is implemented by the {@link List}, {@link Set}, and {@link Map} * classes; it provides the {@link iterator} read-only property that returns an {@link Iterator}. * * Typical usage is: * ```js * const it = anIterableCollection.iterator; * while (it.next()) { * const item = it.value; * } * ``` * * Note that GoJS iteration is quite different than ECMAScript iteration. * The GoJS collection classes were defined in GoJS before the ECMAScript collection classes were proposed. * @category Collection */ export interface Iterable<T> { /** * Gets an {@link Iterator} that can iterate over the items in the collection. * * Typical usage is: * ```js * const it = anIterableCollection.iterator; * while (it.next()) { * const item = it.value; * } * ``` */ iterator: Iterator<T>; [Symbol.iterator](): IterableIterator<T>; /** * Returns the first item in the list, or null if there is none. * @returns This returns null if there are no items in the list. */ first(): T | null; /** * This read-only property is the number of elements in the collection. */ readonly count: number; } /** * This interface defines properties and methods for iterating over a collection; * it provides the {@link next} predicate and the {@link value} read-only property. * Some Iterators also provide `key` property values along with each `value`. * * Typical usage is: * ```js * const it = anIterableCollection.iterator; * while (it.next()) { * const item = it.value; * } * ``` * * It is an error if {@link next} is called * after the underlying collection has been modified. * * To avoid confusion when dealing with {@link Iterable}s, * iterators implement the {@link Iterable.iterator} property * by just returning themselves. * * Note that GoJS iteration is quite different than ECMAScript iteration. * The GoJS collection classes were defined in GoJS before the ECMAScript collection classes were proposed. * @category Collection */ export interface Iterator<T> extends Iterable<T> { /** * Returns itself, which is convenient for code that expects an {@link Iterable} * instead of an {@link Iterator}. */ iterator: Iterator<T>; /** * Call this method to advance the iterator to the next item in the collection. * This should be called before accessing any {@link value}. * @returns whether another item is available; when true the value of {@link value} will be that item. */ next(): boolean; /** * Call this method to advance the iterator to the next item in the collection. * This should be called before accessing any {@link value}. * @returns whether another item is available; when true the value of {@link value} will be that item. */ hasNext(): boolean; /** * Advance if needed to the first item in the collection and return it, or return null if there is none. * * Caution: this returns a *key/value pair*, not a *value*, for {@link Map} iterators. */ first(): T | null; /** * Start this iterator all over again. */ reset(): void; /** * This is true if any invocation of the given predicate on items in the collection is true. * * Call the given predicate on each item in the collection. * As soon as a call returns true, this returns true. * Otherwise this returns false. * For an empty collection this returns false. * * This automatically {@link reset}'s itself when it is called. * @virtual * @param pred - This function must not have any side-effects. * @returns True if any predicate call is true; false otherwise. */ any(pred: (x: T) => boolean): boolean; /** * This is true if all invocations of the given predicate on items in the collection are true. * * Call the given predicate on each item in the collection. * As soon as a call returns false, this returns false. * Otherwise this returns true. * For an empty collection this returns true. * * This automatically {@link reset}'s itself when it is called. * @virtual * @param pred - This function must not have any side-effects. * @returns True if all predicate calls are true; false otherwise. */ all(pred: (x: T) => boolean): boolean; /** * Call the given function on each item in the collection. * * This automatically {@link reset}'s itself when it is called. * @virtual * @param func - This function must not modify the collection. * @returns this iterator itself */ each(func: (x: T) => void): void; /** * Call the given function on each item in the collection and present the results in an iterator. * * This automatically {@link reset}'s itself when it is called. * @virtual * @param func - This function must not modify the collection. * @returns this */ map<S>(func: (x: T) => S): Iterator<S>; /** * Call the given predicate on each item in the collection and for each item that it returns true, present the item in an iterator. * * This automatically {@link reset}'s itself when it is called. * @virtual * @param pred - This function must not have any side-effects. * @returns this */ filter(pred: (x: T) => boolean): Iterator<T>; /** * Gets the current item in the collection, assuming {@link next} has just returned true. */ readonly value: T; /** * Gets the current index to the item in the collection, assuming {@link next} has just returned true. */ readonly key: any; /** * This read-only property is the total number of items in the iterated collection. */ readonly count: number; } /** * This interface defines properties and methods for iterating over a {@link Map}; * it provides the {@link next} predicate and the {@link key} and {@link value} read-only properties. * * Iterating over Maps is very similar to an {@link Iterator}<{@link IKeyValuePair}>, * but not exactly, because the type of the value property is T, not an {@link IKeyValuePair}. * * Typical usage is: * ```js * const it = aMap.iterator; * while (it.next()) { * const key = it.key; * const val = it.value; * } * ``` * @see {@link Iterator} * @category Collection */ export interface IMapIterator<K, T> { /** {@inheritDoc Iterator.iterator} */ iterator: IMapIterator<K, T>; /** {@inheritDoc Iterator.next} */ next(): boolean; /** * {@inheritDoc Iterator.hasNext} */ hasNext(): boolean; /** * Advance if needed to the first item in the collection and return it, or return null if there is none. * Returns a *key/value pair*, not a *value*. */ first(): IKeyValuePair<K, T> | null; /** {@inheritDoc Iterator.reset} */ reset(): void; /** {@inheritDoc Iterator.any} */ any(pred: (x: IKeyValuePair<K, T>) => boolean): boolean; /** {@inheritDoc Iterator.all} */ all(pred: (x: IKeyValuePair<K, T>) => boolean): boolean; /** {@inheritDoc Iterator.each} */ each(func: (x: IKeyValuePair<K, T>) => void): IMapIterator<K, T>; /** * {@inheritDoc Iterator.map} */ map<S>(func: (x: IKeyValuePair<K, T>) => S): Iterator<S>; /** * {@inheritDoc Iterator.filter} */ filter(pred: (x: IKeyValuePair<K, T>) => boolean): Iterator<IKeyValuePair<K, T>>; /** * Gets the current {@link IKeyValuePair.value|value} in the collection, assuming {@link next} has just returned true. */ readonly value: T; /** * Gets the current {@link IKeyValuePair.key|key} in the collection, assuming {@link next} has just returned true. */ readonly key: K; /** {@inheritDoc Iterator.count} */ readonly count: number; } /** * A (key, value) pair, used in {@link Map}s. * @category Collection */ export interface IKeyValuePair<K, V> { /** * Gets a key for a value in a {@link Map}. * @returns the key uniquely identifying a {@link value} in a {@link Map}. */ readonly key: K; /** * Gets a value in a {@link Map}. * @returns a value in a {@link Map} corresponding to a {@link key}. */ readonly value: V; } /** * (undocumented) interface used for both the SVGSurface and the CanvasSurface, which are undocumented classes. */ export interface ISurface { width: number; height: number; resize(pixelWidth: number, pixelHeight: number, width: number, height: number): boolean; getBoundingClientRect(): DOMRect; focus(): void; dispose(): void; style: CSSStyleDeclaration; } /** * (undocumented) interface used for both the SVGContext and the CanvasSurfaceContext, which are undocumented classes. */ export interface IContext { fillStyle: string | CanvasGradient | CanvasPattern | SGradient; font: string; globalAlpha: number; lineCap: string; lineDashOffset: number; lineJoin: string; lineWidth: number; miterLimit: number; shadowBlur: number; shadowColor: string; shadowOffsetX: number; shadowOffsetY: number; strokeStyle: string | CanvasGradient | CanvasPattern | SGradient; textAlign: string; imageSmoothingEnabled: boolean; /** Only true if a Spot panel has isClipping element */ clipInsteadOfFill: boolean; filter: string; letterSpacing: string; wordSpacing: string; commitTransform(): void; setImageSmoothingEnabled(smooth: boolean): void; arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise: boolean, lx?: number, ly?: number): void; beginPath(): void; endPath(pathIndex?: number): void; bezierCurveTo(a: number, b: number, c: number, d: number, e: number, f: number): void; clearRect(x: number, y: number, w: number, h: number): void; clip(): void; closePath(): void; createLinearGradient(aX0: number, aY0: number, aX1: number, aY1: number): CanvasGradient | SGradient; createPattern(image: HTMLCanvasElement | HTMLImageElement, repetition: string): CanvasPattern | string; createRadialGradient(aX0: number, aY0: number, aR0: number, aX1: number, aY1: number, aR1: number): CanvasGradient | SGradient; drawImage(src: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement, sx: number, sy: number, sw?: number, sh?: number, dx?: number, dy?: number, dw?: number, dh?: number): void; fill(fillRule: boolean, path: Path2D | null): void; fillRect(x: number, y: number, w: number, h: number): void; fillBackground(x: number, y: number, w: number, h: number): void; fillText(str: string, x: number, y: number): void; getImageData(x: number, y: number, w: number, h: number): ImageData; lineTo(x: number, y: number): void; measureText(text: string): TextMetrics; moveTo(x: number, y: number): void; quadraticCurveTo(a: number, b: number, c: number, d: number): void; rect(x: number, y: number, w: number, h: number): void; ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void; restore(): void; rotate(angle: number): void; save(): void; setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void; scale(x: number, y: number): void; stroke(p?: Path2D): void; transform(a: number, b: number, c: number, d: number, e: number, f: number): void; translate(x: number, y: number): void; fillContext(brush: BrushLike, fillRule: boolean, path: Path2D | null): void; strokeContext(): void; shadowsSet(x: number, y: number, blur: number): void; shadowsOff(): void; shadowsOn(): void; enableDash(strokeDashArray: Array<number>, strokeDashOffset: number): void; disableDash(): void; clearContextCache(clearFont: boolean): void; removePartFromView(p: GraphObject): void; createOrUpdateClipGroup(panel: GraphObject, rect: Rect): void; } /** * An ordered iterable collection. * In TypeScript it is a generic class that enforces at compile-time the type of elements that may be added to the List. * * An example usage: * ```js * const list = new go.List(); // or in TypeScript: new go.List<go.Point>(); * list.add(new go.Point(0, 0)); * list.add(new go.Point(20, 10)); * list.add(new go.Point(10, 20)); * // now list.length === 3 * // and list.elt(1) instanceof go.Point * ``` * * You can iterate over the items in a List: * ```js * const it = aList.iterator; * while (it.next()) { * console.log("#" + it.key + " is " + it.value); * } * ``` * Or: * ```js * aList.each(val => { * console.log(val); * }); * ``` * The key will range from zero to {@link count}-1. * * For convenience this **GoJS** List class has synonyms for the following methods and property: * - **get(idx)**: {@link elt} * - **set(idx,val)**: {@link setElt} * - **has(val)**: {@link has} * - **delete(val)**: {@link delete} * - **clear()**: {@link clear} * - **size**: {@link count} * * The constructor now takes an optional Iterable or Array argument that provides the initial elements for the new List. * * Note that GoJS iteration is quite different than ECMAScript iteration, so that functionality has not been made somewhat compatible. * These collection classes were defined in GoJS before the ECMAScript collection classes were proposed. * @category Collection */ export class List<T> implements Iterable<T> { /** * There are two possible constructors: * * `new go.List()`, for JavaScript * * `new go.List<type>()` for TypeScript, to enforce type checking. * @param coll - an optional collection of items to add; it can be either a GoJS Iterable or a JavaScript Iterable, including an Array */ constructor(coll?: Iterable<T> | globalThis.Iterable<T>); /** * This class implements the JavaScript `Symbol.iterator`, * and can be used with spread syntax or `for ... of` statements. */ [Symbol.iterator](): ArrayIterator<T>; /** */ toString(): string; /** * Adds a given value to the end of the List. * * Be careful not to call this method while iterating over the collection. * @param val * @returns This modified List. */ add(val: T): this; /** * Adds a given value to the end of the List. * * Be careful not to call this method while iterating over the collection. * @param val */ push(val: T): void; /** * Adds all of the values of a collection to the end of this List. * * Be careful not to call this method while iterating over the collection. * @param coll - the collection of items to add -- it can be either a GoJS Iterable or a JavaScript Iterable, including an Array * @returns This modified List. */ addAll(coll: Iterable<T> | globalThis.Iterable<T>): this; /** * Clears the List. * This sets the {@link count} to zero. * * Be careful not to call this method while iterating over the collection. */ clear(): void; /** * Returns whether the given value is in this List. * A synonym for {@link has}. * * @param val - The value to check. * @returns Whether or not the value is contained within the List. */ contains(val: T): boolean; /** * Returns whether the given value is in this List. * @param val - The value to check. * @returns Whether or not the value is contained within the List. */ has(val: T): boolean; /** * Returns the index of the given value if it is in this List. * @param val - The value to check. * @returns returns -1 if the value is not in this list. */ indexOf(val: T): number; /** * Returns the element at the given index. * @param i - int The index of the element to return. * @returns the value at the given index. */ elt(i: number): T; /** * Returns the element at the given index. * A synonym for {@link elt}. * * @param i - int The index of the element to return. * @returns the value at the given index. */ get(i: number): T; /** * Set the element at the given index to a given value. * @param i - int The index of the element to set. * @param val - The value to set at the index. */ setElt(i: number, val: T): void; /** * Set the element at the given index to a given value. * @param i - int The index of the element to set. * @param val - The value to set at the index. */ set(i: number, val: T): void; /** * Returns the first item in the list, or null if there is none. * @returns This returns null if there are no items in the list. */ first(): T | null; /** * Returns the last item in the list, or null if these is none. * @returns This returns null if there are no items in the list. */ last(): T | null; /** * Returns the last item in the list and removes it from the list, or just return null if these is none. * Use {@link add} to push an item onto the end of the list. * Use {@link last} to get the last item without reducing the length of the list. * @returns This returns null if there are no items in the list. */ pop(): T | null; /** * This is true if any invocation of the given predicate on items in the collection is true. * * Call the given predicate on each item in the collection. * As soon as a call returns true, this returns true. * Otherwise this returns false. * For an empty collection this returns false. * @virtual * @param pred - This function must not have any side-effects. * @returns True if any predicate call is true; false otherwise. */ any(pred: ((a: T) => boolean)): boolean; /** * This is true if all invocations of the given predicate on items in the collection are true. * * Call the given predicate on each item in the collection. * As soon as a call returns false, this returns false. * Otherwise this returns true. * For an empty collection this returns true. * @virtual * @param pred - This function must not have any side-effects. * @returns True if all predicate calls are true; false otherwise. */ all(pred: ((a: T) => boolean)): boolean; /** * Call the given function on each item in the collection. * @virtual * @param func - This function must not modify the collection. * @returns This List itself */ each(func: ((a: T) => void)): this; /** * Call the given function on each item in the collection and collect the results in a new List. * * Unlike {@link Iterator.map}, this returns a List, not an Iterator. * @virtual * @param func - This function must not modify the collection. */ map<S>(func: ((a: T) => S)): List<S>; /** * Call the given predicate on each item in the collection and for each item that it returns true, collect the item in a new List. * * Unlike {@link Iterator.filter}, this returns a List, not an Iterator. * @virtual * @param pred - This function must not have any side-effects. */ filter(pred: ((a: T) => boolean)): List<T>; /** * Insert a value before the index i. * * Be careful not to call this method while iterating over the collection. * @param i - int The index to insert before. * @param val - The value to insert. */ insertAt(i: number, val: T): void; /** * Removes a given value (if found) from the List. * A synonym for {@link delete}. * * Be careful not to call this method while iterating over the collection. * @param val - The value to remove. * @returns true if the value was found and removed, false otherwise. */ remove(val: T): boolean; /** * Removes a given value (if found) from the List. * * Be careful not to call this method while iterating over the collection. * @param val - The value to remove. * @returns true if the value was found and removed, false otherwise. */ delete(val: T): boolean; /** * Removes a value at a given index from the List. * * Be careful not to call this method while iterating over the collection. * @param i - int The index to remove. */ removeAt(i: number): void; /** * Removes a range of values from the List, given both the starting and the ending zero-based indexes. * For example, * ```js * list.removeRange(2, 4) * ``` * will remove elements 2, 3, and 4 from the list. * If there were two or fewer elements in the list to begin with, the list is unchanged. * If *from* is greater than *to*, the list is unchanged. * If *from* is greater than or equal to the length, the list is unchanged. * If *to* is less than zero, the list is unchanged. * * Be careful not to call this method while iterating over the collection. * @param from - int The starting index of the range to remove, inclusive; negative values are treated as zero * @param to - int The ending index of the range to remove, inclusive; values greater than the length of the list are treated as referring to the last element * @returns This modified List */ removeRange(from: number, to: number): this; /** * Makes a shallow copy of this List. * The values are not copied, * so if they are objects they may continue to be shared with the original List. * @virtual * @returns The new List with the same elements. */ copy(): List<T>; /** * Produces a JavaScript Array from the contents of this List. * @returns A copy of the List in Array form. */ toArray(): Array<T>; /** * Converts the List to a {@link Set | go.Set}. * The count of the resulting Set may be less than the count of this List * if any duplicates were removed. * @returns A copy of the contents of this List, * but with duplicates removed and ordering lost. */ toSet(): Set<T>; /** * Sort the List according to a comparison function. * @param sortfunc - This function is passed two items in the list. * It should return zero if they are equal, * less than zero if the first value should come before the second value, * or greater than zero if the first value should come after the second value. * @returns This modified List. */ sort(sortfunc: ((a: T, b: T) => number)): this; /** * (undocumented) * Sorts a range of consecutive elements in this List based on the given comparison function. * @param sortfunc - This function is passed two elements in the list. * It should return zero if they are equal, * less than zero if the first value should come before the second value, * or greater than zero if the first value should come after the second value. * @param from - int The optional index at which to start the sort, including that element; * default to zero, the first element of the list. * @param to - int The optional index at which to end the sort, excluding that element; * defaults to the end of the list. * @returns This modified List. */ sortRange(sortfunc: ((a: T, b: T) => number), from?: number, to?: number): this; /** * Reverse the order of items in this List. * @returns This modified List. */ reverse(): this; /** * This read-only property is the length of the List. */ get count(): number; /** * This read-only property is the length of the List. */ get size(): number; /** * This read-only property is the length of the List, a synonym for the {@link count} property. */ get length(): number; /** * Gets an object that you can use for iterating over the List. * The key will be an integer from zero to the count-1. * The value will be the item at that index in the list. * Typical usage: * ```js * const it = aList.iterator; * while (it.next()) { * . . . "index: " + it.key + " value: " + it.value . . . * } * ``` */ get iterator(): Iterator<T>; /** * Gets an object that you can use for iterating over the List in backwards order. * The key will be an integer from count-1 to zero. * The value will be the item at that index in the list. * The list is not modified by traversing in reverse order. * Typical usage: * ```js * const it = aList.iteratorBackwards; * while (it.next()) { * . . . 'key: ' + it.key + ' value: ' + it.value . . . * } * ``` */ get iteratorBackwards(): Iterator<T>; } /** * An unordered iterable collection that cannot contain two instances of the same value. * In TypeScript it is a generic class that enforces at compile-time the type of elements that may be added to the Set. * * An example usage: * ```js * const set = new go.Set(); // In TypeScript: new go.Set<string>(); * set.add("orange"); * set.add("apple"); * set.add("orange"); * // now set.size === 2 * // and set.has("orange") === true * // and set.has("banana") === false * ``` * * You can iterate over the items in a Set: * ```js * const it = aSet.iterator; * while (it.next()) { * . . . it.value . . . * } * ``` * Or: * ```js * aSet.each(val => { * . . . val . . . * }); * ``` * * For compatibility with versions of GoJS before version 3.0, the following synonyms are defined: * - **remove(val)**: {@link delete} * - **contains(val)**: {@link has} * - **count**: {@link size} * * The constructor now takes an optional Iterable or Array argument that provides the initial elements for the new Set. * * Note that GoJS iteration is quite different than ECMAScript iteration, so that functionality has not been made somewhat compatible. * These collection classes were defined in GoJS before the ECMAScript collection classes were proposed. * @category Collection */ export class Set<T> implements Iterable<T> { /** * There are two possible constructors: * * `new go.Set()`, for JavaScript * * `new go.Set<T>()` for TypeScript * * In TypeScript, the optional generic argument describes the type of values * that this Set may hold. * * @param coll - an optional collection of items to add; it can be either a GoJS Iterable or a JavaScript Iterable, including an Array */ constructor(coll?: Iterable<T> | globalThis.Iterable<T>); /** * This class implements the JavaScript `Symbol.iterator`, * and can be used with spread syntax or `for ... of` statements. * @since 3.0 */ [Symbol.iterator](): IterableIterator<T>; /** * Return a JavaScript iterator that produces the values in this Set. * This does not produce the old GoJS style {@link Iterator} -- * use the {@link iterator} property if you want that. * @since 3.0 */ values(): IterableIterator<T>; /** */ toString(): string; /** * Adds a given value to the Set, if not already present. * * Be careful not to call this method while iterating over the collection. * @param val - The value to add to the Set; must not be null. * @returns This modified Set. */ add(val: T): this; /** * Adds all of the values of a collection to this Set. * * Be careful not to call this method while iterating over the collection. * @param coll - the collection of items to add -- it can be either a GoJS Iterable or a JavaScript Iterable, including an Array * @returns This modified Set. */ addAll(coll: Iterable<T> | globalThis.Iterable<T>): this; /** * Returns whether the given value is in this Set. * @param val - The value to check. * @returns Whether or not the value is contained within the Set. */ has(val: T): boolean; /** * Returns whether the given value is in this Set. * A synonym for {@link has}. * @param val - The value to check. * @returns Whether or not the value is contained within the Set. */ contains(val: T): boolean; /** * Returns true if all of the values of a given collection are in this Set. * @param coll - the collection of items to check for. */ containsAll(coll: Iterable<T> | globalThis.Iterable<T>): boolean; /** * Returns true if any of the values of a given collection are in this Set. * @param coll - the collection of items to check for. */ containsAny(coll: Iterable<T> | globalThis.Iterable<T>): boolean; /** * Returns the first item in the collection, or null if there is none. * @returns This returns null if there are no items in the collection. */ first(): T | null; /** * This is true if any invocation of the given predicate on items in the collection is true. * * Call the given predicate on each item in the collection. * As soon as a call returns true, this returns true. * Otherwise this returns false. * For an empty collection this returns false. * @virtual * @param pred - This function must not have any side-effects. * @returns True if any predicate call is true; false otherwise. */ any(pred: ((a: T) => boolean)): boolean; /** * This is true if all invocations of the given predicate on items in the collection are true. * * Call the given predicate on each item in the collection. * As soon as a call returns false, this returns false. * Otherwise this returns true. * For an empty collection this returns true. * @virtual * @param pred - This function must not have any side-effects. * @returns True if all predicate calls are true; false otherwise. */ all(pred: ((a: T) => boolean)): boolean; /** * Call the given function on each item in the collection. * @virtual * @param func - This function must not modify the collection. * @returns This Set itself. */ each(func: ((a: T) => void)): this; /** * Call the given function on each item in the collection and collect the results in a new Set. * * Unlike {@link Iterator.map}, this returns a Set, not an Iterator. * @virtual * @param func - This function must not modify the collection. */ map<S>(func: ((a: T) => S)): Set<S>; /** * Call the given predicate on each item in the collection and for each item that it returns true, collect the item in a new Set. * * Unlike {@link Iterator.filter}, this returns a Set, not an Iterator. * @virtual * @param pred - This function must not have any side-effects. */ filter(pred: ((a: T) => boolean)): Set<T>; /** * Removes a value (if found) from the Set. * * Be careful not to call this method while iterating over the collection. * @param val - The value to remove. * @returns true if the value was found and removed, false otherwise. */ delete(val: T): boolean; /** * Removes a value (if found) from the Set. * A synonym for {@link delete}. * * Be careful not to call this method while iterating over the collection. * @param val - The value to insert. * @returns true if the value was found and removed, false otherwise. */ remove(val: T): boolean; /** * Removes all of the values of a collection from this Set. * * Be careful not to call this method while iterating over the collection. * @param coll - the collection of items to remove. * @returns This modified Set. */ removeAll(coll: Iterable<T> | globalThis.Iterable<T>): this; /** * Removes from this Set all items that are not in the given collection. * * Be careful not to call this method while iterating over the collection. * @param coll - the collection of items that should be kept in this Set. * @returns This modified Set. */ retainAll(coll: Iterable<T> | globalThis.Iterable<T>): this; /** * Clears the Set. * This sets the {@link count} to zero. * * Be careful not to call this method while iterating over the collection. */ clear(): void; /** * Makes a shallow copy of this Set. * The values are not copied, * so if they are objects they may continue to be shared with the original Set. * @virtual * @returns The new Set with the same elements. */ copy(): Set<T>; /** * Produces a JavaScript Array from the contents of this Set. * @returns A copy of the Set in Array form. */ toArray(): Array<T>; /** * Converts the Set to a {@link List}. * Because there is no ordering within a Set, * the values in the List may be in any order. * @returns A copy of the contents of this Set in List form. */ toList(): List<T>; /** * This read-only property is the number of elements in the Set. */ get count(): number; /** * This read-only property is the number of elements in the Set. */ get size(): number; /** * Gets an object that you can use for iterating over the Set. * The value will be a member of the Set. * Typical usage: * ```js * const it = aSet.iterator; * while (it.next()) { * . . . " value: " + it.value . . . * } * ``` */ get iterator(): Iterator<T>; /** * For compatibility with the JavaScript Set class, this returns a JavaScript Set iterator of [value, value]s. */ entries(): IterableIterator<[T, T]>; /** * For compatibility with the JavaScript Set class, this returns a JavaScript Set iterator of values. */ keys(): IterableIterator<T>; /** * Call a provided function once per each key/value pair in this Set. * @param callbackFunc a function to call for each value in the Set * @param thisArg a value to use as this when executing callbackFunc * @since 3.0 */ forEach(callbackFunc: (value1: T, value2: T, map: Set<T>) => void, thisArg: any): void; } /** * An unordered iterable collection of key/value pairs that cannot contain two instances of the same key. * In TypeScript it is a generic class that enforces at compile-time the type of the key and the type of the associated value. * * To create a Map: * ```js * const map = new go.Map(); // In TypeScript: new go.Map<string, number>(); * map.set("one", 1); * map.set("two", 2); * map.set("three", 3); * // now map.size === 3 * // and map.get("two") === 2 * // and map.has("zero") === false * ``` * * You can iterate over the key/value pairs in a Map: * ```js * const it = aMap.iterator; * while (it.next()) { * console.log(it.key + ": " + it.value); * } * ``` * Or: * ```js * aMap.each(kvp => { * console.log(kvp.key + ": " + kvp.value); * }); * ``` * But note that there is no guaranteed ordering amongst the key/value pairs. * * Call {@link toKeySet} to get a read-only {@link Set | go.Set} that holds all of the keys of a Map. * Iterating over that Set will produce values that are the keys in the Map. * * For compatibility with versions of GoJS before version 3.0, the following synonyms are defined: * - **getValue(key)**: {@link get}, but returns null instead of undefined when key is not present * - **add(key,val)**: {@link set} * - **contains(key)**: {@link has} * - **remove(key)**: {@link delete} * - **count**: {@link size} * * The constructor now takes an optional Iterable or Array argument that provides the initial entries for the new Map. * * Note that GoJS iteration is quite different than ECMAScript iteration, so that functionality has not been made somewhat compatible. * These collection classes were defined in GoJS before the ECMAScript collection classes were proposed. * @category Collection */ export class Map<K, V> { /** * There are two possible constructors: * * `new go.Map()`, for JavaScript * * `new go.Map<K, V>()` for TypeScript * * In TypeScript, the two optional generic arguments describe the types of keys * and the types of values that this Map may hold. * * @param coll - an optional collection of {@link IKeyValuePair}s to add -- * it can be either a GoJS Iterable or a JavaScript Iterable, including an Array */ constructor(coll?: Iterable<IKeyValuePair<K, V>> | Array<IKeyValuePair<K, V>> | Map<K, V> | globalThis.Iterable<readonly [K, V]>); /** * This class implements the JavaScript `Symbol.iterator`, * and can be used with spread syntax or `for ... of` statements. * @since 3.0 */ [Symbol.iterator](): IterableIterator<[K, V]>; /** * Return a JavaScript iterator that produces the entries ([key, value] pairs) of this Map. * This does not produce the old GoJS style {@link Iterator} -- * use the {@link iterator} property if you want that. * @since 3.0 */ entries(): IterableIterator<[K, V]>; /** */ toString(): string; /** * Adds a key-value association to the Map, or replaces the value associated with the key * if the key was already present in the map. * * Be careful not to call this method while iterating over the collection. * @param key - The key or index for storing the value in the Map. * @param val - The value to add to the Map, associated with the key. * @returns This modified Map. */ set(key: K, val: V): this; /** * Adds a key-value association to the Map, or replaces the value associated with the key * if the key was already present in the map. * A synonym for {@link set}. * * Be careful not to call this method while iterating over the collection. * @param key - The key or index for storing the value in the Map. * @param val - The value to add to the Map, associated with the key. * @returns This modified Map. */ add(key: K, val: V): Map<K, V>; /** * Adds all of the key-value pairs to this Map. * If a key is already present in this Map, * its value is replaced with the corresponding value from the given map. * * Be careful not to call this method while iterating over the collection. * @param coll - the collection of {@link IKeyValuePair}s to add, or an Array of {@link IKeyValuePair}s, * or a GoJS {@link Map}, or a JavaScript `Map`, or an Array or other JavaScript Iterable wh