@tldraw/utils 5.5.0-canary.fdb2d37fcb2a → 5.5.0-canary.fdd9b4dee0d9

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.
@@ -1,6 +1,5 @@
1
1
  import { default as isEqual } from 'lodash.isequal';
2
2
  import { default as isEqualWith } from 'lodash.isequalwith';
3
- import { default as throttle } from 'lodash.throttle';
4
3
  import { default as uniq } from 'lodash.uniq';
5
4
 
6
5
  /* Excluded from this release type: annotateError */
@@ -1791,7 +1790,48 @@ export declare function sortByMaybeIndex<T extends {
1791
1790
  declare const structuredClone_2: <T>(i: T) => T;
1792
1791
  export { structuredClone_2 as structuredClone }
1793
1792
 
1794
- export { throttle }
1793
+ /**
1794
+ * Creates a throttled function that invokes `fn` at most once per `wait` milliseconds. Wraps
1795
+ * lodash's `throttle`, typed with {@link ThrottledFunction} so the published types don't depend
1796
+ * on lodash's type packages.
1797
+ *
1798
+ * @example
1799
+ * ```ts
1800
+ * const save = throttle(() => persist(), 1000, { leading: false })
1801
+ * save()
1802
+ * save.flush()
1803
+ * ```
1804
+ *
1805
+ * @public
1806
+ */
1807
+ export declare const throttle: <T extends (...args: any[]) => any>(fn: T, wait?: number, options?: {
1808
+ leading?: boolean;
1809
+ trailing?: boolean;
1810
+ }) => ThrottledFunction<T>;
1811
+
1812
+ /**
1813
+ * The function returned by `throttle`. Call it like the original function; it returns the
1814
+ * result of the last invocation, or `undefined` if the original hasn't run yet.
1815
+ *
1816
+ * Declared here rather than re-exported from `@types/lodash`, so code can name a throttled
1817
+ * function's type without depending on lodash's type packages.
1818
+ *
1819
+ * @example
1820
+ * ```ts
1821
+ * class Saver {
1822
+ * save: ThrottledFunction<() => void> = throttle(() => this.persist(), 1000)
1823
+ * }
1824
+ * ```
1825
+ *
1826
+ * @public
1827
+ */
1828
+ export declare interface ThrottledFunction<T extends (...args: any[]) => any> {
1829
+ (...args: Parameters<T>): ReturnType<T> | undefined;
1830
+ /** Cancels any pending invocation. */
1831
+ cancel(): void;
1832
+ /** Immediately runs any pending invocation and returns its result. */
1833
+ flush(): ReturnType<T> | undefined;
1834
+ }
1795
1835
 
1796
1836
  /* Excluded from this release type: throttleToNextFrame */
1797
1837
 
@@ -1876,6 +1916,47 @@ export declare class Timers {
1876
1916
  * @public
1877
1917
  */
1878
1918
  requestAnimationFrame(contextId: string, callback: FrameRequestCallback): number;
1919
+ /**
1920
+ * Clears a timeout created with {@link Timers.setTimeout} and stops tracking it.
1921
+ * Prefer this over the global `clearTimeout` for ids that came from this instance,
1922
+ * otherwise the id stays tracked until its context is disposed.
1923
+ * @param contextId - The context identifier the timeout was created under.
1924
+ * @param id - The timer ID returned by `setTimeout`. Ignored when undefined.
1925
+ * @example
1926
+ * ```ts
1927
+ * const timers = new Timers()
1928
+ * const id = timers.setTimeout('autosave', () => save(), 5000)
1929
+ * timers.clearTimeout('autosave', id)
1930
+ * ```
1931
+ * @public
1932
+ */
1933
+ clearTimeout(contextId: string, id: number | undefined): void;
1934
+ /**
1935
+ * Clears an interval created with {@link Timers.setInterval} and stops tracking it.
1936
+ * @param contextId - The context identifier the interval was created under.
1937
+ * @param id - The interval ID returned by `setInterval`. Ignored when undefined.
1938
+ * @example
1939
+ * ```ts
1940
+ * const timers = new Timers()
1941
+ * const id = timers.setInterval('refresh', () => updateData(), 1000)
1942
+ * timers.clearInterval('refresh', id)
1943
+ * ```
1944
+ * @public
1945
+ */
1946
+ clearInterval(contextId: string, id: number | undefined): void;
1947
+ /**
1948
+ * Cancels an animation frame requested with {@link Timers.requestAnimationFrame} and stops tracking it.
1949
+ * @param contextId - The context identifier the animation frame was requested under.
1950
+ * @param id - The request ID returned by `requestAnimationFrame`. Ignored when undefined.
1951
+ * @example
1952
+ * ```ts
1953
+ * const timers = new Timers()
1954
+ * const id = timers.requestAnimationFrame('render', () => draw())
1955
+ * timers.cancelAnimationFrame('render', id)
1956
+ * ```
1957
+ * @public
1958
+ */
1959
+ cancelAnimationFrame(contextId: string, id: number | undefined): void;
1879
1960
  /**
1880
1961
  * Disposes of all timers associated with the specified context.
1881
1962
  * Clears all timeouts, intervals, and animation frames for the given context ID.
@@ -1913,23 +1994,29 @@ export declare class Timers {
1913
1994
  * Returns an object with timer methods bound to a specific context.
1914
1995
  * Convenient for getting context-specific timer functions without repeatedly passing the contextId.
1915
1996
  * @param contextId - The context identifier to bind the returned methods to.
1916
- * @returns An object with setTimeout, setInterval, requestAnimationFrame, and dispose methods bound to the context.
1997
+ * @returns An object with setTimeout, setInterval, requestAnimationFrame, the matching clear methods, and dispose bound to the context.
1917
1998
  * @example
1918
1999
  * ```ts
1919
2000
  * const timers = new Timers()
1920
2001
  * const uiTimers = timers.forContext('ui')
1921
2002
  *
1922
2003
  * // These are equivalent to calling timers.setTimeout('ui', ...)
1923
- * uiTimers.setTimeout(() => console.log('timeout'), 1000)
2004
+ * const id = uiTimers.setTimeout(() => console.log('timeout'), 1000)
1924
2005
  * uiTimers.setInterval(() => console.log('interval'), 500)
1925
2006
  * uiTimers.requestAnimationFrame(() => console.log('frame'))
1926
2007
  *
2008
+ * // Clear a single timer
2009
+ * uiTimers.clearTimeout(id)
2010
+ *
1927
2011
  * // Dispose only this context
1928
2012
  * uiTimers.dispose()
1929
2013
  * ```
1930
2014
  * @public
1931
2015
  */
1932
2016
  forContext(contextId: string): {
2017
+ cancelAnimationFrame: (id: number | undefined) => void;
2018
+ clearInterval: (id: number | undefined) => void;
2019
+ clearTimeout: (id: number | undefined) => void;
1933
2020
  dispose: () => void;
1934
2021
  requestAnimationFrame: (callback: FrameRequestCallback) => number;
1935
2022
  setInterval: (handler: TimerHandler, timeout?: number, ...args: any[]) => number;
@@ -1,8 +1,7 @@
1
1
  import { registerTldrawLibraryVersion } from "./lib/version.mjs";
2
2
  import { default as default2 } from "lodash.isequal";
3
3
  import { default as default3 } from "lodash.isequalwith";
4
- import { default as default4 } from "lodash.throttle";
5
- import { default as default5 } from "lodash.uniq";
4
+ import { default as default4 } from "lodash.uniq";
6
5
  import {
7
6
  areArraysShallowEqual,
8
7
  compact,
@@ -88,7 +87,12 @@ import {
88
87
  } from "./lib/storage.mjs";
89
88
  import { getFirstCharacter, iterateGraphemes } from "./lib/string.mjs";
90
89
  import { stringEnum } from "./lib/stringEnum.mjs";
91
- import { FpsScheduler, fpsThrottle, throttleToNextFrame } from "./lib/throttle.mjs";
90
+ import {
91
+ FpsScheduler,
92
+ fpsThrottle,
93
+ throttle,
94
+ throttleToNextFrame
95
+ } from "./lib/throttle.mjs";
92
96
  import { Timers } from "./lib/timers.mjs";
93
97
  import { safeParseUrl } from "./lib/url.mjs";
94
98
  import {
@@ -103,7 +107,7 @@ import { registerTldrawLibraryVersion as registerTldrawLibraryVersion2 } from ".
103
107
  import { warnDeprecatedGetter, warnOnce } from "./lib/warn.mjs";
104
108
  registerTldrawLibraryVersion(
105
109
  "@tldraw/utils",
106
- "5.5.0-canary.fdb2d37fcb2a",
110
+ "5.5.0-canary.fdd9b4dee0d9",
107
111
  "esm"
108
112
  );
109
113
  export {
@@ -205,9 +209,9 @@ export {
205
209
  sortByMaybeIndex,
206
210
  stringEnum,
207
211
  structuredClone,
208
- default4 as throttle,
212
+ throttle,
209
213
  throttleToNextFrame,
210
- default5 as uniq,
214
+ default4 as uniq,
211
215
  uniqueId,
212
216
  validateIndexKey,
213
217
  warnDeprecatedGetter,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["import { registerTldrawLibraryVersion } from './lib/version'\n\nexport { default as isEqual } from 'lodash.isequal'\nexport { default as isEqualWith } from 'lodash.isequalwith'\nexport { default as throttle } from 'lodash.throttle'\nexport { default as uniq } from 'lodash.uniq'\nexport {\n\tareArraysShallowEqual,\n\tcompact,\n\tdedupe,\n\tlast,\n\tmaxBy,\n\tmergeArraysAndReplaceDefaults,\n\tminBy,\n\tpartition,\n\trotateArray,\n} from './lib/array'\nexport { bind } from './lib/bind'\nexport { WeakCache } from './lib/cache'\nexport {\n\tassert,\n\tassertExists,\n\texhaustiveSwitchError,\n\tpromiseWithResolve,\n\tResult,\n\tsleep,\n\ttype ErrorResult,\n\ttype OkResult,\n} from './lib/control'\nexport { debounce } from './lib/debounce'\nexport { annotateError, getErrorAnnotations, type ErrorAnnotations } from './lib/error'\nexport { ExecutionQueue } from './lib/ExecutionQueue'\nexport { FileHelpers } from './lib/file'\nexport { noop, omitFromStackTrace } from './lib/function'\nexport { getHashForBuffer, getHashForObject, getHashForString, lns } from './lib/hash'\nexport { mockUniqueId, restoreUniqueId, uniqueId } from './lib/id'\nexport { getFirstFromIterable } from './lib/iterable'\nexport { LruCache } from './lib/LruCache'\nexport type { JsonArray, JsonObject, JsonPrimitive, JsonValue } from './lib/json-value'\nexport {\n\tDEFAULT_SUPPORT_VIDEO_TYPES,\n\tDEFAULT_SUPPORTED_IMAGE_TYPES,\n\tDEFAULT_SUPPORTED_MEDIA_TYPE_LIST,\n\tDEFAULT_SUPPORTED_MEDIA_TYPES,\n\tMediaHelpers,\n} from './lib/media/media'\nexport { PngHelpers } from './lib/media/png'\nexport { fetch, Image } from './lib/network'\nexport { invLerp, lerp, modulate, rng } from './lib/number'\nexport {\n\tareObjectsShallowEqual,\n\tfilterEntries,\n\tgetChangedKeys,\n\tgetOwnProperty,\n\tgroupBy,\n\thasOwnProperty,\n\tisEqualAllowingForFloatingPointErrors,\n\tmapObjectMapValues,\n\tobjectMapEntries,\n\tobjectMapEntriesIterable,\n\tobjectMapFromEntries,\n\tobjectMapKeys,\n\tobjectMapValues,\n\tomit,\n} from './lib/object'\nexport { measureAverageDuration, measureCbDuration, measureDuration } from './lib/perf'\nexport { PerformanceTracker } from './lib/PerformanceTracker'\nexport {\n\tgetIndexAbove,\n\tgetIndexBelow,\n\tgetIndexBetween,\n\tgetIndices,\n\tgetIndicesAbove,\n\tgetIndicesBelow,\n\tgetIndicesBetween,\n\tsortByIndex,\n\tsortByMaybeIndex,\n\tvalidateIndexKey,\n\tZERO_INDEX_KEY,\n\ttype IndexKey,\n} from './lib/reordering'\nexport { retry } from './lib/retry'\nexport { sortById } from './lib/sort'\nexport {\n\tclearLocalStorage,\n\tclearSessionStorage,\n\tdeleteFromLocalStorage,\n\tdeleteFromSessionStorage,\n\tgetFromLocalStorage,\n\tgetFromSessionStorage,\n\tsetInLocalStorage,\n\tsetInSessionStorage,\n} from './lib/storage'\nexport { getFirstCharacter, iterateGraphemes } from './lib/string'\nexport { stringEnum } from './lib/stringEnum'\nexport { FpsScheduler, fpsThrottle, throttleToNextFrame } from './lib/throttle'\nexport { Timers } from './lib/timers'\nexport {\n\ttype Awaitable,\n\ttype Expand,\n\ttype MakeUndefinedOptional,\n\ttype RecursivePartial,\n\ttype Required,\n} from './lib/types'\nexport { safeParseUrl } from './lib/url'\nexport {\n\tisDefined,\n\tisNativeStructuredClone,\n\tisNonNull,\n\tisNonNullish,\n\tSTRUCTURED_CLONE_OBJECT_PROTOTYPE,\n\tstructuredClone,\n} from './lib/value'\nexport { registerTldrawLibraryVersion } from './lib/version'\nexport { warnDeprecatedGetter, warnOnce } from './lib/warn'\n\nregisterTldrawLibraryVersion(\n\t(globalThis as any).TLDRAW_LIBRARY_NAME,\n\t(globalThis as any).TLDRAW_LIBRARY_VERSION,\n\t(globalThis as any).TLDRAW_LIBRARY_MODULES\n)\n"],
5
- "mappings": "AAAA,SAAS,oCAAoC;AAE7C,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAA8B;AACvC,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAAuB;AAChC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP,SAAS,gBAAgB;AACzB,SAAS,eAAe,2BAAkD;AAC1E,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,MAAM,0BAA0B;AACzC,SAAS,kBAAkB,kBAAkB,kBAAkB,WAAW;AAC1E,SAAS,cAAc,iBAAiB,gBAAgB;AACxD,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AAEzB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,kBAAkB;AAC3B,SAAS,OAAO,aAAa;AAC7B,SAAS,SAAS,MAAM,UAAU,WAAW;AAC7C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,wBAAwB,mBAAmB,uBAAuB;AAC3E,SAAS,0BAA0B;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAmB,wBAAwB;AACpD,SAAS,kBAAkB;AAC3B,SAAS,cAAc,aAAa,2BAA2B;AAC/D,SAAS,cAAc;AAQvB,SAAS,oBAAoB;AAC7B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,gCAAAC,qCAAoC;AAC7C,SAAS,sBAAsB,gBAAgB;AAE/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF;",
4
+ "sourcesContent": ["import { registerTldrawLibraryVersion } from './lib/version'\n\nexport { default as isEqual } from 'lodash.isequal'\nexport { default as isEqualWith } from 'lodash.isequalwith'\nexport { default as uniq } from 'lodash.uniq'\nexport {\n\tareArraysShallowEqual,\n\tcompact,\n\tdedupe,\n\tlast,\n\tmaxBy,\n\tmergeArraysAndReplaceDefaults,\n\tminBy,\n\tpartition,\n\trotateArray,\n} from './lib/array'\nexport { bind } from './lib/bind'\nexport { WeakCache } from './lib/cache'\nexport {\n\tassert,\n\tassertExists,\n\texhaustiveSwitchError,\n\tpromiseWithResolve,\n\tResult,\n\tsleep,\n\ttype ErrorResult,\n\ttype OkResult,\n} from './lib/control'\nexport { debounce } from './lib/debounce'\nexport { annotateError, getErrorAnnotations, type ErrorAnnotations } from './lib/error'\nexport { ExecutionQueue } from './lib/ExecutionQueue'\nexport { FileHelpers } from './lib/file'\nexport { noop, omitFromStackTrace } from './lib/function'\nexport { getHashForBuffer, getHashForObject, getHashForString, lns } from './lib/hash'\nexport { mockUniqueId, restoreUniqueId, uniqueId } from './lib/id'\nexport { getFirstFromIterable } from './lib/iterable'\nexport { LruCache } from './lib/LruCache'\nexport type { JsonArray, JsonObject, JsonPrimitive, JsonValue } from './lib/json-value'\nexport {\n\tDEFAULT_SUPPORT_VIDEO_TYPES,\n\tDEFAULT_SUPPORTED_IMAGE_TYPES,\n\tDEFAULT_SUPPORTED_MEDIA_TYPE_LIST,\n\tDEFAULT_SUPPORTED_MEDIA_TYPES,\n\tMediaHelpers,\n} from './lib/media/media'\nexport { PngHelpers } from './lib/media/png'\nexport { fetch, Image } from './lib/network'\nexport { invLerp, lerp, modulate, rng } from './lib/number'\nexport {\n\tareObjectsShallowEqual,\n\tfilterEntries,\n\tgetChangedKeys,\n\tgetOwnProperty,\n\tgroupBy,\n\thasOwnProperty,\n\tisEqualAllowingForFloatingPointErrors,\n\tmapObjectMapValues,\n\tobjectMapEntries,\n\tobjectMapEntriesIterable,\n\tobjectMapFromEntries,\n\tobjectMapKeys,\n\tobjectMapValues,\n\tomit,\n} from './lib/object'\nexport { measureAverageDuration, measureCbDuration, measureDuration } from './lib/perf'\nexport { PerformanceTracker } from './lib/PerformanceTracker'\nexport {\n\tgetIndexAbove,\n\tgetIndexBelow,\n\tgetIndexBetween,\n\tgetIndices,\n\tgetIndicesAbove,\n\tgetIndicesBelow,\n\tgetIndicesBetween,\n\tsortByIndex,\n\tsortByMaybeIndex,\n\tvalidateIndexKey,\n\tZERO_INDEX_KEY,\n\ttype IndexKey,\n} from './lib/reordering'\nexport { retry } from './lib/retry'\nexport { sortById } from './lib/sort'\nexport {\n\tclearLocalStorage,\n\tclearSessionStorage,\n\tdeleteFromLocalStorage,\n\tdeleteFromSessionStorage,\n\tgetFromLocalStorage,\n\tgetFromSessionStorage,\n\tsetInLocalStorage,\n\tsetInSessionStorage,\n} from './lib/storage'\nexport { getFirstCharacter, iterateGraphemes } from './lib/string'\nexport { stringEnum } from './lib/stringEnum'\nexport {\n\tFpsScheduler,\n\tfpsThrottle,\n\tthrottle,\n\tthrottleToNextFrame,\n\ttype ThrottledFunction,\n} from './lib/throttle'\nexport { Timers } from './lib/timers'\nexport {\n\ttype Awaitable,\n\ttype Expand,\n\ttype MakeUndefinedOptional,\n\ttype RecursivePartial,\n\ttype Required,\n} from './lib/types'\nexport { safeParseUrl } from './lib/url'\nexport {\n\tisDefined,\n\tisNativeStructuredClone,\n\tisNonNull,\n\tisNonNullish,\n\tSTRUCTURED_CLONE_OBJECT_PROTOTYPE,\n\tstructuredClone,\n} from './lib/value'\nexport { registerTldrawLibraryVersion } from './lib/version'\nexport { warnDeprecatedGetter, warnOnce } from './lib/warn'\n\nregisterTldrawLibraryVersion(\n\t(globalThis as any).TLDRAW_LIBRARY_NAME,\n\t(globalThis as any).TLDRAW_LIBRARY_VERSION,\n\t(globalThis as any).TLDRAW_LIBRARY_MODULES\n)\n"],
5
+ "mappings": "AAAA,SAAS,oCAAoC;AAE7C,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAA8B;AACvC,SAAoB,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ACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,cAAc;AAQvB,SAAS,oBAAoB;AAC7B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,gCAAAC,qCAAoC;AAC7C,SAAS,sBAAsB,gBAAgB;AAE/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF;",
6
6
  "names": ["default", "registerTldrawLibraryVersion"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ import _throttle from "lodash.throttle";
1
2
  const isTest = () => typeof process !== "undefined" && process.env.NODE_ENV === "test" && // @ts-expect-error
2
3
  !globalThis.__FORCE_RAF_IN_TESTS__;
3
4
  const timingVarianceFactor = 0.9;
@@ -124,9 +125,11 @@ function fpsThrottle(fn) {
124
125
  function throttleToNextFrame(fn) {
125
126
  return defaultScheduler.throttleToNextFrame(fn);
126
127
  }
128
+ const throttle = _throttle;
127
129
  export {
128
130
  FpsScheduler,
129
131
  fpsThrottle,
132
+ throttle,
130
133
  throttleToNextFrame
131
134
  };
132
135
  //# sourceMappingURL=throttle.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/throttle.ts"],
4
- "sourcesContent": ["const isTest = () =>\n\ttypeof process !== 'undefined' &&\n\tprocess.env.NODE_ENV === 'test' &&\n\t// @ts-expect-error\n\t!globalThis.__FORCE_RAF_IN_TESTS__\n\n// Browsers aren't precise with frame timing - this factor prevents skipping frames unnecessarily\n// by aiming slightly below the theoretical frame duration (e.g., ~7.5ms instead of 8.33ms for 120fps)\nconst timingVarianceFactor = 0.9\nconst getTargetTimePerFrame = (targetFps: number) =>\n\tMath.floor(1000 / targetFps) * timingVarianceFactor\n\n/**\n * A scheduler class that manages a queue of functions to be executed at a target frame rate.\n * Each instance maintains its own queue and state, allowing for separate throttling contexts\n * (e.g., UI operations vs network sync operations).\n *\n * @public\n */\nexport class FpsScheduler {\n\tprivate targetFps: number\n\tprivate targetTimePerFrame: number\n\tprivate fpsQueue: Array<() => void> = []\n\tprivate frameRaf: undefined | number\n\tprivate flushRaf: undefined | number\n\tprivate lastFlushTime: number\n\n\tconstructor(targetFps: number = 120) {\n\t\tthis.targetFps = targetFps\n\t\tthis.targetTimePerFrame = getTargetTimePerFrame(targetFps)\n\t\tthis.lastFlushTime = -this.targetTimePerFrame\n\t}\n\n\tupdateTargetFps(targetFps: number) {\n\t\tif (targetFps === this.targetFps) return\n\t\tthis.targetFps = targetFps\n\t\tthis.targetTimePerFrame = getTargetTimePerFrame(targetFps)\n\t\tthis.lastFlushTime = -this.targetTimePerFrame\n\t}\n\n\tprivate flush() {\n\t\tconst queue = this.fpsQueue.splice(0, this.fpsQueue.length)\n\t\tfor (const fn of queue) {\n\t\t\tfn()\n\t\t}\n\t}\n\n\tprivate tick(isOnNextFrame = false) {\n\t\tif (this.frameRaf) return\n\n\t\tconst now = Date.now()\n\t\tconst elapsed = now - this.lastFlushTime\n\n\t\tif (elapsed < this.targetTimePerFrame) {\n\t\t\t// If we're too early to flush, we need to wait until the next frame to try and flush again.\n\t\t\t// eslint-disable-next-line no-restricted-globals\n\t\t\tthis.frameRaf = requestAnimationFrame(() => {\n\t\t\t\tthis.frameRaf = undefined\n\t\t\t\tthis.tick(true)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\n\t\tif (isOnNextFrame) {\n\t\t\t// If we've already waited for the next frame to run the tick, then we can flush immediately\n\t\t\tif (this.flushRaf) return // ...though if there's a flush raf, that means we'll be flushing on this frame already, so we can do nothing here.\n\t\t\tthis.lastFlushTime = now\n\t\t\tthis.flush()\n\t\t} else {\n\t\t\t// If we haven't already waited for the next frame to run the tick, we need to wait until the next frame to flush.\n\t\t\tif (this.flushRaf) return // ...though if there's a flush raf, that means we'll be flushing on the next frame already, so we can do nothing here.\n\t\t\t// eslint-disable-next-line no-restricted-globals\n\t\t\tthis.flushRaf = requestAnimationFrame(() => {\n\t\t\t\tthis.flushRaf = undefined\n\t\t\t\tthis.lastFlushTime = Date.now()\n\t\t\t\tthis.flush()\n\t\t\t})\n\t\t}\n\t}\n\n\t/**\n\t * Creates a throttled version of a function that executes at most once per frame.\n\t * The default target frame rate is set by the FpsScheduler instance.\n\t * Subsequent calls within the same frame are ignored, ensuring smooth performance\n\t * for high-frequency events like mouse movements or scroll events.\n\t *\n\t * @param fn - The function to throttle, optionally with a cancel method\n\t * @returns A throttled function with an optional cancel method to remove pending calls\n\t *\n\t * @public\n\t */\n\tfpsThrottle(fn: { (): void; cancel?(): void }): {\n\t\t(): void\n\t\tcancel?(): void\n\t} {\n\t\tif (isTest()) {\n\t\t\tfn.cancel = () => {\n\t\t\t\tif (this.frameRaf) {\n\t\t\t\t\tcancelAnimationFrame(this.frameRaf)\n\t\t\t\t\tthis.frameRaf = undefined\n\t\t\t\t}\n\t\t\t\tif (this.flushRaf) {\n\t\t\t\t\tcancelAnimationFrame(this.flushRaf)\n\t\t\t\t\tthis.flushRaf = undefined\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn fn\n\t\t}\n\n\t\tconst throttledFn = () => {\n\t\t\tif (this.fpsQueue.includes(fn)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.fpsQueue.push(fn)\n\t\t\tthis.tick()\n\t\t}\n\t\tthrottledFn.cancel = () => {\n\t\t\tconst index = this.fpsQueue.indexOf(fn)\n\t\t\tif (index > -1) {\n\t\t\t\tthis.fpsQueue.splice(index, 1)\n\t\t\t}\n\t\t}\n\t\treturn throttledFn\n\t}\n\n\t/**\n\t * Schedules a function to execute on the next animation frame.\n\t * If the same function is passed multiple times before the frame executes,\n\t * it will only be called once, effectively batching multiple calls.\n\t *\n\t * @param fn - The function to execute on the next frame\n\t * @returns A cancel function that can prevent execution if called before the next frame\n\t *\n\t * @public\n\t */\n\tthrottleToNextFrame(fn: () => void): () => void {\n\t\tif (isTest()) {\n\t\t\tfn()\n\t\t\treturn () => void null // noop\n\t\t}\n\n\t\tif (!this.fpsQueue.includes(fn)) {\n\t\t\tthis.fpsQueue.push(fn)\n\t\t\tthis.tick()\n\t\t}\n\n\t\treturn () => {\n\t\t\tconst index = this.fpsQueue.indexOf(fn)\n\t\t\tif (index > -1) {\n\t\t\t\tthis.fpsQueue.splice(index, 1)\n\t\t\t}\n\t\t}\n\t}\n}\n\n// Default instance for UI operations\nconst defaultScheduler = new FpsScheduler(120)\n\n/**\n * Creates a throttled version of a function that executes at most once per frame.\n * The default target frame rate is 120fps, but can be customized per function.\n * Subsequent calls within the same frame are ignored, ensuring smooth performance\n * for high-frequency events like mouse movements or scroll events.\n *\n * Uses the default throttle instance for UI operations. If you need a separate\n * throttling queue (e.g., for network operations), create your own Throttle instance.\n *\n * @param fn - The function to throttle, optionally with a cancel method\n * @returns A throttled function with an optional cancel method to remove pending calls\n *\n * @example\n * ```ts\n * // Default 120fps throttling\n * const updateCanvas = fpsThrottle(() => {\n * // This will run at most once per frame (~8.33ms)\n * redrawCanvas()\n * })\n *\n * // Call as often as you want - automatically throttled to 120fps\n * document.addEventListener('mousemove', updateCanvas)\n *\n * // Cancel pending calls if needed\n * updateCanvas.cancel?.()\n * ```\n *\n * @internal\n */\nexport function fpsThrottle(fn: { (): void; cancel?(): void }): {\n\t(): void\n\tcancel?(): void\n} {\n\treturn defaultScheduler.fpsThrottle(fn)\n}\n\n/**\n * Schedules a function to execute on the next animation frame, targeting 120fps.\n * If the same function is passed multiple times before the frame executes,\n * it will only be called once, effectively batching multiple calls.\n *\n * Uses the default throttle instance for UI operations.\n *\n * @param fn - The function to execute on the next frame\n * @returns A cancel function that can prevent execution if called before the next frame\n *\n * @example\n * ```ts\n * const updateUI = throttleToNextFrame(() => {\n * // Batches multiple calls into the next animation frame\n * updateStatusBar()\n * refreshToolbar()\n * })\n *\n * // Multiple calls within the same frame are batched\n * updateUI() // Will execute\n * updateUI() // Ignored (same function already queued)\n * updateUI() // Ignored (same function already queued)\n *\n * // Get cancel function to prevent execution\n * const cancel = updateUI()\n * cancel() // Prevents execution if called before next frame\n * ```\n *\n * @internal\n */\nexport function throttleToNextFrame(fn: () => void): () => void {\n\treturn defaultScheduler.throttleToNextFrame(fn)\n}\n"],
5
- "mappings": "AAAA,MAAM,SAAS,MACd,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa;AAEzB,CAAC,WAAW;AAIb,MAAM,uBAAuB;AAC7B,MAAM,wBAAwB,CAAC,cAC9B,KAAK,MAAM,MAAO,SAAS,IAAI;AASzB,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA,WAA8B,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,YAAoB,KAAK;AACpC,SAAK,YAAY;AACjB,SAAK,qBAAqB,sBAAsB,SAAS;AACzD,SAAK,gBAAgB,CAAC,KAAK;AAAA,EAC5B;AAAA,EAEA,gBAAgB,WAAmB;AAClC,QAAI,cAAc,KAAK,UAAW;AAClC,SAAK,YAAY;AACjB,SAAK,qBAAqB,sBAAsB,SAAS;AACzD,SAAK,gBAAgB,CAAC,KAAK;AAAA,EAC5B;AAAA,EAEQ,QAAQ;AACf,UAAM,QAAQ,KAAK,SAAS,OAAO,GAAG,KAAK,SAAS,MAAM;AAC1D,eAAW,MAAM,OAAO;AACvB,SAAG;AAAA,IACJ;AAAA,EACD;AAAA,EAEQ,KAAK,gBAAgB,OAAO;AACnC,QAAI,KAAK,SAAU;AAEnB,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,UAAU,MAAM,KAAK;AAE3B,QAAI,UAAU,KAAK,oBAAoB;AAGtC,WAAK,WAAW,sBAAsB,MAAM;AAC3C,aAAK,WAAW;AAChB,aAAK,KAAK,IAAI;AAAA,MACf,CAAC;AACD;AAAA,IACD;AAEA,QAAI,eAAe;AAElB,UAAI,KAAK,SAAU;AACnB,WAAK,gBAAgB;AACrB,WAAK,MAAM;AAAA,IACZ,OAAO;AAEN,UAAI,KAAK,SAAU;AAEnB,WAAK,WAAW,sBAAsB,MAAM;AAC3C,a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AG1B;AACD,SAAO,iBAAiB,YAAY,EAAE;AACvC;AAgCO,SAAS,oBAAoB,IAA4B;AAC/D,SAAO,iBAAiB,oBAAoB,EAAE;AAC/C;",
4
+ "sourcesContent": ["import _throttle from 'lodash.throttle'\n\nconst isTest = () =>\n\ttypeof process !== 'undefined' &&\n\tprocess.env.NODE_ENV === 'test' &&\n\t// @ts-expect-error\n\t!globalThis.__FORCE_RAF_IN_TESTS__\n\n// Browsers aren't precise with frame timing - this factor prevents skipping frames unnecessarily\n// by aiming slightly below the theoretical frame duration (e.g., ~7.5ms instead of 8.33ms for 120fps)\nconst timingVarianceFactor = 0.9\nconst getTargetTimePerFrame = (targetFps: number) =>\n\tMath.floor(1000 / targetFps) * timingVarianceFactor\n\n/**\n * A scheduler class that manages a queue of functions to be executed at a target frame rate.\n * Each instance maintains its own queue and state, allowing for separate throttling contexts\n * (e.g., UI operations vs network sync operations).\n *\n * @public\n */\nexport class FpsScheduler {\n\tprivate targetFps: number\n\tprivate targetTimePerFrame: number\n\tprivate fpsQueue: Array<() => void> = []\n\tprivate frameRaf: undefined | number\n\tprivate flushRaf: undefined | number\n\tprivate lastFlushTime: number\n\n\tconstructor(targetFps: number = 120) {\n\t\tthis.targetFps = targetFps\n\t\tthis.targetTimePerFrame = getTargetTimePerFrame(targetFps)\n\t\tthis.lastFlushTime = -this.targetTimePerFrame\n\t}\n\n\tupdateTargetFps(targetFps: number) {\n\t\tif (targetFps === this.targetFps) return\n\t\tthis.targetFps = targetFps\n\t\tthis.targetTimePerFrame = getTargetTimePerFrame(targetFps)\n\t\tthis.lastFlushTime = -this.targetTimePerFrame\n\t}\n\n\tprivate flush() {\n\t\tconst queue = this.fpsQueue.splice(0, this.fpsQueue.length)\n\t\tfor (const fn of queue) {\n\t\t\tfn()\n\t\t}\n\t}\n\n\tprivate tick(isOnNextFrame = false) {\n\t\tif (this.frameRaf) return\n\n\t\tconst now = Date.now()\n\t\tconst elapsed = now - this.lastFlushTime\n\n\t\tif (elapsed < this.targetTimePerFrame) {\n\t\t\t// If we're too early to flush, we need to wait until the next frame to try and flush again.\n\t\t\t// eslint-disable-next-line no-restricted-globals\n\t\t\tthis.frameRaf = requestAnimationFrame(() => {\n\t\t\t\tthis.frameRaf = undefined\n\t\t\t\tthis.tick(true)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\n\t\tif (isOnNextFrame) {\n\t\t\t// If we've already waited for the next frame to run the tick, then we can flush immediately\n\t\t\tif (this.flushRaf) return // ...though if there's a flush raf, that means we'll be flushing on this frame already, so we can do nothing here.\n\t\t\tthis.lastFlushTime = now\n\t\t\tthis.flush()\n\t\t} else {\n\t\t\t// If we haven't already waited for the next frame to run the tick, we need to wait until the next frame to flush.\n\t\t\tif (this.flushRaf) return // ...though if there's a flush raf, that means we'll be flushing on the next frame already, so we can do nothing here.\n\t\t\t// eslint-disable-next-line no-restricted-globals\n\t\t\tthis.flushRaf = requestAnimationFrame(() => {\n\t\t\t\tthis.flushRaf = undefined\n\t\t\t\tthis.lastFlushTime = Date.now()\n\t\t\t\tthis.flush()\n\t\t\t})\n\t\t}\n\t}\n\n\t/**\n\t * Creates a throttled version of a function that executes at most once per frame.\n\t * The default target frame rate is set by the FpsScheduler instance.\n\t * Subsequent calls within the same frame are ignored, ensuring smooth performance\n\t * for high-frequency events like mouse movements or scroll events.\n\t *\n\t * @param fn - The function to throttle, optionally with a cancel method\n\t * @returns A throttled function with an optional cancel method to remove pending calls\n\t *\n\t * @public\n\t */\n\tfpsThrottle(fn: { (): void; cancel?(): void }): {\n\t\t(): void\n\t\tcancel?(): void\n\t} {\n\t\tif (isTest()) {\n\t\t\tfn.cancel = () => {\n\t\t\t\tif (this.frameRaf) {\n\t\t\t\t\tcancelAnimationFrame(this.frameRaf)\n\t\t\t\t\tthis.frameRaf = undefined\n\t\t\t\t}\n\t\t\t\tif (this.flushRaf) {\n\t\t\t\t\tcancelAnimationFrame(this.flushRaf)\n\t\t\t\t\tthis.flushRaf = undefined\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn fn\n\t\t}\n\n\t\tconst throttledFn = () => {\n\t\t\tif (this.fpsQueue.includes(fn)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.fpsQueue.push(fn)\n\t\t\tthis.tick()\n\t\t}\n\t\tthrottledFn.cancel = () => {\n\t\t\tconst index = this.fpsQueue.indexOf(fn)\n\t\t\tif (index > -1) {\n\t\t\t\tthis.fpsQueue.splice(index, 1)\n\t\t\t}\n\t\t}\n\t\treturn throttledFn\n\t}\n\n\t/**\n\t * Schedules a function to execute on the next animation frame.\n\t * If the same function is passed multiple times before the frame executes,\n\t * it will only be called once, effectively batching multiple calls.\n\t *\n\t * @param fn - The function to execute on the next frame\n\t * @returns A cancel function that can prevent execution if called before the next frame\n\t *\n\t * @public\n\t */\n\tthrottleToNextFrame(fn: () => void): () => void {\n\t\tif (isTest()) {\n\t\t\tfn()\n\t\t\treturn () => void null // noop\n\t\t}\n\n\t\tif (!this.fpsQueue.includes(fn)) {\n\t\t\tthis.fpsQueue.push(fn)\n\t\t\tthis.tick()\n\t\t}\n\n\t\treturn () => {\n\t\t\tconst index = this.fpsQueue.indexOf(fn)\n\t\t\tif (index > -1) {\n\t\t\t\tthis.fpsQueue.splice(index, 1)\n\t\t\t}\n\t\t}\n\t}\n}\n\n// Default instance for UI operations\nconst defaultScheduler = new FpsScheduler(120)\n\n/**\n * Creates a throttled version of a function that executes at most once per frame.\n * The default target frame rate is 120fps, but can be customized per function.\n * Subsequent calls within the same frame are ignored, ensuring smooth performance\n * for high-frequency events like mouse movements or scroll events.\n *\n * Uses the default throttle instance for UI operations. If you need a separate\n * throttling queue (e.g., for network operations), create your own Throttle instance.\n *\n * @param fn - The function to throttle, optionally with a cancel method\n * @returns A throttled function with an optional cancel method to remove pending calls\n *\n * @example\n * ```ts\n * // Default 120fps throttling\n * const updateCanvas = fpsThrottle(() => {\n * // This will run at most once per frame (~8.33ms)\n * redrawCanvas()\n * })\n *\n * // Call as often as you want - automatically throttled to 120fps\n * document.addEventListener('mousemove', updateCanvas)\n *\n * // Cancel pending calls if needed\n * updateCanvas.cancel?.()\n * ```\n *\n * @internal\n */\nexport function fpsThrottle(fn: { (): void; cancel?(): void }): {\n\t(): void\n\tcancel?(): void\n} {\n\treturn defaultScheduler.fpsThrottle(fn)\n}\n\n/**\n * Schedules a function to execute on the next animation frame, targeting 120fps.\n * If the same function is passed multiple times before the frame executes,\n * it will only be called once, effectively batching multiple calls.\n *\n * Uses the default throttle instance for UI operations.\n *\n * @param fn - The function to execute on the next frame\n * @returns A cancel function that can prevent execution if called before the next frame\n *\n * @example\n * ```ts\n * const updateUI = throttleToNextFrame(() => {\n * // Batches multiple calls into the next animation frame\n * updateStatusBar()\n * refreshToolbar()\n * })\n *\n * // Multiple calls within the same frame are batched\n * updateUI() // Will execute\n * updateUI() // Ignored (same function already queued)\n * updateUI() // Ignored (same function already queued)\n *\n * // Get cancel function to prevent execution\n * const cancel = updateUI()\n * cancel() // Prevents execution if called before next frame\n * ```\n *\n * @internal\n */\nexport function throttleToNextFrame(fn: () => void): () => void {\n\treturn defaultScheduler.throttleToNextFrame(fn)\n}\n\n/**\n * The function returned by `throttle`. Call it like the original function; it returns the\n * result of the last invocation, or `undefined` if the original hasn't run yet.\n *\n * Declared here rather than re-exported from `@types/lodash`, so code can name a throttled\n * function's type without depending on lodash's type packages.\n *\n * @example\n * ```ts\n * class Saver {\n * save: ThrottledFunction<() => void> = throttle(() => this.persist(), 1000)\n * }\n * ```\n *\n * @public\n */\nexport interface ThrottledFunction<T extends (...args: any[]) => any> {\n\t(...args: Parameters<T>): ReturnType<T> | undefined\n\t/** Cancels any pending invocation. */\n\tcancel(): void\n\t/** Immediately runs any pending invocation and returns its result. */\n\tflush(): ReturnType<T> | undefined\n}\n\n/**\n * Creates a throttled function that invokes `fn` at most once per `wait` milliseconds. Wraps\n * lodash's `throttle`, typed with {@link ThrottledFunction} so the published types don't depend\n * on lodash's type packages.\n *\n * @example\n * ```ts\n * const save = throttle(() => persist(), 1000, { leading: false })\n * save()\n * save.flush()\n * ```\n *\n * @public\n */\nexport const throttle: <T extends (...args: any[]) => any>(\n\tfn: T,\n\twait?: number,\n\toptions?: { leading?: boolean; trailing?: boolean }\n) => ThrottledFunction<T> = _throttle\n"],
5
+ "mappings": "AAAA,OAAO,eAAe;AAEtB,MAAM,SAAS,MACd,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa;AAEzB,CAAC,WAAW;AAIb,MAAM,uBAAuB;AAC7B,MAAM,wBAAwB,CAAC,cAC9B,KAAK,MAAM,MAAO,SAAS,IAAI;AASzB,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA,WAA8B,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,YAAoB,KAAK;AACpC,SAAK,YAAY;AACjB,SAAK,qBAAqB,sBAAsB,SAAS;AACzD,SAAK,gBAAgB,CAAC,KAAK;AAAA,EAC5B;AAAA,EAEA,gBAAgB,WAAmB;AAClC,QAAI,cAAc,KAAK,UAAW;AAClC,SAAK,YAAY;AACjB,SAAK,qBAAqB,sBAAsB,SAAS;AACzD,SAAK,gBAAgB,CAAC,KAAK;AAAA,EAC5B;AAAA,EAEQ,QAAQ;AACf,UAAM,QAAQ,KAAK,SAAS,OAAO,GAAG,KAAK,SAAS,MAAM;AAC1D,eAAW,MAAM,OAAO;AACvB,SAAG;AAAA,IACJ;AAAA,EACD;AAAA,EAEQ,KAAK,gBAAgB,OAAO;AACnC,QAAI,KAAK,SAAU;AAEnB,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,UAAU,MAAM,KAAK;AAE3B,QAAI,UAAU,KAAK,oBAAoB;AAGtC,WAAK,WAAW,sBAAsB,MAAM;AAC3C,aAAK,WAAW;AAChB,aAAK,KAAK,IAAI;AAAA,MACf,CAAC;AACD;AAAA,IACD;AAEA,QAAI,eAAe;AAElB,UAAI,KAAK,SAAU;AACnB,WAAK,gBAAgB;AACrB,WAAK,MAAM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AAA,IACD;AAAA,EACD;AACD;AAGA,MAAM,mBAAmB,IAAI,aAAa,GAAG;AA+BtC,SAAS,YAAY,IAG1B;AACD,SAAO,iBAAiB,YAAY,EAAE;AACvC;AAgCO,SAAS,oBAAoB,IAA4B;AAC/D,SAAO,iBAAiB,oBAAoB,EAAE;AAC/C;AAwCO,MAAM,WAIe;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,7 @@
1
1
  class Timers {
2
+ // Ids are dropped as soon as a timer fires or is cleared through this class, so a
3
+ // long-lived context (the editor creates two timeouts per pointer down) does not
4
+ // accumulate stale ids that `dispose` would otherwise have to clear one by one.
2
5
  timeouts = /* @__PURE__ */ new Map();
3
6
  intervals = /* @__PURE__ */ new Map();
4
7
  rafs = /* @__PURE__ */ new Map();
@@ -15,6 +18,9 @@ class Timers {
15
18
  this.setTimeout = this.setTimeout.bind(this);
16
19
  this.setInterval = this.setInterval.bind(this);
17
20
  this.requestAnimationFrame = this.requestAnimationFrame.bind(this);
21
+ this.clearTimeout = this.clearTimeout.bind(this);
22
+ this.clearInterval = this.clearInterval.bind(this);
23
+ this.cancelAnimationFrame = this.cancelAnimationFrame.bind(this);
18
24
  this.dispose = this.dispose.bind(this);
19
25
  }
20
26
  /**
@@ -33,9 +39,16 @@ class Timers {
33
39
  * @public
34
40
  */
35
41
  setTimeout(contextId, handler, timeout, ...args) {
36
- const id = window.setTimeout(handler, timeout, args);
37
- const current = this.timeouts.get(contextId) ?? [];
38
- this.timeouts.set(contextId, [...current, id]);
42
+ const ids = getOrCreateSet(this.timeouts, contextId);
43
+ let fired = false;
44
+ let id = -1;
45
+ const wrapped = typeof handler === "function" ? (...handlerArgs) => {
46
+ fired = true;
47
+ ids.delete(id);
48
+ handler(...handlerArgs);
49
+ } : handler;
50
+ id = window.setTimeout(wrapped, timeout, args);
51
+ if (!fired) ids.add(id);
39
52
  return id;
40
53
  }
41
54
  /**
@@ -55,8 +68,7 @@ class Timers {
55
68
  */
56
69
  setInterval(contextId, handler, timeout, ...args) {
57
70
  const id = window.setInterval(handler, timeout, args);
58
- const current = this.intervals.get(contextId) ?? [];
59
- this.intervals.set(contextId, [...current, id]);
71
+ getOrCreateSet(this.intervals, contextId).add(id);
60
72
  return id;
61
73
  }
62
74
  /**
@@ -73,11 +85,70 @@ class Timers {
73
85
  * @public
74
86
  */
75
87
  requestAnimationFrame(contextId, callback) {
76
- const id = window.requestAnimationFrame(callback);
77
- const current = this.rafs.get(contextId) ?? [];
78
- this.rafs.set(contextId, [...current, id]);
88
+ const ids = getOrCreateSet(this.rafs, contextId);
89
+ let fired = false;
90
+ let id = -1;
91
+ id = window.requestAnimationFrame((time) => {
92
+ fired = true;
93
+ ids.delete(id);
94
+ callback(time);
95
+ });
96
+ if (!fired) ids.add(id);
79
97
  return id;
80
98
  }
99
+ /**
100
+ * Clears a timeout created with {@link Timers.setTimeout} and stops tracking it.
101
+ * Prefer this over the global `clearTimeout` for ids that came from this instance,
102
+ * otherwise the id stays tracked until its context is disposed.
103
+ * @param contextId - The context identifier the timeout was created under.
104
+ * @param id - The timer ID returned by `setTimeout`. Ignored when undefined.
105
+ * @example
106
+ * ```ts
107
+ * const timers = new Timers()
108
+ * const id = timers.setTimeout('autosave', () => save(), 5000)
109
+ * timers.clearTimeout('autosave', id)
110
+ * ```
111
+ * @public
112
+ */
113
+ clearTimeout(contextId, id) {
114
+ if (id === void 0) return;
115
+ clearTimeout(id);
116
+ this.timeouts.get(contextId)?.delete(id);
117
+ }
118
+ /**
119
+ * Clears an interval created with {@link Timers.setInterval} and stops tracking it.
120
+ * @param contextId - The context identifier the interval was created under.
121
+ * @param id - The interval ID returned by `setInterval`. Ignored when undefined.
122
+ * @example
123
+ * ```ts
124
+ * const timers = new Timers()
125
+ * const id = timers.setInterval('refresh', () => updateData(), 1000)
126
+ * timers.clearInterval('refresh', id)
127
+ * ```
128
+ * @public
129
+ */
130
+ clearInterval(contextId, id) {
131
+ if (id === void 0) return;
132
+ clearInterval(id);
133
+ this.intervals.get(contextId)?.delete(id);
134
+ }
135
+ /**
136
+ * Cancels an animation frame requested with {@link Timers.requestAnimationFrame} and stops tracking it.
137
+ * @param contextId - The context identifier the animation frame was requested under.
138
+ * @param id - The request ID returned by `requestAnimationFrame`. Ignored when undefined.
139
+ * @example
140
+ * ```ts
141
+ * const timers = new Timers()
142
+ * const id = timers.requestAnimationFrame('render', () => draw())
143
+ * timers.cancelAnimationFrame('render', id)
144
+ * ```
145
+ * @public
146
+ */
147
+ cancelAnimationFrame(contextId, id) {
148
+ if (id === void 0) return;
149
+ cancelAnimationFrame(id);
150
+ this.rafs.get(contextId)?.delete(id);
151
+ }
81
152
  /**
82
153
  * Disposes of all timers associated with the specified context.
83
154
  * Clears all timeouts, intervals, and animation frames for the given context ID.
@@ -118,7 +189,12 @@ class Timers {
118
189
  * @public
119
190
  */
120
191
  disposeAll() {
121
- for (const contextId of this.timeouts.keys()) {
192
+ const contextIds = /* @__PURE__ */ new Set([
193
+ ...this.timeouts.keys(),
194
+ ...this.intervals.keys(),
195
+ ...this.rafs.keys()
196
+ ]);
197
+ for (const contextId of contextIds) {
122
198
  this.dispose(contextId);
123
199
  }
124
200
  }
@@ -126,17 +202,20 @@ class Timers {
126
202
  * Returns an object with timer methods bound to a specific context.
127
203
  * Convenient for getting context-specific timer functions without repeatedly passing the contextId.
128
204
  * @param contextId - The context identifier to bind the returned methods to.
129
- * @returns An object with setTimeout, setInterval, requestAnimationFrame, and dispose methods bound to the context.
205
+ * @returns An object with setTimeout, setInterval, requestAnimationFrame, the matching clear methods, and dispose bound to the context.
130
206
  * @example
131
207
  * ```ts
132
208
  * const timers = new Timers()
133
209
  * const uiTimers = timers.forContext('ui')
134
210
  *
135
211
  * // These are equivalent to calling timers.setTimeout('ui', ...)
136
- * uiTimers.setTimeout(() => console.log('timeout'), 1000)
212
+ * const id = uiTimers.setTimeout(() => console.log('timeout'), 1000)
137
213
  * uiTimers.setInterval(() => console.log('interval'), 500)
138
214
  * uiTimers.requestAnimationFrame(() => console.log('frame'))
139
215
  *
216
+ * // Clear a single timer
217
+ * uiTimers.clearTimeout(id)
218
+ *
140
219
  * // Dispose only this context
141
220
  * uiTimers.dispose()
142
221
  * ```
@@ -147,10 +226,21 @@ class Timers {
147
226
  setTimeout: (handler, timeout, ...args) => this.setTimeout(contextId, handler, timeout, args),
148
227
  setInterval: (handler, timeout, ...args) => this.setInterval(contextId, handler, timeout, args),
149
228
  requestAnimationFrame: (callback) => this.requestAnimationFrame(contextId, callback),
229
+ clearTimeout: (id) => this.clearTimeout(contextId, id),
230
+ clearInterval: (id) => this.clearInterval(contextId, id),
231
+ cancelAnimationFrame: (id) => this.cancelAnimationFrame(contextId, id),
150
232
  dispose: () => this.dispose(contextId)
151
233
  };
152
234
  }
153
235
  }
236
+ function getOrCreateSet(map, contextId) {
237
+ let set = map.get(contextId);
238
+ if (!set) {
239
+ set = /* @__PURE__ */ new Set();
240
+ map.set(contextId, set);
241
+ }
242
+ return set;
243
+ }
154
244
  export {
155
245
  Timers
156
246
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/timers.ts"],
4
- "sourcesContent": ["/* eslint-disable tldraw/no-restricted-properties */\n\n/**\n * A utility class for managing timeouts, intervals, and animation frames with context-based organization and automatic cleanup.\n * Helps prevent memory leaks by organizing timers into named contexts that can be cleared together.\n * @example\n * ```ts\n * const timers = new Timers()\n *\n * // Set timers with context organization\n * timers.setTimeout('ui', () => console.log('Auto save'), 5000)\n * timers.setInterval('ui', () => console.log('Refresh'), 1000)\n * timers.requestAnimationFrame('ui', () => console.log('Render'))\n *\n * // Clear all timers for a context\n * timers.dispose('ui')\n *\n * // Or get context-bound functions\n * const uiTimers = timers.forContext('ui')\n * uiTimers.setTimeout(() => console.log('Contextual timeout'), 1000)\n * ```\n * @public\n */\nexport class Timers {\n\tprivate timeouts = new Map<string, number[]>()\n\tprivate intervals = new Map<string, number[]>()\n\tprivate rafs = new Map<string, number[]>()\n\n\t/**\n\t * Creates a new Timers instance with bound methods for safe callback usage.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * // Methods are pre-bound, safe to use as callbacks\n\t * element.addEventListener('click', timers.dispose)\n\t * ```\n\t */\n\tconstructor() {\n\t\tthis.setTimeout = this.setTimeout.bind(this)\n\t\tthis.setInterval = this.setInterval.bind(this)\n\t\tthis.requestAnimationFrame = this.requestAnimationFrame.bind(this)\n\t\tthis.dispose = this.dispose.bind(this)\n\t}\n\n\t/**\n\t * Creates a timeout that will be tracked under the specified context.\n\t * @param contextId - The context identifier to group this timer under.\n\t * @param handler - The function to execute when the timeout expires.\n\t * @param timeout - The delay in milliseconds (default: 0).\n\t * @param args - Additional arguments to pass to the handler.\n\t * @returns The timer ID that can be used with clearTimeout.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const id = timers.setTimeout('autosave', () => save(), 5000)\n\t * // Timer will be automatically cleared when 'autosave' context is disposed\n\t * ```\n\t * @public\n\t */\n\tsetTimeout(contextId: string, handler: TimerHandler, timeout?: number, ...args: any[]): number {\n\t\tconst id = window.setTimeout(handler, timeout, args)\n\t\tconst current = this.timeouts.get(contextId) ?? []\n\t\tthis.timeouts.set(contextId, [...current, id])\n\t\treturn id\n\t}\n\n\t/**\n\t * Creates an interval that will be tracked under the specified context.\n\t * @param contextId - The context identifier to group this timer under.\n\t * @param handler - The function to execute repeatedly.\n\t * @param timeout - The delay in milliseconds between executions (default: 0).\n\t * @param args - Additional arguments to pass to the handler.\n\t * @returns The interval ID that can be used with clearInterval.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const id = timers.setInterval('refresh', () => updateData(), 1000)\n\t * // Interval will be automatically cleared when 'refresh' context is disposed\n\t * ```\n\t * @public\n\t */\n\tsetInterval(contextId: string, handler: TimerHandler, timeout?: number, ...args: any[]): number {\n\t\tconst id = window.setInterval(handler, timeout, args)\n\t\tconst current = this.intervals.get(contextId) ?? []\n\t\tthis.intervals.set(contextId, [...current, id])\n\t\treturn id\n\t}\n\n\t/**\n\t * Requests an animation frame that will be tracked under the specified context.\n\t * @param contextId - The context identifier to group this animation frame under.\n\t * @param callback - The function to execute on the next animation frame.\n\t * @returns The request ID that can be used with cancelAnimationFrame.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const id = timers.requestAnimationFrame('render', () => draw())\n\t * // Animation frame will be automatically cancelled when 'render' context is disposed\n\t * ```\n\t * @public\n\t */\n\trequestAnimationFrame(contextId: string, callback: FrameRequestCallback): number {\n\t\tconst id = window.requestAnimationFrame(callback)\n\t\tconst current = this.rafs.get(contextId) ?? []\n\t\tthis.rafs.set(contextId, [...current, id])\n\t\treturn id\n\t}\n\n\t/**\n\t * Disposes of all timers associated with the specified context.\n\t * Clears all timeouts, intervals, and animation frames for the given context ID.\n\t * @param contextId - The context identifier whose timers should be cleared.\n\t * @returns void\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * timers.setTimeout('ui', () => console.log('timeout'), 1000)\n\t * timers.setInterval('ui', () => console.log('interval'), 500)\n\t *\n\t * // Clear all 'ui' context timers\n\t * timers.dispose('ui')\n\t * ```\n\t * @public\n\t */\n\tdispose(contextId: string) {\n\t\tthis.timeouts.get(contextId)?.forEach((id) => clearTimeout(id))\n\t\tthis.intervals.get(contextId)?.forEach((id) => clearInterval(id))\n\t\tthis.rafs.get(contextId)?.forEach((id) => cancelAnimationFrame(id))\n\n\t\tthis.timeouts.delete(contextId)\n\t\tthis.intervals.delete(contextId)\n\t\tthis.rafs.delete(contextId)\n\t}\n\n\t/**\n\t * Disposes of all timers across all contexts.\n\t * Clears every timeout, interval, and animation frame managed by this instance.\n\t * @returns void\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * timers.setTimeout('ui', () => console.log('ui'), 1000)\n\t * timers.setTimeout('background', () => console.log('bg'), 2000)\n\t *\n\t * // Clear everything\n\t * timers.disposeAll()\n\t * ```\n\t * @public\n\t */\n\tdisposeAll() {\n\t\tfor (const contextId of this.timeouts.keys()) {\n\t\t\tthis.dispose(contextId)\n\t\t}\n\t}\n\n\t/**\n\t * Returns an object with timer methods bound to a specific context.\n\t * Convenient for getting context-specific timer functions without repeatedly passing the contextId.\n\t * @param contextId - The context identifier to bind the returned methods to.\n\t * @returns An object with setTimeout, setInterval, requestAnimationFrame, and dispose methods bound to the context.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const uiTimers = timers.forContext('ui')\n\t *\n\t * // These are equivalent to calling timers.setTimeout('ui', ...)\n\t * uiTimers.setTimeout(() => console.log('timeout'), 1000)\n\t * uiTimers.setInterval(() => console.log('interval'), 500)\n\t * uiTimers.requestAnimationFrame(() => console.log('frame'))\n\t *\n\t * // Dispose only this context\n\t * uiTimers.dispose()\n\t * ```\n\t * @public\n\t */\n\tforContext(contextId: string) {\n\t\treturn {\n\t\t\tsetTimeout: (handler: TimerHandler, timeout?: number, ...args: any[]) =>\n\t\t\t\tthis.setTimeout(contextId, handler, timeout, args),\n\t\t\tsetInterval: (handler: TimerHandler, timeout?: number, ...args: any[]) =>\n\t\t\t\tthis.setInterval(contextId, handler, timeout, args),\n\t\t\trequestAnimationFrame: (callback: FrameRequestCallback) =>\n\t\t\t\tthis.requestAnimationFrame(contextId, callback),\n\t\t\tdispose: () => this.dispose(contextId),\n\t\t}\n\t}\n}\n"],
5
- "mappings": "AAuBO,MAAM,OAAO;AAAA,EACX,WAAW,oBAAI,IAAsB;AAAA,EACrC,YAAY,oBAAI,IAAsB;AAAA,EACtC,OAAO,oBAAI,IAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWzC,cAAc;AACb,SAAK,aAAa,KAAK,WAAW,KAAK,IAAI;AAC3C,SAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAC7C,SAAK,wBAAwB,KAAK,sBAAsB,KAAK,IAAI;AACjE,SAAK,UAAU,KAAK,QAAQ,KAAK,IAAI;AAAA,EACtC;AAAA;AAAA;AAAA;AA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QAAQ,CAAC,OAAO,qBAAqB,EAAE,CAAC;AAElE,SAAK,SAAS,OAAO,SAAS;AAC9B,SAAK,UAAU,OAAO,SAAS;AAC/B,SAAK,KAAK,OAAO,SAAS;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,aAAa;AACZ,eAAW,aAAa,KAAK,SAAS,KAAK,GAAG;AAC7C,WAAK,QAAQ,SAAS;AAAA,IACvB;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,WAAW,WAAmB;AAC7B,WAAO;AAAA,MACN,YAAY,CAAC,SAAuB,YAAqB,SACxD,KAAK,WAAW,WAAW,SAAS,SAAS,IAAI;AAAA,MAClD,aAAa,CAAC,SAAuB,YAAqB,SACzD,KAAK,YAAY,WAAW,SAAS,SAAS,IAAI;AAAA,MACnD,uBAAuB,CAAC,aACvB,KAAK,sBAAsB,WAAW,QAAQ;AAAA,MAC/C,SAAS,MAAM,KAAK,QAAQ,SAAS;AAAA,IACtC;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["/* eslint-disable tldraw/no-restricted-properties */\n\n/**\n * A utility class for managing timeouts, intervals, and animation frames with context-based organization and automatic cleanup.\n * Helps prevent memory leaks by organizing timers into named contexts that can be cleared together.\n * @example\n * ```ts\n * const timers = new Timers()\n *\n * // Set timers with context organization\n * timers.setTimeout('ui', () => console.log('Auto save'), 5000)\n * timers.setInterval('ui', () => console.log('Refresh'), 1000)\n * timers.requestAnimationFrame('ui', () => console.log('Render'))\n *\n * // Clear all timers for a context\n * timers.dispose('ui')\n *\n * // Or get context-bound functions\n * const uiTimers = timers.forContext('ui')\n * uiTimers.setTimeout(() => console.log('Contextual timeout'), 1000)\n * ```\n * @public\n */\nexport class Timers {\n\t// Ids are dropped as soon as a timer fires or is cleared through this class, so a\n\t// long-lived context (the editor creates two timeouts per pointer down) does not\n\t// accumulate stale ids that `dispose` would otherwise have to clear one by one.\n\tprivate timeouts = new Map<string, Set<number>>()\n\tprivate intervals = new Map<string, Set<number>>()\n\tprivate rafs = new Map<string, Set<number>>()\n\n\t/**\n\t * Creates a new Timers instance with bound methods for safe callback usage.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * // Methods are pre-bound, safe to use as callbacks\n\t * element.addEventListener('click', timers.dispose)\n\t * ```\n\t */\n\tconstructor() {\n\t\tthis.setTimeout = this.setTimeout.bind(this)\n\t\tthis.setInterval = this.setInterval.bind(this)\n\t\tthis.requestAnimationFrame = this.requestAnimationFrame.bind(this)\n\t\tthis.clearTimeout = this.clearTimeout.bind(this)\n\t\tthis.clearInterval = this.clearInterval.bind(this)\n\t\tthis.cancelAnimationFrame = this.cancelAnimationFrame.bind(this)\n\t\tthis.dispose = this.dispose.bind(this)\n\t}\n\n\t/**\n\t * Creates a timeout that will be tracked under the specified context.\n\t * @param contextId - The context identifier to group this timer under.\n\t * @param handler - The function to execute when the timeout expires.\n\t * @param timeout - The delay in milliseconds (default: 0).\n\t * @param args - Additional arguments to pass to the handler.\n\t * @returns The timer ID that can be used with clearTimeout.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const id = timers.setTimeout('autosave', () => save(), 5000)\n\t * // Timer will be automatically cleared when 'autosave' context is disposed\n\t * ```\n\t * @public\n\t */\n\tsetTimeout(contextId: string, handler: TimerHandler, timeout?: number, ...args: any[]): number {\n\t\tconst ids = getOrCreateSet(this.timeouts, contextId)\n\t\t// A test stub can run the handler synchronously, before `id` is assigned, so the wrapper\n\t\t// records that it fired instead of relying on the id being set when it runs.\n\t\tlet fired = false\n\t\tlet id = -1\n\t\t// A string handler is evaluated by the browser, so it cannot be wrapped and stays\n\t\t// tracked until it is cleared or the context is disposed.\n\t\tconst wrapped =\n\t\t\ttypeof handler === 'function'\n\t\t\t\t? (...handlerArgs: any[]) => {\n\t\t\t\t\t\tfired = true\n\t\t\t\t\t\tids.delete(id)\n\t\t\t\t\t\thandler(...handlerArgs)\n\t\t\t\t\t}\n\t\t\t\t: handler\n\t\tid = window.setTimeout(wrapped, timeout, args)\n\t\tif (!fired) ids.add(id)\n\t\treturn id\n\t}\n\n\t/**\n\t * Creates an interval that will be tracked under the specified context.\n\t * @param contextId - The context identifier to group this timer under.\n\t * @param handler - The function to execute repeatedly.\n\t * @param timeout - The delay in milliseconds between executions (default: 0).\n\t * @param args - Additional arguments to pass to the handler.\n\t * @returns The interval ID that can be used with clearInterval.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const id = timers.setInterval('refresh', () => updateData(), 1000)\n\t * // Interval will be automatically cleared when 'refresh' context is disposed\n\t * ```\n\t * @public\n\t */\n\tsetInterval(contextId: string, handler: TimerHandler, timeout?: number, ...args: any[]): number {\n\t\tconst id = window.setInterval(handler, timeout, args)\n\t\tgetOrCreateSet(this.intervals, contextId).add(id)\n\t\treturn id\n\t}\n\n\t/**\n\t * Requests an animation frame that will be tracked under the specified context.\n\t * @param contextId - The context identifier to group this animation frame under.\n\t * @param callback - The function to execute on the next animation frame.\n\t * @returns The request ID that can be used with cancelAnimationFrame.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const id = timers.requestAnimationFrame('render', () => draw())\n\t * // Animation frame will be automatically cancelled when 'render' context is disposed\n\t * ```\n\t * @public\n\t */\n\trequestAnimationFrame(contextId: string, callback: FrameRequestCallback): number {\n\t\tconst ids = getOrCreateSet(this.rafs, contextId)\n\t\t// Test stubs (the sync fuzz suite, for one) run the frame synchronously, before `id` is\n\t\t// assigned, so the callback records that it fired rather than touching `id` first.\n\t\tlet fired = false\n\t\tlet id = -1\n\t\tid = window.requestAnimationFrame((time) => {\n\t\t\tfired = true\n\t\t\tids.delete(id)\n\t\t\tcallback(time)\n\t\t})\n\t\tif (!fired) ids.add(id)\n\t\treturn id\n\t}\n\n\t/**\n\t * Clears a timeout created with {@link Timers.setTimeout} and stops tracking it.\n\t * Prefer this over the global `clearTimeout` for ids that came from this instance,\n\t * otherwise the id stays tracked until its context is disposed.\n\t * @param contextId - The context identifier the timeout was created under.\n\t * @param id - The timer ID returned by `setTimeout`. Ignored when undefined.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const id = timers.setTimeout('autosave', () => save(), 5000)\n\t * timers.clearTimeout('autosave', id)\n\t * ```\n\t * @public\n\t */\n\tclearTimeout(contextId: string, id: number | undefined): void {\n\t\tif (id === undefined) return\n\t\tclearTimeout(id)\n\t\tthis.timeouts.get(contextId)?.delete(id)\n\t}\n\n\t/**\n\t * Clears an interval created with {@link Timers.setInterval} and stops tracking it.\n\t * @param contextId - The context identifier the interval was created under.\n\t * @param id - The interval ID returned by `setInterval`. Ignored when undefined.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const id = timers.setInterval('refresh', () => updateData(), 1000)\n\t * timers.clearInterval('refresh', id)\n\t * ```\n\t * @public\n\t */\n\tclearInterval(contextId: string, id: number | undefined): void {\n\t\tif (id === undefined) return\n\t\tclearInterval(id)\n\t\tthis.intervals.get(contextId)?.delete(id)\n\t}\n\n\t/**\n\t * Cancels an animation frame requested with {@link Timers.requestAnimationFrame} and stops tracking it.\n\t * @param contextId - The context identifier the animation frame was requested under.\n\t * @param id - The request ID returned by `requestAnimationFrame`. Ignored when undefined.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const id = timers.requestAnimationFrame('render', () => draw())\n\t * timers.cancelAnimationFrame('render', id)\n\t * ```\n\t * @public\n\t */\n\tcancelAnimationFrame(contextId: string, id: number | undefined): void {\n\t\tif (id === undefined) return\n\t\tcancelAnimationFrame(id)\n\t\tthis.rafs.get(contextId)?.delete(id)\n\t}\n\n\t/**\n\t * Disposes of all timers associated with the specified context.\n\t * Clears all timeouts, intervals, and animation frames for the given context ID.\n\t * @param contextId - The context identifier whose timers should be cleared.\n\t * @returns void\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * timers.setTimeout('ui', () => console.log('timeout'), 1000)\n\t * timers.setInterval('ui', () => console.log('interval'), 500)\n\t *\n\t * // Clear all 'ui' context timers\n\t * timers.dispose('ui')\n\t * ```\n\t * @public\n\t */\n\tdispose(contextId: string) {\n\t\tthis.timeouts.get(contextId)?.forEach((id) => clearTimeout(id))\n\t\tthis.intervals.get(contextId)?.forEach((id) => clearInterval(id))\n\t\tthis.rafs.get(contextId)?.forEach((id) => cancelAnimationFrame(id))\n\n\t\tthis.timeouts.delete(contextId)\n\t\tthis.intervals.delete(contextId)\n\t\tthis.rafs.delete(contextId)\n\t}\n\n\t/**\n\t * Disposes of all timers across all contexts.\n\t * Clears every timeout, interval, and animation frame managed by this instance.\n\t * @returns void\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * timers.setTimeout('ui', () => console.log('ui'), 1000)\n\t * timers.setTimeout('background', () => console.log('bg'), 2000)\n\t *\n\t * // Clear everything\n\t * timers.disposeAll()\n\t * ```\n\t * @public\n\t */\n\tdisposeAll() {\n\t\tconst contextIds = new Set([\n\t\t\t...this.timeouts.keys(),\n\t\t\t...this.intervals.keys(),\n\t\t\t...this.rafs.keys(),\n\t\t])\n\t\tfor (const contextId of contextIds) {\n\t\t\tthis.dispose(contextId)\n\t\t}\n\t}\n\n\t/**\n\t * Returns an object with timer methods bound to a specific context.\n\t * Convenient for getting context-specific timer functions without repeatedly passing the contextId.\n\t * @param contextId - The context identifier to bind the returned methods to.\n\t * @returns An object with setTimeout, setInterval, requestAnimationFrame, the matching clear methods, and dispose bound to the context.\n\t * @example\n\t * ```ts\n\t * const timers = new Timers()\n\t * const uiTimers = timers.forContext('ui')\n\t *\n\t * // These are equivalent to calling timers.setTimeout('ui', ...)\n\t * const id = uiTimers.setTimeout(() => console.log('timeout'), 1000)\n\t * uiTimers.setInterval(() => console.log('interval'), 500)\n\t * uiTimers.requestAnimationFrame(() => console.log('frame'))\n\t *\n\t * // Clear a single timer\n\t * uiTimers.clearTimeout(id)\n\t *\n\t * // Dispose only this context\n\t * uiTimers.dispose()\n\t * ```\n\t * @public\n\t */\n\tforContext(contextId: string) {\n\t\treturn {\n\t\t\tsetTimeout: (handler: TimerHandler, timeout?: number, ...args: any[]) =>\n\t\t\t\tthis.setTimeout(contextId, handler, timeout, args),\n\t\t\tsetInterval: (handler: TimerHandler, timeout?: number, ...args: any[]) =>\n\t\t\t\tthis.setInterval(contextId, handler, timeout, args),\n\t\t\trequestAnimationFrame: (callback: FrameRequestCallback) =>\n\t\t\t\tthis.requestAnimationFrame(contextId, callback),\n\t\t\tclearTimeout: (id: number | undefined) => this.clearTimeout(contextId, id),\n\t\t\tclearInterval: (id: number | undefined) => this.clearInterval(contextId, id),\n\t\t\tcancelAnimationFrame: (id: number | undefined) => this.cancelAnimationFrame(contextId, id),\n\t\t\tdispose: () => this.dispose(contextId),\n\t\t}\n\t}\n}\n\nfunction getOrCreateSet(map: Map<string, Set<number>>, contextId: string): Set<number> {\n\tlet set = map.get(contextId)\n\tif (!set) {\n\t\tset = new Set()\n\t\tmap.set(contextId, set)\n\t}\n\treturn set\n}\n"],
5
+ "mappings": "AAuBO,MAAM,OAAO;AAAA;AAAA;AAAA;AAAA,EAIX,WAAW,oBAAI,IAAyB;AAAA,EACxC,YAAY,oBAAI,IAAyB;AAAA,EACzC,OAAO,oBAAI,IAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW5C,cAAc;AACb,SAAK,aAAa,KAAK,WAAW,KAAK,IAAI;AAC3C,SAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAC7C,SAAK,wBAAwB,KAAK,sBAAsB,KAAK,IAAI;AACjE,SAAK,eAAe,KAAK,aAAa,KAAK,IAAI;AAC/C,SAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,SAAK,uBAAuB,KAAK,qBAAqB,KAAK,I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B,GAAG,KAAK,KAAK,KAAK;AAAA,IACnB,CAAC;AACD,eAAW,aAAa,YAAY;AACnC,WAAK,QAAQ,SAAS;AAAA,IACvB;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBA,WAAW,WAAmB;AAC7B,WAAO;AAAA,MACN,YAAY,CAAC,SAAuB,YAAqB,SACxD,KAAK,WAAW,WAAW,SAAS,SAAS,IAAI;AAAA,MAClD,aAAa,CAAC,SAAuB,YAAqB,SACzD,KAAK,YAAY,WAAW,SAAS,SAAS,IAAI;AAAA,MACnD,uBAAuB,CAAC,aACvB,KAAK,sBAAsB,WAAW,QAAQ;AAAA,MAC/C,cAAc,CAAC,OAA2B,KAAK,aAAa,WAAW,EAAE;AAAA,MACzE,eAAe,CAAC,OAA2B,KAAK,cAAc,WAAW,EAAE;AAAA,MAC3E,sBAAsB,CAAC,OAA2B,KAAK,qBAAqB,WAAW,EAAE;AAAA,MACzF,SAAS,MAAM,KAAK,QAAQ,SAAS;AAAA,IACtC;AAAA,EACD;AACD;AAEA,SAAS,eAAe,KAA+B,WAAgC;AACtF,MAAI,MAAM,IAAI,IAAI,SAAS;AAC3B,MAAI,CAAC,KAAK;AACT,UAAM,oBAAI,IAAI;AACd,QAAI,IAAI,WAAW,GAAG;AAAA,EACvB;AACA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/utils",
3
3
  "description": "tldraw infinite canvas SDK (private utilities).",
4
- "version": "5.5.0-canary.fdb2d37fcb2a",
4
+ "version": "5.5.0-canary.fdd9b4dee0d9",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -38,17 +38,6 @@
38
38
  "src",
39
39
  "DOCS.md"
40
40
  ],
41
- "scripts": {
42
- "test-ci": "yarn run -T vitest run --passWithNoTests",
43
- "test": "yarn run -T vitest --passWithNoTests",
44
- "test-coverage": "yarn run -T vitest run --coverage --passWithNoTests",
45
- "build": "yarn run -T tsx ../../internal/scripts/build-package.ts",
46
- "build-api": "yarn run -T tsx ../../internal/scripts/build-api.ts",
47
- "prepack": "yarn run -T tsx ../../internal/scripts/prepack.ts",
48
- "postpack": "../../internal/scripts/postpack.sh",
49
- "pack-tarball": "yarn pack",
50
- "lint": "yarn run -T tsx ../../internal/scripts/lint.ts"
51
- },
52
41
  "dependencies": {
53
42
  "lodash.isequal": "^4.5.0",
54
43
  "lodash.isequalwith": "^4.4.0",
@@ -73,5 +62,14 @@
73
62
  "import": "./dist-esm/index.mjs",
74
63
  "require": "./dist-cjs/index.js"
75
64
  }
65
+ },
66
+ "scripts": {
67
+ "test-ci": "pnpm exec vitest run --passWithNoTests",
68
+ "test": "pnpm exec vitest --passWithNoTests",
69
+ "test-coverage": "pnpm exec vitest run --coverage --passWithNoTests",
70
+ "build": "pnpm exec tsx ../../internal/scripts/build-package.ts",
71
+ "build-api": "pnpm exec tsx ../../internal/scripts/build-api.ts",
72
+ "pack-tarball": "pnpm pack",
73
+ "lint": "pnpm exec tsx ../../internal/scripts/lint.ts"
76
74
  }
77
75
  }
package/src/index.ts CHANGED
@@ -2,7 +2,6 @@ import { registerTldrawLibraryVersion } from './lib/version'
2
2
 
3
3
  export { default as isEqual } from 'lodash.isequal'
4
4
  export { default as isEqualWith } from 'lodash.isequalwith'
5
- export { default as throttle } from 'lodash.throttle'
6
5
  export { default as uniq } from 'lodash.uniq'
7
6
  export {
8
7
  areArraysShallowEqual,
@@ -93,7 +92,13 @@ export {
93
92
  } from './lib/storage'
94
93
  export { getFirstCharacter, iterateGraphemes } from './lib/string'
95
94
  export { stringEnum } from './lib/stringEnum'
96
- export { FpsScheduler, fpsThrottle, throttleToNextFrame } from './lib/throttle'
95
+ export {
96
+ FpsScheduler,
97
+ fpsThrottle,
98
+ throttle,
99
+ throttleToNextFrame,
100
+ type ThrottledFunction,
101
+ } from './lib/throttle'
97
102
  export { Timers } from './lib/timers'
98
103
  export {
99
104
  type Awaitable,