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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dist-cjs/index.d.ts +47 -23
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  5. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +5 -1
  6. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  7. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +2 -5
  8. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +3 -3
  9. package/dist-cjs/lib/components/default-components/DefaultSpinner.js.map +2 -2
  10. package/dist-cjs/lib/editor/Editor.js +46 -33
  11. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  12. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +3 -2
  13. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
  14. package/dist-cjs/lib/editor/managers/EditorManager.js +11 -2
  15. package/dist-cjs/lib/editor/managers/EditorManager.js.map +2 -2
  16. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +49 -63
  17. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +2 -2
  18. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +1 -1
  19. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +2 -2
  20. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +24 -24
  21. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
  22. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +7 -1
  23. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
  24. package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js +4 -3
  25. package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
  26. package/dist-cjs/lib/editor/shapes/shared/resizeBox.js +21 -16
  27. package/dist-cjs/lib/editor/shapes/shared/resizeBox.js.map +2 -2
  28. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  29. package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
  30. package/dist-cjs/lib/hooks/useCursor.js +12 -8
  31. package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
  32. package/dist-cjs/lib/utils/debug-flags.js +0 -6
  33. package/dist-cjs/lib/utils/debug-flags.js.map +2 -2
  34. package/dist-cjs/lib/utils/deepLinks.js +2 -1
  35. package/dist-cjs/lib/utils/deepLinks.js.map +2 -2
  36. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +19 -8
  37. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  38. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +15 -5
  39. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  40. package/dist-cjs/version.js +3 -3
  41. package/dist-cjs/version.js.map +1 -1
  42. package/dist-esm/index.d.mts +47 -23
  43. package/dist-esm/index.mjs +4 -2
  44. package/dist-esm/index.mjs.map +2 -2
  45. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  46. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +5 -1
  47. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  48. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +2 -5
  49. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +3 -3
  50. package/dist-esm/lib/components/default-components/DefaultSpinner.mjs.map +2 -2
  51. package/dist-esm/lib/editor/Editor.mjs +48 -34
  52. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  53. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +3 -2
  54. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
  55. package/dist-esm/lib/editor/managers/EditorManager.mjs +11 -2
  56. package/dist-esm/lib/editor/managers/EditorManager.mjs.map +2 -2
  57. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +49 -63
  58. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +2 -2
  59. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +1 -1
  60. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +2 -2
  61. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +24 -24
  62. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
  63. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +7 -1
  64. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
  65. package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs +4 -3
  66. package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
  67. package/dist-esm/lib/editor/shapes/shared/resizeBox.mjs +21 -16
  68. package/dist-esm/lib/editor/shapes/shared/resizeBox.mjs.map +2 -2
  69. package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
  70. package/dist-esm/lib/hooks/useCursor.mjs +12 -8
  71. package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
  72. package/dist-esm/lib/utils/debug-flags.mjs +0 -6
  73. package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
  74. package/dist-esm/lib/utils/deepLinks.mjs +2 -1
  75. package/dist-esm/lib/utils/deepLinks.mjs.map +2 -2
  76. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +19 -8
  77. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  78. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +16 -6
  79. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  80. package/dist-esm/version.mjs +3 -3
  81. package/dist-esm/version.mjs.map +1 -1
  82. package/editor.css +9 -1
  83. package/package.json +16 -18
  84. package/src/index.ts +5 -1
  85. package/src/lib/TldrawEditor.tsx +8 -6
  86. package/src/lib/components/default-components/DefaultCanvas.tsx +7 -1
  87. package/src/lib/components/default-components/DefaultErrorFallback.tsx +13 -5
  88. package/src/lib/components/default-components/DefaultSpinner.tsx +4 -1
  89. package/src/lib/editor/Editor.test.ts +45 -0
  90. package/src/lib/editor/Editor.ts +87 -46
  91. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +1 -0
  92. package/src/lib/editor/managers/ClickManager/ClickManager.ts +3 -2
  93. package/src/lib/editor/managers/EditorManager.test.ts +32 -1
  94. package/src/lib/editor/managers/EditorManager.ts +15 -3
  95. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +80 -0
  96. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +54 -81
  97. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +1 -1
  98. package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +32 -36
  99. package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +13 -2
  100. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +13 -0
  101. package/src/lib/editor/managers/SnapManager/SnapManager.ts +6 -4
  102. package/src/lib/editor/shapes/shared/resizeBox.ts +21 -16
  103. package/src/lib/editor/types/external-content.ts +5 -0
  104. package/src/lib/hooks/EditorComponentsContext.tsx +2 -1
  105. package/src/lib/hooks/useCursor.ts +14 -7
  106. package/src/lib/test/useCursor.test.tsx +36 -0
  107. package/src/lib/utils/debug-flags.ts +0 -6
  108. package/src/lib/utils/deepLinks.test.ts +15 -0
  109. package/src/lib/utils/deepLinks.ts +8 -3
  110. package/src/lib/utils/sync/LocalIndexedDb.test.ts +93 -1
  111. package/src/lib/utils/sync/LocalIndexedDb.ts +23 -8
  112. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +94 -1
  113. package/src/lib/utils/sync/TLLocalSyncClient.ts +30 -8
  114. package/src/version.ts +3 -3
@@ -43,10 +43,7 @@ var import_dom = require("../../utils/dom");
43
43
  var import_runtime = require("../../utils/runtime");
44
44
  var import_ErrorBoundary = require("../ErrorBoundary");
45
45
  const BASE_ERROR_URL = "https://github.com/tldraw/tldraw/issues/new";
46
- const DefaultErrorFallback = function DefaultErrorFallback2({
47
- error,
48
- editor
49
- }) {
46
+ function DefaultErrorFallback({ error, editor }) {
50
47
  const containerRef = (0, import_react.useRef)(null);
51
48
  const [shouldShowError, setShouldShowError] = (0, import_react.useState)(process.env.NODE_ENV === "development");
52
49
  const [didCopy, setDidCopy] = (0, import_react.useState)(false);
@@ -207,5 +204,5 @@ My browser: ${navigator.userAgent}`
207
204
  ]
208
205
  }
209
206
  );
210
- };
207
+ }
211
208
  //# sourceMappingURL=DefaultErrorFallback.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/components/default-components/DefaultErrorFallback.tsx"],
4
- "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { noop } from '@tldraw/utils'\nimport classNames from 'classnames'\nimport { ComponentType, useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { Editor } from '../../editor/Editor'\nimport { getOwnerDocument } from '../../exports/domUtils'\nimport { useEditorComponents } from '../../hooks/EditorComponentsContext'\nimport { EditorProvider } from '../../hooks/useEditor'\nimport { getGlobalWindow } from '../../utils/dom'\nimport { hardResetEditor, refreshPage } from '../../utils/runtime'\nimport { ErrorBoundary } from '../ErrorBoundary'\n\nconst BASE_ERROR_URL = 'https://github.com/tldraw/tldraw/issues/new'\n\n/** @public */\nexport type TLErrorFallbackComponent = ComponentType<{ error: unknown; editor?: Editor }>\n\n/** @public @react */\nexport const DefaultErrorFallback: TLErrorFallbackComponent = function DefaultErrorFallback({\n\terror,\n\teditor,\n}) {\n\tconst containerRef = useRef<HTMLDivElement>(null)\n\tconst [shouldShowError, setShouldShowError] = useState(process.env.NODE_ENV === 'development')\n\tconst [didCopy, setDidCopy] = useState(false)\n\tconst [shouldShowResetConfirmation, setShouldShowResetConfirmation] = useState(false)\n\n\tlet Canvas: React.ComponentType | null = null\n\ttry {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst components = useEditorComponents()\n\t\tCanvas = components.Canvas ?? null\n\t} catch {\n\t\t// allow this to fail silently\n\t}\n\n\tconst errorMessage = error instanceof Error ? error.message : String(error)\n\tconst errorStack = error instanceof Error ? error.stack : null\n\n\tconst isDarkModeFromApp = useValue(\n\t\t'isDarkMode',\n\t\t() => {\n\t\t\ttry {\n\t\t\t\tif (editor) {\n\t\t\t\t\treturn editor.user.getIsDarkMode()\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// we're in a funky error state so this might not work for spooky\n\t\t\t\t// reasons. if not, we'll have another attempt later:\n\t\t\t}\n\t\t\treturn null\n\t\t},\n\t\t[editor]\n\t)\n\tconst [isDarkMode, setIsDarkMode] = useState<null | boolean>(null)\n\tuseLayoutEffect(() => {\n\t\t// if we found a theme class from the app, we can just use that\n\t\tif (isDarkModeFromApp !== null) {\n\t\t\tsetIsDarkMode(isDarkModeFromApp)\n\t\t}\n\n\t\t// do any of our parents have a theme class? if yes then we can just\n\t\t// rely on that and don't need to set our own class\n\t\tlet parent = containerRef.current?.parentElement\n\t\tlet foundParentThemeClass = false\n\t\twhile (parent) {\n\t\t\tif (\n\t\t\t\tparent.classList.contains('tl-theme__dark') ||\n\t\t\t\tparent.classList.contains('tl-theme__light')\n\t\t\t) {\n\t\t\t\tfoundParentThemeClass = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tparent = parent.parentElement\n\t\t}\n\t\tif (foundParentThemeClass) {\n\t\t\tsetIsDarkMode(null)\n\t\t\treturn\n\t\t}\n\n\t\t// if we can't find a theme class from the app or from a parent, we have\n\t\t// to fall back on using a media query:\n\t\tif (typeof window !== 'undefined' && getGlobalWindow().matchMedia) {\n\t\t\tsetIsDarkMode(getGlobalWindow().matchMedia('(prefers-color-scheme: dark)').matches)\n\t\t}\n\t}, [isDarkModeFromApp])\n\n\tuseEffect(() => {\n\t\tif (didCopy) {\n\t\t\tconst timeout = editor?.timers.setTimeout(() => {\n\t\t\t\tsetDidCopy(false)\n\t\t\t}, 2000)\n\t\t\treturn () => clearTimeout(timeout)\n\t\t}\n\t}, [didCopy, editor])\n\n\tconst copyError = () => {\n\t\tconst doc = getOwnerDocument(containerRef.current)\n\t\tconst textarea = doc.createElement('textarea')\n\t\ttextarea.value = errorStack ?? errorMessage\n\t\tdoc.body.appendChild(textarea)\n\t\ttextarea.select()\n\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\tdoc.execCommand('copy')\n\t\ttextarea.remove()\n\t\tsetDidCopy(true)\n\t}\n\n\tconst refresh = () => {\n\t\trefreshPage()\n\t}\n\n\tconst resetLocalState = async () => {\n\t\thardResetEditor()\n\t}\n\n\tconst url = new URL(BASE_ERROR_URL)\n\turl.searchParams.set('title', errorMessage)\n\turl.searchParams.set('labels', `bug`)\n\turl.searchParams.set(\n\t\t'body',\n\t\t`Hey, I ran into an error while using tldraw:\n\n\\`\\`\\`js\n${errorStack ?? errorMessage}\n\\`\\`\\`\n\nMy browser: ${navigator.userAgent}`\n\t)\n\n\treturn (\n\t\t<div\n\t\t\tref={containerRef}\n\t\t\tclassName={classNames(\n\t\t\t\t'tl-container tl-error-boundary',\n\t\t\t\t// error-boundary is sometimes used outside of the theme\n\t\t\t\t// container, so we need to provide it with a theme for our\n\t\t\t\t// styles to work correctly\n\t\t\t\tisDarkMode === null ? '' : isDarkMode ? 'tl-theme__dark' : 'tl-theme__light'\n\t\t\t)}\n\t\t>\n\t\t\t<div className=\"tl-error-boundary__overlay\" />\n\t\t\t{editor && (\n\t\t\t\t// opportunistically attempt to render the canvas to reassure\n\t\t\t\t// the user that their document is still there. there's a good\n\t\t\t\t// chance this won't work (ie the error that we're currently\n\t\t\t\t// notifying the user about originates in the canvas) so it's\n\t\t\t\t// not a big deal if it doesn't work - in that case we just have\n\t\t\t\t// a plain grey background.\n\t\t\t\t<ErrorBoundary onError={noop} fallback={() => null}>\n\t\t\t\t\t<EditorProvider editor={editor}>\n\t\t\t\t\t\t<div className=\"tl-overlay tl-error-boundary__canvas\">{Canvas ? <Canvas /> : null}</div>\n\t\t\t\t\t</EditorProvider>\n\t\t\t\t</ErrorBoundary>\n\t\t\t)}\n\t\t\t<div\n\t\t\t\tclassName={classNames('tl-modal', 'tl-error-boundary__content', {\n\t\t\t\t\t'tl-error-boundary__content__expanded': shouldShowError && !shouldShowResetConfirmation,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{shouldShowResetConfirmation ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<h2>Are you sure?</h2>\n\t\t\t\t\t\t<p>Resetting your data will delete your drawing and cannot be undone.</p>\n\t\t\t\t\t\t<div className=\"tl-error-boundary__content__actions\">\n\t\t\t\t\t\t\t<button className=\"tlui-button\" onClick={() => setShouldShowResetConfirmation(false)}>\n\t\t\t\t\t\t\t\tCancel\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button className=\"tlui-button tl-error-boundary__reset\" onClick={resetLocalState}>\n\t\t\t\t\t\t\t\tReset data\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<h2>Something went wrong</h2>\n\t\t\t\t\t\t<p>Please refresh your browser.</p>\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\tIf the issue continues after refreshing, you may need to reset the tldraw data stored\n\t\t\t\t\t\t\ton your device.\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t<strong>Note:</strong> Resetting will erase your current project and any unsaved work.\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t{process.env.NODE_ENV !== 'production' && (\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\tIf you&apos;re developing with the SDK and need help, join us on{' '}\n\t\t\t\t\t\t\t\t<a href=\"https://discord.tldraw.com/?utm_source=sdk&utm_medium=organic&utm_campaign=error-screen\">\n\t\t\t\t\t\t\t\t\tDiscord\n\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t\t.\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{shouldShowError && (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\tMessage:\n\t\t\t\t\t\t\t\t<h4>\n\t\t\t\t\t\t\t\t\t<code>{errorMessage}</code>\n\t\t\t\t\t\t\t\t</h4>\n\t\t\t\t\t\t\t\tStack trace:\n\t\t\t\t\t\t\t\t<div className=\"tl-error-boundary__content__error\">\n\t\t\t\t\t\t\t\t\t<pre>\n\t\t\t\t\t\t\t\t\t\t<code>{errorStack ?? errorMessage}</code>\n\t\t\t\t\t\t\t\t\t</pre>\n\t\t\t\t\t\t\t\t\t<button className=\"tlui-button\" onClick={copyError}>\n\t\t\t\t\t\t\t\t\t\t{didCopy ? 'Copied!' : 'Copy'}\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t<div className=\"tl-error-boundary__content__actions\">\n\t\t\t\t\t\t\t<button className=\"tlui-button\" onClick={() => setShouldShowError(!shouldShowError)}>\n\t\t\t\t\t\t\t\t{shouldShowError ? 'Hide details' : 'Show details'}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<div className=\"tl-error-boundary__content__actions__group\">\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\tclassName=\"tlui-button tl-error-boundary__reset\"\n\t\t\t\t\t\t\t\t\tonClick={() => setShouldShowResetConfirmation(true)}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\tReset data\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\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BAED,4CAAC,QACA,sDAAC,UAAM,wBAAa,GACrB;AAAA,gBAAK;AAAA,gBAEL,6CAAC,SAAI,WAAU,qCACd;AAAA,8DAAC,SACA,sDAAC,UAAM,wBAAc,cAAa,GACnC;AAAA,kBACA,4CAAC,YAAO,WAAU,eAAc,SAAS,WACvC,oBAAU,YAAY,QACxB;AAAA,mBACD;AAAA,iBACD;AAAA,cAED,6CAAC,SAAI,WAAU,uCACd;AAAA,4DAAC,YAAO,WAAU,eAAc,SAAS,MAAM,mBAAmB,CAAC,eAAe,GAChF,4BAAkB,iBAAiB,gBACrC;AAAA,gBACA,6CAAC,SAAI,WAAU,8CACd;AAAA;AAAA,oBAAC;AAAA;AAAA,sBACA,WAAU;AAAA,sBACV,SAAS,MAAM,+BAA+B,IAAI;AAAA,sBAClD;AAAA;AAAA,kBAED;AAAA,kBACA,4CAAC,YAAO,WAAU,0CAAyC,SAAS,SAAS,0BAE7E;AAAA,mBACD;AAAA,iBACD;AAAA,eACD;AAAA;AAAA,QAEF;AAAA;AAAA;AAAA,EACD;AAEF;",
6
- "names": ["DefaultErrorFallback", "classNames"]
4
+ "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { noop } from '@tldraw/utils'\nimport classNames from 'classnames'\nimport { ComponentType, useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { Editor } from '../../editor/Editor'\nimport { getOwnerDocument } from '../../exports/domUtils'\nimport { useEditorComponents } from '../../hooks/EditorComponentsContext'\nimport { EditorProvider } from '../../hooks/useEditor'\nimport { getGlobalWindow } from '../../utils/dom'\nimport { hardResetEditor, refreshPage } from '../../utils/runtime'\nimport { ErrorBoundary } from '../ErrorBoundary'\n\nconst BASE_ERROR_URL = 'https://github.com/tldraw/tldraw/issues/new'\n\n/** @public */\nexport interface TLErrorFallbackProps {\n\t/** The error that was caught. */\n\terror: unknown\n\t/**\n\t * Only set when the caller renders the fallback with an editor; the editor's own error\n\t * boundaries pass just `error`.\n\t */\n\teditor?: Editor\n}\n\n/** @public */\nexport type TLErrorFallbackComponent = ComponentType<TLErrorFallbackProps>\n\n/** @public @react */\nexport function DefaultErrorFallback({ error, editor }: TLErrorFallbackProps) {\n\tconst containerRef = useRef<HTMLDivElement>(null)\n\tconst [shouldShowError, setShouldShowError] = useState(process.env.NODE_ENV === 'development')\n\tconst [didCopy, setDidCopy] = useState(false)\n\tconst [shouldShowResetConfirmation, setShouldShowResetConfirmation] = useState(false)\n\n\tlet Canvas: React.ComponentType | null = null\n\ttry {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst components = useEditorComponents()\n\t\tCanvas = components.Canvas ?? null\n\t} catch {\n\t\t// allow this to fail silently\n\t}\n\n\tconst errorMessage = error instanceof Error ? error.message : String(error)\n\tconst errorStack = error instanceof Error ? error.stack : null\n\n\tconst isDarkModeFromApp = useValue(\n\t\t'isDarkMode',\n\t\t() => {\n\t\t\ttry {\n\t\t\t\tif (editor) {\n\t\t\t\t\treturn editor.user.getIsDarkMode()\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// we're in a funky error state so this might not work for spooky\n\t\t\t\t// reasons. if not, we'll have another attempt later:\n\t\t\t}\n\t\t\treturn null\n\t\t},\n\t\t[editor]\n\t)\n\tconst [isDarkMode, setIsDarkMode] = useState<null | boolean>(null)\n\tuseLayoutEffect(() => {\n\t\t// if we found a theme class from the app, we can just use that\n\t\tif (isDarkModeFromApp !== null) {\n\t\t\tsetIsDarkMode(isDarkModeFromApp)\n\t\t}\n\n\t\t// do any of our parents have a theme class? if yes then we can just\n\t\t// rely on that and don't need to set our own class\n\t\tlet parent = containerRef.current?.parentElement\n\t\tlet foundParentThemeClass = false\n\t\twhile (parent) {\n\t\t\tif (\n\t\t\t\tparent.classList.contains('tl-theme__dark') ||\n\t\t\t\tparent.classList.contains('tl-theme__light')\n\t\t\t) {\n\t\t\t\tfoundParentThemeClass = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tparent = parent.parentElement\n\t\t}\n\t\tif (foundParentThemeClass) {\n\t\t\tsetIsDarkMode(null)\n\t\t\treturn\n\t\t}\n\n\t\t// if we can't find a theme class from the app or from a parent, we have\n\t\t// to fall back on using a media query:\n\t\tif (typeof window !== 'undefined' && getGlobalWindow().matchMedia) {\n\t\t\tsetIsDarkMode(getGlobalWindow().matchMedia('(prefers-color-scheme: dark)').matches)\n\t\t}\n\t}, [isDarkModeFromApp])\n\n\tuseEffect(() => {\n\t\tif (didCopy) {\n\t\t\tconst timeout = editor?.timers.setTimeout(() => {\n\t\t\t\tsetDidCopy(false)\n\t\t\t}, 2000)\n\t\t\treturn () => clearTimeout(timeout)\n\t\t}\n\t}, [didCopy, editor])\n\n\tconst copyError = () => {\n\t\tconst doc = getOwnerDocument(containerRef.current)\n\t\tconst textarea = doc.createElement('textarea')\n\t\ttextarea.value = errorStack ?? errorMessage\n\t\tdoc.body.appendChild(textarea)\n\t\ttextarea.select()\n\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\tdoc.execCommand('copy')\n\t\ttextarea.remove()\n\t\tsetDidCopy(true)\n\t}\n\n\tconst refresh = () => {\n\t\trefreshPage()\n\t}\n\n\tconst resetLocalState = async () => {\n\t\thardResetEditor()\n\t}\n\n\tconst url = new URL(BASE_ERROR_URL)\n\turl.searchParams.set('title', errorMessage)\n\turl.searchParams.set('labels', `bug`)\n\turl.searchParams.set(\n\t\t'body',\n\t\t`Hey, I ran into an error while using tldraw:\n\n\\`\\`\\`js\n${errorStack ?? errorMessage}\n\\`\\`\\`\n\nMy browser: ${navigator.userAgent}`\n\t)\n\n\treturn (\n\t\t<div\n\t\t\tref={containerRef}\n\t\t\tclassName={classNames(\n\t\t\t\t'tl-container tl-error-boundary',\n\t\t\t\t// error-boundary is sometimes used outside of the theme\n\t\t\t\t// container, so we need to provide it with a theme for our\n\t\t\t\t// styles to work correctly\n\t\t\t\tisDarkMode === null ? '' : isDarkMode ? 'tl-theme__dark' : 'tl-theme__light'\n\t\t\t)}\n\t\t>\n\t\t\t<div className=\"tl-error-boundary__overlay\" />\n\t\t\t{editor && (\n\t\t\t\t// opportunistically attempt to render the canvas to reassure\n\t\t\t\t// the user that their document is still there. there's a good\n\t\t\t\t// chance this won't work (ie the error that we're currently\n\t\t\t\t// notifying the user about originates in the canvas) so it's\n\t\t\t\t// not a big deal if it doesn't work - in that case we just have\n\t\t\t\t// a plain grey background.\n\t\t\t\t<ErrorBoundary onError={noop} fallback={() => null}>\n\t\t\t\t\t<EditorProvider editor={editor}>\n\t\t\t\t\t\t<div className=\"tl-overlay tl-error-boundary__canvas\">{Canvas ? <Canvas /> : null}</div>\n\t\t\t\t\t</EditorProvider>\n\t\t\t\t</ErrorBoundary>\n\t\t\t)}\n\t\t\t<div\n\t\t\t\tclassName={classNames('tl-modal', 'tl-error-boundary__content', {\n\t\t\t\t\t'tl-error-boundary__content__expanded': shouldShowError && !shouldShowResetConfirmation,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{shouldShowResetConfirmation ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<h2>Are you sure?</h2>\n\t\t\t\t\t\t<p>Resetting your data will delete your drawing and cannot be undone.</p>\n\t\t\t\t\t\t<div className=\"tl-error-boundary__content__actions\">\n\t\t\t\t\t\t\t<button className=\"tlui-button\" onClick={() => setShouldShowResetConfirmation(false)}>\n\t\t\t\t\t\t\t\tCancel\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button className=\"tlui-button tl-error-boundary__reset\" onClick={resetLocalState}>\n\t\t\t\t\t\t\t\tReset data\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<h2>Something went wrong</h2>\n\t\t\t\t\t\t<p>Please refresh your browser.</p>\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\tIf the issue continues after refreshing, you may need to reset the tldraw data stored\n\t\t\t\t\t\t\ton your device.\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t<strong>Note:</strong> Resetting will erase your current project and any unsaved work.\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t{process.env.NODE_ENV !== 'production' && (\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\tIf you&apos;re developing with the SDK and need help, join us on{' '}\n\t\t\t\t\t\t\t\t<a href=\"https://discord.tldraw.com/?utm_source=sdk&utm_medium=organic&utm_campaign=error-screen\">\n\t\t\t\t\t\t\t\t\tDiscord\n\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t\t.\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{shouldShowError && (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\tMessage:\n\t\t\t\t\t\t\t\t<h4>\n\t\t\t\t\t\t\t\t\t<code>{errorMessage}</code>\n\t\t\t\t\t\t\t\t</h4>\n\t\t\t\t\t\t\t\tStack trace:\n\t\t\t\t\t\t\t\t<div className=\"tl-error-boundary__content__error\">\n\t\t\t\t\t\t\t\t\t<pre>\n\t\t\t\t\t\t\t\t\t\t<code>{errorStack ?? errorMessage}</code>\n\t\t\t\t\t\t\t\t\t</pre>\n\t\t\t\t\t\t\t\t\t<button className=\"tlui-button\" onClick={copyError}>\n\t\t\t\t\t\t\t\t\t\t{didCopy ? 'Copied!' : 'Copy'}\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t<div className=\"tl-error-boundary__content__actions\">\n\t\t\t\t\t\t\t<button className=\"tlui-button\" onClick={() => setShouldShowError(!shouldShowError)}>\n\t\t\t\t\t\t\t\t{shouldShowError ? 'Hide details' : 'Show details'}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<div className=\"tl-error-boundary__content__actions__group\">\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\tclassName=\"tlui-button tl-error-boundary__reset\"\n\t\t\t\t\t\t\t\t\tonClick={() => setShouldShowResetConfirmation(true)}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\tReset data\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<button className=\"tlui-button tl-error-boundary__refresh\" onClick={refresh}>\n\t\t\t\t\t\t\t\t\tRefresh page\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqJG;AArJH,yBAAyB;AACzB,mBAAqB;AACrB,wBAAuB;AACvB,mBAA4E;AAE5E,sBAAiC;AACjC,qCAAoC;AACpC,uBAA+B;AAC/B,iBAAgC;AAChC,qBAA6C;AAC7C,2BAA8B;AAE9B,MAAM,iBAAiB;AAiBhB,SAAS,qBAAqB,EAAE,OAAO,OAAO,GAAyB;AAC7E,QAAM,mBAAe,qBAAuB,IAAI;AAChD,QAAM,CAAC,iBAAiB,kBAAkB,QAAI,uBAAS,QAAQ,IAAI,aAAa,aAAa;AAC7F,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,KAAK;AAC5C,QAAM,CAAC,6BAA6B,8BAA8B,QAAI,uBAAS,KAAK;AAEpF,MAAI,SAAqC;AACzC,MAAI;AAEH,UAAM,iBAAa,oDAAoB;AACvC,aAAS,WAAW,UAAU;AAAA,EAC/B,QAAQ;AAAA,EAER;AAEA,QAAM,eAAe,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC1E,QAAM,aAAa,iBAAiB,QAAQ,MAAM,QAAQ;AAE1D,QAAM,wBAAoB;AAAA,IACzB;AAAA,IACA,MAAM;AACL,UAAI;AACH,YAAI,QAAQ;AACX,iBAAO,OAAO,KAAK,cAAc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zB,6CAAC,OAAE;AAAA;AAAA,gBAC+D;AAAA,gBACjE,4CAAC,OAAE,MAAK,2FAA0F,qBAElG;AAAA,gBAAI;AAAA,iBAEL;AAAA,cAEA,mBACA,4EAAE;AAAA;AAAA,gBAED,4CAAC,QACA,sDAAC,UAAM,wBAAa,GACrB;AAAA,gBAAK;AAAA,gBAEL,6CAAC,SAAI,WAAU,qCACd;AAAA,8DAAC,SACA,sDAAC,UAAM,wBAAc,cAAa,GACnC;AAAA,kBACA,4CAAC,YAAO,WAAU,eAAc,SAAS,WACvC,oBAAU,YAAY,QACxB;AAAA,mBACD;AAAA,iBACD;AAAA,cAED,6CAAC,SAAI,WAAU,uCACd;AAAA,4DAAC,YAAO,WAAU,eAAc,SAAS,MAAM,mBAAmB,CAAC,eAAe,GAChF,4BAAkB,iBAAiB,gBACrC;AAAA,gBACA,6CAAC,SAAI,WAAU,8CACd;AAAA;AAAA,oBAAC;AAAA;AAAA,sBACA,WAAU;AAAA,sBACV,SAAS,MAAM,+BAA+B,IAAI;AAAA,sBAClD;AAAA;AAAA,kBAED;AAAA,kBACA,4CAAC,YAAO,WAAU,0CAAyC,SAAS,SAAS,0BAE7E;AAAA,mBACD;AAAA,iBACD;AAAA,eACD;AAAA;AAAA,QAEF;AAAA;AAAA;AAAA,EACD;AAEF;",
6
+ "names": ["classNames"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/components/default-components/DefaultSpinner.tsx"],
4
- "sourcesContent": ["import classNames from 'classnames'\n\n/** @public @react */\nexport function DefaultSpinner(props: React.SVGProps<SVGSVGElement>) {\n\treturn (\n\t\t<svg\n\t\t\twidth={16}\n\t\t\theight={16}\n\t\t\tviewBox=\"0 0 16 16\"\n\t\t\taria-hidden=\"false\"\n\t\t\t{...props}\n\t\t\tclassName={classNames('tl-spinner', props.className)}\n\t\t>\n\t\t\t<g strokeWidth={2} fill=\"none\" fillRule=\"evenodd\">\n\t\t\t\t<circle strokeOpacity={0.25} cx={8} cy={8} r={7} stroke=\"currentColor\" />\n\t\t\t\t<path strokeLinecap=\"round\" d=\"M15 8c0-4.5-4.5-7-7-7\" stroke=\"currentColor\" />\n\t\t\t</g>\n\t\t</svg>\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaG;AAbH,wBAAuB;AAGhB,SAAS,eAAe,OAAsC;AACpE,SACC;AAAA,IAAC;AAAA;AAAA,MACA,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,SAAQ;AAAA,MACR,eAAY;AAAA,MACX,GAAG;AAAA,MACJ,eAAW,kBAAAA,SAAW,cAAc,MAAM,SAAS;AAAA,MAEnD,uDAAC,OAAE,aAAa,GAAG,MAAK,QAAO,UAAS,WACvC;AAAA,oDAAC,YAAO,eAAe,MAAM,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,QAAO,gBAAe;AAAA,QACvE,4CAAC,UAAK,eAAc,SAAQ,GAAE,yBAAwB,QAAO,gBAAe;AAAA,SAC7E;AAAA;AAAA,EACD;AAEF;",
4
+ "sourcesContent": ["import classNames from 'classnames'\n\n/** @public */\nexport type TLSpinnerProps = React.SVGProps<SVGSVGElement>\n\n/** @public @react */\nexport function DefaultSpinner(props: TLSpinnerProps) {\n\treturn (\n\t\t<svg\n\t\t\twidth={16}\n\t\t\theight={16}\n\t\t\tviewBox=\"0 0 16 16\"\n\t\t\taria-hidden=\"false\"\n\t\t\t{...props}\n\t\t\tclassName={classNames('tl-spinner', props.className)}\n\t\t>\n\t\t\t<g strokeWidth={2} fill=\"none\" fillRule=\"evenodd\">\n\t\t\t\t<circle strokeOpacity={0.25} cx={8} cy={8} r={7} stroke=\"currentColor\" />\n\t\t\t\t<path strokeLinecap=\"round\" d=\"M15 8c0-4.5-4.5-7-7-7\" stroke=\"currentColor\" />\n\t\t\t</g>\n\t\t</svg>\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBG;AAhBH,wBAAuB;AAMhB,SAAS,eAAe,OAAuB;AACrD,SACC;AAAA,IAAC;AAAA;AAAA,MACA,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,SAAQ;AAAA,MACR,eAAY;AAAA,MACX,GAAG;AAAA,MACJ,eAAW,kBAAAA,SAAW,cAAc,MAAM,SAAS;AAAA,MAEnD,uDAAC,OAAE,aAAa,GAAG,MAAK,QAAO,UAAS,WACvC;AAAA,oDAAC,YAAO,eAAe,MAAM,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,QAAO,gBAAe;AAAA,QACvE,4CAAC,UAAK,eAAc,SAAQ,GAAE,yBAAwB,QAAO,gBAAe;AAAA,SAC7E;AAAA;AAAA,EACD;AAEF;",
6
6
  "names": ["classNames"]
7
7
  }
@@ -1408,7 +1408,7 @@ class Editor extends import_eventemitter3.default {
1408
1408
  updateInstanceState(partial, historyOptions) {
1409
1409
  this._updateInstanceState(partial, { history: "ignore", ...historyOptions });
1410
1410
  if (partial.isChangingStyle !== void 0) {
1411
- clearTimeout(this._isChangingStyleTimeout);
1411
+ this.timers.clearTimeout(this._isChangingStyleTimeout);
1412
1412
  if (partial.isChangingStyle === true) {
1413
1413
  this._isChangingStyleTimeout = this.timers.setTimeout(() => {
1414
1414
  this._updateInstanceState({ isChangingStyle: false }, { history: "ignore" });
@@ -2801,11 +2801,14 @@ class Editor extends import_eventemitter3.default {
2801
2801
  _animateViewport(ms) {
2802
2802
  if (!this._viewportAnimation) return;
2803
2803
  this._viewportAnimation.elapsed += ms;
2804
- const { elapsed, easing, duration, start, end } = this._viewportAnimation;
2804
+ const { elapsed, easing, duration, start, end, opts } = this._viewportAnimation;
2805
2805
  if (elapsed > duration) {
2806
2806
  this.off("tick", this._animateViewport);
2807
2807
  this._viewportAnimation = null;
2808
- this._setCamera(new import_Vec.Vec(-end.x, -end.y, this.getViewportScreenBounds().width / end.width));
2808
+ this._setCamera(
2809
+ new import_Vec.Vec(-end.x, -end.y, this.getViewportScreenBounds().width / end.width),
2810
+ opts
2811
+ );
2809
2812
  return;
2810
2813
  }
2811
2814
  const remaining = duration - elapsed;
@@ -2843,7 +2846,8 @@ class Editor extends import_eventemitter3.default {
2843
2846
  duration: duration / animationSpeed,
2844
2847
  easing,
2845
2848
  start: viewportPageBounds.clone(),
2846
- end: targetViewportPage.clone()
2849
+ end: targetViewportPage.clone(),
2850
+ opts: rest
2847
2851
  };
2848
2852
  this.once("stop-camera-animation", () => {
2849
2853
  this.off("tick", this._animateViewport);
@@ -3653,7 +3657,9 @@ class Editor extends import_eventemitter3.default {
3653
3657
  const id = typeof page === "string" ? page : page.id;
3654
3658
  const freshPage = this.getPage(id);
3655
3659
  if (!freshPage) return this;
3656
- const prevCamera = { ...this.getCamera() };
3660
+ const prevCamera = {
3661
+ ...this.store.get(import_tlschema.CameraRecordType.createId(freshPage.id)) ?? this.getCamera()
3662
+ };
3657
3663
  const content = this.getContentFromCurrentPage(this.getSortedChildIdsForParent(freshPage.id));
3658
3664
  this.run(() => {
3659
3665
  const pages = this.getPages();
@@ -3662,7 +3668,7 @@ class Editor extends import_eventemitter3.default {
3662
3668
  this.setCurrentPage(createId);
3663
3669
  this.setCamera(prevCamera);
3664
3670
  if (content) {
3665
- return this.putContentOntoCurrentPage(content);
3671
+ return this.putContentOntoCurrentPage(content, { preservePosition: true });
3666
3672
  }
3667
3673
  });
3668
3674
  return this;
@@ -6026,11 +6032,20 @@ class Editor extends import_eventemitter3.default {
6026
6032
  initialShape: options.initialShape,
6027
6033
  initialBounds: options.initialBounds,
6028
6034
  isAspectRatioLocked: options.isAspectRatioLocked,
6029
- initialPageTransform: options.initialPageTransform
6035
+ initialPageTransform: options.initialPageTransform,
6036
+ dragHandle: options.dragHandle,
6037
+ mode: options.mode,
6038
+ // this is one frame of the same resize, not a new one, so don't fire start/end again
6039
+ skipStartAndEndCallbacks: options.skipStartAndEndCallbacks
6030
6040
  });
6031
6041
  if (Math.sign(scale.x) * Math.sign(scale.y) < 0) {
6032
6042
  const parentRotation = this.getShapeParentTransform(id).rotation();
6033
- const rotation = -options.initialShape.rotation - 2 * parentRotation;
6043
+ const parentDelta = (0, import_utils2.shortAngleDist)(
6044
+ import_Mat.Mat.Cast(options.initialPageTransform).rotation() - options.initialShape.rotation,
6045
+ parentRotation
6046
+ );
6047
+ const initialParentRotation = parentRotation - parentDelta;
6048
+ const rotation = 2 * options.scaleAxisRotation - options.initialShape.rotation - 2 * initialParentRotation - parentDelta;
6034
6049
  this.updateShapes([{ id, type, rotation }]);
6035
6050
  }
6036
6051
  const preScaleShapePageCenter = import_Mat.Mat.applyToPoint(
@@ -7818,22 +7833,22 @@ class Editor extends import_eventemitter3.default {
7818
7833
  const releaseCtrl = this._ctrlKeyTimeout !== -1;
7819
7834
  const releaseMeta = this._metaKeyTimeout !== -1;
7820
7835
  if (releaseShift) {
7821
- clearTimeout(this._shiftKeyTimeout);
7836
+ this.timers.clearTimeout(this._shiftKeyTimeout);
7822
7837
  this._shiftKeyTimeout = -1;
7823
7838
  this.inputs.setShiftKey(false);
7824
7839
  }
7825
7840
  if (releaseAlt) {
7826
- clearTimeout(this._altKeyTimeout);
7841
+ this.timers.clearTimeout(this._altKeyTimeout);
7827
7842
  this._altKeyTimeout = -1;
7828
7843
  this.inputs.setAltKey(false);
7829
7844
  }
7830
7845
  if (releaseCtrl) {
7831
- clearTimeout(this._ctrlKeyTimeout);
7846
+ this.timers.clearTimeout(this._ctrlKeyTimeout);
7832
7847
  this._ctrlKeyTimeout = -1;
7833
7848
  this.inputs.setCtrlKey(false);
7834
7849
  }
7835
7850
  if (releaseMeta) {
7836
- clearTimeout(this._metaKeyTimeout);
7851
+ this.timers.clearTimeout(this._metaKeyTimeout);
7837
7852
  this._metaKeyTimeout = -1;
7838
7853
  this.inputs.setMetaKey(false);
7839
7854
  }
@@ -7947,28 +7962,28 @@ class Editor extends import_eventemitter3.default {
7947
7962
  return;
7948
7963
  }
7949
7964
  if (info.shiftKey) {
7950
- clearTimeout(this._shiftKeyTimeout);
7965
+ this.timers.clearTimeout(this._shiftKeyTimeout);
7951
7966
  this._shiftKeyTimeout = -1;
7952
7967
  inputs.setShiftKey(true);
7953
7968
  } else if (!info.shiftKey && inputs.getShiftKey() && this._shiftKeyTimeout === -1) {
7954
7969
  this._shiftKeyTimeout = this.timers.setTimeout(this._releaseShiftKey, 150);
7955
7970
  }
7956
7971
  if (info.altKey) {
7957
- clearTimeout(this._altKeyTimeout);
7972
+ this.timers.clearTimeout(this._altKeyTimeout);
7958
7973
  this._altKeyTimeout = -1;
7959
7974
  inputs.setAltKey(true);
7960
7975
  } else if (!info.altKey && inputs.getAltKey() && this._altKeyTimeout === -1) {
7961
7976
  this._altKeyTimeout = this.timers.setTimeout(this._releaseAltKey, 150);
7962
7977
  }
7963
7978
  if (info.ctrlKey) {
7964
- clearTimeout(this._ctrlKeyTimeout);
7979
+ this.timers.clearTimeout(this._ctrlKeyTimeout);
7965
7980
  this._ctrlKeyTimeout = -1;
7966
7981
  inputs.setCtrlKey(true);
7967
7982
  } else if (!info.ctrlKey && inputs.getCtrlKey() && this._ctrlKeyTimeout === -1) {
7968
7983
  this._ctrlKeyTimeout = this.timers.setTimeout(this._releaseCtrlKey, 150);
7969
7984
  }
7970
7985
  if (info.metaKey && info.name !== "key_up") {
7971
- clearTimeout(this._metaKeyTimeout);
7986
+ this.timers.clearTimeout(this._metaKeyTimeout);
7972
7987
  this._metaKeyTimeout = -1;
7973
7988
  inputs.setMetaKey(true);
7974
7989
  } else if (!info.metaKey && inputs.getMetaKey() && this._metaKeyTimeout === -1) {
@@ -7982,8 +7997,7 @@ class Editor extends import_eventemitter3.default {
7982
7997
  const cameraOptions = this._cameraOptions.__unsafe__getWithoutCapture();
7983
7998
  switch (type) {
7984
7999
  case "pinch": {
7985
- if (cameraOptions.isLocked) return;
7986
- clearTimeout(this._longPressTimeout);
8000
+ this.timers.clearTimeout(this._longPressTimeout);
7987
8001
  this.inputs.updateFromEvent(info);
7988
8002
  switch (info.name) {
7989
8003
  case "pinch_start": {
@@ -8004,6 +8018,7 @@ class Editor extends import_eventemitter3.default {
8004
8018
  }
8005
8019
  case "pinch": {
8006
8020
  if (!inputs.getIsPinching()) return;
8021
+ if (cameraOptions.isLocked) return;
8007
8022
  const {
8008
8023
  point: { z = 1 },
8009
8024
  delta: { x: dx, y: dy }
@@ -8059,7 +8074,7 @@ class Editor extends import_eventemitter3.default {
8059
8074
  const { panSpeed, zoomSpeed } = cameraOptions;
8060
8075
  let wheelBehavior = cameraOptions.wheelBehavior;
8061
8076
  const inputMode = this.user.getUserPreferences().inputMode;
8062
- if (inputMode !== null) {
8077
+ if (inputMode !== null && wheelBehavior !== "none") {
8063
8078
  wheelBehavior = inputMode === "trackpad" ? "pan" : "zoom";
8064
8079
  }
8065
8080
  if (wheelBehavior !== "none") {
@@ -8111,12 +8126,12 @@ class Editor extends import_eventemitter3.default {
8111
8126
  }
8112
8127
  case "pointer": {
8113
8128
  if (inputs.getIsPinching()) return;
8114
- this.inputs.updateFromEvent(info);
8115
8129
  const { isPen } = info;
8116
8130
  const { isPenMode } = instanceState;
8131
+ if (isPenMode && !isPen) return;
8132
+ this.inputs.updateFromEvent(info);
8117
8133
  switch (info.name) {
8118
8134
  case "pointer_down": {
8119
- if (isPenMode && !isPen) return;
8120
8135
  this._releaseDebouncedModifiers();
8121
8136
  if (!this.inputs.getIsPanning()) {
8122
8137
  this._longPressTimeout = this.timers.setTimeout(() => {
@@ -8145,7 +8160,7 @@ class Editor extends import_eventemitter3.default {
8145
8160
  this.updateInstanceState({ isPenMode: true });
8146
8161
  this.interrupt();
8147
8162
  }
8148
- if (info.button === import_constants.STYLUS_ERASER_BUTTON) {
8163
+ if (info.button === import_constants.STYLUS_ERASER_BUTTON && this.getStateDescendant("eraser")) {
8149
8164
  this._restoreToolId = this.getCurrentToolId();
8150
8165
  this.complete();
8151
8166
  this.setCurrentTool("eraser");
@@ -8154,10 +8169,10 @@ class Editor extends import_eventemitter3.default {
8154
8169
  this._prevCursor = this.getInstanceState().cursor.type;
8155
8170
  }
8156
8171
  this.inputs.setIsPanning(true);
8157
- clearTimeout(this._longPressTimeout);
8172
+ this.timers.clearTimeout(this._longPressTimeout);
8158
8173
  } else if (info.button === import_constants.RIGHT_MOUSE_BUTTON && this.options.rightClickPanning) {
8159
8174
  this.inputs.setIsRightPointing(true);
8160
- clearTimeout(this._longPressTimeout);
8175
+ this.timers.clearTimeout(this._longPressTimeout);
8161
8176
  return this;
8162
8177
  }
8163
8178
  if (this.inputs.getIsPanning()) {
@@ -8168,7 +8183,6 @@ class Editor extends import_eventemitter3.default {
8168
8183
  break;
8169
8184
  }
8170
8185
  case "pointer_move": {
8171
- if (!isPen && isPenMode) return;
8172
8186
  const { x: cx, y: cy, z: cz } = (0, import_state.unsafe__withoutCapture)(() => this.getCamera());
8173
8187
  if (this.inputs.getIsRightPointing() && !this.inputs.getIsPanning()) {
8174
8188
  const currentScreenPoint = this.inputs.getCurrentScreenPoint();
@@ -8199,16 +8213,15 @@ class Editor extends import_eventemitter3.default {
8199
8213
  }
8200
8214
  if (inputs.getIsPointing() && !inputs.getIsDragging() && import_Vec.Vec.Dist2(inputs.getOriginPagePoint(), inputs.getCurrentPagePoint()) * this.getZoomLevel() > (instanceState.isCoarsePointer ? this.options.coarseDragDistanceSquared : this.options.dragDistanceSquared) / cz) {
8201
8215
  inputs.setIsDragging(true);
8202
- clearTimeout(this._longPressTimeout);
8216
+ this.timers.clearTimeout(this._longPressTimeout);
8203
8217
  }
8204
8218
  break;
8205
8219
  }
8206
8220
  case "pointer_up": {
8207
8221
  inputs.setIsDragging(false);
8208
8222
  inputs.setIsPointing(false);
8209
- clearTimeout(this._longPressTimeout);
8223
+ this.timers.clearTimeout(this._longPressTimeout);
8210
8224
  inputs.buttons.delete(info.button);
8211
- if (instanceState.isPenMode && !isPen) return;
8212
8225
  if (this.inputs.getIsRightPointing() && !this.inputs.getIsPanning()) {
8213
8226
  this.inputs.setIsRightPointing(false);
8214
8227
  this._selectedShapeIdsAtPointerDown = [];
@@ -8264,7 +8277,7 @@ class Editor extends import_eventemitter3.default {
8264
8277
  });
8265
8278
  }
8266
8279
  } else {
8267
- if (info.button === import_constants.STYLUS_ERASER_BUTTON) {
8280
+ if (info.button === import_constants.STYLUS_ERASER_BUTTON && this.getStateDescendant("eraser")) {
8268
8281
  this.complete();
8269
8282
  this.setCurrentTool(this._restoreToolId);
8270
8283
  }
@@ -8291,7 +8304,7 @@ class Editor extends import_eventemitter3.default {
8291
8304
  }
8292
8305
  this.inputs.setIsPanning(true);
8293
8306
  this.inputs.setIsSpacebarPanning(true);
8294
- clearTimeout(this._longPressTimeout);
8307
+ this.timers.clearTimeout(this._longPressTimeout);
8295
8308
  this.setCursor({
8296
8309
  type: this.inputs.getIsPointing() ? "grabbing" : "grab",
8297
8310
  rotation: 0
@@ -8317,7 +8330,7 @@ class Editor extends import_eventemitter3.default {
8317
8330
  break;
8318
8331
  }
8319
8332
  }
8320
- if (offset) {
8333
+ if (offset && !cameraOptions.isLocked) {
8321
8334
  const bounds = this.getViewportPageBounds();
8322
8335
  const next = bounds.clone().translate(offset.mulV({ x: bounds.w, y: bounds.h }));
8323
8336
  this._animateToViewport(next, { animation: { duration: 320 } });
@@ -8357,7 +8370,7 @@ class Editor extends import_eventemitter3.default {
8357
8370
  this.setCurrentTool("select");
8358
8371
  }
8359
8372
  const { isPenMode } = this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID);
8360
- if (info.isPen === isPenMode) {
8373
+ if (!isPenMode || info.isPen) {
8361
8374
  const clickInfo = this._clickManager.handlePointerEvent(info);
8362
8375
  if (info.name !== clickInfo.name) {
8363
8376
  this.root.handleEvent(info);
@@ -8379,7 +8392,7 @@ class Editor extends import_eventemitter3.default {
8379
8392
  maybeTrackPerformance(name) {
8380
8393
  if (import_debug_flags.debugFlags.measurePerformance.get()) {
8381
8394
  if (this.performanceTracker.isStarted()) {
8382
- clearTimeout(this.performanceTrackerTimeout);
8395
+ this.timers.clearTimeout(this.performanceTrackerTimeout);
8383
8396
  } else {
8384
8397
  this.performanceTracker.start(name);
8385
8398
  }