@tldraw/editor 3.16.0-next.eafb52d15064 → 3.16.0-next.fe14f1b4181f
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.
- package/dist-cjs/index.d.ts +30 -0
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/TldrawEditor.js +6 -2
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +0 -5
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +7 -10
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -23
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +9 -1
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
- package/dist-cjs/lib/config/TLUserPreferences.js +1 -1
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +44 -15
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +1 -1
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +13 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgJsx.js +35 -16
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +31 -25
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +6 -6
- package/dist-cjs/lib/license/Watermark.js.map +1 -1
- package/dist-cjs/lib/options.js +6 -0
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +3 -0
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +30 -0
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/TldrawEditor.mjs +6 -2
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +0 -5
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +7 -10
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +4 -23
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +1 -1
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +9 -1
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
- package/dist-esm/lib/config/TLUserPreferences.mjs +1 -1
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +44 -15
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +13 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +36 -16
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +32 -26
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +6 -6
- package/dist-esm/lib/license/Watermark.mjs.map +1 -1
- package/dist-esm/lib/options.mjs +6 -0
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +4 -1
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +301 -290
- package/package.json +14 -37
- package/src/lib/TldrawEditor.tsx +11 -6
- package/src/lib/components/MenuClickCapture.tsx +0 -8
- package/src/lib/components/Shape.tsx +6 -12
- package/src/lib/components/default-components/DefaultCanvas.tsx +5 -22
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
- package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +5 -1
- package/src/lib/config/TLUserPreferences.ts +1 -1
- package/src/lib/editor/Editor.test.ts +12 -11
- package/src/lib/editor/Editor.ts +55 -20
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +15 -14
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +16 -15
- package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +49 -48
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +24 -23
- package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +7 -6
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +12 -11
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +57 -50
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +51 -26
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +14 -13
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +21 -26
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +1 -1
- package/src/lib/editor/shapes/ShapeUtil.ts +14 -0
- package/src/lib/exports/getSvgJsx.test.ts +868 -0
- package/src/lib/exports/getSvgJsx.tsx +78 -21
- package/src/lib/hooks/useCanvasEvents.ts +45 -38
- package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
- package/src/lib/license/LicenseManager.test.ts +3 -1
- package/src/lib/license/Watermark.test.tsx +2 -1
- package/src/lib/license/Watermark.tsx +6 -6
- package/src/lib/options.ts +6 -0
- package/src/lib/primitives/Box.test.ts +126 -0
- package/src/lib/primitives/Box.ts +10 -1
- package/src/lib/utils/sync/LocalIndexedDb.test.ts +2 -1
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
- package/src/version.ts +3 -3
- package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
- package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
- package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
- package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
- package/src/lib/utils/nearestMultiple.ts +0 -13
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/hooks/usePassThroughWheelEvents.ts"],
|
|
4
|
-
"sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\n\n/** @public */\nexport function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\n\tuseEffect(() => {\n\t\tfunction onWheel(e: WheelEvent) {\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\n\t\t\t// if the element is scrollable, don't redispatch the event\n\t\t\tconst elm = ref.current\n\t\t\tif (elm && elm.scrollHeight > elm.clientHeight) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new WheelEvent('wheel', e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('wheel', onWheel, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('wheel', onWheel)\n\t\t}\n\t}, [container, ref])\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,iBAA+B;AAC/B,0BAA6B;
|
|
4
|
+
"sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\nimport { useMaybeEditor } from './useEditor'\n\n/** @public */\nexport function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\tconst editor = useMaybeEditor()\n\n\tuseEffect(() => {\n\t\tfunction onWheel(e: WheelEvent) {\n\t\t\t// Only pass through wheel events if the editor is focused\n\t\t\tif (!editor?.getInstanceState().isFocused) return\n\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\n\t\t\t// if the element is scrollable, don't redispatch the event\n\t\t\tconst elm = ref.current\n\t\t\tif (elm && elm.scrollHeight > elm.clientHeight) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new WheelEvent('wheel', e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('wheel', onWheel, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('wheel', onWheel)\n\t\t}\n\t}, [container, editor, ref])\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,iBAA+B;AAC/B,0BAA6B;AAC7B,uBAA+B;AAGxB,SAAS,0BAA0B,KAA6B;AACtE,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,gBAAY,kCAAa;AAC/B,QAAM,aAAS,iCAAe;AAE9B,8BAAU,MAAM;AACf,aAAS,QAAQ,GAAe;AAE/B,UAAI,CAAC,QAAQ,iBAAiB,EAAE,UAAW;AAE3C,UAAK,EAAU,2BAA4B;AAG3C,YAAMA,OAAM,IAAI;AAChB,UAAIA,QAAOA,KAAI,eAAeA,KAAI,cAAc;AAC/C;AAAA,MACD;AAEA,qCAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,WAAW,SAAS,CAAQ;AAChD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,SAAS,SAAS,EAAE,SAAS,MAAM,CAAC;AACzD,WAAO,MAAM;AACZ,UAAI,oBAAoB,SAAS,OAAO;AAAA,IACzC;AAAA,EACD,GAAG,CAAC,WAAW,QAAQ,GAAG,CAAC;AAC5B;",
|
|
6
6
|
"names": ["elm"]
|
|
7
7
|
}
|
|
@@ -99,15 +99,15 @@ To remove the watermark, please purchase a license at tldraw.dev.
|
|
|
99
99
|
|
|
100
100
|
.${className} {
|
|
101
101
|
position: absolute;
|
|
102
|
-
bottom: var(--space-2);
|
|
103
|
-
right: var(--space-2);
|
|
102
|
+
bottom: var(--tl-space-2);
|
|
103
|
+
right: var(--tl-space-2);
|
|
104
104
|
width: 96px;
|
|
105
105
|
height: 32px;
|
|
106
106
|
display: flex;
|
|
107
107
|
align-items: center;
|
|
108
108
|
justify-content: center;
|
|
109
|
-
z-index: var(--layer-watermark) !important;
|
|
110
|
-
background-color: color-mix(in srgb, var(--color-background) 62%, transparent);
|
|
109
|
+
z-index: var(--tl-layer-watermark) !important;
|
|
110
|
+
background-color: color-mix(in srgb, var(--tl-color-background) 62%, transparent);
|
|
111
111
|
opacity: 1;
|
|
112
112
|
border-radius: 5px;
|
|
113
113
|
pointer-events: all;
|
|
@@ -121,7 +121,7 @@ To remove the watermark, please purchase a license at tldraw.dev.
|
|
|
121
121
|
height: 32px;
|
|
122
122
|
pointer-events: all;
|
|
123
123
|
cursor: inherit;
|
|
124
|
-
color: var(--color-text);
|
|
124
|
+
color: var(--tl-color-text);
|
|
125
125
|
opacity: .38;
|
|
126
126
|
border: 0;
|
|
127
127
|
padding: 0;
|
|
@@ -150,7 +150,7 @@ To remove the watermark, please purchase a license at tldraw.dev.
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
.${className}:hover {
|
|
153
|
-
background-color: var(--color-background);
|
|
153
|
+
background-color: var(--tl-color-background);
|
|
154
154
|
transition: background-color 0.2s ease-in-out;
|
|
155
155
|
transition-delay: 0.32s;
|
|
156
156
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/license/Watermark.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { memo, useRef } from 'react'\nimport { useCanvasEvents } from '../hooks/useCanvasEvents'\nimport { useEditor } from '../hooks/useEditor'\nimport { usePassThroughWheelEvents } from '../hooks/usePassThroughWheelEvents'\nimport { preventDefault, stopEventPropagation } from '../utils/dom'\nimport { runtime } from '../utils/runtime'\nimport { watermarkDesktopSvg, watermarkMobileSvg } from '../watermarks'\nimport { LicenseManager } from './LicenseManager'\nimport { useLicenseContext } from './LicenseProvider'\nimport { useLicenseManagerState } from './useLicenseManagerState'\n\nconst WATERMARK_DESKTOP_LOCAL_SRC = `data:image/svg+xml;utf8,${encodeURIComponent(watermarkDesktopSvg)}`\nconst WATERMARK_MOBILE_LOCAL_SRC = `data:image/svg+xml;utf8,${encodeURIComponent(watermarkMobileSvg)}`\n\n/** @internal */\nexport const Watermark = memo(function Watermark() {\n\tconst licenseManager = useLicenseContext()\n\tconst editor = useEditor()\n\tconst isMobile = useValue('is mobile', () => editor.getViewportScreenBounds().width < 700, [\n\t\teditor,\n\t])\n\n\tconst licenseManagerState = useLicenseManagerState(licenseManager)\n\n\tif (!['licensed-with-watermark', 'unlicensed'].includes(licenseManagerState)) return null\n\n\treturn (\n\t\t<>\n\t\t\t<LicenseStyles />\n\t\t\t<WatermarkInner src={isMobile ? WATERMARK_MOBILE_LOCAL_SRC : WATERMARK_DESKTOP_LOCAL_SRC} />\n\t\t</>\n\t)\n})\n\nconst WatermarkInner = memo(function WatermarkInner({ src }: { src: string }) {\n\tconst editor = useEditor()\n\tconst isDebugMode = useValue('debug mode', () => editor.getInstanceState().isDebugMode, [editor])\n\tconst isMobile = useValue('is mobile', () => editor.getViewportScreenBounds().width < 700, [\n\t\teditor,\n\t])\n\tconst events = useCanvasEvents()\n\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\n\tconst maskCss = `url('${src}') center 100% / 100% no-repeat`\n\tconst url = 'https://tldraw.dev/?utm_source=dotcom&utm_medium=organic&utm_campaign=watermark'\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tclassName={LicenseManager.className}\n\t\t\tdata-debug={isDebugMode}\n\t\t\tdata-mobile={isMobile}\n\t\t\tdraggable={false}\n\t\t\t{...events}\n\t\t>\n\t\t\t<button\n\t\t\t\tdraggable={false}\n\t\t\t\trole=\"button\"\n\t\t\t\tonPointerDown={(e) => {\n\t\t\t\t\tstopEventPropagation(e)\n\t\t\t\t\tpreventDefault(e)\n\t\t\t\t}}\n\t\t\t\ttitle=\"made with tldraw\"\n\t\t\t\tonClick={() => runtime.openWindow(url, '_blank')}\n\t\t\t\tstyle={{ mask: maskCss, WebkitMask: maskCss }}\n\t\t\t/>\n\t\t</div>\n\t)\n})\n\nconst LicenseStyles = memo(function LicenseStyles() {\n\tconst editor = useEditor()\n\tconst className = LicenseManager.className\n\n\tconst CSS = `/* ------------------- SEE LICENSE -------------------\nThe tldraw watermark is part of tldraw's license. It is shown for unlicensed\nor \"licensed-with-watermark\" users. By using this library, you agree to\npreserve the watermark's behavior, keeping it visible, unobscured, and\navailable to user-interaction.\n\nTo remove the watermark, please purchase a license at tldraw.dev.\n*/\n\n\t.${className} {\n\t\tposition: absolute;\n\t\tbottom: var(--space-2);\n\t\tright: var(--space-2);\n\t\twidth: 96px;\n\t\theight: 32px;\n\t\tdisplay: flex;\n\t\talign-items: center;\n\t\tjustify-content: center;\n\t\tz-index: var(--layer-watermark) !important;\n\t\tbackground-color: color-mix(in srgb, var(--color-background) 62%, transparent);\n\t\topacity: 1;\n\t\tborder-radius: 5px;\n\t\tpointer-events: all;\n\t\tpadding: 2px;\n\t\tbox-sizing: content-box;\n\t}\n\n\t.${className} > button {\n\t\tposition: absolute;\n\t\twidth: 96px;\n\t\theight: 32px;\n\t\tpointer-events: all;\n\t\tcursor: inherit;\n\t\tcolor: var(--color-text);\n\t\topacity: .38;\n\t\tborder: 0;\n\t\tpadding: 0;\n\t\tbackground-color: currentColor;\n\t}\n\n\t.${className}[data-debug='true'] {\n\t\tbottom: 46px;\n\t}\n\n\t.${className}[data-mobile='true'] {\n\t\tborder-radius: 4px 0px 0px 4px;\n\t\tright: -2px;\n\t\twidth: 8px;\n\t\theight: 48px;\n\t}\n\n\t.${className}[data-mobile='true'] > button {\n\t\twidth: 8px;\n\t\theight: 32px;\n\t}\n\n\t@media (hover: hover) {\n\t\t.${className} > button {\n\t\t\tpointer-events: none;\n\t\t}\n\n\t\t.${className}:hover {\n\t\t\tbackground-color: var(--color-background);\n\t\t\ttransition: background-color 0.2s ease-in-out;\n\t\t\ttransition-delay: 0.32s;\n\t\t}\n\n\t\t.${className}:hover > button {\n\t\t\tanimation: ${className}_delayed_link 0.2s forwards ease-in-out;\n\t\t\tanimation-delay: 0.32s;\n\t\t}\n\n\t\t.${className} > button:focus-visible {\n\t\t\topacity: 1;\n\t\t}\n\t}\n\n\n\t@keyframes ${className}_delayed_link {\n\t\t0% {\n\t\t\tcursor: inherit;\n\t\t\topacity: .38;\n\t\t\tpointer-events: none;\n\t\t}\n\t\t100% {\n\t\t\tcursor: pointer;\n\t\t\topacity: 1;\n\t\t\tpointer-events: all;\n\t\t}\n\t}`\n\n\treturn <style nonce={editor.options.nonce}>{CSS}</style>\n})\n"],
|
|
4
|
+
"sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { memo, useRef } from 'react'\nimport { useCanvasEvents } from '../hooks/useCanvasEvents'\nimport { useEditor } from '../hooks/useEditor'\nimport { usePassThroughWheelEvents } from '../hooks/usePassThroughWheelEvents'\nimport { preventDefault, stopEventPropagation } from '../utils/dom'\nimport { runtime } from '../utils/runtime'\nimport { watermarkDesktopSvg, watermarkMobileSvg } from '../watermarks'\nimport { LicenseManager } from './LicenseManager'\nimport { useLicenseContext } from './LicenseProvider'\nimport { useLicenseManagerState } from './useLicenseManagerState'\n\nconst WATERMARK_DESKTOP_LOCAL_SRC = `data:image/svg+xml;utf8,${encodeURIComponent(watermarkDesktopSvg)}`\nconst WATERMARK_MOBILE_LOCAL_SRC = `data:image/svg+xml;utf8,${encodeURIComponent(watermarkMobileSvg)}`\n\n/** @internal */\nexport const Watermark = memo(function Watermark() {\n\tconst licenseManager = useLicenseContext()\n\tconst editor = useEditor()\n\tconst isMobile = useValue('is mobile', () => editor.getViewportScreenBounds().width < 700, [\n\t\teditor,\n\t])\n\n\tconst licenseManagerState = useLicenseManagerState(licenseManager)\n\n\tif (!['licensed-with-watermark', 'unlicensed'].includes(licenseManagerState)) return null\n\n\treturn (\n\t\t<>\n\t\t\t<LicenseStyles />\n\t\t\t<WatermarkInner src={isMobile ? WATERMARK_MOBILE_LOCAL_SRC : WATERMARK_DESKTOP_LOCAL_SRC} />\n\t\t</>\n\t)\n})\n\nconst WatermarkInner = memo(function WatermarkInner({ src }: { src: string }) {\n\tconst editor = useEditor()\n\tconst isDebugMode = useValue('debug mode', () => editor.getInstanceState().isDebugMode, [editor])\n\tconst isMobile = useValue('is mobile', () => editor.getViewportScreenBounds().width < 700, [\n\t\teditor,\n\t])\n\tconst events = useCanvasEvents()\n\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\n\tconst maskCss = `url('${src}') center 100% / 100% no-repeat`\n\tconst url = 'https://tldraw.dev/?utm_source=dotcom&utm_medium=organic&utm_campaign=watermark'\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tclassName={LicenseManager.className}\n\t\t\tdata-debug={isDebugMode}\n\t\t\tdata-mobile={isMobile}\n\t\t\tdraggable={false}\n\t\t\t{...events}\n\t\t>\n\t\t\t<button\n\t\t\t\tdraggable={false}\n\t\t\t\trole=\"button\"\n\t\t\t\tonPointerDown={(e) => {\n\t\t\t\t\tstopEventPropagation(e)\n\t\t\t\t\tpreventDefault(e)\n\t\t\t\t}}\n\t\t\t\ttitle=\"made with tldraw\"\n\t\t\t\tonClick={() => runtime.openWindow(url, '_blank')}\n\t\t\t\tstyle={{ mask: maskCss, WebkitMask: maskCss }}\n\t\t\t/>\n\t\t</div>\n\t)\n})\n\nconst LicenseStyles = memo(function LicenseStyles() {\n\tconst editor = useEditor()\n\tconst className = LicenseManager.className\n\n\tconst CSS = `/* ------------------- SEE LICENSE -------------------\nThe tldraw watermark is part of tldraw's license. It is shown for unlicensed\nor \"licensed-with-watermark\" users. By using this library, you agree to\npreserve the watermark's behavior, keeping it visible, unobscured, and\navailable to user-interaction.\n\nTo remove the watermark, please purchase a license at tldraw.dev.\n*/\n\n\t.${className} {\n\t\tposition: absolute;\n\t\tbottom: var(--tl-space-2);\n\t\tright: var(--tl-space-2);\n\t\twidth: 96px;\n\t\theight: 32px;\n\t\tdisplay: flex;\n\t\talign-items: center;\n\t\tjustify-content: center;\n\t\tz-index: var(--tl-layer-watermark) !important;\n\t\tbackground-color: color-mix(in srgb, var(--tl-color-background) 62%, transparent);\n\t\topacity: 1;\n\t\tborder-radius: 5px;\n\t\tpointer-events: all;\n\t\tpadding: 2px;\n\t\tbox-sizing: content-box;\n\t}\n\n\t.${className} > button {\n\t\tposition: absolute;\n\t\twidth: 96px;\n\t\theight: 32px;\n\t\tpointer-events: all;\n\t\tcursor: inherit;\n\t\tcolor: var(--tl-color-text);\n\t\topacity: .38;\n\t\tborder: 0;\n\t\tpadding: 0;\n\t\tbackground-color: currentColor;\n\t}\n\n\t.${className}[data-debug='true'] {\n\t\tbottom: 46px;\n\t}\n\n\t.${className}[data-mobile='true'] {\n\t\tborder-radius: 4px 0px 0px 4px;\n\t\tright: -2px;\n\t\twidth: 8px;\n\t\theight: 48px;\n\t}\n\n\t.${className}[data-mobile='true'] > button {\n\t\twidth: 8px;\n\t\theight: 32px;\n\t}\n\n\t@media (hover: hover) {\n\t\t.${className} > button {\n\t\t\tpointer-events: none;\n\t\t}\n\n\t\t.${className}:hover {\n\t\t\tbackground-color: var(--tl-color-background);\n\t\t\ttransition: background-color 0.2s ease-in-out;\n\t\t\ttransition-delay: 0.32s;\n\t\t}\n\n\t\t.${className}:hover > button {\n\t\t\tanimation: ${className}_delayed_link 0.2s forwards ease-in-out;\n\t\t\tanimation-delay: 0.32s;\n\t\t}\n\n\t\t.${className} > button:focus-visible {\n\t\t\topacity: 1;\n\t\t}\n\t}\n\n\n\t@keyframes ${className}_delayed_link {\n\t\t0% {\n\t\t\tcursor: inherit;\n\t\t\topacity: .38;\n\t\t\tpointer-events: none;\n\t\t}\n\t\t100% {\n\t\t\tcursor: pointer;\n\t\t\topacity: 1;\n\t\t\tpointer-events: all;\n\t\t}\n\t}`\n\n\treturn <style nonce={editor.options.nonce}>{CSS}</style>\n})\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BE;AA5BF,yBAAyB;AACzB,mBAA6B;AAC7B,6BAAgC;AAChC,uBAA0B;AAC1B,uCAA0C;AAC1C,iBAAqD;AACrD,qBAAwB;AACxB,wBAAwD;AACxD,4BAA+B;AAC/B,6BAAkC;AAClC,oCAAuC;AAEvC,MAAM,8BAA8B,2BAA2B,mBAAmB,qCAAmB,CAAC;AACtG,MAAM,6BAA6B,2BAA2B,mBAAmB,oCAAkB,CAAC;AAG7F,MAAM,gBAAY,mBAAK,SAASA,aAAY;AAClD,QAAM,qBAAiB,0CAAkB;AACzC,QAAM,aAAS,4BAAU;AACzB,QAAM,eAAW,6BAAS,aAAa,MAAM,OAAO,wBAAwB,EAAE,QAAQ,KAAK;AAAA,IAC1F;AAAA,EACD,CAAC;AAED,QAAM,0BAAsB,sDAAuB,cAAc;AAEjE,MAAI,CAAC,CAAC,2BAA2B,YAAY,EAAE,SAAS,mBAAmB,EAAG,QAAO;AAErF,SACC,4EACC;AAAA,gDAAC,iBAAc;AAAA,IACf,4CAAC,kBAAe,KAAK,WAAW,6BAA6B,6BAA6B;AAAA,KAC3F;AAEF,CAAC;AAED,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AAA;AAAA;AAAA;AAAA,IAIT,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOT,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAMR,SAAS;AAAA;AAAA;AAAA;AAAA,KAIT,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAMT,SAAS;AAAA,gBACE,SAAS;AAAA;AAAA;AAAA;AAAA,KAIpB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAMA,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAatB,SAAO,4CAAC,WAAM,OAAO,OAAO,QAAQ,OAAQ,eAAI;AACjD,CAAC;",
|
|
6
6
|
"names": ["Watermark", "WatermarkInner", "LicenseStyles"]
|
|
7
7
|
}
|
package/dist-cjs/lib/options.js
CHANGED
|
@@ -34,6 +34,12 @@ const defaultTldrawOptions = {
|
|
|
34
34
|
// 6 squared
|
|
35
35
|
dragDistanceSquared: 16,
|
|
36
36
|
// 4 squared
|
|
37
|
+
uiDragDistanceSquared: 16,
|
|
38
|
+
// 4 squared
|
|
39
|
+
// it's really easy to accidentally drag from the toolbar on mobile, so we use a much larger
|
|
40
|
+
// threshold than usual here to try and prevent accidental drags.
|
|
41
|
+
uiCoarseDragDistanceSquared: 625,
|
|
42
|
+
// 25 squared
|
|
37
43
|
defaultSvgPadding: 32,
|
|
38
44
|
cameraSlideFriction: 0.09,
|
|
39
45
|
gridSteps: [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/options.ts"],
|
|
4
|
-
"sourcesContent": ["import { ComponentType, Fragment } from 'react'\n\n/**\n * Options for configuring tldraw. For defaults, see {@link defaultTldrawOptions}.\n *\n * @example\n * ```tsx\n * const options: Partial<TldrawOptions> = {\n * maxPages: 3,\n * maxShapesPerPage: 1000,\n * }\n *\n * function MyTldrawComponent() {\n * return <Tldraw options={options} />\n * }\n * ```\n *\n * @public\n */\nexport interface TldrawOptions {\n\treadonly maxShapesPerPage: number\n\treadonly maxFilesAtOnce: number\n\treadonly maxPages: number\n\treadonly animationMediumMs: number\n\treadonly followChaseViewportSnap: number\n\treadonly doubleClickDurationMs: number\n\treadonly multiClickDurationMs: number\n\treadonly coarseDragDistanceSquared: number\n\treadonly dragDistanceSquared: number\n\treadonly defaultSvgPadding: number\n\treadonly cameraSlideFriction: number\n\treadonly gridSteps: readonly {\n\t\treadonly min: number\n\t\treadonly mid: number\n\t\treadonly step: number\n\t}[]\n\treadonly collaboratorInactiveTimeoutMs: number\n\treadonly collaboratorIdleTimeoutMs: number\n\treadonly collaboratorCheckIntervalMs: number\n\treadonly cameraMovingTimeoutMs: number\n\treadonly hitTestMargin: number\n\treadonly edgeScrollDelay: number\n\treadonly edgeScrollEaseDuration: number\n\treadonly edgeScrollSpeed: number\n\treadonly edgeScrollDistance: number\n\treadonly coarsePointerWidth: number\n\treadonly coarseHandleRadius: number\n\treadonly handleRadius: number\n\treadonly longPressDurationMs: number\n\treadonly textShadowLod: number\n\treadonly adjacentShapeMargin: number\n\treadonly flattenImageBoundsExpand: number\n\treadonly flattenImageBoundsPadding: number\n\treadonly laserDelayMs: number\n\treadonly maxExportDelayMs: number\n\treadonly tooltipDelayMs: number\n\t/**\n\t * How long should previews created by {@link Editor.createTemporaryAssetPreview} last before\n\t * they expire? Defaults to 3 minutes.\n\t */\n\treadonly temporaryAssetPreviewLifetimeMs: number\n\treadonly actionShortcutsLocation: 'menu' | 'toolbar' | 'swap'\n\treadonly createTextOnCanvasDoubleClick: boolean\n\t/**\n\t * The react provider to use when exporting an image. This is useful if your shapes depend on\n\t * external context providers. By default, this is `React.Fragment`.\n\t */\n\treadonly exportProvider: ComponentType<{ children: React.ReactNode }>\n\t/**\n\t * By default, the toolbar items are accessible via number shortcuts according to their order. To disable this, set this option to false.\n\t */\n\treadonly enableToolbarKeyboardShortcuts: boolean\n\t/**\n\t * The maximum number of fonts that will be loaded while blocking the main rendering of the\n\t * canvas. If there are more than this number of fonts needed, we'll just show the canvas right\n\t * away and let the fonts load in in the background.\n\t */\n\treadonly maxFontsToLoadBeforeRender: number\n\t/**\n\t * If you have a CSP policy that blocks inline styles, you can use this prop to provide a\n\t * nonce to use in the editor's styles.\n\t */\n\treadonly nonce: string | undefined\n\t/**\n\t * Branding name of the app, currently only used for adding aria-label for the application.\n\t */\n\treadonly branding?: string\n}\n\n/** @public */\nexport const defaultTldrawOptions = {\n\tmaxShapesPerPage: 4000,\n\tmaxFilesAtOnce: 100,\n\tmaxPages: 40,\n\tanimationMediumMs: 320,\n\tfollowChaseViewportSnap: 2,\n\tdoubleClickDurationMs: 450,\n\tmultiClickDurationMs: 200,\n\tcoarseDragDistanceSquared: 36, // 6 squared\n\tdragDistanceSquared: 16, // 4 squared\n\tdefaultSvgPadding: 32,\n\tcameraSlideFriction: 0.09,\n\tgridSteps: [\n\t\t{ min: -1, mid: 0.15, step: 64 },\n\t\t{ min: 0.05, mid: 0.375, step: 16 },\n\t\t{ min: 0.15, mid: 1, step: 4 },\n\t\t{ min: 0.7, mid: 2.5, step: 1 },\n\t],\n\tcollaboratorInactiveTimeoutMs: 60000,\n\tcollaboratorIdleTimeoutMs: 3000,\n\tcollaboratorCheckIntervalMs: 1200,\n\tcameraMovingTimeoutMs: 64,\n\thitTestMargin: 8,\n\tedgeScrollDelay: 200,\n\tedgeScrollEaseDuration: 200,\n\tedgeScrollSpeed: 25,\n\tedgeScrollDistance: 8,\n\tcoarsePointerWidth: 12,\n\tcoarseHandleRadius: 20,\n\thandleRadius: 12,\n\tlongPressDurationMs: 500,\n\ttextShadowLod: 0.35,\n\tadjacentShapeMargin: 10,\n\tflattenImageBoundsExpand: 64,\n\tflattenImageBoundsPadding: 16,\n\tlaserDelayMs: 1200,\n\tmaxExportDelayMs: 5000,\n\ttooltipDelayMs: 700,\n\ttemporaryAssetPreviewLifetimeMs: 180000,\n\tactionShortcutsLocation: 'swap',\n\tcreateTextOnCanvasDoubleClick: true,\n\texportProvider: Fragment,\n\tenableToolbarKeyboardShortcuts: true,\n\tmaxFontsToLoadBeforeRender: Infinity,\n\tnonce: undefined,\n} as const satisfies TldrawOptions\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwC;
|
|
4
|
+
"sourcesContent": ["import { ComponentType, Fragment } from 'react'\n\n/**\n * Options for configuring tldraw. For defaults, see {@link defaultTldrawOptions}.\n *\n * @example\n * ```tsx\n * const options: Partial<TldrawOptions> = {\n * maxPages: 3,\n * maxShapesPerPage: 1000,\n * }\n *\n * function MyTldrawComponent() {\n * return <Tldraw options={options} />\n * }\n * ```\n *\n * @public\n */\nexport interface TldrawOptions {\n\treadonly maxShapesPerPage: number\n\treadonly maxFilesAtOnce: number\n\treadonly maxPages: number\n\treadonly animationMediumMs: number\n\treadonly followChaseViewportSnap: number\n\treadonly doubleClickDurationMs: number\n\treadonly multiClickDurationMs: number\n\treadonly coarseDragDistanceSquared: number\n\treadonly dragDistanceSquared: number\n\treadonly uiDragDistanceSquared: number\n\treadonly uiCoarseDragDistanceSquared: number\n\treadonly defaultSvgPadding: number\n\treadonly cameraSlideFriction: number\n\treadonly gridSteps: readonly {\n\t\treadonly min: number\n\t\treadonly mid: number\n\t\treadonly step: number\n\t}[]\n\treadonly collaboratorInactiveTimeoutMs: number\n\treadonly collaboratorIdleTimeoutMs: number\n\treadonly collaboratorCheckIntervalMs: number\n\treadonly cameraMovingTimeoutMs: number\n\treadonly hitTestMargin: number\n\treadonly edgeScrollDelay: number\n\treadonly edgeScrollEaseDuration: number\n\treadonly edgeScrollSpeed: number\n\treadonly edgeScrollDistance: number\n\treadonly coarsePointerWidth: number\n\treadonly coarseHandleRadius: number\n\treadonly handleRadius: number\n\treadonly longPressDurationMs: number\n\treadonly textShadowLod: number\n\treadonly adjacentShapeMargin: number\n\treadonly flattenImageBoundsExpand: number\n\treadonly flattenImageBoundsPadding: number\n\treadonly laserDelayMs: number\n\treadonly maxExportDelayMs: number\n\treadonly tooltipDelayMs: number\n\t/**\n\t * How long should previews created by {@link Editor.createTemporaryAssetPreview} last before\n\t * they expire? Defaults to 3 minutes.\n\t */\n\treadonly temporaryAssetPreviewLifetimeMs: number\n\treadonly actionShortcutsLocation: 'menu' | 'toolbar' | 'swap'\n\treadonly createTextOnCanvasDoubleClick: boolean\n\t/**\n\t * The react provider to use when exporting an image. This is useful if your shapes depend on\n\t * external context providers. By default, this is `React.Fragment`.\n\t */\n\treadonly exportProvider: ComponentType<{ children: React.ReactNode }>\n\t/**\n\t * By default, the toolbar items are accessible via number shortcuts according to their order. To disable this, set this option to false.\n\t */\n\treadonly enableToolbarKeyboardShortcuts: boolean\n\t/**\n\t * The maximum number of fonts that will be loaded while blocking the main rendering of the\n\t * canvas. If there are more than this number of fonts needed, we'll just show the canvas right\n\t * away and let the fonts load in in the background.\n\t */\n\treadonly maxFontsToLoadBeforeRender: number\n\t/**\n\t * If you have a CSP policy that blocks inline styles, you can use this prop to provide a\n\t * nonce to use in the editor's styles.\n\t */\n\treadonly nonce: string | undefined\n\t/**\n\t * Branding name of the app, currently only used for adding aria-label for the application.\n\t */\n\treadonly branding?: string\n}\n\n/** @public */\nexport const defaultTldrawOptions = {\n\tmaxShapesPerPage: 4000,\n\tmaxFilesAtOnce: 100,\n\tmaxPages: 40,\n\tanimationMediumMs: 320,\n\tfollowChaseViewportSnap: 2,\n\tdoubleClickDurationMs: 450,\n\tmultiClickDurationMs: 200,\n\tcoarseDragDistanceSquared: 36, // 6 squared\n\tdragDistanceSquared: 16, // 4 squared\n\tuiDragDistanceSquared: 16, // 4 squared\n\t// it's really easy to accidentally drag from the toolbar on mobile, so we use a much larger\n\t// threshold than usual here to try and prevent accidental drags.\n\tuiCoarseDragDistanceSquared: 625, // 25 squared\n\tdefaultSvgPadding: 32,\n\tcameraSlideFriction: 0.09,\n\tgridSteps: [\n\t\t{ min: -1, mid: 0.15, step: 64 },\n\t\t{ min: 0.05, mid: 0.375, step: 16 },\n\t\t{ min: 0.15, mid: 1, step: 4 },\n\t\t{ min: 0.7, mid: 2.5, step: 1 },\n\t],\n\tcollaboratorInactiveTimeoutMs: 60000,\n\tcollaboratorIdleTimeoutMs: 3000,\n\tcollaboratorCheckIntervalMs: 1200,\n\tcameraMovingTimeoutMs: 64,\n\thitTestMargin: 8,\n\tedgeScrollDelay: 200,\n\tedgeScrollEaseDuration: 200,\n\tedgeScrollSpeed: 25,\n\tedgeScrollDistance: 8,\n\tcoarsePointerWidth: 12,\n\tcoarseHandleRadius: 20,\n\thandleRadius: 12,\n\tlongPressDurationMs: 500,\n\ttextShadowLod: 0.35,\n\tadjacentShapeMargin: 10,\n\tflattenImageBoundsExpand: 64,\n\tflattenImageBoundsPadding: 16,\n\tlaserDelayMs: 1200,\n\tmaxExportDelayMs: 5000,\n\ttooltipDelayMs: 700,\n\ttemporaryAssetPreviewLifetimeMs: 180000,\n\tactionShortcutsLocation: 'swap',\n\tcreateTextOnCanvasDoubleClick: true,\n\texportProvider: Fragment,\n\tenableToolbarKeyboardShortcuts: true,\n\tmaxFontsToLoadBeforeRender: Infinity,\n\tnonce: undefined,\n} as const satisfies TldrawOptions\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwC;AA4FjC,MAAM,uBAAuB;AAAA,EACnC,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,yBAAyB;AAAA,EACzB,uBAAuB;AAAA,EACvB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA;AAAA,EAC3B,qBAAqB;AAAA;AAAA,EACrB,uBAAuB;AAAA;AAAA;AAAA;AAAA,EAGvB,6BAA6B;AAAA;AAAA,EAC7B,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,WAAW;AAAA,IACV,EAAE,KAAK,IAAI,KAAK,MAAM,MAAM,GAAG;AAAA,IAC/B,EAAE,KAAK,MAAM,KAAK,OAAO,MAAM,GAAG;AAAA,IAClC,EAAE,KAAK,MAAM,KAAK,GAAG,MAAM,EAAE;AAAA,IAC7B,EAAE,KAAK,KAAK,KAAK,KAAK,MAAM,EAAE;AAAA,EAC/B;AAAA,EACA,+BAA+B;AAAA,EAC/B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,uBAAuB;AAAA,EACvB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,wBAAwB;AAAA,EACxB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,qBAAqB;AAAA,EACrB,eAAe;AAAA,EACf,qBAAqB;AAAA,EACrB,0BAA0B;AAAA,EAC1B,2BAA2B;AAAA,EAC3B,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,iCAAiC;AAAA,EACjC,yBAAyB;AAAA,EACzB,+BAA+B;AAAA,EAC/B,gBAAgB;AAAA,EAChB,gCAAgC;AAAA,EAChC,4BAA4B;AAAA,EAC5B,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -357,6 +357,9 @@ class Box {
|
|
|
357
357
|
static Contains(A, B) {
|
|
358
358
|
return A.minX < B.minX && A.minY < B.minY && A.maxY > B.maxY && A.maxX > B.maxX;
|
|
359
359
|
}
|
|
360
|
+
static ContainsApproximately(A, B, precision) {
|
|
361
|
+
return (0, import_utils.approximatelyLte)(A.minX, B.minX, precision) && (0, import_utils.approximatelyLte)(A.minY, B.minY, precision) && (0, import_utils.approximatelyLte)(B.maxX, A.maxX, precision) && (0, import_utils.approximatelyLte)(B.maxY, A.maxY, precision);
|
|
362
|
+
}
|
|
360
363
|
static Includes(A, B) {
|
|
361
364
|
return Box.Collides(A, B) || Box.Contains(A, B);
|
|
362
365
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/primitives/Box.ts"],
|
|
4
|
-
"sourcesContent": ["import { BoxModel } from '@tldraw/tlschema'\nimport { Vec, VecLike } from './Vec'\nimport { PI, PI2, toPrecision } from './utils'\n\n/** @public */\nexport type BoxLike = BoxModel | Box\n\n/** @public */\nexport type SelectionEdge = 'top' | 'right' | 'bottom' | 'left'\n\n/** @public */\nexport type SelectionCorner = 'top_left' | 'top_right' | 'bottom_right' | 'bottom_left'\n\n/** @public */\nexport type SelectionHandle = SelectionEdge | SelectionCorner\n\n/** @public */\nexport type RotateCorner =\n\t| 'top_left_rotate'\n\t| 'top_right_rotate'\n\t| 'bottom_right_rotate'\n\t| 'bottom_left_rotate'\n\t| 'mobile_rotate'\n\n/** @public */\nexport class Box {\n\tconstructor(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t}\n\n\tx = 0\n\ty = 0\n\tw = 0\n\th = 0\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget point() {\n\t\treturn new Vec(this.x, this.y)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset point(val: Vec) {\n\t\tthis.x = val.x\n\t\tthis.y = val.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minX() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minX(n: number) {\n\t\tthis.x = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget left() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midX() {\n\t\treturn this.x + this.w / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxX() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget right() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minY() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minY(n: number) {\n\t\tthis.y = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget top() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midY() {\n\t\treturn this.y + this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxY() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget bottom() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget width() {\n\t\treturn this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset width(n: number) {\n\t\tthis.w = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget height() {\n\t\treturn this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset height(n: number) {\n\t\tthis.h = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget aspectRatio() {\n\t\treturn this.width / this.height\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget center() {\n\t\treturn new Vec(this.x + this.w / 2, this.y + this.h / 2)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset center(v: Vec) {\n\t\tthis.x = v.x - this.w / 2\n\t\tthis.y = v.y - this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget corners() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget cornersAndCenter() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t\tnew Vec(this.x + this.w / 2, this.y + this.h / 2),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget sides(): Array<[Vec, Vec]> {\n\t\tconst { corners } = this\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget size(): Vec {\n\t\treturn new Vec(this.w, this.h)\n\t}\n\n\ttoFixed() {\n\t\tthis.x = toPrecision(this.x)\n\t\tthis.y = toPrecision(this.y)\n\t\tthis.w = toPrecision(this.w)\n\t\tthis.h = toPrecision(this.h)\n\t\treturn this\n\t}\n\n\tsetTo(B: Box) {\n\t\tthis.x = B.x\n\t\tthis.y = B.y\n\t\tthis.w = B.w\n\t\tthis.h = B.h\n\t\treturn this\n\t}\n\n\tset(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t\treturn this\n\t}\n\n\texpand(A: Box) {\n\t\tconst minX = Math.min(this.x, A.x)\n\t\tconst minY = Math.min(this.y, A.y)\n\t\tconst maxX = Math.max(this.x + this.w, A.x + A.w)\n\t\tconst maxY = Math.max(this.y + this.h, A.y + A.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.w = maxX - minX\n\t\tthis.h = maxY - minY\n\t\treturn this\n\t}\n\n\texpandBy(n: number) {\n\t\tthis.x -= n\n\t\tthis.y -= n\n\t\tthis.w += n * 2\n\t\tthis.h += n * 2\n\t\treturn this\n\t}\n\n\tscale(n: number) {\n\t\tthis.x /= n\n\t\tthis.y /= n\n\t\tthis.w /= n\n\t\tthis.h /= n\n\t\treturn this\n\t}\n\n\tclone() {\n\t\tconst { x, y, w, h } = this\n\t\treturn new Box(x, y, w, h)\n\t}\n\n\ttranslate(delta: VecLike) {\n\t\tthis.x += delta.x\n\t\tthis.y += delta.y\n\t\treturn this\n\t}\n\n\tsnapToGrid(size: number) {\n\t\tconst minX = Math.round(this.x / size) * size\n\t\tconst minY = Math.round(this.y / size) * size\n\t\tconst maxX = Math.round((this.x + this.w) / size) * size\n\t\tconst maxY = Math.round((this.y + this.h) / size) * size\n\t\tthis.minX = minX\n\t\tthis.minY = minY\n\t\tthis.width = Math.max(1, maxX - minX)\n\t\tthis.height = Math.max(1, maxY - minY)\n\t}\n\n\tcollides(B: Box) {\n\t\treturn Box.Collides(this, B)\n\t}\n\n\tcontains(B: Box) {\n\t\treturn Box.Contains(this, B)\n\t}\n\n\tincludes(B: Box) {\n\t\treturn Box.Includes(this, B)\n\t}\n\n\tcontainsPoint(V: VecLike, margin = 0) {\n\t\treturn Box.ContainsPoint(this, V, margin)\n\t}\n\n\tgetHandlePoint(handle: SelectionCorner | SelectionEdge) {\n\t\tswitch (handle) {\n\t\t\tcase 'top_left':\n\t\t\t\treturn new Vec(this.x, this.y)\n\t\t\tcase 'top_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y)\n\t\t\tcase 'bottom_left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h)\n\t\t\tcase 'bottom_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h)\n\t\t\tcase 'top':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y)\n\t\t\tcase 'right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h / 2)\n\t\t\tcase 'bottom':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y + this.h)\n\t\t\tcase 'left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h / 2)\n\t\t}\n\t}\n\n\ttoJson(): BoxModel {\n\t\treturn { x: this.x, y: this.y, w: this.w, h: this.h }\n\t}\n\n\tresize(handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = this\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = this\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tthis.minX = b0x\n\t\tthis.minY = b0y\n\t\tthis.width = Math.abs(b1x - b0x)\n\t\tthis.height = Math.abs(b1y - b0y)\n\t}\n\n\tunion(box: BoxModel) {\n\t\tconst minX = Math.min(this.x, box.x)\n\t\tconst minY = Math.min(this.y, box.y)\n\t\tconst maxX = Math.max(this.x + this.w, box.x + box.w)\n\t\tconst maxY = Math.max(this.y + this.h, box.y + box.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.width = maxX - minX\n\t\tthis.height = maxY - minY\n\n\t\treturn this\n\t}\n\n\tstatic From(box: BoxModel) {\n\t\treturn new Box(box.x, box.y, box.w, box.h)\n\t}\n\n\tstatic FromCenter(center: VecLike, size: VecLike) {\n\t\treturn new Box(center.x - size.x / 2, center.y - size.y / 2, size.x, size.y)\n\t}\n\n\tstatic FromPoints(points: VecLike[]) {\n\t\tif (points.length === 0) return new Box()\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\t\tlet point: VecLike\n\t\tfor (let i = 0, n = points.length; i < n; i++) {\n\t\t\tpoint = points[i]\n\t\t\tminX = Math.min(point.x, minX)\n\t\t\tminY = Math.min(point.y, minY)\n\t\t\tmaxX = Math.max(point.x, maxX)\n\t\t\tmaxY = Math.max(point.y, maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Expand(A: Box, B: Box) {\n\t\tconst minX = Math.min(B.minX, A.minX)\n\t\tconst minY = Math.min(B.minY, A.minY)\n\t\tconst maxX = Math.max(B.maxX, A.maxX)\n\t\tconst maxY = Math.max(B.maxY, A.maxY)\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic ExpandBy(A: Box, n: number) {\n\t\treturn new Box(A.minX - n, A.minY - n, A.width + n * 2, A.height + n * 2)\n\t}\n\n\tstatic Collides(A: Box, B: Box) {\n\t\treturn !(A.maxX < B.minX || A.minX > B.maxX || A.maxY < B.minY || A.minY > B.maxY)\n\t}\n\n\tstatic Contains(A: Box, B: Box) {\n\t\treturn A.minX < B.minX && A.minY < B.minY && A.maxY > B.maxY && A.maxX > B.maxX\n\t}\n\n\tstatic Includes(A: Box, B: Box) {\n\t\treturn Box.Collides(A, B) || Box.Contains(A, B)\n\t}\n\n\tstatic ContainsPoint(A: Box, B: VecLike, margin = 0) {\n\t\treturn !(\n\t\t\tB.x < A.minX - margin ||\n\t\t\tB.y < A.minY - margin ||\n\t\t\tB.x > A.maxX + margin ||\n\t\t\tB.y > A.maxY + margin\n\t\t)\n\t}\n\n\tstatic Common(boxes: Box[]) {\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\n\t\tfor (let i = 0; i < boxes.length; i++) {\n\t\t\tconst B = boxes[i]\n\t\t\tminX = Math.min(minX, B.minX)\n\t\t\tminY = Math.min(minY, B.minY)\n\t\t\tmaxX = Math.max(maxX, B.maxX)\n\t\t\tmaxY = Math.max(maxY, B.maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Sides(A: Box, inset = 0) {\n\t\tconst { corners } = A\n\t\tif (inset) {\n\t\t\t// TODO: Inset the corners by the inset amount.\n\t\t}\n\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\tstatic Resize(\n\t\tbox: Box,\n\t\thandle: SelectionCorner | SelectionEdge | string,\n\t\tdx: number,\n\t\tdy: number,\n\t\tisAspectRatioLocked = false\n\t) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = box\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = box\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\t/*\n 2. Aspect ratio\n If the aspect ratio is locked, adjust the corners so that the\n new box's aspect ratio matches the original aspect ratio.\n */\n\t\tif (isAspectRatioLocked) {\n\t\t\tconst aspectRatio = (a1x - a0x) / (a1y - a0y)\n\t\t\tconst bw = Math.abs(b1x - b0x)\n\t\t\tconst bh = Math.abs(b1y - b0y)\n\t\t\tconst tw = bw * (scaleY < 0 ? 1 : -1) * (1 / aspectRatio)\n\t\t\tconst th = bh * (scaleX < 0 ? 1 : -1) * aspectRatio\n\t\t\tconst isTall = aspectRatio < bw / bh\n\n\t\t\tswitch (handle) {\n\t\t\t\tcase 'top_left': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'top_right': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_left': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom':\n\t\t\t\tcase 'top': {\n\t\t\t\t\tconst m = (b0x + b1x) / 2\n\t\t\t\t\tconst w = bh * aspectRatio\n\t\t\t\t\tb0x = m - w / 2\n\t\t\t\t\tb1x = m + w / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'left':\n\t\t\t\tcase 'right': {\n\t\t\t\t\tconst m = (b0y + b1y) / 2\n\t\t\t\t\tconst h = bw / aspectRatio\n\t\t\t\t\tb0y = m - h / 2\n\t\t\t\t\tb1y = m + h / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tconst final = new Box(b0x, b0y, Math.abs(b1x - b0x), Math.abs(b1y - b0y))\n\n\t\treturn {\n\t\t\tbox: final,\n\t\t\tscaleX: +((final.width / box.width) * (scaleX > 0 ? 1 : -1)).toFixed(5),\n\t\t\tscaleY: +((final.height / box.height) * (scaleY > 0 ? 1 : -1)).toFixed(5),\n\t\t}\n\t}\n\n\tequals(other: Box | BoxModel) {\n\t\treturn Box.Equals(this, other)\n\t}\n\n\tstatic Equals(a: Box | BoxModel, b: Box | BoxModel) {\n\t\treturn b.x === a.x && b.y === a.y && b.w === a.w && b.h === a.h\n\t}\n\n\tzeroFix() {\n\t\tthis.w = Math.max(1, this.w)\n\t\tthis.h = Math.max(1, this.h)\n\t\treturn this\n\t}\n\n\tstatic ZeroFix(other: Box | BoxModel) {\n\t\treturn new Box(other.x, other.y, Math.max(1, other.w), Math.max(1, other.h))\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleY(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'top':\n\t\t\treturn 'bottom'\n\t\tcase 'bottom':\n\t\t\treturn 'top'\n\t\tcase 'top_left':\n\t\t\treturn 'bottom_left'\n\t\tcase 'top_right':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_left':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_right':\n\t\t\treturn 'top_right'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleX(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'left':\n\t\t\treturn 'right'\n\t\tcase 'right':\n\t\t\treturn 'left'\n\t\tcase 'top_left':\n\t\t\treturn 'top_right'\n\t\tcase 'top_right':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_left':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_right':\n\t\t\treturn 'bottom_left'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\nconst ORDERED_SELECTION_HANDLES = [\n\t'top',\n\t'top_right',\n\t'right',\n\t'bottom_right',\n\t'bottom',\n\t'bottom_left',\n\t'left',\n\t'top_left',\n] as const\n\n/** @public */\nexport function rotateSelectionHandle(handle: SelectionHandle, rotation: number): SelectionHandle {\n\t// first find out how many tau we need to rotate by\n\trotation = rotation % PI2\n\tconst numSteps = Math.round(rotation / (PI / 4))\n\n\tconst currentIndex = ORDERED_SELECTION_HANDLES.indexOf(handle)\n\treturn ORDERED_SELECTION_HANDLES[(currentIndex + numSteps) % ORDERED_SELECTION_HANDLES.length]\n}\n\n/** @public */\nexport function isSelectionCorner(selection: string): selection is SelectionCorner {\n\treturn (\n\t\tselection === 'top_left' ||\n\t\tselection === 'top_right' ||\n\t\tselection === 'bottom_right' ||\n\t\tselection === 'bottom_left'\n\t)\n}\n\n/** @public */\nexport const ROTATE_CORNER_TO_SELECTION_CORNER = {\n\ttop_left_rotate: 'top_left',\n\ttop_right_rotate: 'top_right',\n\tbottom_right_rotate: 'bottom_right',\n\tbottom_left_rotate: 'bottom_left',\n\tmobile_rotate: 'top_left',\n} as const\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAA6B;AAC7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S,kBAAkB,WAAiD;AAClF,SACC,cAAc,cACd,cAAc,eACd,cAAc,kBACd,cAAc;AAEhB;AAGO,MAAM,oCAAoC;AAAA,EAChD,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,eAAe;AAChB;",
|
|
4
|
+
"sourcesContent": ["import { BoxModel } from '@tldraw/tlschema'\nimport { Vec, VecLike } from './Vec'\nimport { approximatelyLte, PI, PI2, toPrecision } from './utils'\n\n/** @public */\nexport type BoxLike = BoxModel | Box\n\n/** @public */\nexport type SelectionEdge = 'top' | 'right' | 'bottom' | 'left'\n\n/** @public */\nexport type SelectionCorner = 'top_left' | 'top_right' | 'bottom_right' | 'bottom_left'\n\n/** @public */\nexport type SelectionHandle = SelectionEdge | SelectionCorner\n\n/** @public */\nexport type RotateCorner =\n\t| 'top_left_rotate'\n\t| 'top_right_rotate'\n\t| 'bottom_right_rotate'\n\t| 'bottom_left_rotate'\n\t| 'mobile_rotate'\n\n/** @public */\nexport class Box {\n\tconstructor(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t}\n\n\tx = 0\n\ty = 0\n\tw = 0\n\th = 0\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget point() {\n\t\treturn new Vec(this.x, this.y)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset point(val: Vec) {\n\t\tthis.x = val.x\n\t\tthis.y = val.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minX() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minX(n: number) {\n\t\tthis.x = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget left() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midX() {\n\t\treturn this.x + this.w / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxX() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget right() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minY() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minY(n: number) {\n\t\tthis.y = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget top() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midY() {\n\t\treturn this.y + this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxY() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget bottom() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget width() {\n\t\treturn this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset width(n: number) {\n\t\tthis.w = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget height() {\n\t\treturn this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset height(n: number) {\n\t\tthis.h = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget aspectRatio() {\n\t\treturn this.width / this.height\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget center() {\n\t\treturn new Vec(this.x + this.w / 2, this.y + this.h / 2)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset center(v: Vec) {\n\t\tthis.x = v.x - this.w / 2\n\t\tthis.y = v.y - this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget corners() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget cornersAndCenter() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t\tnew Vec(this.x + this.w / 2, this.y + this.h / 2),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget sides(): Array<[Vec, Vec]> {\n\t\tconst { corners } = this\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget size(): Vec {\n\t\treturn new Vec(this.w, this.h)\n\t}\n\n\ttoFixed() {\n\t\tthis.x = toPrecision(this.x)\n\t\tthis.y = toPrecision(this.y)\n\t\tthis.w = toPrecision(this.w)\n\t\tthis.h = toPrecision(this.h)\n\t\treturn this\n\t}\n\n\tsetTo(B: Box) {\n\t\tthis.x = B.x\n\t\tthis.y = B.y\n\t\tthis.w = B.w\n\t\tthis.h = B.h\n\t\treturn this\n\t}\n\n\tset(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t\treturn this\n\t}\n\n\texpand(A: Box) {\n\t\tconst minX = Math.min(this.x, A.x)\n\t\tconst minY = Math.min(this.y, A.y)\n\t\tconst maxX = Math.max(this.x + this.w, A.x + A.w)\n\t\tconst maxY = Math.max(this.y + this.h, A.y + A.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.w = maxX - minX\n\t\tthis.h = maxY - minY\n\t\treturn this\n\t}\n\n\texpandBy(n: number) {\n\t\tthis.x -= n\n\t\tthis.y -= n\n\t\tthis.w += n * 2\n\t\tthis.h += n * 2\n\t\treturn this\n\t}\n\n\tscale(n: number) {\n\t\tthis.x /= n\n\t\tthis.y /= n\n\t\tthis.w /= n\n\t\tthis.h /= n\n\t\treturn this\n\t}\n\n\tclone() {\n\t\tconst { x, y, w, h } = this\n\t\treturn new Box(x, y, w, h)\n\t}\n\n\ttranslate(delta: VecLike) {\n\t\tthis.x += delta.x\n\t\tthis.y += delta.y\n\t\treturn this\n\t}\n\n\tsnapToGrid(size: number) {\n\t\tconst minX = Math.round(this.x / size) * size\n\t\tconst minY = Math.round(this.y / size) * size\n\t\tconst maxX = Math.round((this.x + this.w) / size) * size\n\t\tconst maxY = Math.round((this.y + this.h) / size) * size\n\t\tthis.minX = minX\n\t\tthis.minY = minY\n\t\tthis.width = Math.max(1, maxX - minX)\n\t\tthis.height = Math.max(1, maxY - minY)\n\t}\n\n\tcollides(B: Box) {\n\t\treturn Box.Collides(this, B)\n\t}\n\n\tcontains(B: Box) {\n\t\treturn Box.Contains(this, B)\n\t}\n\n\tincludes(B: Box) {\n\t\treturn Box.Includes(this, B)\n\t}\n\n\tcontainsPoint(V: VecLike, margin = 0) {\n\t\treturn Box.ContainsPoint(this, V, margin)\n\t}\n\n\tgetHandlePoint(handle: SelectionCorner | SelectionEdge) {\n\t\tswitch (handle) {\n\t\t\tcase 'top_left':\n\t\t\t\treturn new Vec(this.x, this.y)\n\t\t\tcase 'top_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y)\n\t\t\tcase 'bottom_left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h)\n\t\t\tcase 'bottom_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h)\n\t\t\tcase 'top':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y)\n\t\t\tcase 'right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h / 2)\n\t\t\tcase 'bottom':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y + this.h)\n\t\t\tcase 'left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h / 2)\n\t\t}\n\t}\n\n\ttoJson(): BoxModel {\n\t\treturn { x: this.x, y: this.y, w: this.w, h: this.h }\n\t}\n\n\tresize(handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = this\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = this\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tthis.minX = b0x\n\t\tthis.minY = b0y\n\t\tthis.width = Math.abs(b1x - b0x)\n\t\tthis.height = Math.abs(b1y - b0y)\n\t}\n\n\tunion(box: BoxModel) {\n\t\tconst minX = Math.min(this.x, box.x)\n\t\tconst minY = Math.min(this.y, box.y)\n\t\tconst maxX = Math.max(this.x + this.w, box.x + box.w)\n\t\tconst maxY = Math.max(this.y + this.h, box.y + box.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.width = maxX - minX\n\t\tthis.height = maxY - minY\n\n\t\treturn this\n\t}\n\n\tstatic From(box: BoxModel) {\n\t\treturn new Box(box.x, box.y, box.w, box.h)\n\t}\n\n\tstatic FromCenter(center: VecLike, size: VecLike) {\n\t\treturn new Box(center.x - size.x / 2, center.y - size.y / 2, size.x, size.y)\n\t}\n\n\tstatic FromPoints(points: VecLike[]) {\n\t\tif (points.length === 0) return new Box()\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\t\tlet point: VecLike\n\t\tfor (let i = 0, n = points.length; i < n; i++) {\n\t\t\tpoint = points[i]\n\t\t\tminX = Math.min(point.x, minX)\n\t\t\tminY = Math.min(point.y, minY)\n\t\t\tmaxX = Math.max(point.x, maxX)\n\t\t\tmaxY = Math.max(point.y, maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Expand(A: Box, B: Box) {\n\t\tconst minX = Math.min(B.minX, A.minX)\n\t\tconst minY = Math.min(B.minY, A.minY)\n\t\tconst maxX = Math.max(B.maxX, A.maxX)\n\t\tconst maxY = Math.max(B.maxY, A.maxY)\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic ExpandBy(A: Box, n: number) {\n\t\treturn new Box(A.minX - n, A.minY - n, A.width + n * 2, A.height + n * 2)\n\t}\n\n\tstatic Collides(A: Box, B: Box) {\n\t\treturn !(A.maxX < B.minX || A.minX > B.maxX || A.maxY < B.minY || A.minY > B.maxY)\n\t}\n\n\tstatic Contains(A: Box, B: Box) {\n\t\treturn A.minX < B.minX && A.minY < B.minY && A.maxY > B.maxY && A.maxX > B.maxX\n\t}\n\n\tstatic ContainsApproximately(A: Box, B: Box, precision?: number) {\n\t\treturn (\n\t\t\tapproximatelyLte(A.minX, B.minX, precision) &&\n\t\t\tapproximatelyLte(A.minY, B.minY, precision) &&\n\t\t\tapproximatelyLte(B.maxX, A.maxX, precision) &&\n\t\t\tapproximatelyLte(B.maxY, A.maxY, precision)\n\t\t)\n\t}\n\n\tstatic Includes(A: Box, B: Box) {\n\t\treturn Box.Collides(A, B) || Box.Contains(A, B)\n\t}\n\n\tstatic ContainsPoint(A: Box, B: VecLike, margin = 0) {\n\t\treturn !(\n\t\t\tB.x < A.minX - margin ||\n\t\t\tB.y < A.minY - margin ||\n\t\t\tB.x > A.maxX + margin ||\n\t\t\tB.y > A.maxY + margin\n\t\t)\n\t}\n\n\tstatic Common(boxes: Box[]) {\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\n\t\tfor (let i = 0; i < boxes.length; i++) {\n\t\t\tconst B = boxes[i]\n\t\t\tminX = Math.min(minX, B.minX)\n\t\t\tminY = Math.min(minY, B.minY)\n\t\t\tmaxX = Math.max(maxX, B.maxX)\n\t\t\tmaxY = Math.max(maxY, B.maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Sides(A: Box, inset = 0) {\n\t\tconst { corners } = A\n\t\tif (inset) {\n\t\t\t// TODO: Inset the corners by the inset amount.\n\t\t}\n\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\tstatic Resize(\n\t\tbox: Box,\n\t\thandle: SelectionCorner | SelectionEdge | string,\n\t\tdx: number,\n\t\tdy: number,\n\t\tisAspectRatioLocked = false\n\t) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = box\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = box\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\t/*\n 2. Aspect ratio\n If the aspect ratio is locked, adjust the corners so that the\n new box's aspect ratio matches the original aspect ratio.\n */\n\t\tif (isAspectRatioLocked) {\n\t\t\tconst aspectRatio = (a1x - a0x) / (a1y - a0y)\n\t\t\tconst bw = Math.abs(b1x - b0x)\n\t\t\tconst bh = Math.abs(b1y - b0y)\n\t\t\tconst tw = bw * (scaleY < 0 ? 1 : -1) * (1 / aspectRatio)\n\t\t\tconst th = bh * (scaleX < 0 ? 1 : -1) * aspectRatio\n\t\t\tconst isTall = aspectRatio < bw / bh\n\n\t\t\tswitch (handle) {\n\t\t\t\tcase 'top_left': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'top_right': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_left': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom':\n\t\t\t\tcase 'top': {\n\t\t\t\t\tconst m = (b0x + b1x) / 2\n\t\t\t\t\tconst w = bh * aspectRatio\n\t\t\t\t\tb0x = m - w / 2\n\t\t\t\t\tb1x = m + w / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'left':\n\t\t\t\tcase 'right': {\n\t\t\t\t\tconst m = (b0y + b1y) / 2\n\t\t\t\t\tconst h = bw / aspectRatio\n\t\t\t\t\tb0y = m - h / 2\n\t\t\t\t\tb1y = m + h / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tconst final = new Box(b0x, b0y, Math.abs(b1x - b0x), Math.abs(b1y - b0y))\n\n\t\treturn {\n\t\t\tbox: final,\n\t\t\tscaleX: +((final.width / box.width) * (scaleX > 0 ? 1 : -1)).toFixed(5),\n\t\t\tscaleY: +((final.height / box.height) * (scaleY > 0 ? 1 : -1)).toFixed(5),\n\t\t}\n\t}\n\n\tequals(other: Box | BoxModel) {\n\t\treturn Box.Equals(this, other)\n\t}\n\n\tstatic Equals(a: Box | BoxModel, b: Box | BoxModel) {\n\t\treturn b.x === a.x && b.y === a.y && b.w === a.w && b.h === a.h\n\t}\n\n\tzeroFix() {\n\t\tthis.w = Math.max(1, this.w)\n\t\tthis.h = Math.max(1, this.h)\n\t\treturn this\n\t}\n\n\tstatic ZeroFix(other: Box | BoxModel) {\n\t\treturn new Box(other.x, other.y, Math.max(1, other.w), Math.max(1, other.h))\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleY(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'top':\n\t\t\treturn 'bottom'\n\t\tcase 'bottom':\n\t\t\treturn 'top'\n\t\tcase 'top_left':\n\t\t\treturn 'bottom_left'\n\t\tcase 'top_right':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_left':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_right':\n\t\t\treturn 'top_right'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleX(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'left':\n\t\t\treturn 'right'\n\t\tcase 'right':\n\t\t\treturn 'left'\n\t\tcase 'top_left':\n\t\t\treturn 'top_right'\n\t\tcase 'top_right':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_left':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_right':\n\t\t\treturn 'bottom_left'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\nconst ORDERED_SELECTION_HANDLES = [\n\t'top',\n\t'top_right',\n\t'right',\n\t'bottom_right',\n\t'bottom',\n\t'bottom_left',\n\t'left',\n\t'top_left',\n] as const\n\n/** @public */\nexport function rotateSelectionHandle(handle: SelectionHandle, rotation: number): SelectionHandle {\n\t// first find out how many tau we need to rotate by\n\trotation = rotation % PI2\n\tconst numSteps = Math.round(rotation / (PI / 4))\n\n\tconst currentIndex = ORDERED_SELECTION_HANDLES.indexOf(handle)\n\treturn ORDERED_SELECTION_HANDLES[(currentIndex + numSteps) % ORDERED_SELECTION_HANDLES.length]\n}\n\n/** @public */\nexport function isSelectionCorner(selection: string): selection is SelectionCorner {\n\treturn (\n\t\tselection === 'top_left' ||\n\t\tselection === 'top_right' ||\n\t\tselection === 'bottom_right' ||\n\t\tselection === 'bottom_left'\n\t)\n}\n\n/** @public */\nexport const ROTATE_CORNER_TO_SELECTION_CORNER = {\n\ttop_left_rotate: 'top_left',\n\ttop_right_rotate: 'top_right',\n\tbottom_right_rotate: 'bottom_right',\n\tbottom_left_rotate: 'bottom_left',\n\tmobile_rotate: 'top_left',\n} as const\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAA6B;AAC7B,mBAAuD;AAuBhD,MAAM,IAAI;AAAA,EAChB,YAAY,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;AACvC,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI;AAAA,EACV;AAAA,EAEA,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA;AAAA,EAGJ,IAAI,QAAQ;AACX,WAAO,IAAI,eAAI,KAAK,GAAG,KAAK,CAAC;AAAA,EAC9B;AAAA;AAAA,EAGA,IAAI,MAAM,KAAU;AACnB,SAAK,IAAI,IAAI;AACb,SAAK,IAAI,IAAI;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK;AAAA,EACb;AAAA;AAAA,EAGA,IAAI,KAAK,GAAW;AACnB,SAAK,IAAI;AAAA,EACV;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK;AAAA,EACb;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK,IAAI,KAAK,IAAI;AAAA,EAC1B;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK,IAAI,KAAK;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,QAAQ;AACX,WAAO,KAAK,IAAI,KAAK;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK;AAAA,EACb;AAAA;AAAA,E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,qBAAqB,QAAyB;AAC7D,UAAQ,QAAQ;AAAA,IACf,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAEA,MAAM,4BAA4B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAGO,SAAS,sBAAsB,QAAyB,UAAmC;AAEjG,aAAW,WAAW;AACtB,QAAM,WAAW,KAAK,MAAM,YAAY,kBAAK,EAAE;AAE/C,QAAM,eAAe,0BAA0B,QAAQ,MAAM;AAC7D,SAAO,2BAA2B,eAAe,YAAY,0BAA0B,MAAM;AAC9F;AAGO,SAAS,kBAAkB,WAAiD;AAClF,SACC,cAAc,cACd,cAAc,eACd,cAAc,kBACd,cAAc;AAEhB;AAGO,MAAM,oCAAoC;AAAA,EAChD,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,eAAe;AAChB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-cjs/version.js
CHANGED
|
@@ -22,10 +22,10 @@ __export(version_exports, {
|
|
|
22
22
|
version: () => version
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(version_exports);
|
|
25
|
-
const version = "3.16.0-next.
|
|
25
|
+
const version = "3.16.0-next.fe14f1b4181f";
|
|
26
26
|
const publishDates = {
|
|
27
27
|
major: "2024-09-13T14:36:29.063Z",
|
|
28
|
-
minor: "2025-08-
|
|
29
|
-
patch: "2025-08-
|
|
28
|
+
minor: "2025-08-27T11:23:00.744Z",
|
|
29
|
+
patch: "2025-08-27T11:23:00.744Z"
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=version.js.map
|
package/dist-cjs/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-next.
|
|
4
|
+
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-next.fe14f1b4181f'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-08-27T11:23:00.744Z',\n\tpatch: '2025-08-27T11:23:00.744Z',\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-esm/index.d.mts
CHANGED
|
@@ -510,6 +510,7 @@ export declare class Box {
|
|
|
510
510
|
static ExpandBy(A: Box, n: number): Box;
|
|
511
511
|
static Collides(A: Box, B: Box): boolean;
|
|
512
512
|
static Contains(A: Box, B: Box): boolean;
|
|
513
|
+
static ContainsApproximately(A: Box, B: Box, precision?: number): boolean;
|
|
513
514
|
static Includes(A: Box, B: Box): boolean;
|
|
514
515
|
static ContainsPoint(A: Box, B: VecLike, margin?: number): boolean;
|
|
515
516
|
static Common(boxes: Box[]): Box;
|
|
@@ -890,6 +891,8 @@ export declare const defaultTldrawOptions: {
|
|
|
890
891
|
readonly temporaryAssetPreviewLifetimeMs: 180000;
|
|
891
892
|
readonly textShadowLod: 0.35;
|
|
892
893
|
readonly tooltipDelayMs: 700;
|
|
894
|
+
readonly uiCoarseDragDistanceSquared: 625;
|
|
895
|
+
readonly uiDragDistanceSquared: 16;
|
|
893
896
|
};
|
|
894
897
|
|
|
895
898
|
/** @public */
|
|
@@ -3706,6 +3709,20 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3706
3709
|
height: number;
|
|
3707
3710
|
width: number;
|
|
3708
3711
|
}>;
|
|
3712
|
+
/**
|
|
3713
|
+
* Get an exported image of the given shapes as a data URL.
|
|
3714
|
+
*
|
|
3715
|
+
* @param shapes - The shapes (or shape ids) to export.
|
|
3716
|
+
* @param opts - Options for the export.
|
|
3717
|
+
*
|
|
3718
|
+
* @returns A data URL of the image.
|
|
3719
|
+
* @public
|
|
3720
|
+
*/
|
|
3721
|
+
toImageDataUrl(shapes: TLShape[] | TLShapeId[], opts?: TLImageExportOptions): Promise<{
|
|
3722
|
+
height: number;
|
|
3723
|
+
url: string;
|
|
3724
|
+
width: number;
|
|
3725
|
+
}>;
|
|
3709
3726
|
/**
|
|
3710
3727
|
* The app's current input state.
|
|
3711
3728
|
*
|
|
@@ -5263,6 +5280,17 @@ export declare abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknown
|
|
|
5263
5280
|
* @public
|
|
5264
5281
|
*/
|
|
5265
5282
|
isAspectRatioLocked(_shape: Shape): boolean;
|
|
5283
|
+
/**
|
|
5284
|
+
* By default, the bounds of an image export are the bounds of all the shapes it contains, plus
|
|
5285
|
+
* some padding. If an export includes a shape where `isExportBoundsContainer` is true, then the
|
|
5286
|
+
* padding is skipped _if the bounds of that shape contains all the other shapes_. This is
|
|
5287
|
+
* useful in cases like annotating on top of an image, where you usually want to avoid extra
|
|
5288
|
+
* padding around the image if you don't need it.
|
|
5289
|
+
*
|
|
5290
|
+
* @param _shape - The shape to check
|
|
5291
|
+
* @returns True if this shape should be treated as an export bounds container
|
|
5292
|
+
*/
|
|
5293
|
+
isExportBoundsContainer(_shape: Shape): boolean;
|
|
5266
5294
|
/* Excluded from this release type: backgroundComponent */
|
|
5267
5295
|
/**
|
|
5268
5296
|
* Get the interpolated props for an animating shape. This is an optional method.
|
|
@@ -6422,6 +6450,8 @@ export declare interface TldrawOptions {
|
|
|
6422
6450
|
readonly multiClickDurationMs: number;
|
|
6423
6451
|
readonly coarseDragDistanceSquared: number;
|
|
6424
6452
|
readonly dragDistanceSquared: number;
|
|
6453
|
+
readonly uiDragDistanceSquared: number;
|
|
6454
|
+
readonly uiCoarseDragDistanceSquared: number;
|
|
6425
6455
|
readonly defaultSvgPadding: number;
|
|
6426
6456
|
readonly cameraSlideFriction: number;
|
|
6427
6457
|
readonly gridSteps: readonly {
|
package/dist-esm/index.mjs
CHANGED
|
@@ -13,8 +13,8 @@ import React, {
|
|
|
13
13
|
} from "react";
|
|
14
14
|
import classNames from "classnames";
|
|
15
15
|
import { version } from "../version.mjs";
|
|
16
|
-
import { OptionalErrorBoundary } from "./components/ErrorBoundary.mjs";
|
|
17
16
|
import { DefaultErrorFallback } from "./components/default-components/DefaultErrorFallback.mjs";
|
|
17
|
+
import { OptionalErrorBoundary } from "./components/ErrorBoundary.mjs";
|
|
18
18
|
import { createTLUser } from "./config/createTLUser.mjs";
|
|
19
19
|
import { Editor } from "./editor/Editor.mjs";
|
|
20
20
|
import { ContainerProvider, useContainer } from "./hooks/useContainer.mjs";
|
|
@@ -298,8 +298,12 @@ function TldrawEditorWithReadyStore({
|
|
|
298
298
|
if (editor !== fontLoadingState?.editor) {
|
|
299
299
|
fontLoadingState = null;
|
|
300
300
|
}
|
|
301
|
-
|
|
301
|
+
useLayoutEffect(() => {
|
|
302
302
|
if (!editor) return;
|
|
303
|
+
if (editor.options.maxFontsToLoadBeforeRender === 0) {
|
|
304
|
+
setFontLoadingState({ editor, isLoaded: true });
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
303
307
|
let isCancelled = false;
|
|
304
308
|
setFontLoadingState({ editor, isLoaded: false });
|
|
305
309
|
editor.fonts.loadRequiredFontsForCurrentPage(editor.options.maxFontsToLoadBeforeRender).finally(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/TldrawEditor.tsx"],
|
|
4
|
-
"sourcesContent": ["import { MigrationSequence, Store } from '@tldraw/store'\nimport { TLShape, TLStore, TLStoreSnapshot } from '@tldraw/tlschema'\nimport { Required, annotateError } from '@tldraw/utils'\nimport React, {\n\tReactNode,\n\tmemo,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from 'react'\n\nimport classNames from 'classnames'\nimport { version } from '../version'\nimport { OptionalErrorBoundary } from './components/ErrorBoundary'\nimport { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'\nimport { TLEditorSnapshot } from './config/TLEditorSnapshot'\nimport { TLStoreBaseOptions } from './config/createTLStore'\nimport { TLUser, createTLUser } from './config/createTLUser'\nimport { TLAnyBindingUtilConstructor } from './config/defaultBindings'\nimport { TLAnyShapeUtilConstructor } from './config/defaultShapes'\nimport { Editor } from './editor/Editor'\nimport { TLStateNodeConstructor } from './editor/tools/StateNode'\nimport { TLCameraOptions } from './editor/types/misc-types'\nimport { ContainerProvider, useContainer } from './hooks/useContainer'\nimport { useCursor } from './hooks/useCursor'\nimport { useDarkMode } from './hooks/useDarkMode'\nimport { EditorProvider, useEditor } from './hooks/useEditor'\nimport {\n\tEditorComponentsProvider,\n\tTLEditorComponents,\n\tuseEditorComponents,\n} from './hooks/useEditorComponents'\nimport { useEvent } from './hooks/useEvent'\nimport { useForceUpdate } from './hooks/useForceUpdate'\nimport { useShallowObjectIdentity } from './hooks/useIdentity'\nimport { useLocalStore } from './hooks/useLocalStore'\nimport { useRefState } from './hooks/useRefState'\nimport { useStateAttribute } from './hooks/useStateAttribute'\nimport { useZoomCss } from './hooks/useZoomCss'\nimport { LicenseProvider } from './license/LicenseProvider'\nimport { Watermark } from './license/Watermark'\nimport { TldrawOptions } from './options'\nimport { TLDeepLinkOptions } from './utils/deepLinks'\nimport { stopEventPropagation } from './utils/dom'\nimport { TLTextOptions } from './utils/richText'\nimport { TLStoreWithStatus } from './utils/sync/StoreWithStatus'\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when passing in a\n * `TLStore` directly. If you would like tldraw to create a store for you, use\n * {@link TldrawEditorWithoutStoreProps}.\n *\n * @public\n */\nexport interface TldrawEditorWithStoreProps {\n\t/**\n\t * The store to use in the editor.\n\t */\n\tstore: TLStore | TLStoreWithStatus\n}\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when not passing in a\n * `TLStore` directly. If you would like to pass in a store directly, use\n * {@link TldrawEditorWithStoreProps}.\n *\n * @public\n */\nexport interface TldrawEditorWithoutStoreProps extends TLStoreBaseOptions {\n\tstore?: undefined\n\n\t/**\n\t * Additional migrations to use in the store\n\t */\n\tmigrations?: readonly MigrationSequence[]\n\n\t/**\n\t * A starting snapshot of data to pre-populate the store. Do not supply both this and\n\t * `initialData`.\n\t */\n\tsnapshot?: TLEditorSnapshot | TLStoreSnapshot\n\n\t/**\n\t * If you would like to persist the store to the browser's local IndexedDB storage and sync it\n\t * across tabs, provide a key here. Each key represents a single tldraw document.\n\t */\n\tpersistenceKey?: string\n\n\tsessionId?: string\n}\n\n/** @public */\nexport type TldrawEditorStoreProps = TldrawEditorWithStoreProps | TldrawEditorWithoutStoreProps\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.\n *\n * @public\n **/\nexport type TldrawEditorProps = TldrawEditorBaseProps & TldrawEditorStoreProps\n\n/**\n * Base props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.\n *\n * @public\n */\nexport interface TldrawEditorBaseProps {\n\t/**\n\t * The component's children.\n\t */\n\tchildren?: ReactNode\n\n\t/**\n\t * An array of shape utils to use in the editor.\n\t */\n\tshapeUtils?: readonly TLAnyShapeUtilConstructor[]\n\n\t/**\n\t * An array of binding utils to use in the editor.\n\t */\n\tbindingUtils?: readonly TLAnyBindingUtilConstructor[]\n\n\t/**\n\t * An array of tools to add to the editor's state chart.\n\t */\n\ttools?: readonly TLStateNodeConstructor[]\n\n\t/**\n\t * Whether to automatically focus the editor when it mounts.\n\t */\n\tautoFocus?: boolean\n\n\t/**\n\t * Overrides for the editor's components, such as handles, collaborator cursors, etc.\n\t */\n\tcomponents?: TLEditorComponents\n\n\t/**\n\t * Called when the editor has mounted.\n\t */\n\tonMount?: TLOnMountHandler\n\n\t/**\n\t * The editor's initial state (usually the id of the first active tool).\n\t */\n\tinitialState?: string\n\n\t/**\n\t * A classname to pass to the editor's container.\n\t */\n\tclassName?: string\n\n\t/**\n\t * The user interacting with the editor.\n\t */\n\tuser?: TLUser\n\n\t/**\n\t * Whether to infer dark mode from the user's OS. Defaults to false.\n\t */\n\tinferDarkMode?: boolean\n\n\t/**\n\t * Camera options for the editor.\n\t */\n\tcameraOptions?: Partial<TLCameraOptions>\n\n\t/**\n\t * Text options for the editor.\n\t */\n\ttextOptions?: TLTextOptions\n\n\t/**\n\t * Options for the editor.\n\t */\n\toptions?: Partial<TldrawOptions>\n\n\t/**\n\t * The license key.\n\t */\n\tlicenseKey?: string\n\n\t/**\n\t * Options for syncing the editor's camera state with the URL.\n\t */\n\tdeepLinks?: true | TLDeepLinkOptions\n\n\t/**\n\t * Predicate for whether or not a shape should be hidden.\n\t *\n\t * @deprecated Use {@link TldrawEditorBaseProps#getShapeVisibility} instead.\n\t */\n\tisShapeHidden?(shape: TLShape, editor: Editor): boolean\n\n\t/**\n\t * Provides a way to hide shapes.\n\t *\n\t * Hidden shapes will not render in the editor, and they will not be eligible for hit test via\n\t * {@link Editor#getShapeAtPoint} and {@link Editor#getShapesAtPoint}. But otherwise they will\n\t * remain in the store and participate in all other operations.\n\t *\n\t * @example\n\t * ```ts\n\t * getShapeVisibility={(shape, editor) => shape.meta.hidden ? 'hidden' : 'inherit'}\n\t * ```\n\t *\n\t * - `'inherit' | undefined` - (default) The shape will be visible unless its parent is hidden.\n\t * - `'hidden'` - The shape will be hidden.\n\t * - `'visible'` - The shape will be visible.\n\t *\n\t * @param shape - The shape to check.\n\t * @param editor - The editor instance.\n\t */\n\tgetShapeVisibility?(\n\t\tshape: TLShape,\n\t\teditor: Editor\n\t): 'visible' | 'hidden' | 'inherit' | null | undefined\n\n\t/**\n\t * The URLs for the fonts to use in the editor.\n\t */\n\tassetUrls?: { fonts?: { [key: string]: string | undefined } }\n}\n\n/**\n * Called when the editor has mounted.\n * @example\n * ```ts\n * <Tldraw onMount={(editor) => editor.selectAll()} />\n * ```\n * @param editor - The editor instance.\n *\n * @public\n */\nexport type TLOnMountHandler = (editor: Editor) => (() => void | undefined) | undefined | void\n\ndeclare global {\n\tinterface Window {\n\t\ttldrawReady: boolean\n\t}\n}\n\nconst EMPTY_SHAPE_UTILS_ARRAY = [] as const\nconst EMPTY_BINDING_UTILS_ARRAY = [] as const\nconst EMPTY_TOOLS_ARRAY = [] as const\n/** @internal */\nexport const TL_CONTAINER_CLASS = 'tl-container'\n\n/** @public @react */\nexport const TldrawEditor = memo(function TldrawEditor({\n\tstore,\n\tcomponents,\n\tclassName,\n\tuser: _user,\n\toptions: _options,\n\t...rest\n}: TldrawEditorProps) {\n\tconst [container, setContainer] = useState<HTMLElement | null>(null)\n\tconst user = useMemo(() => _user ?? createTLUser(), [_user])\n\n\tconst ErrorFallback =\n\t\tcomponents?.ErrorFallback === undefined ? DefaultErrorFallback : components?.ErrorFallback\n\n\t// apply defaults. if you're using the bare @tldraw/editor package, we\n\t// default these to the \"tldraw zero\" configuration. We have different\n\t// defaults applied in tldraw.\n\tconst withDefaults = {\n\t\t...rest,\n\t\tshapeUtils: rest.shapeUtils ?? EMPTY_SHAPE_UTILS_ARRAY,\n\t\tbindingUtils: rest.bindingUtils ?? EMPTY_BINDING_UTILS_ARRAY,\n\t\ttools: rest.tools ?? EMPTY_TOOLS_ARRAY,\n\t\tcomponents,\n\t\toptions: useShallowObjectIdentity(_options),\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={setContainer}\n\t\t\tdata-tldraw={version}\n\t\t\tdraggable={false}\n\t\t\tclassName={classNames(`${TL_CONTAINER_CLASS} tl-theme__light`, className)}\n\t\t\tonPointerDown={stopEventPropagation}\n\t\t\ttabIndex={-1}\n\t\t\trole=\"application\"\n\t\t\taria-label={_options?.branding ?? 'tldraw'}\n\t\t>\n\t\t\t<OptionalErrorBoundary\n\t\t\t\tfallback={ErrorFallback}\n\t\t\t\tonError={(error) => annotateError(error, { tags: { origin: 'react.tldraw-before-app' } })}\n\t\t\t>\n\t\t\t\t{container && (\n\t\t\t\t\t<LicenseProvider licenseKey={rest.licenseKey}>\n\t\t\t\t\t\t<ContainerProvider container={container}>\n\t\t\t\t\t\t\t<EditorComponentsProvider overrides={components}>\n\t\t\t\t\t\t\t\t{store ? (\n\t\t\t\t\t\t\t\t\tstore instanceof Store ? (\n\t\t\t\t\t\t\t\t\t\t// Store is ready to go, whether externally synced or not\n\t\t\t\t\t\t\t\t\t\t<TldrawEditorWithReadyStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t// Store is a synced store, so handle syncing stages internally\n\t\t\t\t\t\t\t\t\t\t<TldrawEditorWithLoadingStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t// We have no store (it's undefined) so create one and possibly sync it\n\t\t\t\t\t\t\t\t\t<TldrawEditorWithOwnStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</EditorComponentsProvider>\n\t\t\t\t\t\t</ContainerProvider>\n\t\t\t\t\t</LicenseProvider>\n\t\t\t\t)}\n\t\t\t</OptionalErrorBoundary>\n\t\t</div>\n\t)\n})\n\nfunction TldrawEditorWithOwnStore(\n\tprops: Required<\n\t\tTldrawEditorProps & { store: undefined; user: TLUser },\n\t\t'shapeUtils' | 'bindingUtils' | 'tools'\n\t>\n) {\n\tconst {\n\t\tdefaultName,\n\t\tsnapshot,\n\t\tinitialData,\n\t\tshapeUtils,\n\t\tbindingUtils,\n\t\tpersistenceKey,\n\t\tsessionId,\n\t\tuser,\n\t\tassets,\n\t\tmigrations,\n\t} = props\n\n\tconst syncedStore = useLocalStore({\n\t\tshapeUtils,\n\t\tbindingUtils,\n\t\tinitialData,\n\t\tpersistenceKey,\n\t\tsessionId,\n\t\tdefaultName,\n\t\tsnapshot,\n\t\tassets,\n\t\tmigrations,\n\t})\n\n\treturn <TldrawEditorWithLoadingStore {...props} store={syncedStore} user={user} />\n}\n\nconst TldrawEditorWithLoadingStore = memo(function TldrawEditorBeforeLoading({\n\tstore,\n\tuser,\n\t...rest\n}: Required<\n\tTldrawEditorProps & { store: TLStoreWithStatus; user: TLUser },\n\t'shapeUtils' | 'bindingUtils' | 'tools'\n>) {\n\tconst container = useContainer()\n\n\tuseLayoutEffect(() => {\n\t\tif (user.userPreferences.get().colorScheme === 'dark') {\n\t\t\tcontainer.classList.remove('tl-theme__light')\n\t\t\tcontainer.classList.add('tl-theme__dark')\n\t\t}\n\t}, [container, user])\n\n\tconst { LoadingScreen } = useEditorComponents()\n\n\tswitch (store.status) {\n\t\tcase 'error': {\n\t\t\t// for error handling, we fall back to the default error boundary.\n\t\t\t// if users want to handle this error differently, they can render\n\t\t\t// their own error screen before the TldrawEditor component\n\t\t\tthrow store.error\n\t\t}\n\t\tcase 'loading': {\n\t\t\treturn LoadingScreen ? <LoadingScreen /> : null\n\t\t}\n\t\tcase 'not-synced': {\n\t\t\tbreak\n\t\t}\n\t\tcase 'synced-local': {\n\t\t\tbreak\n\t\t}\n\t\tcase 'synced-remote': {\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn <TldrawEditorWithReadyStore {...rest} store={store.store} user={user} />\n})\n\nconst noAutoFocus = () => document.location.search.includes('tldraw_preserve_focus') // || !document.hasFocus() // breaks in nextjs\n\nfunction TldrawEditorWithReadyStore({\n\tonMount,\n\tchildren,\n\tstore,\n\ttools,\n\tshapeUtils,\n\tbindingUtils,\n\tuser,\n\tinitialState,\n\tautoFocus = true,\n\tinferDarkMode,\n\tcameraOptions,\n\ttextOptions,\n\toptions,\n\tlicenseKey,\n\tdeepLinks: _deepLinks,\n\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\tisShapeHidden,\n\tgetShapeVisibility,\n\tassetUrls,\n}: Required<\n\tTldrawEditorProps & {\n\t\tstore: TLStore\n\t\tuser: TLUser\n\t},\n\t'shapeUtils' | 'bindingUtils' | 'tools'\n>) {\n\tconst { ErrorFallback } = useEditorComponents()\n\tconst container = useContainer()\n\n\tconst [editor, setEditor] = useRefState<Editor | null>(null)\n\n\tconst canvasRef = useRef<HTMLDivElement | null>(null)\n\n\tconst deepLinks = useShallowObjectIdentity(_deepLinks === true ? {} : _deepLinks)\n\n\t// props in this ref can be changed without causing the editor to be recreated.\n\tconst editorOptionsRef = useRef({\n\t\t// for these, it's because they're only used when the editor first mounts:\n\t\tautoFocus: autoFocus && !noAutoFocus(),\n\t\tinferDarkMode,\n\t\tinitialState,\n\n\t\t// for these, it's because we keep them up to date in a separate effect:\n\t\tcameraOptions,\n\t\tdeepLinks,\n\t})\n\n\tuseLayoutEffect(() => {\n\t\teditorOptionsRef.current = {\n\t\t\tautoFocus: autoFocus && !noAutoFocus(),\n\t\t\tinferDarkMode,\n\t\t\tinitialState,\n\t\t\tcameraOptions,\n\t\t\tdeepLinks,\n\t\t}\n\t}, [autoFocus, inferDarkMode, initialState, cameraOptions, deepLinks])\n\n\tuseLayoutEffect(\n\t\t() => {\n\t\t\tconst { autoFocus, inferDarkMode, initialState, cameraOptions, deepLinks } =\n\t\t\t\teditorOptionsRef.current\n\t\t\tconst editor = new Editor({\n\t\t\t\tstore,\n\t\t\t\tshapeUtils,\n\t\t\t\tbindingUtils,\n\t\t\t\ttools,\n\t\t\t\tgetContainer: () => container,\n\t\t\t\tuser,\n\t\t\t\tinitialState,\n\t\t\t\t// we should check for some kind of query parameter that turns off autofocus\n\t\t\t\tautoFocus,\n\t\t\t\tinferDarkMode,\n\t\t\t\tcameraOptions,\n\t\t\t\ttextOptions,\n\t\t\t\toptions,\n\t\t\t\tlicenseKey,\n\t\t\t\tisShapeHidden,\n\t\t\t\tgetShapeVisibility,\n\t\t\t\tfontAssetUrls: assetUrls?.fonts,\n\t\t\t})\n\n\t\t\teditor.updateViewportScreenBounds(canvasRef.current ?? container)\n\n\t\t\t// Use the ref here because we only want to do this once when the editor is created.\n\t\t\t// We don't want changes to the urlStateSync prop to trigger creating new editors.\n\t\t\tif (deepLinks) {\n\t\t\t\tif (!deepLinks?.getUrl) {\n\t\t\t\t\t// load the state from window.location\n\t\t\t\t\teditor.navigateToDeepLink(deepLinks)\n\t\t\t\t} else {\n\t\t\t\t\t// load the state from the provided URL\n\t\t\t\t\teditor.navigateToDeepLink({ ...deepLinks, url: deepLinks.getUrl(editor) })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsetEditor(editor)\n\n\t\t\treturn () => {\n\t\t\t\teditor.dispose()\n\t\t\t}\n\t\t},\n\t\t// if any of these change, we need to recreate the editor.\n\t\t[\n\t\t\tbindingUtils,\n\t\t\tcontainer,\n\t\t\toptions,\n\t\t\tshapeUtils,\n\t\t\tstore,\n\t\t\ttools,\n\t\t\tuser,\n\t\t\tsetEditor,\n\t\t\tlicenseKey,\n\t\t\tisShapeHidden,\n\t\t\tgetShapeVisibility,\n\t\t\ttextOptions,\n\t\t\tassetUrls,\n\t\t]\n\t)\n\n\tuseLayoutEffect(() => {\n\t\tif (!editor) return\n\t\tif (deepLinks) {\n\t\t\treturn editor.registerDeepLinkListener(deepLinks)\n\t\t}\n\t}, [editor, deepLinks])\n\n\t// keep the editor up to date with the latest camera options\n\tuseLayoutEffect(() => {\n\t\tif (editor && cameraOptions) {\n\t\t\teditor.setCameraOptions(cameraOptions)\n\t\t}\n\t}, [editor, cameraOptions])\n\n\tconst crashingError = useSyncExternalStore(\n\t\tuseCallback(\n\t\t\t(onStoreChange) => {\n\t\t\t\tif (editor) {\n\t\t\t\t\teditor.on('crash', onStoreChange)\n\t\t\t\t\treturn () => editor.off('crash', onStoreChange)\n\t\t\t\t}\n\t\t\t\treturn () => {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t},\n\t\t\t[editor]\n\t\t),\n\t\t() => editor?.getCrashingError() ?? null\n\t)\n\n\t// For our examples site, we want autoFocus to be true on the examples site, but not\n\t// when embedded in our docs site. If present, the `tldraw_preserve_focus` search param\n\t// overrides the `autoFocus` prop and prevents the editor from focusing immediately,\n\t// however here we also add some logic to focus the editor when the user clicks\n\t// on it and unfocus it when the user clicks away from it.\n\tuseEffect(\n\t\tfunction handleFocusOnPointerDownForPreserveFocusMode() {\n\t\t\tif (!editor) return\n\n\t\t\tfunction handleFocusOnPointerDown() {\n\t\t\t\tif (!editor) return\n\t\t\t\teditor.focus()\n\t\t\t}\n\n\t\t\tfunction handleBlurOnPointerDown() {\n\t\t\t\tif (!editor) return\n\t\t\t\teditor.blur()\n\t\t\t}\n\n\t\t\tif (autoFocus && noAutoFocus()) {\n\t\t\t\teditor.getContainer().addEventListener('pointerdown', handleFocusOnPointerDown)\n\t\t\t\tdocument.body.addEventListener('pointerdown', handleBlurOnPointerDown)\n\n\t\t\t\treturn () => {\n\t\t\t\t\teditor.getContainer()?.removeEventListener('pointerdown', handleFocusOnPointerDown)\n\t\t\t\t\tdocument.body.removeEventListener('pointerdown', handleBlurOnPointerDown)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor, autoFocus]\n\t)\n\n\tconst [_fontLoadingState, setFontLoadingState] = useState<{\n\t\teditor: Editor\n\t\tisLoaded: boolean\n\t} | null>(null)\n\tlet fontLoadingState = _fontLoadingState\n\tif (editor !== fontLoadingState?.editor) {\n\t\tfontLoadingState = null\n\t}\n\tuseEffect(() => {\n\t\tif (!editor) return\n\t\tlet isCancelled = false\n\n\t\tsetFontLoadingState({ editor, isLoaded: false })\n\n\t\teditor.fonts\n\t\t\t.loadRequiredFontsForCurrentPage(editor.options.maxFontsToLoadBeforeRender)\n\t\t\t.finally(() => {\n\t\t\t\tif (isCancelled) return\n\t\t\t\tsetFontLoadingState({ editor, isLoaded: true })\n\t\t\t})\n\n\t\treturn () => {\n\t\t\tisCancelled = true\n\t\t}\n\t}, [editor])\n\n\tconst { Canvas, LoadingScreen } = useEditorComponents()\n\n\tif (!editor || !fontLoadingState?.isLoaded) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{LoadingScreen && <LoadingScreen />}\n\t\t\t\t<div className=\"tl-canvas\" ref={canvasRef} />\n\t\t\t</>\n\t\t)\n\t}\n\n\treturn (\n\t\t// the top-level tldraw component also renders an error boundary almost\n\t\t// identical to this one. the reason we have two is because this one has\n\t\t// access to `App`, which means that here we can enrich errors with data\n\t\t// from app for reporting, and also still attempt to render the user's\n\t\t// document in the event of an error to reassure them that their work is\n\t\t// not lost.\n\t\t<OptionalErrorBoundary\n\t\t\tfallback={ErrorFallback as any}\n\t\t\tonError={(error) =>\n\t\t\t\teditor.annotateError(error, { origin: 'react.tldraw', willCrashApp: true })\n\t\t\t}\n\t\t>\n\t\t\t{crashingError ? (\n\t\t\t\t<Crash crashingError={crashingError} />\n\t\t\t) : (\n\t\t\t\t<EditorProvider editor={editor}>\n\t\t\t\t\t<Layout onMount={onMount}>\n\t\t\t\t\t\t{children ?? (Canvas ? <Canvas key={editor.contextId} /> : null)}\n\t\t\t\t\t\t<Watermark />\n\t\t\t\t\t</Layout>\n\t\t\t\t</EditorProvider>\n\t\t\t)}\n\t\t</OptionalErrorBoundary>\n\t)\n}\n\nfunction Layout({ children, onMount }: { children: ReactNode; onMount?: TLOnMountHandler }) {\n\tuseZoomCss()\n\tuseCursor()\n\tuseDarkMode()\n\tuseForceUpdate()\n\tuseStateAttribute()\n\tuseOnMount((editor) => {\n\t\tconst teardownStore = editor.store.props.onMount(editor)\n\t\tconst teardownCallback = onMount?.(editor)\n\n\t\treturn () => {\n\t\t\tteardownStore?.()\n\t\t\tteardownCallback?.()\n\t\t}\n\t})\n\n\treturn children\n}\n\nfunction Crash({ crashingError }: { crashingError: unknown }): null {\n\tthrow crashingError\n}\n\n/** @public */\nexport interface LoadingScreenProps {\n\tchildren: ReactNode\n}\n\n/** @public @react */\nexport function LoadingScreen({ children }: LoadingScreenProps) {\n\treturn (\n\t\t<div className=\"tl-loading\" aria-busy=\"true\" tabIndex={0}>\n\t\t\t{children}\n\t\t</div>\n\t)\n}\n\n/** @public @react */\nexport function ErrorScreen({ children }: LoadingScreenProps) {\n\treturn <div className=\"tl-loading\">{children}</div>\n}\n\n/** @internal */\nexport function useOnMount(onMount?: TLOnMountHandler) {\n\tconst editor = useEditor()\n\n\tconst onMountEvent = useEvent((editor: Editor) => {\n\t\tlet teardown: (() => void) | void = undefined\n\t\t// If the user wants to do something when the editor mounts, we make sure it doesn't effect the history.\n\t\t// todo: is this reeeeally what we want to do, or should we leave it up to the caller?\n\t\teditor.run(\n\t\t\t() => {\n\t\t\t\tteardown = onMount?.(editor)\n\t\t\t\teditor.emit('mount')\n\t\t\t},\n\t\t\t{ history: 'ignore' }\n\t\t)\n\t\twindow.tldrawReady = true\n\t\treturn teardown\n\t})\n\n\tReact.useLayoutEffect(() => {\n\t\tif (editor) return onMountEvent?.(editor)\n\t}, [editor, onMountEvent])\n}\n"],
|
|
5
|
-
"mappings": "AA6SU,
|
|
4
|
+
"sourcesContent": ["import { MigrationSequence, Store } from '@tldraw/store'\nimport { TLShape, TLStore, TLStoreSnapshot } from '@tldraw/tlschema'\nimport { annotateError, Required } from '@tldraw/utils'\nimport React, {\n\tmemo,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from 'react'\n\nimport classNames from 'classnames'\nimport { version } from '../version'\nimport { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'\nimport { OptionalErrorBoundary } from './components/ErrorBoundary'\nimport { TLStoreBaseOptions } from './config/createTLStore'\nimport { createTLUser, TLUser } from './config/createTLUser'\nimport { TLAnyBindingUtilConstructor } from './config/defaultBindings'\nimport { TLAnyShapeUtilConstructor } from './config/defaultShapes'\nimport { TLEditorSnapshot } from './config/TLEditorSnapshot'\nimport { Editor } from './editor/Editor'\nimport { TLStateNodeConstructor } from './editor/tools/StateNode'\nimport { TLCameraOptions } from './editor/types/misc-types'\nimport { ContainerProvider, useContainer } from './hooks/useContainer'\nimport { useCursor } from './hooks/useCursor'\nimport { useDarkMode } from './hooks/useDarkMode'\nimport { EditorProvider, useEditor } from './hooks/useEditor'\nimport {\n\tEditorComponentsProvider,\n\tTLEditorComponents,\n\tuseEditorComponents,\n} from './hooks/useEditorComponents'\nimport { useEvent } from './hooks/useEvent'\nimport { useForceUpdate } from './hooks/useForceUpdate'\nimport { useShallowObjectIdentity } from './hooks/useIdentity'\nimport { useLocalStore } from './hooks/useLocalStore'\nimport { useRefState } from './hooks/useRefState'\nimport { useStateAttribute } from './hooks/useStateAttribute'\nimport { useZoomCss } from './hooks/useZoomCss'\nimport { LicenseProvider } from './license/LicenseProvider'\nimport { Watermark } from './license/Watermark'\nimport { TldrawOptions } from './options'\nimport { TLDeepLinkOptions } from './utils/deepLinks'\nimport { stopEventPropagation } from './utils/dom'\nimport { TLTextOptions } from './utils/richText'\nimport { TLStoreWithStatus } from './utils/sync/StoreWithStatus'\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when passing in a\n * `TLStore` directly. If you would like tldraw to create a store for you, use\n * {@link TldrawEditorWithoutStoreProps}.\n *\n * @public\n */\nexport interface TldrawEditorWithStoreProps {\n\t/**\n\t * The store to use in the editor.\n\t */\n\tstore: TLStore | TLStoreWithStatus\n}\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when not passing in a\n * `TLStore` directly. If you would like to pass in a store directly, use\n * {@link TldrawEditorWithStoreProps}.\n *\n * @public\n */\nexport interface TldrawEditorWithoutStoreProps extends TLStoreBaseOptions {\n\tstore?: undefined\n\n\t/**\n\t * Additional migrations to use in the store\n\t */\n\tmigrations?: readonly MigrationSequence[]\n\n\t/**\n\t * A starting snapshot of data to pre-populate the store. Do not supply both this and\n\t * `initialData`.\n\t */\n\tsnapshot?: TLEditorSnapshot | TLStoreSnapshot\n\n\t/**\n\t * If you would like to persist the store to the browser's local IndexedDB storage and sync it\n\t * across tabs, provide a key here. Each key represents a single tldraw document.\n\t */\n\tpersistenceKey?: string\n\n\tsessionId?: string\n}\n\n/** @public */\nexport type TldrawEditorStoreProps = TldrawEditorWithStoreProps | TldrawEditorWithoutStoreProps\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.\n *\n * @public\n **/\nexport type TldrawEditorProps = TldrawEditorBaseProps & TldrawEditorStoreProps\n\n/**\n * Base props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.\n *\n * @public\n */\nexport interface TldrawEditorBaseProps {\n\t/**\n\t * The component's children.\n\t */\n\tchildren?: ReactNode\n\n\t/**\n\t * An array of shape utils to use in the editor.\n\t */\n\tshapeUtils?: readonly TLAnyShapeUtilConstructor[]\n\n\t/**\n\t * An array of binding utils to use in the editor.\n\t */\n\tbindingUtils?: readonly TLAnyBindingUtilConstructor[]\n\n\t/**\n\t * An array of tools to add to the editor's state chart.\n\t */\n\ttools?: readonly TLStateNodeConstructor[]\n\n\t/**\n\t * Whether to automatically focus the editor when it mounts.\n\t */\n\tautoFocus?: boolean\n\n\t/**\n\t * Overrides for the editor's components, such as handles, collaborator cursors, etc.\n\t */\n\tcomponents?: TLEditorComponents\n\n\t/**\n\t * Called when the editor has mounted.\n\t */\n\tonMount?: TLOnMountHandler\n\n\t/**\n\t * The editor's initial state (usually the id of the first active tool).\n\t */\n\tinitialState?: string\n\n\t/**\n\t * A classname to pass to the editor's container.\n\t */\n\tclassName?: string\n\n\t/**\n\t * The user interacting with the editor.\n\t */\n\tuser?: TLUser\n\n\t/**\n\t * Whether to infer dark mode from the user's OS. Defaults to false.\n\t */\n\tinferDarkMode?: boolean\n\n\t/**\n\t * Camera options for the editor.\n\t */\n\tcameraOptions?: Partial<TLCameraOptions>\n\n\t/**\n\t * Text options for the editor.\n\t */\n\ttextOptions?: TLTextOptions\n\n\t/**\n\t * Options for the editor.\n\t */\n\toptions?: Partial<TldrawOptions>\n\n\t/**\n\t * The license key.\n\t */\n\tlicenseKey?: string\n\n\t/**\n\t * Options for syncing the editor's camera state with the URL.\n\t */\n\tdeepLinks?: true | TLDeepLinkOptions\n\n\t/**\n\t * Predicate for whether or not a shape should be hidden.\n\t *\n\t * @deprecated Use {@link TldrawEditorBaseProps#getShapeVisibility} instead.\n\t */\n\tisShapeHidden?(shape: TLShape, editor: Editor): boolean\n\n\t/**\n\t * Provides a way to hide shapes.\n\t *\n\t * Hidden shapes will not render in the editor, and they will not be eligible for hit test via\n\t * {@link Editor#getShapeAtPoint} and {@link Editor#getShapesAtPoint}. But otherwise they will\n\t * remain in the store and participate in all other operations.\n\t *\n\t * @example\n\t * ```ts\n\t * getShapeVisibility={(shape, editor) => shape.meta.hidden ? 'hidden' : 'inherit'}\n\t * ```\n\t *\n\t * - `'inherit' | undefined` - (default) The shape will be visible unless its parent is hidden.\n\t * - `'hidden'` - The shape will be hidden.\n\t * - `'visible'` - The shape will be visible.\n\t *\n\t * @param shape - The shape to check.\n\t * @param editor - The editor instance.\n\t */\n\tgetShapeVisibility?(\n\t\tshape: TLShape,\n\t\teditor: Editor\n\t): 'visible' | 'hidden' | 'inherit' | null | undefined\n\n\t/**\n\t * The URLs for the fonts to use in the editor.\n\t */\n\tassetUrls?: { fonts?: { [key: string]: string | undefined } }\n}\n\n/**\n * Called when the editor has mounted.\n * @example\n * ```ts\n * <Tldraw onMount={(editor) => editor.selectAll()} />\n * ```\n * @param editor - The editor instance.\n *\n * @public\n */\nexport type TLOnMountHandler = (editor: Editor) => (() => void | undefined) | undefined | void\n\ndeclare global {\n\tinterface Window {\n\t\ttldrawReady: boolean\n\t}\n}\n\nconst EMPTY_SHAPE_UTILS_ARRAY = [] as const\nconst EMPTY_BINDING_UTILS_ARRAY = [] as const\nconst EMPTY_TOOLS_ARRAY = [] as const\n/** @internal */\nexport const TL_CONTAINER_CLASS = 'tl-container'\n\n/** @public @react */\nexport const TldrawEditor = memo(function TldrawEditor({\n\tstore,\n\tcomponents,\n\tclassName,\n\tuser: _user,\n\toptions: _options,\n\t...rest\n}: TldrawEditorProps) {\n\tconst [container, setContainer] = useState<HTMLElement | null>(null)\n\tconst user = useMemo(() => _user ?? createTLUser(), [_user])\n\n\tconst ErrorFallback =\n\t\tcomponents?.ErrorFallback === undefined ? DefaultErrorFallback : components?.ErrorFallback\n\n\t// apply defaults. if you're using the bare @tldraw/editor package, we\n\t// default these to the \"tldraw zero\" configuration. We have different\n\t// defaults applied in tldraw.\n\tconst withDefaults = {\n\t\t...rest,\n\t\tshapeUtils: rest.shapeUtils ?? EMPTY_SHAPE_UTILS_ARRAY,\n\t\tbindingUtils: rest.bindingUtils ?? EMPTY_BINDING_UTILS_ARRAY,\n\t\ttools: rest.tools ?? EMPTY_TOOLS_ARRAY,\n\t\tcomponents,\n\t\toptions: useShallowObjectIdentity(_options),\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={setContainer}\n\t\t\tdata-tldraw={version}\n\t\t\tdraggable={false}\n\t\t\tclassName={classNames(`${TL_CONTAINER_CLASS} tl-theme__light`, className)}\n\t\t\tonPointerDown={stopEventPropagation}\n\t\t\ttabIndex={-1}\n\t\t\trole=\"application\"\n\t\t\taria-label={_options?.branding ?? 'tldraw'}\n\t\t>\n\t\t\t<OptionalErrorBoundary\n\t\t\t\tfallback={ErrorFallback}\n\t\t\t\tonError={(error) => annotateError(error, { tags: { origin: 'react.tldraw-before-app' } })}\n\t\t\t>\n\t\t\t\t{container && (\n\t\t\t\t\t<LicenseProvider licenseKey={rest.licenseKey}>\n\t\t\t\t\t\t<ContainerProvider container={container}>\n\t\t\t\t\t\t\t<EditorComponentsProvider overrides={components}>\n\t\t\t\t\t\t\t\t{store ? (\n\t\t\t\t\t\t\t\t\tstore instanceof Store ? (\n\t\t\t\t\t\t\t\t\t\t// Store is ready to go, whether externally synced or not\n\t\t\t\t\t\t\t\t\t\t<TldrawEditorWithReadyStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t// Store is a synced store, so handle syncing stages internally\n\t\t\t\t\t\t\t\t\t\t<TldrawEditorWithLoadingStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t// We have no store (it's undefined) so create one and possibly sync it\n\t\t\t\t\t\t\t\t\t<TldrawEditorWithOwnStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</EditorComponentsProvider>\n\t\t\t\t\t\t</ContainerProvider>\n\t\t\t\t\t</LicenseProvider>\n\t\t\t\t)}\n\t\t\t</OptionalErrorBoundary>\n\t\t</div>\n\t)\n})\n\nfunction TldrawEditorWithOwnStore(\n\tprops: Required<\n\t\tTldrawEditorProps & { store: undefined; user: TLUser },\n\t\t'shapeUtils' | 'bindingUtils' | 'tools'\n\t>\n) {\n\tconst {\n\t\tdefaultName,\n\t\tsnapshot,\n\t\tinitialData,\n\t\tshapeUtils,\n\t\tbindingUtils,\n\t\tpersistenceKey,\n\t\tsessionId,\n\t\tuser,\n\t\tassets,\n\t\tmigrations,\n\t} = props\n\n\tconst syncedStore = useLocalStore({\n\t\tshapeUtils,\n\t\tbindingUtils,\n\t\tinitialData,\n\t\tpersistenceKey,\n\t\tsessionId,\n\t\tdefaultName,\n\t\tsnapshot,\n\t\tassets,\n\t\tmigrations,\n\t})\n\n\treturn <TldrawEditorWithLoadingStore {...props} store={syncedStore} user={user} />\n}\n\nconst TldrawEditorWithLoadingStore = memo(function TldrawEditorBeforeLoading({\n\tstore,\n\tuser,\n\t...rest\n}: Required<\n\tTldrawEditorProps & { store: TLStoreWithStatus; user: TLUser },\n\t'shapeUtils' | 'bindingUtils' | 'tools'\n>) {\n\tconst container = useContainer()\n\n\tuseLayoutEffect(() => {\n\t\tif (user.userPreferences.get().colorScheme === 'dark') {\n\t\t\tcontainer.classList.remove('tl-theme__light')\n\t\t\tcontainer.classList.add('tl-theme__dark')\n\t\t}\n\t}, [container, user])\n\n\tconst { LoadingScreen } = useEditorComponents()\n\n\tswitch (store.status) {\n\t\tcase 'error': {\n\t\t\t// for error handling, we fall back to the default error boundary.\n\t\t\t// if users want to handle this error differently, they can render\n\t\t\t// their own error screen before the TldrawEditor component\n\t\t\tthrow store.error\n\t\t}\n\t\tcase 'loading': {\n\t\t\treturn LoadingScreen ? <LoadingScreen /> : null\n\t\t}\n\t\tcase 'not-synced': {\n\t\t\tbreak\n\t\t}\n\t\tcase 'synced-local': {\n\t\t\tbreak\n\t\t}\n\t\tcase 'synced-remote': {\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn <TldrawEditorWithReadyStore {...rest} store={store.store} user={user} />\n})\n\nconst noAutoFocus = () => document.location.search.includes('tldraw_preserve_focus') // || !document.hasFocus() // breaks in nextjs\n\nfunction TldrawEditorWithReadyStore({\n\tonMount,\n\tchildren,\n\tstore,\n\ttools,\n\tshapeUtils,\n\tbindingUtils,\n\tuser,\n\tinitialState,\n\tautoFocus = true,\n\tinferDarkMode,\n\tcameraOptions,\n\ttextOptions,\n\toptions,\n\tlicenseKey,\n\tdeepLinks: _deepLinks,\n\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\tisShapeHidden,\n\tgetShapeVisibility,\n\tassetUrls,\n}: Required<\n\tTldrawEditorProps & {\n\t\tstore: TLStore\n\t\tuser: TLUser\n\t},\n\t'shapeUtils' | 'bindingUtils' | 'tools'\n>) {\n\tconst { ErrorFallback } = useEditorComponents()\n\tconst container = useContainer()\n\n\tconst [editor, setEditor] = useRefState<Editor | null>(null)\n\n\tconst canvasRef = useRef<HTMLDivElement | null>(null)\n\n\tconst deepLinks = useShallowObjectIdentity(_deepLinks === true ? {} : _deepLinks)\n\n\t// props in this ref can be changed without causing the editor to be recreated.\n\tconst editorOptionsRef = useRef({\n\t\t// for these, it's because they're only used when the editor first mounts:\n\t\tautoFocus: autoFocus && !noAutoFocus(),\n\t\tinferDarkMode,\n\t\tinitialState,\n\n\t\t// for these, it's because we keep them up to date in a separate effect:\n\t\tcameraOptions,\n\t\tdeepLinks,\n\t})\n\n\tuseLayoutEffect(() => {\n\t\teditorOptionsRef.current = {\n\t\t\tautoFocus: autoFocus && !noAutoFocus(),\n\t\t\tinferDarkMode,\n\t\t\tinitialState,\n\t\t\tcameraOptions,\n\t\t\tdeepLinks,\n\t\t}\n\t}, [autoFocus, inferDarkMode, initialState, cameraOptions, deepLinks])\n\n\tuseLayoutEffect(\n\t\t() => {\n\t\t\tconst { autoFocus, inferDarkMode, initialState, cameraOptions, deepLinks } =\n\t\t\t\teditorOptionsRef.current\n\t\t\tconst editor = new Editor({\n\t\t\t\tstore,\n\t\t\t\tshapeUtils,\n\t\t\t\tbindingUtils,\n\t\t\t\ttools,\n\t\t\t\tgetContainer: () => container,\n\t\t\t\tuser,\n\t\t\t\tinitialState,\n\t\t\t\t// we should check for some kind of query parameter that turns off autofocus\n\t\t\t\tautoFocus,\n\t\t\t\tinferDarkMode,\n\t\t\t\tcameraOptions,\n\t\t\t\ttextOptions,\n\t\t\t\toptions,\n\t\t\t\tlicenseKey,\n\t\t\t\tisShapeHidden,\n\t\t\t\tgetShapeVisibility,\n\t\t\t\tfontAssetUrls: assetUrls?.fonts,\n\t\t\t})\n\n\t\t\teditor.updateViewportScreenBounds(canvasRef.current ?? container)\n\n\t\t\t// Use the ref here because we only want to do this once when the editor is created.\n\t\t\t// We don't want changes to the urlStateSync prop to trigger creating new editors.\n\t\t\tif (deepLinks) {\n\t\t\t\tif (!deepLinks?.getUrl) {\n\t\t\t\t\t// load the state from window.location\n\t\t\t\t\teditor.navigateToDeepLink(deepLinks)\n\t\t\t\t} else {\n\t\t\t\t\t// load the state from the provided URL\n\t\t\t\t\teditor.navigateToDeepLink({ ...deepLinks, url: deepLinks.getUrl(editor) })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsetEditor(editor)\n\n\t\t\treturn () => {\n\t\t\t\teditor.dispose()\n\t\t\t}\n\t\t},\n\t\t// if any of these change, we need to recreate the editor.\n\t\t[\n\t\t\tbindingUtils,\n\t\t\tcontainer,\n\t\t\toptions,\n\t\t\tshapeUtils,\n\t\t\tstore,\n\t\t\ttools,\n\t\t\tuser,\n\t\t\tsetEditor,\n\t\t\tlicenseKey,\n\t\t\tisShapeHidden,\n\t\t\tgetShapeVisibility,\n\t\t\ttextOptions,\n\t\t\tassetUrls,\n\t\t]\n\t)\n\n\tuseLayoutEffect(() => {\n\t\tif (!editor) return\n\t\tif (deepLinks) {\n\t\t\treturn editor.registerDeepLinkListener(deepLinks)\n\t\t}\n\t}, [editor, deepLinks])\n\n\t// keep the editor up to date with the latest camera options\n\tuseLayoutEffect(() => {\n\t\tif (editor && cameraOptions) {\n\t\t\teditor.setCameraOptions(cameraOptions)\n\t\t}\n\t}, [editor, cameraOptions])\n\n\tconst crashingError = useSyncExternalStore(\n\t\tuseCallback(\n\t\t\t(onStoreChange) => {\n\t\t\t\tif (editor) {\n\t\t\t\t\teditor.on('crash', onStoreChange)\n\t\t\t\t\treturn () => editor.off('crash', onStoreChange)\n\t\t\t\t}\n\t\t\t\treturn () => {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t},\n\t\t\t[editor]\n\t\t),\n\t\t() => editor?.getCrashingError() ?? null\n\t)\n\n\t// For our examples site, we want autoFocus to be true on the examples site, but not\n\t// when embedded in our docs site. If present, the `tldraw_preserve_focus` search param\n\t// overrides the `autoFocus` prop and prevents the editor from focusing immediately,\n\t// however here we also add some logic to focus the editor when the user clicks\n\t// on it and unfocus it when the user clicks away from it.\n\tuseEffect(\n\t\tfunction handleFocusOnPointerDownForPreserveFocusMode() {\n\t\t\tif (!editor) return\n\n\t\t\tfunction handleFocusOnPointerDown() {\n\t\t\t\tif (!editor) return\n\t\t\t\teditor.focus()\n\t\t\t}\n\n\t\t\tfunction handleBlurOnPointerDown() {\n\t\t\t\tif (!editor) return\n\t\t\t\teditor.blur()\n\t\t\t}\n\n\t\t\tif (autoFocus && noAutoFocus()) {\n\t\t\t\teditor.getContainer().addEventListener('pointerdown', handleFocusOnPointerDown)\n\t\t\t\tdocument.body.addEventListener('pointerdown', handleBlurOnPointerDown)\n\n\t\t\t\treturn () => {\n\t\t\t\t\teditor.getContainer()?.removeEventListener('pointerdown', handleFocusOnPointerDown)\n\t\t\t\t\tdocument.body.removeEventListener('pointerdown', handleBlurOnPointerDown)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor, autoFocus]\n\t)\n\n\tconst [_fontLoadingState, setFontLoadingState] = useState<{\n\t\teditor: Editor\n\t\tisLoaded: boolean\n\t} | null>(null)\n\tlet fontLoadingState = _fontLoadingState\n\tif (editor !== fontLoadingState?.editor) {\n\t\tfontLoadingState = null\n\t}\n\tuseLayoutEffect(() => {\n\t\tif (!editor) return\n\t\tif (editor.options.maxFontsToLoadBeforeRender === 0) {\n\t\t\tsetFontLoadingState({ editor, isLoaded: true })\n\t\t\treturn\n\t\t}\n\n\t\tlet isCancelled = false\n\n\t\tsetFontLoadingState({ editor, isLoaded: false })\n\n\t\teditor.fonts\n\t\t\t.loadRequiredFontsForCurrentPage(editor.options.maxFontsToLoadBeforeRender)\n\t\t\t.finally(() => {\n\t\t\t\tif (isCancelled) return\n\t\t\t\tsetFontLoadingState({ editor, isLoaded: true })\n\t\t\t})\n\n\t\treturn () => {\n\t\t\tisCancelled = true\n\t\t}\n\t}, [editor])\n\n\tconst { Canvas, LoadingScreen } = useEditorComponents()\n\n\tif (!editor || !fontLoadingState?.isLoaded) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{LoadingScreen && <LoadingScreen />}\n\t\t\t\t<div className=\"tl-canvas\" ref={canvasRef} />\n\t\t\t</>\n\t\t)\n\t}\n\n\treturn (\n\t\t// the top-level tldraw component also renders an error boundary almost\n\t\t// identical to this one. the reason we have two is because this one has\n\t\t// access to `App`, which means that here we can enrich errors with data\n\t\t// from app for reporting, and also still attempt to render the user's\n\t\t// document in the event of an error to reassure them that their work is\n\t\t// not lost.\n\t\t<OptionalErrorBoundary\n\t\t\tfallback={ErrorFallback as any}\n\t\t\tonError={(error) =>\n\t\t\t\teditor.annotateError(error, { origin: 'react.tldraw', willCrashApp: true })\n\t\t\t}\n\t\t>\n\t\t\t{crashingError ? (\n\t\t\t\t<Crash crashingError={crashingError} />\n\t\t\t) : (\n\t\t\t\t<EditorProvider editor={editor}>\n\t\t\t\t\t<Layout onMount={onMount}>\n\t\t\t\t\t\t{children ?? (Canvas ? <Canvas key={editor.contextId} /> : null)}\n\t\t\t\t\t\t<Watermark />\n\t\t\t\t\t</Layout>\n\t\t\t\t</EditorProvider>\n\t\t\t)}\n\t\t</OptionalErrorBoundary>\n\t)\n}\n\nfunction Layout({ children, onMount }: { children: ReactNode; onMount?: TLOnMountHandler }) {\n\tuseZoomCss()\n\tuseCursor()\n\tuseDarkMode()\n\tuseForceUpdate()\n\tuseStateAttribute()\n\tuseOnMount((editor) => {\n\t\tconst teardownStore = editor.store.props.onMount(editor)\n\t\tconst teardownCallback = onMount?.(editor)\n\n\t\treturn () => {\n\t\t\tteardownStore?.()\n\t\t\tteardownCallback?.()\n\t\t}\n\t})\n\n\treturn children\n}\n\nfunction Crash({ crashingError }: { crashingError: unknown }): null {\n\tthrow crashingError\n}\n\n/** @public */\nexport interface LoadingScreenProps {\n\tchildren: ReactNode\n}\n\n/** @public @react */\nexport function LoadingScreen({ children }: LoadingScreenProps) {\n\treturn (\n\t\t<div className=\"tl-loading\" aria-busy=\"true\" tabIndex={0}>\n\t\t\t{children}\n\t\t</div>\n\t)\n}\n\n/** @public @react */\nexport function ErrorScreen({ children }: LoadingScreenProps) {\n\treturn <div className=\"tl-loading\">{children}</div>\n}\n\n/** @internal */\nexport function useOnMount(onMount?: TLOnMountHandler) {\n\tconst editor = useEditor()\n\n\tconst onMountEvent = useEvent((editor: Editor) => {\n\t\tlet teardown: (() => void) | void = undefined\n\t\t// If the user wants to do something when the editor mounts, we make sure it doesn't effect the history.\n\t\t// todo: is this reeeeally what we want to do, or should we leave it up to the caller?\n\t\teditor.run(\n\t\t\t() => {\n\t\t\t\tteardown = onMount?.(editor)\n\t\t\t\teditor.emit('mount')\n\t\t\t},\n\t\t\t{ history: 'ignore' }\n\t\t)\n\t\twindow.tldrawReady = true\n\t\treturn teardown\n\t})\n\n\tReact.useLayoutEffect(() => {\n\t\tif (editor) return onMountEvent?.(editor)\n\t}, [editor, onMountEvent])\n}\n"],
|
|
5
|
+
"mappings": "AA6SU,SA0TP,UA1TO,KA0TP,YA1TO;AA7SV,SAA4B,aAAa;AAEzC,SAAS,qBAA+B;AACxC,OAAO;AAAA,EACN;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,OAAO,gBAAgB;AACvB,SAAS,eAAe;AACxB,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AAEtC,SAAS,oBAA4B;AAIrC,SAAS,cAAc;AAGvB,SAAS,mBAAmB,oBAAoB;AAChD,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB,iBAAiB;AAC1C;AAAA,EACC;AAAA,EAEA;AAAA,OACM;AACP,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC;AACzC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAG1B,SAAS,4BAA4B;AAuMrC,MAAM,0BAA0B,CAAC;AACjC,MAAM,4BAA4B,CAAC;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awEditor", "LoadingScreen", "autoFocus", "inferDarkMode", "initialState", "cameraOptions", "deepLinks", "editor"]
|
|
7
7
|
}
|
|
@@ -32,10 +32,6 @@ function MenuClickCapture() {
|
|
|
32
32
|
const handlePointerMove = useCallback(
|
|
33
33
|
(e) => {
|
|
34
34
|
if (!rPointerState.current.isDown) return;
|
|
35
|
-
if (rPointerState.current.isDragging) {
|
|
36
|
-
canvasEvents.onPointerMove?.(e);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
35
|
if (
|
|
40
36
|
// We're pointing, but are we dragging?
|
|
41
37
|
Vec.Dist2(rPointerState.current.start, new Vec(e.clientX, e.clientY)) > editor.options.dragDistanceSquared
|
|
@@ -52,7 +48,6 @@ function MenuClickCapture() {
|
|
|
52
48
|
clientY: y,
|
|
53
49
|
button: 0
|
|
54
50
|
});
|
|
55
|
-
canvasEvents.onPointerMove?.(e);
|
|
56
51
|
}
|
|
57
52
|
},
|
|
58
53
|
[canvasEvents, editor]
|