import { a as EitherKey, c as TableValue, i as ArrayKeys, l as isObjectKeys, o as ObjectKeys, s as TableRow } from "./map-Dgj9_4Jy.js"; import { i as Table, t as index_d_exports } from "./index-D1dhV6fv.js"; import { A as ExpiringMap, E as MapOfSimpleMutable, F as CircularArray, I as ICircularArray, t as index_d_exports$1 } from "./index-gGF20WwQ.js"; import { g as QueueOpts, h as QueueDiscardPolicy, l as QueueImmutable, p as QueueMutable, t as index_d_exports$2 } from "./index-C-VpPrt2.js"; import { a as ISetImmutable, c as ISetMutable, l as ValueSetEventMap, o as SetStringMutable, r as SetStringImmutable, t as index_d_exports$3 } from "./index-CzJoDvxd.js"; import { IStackImmutable, StackImmutable, StackMutable, t as index_d_exports$4 } from "./stack/index.js"; import { C as TraverseObjectEntryStatic, D as WrappedNode, E as TreeNode, S as TraverseObjectEntry, T as TraverseObjectPathOpts, _ as LabelledSingleValue, b as SimplifiedNode, g as LabelledNode, t as index_d_exports$5, v as LabelledValue, w as TraverseObjectEntryWithAncestors, x as TraversableTree, y as LabelledValues } from "./index-rrpZOWbs.js"; import { Comparer } from "@ixfx/core"; import { Result } from "@ixfx/guards"; //#region src/events/types.d.ts type EventItem = Readonly<{ /** * Start point, inclusive */ start: number; /** * End point, exclusive */ end: number; }>; type EventItemAsDuration = Readonly<{ start: number; duration: number; }>; type IdEventItem = EventItem & Readonly<{ id: string; }>; type SplitOptionsRelative = { percentage: number; }; type SplitOptionsAbsolute = { start: number; }; type SplitOptions = (SplitOptionsRelative | SplitOptionsAbsolute); type IndexedEventItem = Readonly<{ event: EventItem; index: number; }>; type EventInterval = Readonly<{ a: EventItem; b: EventItem; /** * Interval between start points (B - A) */ startInterval: number; /** * Interval between end points (B - A) */ endInterval: number; /** * Interval between end of `a` and start of `b` (B.start - A.end) * Note, this might be negative if a and b overlap */ betweenInterval: number; indexA: number; indexB: number; }>; type DefragmentOptions = Readonly<{ gap: number; startAt: number; }>; //#endregion //#region src/events/events-fns.d.ts /** * Sorts by start, such that 'start' values are ascending. * * Returns: * 0 if A and B are have same start & end. * positive if B is before A. * negative if B is after A. * * If A and B have the same start point, they are secondarily sorted based on end time, with earlier end time considered "before" later end time. * * Use {@link CompareByStartOnly} to ignore end time and consider events equal if they share a `start`. * @param a * @param b */ declare const CompareByStart: Comparer; declare const CompareByStartOnly: Comparer; /** * Sorts by end, such that 'end' values are ascending. * * Returns: * 0 if A and B are have same start & end. * Returns positive if B is before A. * Returns negative if B is after A. * * If A and B share the same end, shorter items will come first (ie. those with higher start) * @param a * @param b */ declare const CompareByEnd: Comparer; declare const CompareByEndOnly: Comparer; /** * Returns a new array of events ordered by their start time (ascending) * @param events * @returns Events ordered by start time */ declare function sortByStart(events: EventItem[]): EventItem[]; /** * Returns a new array of events ordered by their end time (ascending) * @param events * @returns Events ordered by end time */ declare function sortByEnd(events: EventItem[]): EventItem[]; /** * Yields every item in `sortedEvents` that has the specified `start` value * * Return item is a wrapped object consisting of the event as well as its index. * ```js * const events = [ { start: 1, end: 2}, { start: 5, end: 10 }, { start: 10, end: 12 }]; * const matched = [...itemsWithStart(events, 5)]; * // matched is [{ event: { start: 5, end: 10 }, index: 1 }] * ``` * @param sortedEvents Sorted events * @param start Start position */ declare function itemsWithStart(sortedEvents: EventItem[], start: number): Generator; /** * Yields every item in `eventsByEnd` that has the specified `end` value. * Return item is a wrapped object consisting of the event as well as its index. * * The function expects that the input array has been sorted using {@link sortByEnd}, and therefore * sorted by ascending end value. * * ```js * const events = [ { start: 1, end: 2}, { start: 5, end: 10 }, { start: 10, end: 12 }]; * const matched = [...itemsWithEnd(events, 10)]; * // matched is [{ event: { start: 5, end: 10 }, index: 1 }] * ``` * @param eventsByEnd Events sorted with {@link sortByEnd} * @param end End position */ declare function itemsWithEnd(eventsByEnd: EventItem[], end: number): Generator; /** * Converts a collection of `IndexedEventItem` back into an array of `EventItem`, placing items at their original index. * * ```js * // Get all items that start at position 5 * const itemsAtPosition = [...itemsWithStart(sortedEvents, 5)]; * * // Make this into an array: * const items = arrayFromItems(itemsAtPosition); * ``` * * By default, the `index` field is used to construct the array. If `ignoreIndexes` is set to _true_, * the the returned array is constructed in the order of the input items, ignoring the `index` field. This can be useful if you just want to extract the events from a generator without caring about their original position. * @param items * @returns EventItems */ declare function arrayFromItems(items: Iterable, ignoreIndexes?: boolean): EventItem[]; /** * Yields all events that overlap with `point`. * By default event end is considered exclusive, meaning that if `point == event.end`, it is not considered overlapping. * If `endInclusive` is true, event end is considered inclusive, and the aforementioned would be considered ovlerapping. * * By default start is inclusive. * * @param sortedEvents * @param point * @param endInclusive Whether event end is considered inclusive for determining overlap (default:false) * @param startInclusive Whether event start is considered inclusive for determining overlap (default:true) */ declare function overlapping(sortedEvents: T[], point: number, endInclusive?: boolean, startInclusive?: boolean): Generator; /** * Inserts space within `sortedEvents`. It does this by shifting events forward. * * If `start` overlaps with existing item(s), `overlappingPolicy` is used: * - 'ignore': Event duration is not changed * - 'stretch': Events that overlap are stretched by `length`. * * When considering overlap, both end is exclusive and start are considered exclusive. * * Eg, if we have the event `{ start: 5, end: 10 }`. * - insertSpace(data, 5, 1, `ignore`); // Would not be considered overlapping, but event would be shifted to { start: 6, end: 11 } * - insertSpace(data, 10, 1, `ignore`); // Would not be considered overlapping, event would remain { start: 5, end: 10 } * - insertSpace(data, 5, 1, `stretch`); // Would be considered overlapping, event shifted to { start: 6, end: 11 } * - insertSpace(data, 6, 1, `stretch`); // Would be considered overlapping, event would be stretched to { start: 5, end: 11 } * @param sortedEvents * @param start * @param length * @param overlappingPolicy */ declare function insertSpace(sortedEvents: T[], start: number, length: number, overlappingPolicy: `ignore` | `stretch`): T[]; /** * Punches a hole in `sortedEvents` which overlap `hole`. * It does this by splitting/trimming events, or removing an event entirely it is fully covered by the hole. * * This will never shift events in time. * @param sortedEvents * @param hole */ declare function holepunch(sortedEvents: T[], hole: EventItem): T[]; /** * Returns _true_ if `item` has zero duration (start and end are the same), _false_ otherwise. * ```js * isEmpty({ start: 1, end: 1 }); // true * isEmpty({ start: 1, end: 2 }); // false * ``` * @param item * @returns _true_ if `item` is empty. */ declare function isEmpty(item: EventItem): boolean; /** * Creates an `EventItem` from an `EventItemAsDuration` by calculating the end as start + duration. * ```js * fromDuration({ start: 1, duration: 2 }); // { start: 1, end: 3 } * ``` * * Copies additional properties to the return result. * @param item * @returns EventItem */ declare function fromDuration(item: EventItemAsDuration): EventItem; /** * Creats an `EventItemAsDuration` from an `EventItem` by calculating the duration as end - start. * ```js * toDuration({ start: 1, end: 3 }); // { start: 1, duration: 2 } * ``` * * Copies additional properties to the return result. * @param item * @returns EventItemAsDuration */ declare function toDuration(item: EventItem): EventItemAsDuration; /** * Returns the intervals between pairs of events. * * If `sortedEvents` has less than two events, yields nothing * @param sortedEvents */ declare function intervals(sortedEvents: EventItem[]): Generator; declare function isValid(item: unknown): Result; declare function isEventItem(item: unknown): item is EventItem; /** * Removes `toRemove` from `sortedEvents`. * * Consider {@link holepunch} if you want to create an empty hole in the events and maintain overall length of event series. * * After removing: * - 'nothing': Gap is left, other items not affected * - 'shuffle-following': Events after 'toRemove' are shifted back by duration of `toRemove`, maintaining their spacing after that * - 'shuffle-leading': Events before 'toRemove' are shifted forward by duration of `toRemove`, maintaining their spacing before that * - 'slice-following': Events after 'toRemove' are shifted back to start at `toRemoved.start`, maintaining their spacing after that * - 'slice-leading': Events before 'toRemove' are shifted forward to end at `toRemoved.end`, maintaining their spacing before that * @param sortedEvents * @param toRemove */ declare function remove(sortedEvents: EventItem[], toRemove: EventItem, andThen: `nothing` | `shuffle-following` | `shuffle-leading` | `slice-following` | `slice-leading`): EventItem[]; /** * Splits `event` into two events by either a percentange of duration or by a specific start position. * * If `options` has a `percentage` field, the split point is calculated as `event.start + (event.end - event.start) * percentage`. * If `options` has a `start` field, the split point is simply that value. * * ```js * splitEvent({ start: 0, end: 10 }, { percentage: 0.5 }); // [{ start: 0, end: 5 }, { start: 5, end: 10 }] * splitEvent({ start: 0, end: 10 }, { start: 3 }); // [{ start: 0, end: 3 }, { start: 3, end: 10 }] * ``` * * Any other properties on `event` are copied to split events. * @param event Input event * @param options How to split * @returns Split event */ declare function splitEvent(event: EventItem, options: SplitOptions): [a: EventItem, b: EventItem]; /** * Applies `fn` to both `start` and `end` fields, returning a new event. * * Existing data on `event` is maintained. * * ```js * applyToPosition( { start:1.2, end:2.4 }, v => Math.round(v)); // { start:1, end:2 } * applyToPosition( { start:1, end:2 }, v => v*2); // { start:2, end:4 } * ``` * * Use {@link translate} if you just want to add an amount to start and end, instead of applying a custom function. * @param event Input event * @param fn Function to run over start and end * @returns New event with `fn` applied to start and end */ declare function applyToPositions(event: EventItem, fn: (v: number) => number): EventItem; /** * Translates an event by adding `amount` to both `start` and `end`, returning a new event. * ```js * translate( { start:1, end:2 }, 3); // { start:4, end:5 } * translate( { start:1, end:2 }, -1); // { start:0, end:1 } * ``` * * Existing data on `event` is maintained. * * Use {@link applyToPositions} if you want to apply a custom function to the start and end, instead of just adding an amount. * @param event * @param amount * @returns New EventItem */ declare function translate(event: T, amount: number): T; /** * Returns how `b` overlaps with `a`. * * Returns: * - `none` if `b` does not overlap with `a` * - `equal` if `b` has the same start and end as `a` * - `full` if `b` is fully contained within `a` and `a` does not share a start/end * - `full-border` if `b` is fully contained within `a` and `a` shares a start/end * - `partial` if `b` overlaps with `a` but is not fully contained within it * * ```js * compareRange({ start:2, end:4 }, { start:0, end:1 }); // 'none' * compareRange({ start:2, end:4 }, { start: 2, end:4 }); // 'equal' * compareRange({ start:2, end:4 }, { start: 3, end: 3 }); // 'full' * compareRange({ start:2, end:4 }, { start: 3, end: 4 }); // 'full-border' * compareRange({ start:2, end:4 }, { start: 1, end: 3 }); // 'partial' * ``` * @param a * @param b */ declare function compareRange(a: T, b: T): `none` | `partial` | `full` | `full-border` | `equal`; /** * Lays out events end-to-end, removing gaps between them and having the first start at 0. * Duration of events is maintained. * @param sortedEvents */ declare function defragment(sortedEvents: EventItem[], options?: Partial): EventItem[]; declare function createFromStarts(starts: number[], duration: number, idPrefix?: string): IdEventItem[]; /** * Gets the range of `events`: the smallest 'start' and the largest 'end'. * * If there are gaps between events, this is still included in the range. Use {@link sumDuration} * to add up the duration of all events as if they are stacked end-to-end. * @param events * @returns Range of events */ declare function computeRange(events: EventItem[]): { start: number; end: number; }; /** * Returns the total duration of all events. Doesn't take into account * the spacing between events, just sums the duration of each one. * * Use {@link computeRange} if you want to calculate the min and max starting points. * @param events * @returns Duration */ declare function sumDuration(events: EventItem[]): number; //#endregion export { ArrayKeys, CircularArray, CompareByEnd, CompareByEndOnly, CompareByStart, CompareByStartOnly, DefragmentOptions, EitherKey, EventInterval, EventItem, EventItemAsDuration, ExpiringMap, index_d_exports as Graphs, ICircularArray, type ISetImmutable, ISetMutable, type IStackImmutable, IdEventItem, IndexedEventItem, LabelledNode, LabelledSingleValue, LabelledValue, LabelledValues, MapOfSimpleMutable, index_d_exports$1 as Maps, ObjectKeys, QueueDiscardPolicy, QueueImmutable, QueueMutable, QueueOpts, index_d_exports$2 as Queues, SetStringImmutable, SetStringMutable, index_d_exports$3 as Sets, SimplifiedNode, SplitOptions, SplitOptionsAbsolute, SplitOptionsRelative, StackImmutable, StackMutable, index_d_exports$4 as Stacks, Table, TableRow, TableValue, TraversableTree, TraverseObjectEntry, TraverseObjectEntryStatic, TraverseObjectEntryWithAncestors, TraverseObjectPathOpts, TreeNode, index_d_exports$5 as Trees, ValueSetEventMap, WrappedNode, applyToPositions, arrayFromItems, compareRange, computeRange, createFromStarts, defragment, fromDuration, holepunch, insertSpace, intervals, isEmpty, isEventItem, isObjectKeys, isValid, itemsWithEnd, itemsWithStart, overlapping, remove, sortByEnd, sortByStart, splitEvent, sumDuration, toDuration, translate };