@tldraw/editor 3.14.0-canary.ff61ab6deaa2 → 3.14.0-internal.eada756f6aa0

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 (103) hide show
  1. package/dist-cjs/index.d.ts +166 -59
  2. package/dist-cjs/index.js +4 -3
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/config/TLSessionStateSnapshot.js +1 -12
  5. package/dist-cjs/lib/config/TLSessionStateSnapshot.js.map +3 -3
  6. package/dist-cjs/lib/editor/Editor.js +113 -45
  7. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  8. package/dist-cjs/lib/editor/bindings/BindingUtil.js.map +2 -2
  9. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +1 -2
  10. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
  11. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +3 -1
  12. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
  13. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +73 -42
  14. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  15. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +0 -10
  16. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  17. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -1
  18. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +1 -1
  19. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +10 -6
  20. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +3 -3
  21. package/dist-cjs/lib/editor/tools/StateNode.js +3 -3
  22. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  23. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  24. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  25. package/dist-cjs/lib/hooks/useCanvasEvents.js +1 -2
  26. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  27. package/dist-cjs/lib/primitives/Box.js +0 -6
  28. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  29. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +6 -2
  30. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  31. package/dist-cjs/lib/utils/areShapesContentEqual.js +1 -1
  32. package/dist-cjs/lib/utils/areShapesContentEqual.js.map +2 -2
  33. package/dist-cjs/lib/utils/dom.js +1 -1
  34. package/dist-cjs/lib/utils/dom.js.map +2 -2
  35. package/dist-cjs/lib/utils/reparenting.js +232 -0
  36. package/dist-cjs/lib/utils/reparenting.js.map +7 -0
  37. package/dist-cjs/lib/utils/richText.js +7 -2
  38. package/dist-cjs/lib/utils/richText.js.map +2 -2
  39. package/dist-cjs/version.js +3 -3
  40. package/dist-cjs/version.js.map +1 -1
  41. package/dist-esm/index.d.mts +166 -59
  42. package/dist-esm/index.mjs +4 -3
  43. package/dist-esm/index.mjs.map +2 -2
  44. package/dist-esm/lib/config/TLSessionStateSnapshot.mjs +1 -1
  45. package/dist-esm/lib/config/TLSessionStateSnapshot.mjs.map +2 -2
  46. package/dist-esm/lib/editor/Editor.mjs +113 -45
  47. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  48. package/dist-esm/lib/editor/bindings/BindingUtil.mjs.map +2 -2
  49. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +1 -2
  50. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
  51. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +3 -1
  52. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
  53. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +73 -42
  54. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  55. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +0 -10
  56. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  57. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -1
  58. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +1 -1
  59. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +10 -6
  60. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +3 -3
  61. package/dist-esm/lib/editor/tools/StateNode.mjs +3 -3
  62. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  63. package/dist-esm/lib/hooks/useCanvasEvents.mjs +1 -2
  64. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  65. package/dist-esm/lib/primitives/Box.mjs +0 -6
  66. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  67. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +6 -2
  68. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  69. package/dist-esm/lib/utils/areShapesContentEqual.mjs +1 -1
  70. package/dist-esm/lib/utils/areShapesContentEqual.mjs.map +2 -2
  71. package/dist-esm/lib/utils/dom.mjs +1 -1
  72. package/dist-esm/lib/utils/dom.mjs.map +2 -2
  73. package/dist-esm/lib/utils/reparenting.mjs +216 -0
  74. package/dist-esm/lib/utils/reparenting.mjs.map +7 -0
  75. package/dist-esm/lib/utils/richText.mjs +8 -3
  76. package/dist-esm/lib/utils/richText.mjs.map +2 -2
  77. package/dist-esm/version.mjs +3 -3
  78. package/dist-esm/version.mjs.map +1 -1
  79. package/editor.css +442 -492
  80. package/package.json +8 -9
  81. package/src/index.ts +7 -1
  82. package/src/lib/config/TLSessionStateSnapshot.ts +1 -1
  83. package/src/lib/editor/Editor.test.ts +252 -3
  84. package/src/lib/editor/Editor.ts +129 -52
  85. package/src/lib/editor/bindings/BindingUtil.ts +6 -0
  86. package/src/lib/editor/managers/FontManager/FontManager.ts +1 -2
  87. package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +3 -1
  88. package/src/lib/editor/managers/TextManager/TextManager.test.ts +1 -5
  89. package/src/lib/editor/managers/TextManager/TextManager.ts +118 -86
  90. package/src/lib/editor/shapes/ShapeUtil.ts +47 -15
  91. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +1 -1
  92. package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +22 -17
  93. package/src/lib/editor/tools/StateNode.ts +3 -3
  94. package/src/lib/editor/types/emit-types.ts +4 -0
  95. package/src/lib/editor/types/external-content.ts +11 -2
  96. package/src/lib/hooks/useCanvasEvents.ts +0 -1
  97. package/src/lib/primitives/Box.ts +0 -8
  98. package/src/lib/primitives/geometry/Geometry2d.ts +7 -2
  99. package/src/lib/utils/areShapesContentEqual.ts +1 -2
  100. package/src/lib/utils/dom.ts +1 -1
  101. package/src/lib/utils/reparenting.ts +383 -0
  102. package/src/lib/utils/richText.ts +9 -3
  103. package/src/version.ts +3 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/config/TLSessionStateSnapshot.ts"],
4
- "sourcesContent": ["import { Signal, computed } from '@tldraw/state'\nimport { UnknownRecord } from '@tldraw/store'\nimport {\n\tCameraRecordType,\n\tInstancePageStateRecordType,\n\tTLINSTANCE_ID,\n\tTLPageId,\n\tTLShapeId,\n\tTLStore,\n\tpageIdValidator,\n\tpluckPreservingValues,\n\tshapeIdValidator,\n} from '@tldraw/tlschema'\nimport {\n\tdeleteFromSessionStorage,\n\tgetFromSessionStorage,\n\tsetInSessionStorage,\n\tstructuredClone,\n\tuniqueId,\n} from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport isEqual from 'lodash.isequal'\nimport { tlenv } from '../globals/environment'\n\nconst tabIdKey = 'TLDRAW_TAB_ID_v2' as const\n\nconst window = globalThis.window as\n\t| {\n\t\t\tnavigator: Window['navigator']\n\t\t\taddEventListener: Window['addEventListener']\n\t\t\tTLDRAW_TAB_ID_v2?: string\n\t }\n\t| undefined\n\n// https://stackoverflow.com/a/9039885\nfunction iOS() {\n\tif (!window) return false\n\treturn (\n\t\t['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\t\twindow.navigator.platform\n\t\t) ||\n\t\t// iPad on iOS 13 detection\n\t\t(tlenv.isDarwin && 'ontouchend' in document)\n\t)\n}\n\n/**\n * A string that is unique per browser tab\n * @public\n */\nexport const TAB_ID: string = window\n\t? (window[tabIdKey] ??\n\t\tgetFromSessionStorage(tabIdKey) ??\n\t\t`TLDRAW_INSTANCE_STATE_V1_` + uniqueId())\n\t: '<error>'\nif (window) {\n\twindow[tabIdKey] = TAB_ID\n\tif (iOS()) {\n\t\t// iOS does not trigger beforeunload\n\t\t// so we need to keep the sessionStorage value around\n\t\t// and hope the user doesn't figure out a way to duplicate their tab\n\t\t// in which case they'll have two tabs with the same UI state.\n\t\t// It's not a big deal, but it's not ideal.\n\t\t// And anyway I can't see a way to duplicate a tab in iOS Safari.\n\t\tsetInSessionStorage(tabIdKey, TAB_ID)\n\t} else {\n\t\tdeleteFromSessionStorage(tabIdKey)\n\t}\n}\n\nwindow?.addEventListener('beforeunload', () => {\n\tsetInSessionStorage(tabIdKey, TAB_ID)\n})\n\nconst Versions = {\n\tInitial: 0,\n} as const\n\nconst CURRENT_SESSION_STATE_SNAPSHOT_VERSION = Math.max(...Object.values(Versions))\n\nfunction migrate(snapshot: any) {\n\tif (snapshot.version < Versions.Initial) {\n\t\t// initial version\n\t\t// noop\n\t}\n\t// add further migrations down here. see TLUserPreferences.ts for an example.\n\n\t// finally\n\tsnapshot.version = CURRENT_SESSION_STATE_SNAPSHOT_VERSION\n}\n\n/**\n * The state of the editor instance, not including any document state.\n *\n * @public\n */\nexport interface TLSessionStateSnapshot {\n\tversion: number\n\tcurrentPageId?: TLPageId\n\tisFocusMode?: boolean\n\texportBackground?: boolean\n\tisDebugMode?: boolean\n\tisToolLocked?: boolean\n\tisGridMode?: boolean\n\tpageStates?: Array<{\n\t\tpageId: TLPageId\n\t\tcamera?: { x: number; y: number; z: number }\n\t\tselectedShapeIds?: TLShapeId[]\n\t\tfocusedGroupId?: TLShapeId | null\n\t}>\n}\n\nconst sessionStateSnapshotValidator: T.Validator<TLSessionStateSnapshot> = T.object({\n\tversion: T.number,\n\tcurrentPageId: pageIdValidator.optional(),\n\tisFocusMode: T.boolean.optional(),\n\texportBackground: T.boolean.optional(),\n\tisDebugMode: T.boolean.optional(),\n\tisToolLocked: T.boolean.optional(),\n\tisGridMode: T.boolean.optional(),\n\tpageStates: T.arrayOf(\n\t\tT.object({\n\t\t\tpageId: pageIdValidator,\n\t\t\tcamera: T.object({\n\t\t\t\tx: T.number,\n\t\t\t\ty: T.number,\n\t\t\t\tz: T.number,\n\t\t\t}).optional(),\n\t\t\tselectedShapeIds: T.arrayOf(shapeIdValidator).optional(),\n\t\t\tfocusedGroupId: shapeIdValidator.nullable().optional(),\n\t\t})\n\t).optional(),\n})\n\nfunction migrateAndValidateSessionStateSnapshot(state: unknown): TLSessionStateSnapshot | null {\n\tif (!state || typeof state !== 'object') {\n\t\tconsole.warn('Invalid instance state')\n\t\treturn null\n\t}\n\tif (!('version' in state) || typeof state.version !== 'number') {\n\t\tconsole.warn('No version in instance state')\n\t\treturn null\n\t}\n\tif (state.version !== CURRENT_SESSION_STATE_SNAPSHOT_VERSION) {\n\t\tstate = structuredClone(state)\n\t\tmigrate(state)\n\t}\n\n\ttry {\n\t\treturn sessionStateSnapshotValidator.validate(state)\n\t} catch (e) {\n\t\tconsole.warn(e)\n\t\treturn null\n\t}\n}\n\n/**\n * Creates a signal of the instance state for a given store.\n * @public\n * @param store - The store to create the instance state snapshot signal for\n * @returns\n */\nexport function createSessionStateSnapshotSignal(\n\tstore: TLStore\n): Signal<TLSessionStateSnapshot | null> {\n\tconst $allPageIds = store.query.ids('page')\n\n\treturn computed<TLSessionStateSnapshot | null>(\n\t\t'sessionStateSnapshot',\n\t\t() => {\n\t\t\tconst instanceState = store.get(TLINSTANCE_ID)\n\t\t\tif (!instanceState) return null\n\n\t\t\tconst allPageIds = [...$allPageIds.get()]\n\t\t\treturn {\n\t\t\t\tversion: CURRENT_SESSION_STATE_SNAPSHOT_VERSION,\n\t\t\t\tcurrentPageId: instanceState.currentPageId,\n\t\t\t\texportBackground: instanceState.exportBackground,\n\t\t\t\tisFocusMode: instanceState.isFocusMode,\n\t\t\t\tisDebugMode: instanceState.isDebugMode,\n\t\t\t\tisToolLocked: instanceState.isToolLocked,\n\t\t\t\tisGridMode: instanceState.isGridMode,\n\t\t\t\tpageStates: allPageIds.map((id) => {\n\t\t\t\t\tconst ps = store.get(InstancePageStateRecordType.createId(id))\n\t\t\t\t\tconst camera = store.get(CameraRecordType.createId(id))\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpageId: id,\n\t\t\t\t\t\tcamera: {\n\t\t\t\t\t\t\tx: camera?.x ?? 0,\n\t\t\t\t\t\t\ty: camera?.y ?? 0,\n\t\t\t\t\t\t\tz: camera?.z ?? 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tselectedShapeIds: ps?.selectedShapeIds ?? [],\n\t\t\t\t\t\tfocusedGroupId: ps?.focusedGroupId ?? null,\n\t\t\t\t\t} satisfies NonNullable<TLSessionStateSnapshot['pageStates']>[0]\n\t\t\t\t}),\n\t\t\t} satisfies TLSessionStateSnapshot\n\t\t},\n\t\t{ isEqual }\n\t)\n}\n\n/**\n * Options for {@link loadSessionStateSnapshotIntoStore}\n * @public\n */\nexport interface TLLoadSessionStateSnapshotOptions {\n\t/**\n\t * By default, some session state flags like `isDebugMode` are not overwritten when loading a snapshot.\n\t * These are usually considered \"sticky\" by users while the document data is not.\n\t * If you want to overwrite these flags, set this to `true`.\n\t */\n\tforceOverwrite?: boolean\n}\n\n/**\n * Loads a snapshot of the editor's instance state into the store of a new editor instance.\n *\n * @public\n * @param store - The store to load the instance state into\n * @param snapshot - The instance state snapshot to load\n * @returns\n */\nexport function loadSessionStateSnapshotIntoStore(\n\tstore: TLStore,\n\tsnapshot: TLSessionStateSnapshot,\n\topts?: TLLoadSessionStateSnapshotOptions\n) {\n\tconst res = migrateAndValidateSessionStateSnapshot(snapshot)\n\tif (!res) return\n\n\tconst preserved = pluckPreservingValues(store.get(TLINSTANCE_ID))\n\tconst primary = opts?.forceOverwrite ? res : preserved\n\tconst secondary = opts?.forceOverwrite ? preserved : res\n\n\tconst instanceState = store.schema.types.instance.create({\n\t\tid: TLINSTANCE_ID,\n\t\t...preserved,\n\t\t// the integrity checker will ensure that the currentPageId is valid\n\t\tcurrentPageId: res.currentPageId,\n\t\tisDebugMode: primary?.isDebugMode ?? secondary?.isDebugMode,\n\t\tisFocusMode: primary?.isFocusMode ?? secondary?.isFocusMode,\n\t\tisToolLocked: primary?.isToolLocked ?? secondary?.isToolLocked,\n\t\tisGridMode: primary?.isGridMode ?? secondary?.isGridMode,\n\t\texportBackground: primary?.exportBackground ?? secondary?.exportBackground,\n\t})\n\n\tstore.atomic(() => {\n\t\tfor (const ps of res.pageStates ?? []) {\n\t\t\tif (!store.has(ps.pageId)) continue\n\t\t\tconst cameraId = CameraRecordType.createId(ps.pageId)\n\t\t\tconst instancePageState = InstancePageStateRecordType.createId(ps.pageId)\n\t\t\tconst previousCamera = store.get(cameraId)\n\t\t\tconst previousInstanceState = store.get(instancePageState)\n\t\t\tstore.put([\n\t\t\t\tCameraRecordType.create({\n\t\t\t\t\tid: cameraId,\n\t\t\t\t\tx: ps.camera?.x ?? previousCamera?.x,\n\t\t\t\t\ty: ps.camera?.y ?? previousCamera?.y,\n\t\t\t\t\tz: ps.camera?.z ?? previousCamera?.z,\n\t\t\t\t}),\n\t\t\t\tInstancePageStateRecordType.create({\n\t\t\t\t\tid: instancePageState,\n\t\t\t\t\tpageId: ps.pageId,\n\t\t\t\t\tselectedShapeIds: ps.selectedShapeIds ?? previousInstanceState?.selectedShapeIds,\n\t\t\t\t\tfocusedGroupId: ps.focusedGroupId ?? previousInstanceState?.focusedGroupId,\n\t\t\t\t}),\n\t\t\t])\n\t\t}\n\n\t\tstore.put([instanceState])\n\t\tstore.ensureStoreIsUsable()\n\t})\n}\n\n/**\n * @internal\n */\nexport function extractSessionStateFromLegacySnapshot(\n\tstore: Record<string, UnknownRecord>\n): TLSessionStateSnapshot | null {\n\tconst instanceRecords = []\n\tfor (const record of Object.values(store)) {\n\t\tif (record.typeName?.match(/^(instance.*|pointer|camera)$/)) {\n\t\t\tinstanceRecords.push(record)\n\t\t}\n\t}\n\n\t// for scratch documents, we need to extract the most recently-used instance and it's associated page states\n\t// but oops we don't have the concept of \"most recently-used\" so we'll just take the first one\n\tconst oldInstance = instanceRecords.filter(\n\t\t(r) => r.typeName === 'instance' && r.id !== TLINSTANCE_ID\n\t)[0] as any\n\tif (!oldInstance) return null\n\n\tconst result: TLSessionStateSnapshot = {\n\t\tversion: CURRENT_SESSION_STATE_SNAPSHOT_VERSION,\n\t\tcurrentPageId: oldInstance.currentPageId,\n\t\texportBackground: !!oldInstance.exportBackground,\n\t\tisFocusMode: !!oldInstance.isFocusMode,\n\t\tisDebugMode: !!oldInstance.isDebugMode,\n\t\tisToolLocked: !!oldInstance.isToolLocked,\n\t\tisGridMode: false,\n\t\tpageStates: instanceRecords\n\t\t\t.filter((r: any) => r.typeName === 'instance_page_state' && r.instanceId === oldInstance.id)\n\t\t\t.map((ps: any) => {\n\t\t\t\tconst camera = (store[ps.cameraId] as any) ?? { x: 0, y: 0, z: 1 }\n\t\t\t\treturn {\n\t\t\t\t\tpageId: ps.pageId,\n\t\t\t\t\tcamera: {\n\t\t\t\t\t\tx: camera.x,\n\t\t\t\t\t\ty: camera.y,\n\t\t\t\t\t\tz: camera.z,\n\t\t\t\t\t},\n\t\t\t\t\tselectedShapeIds: ps.selectedShapeIds,\n\t\t\t\t\tfocusedGroupId: ps.focusedGroupId,\n\t\t\t\t} satisfies NonNullable<TLSessionStateSnapshot['pageStates']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BACV,OAAO,CAAC,MAAW,EAAE,aAAa,yBAAyB,EAAE,eAAe,YAAY,EAAE,EAC1F,IAAI,CAAC,OAAY;AACjB,YAAM,SAAU,MAAM,GAAG,QAAQ,KAAa,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AACjE,aAAO;AAAA,QACN,QAAQ,GAAG;AAAA,QACX,QAAQ;AAAA,UACP,GAAG,OAAO;AAAA,UACV,GAAG,OAAO;AAAA,UACV,GAAG,OAAO;AAAA,QACX;AAAA,QACA,kBAAkB,GAAG;AAAA,QACrB,gBAAgB,GAAG;AAAA,MACpB;AAAA,IACD,CAAC;AAAA,EACH;AAEA,MAAI;AACH,kCAA8B,SAAS,MAAM;AAC7C,WAAO;AAAA,EACR,QAAQ;AACP,WAAO;AAAA,EACR;AACD;",
6
- "names": ["isEqual"]
4
+ "sourcesContent": ["import { Signal, computed } from '@tldraw/state'\nimport { UnknownRecord } from '@tldraw/store'\nimport {\n\tCameraRecordType,\n\tInstancePageStateRecordType,\n\tTLINSTANCE_ID,\n\tTLPageId,\n\tTLShapeId,\n\tTLStore,\n\tpageIdValidator,\n\tpluckPreservingValues,\n\tshapeIdValidator,\n} from '@tldraw/tlschema'\nimport {\n\tdeleteFromSessionStorage,\n\tgetFromSessionStorage,\n\tisEqual,\n\tsetInSessionStorage,\n\tstructuredClone,\n\tuniqueId,\n} from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { tlenv } from '../globals/environment'\n\nconst tabIdKey = 'TLDRAW_TAB_ID_v2' as const\n\nconst window = globalThis.window as\n\t| {\n\t\t\tnavigator: Window['navigator']\n\t\t\taddEventListener: Window['addEventListener']\n\t\t\tTLDRAW_TAB_ID_v2?: string\n\t }\n\t| undefined\n\n// https://stackoverflow.com/a/9039885\nfunction iOS() {\n\tif (!window) return false\n\treturn (\n\t\t['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\t\twindow.navigator.platform\n\t\t) ||\n\t\t// iPad on iOS 13 detection\n\t\t(tlenv.isDarwin && 'ontouchend' in document)\n\t)\n}\n\n/**\n * A string that is unique per browser tab\n * @public\n */\nexport const TAB_ID: string = window\n\t? (window[tabIdKey] ??\n\t\tgetFromSessionStorage(tabIdKey) ??\n\t\t`TLDRAW_INSTANCE_STATE_V1_` + uniqueId())\n\t: '<error>'\nif (window) {\n\twindow[tabIdKey] = TAB_ID\n\tif (iOS()) {\n\t\t// iOS does not trigger beforeunload\n\t\t// so we need to keep the sessionStorage value around\n\t\t// and hope the user doesn't figure out a way to duplicate their tab\n\t\t// in which case they'll have two tabs with the same UI state.\n\t\t// It's not a big deal, but it's not ideal.\n\t\t// And anyway I can't see a way to duplicate a tab in iOS Safari.\n\t\tsetInSessionStorage(tabIdKey, TAB_ID)\n\t} else {\n\t\tdeleteFromSessionStorage(tabIdKey)\n\t}\n}\n\nwindow?.addEventListener('beforeunload', () => {\n\tsetInSessionStorage(tabIdKey, TAB_ID)\n})\n\nconst Versions = {\n\tInitial: 0,\n} as const\n\nconst CURRENT_SESSION_STATE_SNAPSHOT_VERSION = Math.max(...Object.values(Versions))\n\nfunction migrate(snapshot: any) {\n\tif (snapshot.version < Versions.Initial) {\n\t\t// initial version\n\t\t// noop\n\t}\n\t// add further migrations down here. see TLUserPreferences.ts for an example.\n\n\t// finally\n\tsnapshot.version = CURRENT_SESSION_STATE_SNAPSHOT_VERSION\n}\n\n/**\n * The state of the editor instance, not including any document state.\n *\n * @public\n */\nexport interface TLSessionStateSnapshot {\n\tversion: number\n\tcurrentPageId?: TLPageId\n\tisFocusMode?: boolean\n\texportBackground?: boolean\n\tisDebugMode?: boolean\n\tisToolLocked?: boolean\n\tisGridMode?: boolean\n\tpageStates?: Array<{\n\t\tpageId: TLPageId\n\t\tcamera?: { x: number; y: number; z: number }\n\t\tselectedShapeIds?: TLShapeId[]\n\t\tfocusedGroupId?: TLShapeId | null\n\t}>\n}\n\nconst sessionStateSnapshotValidator: T.Validator<TLSessionStateSnapshot> = T.object({\n\tversion: T.number,\n\tcurrentPageId: pageIdValidator.optional(),\n\tisFocusMode: T.boolean.optional(),\n\texportBackground: T.boolean.optional(),\n\tisDebugMode: T.boolean.optional(),\n\tisToolLocked: T.boolean.optional(),\n\tisGridMode: T.boolean.optional(),\n\tpageStates: T.arrayOf(\n\t\tT.object({\n\t\t\tpageId: pageIdValidator,\n\t\t\tcamera: T.object({\n\t\t\t\tx: T.number,\n\t\t\t\ty: T.number,\n\t\t\t\tz: T.number,\n\t\t\t}).optional(),\n\t\t\tselectedShapeIds: T.arrayOf(shapeIdValidator).optional(),\n\t\t\tfocusedGroupId: shapeIdValidator.nullable().optional(),\n\t\t})\n\t).optional(),\n})\n\nfunction migrateAndValidateSessionStateSnapshot(state: unknown): TLSessionStateSnapshot | null {\n\tif (!state || typeof state !== 'object') {\n\t\tconsole.warn('Invalid instance state')\n\t\treturn null\n\t}\n\tif (!('version' in state) || typeof state.version !== 'number') {\n\t\tconsole.warn('No version in instance state')\n\t\treturn null\n\t}\n\tif (state.version !== CURRENT_SESSION_STATE_SNAPSHOT_VERSION) {\n\t\tstate = structuredClone(state)\n\t\tmigrate(state)\n\t}\n\n\ttry {\n\t\treturn sessionStateSnapshotValidator.validate(state)\n\t} catch (e) {\n\t\tconsole.warn(e)\n\t\treturn null\n\t}\n}\n\n/**\n * Creates a signal of the instance state for a given store.\n * @public\n * @param store - The store to create the instance state snapshot signal for\n * @returns\n */\nexport function createSessionStateSnapshotSignal(\n\tstore: TLStore\n): Signal<TLSessionStateSnapshot | null> {\n\tconst $allPageIds = store.query.ids('page')\n\n\treturn computed<TLSessionStateSnapshot | null>(\n\t\t'sessionStateSnapshot',\n\t\t() => {\n\t\t\tconst instanceState = store.get(TLINSTANCE_ID)\n\t\t\tif (!instanceState) return null\n\n\t\t\tconst allPageIds = [...$allPageIds.get()]\n\t\t\treturn {\n\t\t\t\tversion: CURRENT_SESSION_STATE_SNAPSHOT_VERSION,\n\t\t\t\tcurrentPageId: instanceState.currentPageId,\n\t\t\t\texportBackground: instanceState.exportBackground,\n\t\t\t\tisFocusMode: instanceState.isFocusMode,\n\t\t\t\tisDebugMode: instanceState.isDebugMode,\n\t\t\t\tisToolLocked: instanceState.isToolLocked,\n\t\t\t\tisGridMode: instanceState.isGridMode,\n\t\t\t\tpageStates: allPageIds.map((id) => {\n\t\t\t\t\tconst ps = store.get(InstancePageStateRecordType.createId(id))\n\t\t\t\t\tconst camera = store.get(CameraRecordType.createId(id))\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpageId: id,\n\t\t\t\t\t\tcamera: {\n\t\t\t\t\t\t\tx: camera?.x ?? 0,\n\t\t\t\t\t\t\ty: camera?.y ?? 0,\n\t\t\t\t\t\t\tz: camera?.z ?? 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tselectedShapeIds: ps?.selectedShapeIds ?? [],\n\t\t\t\t\t\tfocusedGroupId: ps?.focusedGroupId ?? null,\n\t\t\t\t\t} satisfies NonNullable<TLSessionStateSnapshot['pageStates']>[0]\n\t\t\t\t}),\n\t\t\t} satisfies TLSessionStateSnapshot\n\t\t},\n\t\t{ isEqual }\n\t)\n}\n\n/**\n * Options for {@link loadSessionStateSnapshotIntoStore}\n * @public\n */\nexport interface TLLoadSessionStateSnapshotOptions {\n\t/**\n\t * By default, some session state flags like `isDebugMode` are not overwritten when loading a snapshot.\n\t * These are usually considered \"sticky\" by users while the document data is not.\n\t * If you want to overwrite these flags, set this to `true`.\n\t */\n\tforceOverwrite?: boolean\n}\n\n/**\n * Loads a snapshot of the editor's instance state into the store of a new editor instance.\n *\n * @public\n * @param store - The store to load the instance state into\n * @param snapshot - The instance state snapshot to load\n * @returns\n */\nexport function loadSessionStateSnapshotIntoStore(\n\tstore: TLStore,\n\tsnapshot: TLSessionStateSnapshot,\n\topts?: TLLoadSessionStateSnapshotOptions\n) {\n\tconst res = migrateAndValidateSessionStateSnapshot(snapshot)\n\tif (!res) return\n\n\tconst preserved = pluckPreservingValues(store.get(TLINSTANCE_ID))\n\tconst primary = opts?.forceOverwrite ? res : preserved\n\tconst secondary = opts?.forceOverwrite ? preserved : res\n\n\tconst instanceState = store.schema.types.instance.create({\n\t\tid: TLINSTANCE_ID,\n\t\t...preserved,\n\t\t// the integrity checker will ensure that the currentPageId is valid\n\t\tcurrentPageId: res.currentPageId,\n\t\tisDebugMode: primary?.isDebugMode ?? secondary?.isDebugMode,\n\t\tisFocusMode: primary?.isFocusMode ?? secondary?.isFocusMode,\n\t\tisToolLocked: primary?.isToolLocked ?? secondary?.isToolLocked,\n\t\tisGridMode: primary?.isGridMode ?? secondary?.isGridMode,\n\t\texportBackground: primary?.exportBackground ?? secondary?.exportBackground,\n\t})\n\n\tstore.atomic(() => {\n\t\tfor (const ps of res.pageStates ?? []) {\n\t\t\tif (!store.has(ps.pageId)) continue\n\t\t\tconst cameraId = CameraRecordType.createId(ps.pageId)\n\t\t\tconst instancePageState = InstancePageStateRecordType.createId(ps.pageId)\n\t\t\tconst previousCamera = store.get(cameraId)\n\t\t\tconst previousInstanceState = store.get(instancePageState)\n\t\t\tstore.put([\n\t\t\t\tCameraRecordType.create({\n\t\t\t\t\tid: cameraId,\n\t\t\t\t\tx: ps.camera?.x ?? previousCamera?.x,\n\t\t\t\t\ty: ps.camera?.y ?? previousCamera?.y,\n\t\t\t\t\tz: ps.camera?.z ?? previousCamera?.z,\n\t\t\t\t}),\n\t\t\t\tInstancePageStateRecordType.create({\n\t\t\t\t\tid: instancePageState,\n\t\t\t\t\tpageId: ps.pageId,\n\t\t\t\t\tselectedShapeIds: ps.selectedShapeIds ?? previousInstanceState?.selectedShapeIds,\n\t\t\t\t\tfocusedGroupId: ps.focusedGroupId ?? previousInstanceState?.focusedGroupId,\n\t\t\t\t}),\n\t\t\t])\n\t\t}\n\n\t\tstore.put([instanceState])\n\t\tstore.ensureStoreIsUsable()\n\t})\n}\n\n/**\n * @internal\n */\nexport function extractSessionStateFromLegacySnapshot(\n\tstore: Record<string, UnknownRecord>\n): TLSessionStateSnapshot | null {\n\tconst instanceRecords = []\n\tfor (const record of Object.values(store)) {\n\t\tif (record.typeName?.match(/^(instance.*|pointer|camera)$/)) {\n\t\t\tinstanceRecords.push(record)\n\t\t}\n\t}\n\n\t// for scratch documents, we need to extract the most recently-used instance and it's associated page states\n\t// but oops we don't have the concept of \"most recently-used\" so we'll just take the first one\n\tconst oldInstance = instanceRecords.filter(\n\t\t(r) => r.typeName === 'instance' && r.id !== TLINSTANCE_ID\n\t)[0] as any\n\tif (!oldInstance) return null\n\n\tconst result: TLSessionStateSnapshot = {\n\t\tversion: CURRENT_SESSION_STATE_SNAPSHOT_VERSION,\n\t\tcurrentPageId: oldInstance.currentPageId,\n\t\texportBackground: !!oldInstance.exportBackground,\n\t\tisFocusMode: !!oldInstance.isFocusMode,\n\t\tisDebugMode: !!oldInstance.isDebugMode,\n\t\tisToolLocked: !!oldInstance.isToolLocked,\n\t\tisGridMode: false,\n\t\tpageStates: instanceRecords\n\t\t\t.filter((r: any) => r.typeName === 'instance_page_state' && r.instanceId === oldInstance.id)\n\t\t\t.map((ps: any) => {\n\t\t\t\tconst camera = (store[ps.cameraId] as any) ?? { x: 0, y: 0, z: 1 }\n\t\t\t\treturn {\n\t\t\t\t\tpageId: ps.pageId,\n\t\t\t\t\tcamera: {\n\t\t\t\t\t\tx: camera.x,\n\t\t\t\t\t\ty: camera.y,\n\t\t\t\t\t\tz: camera.z,\n\t\t\t\t\t},\n\t\t\t\t\tselectedShapeIds: ps.selectedShapeIds,\n\t\t\t\t\tfocusedGroupId: ps.focusedGroupId,\n\t\t\t\t} satisfies NonNullable<TLSessionStateSnapshot['pageStates']>[0]\n\t\t\t}),\n\t}\n\n\ttry {\n\t\tsessionStateSnapshotValidator.validate(result)\n\t\treturn result\n\t} catch {\n\t\treturn null\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;A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GAAG;AAAA,QACX,QAAQ;AAAA,UACP,GAAG,OAAO;AAAA,UACV,GAAG,OAAO;AAAA,UACV,GAAG,OAAO;AAAA,QACX;AAAA,QACA,kBAAkB,GAAG;AAAA,QACrB,gBAAgB,GAAG;AAAA,MACpB;AAAA,IACD,CAAC;AAAA,EACH;AAEA,MAAI;AACH,kCAA8B,SAAS,MAAM;AAC7C,WAAO;AAAA,EACR,QAAQ;AACP,WAAO;AAAA,EACR;AACD;",
6
+ "names": []
7
7
  }
@@ -123,8 +123,8 @@ var import_TextManager = require("./managers/TextManager/TextManager");
123
123
  var import_TickManager = require("./managers/TickManager/TickManager");
124
124
  var import_UserPreferencesManager = require("./managers/UserPreferencesManager/UserPreferencesManager");
125
125
  var import_RootState = require("./tools/RootState");
126
- var __setMetaKeyTimeout_dec, __setCtrlKeyTimeout_dec, __setAltKeyTimeout_dec, __setShiftKeyTimeout_dec, _getIsReadonly_dec, _getIsFocused_dec, _getSharedOpacity_dec, _getSharedStyles_dec, __getSelectionSharedStyles_dec, __getBindingsIndexCache_dec, _getCurrentPageRenderingShapesSorted_dec, _getCurrentPageShapesSorted_dec, _getCurrentPageShapes_dec, _getCurrentPageBounds_dec, _getCulledShapes_dec, __notVisibleShapes_dec, __getShapeMaskedPageBoundsCache_dec, __getShapeMaskCache_dec, __getShapeClipPathCache_dec, __getShapePageBoundsCache_dec, __getShapePageTransformCache_dec, __getShapeHandlesCache_dec, __getAllAssetsQuery_dec, _getCurrentPageShapeIdsSorted_dec, _getCurrentPageId_dec, _getPages_dec, __getAllPagesQuery_dec, _getRenderingShapes_dec, _getCollaboratorsOnCurrentPage_dec, _getCollaborators_dec, __getCollaboratorsQuery_dec, _getViewportPageBounds_dec, _getViewportScreenCenter_dec, _getViewportScreenBounds_dec, _getZoomLevel_dec, _getCameraForFollowing_dec, _getViewportPageBoundsForFollowing_dec, _getCamera_dec, __unsafe_getCameraId_dec, _getErasingShapes_dec, _getErasingShapeIds_dec, _getHintingShape_dec, _getHintingShapeIds_dec, _getHoveredShape_dec, _getHoveredShapeId_dec, _getRichTextEditor_dec, _getEditingShape_dec, _getEditingShapeId_dec, _getFocusedGroup_dec, _getFocusedGroupId_dec, _getSelectionRotatedScreenBounds_dec, _getSelectionRotatedPageBounds_dec, _getSelectionRotation_dec, _getSelectionPageBounds_dec, _getOnlySelectedShape_dec, _getOnlySelectedShapeId_dec, _getCurrentPageShapesInReadingOrder_dec, _getSelectedShapes_dec, _getSelectedShapeIds_dec, __getCurrentPageStateId_dec, _getCurrentPageState_dec, __getPageStatesQuery_dec, _getPageStates_dec, _getIsMenuOpen_dec, _getOpenMenus_dec, _getInstanceState_dec, _getDocumentSettings_dec, _getCurrentToolId_dec, _getCurrentTool_dec, _getPath_dec, _getCanRedo_dec, _getCanUndo_dec, _getIsShapeHiddenCache_dec, _a, _init;
127
- class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_dec = [import_state.computed], _getCanUndo_dec = [import_state.computed], _getCanRedo_dec = [import_state.computed], _getPath_dec = [import_state.computed], _getCurrentTool_dec = [import_state.computed], _getCurrentToolId_dec = [import_state.computed], _getDocumentSettings_dec = [import_state.computed], _getInstanceState_dec = [import_state.computed], _getOpenMenus_dec = [import_state.computed], _getIsMenuOpen_dec = [import_state.computed], _getPageStates_dec = [import_state.computed], __getPageStatesQuery_dec = [import_state.computed], _getCurrentPageState_dec = [import_state.computed], __getCurrentPageStateId_dec = [import_state.computed], _getSelectedShapeIds_dec = [import_state.computed], _getSelectedShapes_dec = [import_state.computed], _getCurrentPageShapesInReadingOrder_dec = [import_state.computed], _getOnlySelectedShapeId_dec = [import_state.computed], _getOnlySelectedShape_dec = [import_state.computed], _getSelectionPageBounds_dec = [import_state.computed], _getSelectionRotation_dec = [import_state.computed], _getSelectionRotatedPageBounds_dec = [import_state.computed], _getSelectionRotatedScreenBounds_dec = [import_state.computed], _getFocusedGroupId_dec = [import_state.computed], _getFocusedGroup_dec = [import_state.computed], _getEditingShapeId_dec = [import_state.computed], _getEditingShape_dec = [import_state.computed], _getRichTextEditor_dec = [import_state.computed], _getHoveredShapeId_dec = [import_state.computed], _getHoveredShape_dec = [import_state.computed], _getHintingShapeIds_dec = [import_state.computed], _getHintingShape_dec = [import_state.computed], _getErasingShapeIds_dec = [import_state.computed], _getErasingShapes_dec = [import_state.computed], __unsafe_getCameraId_dec = [import_state.computed], _getCamera_dec = [import_state.computed], _getViewportPageBoundsForFollowing_dec = [import_state.computed], _getCameraForFollowing_dec = [import_state.computed], _getZoomLevel_dec = [import_state.computed], _getViewportScreenBounds_dec = [import_state.computed], _getViewportScreenCenter_dec = [import_state.computed], _getViewportPageBounds_dec = [import_state.computed], __getCollaboratorsQuery_dec = [import_state.computed], _getCollaborators_dec = [import_state.computed], _getCollaboratorsOnCurrentPage_dec = [import_state.computed], _getRenderingShapes_dec = [import_state.computed], __getAllPagesQuery_dec = [import_state.computed], _getPages_dec = [import_state.computed], _getCurrentPageId_dec = [import_state.computed], _getCurrentPageShapeIdsSorted_dec = [import_state.computed], __getAllAssetsQuery_dec = [import_state.computed], __getShapeHandlesCache_dec = [import_state.computed], __getShapePageTransformCache_dec = [import_state.computed], __getShapePageBoundsCache_dec = [import_state.computed], __getShapeClipPathCache_dec = [import_state.computed], __getShapeMaskCache_dec = [import_state.computed], __getShapeMaskedPageBoundsCache_dec = [import_state.computed], __notVisibleShapes_dec = [import_state.computed], _getCulledShapes_dec = [import_state.computed], _getCurrentPageBounds_dec = [import_state.computed], _getCurrentPageShapes_dec = [import_state.computed], _getCurrentPageShapesSorted_dec = [import_state.computed], _getCurrentPageRenderingShapesSorted_dec = [import_state.computed], __getBindingsIndexCache_dec = [import_state.computed], __getSelectionSharedStyles_dec = [import_state.computed], _getSharedStyles_dec = [(0, import_state.computed)({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [import_state.computed], _getIsFocused_dec = [import_state.computed], _getIsReadonly_dec = [import_state.computed], __setShiftKeyTimeout_dec = [import_utils.bind], __setAltKeyTimeout_dec = [import_utils.bind], __setCtrlKeyTimeout_dec = [import_utils.bind], __setMetaKeyTimeout_dec = [import_utils.bind], _a) {
126
+ var __setMetaKeyTimeout_dec, __setCtrlKeyTimeout_dec, __setAltKeyTimeout_dec, __setShiftKeyTimeout_dec, _getIsReadonly_dec, _getIsFocused_dec, _getSharedOpacity_dec, _getSharedStyles_dec, __getSelectionSharedStyles_dec, __getBindingsIndexCache_dec, _getCurrentPageRenderingShapesSorted_dec, _getCurrentPageShapesSorted_dec, _getCurrentPageShapes_dec, _getCurrentPageBounds_dec, _getCulledShapes_dec, _getNotVisibleShapes_dec, __getShapeMaskedPageBoundsCache_dec, __getShapeMaskCache_dec, __getShapeClipPathCache_dec, __getShapePageBoundsCache_dec, __getShapePageTransformCache_dec, __getShapeHandlesCache_dec, __getAllAssetsQuery_dec, _getCurrentPageShapeIdsSorted_dec, _getCurrentPageId_dec, _getPages_dec, __getAllPagesQuery_dec, _getRenderingShapes_dec, _getCollaboratorsOnCurrentPage_dec, _getCollaborators_dec, __getCollaboratorsQuery_dec, _getViewportPageBounds_dec, _getViewportScreenCenter_dec, _getViewportScreenBounds_dec, _getZoomLevel_dec, _getCameraForFollowing_dec, _getViewportPageBoundsForFollowing_dec, _getCamera_dec, __unsafe_getCameraId_dec, _getErasingShapes_dec, _getErasingShapeIds_dec, _getHintingShape_dec, _getHintingShapeIds_dec, _getHoveredShape_dec, _getHoveredShapeId_dec, _getRichTextEditor_dec, _getEditingShape_dec, _getEditingShapeId_dec, _getFocusedGroup_dec, _getFocusedGroupId_dec, _getSelectionRotatedScreenBounds_dec, _getSelectionRotatedPageBounds_dec, _getSelectionRotation_dec, _getSelectionPageBounds_dec, _getOnlySelectedShape_dec, _getOnlySelectedShapeId_dec, _getCurrentPageShapesInReadingOrder_dec, _getSelectedShapes_dec, _getSelectedShapeIds_dec, __getCurrentPageStateId_dec, _getCurrentPageState_dec, __getPageStatesQuery_dec, _getPageStates_dec, _getIsMenuOpen_dec, _getOpenMenus_dec, _getInstanceState_dec, _getDocumentSettings_dec, _getCurrentToolId_dec, _getCurrentTool_dec, _getPath_dec, _getCanRedo_dec, _getCanUndo_dec, _getIsShapeHiddenCache_dec, _a, _init;
127
+ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_dec = [import_state.computed], _getCanUndo_dec = [import_state.computed], _getCanRedo_dec = [import_state.computed], _getPath_dec = [import_state.computed], _getCurrentTool_dec = [import_state.computed], _getCurrentToolId_dec = [import_state.computed], _getDocumentSettings_dec = [import_state.computed], _getInstanceState_dec = [import_state.computed], _getOpenMenus_dec = [import_state.computed], _getIsMenuOpen_dec = [import_state.computed], _getPageStates_dec = [import_state.computed], __getPageStatesQuery_dec = [import_state.computed], _getCurrentPageState_dec = [import_state.computed], __getCurrentPageStateId_dec = [import_state.computed], _getSelectedShapeIds_dec = [import_state.computed], _getSelectedShapes_dec = [import_state.computed], _getCurrentPageShapesInReadingOrder_dec = [import_state.computed], _getOnlySelectedShapeId_dec = [import_state.computed], _getOnlySelectedShape_dec = [import_state.computed], _getSelectionPageBounds_dec = [import_state.computed], _getSelectionRotation_dec = [import_state.computed], _getSelectionRotatedPageBounds_dec = [import_state.computed], _getSelectionRotatedScreenBounds_dec = [import_state.computed], _getFocusedGroupId_dec = [import_state.computed], _getFocusedGroup_dec = [import_state.computed], _getEditingShapeId_dec = [import_state.computed], _getEditingShape_dec = [import_state.computed], _getRichTextEditor_dec = [import_state.computed], _getHoveredShapeId_dec = [import_state.computed], _getHoveredShape_dec = [import_state.computed], _getHintingShapeIds_dec = [import_state.computed], _getHintingShape_dec = [import_state.computed], _getErasingShapeIds_dec = [import_state.computed], _getErasingShapes_dec = [import_state.computed], __unsafe_getCameraId_dec = [import_state.computed], _getCamera_dec = [import_state.computed], _getViewportPageBoundsForFollowing_dec = [import_state.computed], _getCameraForFollowing_dec = [import_state.computed], _getZoomLevel_dec = [import_state.computed], _getViewportScreenBounds_dec = [import_state.computed], _getViewportScreenCenter_dec = [import_state.computed], _getViewportPageBounds_dec = [import_state.computed], __getCollaboratorsQuery_dec = [import_state.computed], _getCollaborators_dec = [import_state.computed], _getCollaboratorsOnCurrentPage_dec = [import_state.computed], _getRenderingShapes_dec = [import_state.computed], __getAllPagesQuery_dec = [import_state.computed], _getPages_dec = [import_state.computed], _getCurrentPageId_dec = [import_state.computed], _getCurrentPageShapeIdsSorted_dec = [import_state.computed], __getAllAssetsQuery_dec = [import_state.computed], __getShapeHandlesCache_dec = [import_state.computed], __getShapePageTransformCache_dec = [import_state.computed], __getShapePageBoundsCache_dec = [import_state.computed], __getShapeClipPathCache_dec = [import_state.computed], __getShapeMaskCache_dec = [import_state.computed], __getShapeMaskedPageBoundsCache_dec = [import_state.computed], _getNotVisibleShapes_dec = [import_state.computed], _getCulledShapes_dec = [import_state.computed], _getCurrentPageBounds_dec = [import_state.computed], _getCurrentPageShapes_dec = [import_state.computed], _getCurrentPageShapesSorted_dec = [import_state.computed], _getCurrentPageRenderingShapesSorted_dec = [import_state.computed], __getBindingsIndexCache_dec = [import_state.computed], __getSelectionSharedStyles_dec = [import_state.computed], _getSharedStyles_dec = [(0, import_state.computed)({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [import_state.computed], _getIsFocused_dec = [import_state.computed], _getIsReadonly_dec = [import_state.computed], __setShiftKeyTimeout_dec = [import_utils.bind], __setAltKeyTimeout_dec = [import_utils.bind], __setCtrlKeyTimeout_dec = [import_utils.bind], __setMetaKeyTimeout_dec = [import_utils.bind], _a) {
128
128
  constructor({
129
129
  store,
130
130
  user,
@@ -302,6 +302,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
302
302
  __publicField(this, "_currentPageShapeIds");
303
303
  /* --------------------- Shapes --------------------- */
304
304
  __publicField(this, "_shapeGeometryCaches", {});
305
+ __publicField(this, "_notVisibleShapes", (0, import_notVisibleShapes.notVisibleShapes)(this));
305
306
  // Parents and children
306
307
  /**
307
308
  * A cache of parents to children.
@@ -322,6 +323,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
322
323
  __publicField(this, "externalContentHandlers", {
323
324
  text: null,
324
325
  files: null,
326
+ "file-replace": null,
325
327
  embed: null,
326
328
  "svg-text": null,
327
329
  url: null,
@@ -438,6 +440,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
438
440
  this.disposables.add(() => this.user.dispose());
439
441
  this.getContainer = getContainer;
440
442
  this.textMeasure = new import_TextManager.TextManager(this);
443
+ this.disposables.add(() => this.textMeasure.dispose());
441
444
  this.fonts = new import_FontManager.FontManager(this, fontAssetUrls);
442
445
  this._tickManager = new import_TickManager.TickManager(this);
443
446
  class NewRoot extends import_RootState.RootState {
@@ -558,20 +561,21 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
558
561
  shape: {
559
562
  afterChange: (shapeBefore, shapeAfter) => {
560
563
  for (const binding of this.getBindingsInvolvingShape(shapeAfter)) {
561
- if ((0, import_areShapesContentEqual.areShapesContentEqual)(shapeBefore, shapeAfter)) continue;
562
564
  invalidBindingTypes.add(binding.type);
563
565
  if (binding.fromId === shapeAfter.id) {
564
566
  this.getBindingUtil(binding).onAfterChangeFromShape?.({
565
567
  binding,
566
568
  shapeBefore,
567
- shapeAfter
569
+ shapeAfter,
570
+ reason: "self"
568
571
  });
569
572
  }
570
573
  if (binding.toId === shapeAfter.id) {
571
574
  this.getBindingUtil(binding).onAfterChangeToShape?.({
572
575
  binding,
573
576
  shapeBefore,
574
- shapeAfter
577
+ shapeAfter,
578
+ reason: "self"
575
579
  });
576
580
  }
577
581
  }
@@ -585,14 +589,16 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
585
589
  this.getBindingUtil(binding).onAfterChangeFromShape?.({
586
590
  binding,
587
591
  shapeBefore: descendantShape,
588
- shapeAfter: descendantShape
592
+ shapeAfter: descendantShape,
593
+ reason: "ancestry"
589
594
  });
590
595
  }
591
596
  if (binding.toId === descendantShape.id) {
592
597
  this.getBindingUtil(binding).onAfterChangeToShape?.({
593
598
  binding,
594
599
  shapeBefore: descendantShape,
595
- shapeAfter: descendantShape
600
+ shapeAfter: descendantShape,
601
+ reason: "ancestry"
596
602
  });
597
603
  }
598
604
  }
@@ -1636,6 +1642,19 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1636
1642
  getSelectionPageBounds() {
1637
1643
  return this.getShapesPageBounds(this.getSelectedShapeIds());
1638
1644
  }
1645
+ /**
1646
+ * The bounds of the selection bounding box in the current page space.
1647
+ *
1648
+ * @readonly
1649
+ * @public
1650
+ */
1651
+ getSelectionScreenBounds() {
1652
+ const bounds = this.getSelectionPageBounds();
1653
+ if (!bounds) return void 0;
1654
+ const { x, y } = this.pageToScreen(bounds.point);
1655
+ const zoom = this.getZoomLevel();
1656
+ return new import_Box.Box(x, y, bounds.width * zoom, bounds.height * zoom);
1657
+ }
1639
1658
  /**
1640
1659
  * @internal
1641
1660
  */
@@ -2769,7 +2788,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
2769
2788
  * @public
2770
2789
  */
2771
2790
  updateViewportScreenBounds(screenBounds, center = false) {
2772
- if (screenBounds instanceof HTMLElement) {
2791
+ if (!(screenBounds instanceof import_Box.Box)) {
2773
2792
  const rect = screenBounds.getBoundingClientRect();
2774
2793
  screenBounds = new import_Box.Box(
2775
2794
  rect.left || rect.x,
@@ -3815,17 +3834,24 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3815
3834
  }
3816
3835
  return void 0;
3817
3836
  }
3818
- isShapeOrAncestorLocked(arg) {
3819
- const shape = typeof arg === "string" ? this.getShape(arg) : arg;
3820
- if (shape === void 0) return false;
3821
- if (shape.isLocked) return true;
3822
- return this.isShapeOrAncestorLocked(this.getShapeParent(shape));
3837
+ /**
3838
+ * Check whether a shape or its parent is locked.
3839
+ *
3840
+ * @param shape - The shape (or shape id) to check.
3841
+ *
3842
+ * @public
3843
+ */
3844
+ isShapeOrAncestorLocked(shape) {
3845
+ const _shape = shape && this.getShape(shape);
3846
+ if (_shape === void 0) return false;
3847
+ if (_shape.isLocked) return true;
3848
+ return this.isShapeOrAncestorLocked(this.getShapeParent(_shape));
3823
3849
  }
3824
- _notVisibleShapes() {
3825
- return (0, import_notVisibleShapes.notVisibleShapes)(this);
3850
+ getNotVisibleShapes() {
3851
+ return this._notVisibleShapes.get();
3826
3852
  }
3827
3853
  getCulledShapes() {
3828
- const notVisibleShapes2 = this._notVisibleShapes().get();
3854
+ const notVisibleShapes2 = this.getNotVisibleShapes();
3829
3855
  const selectedShapeIds = this.getSelectedShapeIds();
3830
3856
  const editingId = this.getEditingShapeId();
3831
3857
  const culledShapes = new Set(notVisibleShapes2);
@@ -3970,18 +3996,18 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3970
3996
  * @example
3971
3997
  * ```ts
3972
3998
  * editor.getShapesAtPoint({ x: 100, y: 100 })
3973
- * editor.getShapesAtPoint({ x: 100, y: 100 }, { hitInside: true, exact: true })
3999
+ * editor.getShapesAtPoint({ x: 100, y: 100 }, { hitInside: true, margin: 8 })
3974
4000
  * ```
3975
4001
  *
3976
4002
  * @param point - The page point to test.
3977
4003
  * @param opts - The options for the hit point testing.
3978
4004
  *
4005
+ * @returns An array of shapes at the given point, sorted in reverse order of their absolute z-index (top-most shape first).
4006
+ *
3979
4007
  * @public
3980
4008
  */
3981
4009
  getShapesAtPoint(point, opts = {}) {
3982
- return this.getCurrentPageShapes().filter(
3983
- (shape) => !this.isShapeHidden(shape) && this.isPointInShape(shape, point, opts)
3984
- );
4010
+ return this.getCurrentPageShapesSorted().filter((shape) => !this.isShapeHidden(shape) && this.isPointInShape(shape, point, opts)).reverse();
3985
4011
  }
3986
4012
  /**
3987
4013
  * Test whether a point (in the current page space) will will a shape. This method takes into account masks,
@@ -4105,7 +4131,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4105
4131
  if (!id) return void 0;
4106
4132
  const freshShape = this.getShape(id);
4107
4133
  if (freshShape === void 0 || !(0, import_tlschema.isShapeId)(freshShape.parentId)) return void 0;
4108
- return this.store.get(freshShape.parentId);
4134
+ return this.getShape(freshShape.parentId);
4109
4135
  }
4110
4136
  /**
4111
4137
  * If siblingShape and targetShape are siblings, this returns targetShape. If targetShape has an
@@ -4237,6 +4263,9 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4237
4263
  if (!pagePoint) continue;
4238
4264
  const newPoint = invertedParentTransform.applyToPoint(pagePoint);
4239
4265
  const newRotation = pageTransform.rotation() - parentPageRotation;
4266
+ if (shape.id === parentId) {
4267
+ throw Error("Attempted to reparent a shape to itself!");
4268
+ }
4240
4269
  changes.push({
4241
4270
  id: shape.id,
4242
4271
  type: shape.type,
@@ -4329,6 +4358,10 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4329
4358
  }
4330
4359
  return shapeIds;
4331
4360
  }
4361
+ /** @deprecated Use {@link Editor.getDraggingOverShape} instead */
4362
+ getDroppingOverShape(point, droppingShapes) {
4363
+ return this.getDraggingOverShape(point, droppingShapes);
4364
+ }
4332
4365
  /**
4333
4366
  * Get the shape that some shapes should be dropped on at a given point.
4334
4367
  *
@@ -4339,22 +4372,20 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4339
4372
  *
4340
4373
  * @public
4341
4374
  */
4342
- getDroppingOverShape(point, droppingShapes = []) {
4343
- const currentPageShapesSorted = this.getCurrentPageShapesSorted();
4344
- for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
4345
- const shape = currentPageShapesSorted[i];
4346
- if (
4347
- // ignore hidden shapes
4348
- this.isShapeHidden(shape) || // don't allow dropping on selected shapes
4349
- this.getSelectedShapeIds().includes(shape.id) || // only allow shapes that can receive children
4350
- !this.getShapeUtil(shape).canDropShapes(shape, droppingShapes) || // don't allow dropping a shape on itself or one of it's children
4351
- droppingShapes.find((s) => s.id === shape.id || this.hasAncestor(shape, s.id))
4352
- ) {
4353
- continue;
4354
- }
4355
- const maskedPageBounds = this.getShapeMaskedPageBounds(shape.id);
4356
- if (maskedPageBounds && maskedPageBounds.containsPoint(point) && this.getShapeGeometry(shape).hitTestPoint(this.getPointInShapeSpace(shape, point), 0, true)) {
4357
- return shape;
4375
+ getDraggingOverShape(point, droppingShapes) {
4376
+ const draggingShapes = (0, import_utils.compact)(droppingShapes.map((s) => this.getShape(s))).filter(
4377
+ (s) => !s.isLocked && !this.isShapeHidden(s)
4378
+ );
4379
+ const maybeDraggingOverShapes = this.getShapesAtPoint(point, {
4380
+ hitInside: true,
4381
+ margin: 0
4382
+ }).filter(
4383
+ (s) => !droppingShapes.includes(s) && !s.isLocked && !this.isShapeHidden(s) && !draggingShapes.includes(s)
4384
+ );
4385
+ for (const maybeDraggingOverShape of maybeDraggingOverShapes) {
4386
+ const shapeUtil = this.getShapeUtil(maybeDraggingOverShape);
4387
+ if (shapeUtil.onDragShapesOver || shapeUtil.onDragShapesIn || shapeUtil.onDragShapesOut || shapeUtil.onDropShapesOver) {
4388
+ return maybeDraggingOverShape;
4358
4389
  }
4359
4390
  }
4360
4391
  }
@@ -4631,7 +4662,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4631
4662
  */
4632
4663
  duplicateShapes(shapes, offset) {
4633
4664
  this.run(() => {
4634
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4665
+ const _ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4666
+ const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids);
4635
4667
  if (ids.length <= 0) return this;
4636
4668
  const initialIds = new Set(ids);
4637
4669
  const shapeIdSet = this.getShapeAndDescendantIds(ids);
@@ -4695,8 +4727,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4695
4727
  shape.index = index;
4696
4728
  });
4697
4729
  const shapesToCreate = shapesToCreateWithOriginals.map(({ shape }) => shape);
4698
- const maxShapesReached = shapesToCreate.length + this.getCurrentPageShapeIds().size > this.options.maxShapesPerPage;
4699
- if (maxShapesReached) {
4730
+ if (!this.canCreateShapes(shapesToCreate)) {
4700
4731
  alertMaxShapes(this);
4701
4732
  return;
4702
4733
  }
@@ -5711,6 +5742,26 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5711
5742
  getInitialMetaForShape(_shape) {
5712
5743
  return {};
5713
5744
  }
5745
+ /**
5746
+ * Get whether the provided shape can be created.
5747
+ *
5748
+ * @param shape - The shape or shape IDs to check.
5749
+ *
5750
+ * @public
5751
+ */
5752
+ canCreateShape(shape) {
5753
+ return this.canCreateShapes([shape]);
5754
+ }
5755
+ /**
5756
+ * Get whether the provided shapes can be created.
5757
+ *
5758
+ * @param shapes - The shapes or shape IDs to create.
5759
+ *
5760
+ * @public
5761
+ */
5762
+ canCreateShapes(shapes) {
5763
+ return shapes.length + this.getCurrentPageShapeIds().size <= this.options.maxShapesPerPage;
5764
+ }
5714
5765
  /**
5715
5766
  * Create a single shape.
5716
5767
  *
@@ -5764,7 +5815,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5764
5815
  let parentId = this.getFocusedGroupId();
5765
5816
  for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
5766
5817
  const parent = currentPageShapesSorted[i];
5767
- if (!this.isShapeHidden(parent) && this.getShapeUtil(parent).canReceiveNewChildrenOfType(parent, partial.type) && this.isPointInShape(
5818
+ const util = this.getShapeUtil(parent);
5819
+ if (util.canReceiveNewChildrenOfType(parent, partial.type) && !this.isShapeHidden(parent) && this.isPointInShape(
5768
5820
  parent,
5769
5821
  // If no parent is provided, then we can treat the
5770
5822
  // shape's provided x/y as being in the page's space.
@@ -5839,6 +5891,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5839
5891
  ...shape.meta
5840
5892
  };
5841
5893
  });
5894
+ this.emit("created-shapes", shapeRecordsToCreate);
5895
+ this.emit("edit");
5842
5896
  this.store.put(shapeRecordsToCreate);
5843
5897
  });
5844
5898
  return this;
@@ -6080,6 +6134,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
6080
6134
  updated = this.getShapeUtil(shape).onBeforeUpdate?.(shape, updated) ?? updated;
6081
6135
  updates.push(updated);
6082
6136
  }
6137
+ this.emit("edited-shapes", updates);
6138
+ this.emit("edit");
6083
6139
  this.store.put(updates);
6084
6140
  });
6085
6141
  }
@@ -6101,6 +6157,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
6101
6157
  allShapeIdsToDelete.add(childId);
6102
6158
  });
6103
6159
  }
6160
+ this.emit("deleted-shapes", [...allShapeIdsToDelete]);
6161
+ this.emit("edit");
6104
6162
  return this.run(() => this.store.remove([...allShapeIdsToDelete]));
6105
6163
  }
6106
6164
  deleteShape(_id) {
@@ -6444,6 +6502,14 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
6444
6502
  async putExternalContent(info) {
6445
6503
  return this.externalContentHandlers[info.type]?.(info);
6446
6504
  }
6505
+ /**
6506
+ * Handle replacing external content.
6507
+ *
6508
+ * @param info - Info about the external content.
6509
+ */
6510
+ async replaceExternalContent(info) {
6511
+ return this.externalContentHandlers[info.type]?.(info);
6512
+ }
6447
6513
  /**
6448
6514
  * Get content that can be exported for the given shape ids.
6449
6515
  *
@@ -6861,7 +6927,9 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
6861
6927
  previousScreenPoint,
6862
6928
  previousPagePoint,
6863
6929
  currentScreenPoint,
6864
- currentPagePoint
6930
+ currentPagePoint,
6931
+ originScreenPoint,
6932
+ originPagePoint
6865
6933
  } = this.inputs;
6866
6934
  const { screenBounds } = this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID);
6867
6935
  const { x: cx, y: cy, z: cz } = (0, import_state.unsafe__withoutCapture)(() => this.getCamera());
@@ -6879,8 +6947,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
6879
6947
  this.inputs.isPen = info.type === "pointer" && info.isPen;
6880
6948
  if (info.name === "pointer_down" || this.inputs.isPinching) {
6881
6949
  pointerVelocity.set(0, 0);
6882
- this.inputs.originScreenPoint.setTo(currentScreenPoint);
6883
- this.inputs.originPagePoint.setTo(currentPagePoint);
6950
+ originScreenPoint.setTo(currentScreenPoint);
6951
+ originPagePoint.setTo(currentPagePoint);
6884
6952
  }
6885
6953
  this.run(
6886
6954
  () => {
@@ -7770,7 +7838,7 @@ __decorateElement(_init, 1, "_getShapePageBoundsCache", __getShapePageBoundsCach
7770
7838
  __decorateElement(_init, 1, "_getShapeClipPathCache", __getShapeClipPathCache_dec, Editor);
7771
7839
  __decorateElement(_init, 1, "_getShapeMaskCache", __getShapeMaskCache_dec, Editor);
7772
7840
  __decorateElement(_init, 1, "_getShapeMaskedPageBoundsCache", __getShapeMaskedPageBoundsCache_dec, Editor);
7773
- __decorateElement(_init, 1, "_notVisibleShapes", __notVisibleShapes_dec, Editor);
7841
+ __decorateElement(_init, 1, "getNotVisibleShapes", _getNotVisibleShapes_dec, Editor);
7774
7842
  __decorateElement(_init, 1, "getCulledShapes", _getCulledShapes_dec, Editor);
7775
7843
  __decorateElement(_init, 1, "getCurrentPageBounds", _getCurrentPageBounds_dec, Editor);
7776
7844
  __decorateElement(_init, 1, "getCurrentPageShapes", _getCurrentPageShapes_dec, Editor);