@tldraw/editor 3.14.0-canary.a2263c31d532 → 3.14.0-canary.a46dd7192bcb

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 (180) hide show
  1. package/dist-cjs/index.d.ts +166 -76
  2. package/dist-cjs/index.js +11 -10
  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 +131 -100
  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/derivations/bindingsIndex.js +22 -22
  10. package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
  11. package/dist-cjs/lib/editor/derivations/parentsToChildren.js +16 -16
  12. package/dist-cjs/lib/editor/derivations/parentsToChildren.js.map +2 -2
  13. package/dist-cjs/lib/editor/managers/{ClickManager.js → ClickManager/ClickManager.js} +1 -1
  14. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +7 -0
  15. package/dist-cjs/lib/editor/managers/{EdgeScrollManager.js → EdgeScrollManager/EdgeScrollManager.js} +2 -2
  16. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +7 -0
  17. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +7 -0
  18. package/dist-cjs/lib/editor/managers/{FontManager.js → FontManager/FontManager.js} +4 -1
  19. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +7 -0
  20. package/dist-cjs/lib/editor/managers/{HistoryManager.js → HistoryManager/HistoryManager.js} +67 -7
  21. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +7 -0
  22. package/dist-cjs/lib/editor/managers/{ScribbleManager.js → ScribbleManager/ScribbleManager.js} +1 -1
  23. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +7 -0
  24. package/dist-cjs/lib/editor/managers/{TextManager.js → TextManager/TextManager.js} +73 -42
  25. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +7 -0
  26. package/dist-cjs/lib/editor/managers/{TickManager.js → TickManager/TickManager.js} +1 -1
  27. package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +7 -0
  28. package/dist-cjs/lib/editor/managers/{UserPreferencesManager.js → UserPreferencesManager/UserPreferencesManager.js} +1 -1
  29. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +7 -0
  30. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +0 -10
  31. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  32. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -1
  33. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +1 -1
  34. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +10 -6
  35. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +3 -3
  36. package/dist-cjs/lib/editor/tools/StateNode.js +3 -3
  37. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  38. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  39. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  40. package/dist-cjs/lib/exports/getSvgJsx.js.map +1 -1
  41. package/dist-cjs/lib/hooks/useCanvasEvents.js +1 -2
  42. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  43. package/dist-cjs/lib/primitives/Box.js +33 -39
  44. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  45. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +6 -2
  46. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  47. package/dist-cjs/lib/utils/areShapesContentEqual.js +1 -1
  48. package/dist-cjs/lib/utils/areShapesContentEqual.js.map +2 -2
  49. package/dist-cjs/lib/utils/reorderShapes.js +11 -10
  50. package/dist-cjs/lib/utils/reorderShapes.js.map +2 -2
  51. package/dist-cjs/lib/utils/reparenting.js +232 -0
  52. package/dist-cjs/lib/utils/reparenting.js.map +7 -0
  53. package/dist-cjs/lib/utils/richText.js +7 -2
  54. package/dist-cjs/lib/utils/richText.js.map +2 -2
  55. package/dist-cjs/version.js +3 -3
  56. package/dist-cjs/version.js.map +1 -1
  57. package/dist-esm/index.d.mts +166 -76
  58. package/dist-esm/index.mjs +15 -10
  59. package/dist-esm/index.mjs.map +2 -2
  60. package/dist-esm/lib/config/TLSessionStateSnapshot.mjs +1 -1
  61. package/dist-esm/lib/config/TLSessionStateSnapshot.mjs.map +2 -2
  62. package/dist-esm/lib/editor/Editor.mjs +131 -100
  63. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  64. package/dist-esm/lib/editor/bindings/BindingUtil.mjs.map +2 -2
  65. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +22 -22
  66. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
  67. package/dist-esm/lib/editor/derivations/parentsToChildren.mjs +16 -16
  68. package/dist-esm/lib/editor/derivations/parentsToChildren.mjs.map +2 -2
  69. package/dist-esm/lib/editor/managers/{ClickManager.mjs → ClickManager/ClickManager.mjs} +1 -1
  70. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +7 -0
  71. package/dist-esm/lib/editor/managers/{EdgeScrollManager.mjs → EdgeScrollManager/EdgeScrollManager.mjs} +2 -2
  72. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +7 -0
  73. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +7 -0
  74. package/dist-esm/lib/editor/managers/{FontManager.mjs → FontManager/FontManager.mjs} +4 -1
  75. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +7 -0
  76. package/dist-esm/lib/editor/managers/{HistoryManager.mjs → HistoryManager/HistoryManager.mjs} +63 -3
  77. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +7 -0
  78. package/dist-esm/lib/editor/managers/{ScribbleManager.mjs → ScribbleManager/ScribbleManager.mjs} +1 -1
  79. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +7 -0
  80. package/dist-esm/lib/editor/managers/{TextManager.mjs → TextManager/TextManager.mjs} +73 -42
  81. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +7 -0
  82. package/dist-esm/lib/editor/managers/{TickManager.mjs → TickManager/TickManager.mjs} +1 -1
  83. package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +7 -0
  84. package/dist-esm/lib/editor/managers/{UserPreferencesManager.mjs → UserPreferencesManager/UserPreferencesManager.mjs} +1 -1
  85. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +7 -0
  86. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +0 -10
  87. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  88. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -1
  89. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +1 -1
  90. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +10 -6
  91. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +3 -3
  92. package/dist-esm/lib/editor/tools/StateNode.mjs +3 -3
  93. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  94. package/dist-esm/lib/exports/getSvgJsx.mjs.map +1 -1
  95. package/dist-esm/lib/hooks/useCanvasEvents.mjs +1 -2
  96. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  97. package/dist-esm/lib/primitives/Box.mjs +33 -39
  98. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  99. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +6 -2
  100. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  101. package/dist-esm/lib/utils/areShapesContentEqual.mjs +1 -1
  102. package/dist-esm/lib/utils/areShapesContentEqual.mjs.map +2 -2
  103. package/dist-esm/lib/utils/reorderShapes.mjs +11 -10
  104. package/dist-esm/lib/utils/reorderShapes.mjs.map +2 -2
  105. package/dist-esm/lib/utils/reparenting.mjs +216 -0
  106. package/dist-esm/lib/utils/reparenting.mjs.map +7 -0
  107. package/dist-esm/lib/utils/richText.mjs +8 -3
  108. package/dist-esm/lib/utils/richText.mjs.map +2 -2
  109. package/dist-esm/version.mjs +3 -3
  110. package/dist-esm/version.mjs.map +1 -1
  111. package/editor.css +442 -492
  112. package/package.json +8 -9
  113. package/src/index.ts +20 -8
  114. package/src/lib/config/TLSessionStateSnapshot.ts +1 -1
  115. package/src/lib/editor/Editor.test.ts +252 -3
  116. package/src/lib/editor/Editor.ts +149 -109
  117. package/src/lib/editor/bindings/BindingUtil.ts +6 -0
  118. package/src/lib/editor/derivations/bindingsIndex.ts +27 -26
  119. package/src/lib/editor/derivations/parentsToChildren.ts +28 -25
  120. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +442 -0
  121. package/src/lib/editor/managers/{ClickManager.ts → ClickManager/ClickManager.ts} +3 -3
  122. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +374 -0
  123. package/src/lib/editor/managers/{EdgeScrollManager.ts → EdgeScrollManager/EdgeScrollManager.ts} +3 -3
  124. package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +455 -0
  125. package/src/lib/editor/managers/{FocusManager.ts → FocusManager/FocusManager.ts} +1 -1
  126. package/src/lib/editor/managers/FontManager/FontManager.test.ts +263 -0
  127. package/src/lib/editor/managers/{FontManager.ts → FontManager/FontManager.ts} +5 -2
  128. package/src/lib/editor/managers/{HistoryManager.test.ts → HistoryManager/HistoryManager.test.ts} +388 -1
  129. package/src/lib/editor/managers/{HistoryManager.ts → HistoryManager/HistoryManager.ts} +76 -3
  130. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +624 -0
  131. package/src/lib/editor/managers/{ScribbleManager.ts → ScribbleManager/ScribbleManager.ts} +2 -2
  132. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +485 -0
  133. package/src/lib/editor/managers/TextManager/TextManager.test.ts +407 -0
  134. package/src/lib/editor/managers/{TextManager.ts → TextManager/TextManager.ts} +119 -87
  135. package/src/lib/editor/managers/TickManager/TickManager.test.ts +314 -0
  136. package/src/lib/editor/managers/{TickManager.ts → TickManager/TickManager.ts} +2 -2
  137. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +591 -0
  138. package/src/lib/editor/managers/{UserPreferencesManager.ts → UserPreferencesManager/UserPreferencesManager.ts} +2 -2
  139. package/src/lib/editor/shapes/ShapeUtil.ts +48 -16
  140. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +1 -1
  141. package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +22 -17
  142. package/src/lib/editor/tools/StateNode.ts +3 -3
  143. package/src/lib/editor/types/emit-types.ts +4 -0
  144. package/src/lib/editor/types/external-content.ts +11 -2
  145. package/src/lib/exports/getSvgJsx.tsx +1 -1
  146. package/src/lib/hooks/useCanvasEvents.ts +0 -1
  147. package/src/lib/primitives/Box.test.ts +588 -7
  148. package/src/lib/primitives/Box.ts +33 -41
  149. package/src/lib/primitives/geometry/Geometry2d.ts +7 -2
  150. package/src/lib/utils/areShapesContentEqual.ts +1 -2
  151. package/src/lib/utils/reorderShapes.ts +10 -13
  152. package/src/lib/utils/reparenting.ts +383 -0
  153. package/src/lib/utils/richText.ts +10 -4
  154. package/src/version.ts +3 -3
  155. package/dist-cjs/lib/editor/managers/ClickManager.js.map +0 -7
  156. package/dist-cjs/lib/editor/managers/EdgeScrollManager.js.map +0 -7
  157. package/dist-cjs/lib/editor/managers/FocusManager.js.map +0 -7
  158. package/dist-cjs/lib/editor/managers/FontManager.js.map +0 -7
  159. package/dist-cjs/lib/editor/managers/HistoryManager.js.map +0 -7
  160. package/dist-cjs/lib/editor/managers/ScribbleManager.js.map +0 -7
  161. package/dist-cjs/lib/editor/managers/Stack.js +0 -82
  162. package/dist-cjs/lib/editor/managers/Stack.js.map +0 -7
  163. package/dist-cjs/lib/editor/managers/TextManager.js.map +0 -7
  164. package/dist-cjs/lib/editor/managers/TickManager.js.map +0 -7
  165. package/dist-cjs/lib/editor/managers/UserPreferencesManager.js.map +0 -7
  166. package/dist-esm/lib/editor/managers/ClickManager.mjs.map +0 -7
  167. package/dist-esm/lib/editor/managers/EdgeScrollManager.mjs.map +0 -7
  168. package/dist-esm/lib/editor/managers/FocusManager.mjs.map +0 -7
  169. package/dist-esm/lib/editor/managers/FontManager.mjs.map +0 -7
  170. package/dist-esm/lib/editor/managers/HistoryManager.mjs.map +0 -7
  171. package/dist-esm/lib/editor/managers/ScribbleManager.mjs.map +0 -7
  172. package/dist-esm/lib/editor/managers/Stack.mjs +0 -62
  173. package/dist-esm/lib/editor/managers/Stack.mjs.map +0 -7
  174. package/dist-esm/lib/editor/managers/TextManager.mjs.map +0 -7
  175. package/dist-esm/lib/editor/managers/TickManager.mjs.map +0 -7
  176. package/dist-esm/lib/editor/managers/UserPreferencesManager.mjs.map +0 -7
  177. package/src/lib/editor/managers/ScribbleManager.test.ts +0 -32
  178. package/src/lib/editor/managers/Stack.ts +0 -71
  179. /package/dist-cjs/lib/editor/managers/{FocusManager.js → FocusManager/FocusManager.js} +0 -0
  180. /package/dist-esm/lib/editor/managers/{FocusManager.mjs → FocusManager/FocusManager.mjs} +0 -0
@@ -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']>[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,SAAiB,gBAAgB;AAEjC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,SAAS;AAClB,OAAO,aAAa;AACpB,SAAS,aAAa;AAEtB,MAAM,WAAW;AAEjB,MAAM,SAAS,WAAW;AAS1B,SAAS,MAAM;AACd,MAAI,CAAC,OAAQ,QAAO;AACpB,SACC,CAAC,kBAAkB,oBAAoB,kBAAkB,QAAQ,UAAU,MAAM,EAAE;AAAA;AAAA,IAElF,OAAO,UAAU;AAAA,EAClB;AAAA,EAEC,MAAM,YAAY,gBAAgB;AAErC;AAMO,MAAM,SAAiB,SAC1B,OAAO,QAAQ,KACjB,sBAAsB,QAAQ,KAC9B,8BAA8B,SAAS,IACtC;AACH,IAAI,QAAQ;AACX,SAAO,QAAQ,IAAI;AACnB,MAAI,IAAI,GAAG;AAOV,wBAAoB,UAAU,MAAM;AAAA,EACrC,OAAO;AACN,6BAAyB,QAAQ;AAAA,EAClC;AACD;AAEA,QAAQ,iBAAiB,g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M;AAAA,IAC5B;AAAA,EACD;AAIA,QAAM,cAAc,gBAAgB;AAAA,IACnC,CAAC,MAAM,EAAE,aAAa,cAAc,EAAE,OAAO;AAAA,EAC9C,EAAE,CAAC;AACH,MAAI,CAAC,YAAa,QAAO;AAEzB,QAAM,SAAiC;AAAA,IACtC,SAAS;AAAA,IACT,eAAe,YAAY;AAAA,IAC3B,kBAAkB,CAAC,CAAC,YAAY;AAAA,IAChC,aAAa,CAAC,CAAC,YAAY;AAAA,IAC3B,aAAa,CAAC,CAAC,YAAY;AAAA,IAC3B,cAAc,CAAC,CAAC,YAAY;AAAA,IAC5B,YAAY;AAAA,IACZ,YAAY,gBACV,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;",
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,SAAiB,gBAAgB;AAEjC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,SAAS;AAClB,SAAS,aAAa;AAEtB,MAAM,WAAW;AAEjB,MAAM,SAAS,WAAW;AAS1B,SAAS,MAAM;AACd,MAAI,CAAC,OAAQ,QAAO;AACpB,SACC,CAAC,kBAAkB,oBAAoB,kBAAkB,QAAQ,UAAU,MAAM,EAAE;AAAA;AAAA,IAElF,OAAO,UAAU;AAAA,EAClB;AAAA,EAEC,MAAM,YAAY,gBAAgB;AAErC;AAMO,MAAM,SAAiB,SAC1B,OAAO,QAAQ,KACjB,sBAAsB,QAAQ,KAC9B,8BAA8B,SAAS,IACtC;AACH,IAAI,QAAQ;AACX,SAAO,QAAQ,IAAI;AACnB,MAAI,IAAI,GAAG;AAOV,wBAAoB,UAAU,MAAM;AAAA,EACrC,OAAO;AACN,6BAAyB,QAAQ;AAAA,EAClC;AACD;AAEA,QAAQ,iBAAiB,gBAAgB,MAAM;AAC9C,sBAAoB,UAAU,MAAM;AACrC,CAAC;AAED,MAAM,WAAW;AAAA,EAChB,SAAS;AACV;AAEA,MAAM,yCAAyC,KAAK,IAAI,GAAG,OAAO,OAAO,QAAQ,CAAC;AAElF,SAAS,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QAAM,SAAiC;AAAA,IACtC,SAAS;AAAA,IACT,eAAe,YAAY;AAAA,IAC3B,kBAAkB,CAAC,CAAC,YAAY;AAAA,IAChC,aAAa,CAAC,CAAC,YAAY;AAAA,IAC3B,aAAa,CAAC,CAAC,YAAY;AAAA,IAC3B,cAAc,CAAC,CAAC,YAAY;AAAA,IAC5B,YAAY;AAAA,IACZ,YAAY,gBACV,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
6
  "names": []
7
7
  }
@@ -46,7 +46,7 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
46
46
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
47
47
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
48
48
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
49
- 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;
49
+ 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;
50
50
  import {
51
51
  EMPTY_ARRAY,
52
52
  atom,
@@ -147,18 +147,18 @@ import { bindingsIndex } from "./derivations/bindingsIndex.mjs";
147
147
  import { notVisibleShapes } from "./derivations/notVisibleShapes.mjs";
148
148
  import { parentsToChildren } from "./derivations/parentsToChildren.mjs";
149
149
  import { deriveShapeIdsInCurrentPage } from "./derivations/shapeIdsInCurrentPage.mjs";
150
- import { ClickManager } from "./managers/ClickManager.mjs";
151
- import { EdgeScrollManager } from "./managers/EdgeScrollManager.mjs";
152
- import { FocusManager } from "./managers/FocusManager.mjs";
153
- import { FontManager } from "./managers/FontManager.mjs";
154
- import { HistoryManager } from "./managers/HistoryManager.mjs";
155
- import { ScribbleManager } from "./managers/ScribbleManager.mjs";
150
+ import { ClickManager } from "./managers/ClickManager/ClickManager.mjs";
151
+ import { EdgeScrollManager } from "./managers/EdgeScrollManager/EdgeScrollManager.mjs";
152
+ import { FocusManager } from "./managers/FocusManager/FocusManager.mjs";
153
+ import { FontManager } from "./managers/FontManager/FontManager.mjs";
154
+ import { HistoryManager } from "./managers/HistoryManager/HistoryManager.mjs";
155
+ import { ScribbleManager } from "./managers/ScribbleManager/ScribbleManager.mjs";
156
156
  import { SnapManager } from "./managers/SnapManager/SnapManager.mjs";
157
- import { TextManager } from "./managers/TextManager.mjs";
158
- import { TickManager } from "./managers/TickManager.mjs";
159
- import { UserPreferencesManager } from "./managers/UserPreferencesManager.mjs";
157
+ import { TextManager } from "./managers/TextManager/TextManager.mjs";
158
+ import { TickManager } from "./managers/TickManager/TickManager.mjs";
159
+ import { UserPreferencesManager } from "./managers/UserPreferencesManager/UserPreferencesManager.mjs";
160
160
  import { RootState } from "./tools/RootState.mjs";
161
- class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed], _getCanUndo_dec = [computed], _getCanRedo_dec = [computed], _getPath_dec = [computed], _getCurrentTool_dec = [computed], _getCurrentToolId_dec = [computed], _getDocumentSettings_dec = [computed], _getInstanceState_dec = [computed], _getOpenMenus_dec = [computed], _getIsMenuOpen_dec = [computed], _getPageStates_dec = [computed], __getPageStatesQuery_dec = [computed], _getCurrentPageState_dec = [computed], __getCurrentPageStateId_dec = [computed], _getSelectedShapeIds_dec = [computed], _getSelectedShapes_dec = [computed], _getCurrentPageShapesInReadingOrder_dec = [computed], _getOnlySelectedShapeId_dec = [computed], _getOnlySelectedShape_dec = [computed], _getSelectionPageBounds_dec = [computed], _getSelectionRotation_dec = [computed], _getSelectionRotatedPageBounds_dec = [computed], _getSelectionRotatedScreenBounds_dec = [computed], _getFocusedGroupId_dec = [computed], _getFocusedGroup_dec = [computed], _getEditingShapeId_dec = [computed], _getEditingShape_dec = [computed], _getRichTextEditor_dec = [computed], _getHoveredShapeId_dec = [computed], _getHoveredShape_dec = [computed], _getHintingShapeIds_dec = [computed], _getHintingShape_dec = [computed], _getErasingShapeIds_dec = [computed], _getErasingShapes_dec = [computed], __unsafe_getCameraId_dec = [computed], _getCamera_dec = [computed], _getViewportPageBoundsForFollowing_dec = [computed], _getCameraForFollowing_dec = [computed], _getZoomLevel_dec = [computed], _getViewportScreenBounds_dec = [computed], _getViewportScreenCenter_dec = [computed], _getViewportPageBounds_dec = [computed], __getCollaboratorsQuery_dec = [computed], _getCollaborators_dec = [computed], _getCollaboratorsOnCurrentPage_dec = [computed], _getRenderingShapes_dec = [computed], __getAllPagesQuery_dec = [computed], _getPages_dec = [computed], _getCurrentPageId_dec = [computed], _getCurrentPageShapeIdsSorted_dec = [computed], __getAllAssetsQuery_dec = [computed], __getShapeHandlesCache_dec = [computed], __getShapePageTransformCache_dec = [computed], __getShapePageBoundsCache_dec = [computed], __getShapeClipPathCache_dec = [computed], __getShapeMaskCache_dec = [computed], __getShapeMaskedPageBoundsCache_dec = [computed], __notVisibleShapes_dec = [computed], _getCulledShapes_dec = [computed], _getCurrentPageBounds_dec = [computed], _getCurrentPageShapes_dec = [computed], _getCurrentPageShapesSorted_dec = [computed], _getCurrentPageRenderingShapesSorted_dec = [computed], __getBindingsIndexCache_dec = [computed], __getSelectionSharedStyles_dec = [computed], _getSharedStyles_dec = [computed({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [computed], _getIsFocused_dec = [computed], _getIsReadonly_dec = [computed], __setShiftKeyTimeout_dec = [bind], __setAltKeyTimeout_dec = [bind], __setCtrlKeyTimeout_dec = [bind], __setMetaKeyTimeout_dec = [bind], _a) {
161
+ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed], _getCanUndo_dec = [computed], _getCanRedo_dec = [computed], _getPath_dec = [computed], _getCurrentTool_dec = [computed], _getCurrentToolId_dec = [computed], _getDocumentSettings_dec = [computed], _getInstanceState_dec = [computed], _getOpenMenus_dec = [computed], _getIsMenuOpen_dec = [computed], _getPageStates_dec = [computed], __getPageStatesQuery_dec = [computed], _getCurrentPageState_dec = [computed], __getCurrentPageStateId_dec = [computed], _getSelectedShapeIds_dec = [computed], _getSelectedShapes_dec = [computed], _getCurrentPageShapesInReadingOrder_dec = [computed], _getOnlySelectedShapeId_dec = [computed], _getOnlySelectedShape_dec = [computed], _getSelectionPageBounds_dec = [computed], _getSelectionRotation_dec = [computed], _getSelectionRotatedPageBounds_dec = [computed], _getSelectionRotatedScreenBounds_dec = [computed], _getFocusedGroupId_dec = [computed], _getFocusedGroup_dec = [computed], _getEditingShapeId_dec = [computed], _getEditingShape_dec = [computed], _getRichTextEditor_dec = [computed], _getHoveredShapeId_dec = [computed], _getHoveredShape_dec = [computed], _getHintingShapeIds_dec = [computed], _getHintingShape_dec = [computed], _getErasingShapeIds_dec = [computed], _getErasingShapes_dec = [computed], __unsafe_getCameraId_dec = [computed], _getCamera_dec = [computed], _getViewportPageBoundsForFollowing_dec = [computed], _getCameraForFollowing_dec = [computed], _getZoomLevel_dec = [computed], _getViewportScreenBounds_dec = [computed], _getViewportScreenCenter_dec = [computed], _getViewportPageBounds_dec = [computed], __getCollaboratorsQuery_dec = [computed], _getCollaborators_dec = [computed], _getCollaboratorsOnCurrentPage_dec = [computed], _getRenderingShapes_dec = [computed], __getAllPagesQuery_dec = [computed], _getPages_dec = [computed], _getCurrentPageId_dec = [computed], _getCurrentPageShapeIdsSorted_dec = [computed], __getAllAssetsQuery_dec = [computed], __getShapeHandlesCache_dec = [computed], __getShapePageTransformCache_dec = [computed], __getShapePageBoundsCache_dec = [computed], __getShapeClipPathCache_dec = [computed], __getShapeMaskCache_dec = [computed], __getShapeMaskedPageBoundsCache_dec = [computed], _getNotVisibleShapes_dec = [computed], _getCulledShapes_dec = [computed], _getCurrentPageBounds_dec = [computed], _getCurrentPageShapes_dec = [computed], _getCurrentPageShapesSorted_dec = [computed], _getCurrentPageRenderingShapesSorted_dec = [computed], __getBindingsIndexCache_dec = [computed], __getSelectionSharedStyles_dec = [computed], _getSharedStyles_dec = [computed({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [computed], _getIsFocused_dec = [computed], _getIsReadonly_dec = [computed], __setShiftKeyTimeout_dec = [bind], __setAltKeyTimeout_dec = [bind], __setCtrlKeyTimeout_dec = [bind], __setMetaKeyTimeout_dec = [bind], _a) {
162
162
  constructor({
163
163
  store,
164
164
  user,
@@ -336,7 +336,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
336
336
  __publicField(this, "_currentPageShapeIds");
337
337
  /* --------------------- Shapes --------------------- */
338
338
  __publicField(this, "_shapeGeometryCaches", {});
339
- __publicField(this, "_shapePageGeometryCaches", {});
339
+ __publicField(this, "_notVisibleShapes", notVisibleShapes(this));
340
340
  // Parents and children
341
341
  /**
342
342
  * A cache of parents to children.
@@ -357,6 +357,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
357
357
  __publicField(this, "externalContentHandlers", {
358
358
  text: null,
359
359
  files: null,
360
+ "file-replace": null,
360
361
  embed: null,
361
362
  "svg-text": null,
362
363
  url: null,
@@ -473,6 +474,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
473
474
  this.disposables.add(() => this.user.dispose());
474
475
  this.getContainer = getContainer;
475
476
  this.textMeasure = new TextManager(this);
477
+ this.disposables.add(() => this.textMeasure.dispose());
476
478
  this.fonts = new FontManager(this, fontAssetUrls);
477
479
  this._tickManager = new TickManager(this);
478
480
  class NewRoot extends RootState {
@@ -593,20 +595,21 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
593
595
  shape: {
594
596
  afterChange: (shapeBefore, shapeAfter) => {
595
597
  for (const binding of this.getBindingsInvolvingShape(shapeAfter)) {
596
- if (areShapesContentEqual(shapeBefore, shapeAfter)) continue;
597
598
  invalidBindingTypes.add(binding.type);
598
599
  if (binding.fromId === shapeAfter.id) {
599
600
  this.getBindingUtil(binding).onAfterChangeFromShape?.({
600
601
  binding,
601
602
  shapeBefore,
602
- shapeAfter
603
+ shapeAfter,
604
+ reason: "self"
603
605
  });
604
606
  }
605
607
  if (binding.toId === shapeAfter.id) {
606
608
  this.getBindingUtil(binding).onAfterChangeToShape?.({
607
609
  binding,
608
610
  shapeBefore,
609
- shapeAfter
611
+ shapeAfter,
612
+ reason: "self"
610
613
  });
611
614
  }
612
615
  }
@@ -620,14 +623,16 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
620
623
  this.getBindingUtil(binding).onAfterChangeFromShape?.({
621
624
  binding,
622
625
  shapeBefore: descendantShape,
623
- shapeAfter: descendantShape
626
+ shapeAfter: descendantShape,
627
+ reason: "ancestry"
624
628
  });
625
629
  }
626
630
  if (binding.toId === descendantShape.id) {
627
631
  this.getBindingUtil(binding).onAfterChangeToShape?.({
628
632
  binding,
629
633
  shapeBefore: descendantShape,
630
- shapeAfter: descendantShape
634
+ shapeAfter: descendantShape,
635
+ reason: "ancestry"
631
636
  });
632
637
  }
633
638
  }
@@ -1671,6 +1676,19 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
1671
1676
  getSelectionPageBounds() {
1672
1677
  return this.getShapesPageBounds(this.getSelectedShapeIds());
1673
1678
  }
1679
+ /**
1680
+ * The bounds of the selection bounding box in the current page space.
1681
+ *
1682
+ * @readonly
1683
+ * @public
1684
+ */
1685
+ getSelectionScreenBounds() {
1686
+ const bounds = this.getSelectionPageBounds();
1687
+ if (!bounds) return void 0;
1688
+ const { x, y } = this.pageToScreen(bounds.point);
1689
+ const zoom = this.getZoomLevel();
1690
+ return new Box(x, y, bounds.width * zoom, bounds.height * zoom);
1691
+ }
1674
1692
  /**
1675
1693
  * @internal
1676
1694
  */
@@ -2854,10 +2872,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
2854
2872
  }
2855
2873
  getViewportScreenCenter() {
2856
2874
  const viewportScreenBounds = this.getViewportScreenBounds();
2857
- return new Vec(
2858
- viewportScreenBounds.midX - viewportScreenBounds.minX,
2859
- viewportScreenBounds.midY - viewportScreenBounds.minY
2860
- );
2875
+ return new Vec(viewportScreenBounds.w / 2, viewportScreenBounds.h / 2);
2861
2876
  }
2862
2877
  getViewportPageBounds() {
2863
2878
  const { w, h } = this.getViewportScreenBounds();
@@ -3532,41 +3547,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
3532
3547
  typeof shape === "string" ? shape : shape.id
3533
3548
  );
3534
3549
  }
3535
- /**
3536
- * Get the geometry of a shape in page-space.
3537
- *
3538
- * @example
3539
- * ```ts
3540
- * editor.getShapePageGeometry(myShape)
3541
- * editor.getShapePageGeometry(myShapeId)
3542
- * editor.getShapePageGeometry(myShapeId, { context: "arrow" })
3543
- * ```
3544
- *
3545
- * @param shape - The shape (or shape id) to get the geometry for.
3546
- * @param opts - Additional options about the request for geometry. Passed to {@link ShapeUtil.getGeometry}.
3547
- *
3548
- * @public
3549
- */
3550
- getShapePageGeometry(shape, opts) {
3551
- const context = opts?.context ?? "none";
3552
- if (!this._shapePageGeometryCaches[context]) {
3553
- this._shapePageGeometryCaches[context] = this.store.createComputedCache(
3554
- "bounds",
3555
- (shape2) => {
3556
- const geometry = this.getShapeGeometry(shape2.id, opts);
3557
- const pageTransform = this.getShapePageTransform(shape2.id);
3558
- return geometry.transform(pageTransform);
3559
- },
3560
- {
3561
- // we only depend directly on the shape id, and changing geometry/transform will update us anyway
3562
- areRecordsEqual: () => true
3563
- }
3564
- );
3565
- }
3566
- return this._shapePageGeometryCaches[context].get(
3567
- typeof shape === "string" ? shape : shape.id
3568
- );
3569
- }
3570
3550
  _getShapeHandlesCache() {
3571
3551
  return this.store.createComputedCache(
3572
3552
  "handles",
@@ -3660,7 +3640,10 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
3660
3640
  }
3661
3641
  _getShapePageBoundsCache() {
3662
3642
  return this.store.createComputedCache("pageBoundsCache", (shape) => {
3663
- return this.getShapePageGeometry(shape).bounds;
3643
+ const pageTransform = this.getShapePageTransform(shape);
3644
+ if (!pageTransform) return void 0;
3645
+ const geometry = this.getShapeGeometry(shape);
3646
+ return Box.FromPoints(pageTransform.applyToPoints(geometry.vertices));
3664
3647
  });
3665
3648
  }
3666
3649
  /**
@@ -3717,12 +3700,11 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
3717
3700
  (shape2) => this.isShapeOfType(shape2, "frame")
3718
3701
  );
3719
3702
  if (frameAncestors.length === 0) return void 0;
3720
- const pageMask = frameAncestors.map(
3721
- (s) => (
3722
- // Apply the frame transform to the frame outline to get the frame outline in the current page space
3723
- (this.getShapePageGeometry(s.id).vertices)
3724
- )
3725
- ).reduce((acc, b) => {
3703
+ const pageMask = frameAncestors.map((s) => {
3704
+ const geometry = this.getShapeGeometry(s.id);
3705
+ const pageTransform = this.getShapePageTransform(s.id);
3706
+ return pageTransform.applyToPoints(geometry.vertices);
3707
+ }).reduce((acc, b) => {
3726
3708
  if (!(b && acc)) return void 0;
3727
3709
  const intersection = intersectPolygonPolygon(acc, b);
3728
3710
  if (intersection) {
@@ -3886,17 +3868,24 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
3886
3868
  }
3887
3869
  return void 0;
3888
3870
  }
3889
- isShapeOrAncestorLocked(arg) {
3890
- const shape = typeof arg === "string" ? this.getShape(arg) : arg;
3891
- if (shape === void 0) return false;
3892
- if (shape.isLocked) return true;
3893
- return this.isShapeOrAncestorLocked(this.getShapeParent(shape));
3871
+ /**
3872
+ * Check whether a shape or its parent is locked.
3873
+ *
3874
+ * @param shape - The shape (or shape id) to check.
3875
+ *
3876
+ * @public
3877
+ */
3878
+ isShapeOrAncestorLocked(shape) {
3879
+ const _shape = shape && this.getShape(shape);
3880
+ if (_shape === void 0) return false;
3881
+ if (_shape.isLocked) return true;
3882
+ return this.isShapeOrAncestorLocked(this.getShapeParent(_shape));
3894
3883
  }
3895
- _notVisibleShapes() {
3896
- return notVisibleShapes(this);
3884
+ getNotVisibleShapes() {
3885
+ return this._notVisibleShapes.get();
3897
3886
  }
3898
3887
  getCulledShapes() {
3899
- const notVisibleShapes2 = this._notVisibleShapes().get();
3888
+ const notVisibleShapes2 = this.getNotVisibleShapes();
3900
3889
  const selectedShapeIds = this.getSelectedShapeIds();
3901
3890
  const editingId = this.getEditingShapeId();
3902
3891
  const culledShapes = new Set(notVisibleShapes2);
@@ -4041,18 +4030,18 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4041
4030
  * @example
4042
4031
  * ```ts
4043
4032
  * editor.getShapesAtPoint({ x: 100, y: 100 })
4044
- * editor.getShapesAtPoint({ x: 100, y: 100 }, { hitInside: true, exact: true })
4033
+ * editor.getShapesAtPoint({ x: 100, y: 100 }, { hitInside: true, margin: 8 })
4045
4034
  * ```
4046
4035
  *
4047
4036
  * @param point - The page point to test.
4048
4037
  * @param opts - The options for the hit point testing.
4049
4038
  *
4039
+ * @returns An array of shapes at the given point, sorted in reverse order of their absolute z-index (top-most shape first).
4040
+ *
4050
4041
  * @public
4051
4042
  */
4052
4043
  getShapesAtPoint(point, opts = {}) {
4053
- return this.getCurrentPageShapes().filter(
4054
- (shape) => !this.isShapeHidden(shape) && this.isPointInShape(shape, point, opts)
4055
- );
4044
+ return this.getCurrentPageShapesSorted().filter((shape) => !this.isShapeHidden(shape) && this.isPointInShape(shape, point, opts)).reverse();
4056
4045
  }
4057
4046
  /**
4058
4047
  * Test whether a point (in the current page space) will will a shape. This method takes into account masks,
@@ -4176,7 +4165,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4176
4165
  if (!id) return void 0;
4177
4166
  const freshShape = this.getShape(id);
4178
4167
  if (freshShape === void 0 || !isShapeId(freshShape.parentId)) return void 0;
4179
- return this.store.get(freshShape.parentId);
4168
+ return this.getShape(freshShape.parentId);
4180
4169
  }
4181
4170
  /**
4182
4171
  * If siblingShape and targetShape are siblings, this returns targetShape. If targetShape has an
@@ -4308,6 +4297,9 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4308
4297
  if (!pagePoint) continue;
4309
4298
  const newPoint = invertedParentTransform.applyToPoint(pagePoint);
4310
4299
  const newRotation = pageTransform.rotation() - parentPageRotation;
4300
+ if (shape.id === parentId) {
4301
+ throw Error("Attempted to reparent a shape to itself!");
4302
+ }
4311
4303
  changes.push({
4312
4304
  id: shape.id,
4313
4305
  type: shape.type,
@@ -4400,6 +4392,10 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4400
4392
  }
4401
4393
  return shapeIds;
4402
4394
  }
4395
+ /** @deprecated Use {@link Editor.getDraggingOverShape} instead */
4396
+ getDroppingOverShape(point, droppingShapes) {
4397
+ return this.getDraggingOverShape(point, droppingShapes);
4398
+ }
4403
4399
  /**
4404
4400
  * Get the shape that some shapes should be dropped on at a given point.
4405
4401
  *
@@ -4410,22 +4406,20 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4410
4406
  *
4411
4407
  * @public
4412
4408
  */
4413
- getDroppingOverShape(point, droppingShapes = []) {
4414
- const currentPageShapesSorted = this.getCurrentPageShapesSorted();
4415
- for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
4416
- const shape = currentPageShapesSorted[i];
4417
- if (
4418
- // ignore hidden shapes
4419
- this.isShapeHidden(shape) || // don't allow dropping on selected shapes
4420
- this.getSelectedShapeIds().includes(shape.id) || // only allow shapes that can receive children
4421
- !this.getShapeUtil(shape).canDropShapes(shape, droppingShapes) || // don't allow dropping a shape on itself or one of it's children
4422
- droppingShapes.find((s) => s.id === shape.id || this.hasAncestor(shape, s.id))
4423
- ) {
4424
- continue;
4425
- }
4426
- const maskedPageBounds = this.getShapeMaskedPageBounds(shape.id);
4427
- if (maskedPageBounds && maskedPageBounds.containsPoint(point) && this.getShapeGeometry(shape).hitTestPoint(this.getPointInShapeSpace(shape, point), 0, true)) {
4428
- return shape;
4409
+ getDraggingOverShape(point, droppingShapes) {
4410
+ const draggingShapes = compact(droppingShapes.map((s) => this.getShape(s))).filter(
4411
+ (s) => !s.isLocked && !this.isShapeHidden(s)
4412
+ );
4413
+ const maybeDraggingOverShapes = this.getShapesAtPoint(point, {
4414
+ hitInside: true,
4415
+ margin: 0
4416
+ }).filter(
4417
+ (s) => !droppingShapes.includes(s) && !s.isLocked && !this.isShapeHidden(s) && !draggingShapes.includes(s)
4418
+ );
4419
+ for (const maybeDraggingOverShape of maybeDraggingOverShapes) {
4420
+ const shapeUtil = this.getShapeUtil(maybeDraggingOverShape);
4421
+ if (shapeUtil.onDragShapesOver || shapeUtil.onDragShapesIn || shapeUtil.onDragShapesOut || shapeUtil.onDropShapesOver) {
4422
+ return maybeDraggingOverShape;
4429
4423
  }
4430
4424
  }
4431
4425
  }
@@ -4702,7 +4696,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4702
4696
  */
4703
4697
  duplicateShapes(shapes, offset) {
4704
4698
  this.run(() => {
4705
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4699
+ const _ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4700
+ const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids);
4706
4701
  if (ids.length <= 0) return this;
4707
4702
  const initialIds = new Set(ids);
4708
4703
  const shapeIdSet = this.getShapeAndDescendantIds(ids);
@@ -4766,8 +4761,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
4766
4761
  shape.index = index;
4767
4762
  });
4768
4763
  const shapesToCreate = shapesToCreateWithOriginals.map(({ shape }) => shape);
4769
- const maxShapesReached = shapesToCreate.length + this.getCurrentPageShapeIds().size > this.options.maxShapesPerPage;
4770
- if (maxShapesReached) {
4764
+ if (!this.canCreateShapes(shapesToCreate)) {
4771
4765
  alertMaxShapes(this);
4772
4766
  return;
4773
4767
  }
@@ -5782,6 +5776,26 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
5782
5776
  getInitialMetaForShape(_shape) {
5783
5777
  return {};
5784
5778
  }
5779
+ /**
5780
+ * Get whether the provided shape can be created.
5781
+ *
5782
+ * @param shape - The shape or shape IDs to check.
5783
+ *
5784
+ * @public
5785
+ */
5786
+ canCreateShape(shape) {
5787
+ return this.canCreateShapes([shape]);
5788
+ }
5789
+ /**
5790
+ * Get whether the provided shapes can be created.
5791
+ *
5792
+ * @param shapes - The shapes or shape IDs to create.
5793
+ *
5794
+ * @public
5795
+ */
5796
+ canCreateShapes(shapes) {
5797
+ return shapes.length + this.getCurrentPageShapeIds().size <= this.options.maxShapesPerPage;
5798
+ }
5785
5799
  /**
5786
5800
  * Create a single shape.
5787
5801
  *
@@ -5835,7 +5849,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
5835
5849
  let parentId = this.getFocusedGroupId();
5836
5850
  for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
5837
5851
  const parent = currentPageShapesSorted[i];
5838
- if (!this.isShapeHidden(parent) && this.getShapeUtil(parent).canReceiveNewChildrenOfType(parent, partial.type) && this.isPointInShape(
5852
+ const util = this.getShapeUtil(parent);
5853
+ if (util.canReceiveNewChildrenOfType(parent, partial.type) && !this.isShapeHidden(parent) && this.isPointInShape(
5839
5854
  parent,
5840
5855
  // If no parent is provided, then we can treat the
5841
5856
  // shape's provided x/y as being in the page's space.
@@ -5910,6 +5925,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
5910
5925
  ...shape.meta
5911
5926
  };
5912
5927
  });
5928
+ this.emit("created-shapes", shapeRecordsToCreate);
5929
+ this.emit("edit");
5913
5930
  this.store.put(shapeRecordsToCreate);
5914
5931
  });
5915
5932
  return this;
@@ -6151,6 +6168,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
6151
6168
  updated = this.getShapeUtil(shape).onBeforeUpdate?.(shape, updated) ?? updated;
6152
6169
  updates.push(updated);
6153
6170
  }
6171
+ this.emit("edited-shapes", updates);
6172
+ this.emit("edit");
6154
6173
  this.store.put(updates);
6155
6174
  });
6156
6175
  }
@@ -6172,6 +6191,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
6172
6191
  allShapeIdsToDelete.add(childId);
6173
6192
  });
6174
6193
  }
6194
+ this.emit("deleted-shapes", [...allShapeIdsToDelete]);
6195
+ this.emit("edit");
6175
6196
  return this.run(() => this.store.remove([...allShapeIdsToDelete]));
6176
6197
  }
6177
6198
  deleteShape(_id) {
@@ -6515,6 +6536,14 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
6515
6536
  async putExternalContent(info) {
6516
6537
  return this.externalContentHandlers[info.type]?.(info);
6517
6538
  }
6539
+ /**
6540
+ * Handle replacing external content.
6541
+ *
6542
+ * @param info - Info about the external content.
6543
+ */
6544
+ async replaceExternalContent(info) {
6545
+ return this.externalContentHandlers[info.type]?.(info);
6546
+ }
6518
6547
  /**
6519
6548
  * Get content that can be exported for the given shape ids.
6520
6549
  *
@@ -6932,7 +6961,9 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
6932
6961
  previousScreenPoint,
6933
6962
  previousPagePoint,
6934
6963
  currentScreenPoint,
6935
- currentPagePoint
6964
+ currentPagePoint,
6965
+ originScreenPoint,
6966
+ originPagePoint
6936
6967
  } = this.inputs;
6937
6968
  const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID);
6938
6969
  const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera());
@@ -6950,8 +6981,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
6950
6981
  this.inputs.isPen = info.type === "pointer" && info.isPen;
6951
6982
  if (info.name === "pointer_down" || this.inputs.isPinching) {
6952
6983
  pointerVelocity.set(0, 0);
6953
- this.inputs.originScreenPoint.setTo(currentScreenPoint);
6954
- this.inputs.originPagePoint.setTo(currentPagePoint);
6984
+ originScreenPoint.setTo(currentScreenPoint);
6985
+ originPagePoint.setTo(currentPagePoint);
6955
6986
  }
6956
6987
  this.run(
6957
6988
  () => {
@@ -7841,7 +7872,7 @@ __decorateElement(_init, 1, "_getShapePageBoundsCache", __getShapePageBoundsCach
7841
7872
  __decorateElement(_init, 1, "_getShapeClipPathCache", __getShapeClipPathCache_dec, Editor);
7842
7873
  __decorateElement(_init, 1, "_getShapeMaskCache", __getShapeMaskCache_dec, Editor);
7843
7874
  __decorateElement(_init, 1, "_getShapeMaskedPageBoundsCache", __getShapeMaskedPageBoundsCache_dec, Editor);
7844
- __decorateElement(_init, 1, "_notVisibleShapes", __notVisibleShapes_dec, Editor);
7875
+ __decorateElement(_init, 1, "getNotVisibleShapes", _getNotVisibleShapes_dec, Editor);
7845
7876
  __decorateElement(_init, 1, "getCulledShapes", _getCulledShapes_dec, Editor);
7846
7877
  __decorateElement(_init, 1, "getCurrentPageBounds", _getCurrentPageBounds_dec, Editor);
7847
7878
  __decorateElement(_init, 1, "getCurrentPageShapes", _getCurrentPageShapes_dec, Editor);