@tldraw/store 4.2.2 → 4.2.3

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.
Files changed (43) hide show
  1. package/dist-cjs/index.d.ts +1 -49
  2. package/dist-cjs/index.js +1 -3
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/ImmutableMap.js +23 -25
  5. package/dist-cjs/lib/ImmutableMap.js.map +2 -2
  6. package/dist-cjs/lib/StoreSchema.js +24 -80
  7. package/dist-cjs/lib/StoreSchema.js.map +2 -2
  8. package/dist-cjs/lib/StoreSideEffects.js +1 -1
  9. package/dist-cjs/lib/StoreSideEffects.js.map +1 -1
  10. package/dist-cjs/lib/devFreeze.js +3 -5
  11. package/dist-cjs/lib/devFreeze.js.map +2 -2
  12. package/dist-cjs/lib/migrate.js.map +2 -2
  13. package/dist-esm/index.d.mts +1 -49
  14. package/dist-esm/index.mjs +1 -3
  15. package/dist-esm/index.mjs.map +2 -2
  16. package/dist-esm/lib/ImmutableMap.mjs +23 -25
  17. package/dist-esm/lib/ImmutableMap.mjs.map +2 -2
  18. package/dist-esm/lib/StoreSchema.mjs +25 -83
  19. package/dist-esm/lib/StoreSchema.mjs.map +2 -2
  20. package/dist-esm/lib/StoreSideEffects.mjs +1 -1
  21. package/dist-esm/lib/StoreSideEffects.mjs.map +1 -1
  22. package/dist-esm/lib/devFreeze.mjs +3 -5
  23. package/dist-esm/lib/devFreeze.mjs.map +2 -2
  24. package/dist-esm/lib/migrate.mjs.map +2 -2
  25. package/package.json +4 -4
  26. package/src/index.ts +0 -3
  27. package/src/lib/ImmutableMap.ts +33 -25
  28. package/src/lib/StoreSchema.ts +30 -90
  29. package/src/lib/StoreSideEffects.ts +1 -1
  30. package/src/lib/devFreeze.test.ts +2 -6
  31. package/src/lib/devFreeze.ts +3 -7
  32. package/src/lib/migrate.ts +0 -29
  33. package/src/lib/test/recordStore.test.ts +0 -182
  34. package/dist-cjs/lib/AtomSet.js +0 -68
  35. package/dist-cjs/lib/AtomSet.js.map +0 -7
  36. package/dist-cjs/lib/isDev.js +0 -37
  37. package/dist-cjs/lib/isDev.js.map +0 -7
  38. package/dist-esm/lib/AtomSet.mjs +0 -48
  39. package/dist-esm/lib/AtomSet.mjs.map +0 -7
  40. package/dist-esm/lib/isDev.mjs +0 -16
  41. package/dist-esm/lib/isDev.mjs.map +0 -7
  42. package/src/lib/AtomSet.ts +0 -52
  43. package/src/lib/isDev.ts +0 -20
@@ -281,27 +281,6 @@ export declare class AtomMap<K, V> implements Map<K, V> {
281
281
  [Symbol.toStringTag]: string;
282
282
  }
283
283
 
284
- /**
285
- * A drop-in replacement for Set that stores values in atoms and can be used in reactive contexts.
286
- * @public
287
- */
288
- export declare class AtomSet<T> {
289
- private readonly name;
290
- private readonly map;
291
- constructor(name: string, keys?: Iterable<T>);
292
- add(value: T): this;
293
- clear(): void;
294
- delete(value: T): boolean;
295
- forEach(callbackfn: (value: T, value2: T, set: AtomSet<T>) => void, thisArg?: any): void;
296
- has(value: T): boolean;
297
- get size(): number;
298
- entries(): Generator<[T, T], undefined, unknown>;
299
- keys(): Generator<T, undefined, unknown>;
300
- values(): Generator<T, undefined, unknown>;
301
- [Symbol.iterator](): Generator<T, undefined, unknown>;
302
- [Symbol.toStringTag]: string;
303
- }
304
-
305
284
  /**
306
285
  * The base record interface that all records in the store must extend.
307
286
  * This interface provides the fundamental structure required for all records: a unique ID and a type name.
@@ -701,10 +680,6 @@ export declare type Migration = {
701
680
  readonly filter?: (record: UnknownRecord) => boolean;
702
681
  readonly scope: 'record';
703
682
  readonly up: (oldState: UnknownRecord) => UnknownRecord | void;
704
- } | {
705
- readonly down?: never;
706
- readonly scope: 'storage';
707
- readonly up: (storage: SynchronousRecordStorage<UnknownRecord>) => void;
708
683
  });
709
684
 
710
685
  /**
@@ -2422,7 +2397,6 @@ export declare class StoreSchema<R extends UnknownRecord, P = unknown> {
2422
2397
  * @public
2423
2398
  */
2424
2399
  migratePersistedRecord(record: R, persistedSchema: SerializedSchema, direction?: 'down' | 'up'): MigrationResult<R>;
2425
- migrateStorage(storage: SynchronousStorage<R>): void;
2426
2400
  /**
2427
2401
  * Migrates an entire store snapshot to match the current schema version.
2428
2402
  *
@@ -2614,7 +2588,7 @@ export declare class StoreSideEffects<R extends UnknownRecord> {
2614
2588
  * ```ts
2615
2589
  * editor.sideEffects.registerAfterCreateHandler('page', (page, source) => {
2616
2590
  * // Automatically create a shape when a page is created
2617
- * editor.createShape({
2591
+ * editor.createShape<TLTextShape>({
2618
2592
  * id: createShapeId(),
2619
2593
  * type: 'text',
2620
2594
  * props: { richText: toRichText(page.name) },
@@ -2876,28 +2850,6 @@ export declare type StoreValidators<R extends UnknownRecord> = {
2876
2850
  }>>;
2877
2851
  };
2878
2852
 
2879
- /**
2880
- * Abstraction over the store that can be used to perform migrations.
2881
- * @public
2882
- */
2883
- export declare interface SynchronousRecordStorage<R extends UnknownRecord> {
2884
- get(id: string): R | undefined;
2885
- set(id: string, record: R): void;
2886
- delete(id: string): void;
2887
- keys(): Iterable<string>;
2888
- values(): Iterable<R>;
2889
- entries(): Iterable<[string, R]>;
2890
- }
2891
-
2892
- /**
2893
- * Abstraction over the storage that can be used to perform migrations.
2894
- * @public
2895
- */
2896
- export declare interface SynchronousStorage<R extends UnknownRecord> extends SynchronousRecordStorage<R> {
2897
- getSchema(): SerializedSchema;
2898
- setSchema(schema: SerializedSchema): void;
2899
- }
2900
-
2901
2853
  /**
2902
2854
  * A generic type representing any record that extends BaseRecord.
2903
2855
  * This is useful for type constraints when you need to work with records of unknown types,
package/dist-cjs/index.js CHANGED
@@ -19,7 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var index_exports = {};
20
20
  __export(index_exports, {
21
21
  AtomMap: () => import_AtomMap.AtomMap,
22
- AtomSet: () => import_AtomSet.AtomSet,
23
22
  IncrementalSetConstructor: () => import_IncrementalSetConstructor.IncrementalSetConstructor,
24
23
  MigrationFailureReason: () => import_migrate.MigrationFailureReason,
25
24
  RecordType: () => import_RecordType.RecordType,
@@ -44,7 +43,6 @@ __export(index_exports, {
44
43
  module.exports = __toCommonJS(index_exports);
45
44
  var import_utils = require("@tldraw/utils");
46
45
  var import_AtomMap = require("./lib/AtomMap");
47
- var import_AtomSet = require("./lib/AtomSet");
48
46
  var import_devFreeze = require("./lib/devFreeze");
49
47
  var import_IncrementalSetConstructor = require("./lib/IncrementalSetConstructor");
50
48
  var import_migrate = require("./lib/migrate");
@@ -56,7 +54,7 @@ var import_StoreSchema = require("./lib/StoreSchema");
56
54
  var import_StoreSideEffects = require("./lib/StoreSideEffects");
57
55
  (0, import_utils.registerTldrawLibraryVersion)(
58
56
  "@tldraw/store",
59
- "4.2.2",
57
+ "4.2.3",
60
58
  "cjs"
61
59
  );
62
60
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["import { registerTldrawLibraryVersion } from '@tldraw/utils'\nexport { AtomMap } from './lib/AtomMap'\nexport { AtomSet } from './lib/AtomSet'\nexport type { BaseRecord, IdOf, RecordId, UnknownRecord } from './lib/BaseRecord'\nexport { devFreeze } from './lib/devFreeze'\nexport { type QueryExpression, type QueryValueMatcher } from './lib/executeQuery'\nexport { IncrementalSetConstructor } from './lib/IncrementalSetConstructor'\nexport {\n\tcreateMigrationIds,\n\tcreateMigrationSequence,\n\tcreateRecordMigrationSequence,\n\tMigrationFailureReason,\n\tparseMigrationId,\n\ttype LegacyBaseMigrationsInfo,\n\ttype LegacyMigration,\n\ttype LegacyMigrations,\n\ttype Migration,\n\ttype MigrationId,\n\ttype MigrationResult,\n\ttype MigrationSequence,\n\ttype StandaloneDependsOn,\n\ttype SynchronousRecordStorage,\n\ttype SynchronousStorage,\n} from './lib/migrate'\nexport {\n\tcreateEmptyRecordsDiff,\n\tisRecordsDiffEmpty,\n\treverseRecordsDiff,\n\tsquashRecordDiffs,\n\tsquashRecordDiffsMutable,\n\ttype RecordsDiff,\n} from './lib/RecordsDiff'\nexport { assertIdType, createRecordType, RecordType, type RecordScope } from './lib/RecordType'\nexport {\n\tcreateComputedCache,\n\tStore,\n\ttype ChangeSource,\n\ttype CollectionDiff,\n\ttype ComputedCache,\n\ttype CreateComputedCacheOpts,\n\ttype HistoryEntry,\n\ttype RecordFromId,\n\ttype SerializedStore,\n\ttype StoreError,\n\ttype StoreListener,\n\ttype StoreListenerFilters,\n\ttype StoreObject,\n\ttype StoreObjectRecordType,\n\ttype StoreRecord,\n\ttype StoreSnapshot,\n\ttype StoreValidator,\n\ttype StoreValidators,\n} from './lib/Store'\nexport { StoreQueries, type RSIndex, type RSIndexDiff, type RSIndexMap } from './lib/StoreQueries'\nexport { StoreSchema, type StoreValidationFailure } from './lib/StoreSchema'\nexport type {\n\tSerializedSchema,\n\tSerializedSchemaV1,\n\tSerializedSchemaV2,\n\tStoreSchemaOptions,\n} from './lib/StoreSchema'\nexport {\n\tStoreSideEffects,\n\ttype StoreAfterChangeHandler,\n\ttype StoreAfterCreateHandler,\n\ttype StoreAfterDeleteHandler,\n\ttype StoreBeforeChangeHandler,\n\ttype StoreBeforeCreateHandler,\n\ttype StoreBeforeDeleteHandler,\n\ttype StoreOperationCompleteHandler,\n} from './lib/StoreSideEffects'\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6C;AAC7C,qBAAwB;AACxB,qBAAwB;AAExB,uBAA0B;AAE1B,uCAA0C;AAC1C,qBAgBO;AACP,yBAOO;AACP,wBAA6E;AAC7E,mBAmBO;AACP,0BAA8E;AAC9E,yBAAyD;AAOzD,8BASO;AAAA,IAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF;",
4
+ "sourcesContent": ["import { registerTldrawLibraryVersion } from '@tldraw/utils'\nexport { AtomMap } from './lib/AtomMap'\nexport type { BaseRecord, IdOf, RecordId, UnknownRecord } from './lib/BaseRecord'\nexport { devFreeze } from './lib/devFreeze'\nexport { type QueryExpression, type QueryValueMatcher } from './lib/executeQuery'\nexport { IncrementalSetConstructor } from './lib/IncrementalSetConstructor'\nexport {\n\tcreateMigrationIds,\n\tcreateMigrationSequence,\n\tcreateRecordMigrationSequence,\n\tMigrationFailureReason,\n\tparseMigrationId,\n\ttype LegacyBaseMigrationsInfo,\n\ttype LegacyMigration,\n\ttype LegacyMigrations,\n\ttype Migration,\n\ttype MigrationId,\n\ttype MigrationResult,\n\ttype MigrationSequence,\n\ttype StandaloneDependsOn,\n} from './lib/migrate'\nexport {\n\tcreateEmptyRecordsDiff,\n\tisRecordsDiffEmpty,\n\treverseRecordsDiff,\n\tsquashRecordDiffs,\n\tsquashRecordDiffsMutable,\n\ttype RecordsDiff,\n} from './lib/RecordsDiff'\nexport { assertIdType, createRecordType, RecordType, type RecordScope } from './lib/RecordType'\nexport {\n\tcreateComputedCache,\n\tStore,\n\ttype ChangeSource,\n\ttype CollectionDiff,\n\ttype ComputedCache,\n\ttype CreateComputedCacheOpts,\n\ttype HistoryEntry,\n\ttype RecordFromId,\n\ttype SerializedStore,\n\ttype StoreError,\n\ttype StoreListener,\n\ttype StoreListenerFilters,\n\ttype StoreObject,\n\ttype StoreObjectRecordType,\n\ttype StoreRecord,\n\ttype StoreSnapshot,\n\ttype StoreValidator,\n\ttype StoreValidators,\n} from './lib/Store'\nexport { StoreQueries, type RSIndex, type RSIndexDiff, type RSIndexMap } from './lib/StoreQueries'\nexport { StoreSchema, type StoreValidationFailure } from './lib/StoreSchema'\nexport type {\n\tSerializedSchema,\n\tSerializedSchemaV1,\n\tSerializedSchemaV2,\n\tStoreSchemaOptions,\n} from './lib/StoreSchema'\nexport {\n\tStoreSideEffects,\n\ttype StoreAfterChangeHandler,\n\ttype StoreAfterCreateHandler,\n\ttype StoreAfterDeleteHandler,\n\ttype StoreBeforeChangeHandler,\n\ttype StoreBeforeCreateHandler,\n\ttype StoreBeforeDeleteHandler,\n\ttype StoreOperationCompleteHandler,\n} from './lib/StoreSideEffects'\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6C;AAC7C,qBAAwB;AAExB,uBAA0B;AAE1B,uCAA0C;AAC1C,qBAcO;AACP,yBAOO;AACP,wBAA6E;AAC7E,mBAmBO;AACP,0BAA8E;AAC9E,yBAAyD;AAOzD,8BASO;AAAA,IAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF;",
6
6
  "names": []
7
7
  }
@@ -149,9 +149,16 @@ function SetRef(ref) {
149
149
  ref.value = true;
150
150
  }
151
151
  }
152
- function arrCopy(arr, offset = 0) {
153
- return arr.slice(offset);
152
+ function arrCopy(arr, offset) {
153
+ offset = offset || 0;
154
+ const len = Math.max(0, arr.length - offset);
155
+ const newArr = new Array(len);
156
+ for (let ii = 0; ii < len; ii++) {
157
+ newArr[ii] = arr[ii + offset];
158
+ }
159
+ return newArr;
154
160
  }
161
+ const is = Object.is;
155
162
  class OwnerID {
156
163
  }
157
164
  class ImmutableMap {
@@ -376,7 +383,7 @@ class ArrayMapNode {
376
383
  get(_shift, _keyHash, key, notSetValue) {
377
384
  const entries = this.entries;
378
385
  for (let ii = 0, len = entries.length; ii < len; ii++) {
379
- if (Object.is(key, entries[ii][0])) {
386
+ if (is(key, entries[ii][0])) {
380
387
  return entries[ii][1];
381
388
  }
382
389
  }
@@ -388,7 +395,7 @@ class ArrayMapNode {
388
395
  let idx = 0;
389
396
  const len = entries.length;
390
397
  for (; idx < len; idx++) {
391
- if (Object.is(key, entries[idx][0])) {
398
+ if (is(key, entries[idx][0])) {
392
399
  break;
393
400
  }
394
401
  }
@@ -397,7 +404,7 @@ class ArrayMapNode {
397
404
  return this;
398
405
  }
399
406
  SetRef(didAlter);
400
- if (removed || !exists) SetRef(didChangeSize);
407
+ (removed || !exists) && SetRef(didChangeSize);
401
408
  if (removed && entries.length === 1) {
402
409
  return;
403
410
  }
@@ -408,11 +415,7 @@ class ArrayMapNode {
408
415
  const newEntries = isEditable ? entries : arrCopy(entries);
409
416
  if (exists) {
410
417
  if (removed) {
411
- if (idx === len - 1) {
412
- newEntries.pop();
413
- } else {
414
- newEntries[idx] = newEntries.pop();
415
- }
418
+ idx === len - 1 ? newEntries.pop() : newEntries[idx] = newEntries.pop();
416
419
  } else {
417
420
  newEntries[idx] = [key, value];
418
421
  }
@@ -553,7 +556,7 @@ class HashCollisionNode {
553
556
  get(shift, keyHash, key, notSetValue) {
554
557
  const entries = this.entries;
555
558
  for (let ii = 0, len = entries.length; ii < len; ii++) {
556
- if (Object.is(key, entries[ii][0])) {
559
+ if (is(key, entries[ii][0])) {
557
560
  return entries[ii][1];
558
561
  }
559
562
  }
@@ -576,7 +579,7 @@ class HashCollisionNode {
576
579
  let idx = 0;
577
580
  const len = entries.length;
578
581
  for (; idx < len; idx++) {
579
- if (Object.is(key, entries[idx][0])) {
582
+ if (is(key, entries[idx][0])) {
580
583
  break;
581
584
  }
582
585
  }
@@ -585,7 +588,7 @@ class HashCollisionNode {
585
588
  return this;
586
589
  }
587
590
  SetRef(didAlter);
588
- if (removed || !exists) SetRef(didChangeSize);
591
+ (removed || !exists) && SetRef(didChangeSize);
589
592
  if (removed && len === 2) {
590
593
  return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
591
594
  }
@@ -593,11 +596,7 @@ class HashCollisionNode {
593
596
  const newEntries = isEditable ? entries : arrCopy(entries);
594
597
  if (exists) {
595
598
  if (removed) {
596
- if (idx === len - 1) {
597
- newEntries.pop();
598
- } else {
599
- newEntries[idx] = newEntries.pop();
600
- }
599
+ idx === len - 1 ? newEntries.pop() : newEntries[idx] = newEntries.pop();
601
600
  } else {
602
601
  newEntries[idx] = [key, value];
603
602
  }
@@ -618,11 +617,11 @@ class ValueNode {
618
617
  this.entry = entry;
619
618
  }
620
619
  get(shift, keyHash, key, notSetValue) {
621
- return Object.is(key, this.entry[0]) ? this.entry[1] : notSetValue;
620
+ return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
622
621
  }
623
622
  update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
624
623
  const removed = value === NOT_SET;
625
- const keyMatch = Object.is(key, this.entry[0]);
624
+ const keyMatch = is(key, this.entry[0]);
626
625
  if (keyMatch ? value === this.entry[1] : removed) {
627
626
  return this;
628
627
  }
@@ -701,11 +700,10 @@ const ITERATE_VALUES = 1;
701
700
  const ITERATE_ENTRIES = 2;
702
701
  function iteratorValue(type, k, v, iteratorResult) {
703
702
  const value = type === ITERATE_KEYS ? k : type === ITERATE_VALUES ? v : [k, v];
704
- if (iteratorResult) {
705
- iteratorResult.value = value;
706
- } else {
707
- iteratorResult = { value, done: false };
708
- }
703
+ iteratorResult ? iteratorResult.value = value : iteratorResult = {
704
+ value,
705
+ done: false
706
+ };
709
707
  return iteratorResult;
710
708
  }
711
709
  function iteratorDone() {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/ImmutableMap.ts"],
4
- "sourcesContent": ["/*!\n * This file was lovingly and delicately extracted from Immutable.js\n * MIT License: https://github.com/immutable-js/immutable-js/blob/main/LICENSE\n * Copyright (c) 2014-present, Lee Byron and other contributors.\n */\n\nfunction smi(i32: number) {\n\treturn ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff)\n}\n\nconst defaultValueOf = Object.prototype.valueOf\n\nfunction hash(o: any) {\n\tif (o == null) {\n\t\treturn hashNullish(o)\n\t}\n\n\tif (typeof o.hashCode === 'function') {\n\t\t// Drop any high bits from accidentally long hash codes.\n\t\treturn smi(o.hashCode(o))\n\t}\n\n\tconst v = valueOf(o)\n\n\tif (v == null) {\n\t\treturn hashNullish(v)\n\t}\n\n\tswitch (typeof v) {\n\t\tcase 'boolean':\n\t\t\t// The hash values for built-in constants are a 1 value for each 5-byte\n\t\t\t// shift region expect for the first, which encodes the value. This\n\t\t\t// reduces the odds of a hash collision for these common values.\n\t\t\treturn v ? 0x42108421 : 0x42108420\n\t\tcase 'number':\n\t\t\treturn hashNumber(v)\n\t\tcase 'string':\n\t\t\treturn v.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(v) : hashString(v)\n\t\tcase 'object':\n\t\tcase 'function':\n\t\t\treturn hashJSObj(v)\n\t\tcase 'symbol':\n\t\t\treturn hashSymbol(v)\n\t\tdefault:\n\t\t\tif (typeof v.toString === 'function') {\n\t\t\t\treturn hashString(v.toString())\n\t\t\t}\n\t\t\tthrow new Error('Value type ' + typeof v + ' cannot be hashed.')\n\t}\n}\n\nfunction hashNullish(nullish: null | undefined) {\n\treturn nullish === null ? 0x42108422 : /* undefined */ 0x42108423\n}\n\n// Compress arbitrarily large numbers into smi hashes.\nfunction hashNumber(n: number) {\n\tif (n !== n || n === Infinity) {\n\t\treturn 0\n\t}\n\tlet hash = n | 0\n\tif (hash !== n) {\n\t\thash ^= n * 0xffffffff\n\t}\n\twhile (n > 0xffffffff) {\n\t\tn /= 0xffffffff\n\t\thash ^= n\n\t}\n\treturn smi(hash)\n}\n\nfunction cachedHashString(string: string) {\n\tlet hashed = stringHashCache[string]\n\tif (hashed === undefined) {\n\t\thashed = hashString(string)\n\t\tif (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {\n\t\t\tSTRING_HASH_CACHE_SIZE = 0\n\t\t\tstringHashCache = {}\n\t\t}\n\t\tSTRING_HASH_CACHE_SIZE++\n\t\tstringHashCache[string] = hashed\n\t}\n\treturn hashed\n}\n\n// http://jsperf.com/hashing-strings\nfunction hashString(string: string) {\n\t// This is the hash from JVM\n\t// The hash code for a string is computed as\n\t// s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],\n\t// where s[i] is the ith character of the string and n is the length of\n\t// the string. We \"mod\" the result to make it between 0 (inclusive) and 2^31\n\t// (exclusive) by dropping high bits.\n\tlet hashed = 0\n\tfor (let ii = 0; ii < string.length; ii++) {\n\t\thashed = (31 * hashed + string.charCodeAt(ii)) | 0\n\t}\n\treturn smi(hashed)\n}\n\nfunction hashSymbol(sym: symbol) {\n\tlet hashed = symbolMap[sym]\n\tif (hashed !== undefined) {\n\t\treturn hashed\n\t}\n\n\thashed = nextHash()\n\n\tsymbolMap[sym] = hashed\n\n\treturn hashed\n}\n\nfunction hashJSObj(obj: object) {\n\tlet hashed = weakMap.get(obj)\n\tif (hashed !== undefined) {\n\t\treturn hashed\n\t}\n\n\thashed = nextHash()\n\n\tweakMap.set(obj, hashed)\n\n\treturn hashed\n}\n\nfunction valueOf(obj: any) {\n\treturn obj.valueOf !== defaultValueOf && typeof obj.valueOf === 'function'\n\t\t? obj.valueOf(obj)\n\t\t: obj\n}\n\nfunction nextHash() {\n\tconst nextHash = ++_objHashUID\n\tif (_objHashUID & 0x40000000) {\n\t\t_objHashUID = 0\n\t}\n\treturn nextHash\n}\n\n// If possible, use a WeakMap.\nconst weakMap = new WeakMap()\n\nconst symbolMap = Object.create(null)\n\nlet _objHashUID = 0\n\nconst STRING_HASH_CACHE_MIN_STRLEN = 16\nconst STRING_HASH_CACHE_MAX_SIZE = 255\nlet STRING_HASH_CACHE_SIZE = 0\nlet stringHashCache: Record<string, number> = {}\n\n// Constants describing the size of trie nodes.\nconst SHIFT = 5 // Resulted in best performance after ______?\nconst SIZE = 1 << SHIFT\nconst MASK = SIZE - 1\n\n// A consistent shared value representing \"not set\" which equals nothing other\n// than itself, and nothing that could be provided externally.\nconst NOT_SET = {}\n\ninterface Ref {\n\tvalue: boolean\n}\n\n// Boolean references, Rough equivalent of `bool &`.\nfunction MakeRef(): Ref {\n\treturn { value: false }\n}\n\nfunction SetRef(ref?: Ref): void {\n\tif (ref) {\n\t\tref.value = true\n\t}\n}\n\nfunction arrCopy<I>(arr: Array<I>, offset = 0): Array<I> {\n\treturn arr.slice(offset)\n}\n\nclass OwnerID {}\n\n/**\n * A persistent immutable map implementation based on a Hash Array Mapped Trie (HAMT) data structure.\n * Provides efficient operations for creating, reading, updating, and deleting key-value pairs while\n * maintaining structural sharing to minimize memory usage and maximize performance.\n *\n * This implementation is extracted and adapted from Immutable.js, optimized for tldraw's store needs.\n * All operations return new instances rather than modifying existing ones, ensuring immutability.\n *\n * @public\n * @example\n * ```ts\n * // Create a new map\n * const map = new ImmutableMap([\n * ['key1', 'value1'],\n * ['key2', 'value2']\n * ])\n *\n * // Add or update values\n * const updated = map.set('key3', 'value3')\n *\n * // Get values\n * const value = map.get('key1') // 'value1'\n *\n * // Delete values\n * const smaller = map.delete('key1')\n * ```\n */\nexport class ImmutableMap<K, V> {\n\t// @pragma Construction\n\t// @ts-ignore\n\t_root: MapNode<K, V>\n\t// @ts-ignore\n\tsize: number\n\t// @ts-ignore\n\t__ownerID: OwnerID\n\t// @ts-ignore\n\t__hash: number | undefined\n\t// @ts-ignore\n\t__altered: boolean\n\n\t/**\n\t * Creates a new ImmutableMap instance.\n\t *\n\t * @param value - An iterable of key-value pairs to populate the map, or null/undefined for an empty map\n\t * @example\n\t * ```ts\n\t * // Create from array of pairs\n\t * const map1 = new ImmutableMap([['a', 1], ['b', 2]])\n\t *\n\t * // Create empty map\n\t * const map2 = new ImmutableMap()\n\t *\n\t * // Create from another map\n\t * const map3 = new ImmutableMap(map1)\n\t * ```\n\t */\n\tconstructor(value?: Iterable<[K, V]> | null | undefined) {\n\t\t// @ts-ignore\n\t\treturn value === undefined || value === null\n\t\t\t? emptyMap()\n\t\t\t: value instanceof ImmutableMap\n\t\t\t\t? value\n\t\t\t\t: emptyMap().withMutations((map) => {\n\t\t\t\t\t\tfor (const [k, v] of value) {\n\t\t\t\t\t\t\tmap.set(k, v)\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t}\n\n\t/**\n\t * Gets the value associated with the specified key.\n\t *\n\t * @param k - The key to look up\n\t * @returns The value associated with the key, or undefined if not found\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['key1', 'value1']])\n\t * console.log(map.get('key1')) // 'value1'\n\t * console.log(map.get('missing')) // undefined\n\t * ```\n\t */\n\tget(k: K): V | undefined\n\t/**\n\t * Gets the value associated with the specified key, with a fallback value.\n\t *\n\t * @param k - The key to look up\n\t * @param notSetValue - The value to return if the key is not found\n\t * @returns The value associated with the key, or the fallback value if not found\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['key1', 'value1']])\n\t * console.log(map.get('key1', 'default')) // 'value1'\n\t * console.log(map.get('missing', 'default')) // 'default'\n\t * ```\n\t */\n\tget(k: K, notSetValue?: V): V {\n\t\treturn this._root ? this._root.get(0, undefined as any, k, notSetValue)! : notSetValue!\n\t}\n\n\t/**\n\t * Returns a new ImmutableMap with the specified key-value pair added or updated.\n\t * If the key already exists, its value is replaced. Otherwise, a new entry is created.\n\t *\n\t * @param k - The key to set\n\t * @param v - The value to associate with the key\n\t * @returns A new ImmutableMap with the key-value pair set\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1]])\n\t * const updated = map.set('b', 2) // New map with both 'a' and 'b'\n\t * const replaced = map.set('a', 10) // New map with 'a' updated to 10\n\t * ```\n\t */\n\tset(k: K, v: V) {\n\t\treturn updateMap(this, k, v)\n\t}\n\n\t/**\n\t * Returns a new ImmutableMap with the specified key removed.\n\t * If the key doesn't exist, returns the same map instance.\n\t *\n\t * @param k - The key to remove\n\t * @returns A new ImmutableMap with the key removed, or the same instance if key not found\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * const smaller = map.delete('a') // New map with only 'b'\n\t * const same = map.delete('missing') // Returns original map\n\t * ```\n\t */\n\tdelete(k: K) {\n\t\treturn updateMap(this, k, NOT_SET as any)\n\t}\n\n\t/**\n\t * Returns a new ImmutableMap with all specified keys removed.\n\t * This is more efficient than calling delete() multiple times.\n\t *\n\t * @param keys - An iterable of keys to remove\n\t * @returns A new ImmutableMap with all specified keys removed\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2], ['c', 3]])\n\t * const smaller = map.deleteAll(['a', 'c']) // New map with only 'b'\n\t * ```\n\t */\n\tdeleteAll(keys: Iterable<K>) {\n\t\treturn this.withMutations((map) => {\n\t\t\tfor (const key of keys) {\n\t\t\t\tmap.delete(key)\n\t\t\t}\n\t\t})\n\t}\n\n\t__ensureOwner(ownerID: OwnerID) {\n\t\tif (ownerID === this.__ownerID) {\n\t\t\treturn this\n\t\t}\n\t\tif (!ownerID) {\n\t\t\tif (this.size === 0) {\n\t\t\t\treturn emptyMap()\n\t\t\t}\n\t\t\tthis.__ownerID = ownerID\n\t\t\tthis.__altered = false\n\t\t\treturn this\n\t\t}\n\t\treturn makeMap(this.size, this._root, ownerID, this.__hash)\n\t}\n\n\t/**\n\t * Applies multiple mutations efficiently by creating a mutable copy,\n\t * applying all changes, then returning an immutable result.\n\t * This is more efficient than chaining multiple set/delete operations.\n\t *\n\t * @param fn - Function that receives a mutable copy and applies changes\n\t * @returns A new ImmutableMap with all mutations applied, or the same instance if no changes\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1]])\n\t * const updated = map.withMutations(mutable => {\n\t * mutable.set('b', 2)\n\t * mutable.set('c', 3)\n\t * mutable.delete('a')\n\t * }) // Efficiently applies all changes at once\n\t * ```\n\t */\n\twithMutations(fn: (mutable: this) => void): this {\n\t\tconst mutable = this.asMutable()\n\t\tfn(mutable)\n\t\treturn mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this\n\t}\n\n\t/**\n\t * Checks if this map instance has been altered during a mutation operation.\n\t * This is used internally to optimize mutations.\n\t *\n\t * @returns True if the map was altered, false otherwise\n\t * @internal\n\t */\n\twasAltered() {\n\t\treturn this.__altered\n\t}\n\n\t/**\n\t * Returns a mutable copy of this map that can be efficiently modified.\n\t * Multiple changes to the mutable copy are batched together.\n\t *\n\t * @returns A mutable copy of this map\n\t * @internal\n\t */\n\tasMutable() {\n\t\treturn this.__ownerID ? this : this.__ensureOwner(new OwnerID())\n\t}\n\n\t/**\n\t * Makes the map iterable, yielding key-value pairs.\n\t *\n\t * @returns An iterator over [key, value] pairs\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * for (const [key, value] of map) {\n\t * console.log(key, value) // 'a' 1, then 'b' 2\n\t * }\n\t * ```\n\t */\n\t[Symbol.iterator](): Iterator<[K, V]> {\n\t\treturn this.entries()[Symbol.iterator]()\n\t}\n\n\t/**\n\t * Returns an iterable of key-value pairs.\n\t *\n\t * @returns An iterable over [key, value] pairs\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * const entries = Array.from(map.entries()) // [['a', 1], ['b', 2]]\n\t * ```\n\t */\n\tentries(): Iterable<[K, V]> {\n\t\treturn new MapIterator(this, ITERATE_ENTRIES, false)\n\t}\n\n\t/**\n\t * Returns an iterable of keys.\n\t *\n\t * @returns An iterable over keys\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * const keys = Array.from(map.keys()) // ['a', 'b']\n\t * ```\n\t */\n\tkeys(): Iterable<K> {\n\t\treturn new MapIterator(this, ITERATE_KEYS, false)\n\t}\n\n\t/**\n\t * Returns an iterable of values.\n\t *\n\t * @returns An iterable over values\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * const values = Array.from(map.values()) // [1, 2]\n\t * ```\n\t */\n\tvalues(): Iterable<V> {\n\t\treturn new MapIterator(this, ITERATE_VALUES, false)\n\t}\n}\n\ntype MapNode<K, V> =\n\t| ArrayMapNode<K, V>\n\t| BitmapIndexedNode<K, V>\n\t| HashArrayMapNode<K, V>\n\t| HashCollisionNode<K, V>\n\t| ValueNode<K, V>\n\n// #pragma Trie Nodes\n\nclass ArrayMapNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic entries: Array<[K, V]>\n\t) {}\n\n\tget(_shift: unknown, _keyHash: unknown, key: K, notSetValue?: V) {\n\t\tconst entries = this.entries\n\t\tfor (let ii = 0, len = entries.length; ii < len; ii++) {\n\t\t\tif (Object.is(key, entries[ii][0])) {\n\t\t\t\treturn entries[ii][1]\n\t\t\t}\n\t\t}\n\t\treturn notSetValue\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\t_shift: unknown,\n\t\t_keyHash: unknown,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t): MapNode<K, V> | undefined {\n\t\tconst removed = value === NOT_SET\n\n\t\tconst entries = this.entries\n\t\tlet idx = 0\n\t\tconst len = entries.length\n\t\tfor (; idx < len; idx++) {\n\t\t\tif (Object.is(key, entries[idx][0])) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tconst exists = idx < len\n\n\t\tif (exists ? entries[idx][1] === value : removed) {\n\t\t\treturn this\n\t\t}\n\n\t\tSetRef(didAlter)\n\t\tif (removed || !exists) SetRef(didChangeSize)\n\n\t\tif (removed && entries.length === 1) {\n\t\t\treturn // undefined\n\t\t}\n\n\t\tif (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {\n\t\t\treturn createNodes(ownerID, entries, key, value)\n\t\t}\n\n\t\tconst isEditable = ownerID && ownerID === this.ownerID\n\t\tconst newEntries = isEditable ? entries : arrCopy(entries)\n\n\t\tif (exists) {\n\t\t\tif (removed) {\n\t\t\t\tif (idx === len - 1) {\n\t\t\t\t\tnewEntries.pop()\n\t\t\t\t} else {\n\t\t\t\t\tnewEntries[idx] = newEntries.pop()!\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnewEntries[idx] = [key, value]\n\t\t\t}\n\t\t} else {\n\t\t\tnewEntries.push([key, value])\n\t\t}\n\n\t\tif (isEditable) {\n\t\t\tthis.entries = newEntries\n\t\t\treturn this\n\t\t}\n\n\t\treturn new ArrayMapNode(ownerID, newEntries)\n\t}\n}\n\nclass BitmapIndexedNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic bitmap: number,\n\t\tpublic nodes: Array<MapNode<K, V>>\n\t) {}\n\n\tget(shift: number, keyHash: number, key: K, notSetValue?: V): V | undefined {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\t\tconst bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK)\n\t\tconst bitmap = this.bitmap\n\t\treturn (bitmap & bit) === 0\n\t\t\t? notSetValue\n\t\t\t: this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue)\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\tshift: number,\n\t\tkeyHash: number,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t): MapNode<K, V> | undefined {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\t\tconst keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK\n\t\tconst bit = 1 << keyHashFrag\n\t\tconst bitmap = this.bitmap\n\t\tconst exists = (bitmap & bit) !== 0\n\n\t\tif (!exists && value === NOT_SET) {\n\t\t\treturn this\n\t\t}\n\n\t\tconst idx = popCount(bitmap & (bit - 1))\n\t\tconst nodes = this.nodes\n\t\tconst node = exists ? nodes[idx] : undefined\n\t\tconst newNode = updateNode(\n\t\t\tnode,\n\t\t\townerID,\n\t\t\tshift + SHIFT,\n\t\t\tkeyHash,\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\tdidChangeSize,\n\t\t\tdidAlter\n\t\t)\n\n\t\tif (newNode === node) {\n\t\t\treturn this\n\t\t}\n\n\t\tif (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {\n\t\t\treturn expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode)\n\t\t}\n\n\t\tif (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {\n\t\t\treturn nodes[idx ^ 1]\n\t\t}\n\n\t\tif (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {\n\t\t\treturn newNode\n\t\t}\n\n\t\tconst isEditable = ownerID && ownerID === this.ownerID\n\t\tconst newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit\n\t\tconst newNodes = exists\n\t\t\t? newNode\n\t\t\t\t? setAt(nodes, idx, newNode, isEditable)\n\t\t\t\t: spliceOut(nodes, idx, isEditable)\n\t\t\t: spliceIn(nodes, idx, newNode, isEditable)\n\n\t\tif (isEditable) {\n\t\t\tthis.bitmap = newBitmap\n\t\t\tthis.nodes = newNodes\n\t\t\treturn this\n\t\t}\n\n\t\treturn new BitmapIndexedNode(ownerID, newBitmap, newNodes)\n\t}\n}\n\nclass HashArrayMapNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic count: number,\n\t\tpublic nodes: Array<MapNode<K, V>>\n\t) {}\n\n\tget(shift: number, keyHash: number, key: K, notSetValue?: V): V | undefined {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\t\tconst idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK\n\t\tconst node = this.nodes[idx]\n\t\treturn node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\tshift: number,\n\t\tkeyHash: number,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t) {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\t\tconst idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK\n\t\tconst removed = value === NOT_SET\n\t\tconst nodes = this.nodes\n\t\tconst node = nodes[idx]\n\n\t\tif (removed && !node) {\n\t\t\treturn this\n\t\t}\n\n\t\tconst newNode = updateNode(\n\t\t\tnode,\n\t\t\townerID,\n\t\t\tshift + SHIFT,\n\t\t\tkeyHash,\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\tdidChangeSize,\n\t\t\tdidAlter\n\t\t)\n\t\tif (newNode === node) {\n\t\t\treturn this\n\t\t}\n\n\t\tlet newCount = this.count\n\t\tif (!node) {\n\t\t\tnewCount++\n\t\t} else if (!newNode) {\n\t\t\tnewCount--\n\t\t\tif (newCount < MIN_HASH_ARRAY_MAP_SIZE) {\n\t\t\t\treturn packNodes(ownerID, nodes, newCount, idx)\n\t\t\t}\n\t\t}\n\n\t\tconst isEditable = ownerID && ownerID === this.ownerID\n\t\tconst newNodes = setAt(nodes, idx, newNode!, isEditable)\n\n\t\tif (isEditable) {\n\t\t\tthis.count = newCount\n\t\t\tthis.nodes = newNodes\n\t\t\treturn this\n\t\t}\n\n\t\treturn new HashArrayMapNode(ownerID, newCount, newNodes)\n\t}\n}\n\nclass HashCollisionNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic keyHash: number,\n\t\tpublic entries: Array<[K, V]>\n\t) {}\n\n\tget(shift: number, keyHash: number, key: K, notSetValue?: V) {\n\t\tconst entries = this.entries\n\t\tfor (let ii = 0, len = entries.length; ii < len; ii++) {\n\t\t\tif (Object.is(key, entries[ii][0])) {\n\t\t\t\treturn entries[ii][1]\n\t\t\t}\n\t\t}\n\t\treturn notSetValue\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\tshift: number,\n\t\tkeyHash: number,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t): MapNode<K, V> {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\n\t\tconst removed = value === NOT_SET\n\n\t\tif (keyHash !== this.keyHash) {\n\t\t\tif (removed) {\n\t\t\t\treturn this\n\t\t\t}\n\t\t\tSetRef(didAlter)\n\t\t\tSetRef(didChangeSize)\n\t\t\treturn mergeIntoNode(this, ownerID, shift, keyHash, [key, value])\n\t\t}\n\n\t\tconst entries = this.entries\n\t\tlet idx = 0\n\t\tconst len = entries.length\n\t\tfor (; idx < len; idx++) {\n\t\t\tif (Object.is(key, entries[idx][0])) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tconst exists = idx < len\n\n\t\tif (exists ? entries[idx][1] === value : removed) {\n\t\t\treturn this\n\t\t}\n\n\t\tSetRef(didAlter)\n\t\tif (removed || !exists) SetRef(didChangeSize)\n\n\t\tif (removed && len === 2) {\n\t\t\treturn new ValueNode(ownerID, this.keyHash, entries[idx ^ 1])\n\t\t}\n\n\t\tconst isEditable = ownerID && ownerID === this.ownerID\n\t\tconst newEntries = isEditable ? entries : arrCopy(entries)\n\n\t\tif (exists) {\n\t\t\tif (removed) {\n\t\t\t\tif (idx === len - 1) {\n\t\t\t\t\tnewEntries.pop()\n\t\t\t\t} else {\n\t\t\t\t\tnewEntries[idx] = newEntries.pop()!\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnewEntries[idx] = [key, value]\n\t\t\t}\n\t\t} else {\n\t\t\tnewEntries.push([key, value])\n\t\t}\n\n\t\tif (isEditable) {\n\t\t\tthis.entries = newEntries\n\t\t\treturn this\n\t\t}\n\n\t\treturn new HashCollisionNode(ownerID, this.keyHash, newEntries)\n\t}\n}\n\nclass ValueNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic keyHash: number | undefined,\n\t\tpublic entry: [K, V]\n\t) {}\n\n\tget(shift: number, keyHash: number, key: K, notSetValue?: V) {\n\t\treturn Object.is(key, this.entry[0]) ? this.entry[1] : notSetValue\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\tshift: number,\n\t\tkeyHash: number | undefined,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t) {\n\t\tconst removed = value === NOT_SET\n\t\tconst keyMatch = Object.is(key, this.entry[0])\n\t\tif (keyMatch ? value === this.entry[1] : removed) {\n\t\t\treturn this\n\t\t}\n\n\t\tSetRef(didAlter)\n\n\t\tif (removed) {\n\t\t\tSetRef(didChangeSize)\n\t\t\treturn // undefined\n\t\t}\n\n\t\tif (keyMatch) {\n\t\t\tif (ownerID && ownerID === this.ownerID) {\n\t\t\t\tthis.entry[1] = value\n\t\t\t\treturn this\n\t\t\t}\n\t\t\treturn new ValueNode(ownerID, this.keyHash, [key, value])\n\t\t}\n\n\t\tSetRef(didChangeSize)\n\t\treturn mergeIntoNode(this, ownerID, shift, hash(key), [key, value])\n\t}\n}\n\n// #pragma Iterators\n\nclass MapIterator<K, V> implements Iterator<any>, Iterable<any> {\n\t_stack\n\n\tconstructor(\n\t\tmap: ImmutableMap<K, V>,\n\t\tpublic _type: IterationType,\n\t\tpublic _reverse: boolean\n\t) {\n\t\tthis._stack = map._root && mapIteratorFrame<K, V>(map._root)\n\t}\n\n\t[Symbol.iterator](): Iterator<any> {\n\t\treturn this\n\t}\n\n\tnext() {\n\t\tconst type = this._type\n\t\tlet stack = this._stack\n\t\twhile (stack) {\n\t\t\tconst node = stack.node as any\n\t\t\tconst index = stack.index++\n\t\t\tlet maxIndex\n\t\t\tif (node.entry) {\n\t\t\t\tif (index === 0) {\n\t\t\t\t\treturn mapIteratorValue(type, node.entry)\n\t\t\t\t}\n\t\t\t} else if ('entries' in node && node.entries) {\n\t\t\t\tmaxIndex = node.entries.length - 1\n\t\t\t\tif (index <= maxIndex) {\n\t\t\t\t\treturn mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index])\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmaxIndex = node.nodes.length - 1\n\t\t\t\tif (index <= maxIndex) {\n\t\t\t\t\tconst subNode = node.nodes[this._reverse ? maxIndex - index : index]\n\t\t\t\t\tif (subNode) {\n\t\t\t\t\t\tif (subNode.entry) {\n\t\t\t\t\t\t\treturn mapIteratorValue(type, subNode.entry)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstack = this._stack = mapIteratorFrame(subNode, stack)\n\t\t\t\t\t}\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\tstack = this._stack = this._stack.__prev!\n\t\t}\n\t\treturn iteratorDone() as any\n\t}\n}\n\nfunction mapIteratorValue<K, V>(type: IterationType, entry: [K, V]) {\n\treturn iteratorValue(type, entry[0], entry[1])\n}\n\ninterface IStack {\n\tnode: MapNode<unknown, unknown>\n\tindex: number\n\t__prev?: IStack\n}\n\nfunction mapIteratorFrame<K, V>(\n\tnode: MapNode<K, V>,\n\tprev?: { node: MapNode<K, V>; index: number; __prev?: IStack }\n): IStack {\n\treturn {\n\t\tnode: node,\n\t\tindex: 0,\n\t\t__prev: prev,\n\t}\n}\n\nconst ITERATE_KEYS = 0\nconst ITERATE_VALUES = 1\nconst ITERATE_ENTRIES = 2\n\ntype IterationType = typeof ITERATE_KEYS | typeof ITERATE_VALUES | typeof ITERATE_ENTRIES\n\nfunction iteratorValue<K, V>(\n\ttype: IterationType,\n\tk: K,\n\tv: V,\n\titeratorResult?: IteratorResult<any>\n) {\n\tconst value = type === ITERATE_KEYS ? k : type === ITERATE_VALUES ? v : [k, v]\n\tif (iteratorResult) {\n\t\titeratorResult.value = value\n\t} else {\n\t\titeratorResult = { value, done: false }\n\t}\n\treturn iteratorResult\n}\n\n/**\n * Creates a completed iterator result object indicating iteration is finished.\n * Used internally by map iterators to signal the end of iteration.\n *\n * @returns An IteratorResult object with done set to true and value as undefined\n * @public\n * @example\n * ```ts\n * // Used internally by iterators\n * const result = iteratorDone()\n * console.log(result) // { value: undefined, done: true }\n * ```\n */\nexport function iteratorDone() {\n\treturn { value: undefined, done: true }\n}\n\nfunction makeMap<K, V>(size: number, root?: MapNode<K, V>, ownerID?: OwnerID, hash?: number) {\n\tconst map = Object.create(ImmutableMap.prototype)\n\tmap.size = size\n\tmap._root = root\n\tmap.__ownerID = ownerID\n\tmap.__hash = hash\n\tmap.__altered = false\n\treturn map\n}\n\nlet EMPTY_MAP: ImmutableMap<unknown, unknown>\n/**\n * Returns a singleton empty ImmutableMap instance.\n * This function is optimized to return the same empty map instance for all calls,\n * saving memory when working with many empty maps.\n *\n * @returns An empty ImmutableMap instance\n * @public\n * @example\n * ```ts\n * // Get an empty map\n * const empty = emptyMap<string, number>()\n * console.log(empty.size) // 0\n *\n * // All empty maps are the same instance\n * const empty1 = emptyMap()\n * const empty2 = emptyMap()\n * console.log(empty1 === empty2) // true\n * ```\n */\nexport function emptyMap<K, V>(): ImmutableMap<K, V> {\n\treturn (EMPTY_MAP as any) || (EMPTY_MAP = makeMap(0))\n}\n\nfunction updateMap<K, V>(map: ImmutableMap<K, V>, k: K, v: V) {\n\tlet newRoot\n\tlet newSize\n\tif (!map._root) {\n\t\tif (v === NOT_SET) {\n\t\t\treturn map\n\t\t}\n\t\tnewSize = 1\n\t\tnewRoot = new ArrayMapNode(map.__ownerID, [[k, v]])\n\t} else {\n\t\tconst didChangeSize = MakeRef()\n\t\tconst didAlter = MakeRef()\n\t\tnewRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter)\n\t\tif (!didAlter.value) {\n\t\t\treturn map\n\t\t}\n\t\tnewSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0)\n\t}\n\tif (map.__ownerID) {\n\t\tmap.size = newSize\n\t\tmap._root = newRoot as any\n\t\tmap.__hash = undefined\n\t\tmap.__altered = true\n\t\treturn map\n\t}\n\treturn newRoot ? makeMap(newSize, newRoot) : emptyMap()\n}\n\nfunction updateNode<K, V>(\n\tnode: MapNode<K, V> | undefined,\n\townerID: OwnerID,\n\tshift: number,\n\tkeyHash: number | undefined,\n\tkey: K,\n\tvalue: V,\n\tdidChangeSize?: Ref,\n\tdidAlter?: Ref\n): MapNode<K, V> | undefined {\n\tif (!node) {\n\t\tif (value === NOT_SET) {\n\t\t\treturn node\n\t\t}\n\t\tSetRef(didAlter)\n\t\tSetRef(didChangeSize)\n\t\treturn new ValueNode(ownerID, keyHash, [key, value])\n\t}\n\treturn node.update(ownerID, shift, keyHash!, key, value, didChangeSize, didAlter) as any\n}\n\nfunction isLeafNode(node: MapNode<unknown, unknown>) {\n\treturn node.constructor === ValueNode || node.constructor === HashCollisionNode\n}\n\nfunction mergeIntoNode<K, V>(\n\tnode: any,\n\townerID: OwnerID,\n\tshift: number,\n\tkeyHash: number,\n\tentry: [K, V]\n): MapNode<K, V> {\n\tif (node.keyHash === keyHash) {\n\t\treturn new HashCollisionNode(ownerID, keyHash, [node.entry, entry])\n\t}\n\n\tconst idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK\n\tconst idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK\n\n\tlet newNode\n\tconst nodes =\n\t\tidx1 === idx2\n\t\t\t? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]\n\t\t\t: ((newNode = new ValueNode(ownerID, keyHash, entry)),\n\t\t\t\tidx1 < idx2 ? [node, newNode] : [newNode, node])\n\n\treturn new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes)\n}\n\nfunction createNodes<K, V>(ownerID: OwnerID, entries: [K, V][], key: K, value: V) {\n\tif (!ownerID) {\n\t\townerID = new OwnerID()\n\t}\n\tlet node: MapNode<K, V> = new ValueNode(ownerID, hash(key), [key, value])\n\tfor (let ii = 0; ii < entries.length; ii++) {\n\t\tconst entry = entries[ii]\n\t\tnode = node.update(ownerID, 0, undefined as any as number, entry[0], entry[1]) as any\n\t}\n\treturn node\n}\n\nfunction packNodes<K, V>(\n\townerID: OwnerID,\n\tnodes: MapNode<K, V>[],\n\tcount: number,\n\texcluding: number\n) {\n\tlet bitmap = 0\n\tlet packedII = 0\n\tconst packedNodes = new Array(count)\n\tfor (let ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {\n\t\tconst node = nodes[ii]\n\t\tif (node !== undefined && ii !== excluding) {\n\t\t\tbitmap |= bit\n\t\t\tpackedNodes[packedII++] = node\n\t\t}\n\t}\n\treturn new BitmapIndexedNode(ownerID, bitmap, packedNodes)\n}\n\nfunction expandNodes<K, V>(\n\townerID: OwnerID,\n\tnodes: MapNode<K, V>[],\n\tbitmap: number,\n\tincluding: number,\n\tnode: MapNode<K, V>\n): MapNode<K, V> {\n\tlet count = 0\n\tconst expandedNodes = new Array(SIZE)\n\tfor (let ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {\n\t\texpandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined\n\t}\n\texpandedNodes[including] = node\n\treturn new HashArrayMapNode(ownerID, count + 1, expandedNodes)\n}\n\nfunction popCount(x: number) {\n\tx -= (x >> 1) & 0x55555555\n\tx = (x & 0x33333333) + ((x >> 2) & 0x33333333)\n\tx = (x + (x >> 4)) & 0x0f0f0f0f\n\tx += x >> 8\n\tx += x >> 16\n\treturn x & 0x7f\n}\n\nfunction setAt<T>(array: T[], idx: number, val: T, canEdit: boolean): T[] {\n\tconst newArray = canEdit ? array : arrCopy(array)\n\tnewArray[idx] = val\n\treturn newArray\n}\n\nfunction spliceIn<T>(array: T[], idx: number, val: T, canEdit: boolean): T[] {\n\tconst newLen = array.length + 1\n\tif (canEdit && idx + 1 === newLen) {\n\t\tarray[idx] = val\n\t\treturn array\n\t}\n\tconst newArray = new Array<T>(newLen)\n\tlet after = 0\n\tfor (let ii = 0; ii < newLen; ii++) {\n\t\tif (ii === idx) {\n\t\t\tnewArray[ii] = val\n\t\t\tafter = -1\n\t\t} else {\n\t\t\tnewArray[ii] = array[ii + after]\n\t\t}\n\t}\n\treturn newArray\n}\n\nfunction spliceOut<T>(array: T[], idx: number, canEdit: boolean) {\n\tconst newLen = array.length - 1\n\tif (canEdit && idx === newLen) {\n\t\tarray.pop()\n\t\treturn array\n\t}\n\tconst newArray = new Array(newLen)\n\tlet after = 0\n\tfor (let ii = 0; ii < newLen; ii++) {\n\t\tif (ii === idx) {\n\t\t\tafter = 1\n\t\t}\n\t\tnewArray[ii] = array[ii + after]\n\t}\n\treturn newArray\n}\n\nconst MAX_ARRAY_MAP_SIZE = SIZE / 4\nconst MAX_BITMAP_INDEXED_SIZE = SIZE / 2\nconst MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,IAAI,KAAa;AACzB,SAAS,QAAQ,IAAK,aAAe,MAAM;AAC5C;AAEA,MAAM,iBAAiB,OAAO,UAAU;AAExC,SAAS,KAAK,GAAQ;AACrB,MAAI,KAAK,MAAM;AACd,WAAO,YAAY,CAAC;AAAA,EACrB;AAEA,MAAI,OAAO,EAAE,aAAa,YAAY;AAErC,WAAO,IAAI,EAAE,SAAS,CAAC,CAAC;AAAA,EACzB;AAEA,QAAM,IAAI,QAAQ,CAAC;AAEnB,MAAI,KAAK,MAAM;AACd,WAAO,YAAY,CAAC;AAAA,EACrB;AAEA,UAAQ,OAAO,GAAG;AAAA,IACjB,KAAK;AAIJ,aAAO,IAAI,aAAa;AAAA,IACzB,KAAK;AACJ,aAAO,WAAW,CAAC;AAAA,IACpB,KAAK;AACJ,aAAO,EAAE,SAAS,+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AAW;AAC5B,OAAM,KAAK,IAAK;AAChB,OAAK,IAAI,cAAgB,KAAK,IAAK;AACnC,MAAK,KAAK,KAAK,KAAM;AACrB,OAAK,KAAK;AACV,OAAK,KAAK;AACV,SAAO,IAAI;AACZ;AAEA,SAAS,MAAS,OAAY,KAAa,KAAQ,SAAuB;AACzE,QAAM,WAAW,UAAU,QAAQ,QAAQ,KAAK;AAChD,WAAS,GAAG,IAAI;AAChB,SAAO;AACR;AAEA,SAAS,SAAY,OAAY,KAAa,KAAQ,SAAuB;AAC5E,QAAM,SAAS,MAAM,SAAS;AAC9B,MAAI,WAAW,MAAM,MAAM,QAAQ;AAClC,UAAM,GAAG,IAAI;AACb,WAAO;AAAA,EACR;AACA,QAAM,WAAW,IAAI,MAAS,MAAM;AACpC,MAAI,QAAQ;AACZ,WAAS,KAAK,GAAG,KAAK,QAAQ,MAAM;AACnC,QAAI,OAAO,KAAK;AACf,eAAS,EAAE,IAAI;AACf,cAAQ;AAAA,IACT,OAAO;AACN,eAAS,EAAE,IAAI,MAAM,KAAK,KAAK;AAAA,IAChC;AAAA,EACD;AACA,SAAO;AACR;AAEA,SAAS,UAAa,OAAY,KAAa,SAAkB;AAChE,QAAM,SAAS,MAAM,SAAS;AAC9B,MAAI,WAAW,QAAQ,QAAQ;AAC9B,UAAM,IAAI;AACV,WAAO;AAAA,EACR;AACA,QAAM,WAAW,IAAI,MAAM,MAAM;AACjC,MAAI,QAAQ;AACZ,WAAS,KAAK,GAAG,KAAK,QAAQ,MAAM;AACnC,QAAI,OAAO,KAAK;AACf,cAAQ;AAAA,IACT;AACA,aAAS,EAAE,IAAI,MAAM,KAAK,KAAK;AAAA,EAChC;AACA,SAAO;AACR;AAEA,MAAM,qBAAqB,OAAO;AAClC,MAAM,0BAA0B,OAAO;AACvC,MAAM,0BAA0B,OAAO;",
4
+ "sourcesContent": ["/*!\n * This file was lovingly and delicately extracted from Immutable.js\n * MIT License: https://github.com/immutable-js/immutable-js/blob/main/LICENSE\n * Copyright (c) 2014-present, Lee Byron and other contributors.\n */\n\nfunction smi(i32: number) {\n\treturn ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff)\n}\n\nconst defaultValueOf = Object.prototype.valueOf\n\nfunction hash(o: any) {\n\tif (o == null) {\n\t\treturn hashNullish(o)\n\t}\n\n\tif (typeof o.hashCode === 'function') {\n\t\t// Drop any high bits from accidentally long hash codes.\n\t\treturn smi(o.hashCode(o))\n\t}\n\n\tconst v = valueOf(o)\n\n\tif (v == null) {\n\t\treturn hashNullish(v)\n\t}\n\n\tswitch (typeof v) {\n\t\tcase 'boolean':\n\t\t\t// The hash values for built-in constants are a 1 value for each 5-byte\n\t\t\t// shift region expect for the first, which encodes the value. This\n\t\t\t// reduces the odds of a hash collision for these common values.\n\t\t\treturn v ? 0x42108421 : 0x42108420\n\t\tcase 'number':\n\t\t\treturn hashNumber(v)\n\t\tcase 'string':\n\t\t\treturn v.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(v) : hashString(v)\n\t\tcase 'object':\n\t\tcase 'function':\n\t\t\treturn hashJSObj(v)\n\t\tcase 'symbol':\n\t\t\treturn hashSymbol(v)\n\t\tdefault:\n\t\t\tif (typeof v.toString === 'function') {\n\t\t\t\treturn hashString(v.toString())\n\t\t\t}\n\t\t\tthrow new Error('Value type ' + typeof v + ' cannot be hashed.')\n\t}\n}\n\nfunction hashNullish(nullish: null | undefined) {\n\treturn nullish === null ? 0x42108422 : /* undefined */ 0x42108423\n}\n\n// Compress arbitrarily large numbers into smi hashes.\nfunction hashNumber(n: number) {\n\tif (n !== n || n === Infinity) {\n\t\treturn 0\n\t}\n\tlet hash = n | 0\n\tif (hash !== n) {\n\t\thash ^= n * 0xffffffff\n\t}\n\twhile (n > 0xffffffff) {\n\t\tn /= 0xffffffff\n\t\thash ^= n\n\t}\n\treturn smi(hash)\n}\n\nfunction cachedHashString(string: string) {\n\tlet hashed = stringHashCache[string]\n\tif (hashed === undefined) {\n\t\thashed = hashString(string)\n\t\tif (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {\n\t\t\tSTRING_HASH_CACHE_SIZE = 0\n\t\t\tstringHashCache = {}\n\t\t}\n\t\tSTRING_HASH_CACHE_SIZE++\n\t\tstringHashCache[string] = hashed\n\t}\n\treturn hashed\n}\n\n// http://jsperf.com/hashing-strings\nfunction hashString(string: string) {\n\t// This is the hash from JVM\n\t// The hash code for a string is computed as\n\t// s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],\n\t// where s[i] is the ith character of the string and n is the length of\n\t// the string. We \"mod\" the result to make it between 0 (inclusive) and 2^31\n\t// (exclusive) by dropping high bits.\n\tlet hashed = 0\n\tfor (let ii = 0; ii < string.length; ii++) {\n\t\thashed = (31 * hashed + string.charCodeAt(ii)) | 0\n\t}\n\treturn smi(hashed)\n}\n\nfunction hashSymbol(sym: symbol) {\n\tlet hashed = symbolMap[sym]\n\tif (hashed !== undefined) {\n\t\treturn hashed\n\t}\n\n\thashed = nextHash()\n\n\tsymbolMap[sym] = hashed\n\n\treturn hashed\n}\n\nfunction hashJSObj(obj: object) {\n\tlet hashed = weakMap.get(obj)\n\tif (hashed !== undefined) {\n\t\treturn hashed\n\t}\n\n\thashed = nextHash()\n\n\tweakMap.set(obj, hashed)\n\n\treturn hashed\n}\n\nfunction valueOf(obj: any) {\n\treturn obj.valueOf !== defaultValueOf && typeof obj.valueOf === 'function'\n\t\t? obj.valueOf(obj)\n\t\t: obj\n}\n\nfunction nextHash() {\n\tconst nextHash = ++_objHashUID\n\tif (_objHashUID & 0x40000000) {\n\t\t_objHashUID = 0\n\t}\n\treturn nextHash\n}\n\n// If possible, use a WeakMap.\nconst weakMap = new WeakMap()\n\nconst symbolMap = Object.create(null)\n\nlet _objHashUID = 0\n\nconst STRING_HASH_CACHE_MIN_STRLEN = 16\nconst STRING_HASH_CACHE_MAX_SIZE = 255\nlet STRING_HASH_CACHE_SIZE = 0\nlet stringHashCache: Record<string, number> = {}\n\n// Constants describing the size of trie nodes.\nconst SHIFT = 5 // Resulted in best performance after ______?\nconst SIZE = 1 << SHIFT\nconst MASK = SIZE - 1\n\n// A consistent shared value representing \"not set\" which equals nothing other\n// than itself, and nothing that could be provided externally.\nconst NOT_SET = {}\n\ninterface Ref {\n\tvalue: boolean\n}\n\n// Boolean references, Rough equivalent of `bool &`.\nfunction MakeRef(): Ref {\n\treturn { value: false }\n}\n\nfunction SetRef(ref?: Ref): void {\n\tif (ref) {\n\t\tref.value = true\n\t}\n}\n\n// http://jsperf.com/copy-array-inline\nfunction arrCopy<I>(arr: Array<I>, offset?: number): Array<I> {\n\toffset = offset || 0\n\tconst len = Math.max(0, arr.length - offset)\n\tconst newArr: Array<I> = new Array(len)\n\tfor (let ii = 0; ii < len; ii++) {\n\t\t// We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design\n\t\tnewArr[ii] = arr[ii + offset]\n\t}\n\treturn newArr\n}\n\nconst is = Object.is\n\nclass OwnerID {}\n\n/**\n * A persistent immutable map implementation based on a Hash Array Mapped Trie (HAMT) data structure.\n * Provides efficient operations for creating, reading, updating, and deleting key-value pairs while\n * maintaining structural sharing to minimize memory usage and maximize performance.\n *\n * This implementation is extracted and adapted from Immutable.js, optimized for tldraw's store needs.\n * All operations return new instances rather than modifying existing ones, ensuring immutability.\n *\n * @public\n * @example\n * ```ts\n * // Create a new map\n * const map = new ImmutableMap([\n * ['key1', 'value1'],\n * ['key2', 'value2']\n * ])\n *\n * // Add or update values\n * const updated = map.set('key3', 'value3')\n *\n * // Get values\n * const value = map.get('key1') // 'value1'\n *\n * // Delete values\n * const smaller = map.delete('key1')\n * ```\n */\nexport class ImmutableMap<K, V> {\n\t// @pragma Construction\n\t// @ts-ignore\n\t_root: MapNode<K, V>\n\t// @ts-ignore\n\tsize: number\n\t// @ts-ignore\n\t__ownerID: OwnerID\n\t// @ts-ignore\n\t__hash: number | undefined\n\t// @ts-ignore\n\t__altered: boolean\n\n\t/**\n\t * Creates a new ImmutableMap instance.\n\t *\n\t * @param value - An iterable of key-value pairs to populate the map, or null/undefined for an empty map\n\t * @example\n\t * ```ts\n\t * // Create from array of pairs\n\t * const map1 = new ImmutableMap([['a', 1], ['b', 2]])\n\t *\n\t * // Create empty map\n\t * const map2 = new ImmutableMap()\n\t *\n\t * // Create from another map\n\t * const map3 = new ImmutableMap(map1)\n\t * ```\n\t */\n\tconstructor(value?: Iterable<[K, V]> | null | undefined) {\n\t\t// @ts-ignore\n\t\treturn value === undefined || value === null\n\t\t\t? emptyMap()\n\t\t\t: value instanceof ImmutableMap\n\t\t\t\t? value\n\t\t\t\t: emptyMap().withMutations((map) => {\n\t\t\t\t\t\tfor (const [k, v] of value) {\n\t\t\t\t\t\t\tmap.set(k, v)\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t}\n\n\t/**\n\t * Gets the value associated with the specified key.\n\t *\n\t * @param k - The key to look up\n\t * @returns The value associated with the key, or undefined if not found\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['key1', 'value1']])\n\t * console.log(map.get('key1')) // 'value1'\n\t * console.log(map.get('missing')) // undefined\n\t * ```\n\t */\n\tget(k: K): V | undefined\n\t/**\n\t * Gets the value associated with the specified key, with a fallback value.\n\t *\n\t * @param k - The key to look up\n\t * @param notSetValue - The value to return if the key is not found\n\t * @returns The value associated with the key, or the fallback value if not found\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['key1', 'value1']])\n\t * console.log(map.get('key1', 'default')) // 'value1'\n\t * console.log(map.get('missing', 'default')) // 'default'\n\t * ```\n\t */\n\tget(k: K, notSetValue?: V): V {\n\t\treturn this._root ? this._root.get(0, undefined as any, k, notSetValue)! : notSetValue!\n\t}\n\n\t/**\n\t * Returns a new ImmutableMap with the specified key-value pair added or updated.\n\t * If the key already exists, its value is replaced. Otherwise, a new entry is created.\n\t *\n\t * @param k - The key to set\n\t * @param v - The value to associate with the key\n\t * @returns A new ImmutableMap with the key-value pair set\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1]])\n\t * const updated = map.set('b', 2) // New map with both 'a' and 'b'\n\t * const replaced = map.set('a', 10) // New map with 'a' updated to 10\n\t * ```\n\t */\n\tset(k: K, v: V) {\n\t\treturn updateMap(this, k, v)\n\t}\n\n\t/**\n\t * Returns a new ImmutableMap with the specified key removed.\n\t * If the key doesn't exist, returns the same map instance.\n\t *\n\t * @param k - The key to remove\n\t * @returns A new ImmutableMap with the key removed, or the same instance if key not found\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * const smaller = map.delete('a') // New map with only 'b'\n\t * const same = map.delete('missing') // Returns original map\n\t * ```\n\t */\n\tdelete(k: K) {\n\t\treturn updateMap(this, k, NOT_SET as any)\n\t}\n\n\t/**\n\t * Returns a new ImmutableMap with all specified keys removed.\n\t * This is more efficient than calling delete() multiple times.\n\t *\n\t * @param keys - An iterable of keys to remove\n\t * @returns A new ImmutableMap with all specified keys removed\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2], ['c', 3]])\n\t * const smaller = map.deleteAll(['a', 'c']) // New map with only 'b'\n\t * ```\n\t */\n\tdeleteAll(keys: Iterable<K>) {\n\t\treturn this.withMutations((map) => {\n\t\t\tfor (const key of keys) {\n\t\t\t\tmap.delete(key)\n\t\t\t}\n\t\t})\n\t}\n\n\t__ensureOwner(ownerID: OwnerID) {\n\t\tif (ownerID === this.__ownerID) {\n\t\t\treturn this\n\t\t}\n\t\tif (!ownerID) {\n\t\t\tif (this.size === 0) {\n\t\t\t\treturn emptyMap()\n\t\t\t}\n\t\t\tthis.__ownerID = ownerID\n\t\t\tthis.__altered = false\n\t\t\treturn this\n\t\t}\n\t\treturn makeMap(this.size, this._root, ownerID, this.__hash)\n\t}\n\n\t/**\n\t * Applies multiple mutations efficiently by creating a mutable copy,\n\t * applying all changes, then returning an immutable result.\n\t * This is more efficient than chaining multiple set/delete operations.\n\t *\n\t * @param fn - Function that receives a mutable copy and applies changes\n\t * @returns A new ImmutableMap with all mutations applied, or the same instance if no changes\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1]])\n\t * const updated = map.withMutations(mutable => {\n\t * mutable.set('b', 2)\n\t * mutable.set('c', 3)\n\t * mutable.delete('a')\n\t * }) // Efficiently applies all changes at once\n\t * ```\n\t */\n\twithMutations(fn: (mutable: this) => void): this {\n\t\tconst mutable = this.asMutable()\n\t\tfn(mutable)\n\t\treturn mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this\n\t}\n\n\t/**\n\t * Checks if this map instance has been altered during a mutation operation.\n\t * This is used internally to optimize mutations.\n\t *\n\t * @returns True if the map was altered, false otherwise\n\t * @internal\n\t */\n\twasAltered() {\n\t\treturn this.__altered\n\t}\n\n\t/**\n\t * Returns a mutable copy of this map that can be efficiently modified.\n\t * Multiple changes to the mutable copy are batched together.\n\t *\n\t * @returns A mutable copy of this map\n\t * @internal\n\t */\n\tasMutable() {\n\t\treturn this.__ownerID ? this : this.__ensureOwner(new OwnerID())\n\t}\n\n\t/**\n\t * Makes the map iterable, yielding key-value pairs.\n\t *\n\t * @returns An iterator over [key, value] pairs\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * for (const [key, value] of map) {\n\t * console.log(key, value) // 'a' 1, then 'b' 2\n\t * }\n\t * ```\n\t */\n\t[Symbol.iterator](): Iterator<[K, V]> {\n\t\treturn this.entries()[Symbol.iterator]()\n\t}\n\n\t/**\n\t * Returns an iterable of key-value pairs.\n\t *\n\t * @returns An iterable over [key, value] pairs\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * const entries = Array.from(map.entries()) // [['a', 1], ['b', 2]]\n\t * ```\n\t */\n\tentries(): Iterable<[K, V]> {\n\t\treturn new MapIterator(this, ITERATE_ENTRIES, false)\n\t}\n\n\t/**\n\t * Returns an iterable of keys.\n\t *\n\t * @returns An iterable over keys\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * const keys = Array.from(map.keys()) // ['a', 'b']\n\t * ```\n\t */\n\tkeys(): Iterable<K> {\n\t\treturn new MapIterator(this, ITERATE_KEYS, false)\n\t}\n\n\t/**\n\t * Returns an iterable of values.\n\t *\n\t * @returns An iterable over values\n\t * @example\n\t * ```ts\n\t * const map = new ImmutableMap([['a', 1], ['b', 2]])\n\t * const values = Array.from(map.values()) // [1, 2]\n\t * ```\n\t */\n\tvalues(): Iterable<V> {\n\t\treturn new MapIterator(this, ITERATE_VALUES, false)\n\t}\n}\n\ntype MapNode<K, V> =\n\t| ArrayMapNode<K, V>\n\t| BitmapIndexedNode<K, V>\n\t| HashArrayMapNode<K, V>\n\t| HashCollisionNode<K, V>\n\t| ValueNode<K, V>\n\n// #pragma Trie Nodes\n\nclass ArrayMapNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic entries: Array<[K, V]>\n\t) {}\n\n\tget(_shift: unknown, _keyHash: unknown, key: K, notSetValue?: V) {\n\t\tconst entries = this.entries\n\t\tfor (let ii = 0, len = entries.length; ii < len; ii++) {\n\t\t\tif (is(key, entries[ii][0])) {\n\t\t\t\treturn entries[ii][1]\n\t\t\t}\n\t\t}\n\t\treturn notSetValue\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\t_shift: unknown,\n\t\t_keyHash: unknown,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t): MapNode<K, V> | undefined {\n\t\tconst removed = value === NOT_SET\n\n\t\tconst entries = this.entries\n\t\tlet idx = 0\n\t\tconst len = entries.length\n\t\tfor (; idx < len; idx++) {\n\t\t\tif (is(key, entries[idx][0])) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tconst exists = idx < len\n\n\t\tif (exists ? entries[idx][1] === value : removed) {\n\t\t\treturn this\n\t\t}\n\n\t\tSetRef(didAlter)\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here\n\t\t;(removed || !exists) && SetRef(didChangeSize)\n\n\t\tif (removed && entries.length === 1) {\n\t\t\treturn // undefined\n\t\t}\n\n\t\tif (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {\n\t\t\treturn createNodes(ownerID, entries, key, value)\n\t\t}\n\n\t\tconst isEditable = ownerID && ownerID === this.ownerID\n\t\tconst newEntries = isEditable ? entries : arrCopy(entries)\n\n\t\tif (exists) {\n\t\t\tif (removed) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here\n\t\t\t\tidx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop()!)\n\t\t\t} else {\n\t\t\t\tnewEntries[idx] = [key, value]\n\t\t\t}\n\t\t} else {\n\t\t\tnewEntries.push([key, value])\n\t\t}\n\n\t\tif (isEditable) {\n\t\t\tthis.entries = newEntries\n\t\t\treturn this\n\t\t}\n\n\t\treturn new ArrayMapNode(ownerID, newEntries)\n\t}\n}\n\nclass BitmapIndexedNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic bitmap: number,\n\t\tpublic nodes: Array<MapNode<K, V>>\n\t) {}\n\n\tget(shift: number, keyHash: number, key: K, notSetValue?: V): V | undefined {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\t\tconst bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK)\n\t\tconst bitmap = this.bitmap\n\t\treturn (bitmap & bit) === 0\n\t\t\t? notSetValue\n\t\t\t: this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue)\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\tshift: number,\n\t\tkeyHash: number,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t): MapNode<K, V> | undefined {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\t\tconst keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK\n\t\tconst bit = 1 << keyHashFrag\n\t\tconst bitmap = this.bitmap\n\t\tconst exists = (bitmap & bit) !== 0\n\n\t\tif (!exists && value === NOT_SET) {\n\t\t\treturn this\n\t\t}\n\n\t\tconst idx = popCount(bitmap & (bit - 1))\n\t\tconst nodes = this.nodes\n\t\tconst node = exists ? nodes[idx] : undefined\n\t\tconst newNode = updateNode(\n\t\t\tnode,\n\t\t\townerID,\n\t\t\tshift + SHIFT,\n\t\t\tkeyHash,\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\tdidChangeSize,\n\t\t\tdidAlter\n\t\t)\n\n\t\tif (newNode === node) {\n\t\t\treturn this\n\t\t}\n\n\t\tif (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {\n\t\t\treturn expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode)\n\t\t}\n\n\t\tif (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {\n\t\t\treturn nodes[idx ^ 1]\n\t\t}\n\n\t\tif (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {\n\t\t\treturn newNode\n\t\t}\n\n\t\tconst isEditable = ownerID && ownerID === this.ownerID\n\t\tconst newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit\n\t\tconst newNodes = exists\n\t\t\t? newNode\n\t\t\t\t? setAt(nodes, idx, newNode, isEditable)\n\t\t\t\t: spliceOut(nodes, idx, isEditable)\n\t\t\t: spliceIn(nodes, idx, newNode, isEditable)\n\n\t\tif (isEditable) {\n\t\t\tthis.bitmap = newBitmap\n\t\t\tthis.nodes = newNodes\n\t\t\treturn this\n\t\t}\n\n\t\treturn new BitmapIndexedNode(ownerID, newBitmap, newNodes)\n\t}\n}\n\nclass HashArrayMapNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic count: number,\n\t\tpublic nodes: Array<MapNode<K, V>>\n\t) {}\n\n\tget(shift: number, keyHash: number, key: K, notSetValue?: V): V | undefined {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\t\tconst idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK\n\t\tconst node = this.nodes[idx]\n\t\treturn node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\tshift: number,\n\t\tkeyHash: number,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t) {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\t\tconst idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK\n\t\tconst removed = value === NOT_SET\n\t\tconst nodes = this.nodes\n\t\tconst node = nodes[idx]\n\n\t\tif (removed && !node) {\n\t\t\treturn this\n\t\t}\n\n\t\tconst newNode = updateNode(\n\t\t\tnode,\n\t\t\townerID,\n\t\t\tshift + SHIFT,\n\t\t\tkeyHash,\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\tdidChangeSize,\n\t\t\tdidAlter\n\t\t)\n\t\tif (newNode === node) {\n\t\t\treturn this\n\t\t}\n\n\t\tlet newCount = this.count\n\t\tif (!node) {\n\t\t\tnewCount++\n\t\t} else if (!newNode) {\n\t\t\tnewCount--\n\t\t\tif (newCount < MIN_HASH_ARRAY_MAP_SIZE) {\n\t\t\t\treturn packNodes(ownerID, nodes, newCount, idx)\n\t\t\t}\n\t\t}\n\n\t\tconst isEditable = ownerID && ownerID === this.ownerID\n\t\tconst newNodes = setAt(nodes, idx, newNode!, isEditable)\n\n\t\tif (isEditable) {\n\t\t\tthis.count = newCount\n\t\t\tthis.nodes = newNodes\n\t\t\treturn this\n\t\t}\n\n\t\treturn new HashArrayMapNode(ownerID, newCount, newNodes)\n\t}\n}\n\nclass HashCollisionNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic keyHash: number,\n\t\tpublic entries: Array<[K, V]>\n\t) {}\n\n\tget(shift: number, keyHash: number, key: K, notSetValue?: V) {\n\t\tconst entries = this.entries\n\t\tfor (let ii = 0, len = entries.length; ii < len; ii++) {\n\t\t\tif (is(key, entries[ii][0])) {\n\t\t\t\treturn entries[ii][1]\n\t\t\t}\n\t\t}\n\t\treturn notSetValue\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\tshift: number,\n\t\tkeyHash: number,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t): MapNode<K, V> {\n\t\tif (keyHash === undefined) {\n\t\t\tkeyHash = hash(key)\n\t\t}\n\n\t\tconst removed = value === NOT_SET\n\n\t\tif (keyHash !== this.keyHash) {\n\t\t\tif (removed) {\n\t\t\t\treturn this\n\t\t\t}\n\t\t\tSetRef(didAlter)\n\t\t\tSetRef(didChangeSize)\n\t\t\treturn mergeIntoNode(this, ownerID, shift, keyHash, [key, value])\n\t\t}\n\n\t\tconst entries = this.entries\n\t\tlet idx = 0\n\t\tconst len = entries.length\n\t\tfor (; idx < len; idx++) {\n\t\t\tif (is(key, entries[idx][0])) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tconst exists = idx < len\n\n\t\tif (exists ? entries[idx][1] === value : removed) {\n\t\t\treturn this\n\t\t}\n\n\t\tSetRef(didAlter)\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here\n\t\t;(removed || !exists) && SetRef(didChangeSize)\n\n\t\tif (removed && len === 2) {\n\t\t\treturn new ValueNode(ownerID, this.keyHash, entries[idx ^ 1])\n\t\t}\n\n\t\tconst isEditable = ownerID && ownerID === this.ownerID\n\t\tconst newEntries = isEditable ? entries : arrCopy(entries)\n\n\t\tif (exists) {\n\t\t\tif (removed) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here\n\t\t\t\tidx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop()!)\n\t\t\t} else {\n\t\t\t\tnewEntries[idx] = [key, value]\n\t\t\t}\n\t\t} else {\n\t\t\tnewEntries.push([key, value])\n\t\t}\n\n\t\tif (isEditable) {\n\t\t\tthis.entries = newEntries\n\t\t\treturn this\n\t\t}\n\n\t\treturn new HashCollisionNode(ownerID, this.keyHash, newEntries)\n\t}\n}\n\nclass ValueNode<K, V> {\n\tconstructor(\n\t\tpublic ownerID: OwnerID,\n\t\tpublic keyHash: number | undefined,\n\t\tpublic entry: [K, V]\n\t) {}\n\n\tget(shift: number, keyHash: number, key: K, notSetValue?: V) {\n\t\treturn is(key, this.entry[0]) ? this.entry[1] : notSetValue\n\t}\n\n\tupdate(\n\t\townerID: OwnerID,\n\t\tshift: number,\n\t\tkeyHash: number | undefined,\n\t\tkey: K,\n\t\tvalue: V,\n\t\tdidChangeSize?: Ref,\n\t\tdidAlter?: Ref\n\t) {\n\t\tconst removed = value === NOT_SET\n\t\tconst keyMatch = is(key, this.entry[0])\n\t\tif (keyMatch ? value === this.entry[1] : removed) {\n\t\t\treturn this\n\t\t}\n\n\t\tSetRef(didAlter)\n\n\t\tif (removed) {\n\t\t\tSetRef(didChangeSize)\n\t\t\treturn // undefined\n\t\t}\n\n\t\tif (keyMatch) {\n\t\t\tif (ownerID && ownerID === this.ownerID) {\n\t\t\t\tthis.entry[1] = value\n\t\t\t\treturn this\n\t\t\t}\n\t\t\treturn new ValueNode(ownerID, this.keyHash, [key, value])\n\t\t}\n\n\t\tSetRef(didChangeSize)\n\t\treturn mergeIntoNode(this, ownerID, shift, hash(key), [key, value])\n\t}\n}\n\n// #pragma Iterators\n\nclass MapIterator<K, V> implements Iterator<any>, Iterable<any> {\n\t_stack\n\n\tconstructor(\n\t\tmap: ImmutableMap<K, V>,\n\t\tpublic _type: IterationType,\n\t\tpublic _reverse: boolean\n\t) {\n\t\tthis._stack = map._root && mapIteratorFrame<K, V>(map._root)\n\t}\n\n\t[Symbol.iterator](): Iterator<any> {\n\t\treturn this\n\t}\n\n\tnext() {\n\t\tconst type = this._type\n\t\tlet stack = this._stack\n\t\twhile (stack) {\n\t\t\tconst node = stack.node as any\n\t\t\tconst index = stack.index++\n\t\t\tlet maxIndex\n\t\t\tif (node.entry) {\n\t\t\t\tif (index === 0) {\n\t\t\t\t\treturn mapIteratorValue(type, node.entry)\n\t\t\t\t}\n\t\t\t} else if ('entries' in node && node.entries) {\n\t\t\t\tmaxIndex = node.entries.length - 1\n\t\t\t\tif (index <= maxIndex) {\n\t\t\t\t\treturn mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index])\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmaxIndex = node.nodes.length - 1\n\t\t\t\tif (index <= maxIndex) {\n\t\t\t\t\tconst subNode = node.nodes[this._reverse ? maxIndex - index : index]\n\t\t\t\t\tif (subNode) {\n\t\t\t\t\t\tif (subNode.entry) {\n\t\t\t\t\t\t\treturn mapIteratorValue(type, subNode.entry)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstack = this._stack = mapIteratorFrame(subNode, stack)\n\t\t\t\t\t}\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\tstack = this._stack = this._stack.__prev!\n\t\t}\n\t\treturn iteratorDone() as any\n\t}\n}\n\nfunction mapIteratorValue<K, V>(type: IterationType, entry: [K, V]) {\n\treturn iteratorValue(type, entry[0], entry[1])\n}\n\ninterface IStack {\n\tnode: MapNode<unknown, unknown>\n\tindex: number\n\t__prev?: IStack\n}\n\nfunction mapIteratorFrame<K, V>(\n\tnode: MapNode<K, V>,\n\tprev?: { node: MapNode<K, V>; index: number; __prev?: IStack }\n): IStack {\n\treturn {\n\t\tnode: node,\n\t\tindex: 0,\n\t\t__prev: prev,\n\t}\n}\n\nconst ITERATE_KEYS = 0\nconst ITERATE_VALUES = 1\nconst ITERATE_ENTRIES = 2\n\ntype IterationType = typeof ITERATE_KEYS | typeof ITERATE_VALUES | typeof ITERATE_ENTRIES\n\nfunction iteratorValue<K, V>(\n\ttype: IterationType,\n\tk: K,\n\tv: V,\n\titeratorResult?: IteratorResult<any>\n) {\n\tconst value = type === ITERATE_KEYS ? k : type === ITERATE_VALUES ? v : [k, v]\n\t// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here\n\titeratorResult\n\t\t? (iteratorResult.value = value)\n\t\t: (iteratorResult = {\n\t\t\t\tvalue: value,\n\t\t\t\tdone: false,\n\t\t\t})\n\treturn iteratorResult\n}\n\n/**\n * Creates a completed iterator result object indicating iteration is finished.\n * Used internally by map iterators to signal the end of iteration.\n *\n * @returns An IteratorResult object with done set to true and value as undefined\n * @public\n * @example\n * ```ts\n * // Used internally by iterators\n * const result = iteratorDone()\n * console.log(result) // { value: undefined, done: true }\n * ```\n */\nexport function iteratorDone() {\n\treturn { value: undefined, done: true }\n}\n\nfunction makeMap<K, V>(size: number, root?: MapNode<K, V>, ownerID?: OwnerID, hash?: number) {\n\tconst map = Object.create(ImmutableMap.prototype)\n\tmap.size = size\n\tmap._root = root\n\tmap.__ownerID = ownerID\n\tmap.__hash = hash\n\tmap.__altered = false\n\treturn map\n}\n\nlet EMPTY_MAP: ImmutableMap<unknown, unknown>\n/**\n * Returns a singleton empty ImmutableMap instance.\n * This function is optimized to return the same empty map instance for all calls,\n * saving memory when working with many empty maps.\n *\n * @returns An empty ImmutableMap instance\n * @public\n * @example\n * ```ts\n * // Get an empty map\n * const empty = emptyMap<string, number>()\n * console.log(empty.size) // 0\n *\n * // All empty maps are the same instance\n * const empty1 = emptyMap()\n * const empty2 = emptyMap()\n * console.log(empty1 === empty2) // true\n * ```\n */\nexport function emptyMap<K, V>(): ImmutableMap<K, V> {\n\treturn (EMPTY_MAP as any) || (EMPTY_MAP = makeMap(0))\n}\n\nfunction updateMap<K, V>(map: ImmutableMap<K, V>, k: K, v: V) {\n\tlet newRoot\n\tlet newSize\n\tif (!map._root) {\n\t\tif (v === NOT_SET) {\n\t\t\treturn map\n\t\t}\n\t\tnewSize = 1\n\t\tnewRoot = new ArrayMapNode(map.__ownerID, [[k, v]])\n\t} else {\n\t\tconst didChangeSize = MakeRef()\n\t\tconst didAlter = MakeRef()\n\t\tnewRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter)\n\t\tif (!didAlter.value) {\n\t\t\treturn map\n\t\t}\n\t\tnewSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0)\n\t}\n\tif (map.__ownerID) {\n\t\tmap.size = newSize\n\t\tmap._root = newRoot as any\n\t\tmap.__hash = undefined\n\t\tmap.__altered = true\n\t\treturn map\n\t}\n\treturn newRoot ? makeMap(newSize, newRoot) : emptyMap()\n}\n\nfunction updateNode<K, V>(\n\tnode: MapNode<K, V> | undefined,\n\townerID: OwnerID,\n\tshift: number,\n\tkeyHash: number | undefined,\n\tkey: K,\n\tvalue: V,\n\tdidChangeSize?: Ref,\n\tdidAlter?: Ref\n): MapNode<K, V> | undefined {\n\tif (!node) {\n\t\tif (value === NOT_SET) {\n\t\t\treturn node\n\t\t}\n\t\tSetRef(didAlter)\n\t\tSetRef(didChangeSize)\n\t\treturn new ValueNode(ownerID, keyHash, [key, value])\n\t}\n\treturn node.update(ownerID, shift, keyHash!, key, value, didChangeSize, didAlter) as any\n}\n\nfunction isLeafNode(node: MapNode<unknown, unknown>) {\n\treturn node.constructor === ValueNode || node.constructor === HashCollisionNode\n}\n\nfunction mergeIntoNode<K, V>(\n\tnode: any,\n\townerID: OwnerID,\n\tshift: number,\n\tkeyHash: number,\n\tentry: [K, V]\n): MapNode<K, V> {\n\tif (node.keyHash === keyHash) {\n\t\treturn new HashCollisionNode(ownerID, keyHash, [node.entry, entry])\n\t}\n\n\tconst idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK\n\tconst idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK\n\n\tlet newNode\n\tconst nodes =\n\t\tidx1 === idx2\n\t\t\t? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]\n\t\t\t: ((newNode = new ValueNode(ownerID, keyHash, entry)),\n\t\t\t\tidx1 < idx2 ? [node, newNode] : [newNode, node])\n\n\treturn new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes)\n}\n\nfunction createNodes<K, V>(ownerID: OwnerID, entries: [K, V][], key: K, value: V) {\n\tif (!ownerID) {\n\t\townerID = new OwnerID()\n\t}\n\tlet node: MapNode<K, V> = new ValueNode(ownerID, hash(key), [key, value])\n\tfor (let ii = 0; ii < entries.length; ii++) {\n\t\tconst entry = entries[ii]\n\t\tnode = node.update(ownerID, 0, undefined as any as number, entry[0], entry[1]) as any\n\t}\n\treturn node\n}\n\nfunction packNodes<K, V>(\n\townerID: OwnerID,\n\tnodes: MapNode<K, V>[],\n\tcount: number,\n\texcluding: number\n) {\n\tlet bitmap = 0\n\tlet packedII = 0\n\tconst packedNodes = new Array(count)\n\tfor (let ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {\n\t\tconst node = nodes[ii]\n\t\tif (node !== undefined && ii !== excluding) {\n\t\t\tbitmap |= bit\n\t\t\tpackedNodes[packedII++] = node\n\t\t}\n\t}\n\treturn new BitmapIndexedNode(ownerID, bitmap, packedNodes)\n}\n\nfunction expandNodes<K, V>(\n\townerID: OwnerID,\n\tnodes: MapNode<K, V>[],\n\tbitmap: number,\n\tincluding: number,\n\tnode: MapNode<K, V>\n): MapNode<K, V> {\n\tlet count = 0\n\tconst expandedNodes = new Array(SIZE)\n\tfor (let ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {\n\t\texpandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined\n\t}\n\texpandedNodes[including] = node\n\treturn new HashArrayMapNode(ownerID, count + 1, expandedNodes)\n}\n\nfunction popCount(x: number) {\n\tx -= (x >> 1) & 0x55555555\n\tx = (x & 0x33333333) + ((x >> 2) & 0x33333333)\n\tx = (x + (x >> 4)) & 0x0f0f0f0f\n\tx += x >> 8\n\tx += x >> 16\n\treturn x & 0x7f\n}\n\nfunction setAt<T>(array: T[], idx: number, val: T, canEdit: boolean): T[] {\n\tconst newArray = canEdit ? array : arrCopy(array)\n\tnewArray[idx] = val\n\treturn newArray\n}\n\nfunction spliceIn<T>(array: T[], idx: number, val: T, canEdit: boolean): T[] {\n\tconst newLen = array.length + 1\n\tif (canEdit && idx + 1 === newLen) {\n\t\tarray[idx] = val\n\t\treturn array\n\t}\n\tconst newArray = new Array<T>(newLen)\n\tlet after = 0\n\tfor (let ii = 0; ii < newLen; ii++) {\n\t\tif (ii === idx) {\n\t\t\tnewArray[ii] = val\n\t\t\tafter = -1\n\t\t} else {\n\t\t\tnewArray[ii] = array[ii + after]\n\t\t}\n\t}\n\treturn newArray\n}\n\nfunction spliceOut<T>(array: T[], idx: number, canEdit: boolean) {\n\tconst newLen = array.length - 1\n\tif (canEdit && idx === newLen) {\n\t\tarray.pop()\n\t\treturn array\n\t}\n\tconst newArray = new Array(newLen)\n\tlet after = 0\n\tfor (let ii = 0; ii < newLen; ii++) {\n\t\tif (ii === idx) {\n\t\t\tafter = 1\n\t\t}\n\t\tnewArray[ii] = array[ii + after]\n\t}\n\treturn newArray\n}\n\nconst MAX_ARRAY_MAP_SIZE = SIZE / 4\nconst MAX_BITMAP_INDEXED_SIZE = SIZE / 2\nconst MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,IAAI,KAAa;AACzB,SAAS,QAAQ,IAAK,aAAe,MAAM;AAC5C;AAEA,MAAM,iBAAiB,OAAO,UAAU;AAExC,SAAS,KAAK,GAAQ;AACrB,MAAI,KAAK,MAAM;AACd,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;AAC9B,UAAM,IAAI;AACV,WAAO;AAAA,EACR;AACA,QAAM,WAAW,IAAI,MAAM,MAAM;AACjC,MAAI,QAAQ;AACZ,WAAS,KAAK,GAAG,KAAK,QAAQ,MAAM;AACnC,QAAI,OAAO,KAAK;AACf,cAAQ;AAAA,IACT;AACA,aAAS,EAAE,IAAI,MAAM,KAAK,KAAK;AAAA,EAChC;AACA,SAAO;AACR;AAEA,MAAM,qBAAqB,OAAO;AAClC,MAAM,0BAA0B,OAAO;AACvC,MAAM,0BAA0B,OAAO;",
6
6
  "names": ["hash", "nextHash"]
7
7
  }
@@ -23,7 +23,6 @@ __export(StoreSchema_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(StoreSchema_exports);
25
25
  var import_utils = require("@tldraw/utils");
26
- var import_devFreeze = require("./devFreeze");
27
26
  var import_migrate = require("./migrate");
28
27
  function upgradeSchema(schema) {
29
28
  if (schema.schemaVersion > 2 || schema.schemaVersion < 1) return import_utils.Result.err("Bad schema version");
@@ -265,14 +264,14 @@ class StoreSchema {
265
264
  if (migrationsToApply.length === 0) {
266
265
  return { type: "success", value: record };
267
266
  }
268
- if (!migrationsToApply.every((m) => m.scope === "record")) {
267
+ if (migrationsToApply.some((m) => m.scope === "store")) {
269
268
  return {
270
269
  type: "error",
271
270
  reason: direction === "down" ? import_migrate.MigrationFailureReason.TargetVersionTooOld : import_migrate.MigrationFailureReason.TargetVersionTooNew
272
271
  };
273
272
  }
274
273
  if (direction === "down") {
275
- if (!migrationsToApply.every((m) => m.scope === "record" && m.down)) {
274
+ if (!migrationsToApply.every((m) => m.down)) {
276
275
  return {
277
276
  type: "error",
278
277
  reason: import_migrate.MigrationFailureReason.TargetVersionTooOld
@@ -286,9 +285,6 @@ class StoreSchema {
286
285
  if (migration.scope === "store") throw new Error(
287
286
  /* won't happen, just for TS */
288
287
  );
289
- if (migration.scope === "storage") throw new Error(
290
- /* won't happen, just for TS */
291
- );
292
288
  const shouldApply = migration.filter ? migration.filter(record) : true;
293
289
  if (!shouldApply) continue;
294
290
  const result = migration[direction](record);
@@ -302,57 +298,6 @@ class StoreSchema {
302
298
  }
303
299
  return { type: "success", value: record };
304
300
  }
305
- migrateStorage(storage) {
306
- const schema = storage.getSchema();
307
- (0, import_utils.assert)(schema, "Schema is missing.");
308
- const migrations = this.getMigrationsSince(schema);
309
- if (!migrations.ok) {
310
- console.error("Error migrating store", migrations.error);
311
- throw new Error(migrations.error);
312
- }
313
- const migrationsToApply = migrations.value;
314
- if (migrationsToApply.length === 0) {
315
- return;
316
- }
317
- storage.setSchema(this.serialize());
318
- for (const migration of migrationsToApply) {
319
- if (migration.scope === "record") {
320
- for (const [id, state] of storage.entries()) {
321
- const shouldApply = migration.filter ? migration.filter(state) : true;
322
- if (!shouldApply) continue;
323
- const record = (0, import_utils.structuredClone)(state);
324
- const result = migration.up(record) ?? record;
325
- if (!(0, import_utils.isEqual)(result, state)) {
326
- storage.set(id, result);
327
- }
328
- }
329
- } else if (migration.scope === "store") {
330
- const prevStore = Object.fromEntries(storage.entries());
331
- let nextStore = (0, import_utils.structuredClone)(prevStore);
332
- nextStore = migration.up(nextStore) ?? nextStore;
333
- for (const [id, state] of Object.entries(nextStore)) {
334
- if (!state) continue;
335
- if (!(0, import_utils.isEqual)(state, prevStore[id])) {
336
- storage.set(id, state);
337
- }
338
- }
339
- for (const id of Object.keys(prevStore)) {
340
- if (!nextStore[id]) {
341
- storage.delete(id);
342
- }
343
- }
344
- } else if (migration.scope === "storage") {
345
- migration.up(storage);
346
- } else {
347
- (0, import_utils.exhaustiveSwitchError)(migration);
348
- }
349
- }
350
- for (const [id, state] of storage.entries()) {
351
- if (this.getType(state.typeName).scope !== "document") {
352
- storage.delete(id);
353
- }
354
- }
355
- }
356
301
  /**
357
302
  * Migrates an entire store snapshot to match the current schema version.
358
303
  *
@@ -385,6 +330,7 @@ class StoreSchema {
385
330
  * @public
386
331
  */
387
332
  migrateStoreSnapshot(snapshot, opts) {
333
+ let { store } = snapshot;
388
334
  const migrations = this.getMigrationsSince(snapshot.schema);
389
335
  if (!migrations.ok) {
390
336
  console.error("Error migrating store", migrations.error);
@@ -392,38 +338,36 @@ class StoreSchema {
392
338
  }
393
339
  const migrationsToApply = migrations.value;
394
340
  if (migrationsToApply.length === 0) {
395
- return { type: "success", value: snapshot.store };
341
+ return { type: "success", value: store };
342
+ }
343
+ if (!opts?.mutateInputStore) {
344
+ store = (0, import_utils.structuredClone)(store);
396
345
  }
397
- const store = Object.assign(
398
- new Map((0, import_utils.objectMapEntries)(snapshot.store).map(import_devFreeze.devFreeze)),
399
- {
400
- getSchema: () => snapshot.schema,
401
- setSchema: (_) => {
402
- }
403
- }
404
- );
405
346
  try {
406
- this.migrateStorage(store);
407
- if (opts?.mutateInputStore) {
408
- for (const [id, record] of store.entries()) {
409
- snapshot.store[id] = record;
410
- }
411
- for (const id of Object.keys(snapshot.store)) {
412
- if (!store.has(id)) {
413
- delete snapshot.store[id];
347
+ for (const migration of migrationsToApply) {
348
+ if (migration.scope === "record") {
349
+ for (const [id, record] of Object.entries(store)) {
350
+ const shouldApply = migration.filter ? migration.filter(record) : true;
351
+ if (!shouldApply) continue;
352
+ const result = migration.up(record);
353
+ if (result) {
354
+ store[id] = result;
355
+ }
356
+ }
357
+ } else if (migration.scope === "store") {
358
+ const result = migration.up(store);
359
+ if (result) {
360
+ store = result;
414
361
  }
362
+ } else {
363
+ (0, import_utils.exhaustiveSwitchError)(migration);
415
364
  }
416
- return { type: "success", value: snapshot.store };
417
- } else {
418
- return {
419
- type: "success",
420
- value: Object.fromEntries(store.entries())
421
- };
422
365
  }
423
366
  } catch (e) {
424
367
  console.error("Error migrating store", e);
425
368
  return { type: "error", reason: import_migrate.MigrationFailureReason.MigrationError };
426
369
  }
370
+ return { type: "success", value: store };
427
371
  }
428
372
  /**
429
373
  * Creates an integrity checker function for the given store.