@tldraw/editor 4.6.0-next.74727ac95b72 → 4.6.0-next.a31a8a6b83f2
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 +434 -114
- package/dist-cjs/index.js +16 -6
- package/dist-cjs/index.js.map +3 -3
- package/dist-cjs/lib/TldrawEditor.js +59 -14
- package/dist-cjs/lib/TldrawEditor.js.map +3 -3
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +3 -3
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +2 -2
- package/dist-cjs/lib/config/{createTLUser.js → createTLCurrentUser.js} +9 -9
- package/dist-cjs/lib/config/createTLCurrentUser.js.map +7 -0
- package/dist-cjs/lib/config/createTLStore.js +30 -0
- package/dist-cjs/lib/config/createTLStore.js.map +2 -2
- package/dist-cjs/lib/config/defaultAssets.js +36 -0
- package/dist-cjs/lib/config/defaultAssets.js.map +7 -0
- package/dist-cjs/lib/editor/Editor.js +310 -8
- package/dist-cjs/lib/editor/Editor.js.map +3 -3
- package/dist-cjs/lib/editor/assets/AssetUtil.js +66 -0
- package/dist-cjs/lib/editor/assets/AssetUtil.js.map +7 -0
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js +106 -0
- package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js +586 -0
- package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js.map +7 -0
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +6 -4
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +19 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
- package/dist-cjs/lib/editor/types/clipboard-types.js.map +1 -1
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js +12 -7
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/globals/environment.js +18 -1
- package/dist-cjs/lib/globals/environment.js.map +2 -2
- package/dist-cjs/lib/hooks/{useIsDarkMode.js → useColorMode.js} +14 -10
- package/dist-cjs/lib/hooks/useColorMode.js.map +7 -0
- package/dist-cjs/lib/hooks/useCursor.js +3 -7
- package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
- package/dist-cjs/lib/hooks/useDarkMode.js +4 -4
- package/dist-cjs/lib/hooks/useDarkMode.js.map +2 -2
- package/dist-cjs/lib/hooks/useGestureEvents.js +171 -127
- package/dist-cjs/lib/hooks/useGestureEvents.js.map +3 -3
- package/dist-cjs/lib/utils/reparenting.js +2 -1
- package/dist-cjs/lib/utils/reparenting.js.map +2 -2
- package/dist-cjs/lib/utils/richText.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 +434 -114
- package/dist-esm/index.mjs +21 -9
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +62 -14
- package/dist-esm/lib/TldrawEditor.mjs.map +3 -3
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +3 -3
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +2 -2
- package/dist-esm/lib/config/{createTLUser.mjs → createTLCurrentUser.mjs} +6 -6
- package/dist-esm/lib/config/createTLCurrentUser.mjs.map +7 -0
- package/dist-esm/lib/config/createTLStore.mjs +36 -1
- package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
- package/dist-esm/lib/config/defaultAssets.mjs +16 -0
- package/dist-esm/lib/config/defaultAssets.mjs.map +7 -0
- package/dist-esm/lib/editor/Editor.mjs +312 -8
- package/dist-esm/lib/editor/Editor.mjs.map +3 -3
- package/dist-esm/lib/editor/assets/AssetUtil.mjs +46 -0
- package/dist-esm/lib/editor/assets/AssetUtil.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs +88 -0
- package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs +568 -0
- package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +6 -4
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +19 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +12 -10
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/globals/environment.mjs +18 -1
- package/dist-esm/lib/globals/environment.mjs.map +2 -2
- package/dist-esm/lib/hooks/useColorMode.mjs +19 -0
- package/dist-esm/lib/hooks/useColorMode.mjs.map +7 -0
- package/dist-esm/lib/hooks/useCursor.mjs +3 -7
- package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
- package/dist-esm/lib/hooks/useDarkMode.mjs +4 -4
- package/dist-esm/lib/hooks/useDarkMode.mjs.map +2 -2
- package/dist-esm/lib/hooks/useGestureEvents.mjs +171 -127
- package/dist-esm/lib/hooks/useGestureEvents.mjs.map +3 -3
- package/dist-esm/lib/utils/reparenting.mjs +2 -1
- package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
- package/dist-esm/lib/utils/richText.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +13 -33
- package/package.json +8 -9
- package/src/index.ts +14 -7
- package/src/lib/TldrawEditor.tsx +98 -19
- package/src/lib/components/default-components/CanvasShapeIndicators.tsx +3 -3
- package/src/lib/config/{createTLUser.ts → createTLCurrentUser.ts} +6 -6
- package/src/lib/config/createTLStore.ts +57 -2
- package/src/lib/config/defaultAssets.ts +19 -0
- package/src/lib/editor/Editor.ts +424 -29
- package/src/lib/editor/assets/AssetUtil.ts +85 -0
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +9 -2
- package/src/lib/editor/managers/FontManager/FontManager.ts +1 -67
- package/src/lib/editor/managers/ThemeManager/ThemeManager.ts +116 -0
- package/src/lib/editor/managers/ThemeManager/defaultThemes.ts +605 -0
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +25 -31
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +7 -5
- package/src/lib/editor/shapes/ShapeUtil.ts +37 -1
- package/src/lib/editor/types/SvgExportContext.tsx +5 -0
- package/src/lib/editor/types/clipboard-types.ts +2 -1
- package/src/lib/editor/types/external-content.ts +1 -0
- package/src/lib/exports/getSvgJsx.tsx +21 -15
- package/src/lib/globals/environment.ts +18 -0
- package/src/lib/hooks/{useIsDarkMode.ts → useColorMode.ts} +9 -5
- package/src/lib/hooks/useCursor.ts +3 -7
- package/src/lib/hooks/useDarkMode.ts +4 -4
- package/src/lib/hooks/useGestureEvents.ts +240 -168
- package/src/lib/primitives/Box.test.ts +30 -0
- package/src/lib/primitives/geometry/Geometry2d.test.ts +21 -0
- package/src/lib/utils/reparenting.ts +6 -2
- package/src/lib/utils/richText.ts +1 -1
- package/src/version.ts +3 -3
- package/dist-cjs/lib/config/createTLUser.js.map +0 -7
- package/dist-cjs/lib/hooks/useIsDarkMode.js.map +0 -7
- package/dist-esm/lib/config/createTLUser.mjs.map +0 -7
- package/dist-esm/lib/hooks/useIsDarkMode.mjs +0 -15
- package/dist-esm/lib/hooks/useIsDarkMode.mjs.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/globals/environment.ts"],
|
|
4
|
-
"sourcesContent": ["import { atom } from '@tldraw/state'\nimport { getGlobalWindow } from '../utils/dom'\n\n/**\n * An object that contains information about the current device and environment.\n * This object is not reactive and will not update automatically when the environment changes,\n * so only include values that are fixed, such as the user's browser and operating system.\n *\n * @public\n */\nconst tlenv = {\n\tisSafari: false,\n\tisIos: false,\n\tisChromeForIos: false,\n\tisFirefox: false,\n\tisAndroid: false,\n\tisWebview: false,\n\tisDarwin: false,\n\thasCanvasSupport: false,\n}\n\nlet isForcedFinePointer = false\n\nif (typeof window !== 'undefined') {\n\tif ('navigator' in window) {\n\t\ttlenv.isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)\n\t\ttlenv.isIos = !!navigator.userAgent.match(/iPad/i) || !!navigator.userAgent.match(/iPhone/i)\n\t\ttlenv.isChromeForIos = /crios.*safari/i.test(navigator.userAgent)\n\t\ttlenv.isFirefox = /firefox/i.test(navigator.userAgent)\n\t\ttlenv.isAndroid = /android/i.test(navigator.userAgent)\n\t\ttlenv.isDarwin = getGlobalWindow().navigator.userAgent.toLowerCase().indexOf('mac') > -1\n\t}\n\ttlenv.hasCanvasSupport = 'Promise' in window && 'HTMLCanvasElement' in window\n\tisForcedFinePointer = tlenv.isFirefox && !tlenv.isAndroid && !tlenv.isIos\n}\n\n/**\n * An atom that contains information about the current device and environment.\n * This object is reactive and will update automatically when the environment changes.\n * Use it for values that may change over time, such as the pointer type.\n *\n * @public\n */\nconst tlenvReactive = atom('tlenvReactive', {\n\t// Whether the user's device has a coarse pointer. This is dynamic on many systems, especially\n\t// on touch-screen laptops, which will become \"coarse\" if the user touches the screen.\n\t// See https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/pointer#coarse\n\tisCoarsePointer: false,\n})\n\nif (typeof window !== 'undefined' && !isForcedFinePointer) {\n\tconst mql = getGlobalWindow().matchMedia && getGlobalWindow().matchMedia('(any-pointer: coarse)')\n\n\tconst isCurrentCoarsePointer = () => tlenvReactive.__unsafe__getWithoutCapture().isCoarsePointer\n\n\tif (mql) {\n\t\t// 1. Update the coarse pointer automatically when the media query changes\n\t\tconst updateIsCoarsePointer = () => {\n\t\t\tconst isCoarsePointer = mql.matches\n\t\t\tif (isCoarsePointer !== isCurrentCoarsePointer()) {\n\t\t\t\ttlenvReactive.update((prev) => ({ ...prev, isCoarsePointer: isCoarsePointer }))\n\t\t\t}\n\t\t}\n\t\tupdateIsCoarsePointer()\n\t\tmql.addEventListener('change', updateIsCoarsePointer)\n\t}\n\n\t// 2. Also update the coarse pointer state when a pointer down event occurs. We need `capture: true`\n\t// here because the tldraw component itself stops propagation on pointer events it receives.\n\tgetGlobalWindow().addEventListener(\n\t\t'pointerdown',\n\t\t(e: PointerEvent) => {\n\t\t\t// when the user interacts with a mouse, we assume they have a fine pointer.\n\t\t\t// otherwise, we assume they have a coarse pointer.\n\t\t\tconst isCoarseEvent = e.pointerType !== 'mouse'\n\t\t\tif (isCoarseEvent !== isCurrentCoarsePointer()) {\n\t\t\t\ttlenvReactive.update((prev) => ({ ...prev, isCoarsePointer: isCoarseEvent }))\n\t\t\t}\n\t\t},\n\t\t{ capture: true }\n\t)\n}\n\nexport { tlenv, tlenvReactive }\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqB;AACrB,iBAAgC;AAShC,MAAM,QAAQ;AAAA,EACb,UAAU;AAAA,EACV,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,kBAAkB;AACnB;AAEA,IAAI,sBAAsB;AAE1B,IAAI,OAAO,WAAW,aAAa;AAClC,MAAI,eAAe,QAAQ;AAC1B,UAAM,WAAW,iCAAiC,KAAK,UAAU,SAAS;AAC1E,UAAM,QAAQ,CAAC,CAAC,UAAU,UAAU,MAAM,OAAO,KAAK,CAAC,CAAC,UAAU,UAAU,MAAM,SAAS;AAC3F,UAAM,iBAAiB,iBAAiB,KAAK,UAAU,SAAS;AAChE,UAAM,YAAY,WAAW,KAAK,UAAU,SAAS;AACrD,UAAM,YAAY,WAAW,KAAK,UAAU,SAAS;AACrD,UAAM,eAAW,4BAAgB,EAAE,UAAU,UAAU,YAAY,EAAE,QAAQ,KAAK,IAAI;AAAA,EACvF;AACA,QAAM,mBAAmB,aAAa,UAAU,uBAAuB;AACvE,wBAAsB,MAAM,aAAa,CAAC,MAAM,aAAa,CAAC,MAAM;AACrE;AASA,MAAM,oBAAgB,mBAAK,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAI3C,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import { atom } from '@tldraw/state'\nimport { getGlobalWindow } from '../utils/dom'\n\n/**\n * An object that contains information about the current device and environment.\n * This object is not reactive and will not update automatically when the environment changes,\n * so only include values that are fixed, such as the user's browser and operating system.\n *\n * @public\n */\nconst tlenv = {\n\tisSafari: false,\n\tisIos: false,\n\tisChromeForIos: false,\n\tisFirefox: false,\n\tisAndroid: false,\n\tisWebview: false,\n\tisDarwin: false,\n\thasCanvasSupport: false,\n}\n\nlet isForcedFinePointer = false\n\nif (typeof window !== 'undefined') {\n\tif ('navigator' in window) {\n\t\ttlenv.isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)\n\t\ttlenv.isIos = !!navigator.userAgent.match(/iPad/i) || !!navigator.userAgent.match(/iPhone/i)\n\t\ttlenv.isChromeForIos = /crios.*safari/i.test(navigator.userAgent)\n\t\ttlenv.isFirefox = /firefox/i.test(navigator.userAgent)\n\t\ttlenv.isAndroid = /android/i.test(navigator.userAgent)\n\t\ttlenv.isDarwin = getGlobalWindow().navigator.userAgent.toLowerCase().indexOf('mac') > -1\n\t}\n\ttlenv.hasCanvasSupport = 'Promise' in window && 'HTMLCanvasElement' in window\n\tisForcedFinePointer = tlenv.isFirefox && !tlenv.isAndroid && !tlenv.isIos\n}\n\n/**\n * An atom that contains information about the current device and environment.\n * This object is reactive and will update automatically when the environment changes.\n * Use it for values that may change over time, such as the pointer type.\n *\n * @public\n */\nconst tlenvReactive = atom('tlenvReactive', {\n\t// Whether the user's device has a coarse pointer. This is dynamic on many systems, especially\n\t// on touch-screen laptops, which will become \"coarse\" if the user touches the screen.\n\t// See https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/pointer#coarse\n\tisCoarsePointer: false,\n\t// Whether the user's display supports P3 color space. This is dynamic because a window can\n\t// move between displays with different color gamut support.\n\tsupportsP3ColorSpace: false,\n})\n\nif (typeof window !== 'undefined') {\n\tconst canRenderP3 = typeof CSS !== 'undefined' && CSS.supports('color', 'color(display-p3 1 1 1)')\n\tif (canRenderP3) {\n\t\tconst p3mql = window.matchMedia('(color-gamut: p3)')\n\t\tconst updateSupportsP3 = () => {\n\t\t\tconst supportsP3 = p3mql.matches\n\t\t\tif (supportsP3 !== tlenvReactive.__unsafe__getWithoutCapture().supportsP3ColorSpace) {\n\t\t\t\ttlenvReactive.update((prev) => ({ ...prev, supportsP3ColorSpace: supportsP3 }))\n\t\t\t}\n\t\t}\n\t\tupdateSupportsP3()\n\t\tp3mql.addEventListener('change', updateSupportsP3)\n\t}\n}\n\nif (typeof window !== 'undefined' && !isForcedFinePointer) {\n\tconst mql = getGlobalWindow().matchMedia && getGlobalWindow().matchMedia('(any-pointer: coarse)')\n\n\tconst isCurrentCoarsePointer = () => tlenvReactive.__unsafe__getWithoutCapture().isCoarsePointer\n\n\tif (mql) {\n\t\t// 1. Update the coarse pointer automatically when the media query changes\n\t\tconst updateIsCoarsePointer = () => {\n\t\t\tconst isCoarsePointer = mql.matches\n\t\t\tif (isCoarsePointer !== isCurrentCoarsePointer()) {\n\t\t\t\ttlenvReactive.update((prev) => ({ ...prev, isCoarsePointer: isCoarsePointer }))\n\t\t\t}\n\t\t}\n\t\tupdateIsCoarsePointer()\n\t\tmql.addEventListener('change', updateIsCoarsePointer)\n\t}\n\n\t// 2. Also update the coarse pointer state when a pointer down event occurs. We need `capture: true`\n\t// here because the tldraw component itself stops propagation on pointer events it receives.\n\tgetGlobalWindow().addEventListener(\n\t\t'pointerdown',\n\t\t(e: PointerEvent) => {\n\t\t\t// when the user interacts with a mouse, we assume they have a fine pointer.\n\t\t\t// otherwise, we assume they have a coarse pointer.\n\t\t\tconst isCoarseEvent = e.pointerType !== 'mouse'\n\t\t\tif (isCoarseEvent !== isCurrentCoarsePointer()) {\n\t\t\t\ttlenvReactive.update((prev) => ({ ...prev, isCoarsePointer: isCoarseEvent }))\n\t\t\t}\n\t\t},\n\t\t{ capture: true }\n\t)\n}\n\nexport { tlenv, tlenvReactive }\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqB;AACrB,iBAAgC;AAShC,MAAM,QAAQ;AAAA,EACb,UAAU;AAAA,EACV,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,kBAAkB;AACnB;AAEA,IAAI,sBAAsB;AAE1B,IAAI,OAAO,WAAW,aAAa;AAClC,MAAI,eAAe,QAAQ;AAC1B,UAAM,WAAW,iCAAiC,KAAK,UAAU,SAAS;AAC1E,UAAM,QAAQ,CAAC,CAAC,UAAU,UAAU,MAAM,OAAO,KAAK,CAAC,CAAC,UAAU,UAAU,MAAM,SAAS;AAC3F,UAAM,iBAAiB,iBAAiB,KAAK,UAAU,SAAS;AAChE,UAAM,YAAY,WAAW,KAAK,UAAU,SAAS;AACrD,UAAM,YAAY,WAAW,KAAK,UAAU,SAAS;AACrD,UAAM,eAAW,4BAAgB,EAAE,UAAU,UAAU,YAAY,EAAE,QAAQ,KAAK,IAAI;AAAA,EACvF;AACA,QAAM,mBAAmB,aAAa,UAAU,uBAAuB;AACvE,wBAAsB,MAAM,aAAa,CAAC,MAAM,aAAa,CAAC,MAAM;AACrE;AASA,MAAM,oBAAgB,mBAAK,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAI3C,iBAAiB;AAAA;AAAA;AAAA,EAGjB,sBAAsB;AACvB,CAAC;AAED,IAAI,OAAO,WAAW,aAAa;AAClC,QAAM,cAAc,OAAO,QAAQ,eAAe,IAAI,SAAS,SAAS,yBAAyB;AACjG,MAAI,aAAa;AAChB,UAAM,QAAQ,OAAO,WAAW,mBAAmB;AACnD,UAAM,mBAAmB,MAAM;AAC9B,YAAM,aAAa,MAAM;AACzB,UAAI,eAAe,cAAc,4BAA4B,EAAE,sBAAsB;AACpF,sBAAc,OAAO,CAAC,UAAU,EAAE,GAAG,MAAM,sBAAsB,WAAW,EAAE;AAAA,MAC/E;AAAA,IACD;AACA,qBAAiB;AACjB,UAAM,iBAAiB,UAAU,gBAAgB;AAAA,EAClD;AACD;AAEA,IAAI,OAAO,WAAW,eAAe,CAAC,qBAAqB;AAC1D,QAAM,UAAM,4BAAgB,EAAE,kBAAc,4BAAgB,EAAE,WAAW,uBAAuB;AAEhG,QAAM,yBAAyB,MAAM,cAAc,4BAA4B,EAAE;AAEjF,MAAI,KAAK;AAER,UAAM,wBAAwB,MAAM;AACnC,YAAM,kBAAkB,IAAI;AAC5B,UAAI,oBAAoB,uBAAuB,GAAG;AACjD,sBAAc,OAAO,CAAC,UAAU,EAAE,GAAG,MAAM,gBAAiC,EAAE;AAAA,MAC/E;AAAA,IACD;AACA,0BAAsB;AACtB,QAAI,iBAAiB,UAAU,qBAAqB;AAAA,EACrD;AAIA,kCAAgB,EAAE;AAAA,IACjB;AAAA,IACA,CAAC,MAAoB;AAGpB,YAAM,gBAAgB,EAAE,gBAAgB;AACxC,UAAI,kBAAkB,uBAAuB,GAAG;AAC/C,sBAAc,OAAO,CAAC,UAAU,EAAE,GAAG,MAAM,iBAAiB,cAAc,EAAE;AAAA,MAC7E;AAAA,IACD;AAAA,IACA,EAAE,SAAS,KAAK;AAAA,EACjB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,20 +16,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var useColorMode_exports = {};
|
|
20
|
+
__export(useColorMode_exports, {
|
|
21
|
+
useColorMode: () => useColorMode
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(useColorMode_exports);
|
|
24
24
|
var import_state_react = require("@tldraw/state-react");
|
|
25
25
|
var import_SvgExportContext = require("../editor/types/SvgExportContext");
|
|
26
26
|
var import_useEditor = require("./useEditor");
|
|
27
|
-
function
|
|
27
|
+
function useColorMode() {
|
|
28
28
|
const editor = (0, import_useEditor.useEditor)();
|
|
29
29
|
const exportContext = (0, import_SvgExportContext.useSvgExportContext)();
|
|
30
|
-
return (0, import_state_react.useValue)(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
return (0, import_state_react.useValue)(
|
|
31
|
+
"colorMode",
|
|
32
|
+
() => {
|
|
33
|
+
if (exportContext) return exportContext.colorMode;
|
|
34
|
+
return editor.getColorMode();
|
|
35
|
+
},
|
|
36
|
+
[exportContext, editor]
|
|
37
|
+
);
|
|
34
38
|
}
|
|
35
|
-
//# sourceMappingURL=
|
|
39
|
+
//# sourceMappingURL=useColorMode.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/hooks/useColorMode.ts"],
|
|
4
|
+
"sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { useSvgExportContext } from '../editor/types/SvgExportContext'\nimport { useEditor } from './useEditor'\n\n/** @public */\nexport function useColorMode(): 'light' | 'dark' {\n\tconst editor = useEditor()\n\tconst exportContext = useSvgExportContext()\n\treturn useValue(\n\t\t'colorMode',\n\t\t() => {\n\t\t\tif (exportContext) return exportContext.colorMode\n\t\t\treturn editor.getColorMode()\n\t\t},\n\t\t[exportContext, editor]\n\t)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAyB;AACzB,8BAAoC;AACpC,uBAA0B;AAGnB,SAAS,eAAiC;AAChD,QAAM,aAAS,4BAAU;AACzB,QAAM,oBAAgB,6CAAoB;AAC1C,aAAO;AAAA,IACN;AAAA,IACA,MAAM;AACL,UAAI,cAAe,QAAO,cAAc;AACxC,aAAO,OAAO,aAAa;AAAA,IAC5B;AAAA,IACA,CAAC,eAAe,MAAM;AAAA,EACvB;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -26,7 +26,6 @@ var import_state_react = require("@tldraw/state-react");
|
|
|
26
26
|
var import_utils = require("../primitives/utils");
|
|
27
27
|
var import_useContainer = require("./useContainer");
|
|
28
28
|
var import_useEditor = require("./useEditor");
|
|
29
|
-
var import_useIsDarkMode = require("./useIsDarkMode");
|
|
30
29
|
const CORNER_SVG = `<path d='m19.7432 17.0869-4.072 4.068 2.829 2.828-8.473-.013-.013-8.47 2.841 2.842 4.075-4.068 1.414-1.415-2.844-2.842h8.486v8.484l-2.83-2.827z' fill='%23fff'/><path d='m18.6826 16.7334-4.427 4.424 1.828 1.828-5.056-.016-.014-5.054 1.842 1.841 4.428-4.422 2.474-2.475-1.844-1.843h5.073v5.071l-1.83-1.828z' fill='%23000'/>`;
|
|
31
30
|
const EDGE_SVG = `<path d='m9 17.9907v.005l5.997 5.996.001-3.999h1.999 2.02v4l5.98-6.001-5.98-5.999.001 4.019-2.021.002h-2l.001-4.022zm1.411.003 3.587-3.588-.001 2.587h3.5 2.521v-2.585l3.565 3.586-3.564 3.585-.001-2.585h-2.521l-3.499-.001-.001 2.586z' fill='%23fff'/><path d='m17.4971 18.9932h2.521v2.586l3.565-3.586-3.565-3.585v2.605h-2.521-3.5v-2.607l-3.586 3.587 3.586 3.586v-2.587z' fill='%23000'/>`;
|
|
32
31
|
const ROTATE_CORNER_SVG = `<path d="M22.4789 9.45728L25.9935 12.9942L22.4789 16.5283V14.1032C18.126 14.1502 14.6071 17.6737 14.5675 22.0283H17.05L13.513 25.543L9.97889 22.0283H12.5674C12.6071 16.5691 17.0214 12.1503 22.4789 12.1031L22.4789 9.45728Z" fill="black"/><path fill-rule="evenodd" clip-rule="evenodd" d="M21.4789 7.03223L27.4035 12.9945L21.4789 18.9521V15.1868C18.4798 15.6549 16.1113 18.0273 15.649 21.0284H19.475L13.5128 26.953L7.55519 21.0284H11.6189C12.1243 15.8155 16.2679 11.6677 21.4789 11.1559L21.4789 7.03223ZM22.4789 12.1031C17.0214 12.1503 12.6071 16.5691 12.5674 22.0284H9.97889L13.513 25.543L17.05 22.0284H14.5675C14.5705 21.6896 14.5947 21.3558 14.6386 21.0284C15.1157 17.4741 17.9266 14.6592 21.4789 14.1761C21.8063 14.1316 22.1401 14.1069 22.4789 14.1032V16.5284L25.9935 12.9942L22.4789 9.45729L22.4789 12.1031Z" fill="white"/>`;
|
|
@@ -66,7 +65,6 @@ function getCursor(cursor, rotation = 0, color = "black") {
|
|
|
66
65
|
function useCursor() {
|
|
67
66
|
const editor = (0, import_useEditor.useEditor)();
|
|
68
67
|
const container = (0, import_useContainer.useContainer)();
|
|
69
|
-
const isDarkMode = (0, import_useIsDarkMode.useIsDarkMode)();
|
|
70
68
|
(0, import_state_react.useQuickReactor)(
|
|
71
69
|
"useCursor",
|
|
72
70
|
() => {
|
|
@@ -75,12 +73,10 @@ function useCursor() {
|
|
|
75
73
|
container.style.setProperty("--tl-cursor", `var(--tl-cursor-${type})`);
|
|
76
74
|
return;
|
|
77
75
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
getCursor(type, rotation, isDarkMode ? "white" : "black")
|
|
81
|
-
);
|
|
76
|
+
const { cursor } = editor.getCurrentTheme().colors[editor.getColorMode()];
|
|
77
|
+
container.style.setProperty("--tl-cursor", getCursor(type, rotation, cursor));
|
|
82
78
|
},
|
|
83
|
-
[editor, container
|
|
79
|
+
[editor, container]
|
|
84
80
|
);
|
|
85
81
|
}
|
|
86
82
|
//# sourceMappingURL=useCursor.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/hooks/useCursor.ts"],
|
|
4
|
-
"sourcesContent": ["import { useQuickReactor } from '@tldraw/state-react'\nimport { TLCursorType } from '@tldraw/tlschema'\nimport { PI, radiansToDegrees } from '../primitives/utils'\nimport { useContainer } from './useContainer'\nimport { useEditor } from './useEditor'\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAgC;AAEhC,mBAAqC;AACrC,0BAA6B;AAC7B,uBAA0B;
|
|
4
|
+
"sourcesContent": ["import { useQuickReactor } from '@tldraw/state-react'\nimport { TLCursorType } from '@tldraw/tlschema'\nimport { PI, radiansToDegrees } from '../primitives/utils'\nimport { useContainer } from './useContainer'\nimport { useEditor } from './useEditor'\n\nconst CORNER_SVG = `<path d='m19.7432 17.0869-4.072 4.068 2.829 2.828-8.473-.013-.013-8.47 2.841 2.842 4.075-4.068 1.414-1.415-2.844-2.842h8.486v8.484l-2.83-2.827z' fill='%23fff'/><path d='m18.6826 16.7334-4.427 4.424 1.828 1.828-5.056-.016-.014-5.054 1.842 1.841 4.428-4.422 2.474-2.475-1.844-1.843h5.073v5.071l-1.83-1.828z' fill='%23000'/>`\nconst EDGE_SVG = `<path d='m9 17.9907v.005l5.997 5.996.001-3.999h1.999 2.02v4l5.98-6.001-5.98-5.999.001 4.019-2.021.002h-2l.001-4.022zm1.411.003 3.587-3.588-.001 2.587h3.5 2.521v-2.585l3.565 3.586-3.564 3.585-.001-2.585h-2.521l-3.499-.001-.001 2.586z' fill='%23fff'/><path d='m17.4971 18.9932h2.521v2.586l3.565-3.586-3.565-3.585v2.605h-2.521-3.5v-2.607l-3.586 3.587 3.586 3.586v-2.587z' fill='%23000'/>`\nconst ROTATE_CORNER_SVG = `<path d=\"M22.4789 9.45728L25.9935 12.9942L22.4789 16.5283V14.1032C18.126 14.1502 14.6071 17.6737 14.5675 22.0283H17.05L13.513 25.543L9.97889 22.0283H12.5674C12.6071 16.5691 17.0214 12.1503 22.4789 12.1031L22.4789 9.45728Z\" fill=\"black\"/><path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M21.4789 7.03223L27.4035 12.9945L21.4789 18.9521V15.1868C18.4798 15.6549 16.1113 18.0273 15.649 21.0284H19.475L13.5128 26.953L7.55519 21.0284H11.6189C12.1243 15.8155 16.2679 11.6677 21.4789 11.1559L21.4789 7.03223ZM22.4789 12.1031C17.0214 12.1503 12.6071 16.5691 12.5674 22.0284H9.97889L13.513 25.543L17.05 22.0284H14.5675C14.5705 21.6896 14.5947 21.3558 14.6386 21.0284C15.1157 17.4741 17.9266 14.6592 21.4789 14.1761C21.8063 14.1316 22.1401 14.1069 22.4789 14.1032V16.5284L25.9935 12.9942L22.4789 9.45729L22.4789 12.1031Z\" fill=\"white\"/>`\n\nfunction getCursorCss(\n\tsvg: string,\n\tr: number,\n\ttr: number,\n\tf: boolean,\n\tcolor: string,\n\thotspotX = 16,\n\thotspotY = 16\n) {\n\tconst a = (-tr - r) * (PI / 180)\n\tconst s = Math.sin(a)\n\tconst c = Math.cos(a)\n\tconst dx = 1 * c - 1 * s\n\tconst dy = 1 * s + 1 * c\n\n\treturn (\n\t\t`url(\"data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${color};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${dx}' dy='${dy}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${\n\t\t\tr + tr\n\t\t} 16 16)${f ? ` scale(-1,-1) translate(0, -32)` : ''}' filter='url(%23shadow)'>` +\n\t\tsvg.replaceAll(`\"`, `'`) +\n\t\t`</g></svg>\") ${hotspotX} ${hotspotY}, pointer`\n\t)\n}\n\nconst STATIC_CURSORS = [\n\t'default',\n\t'pointer',\n\t'cross',\n\t'move',\n\t'grab',\n\t'grabbing',\n\t'text',\n\t'zoom-in',\n\t'zoom-out',\n]\n\ntype CursorFunction = (rotation: number, flip: boolean, color: string) => string\n\nconst CURSORS: Record<TLCursorType, CursorFunction> = {\n\tnone: () => 'none',\n\t'ew-resize': (r, f, c) => getCursorCss(EDGE_SVG, r, 0, f, c),\n\t'ns-resize': (r, f, c) => getCursorCss(EDGE_SVG, r, 90, f, c),\n\t'nesw-resize': (r, f, c) => getCursorCss(CORNER_SVG, r, 0, f, c),\n\t'nwse-resize': (r, f, c) => getCursorCss(CORNER_SVG, r, 90, f, c),\n\t'nwse-rotate': (r, f, c) => getCursorCss(ROTATE_CORNER_SVG, r, 0, f, c),\n\t'nesw-rotate': (r, f, c) => getCursorCss(ROTATE_CORNER_SVG, r, 90, f, c),\n\t'senw-rotate': (r, f, c) => getCursorCss(ROTATE_CORNER_SVG, r, 180, f, c),\n\t'swne-rotate': (r, f, c) => getCursorCss(ROTATE_CORNER_SVG, r, 270, f, c),\n}\n\n/** @public */\nexport function getCursor(cursor: TLCursorType, rotation = 0, color = 'black') {\n\treturn CURSORS[cursor](radiansToDegrees(rotation), false, color)\n}\n\nexport function useCursor() {\n\tconst editor = useEditor()\n\tconst container = useContainer()\n\n\tuseQuickReactor(\n\t\t'useCursor',\n\t\t() => {\n\t\t\tconst { type, rotation } = editor.getInstanceState().cursor\n\n\t\t\tif (STATIC_CURSORS.includes(type)) {\n\t\t\t\tcontainer.style.setProperty('--tl-cursor', `var(--tl-cursor-${type})`)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst { cursor } = editor.getCurrentTheme().colors[editor.getColorMode()]\n\t\t\tcontainer.style.setProperty('--tl-cursor', getCursor(type, rotation, cursor))\n\t\t},\n\t\t[editor, container]\n\t)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAgC;AAEhC,mBAAqC;AACrC,0BAA6B;AAC7B,uBAA0B;AAE1B,MAAM,aAAa;AACnB,MAAM,WAAW;AACjB,MAAM,oBAAoB;AAE1B,SAAS,aACR,KACA,GACA,IACA,GACA,OACA,WAAW,IACX,WAAW,IACV;AACD,QAAM,KAAK,CAAC,KAAK,MAAM,kBAAK;AAC5B,QAAM,IAAI,KAAK,IAAI,CAAC;AACpB,QAAM,IAAI,KAAK,IAAI,CAAC;AACpB,QAAM,KAAK,IAAI,IAAI,IAAI;AACvB,QAAM,KAAK,IAAI,IAAI,IAAI;AAEvB,SACC,4HAA4H,KAAK,mIAAmI,EAAE,SAAS,EAAE,6FAChR,IAAI,EACL,UAAU,IAAI,oCAAoC,EAAE,+BACpD,IAAI,WAAW,KAAK,GAAG,IACvB,gBAAgB,QAAQ,IAAI,QAAQ;AAEtC;AAEA,MAAM,iBAAiB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAIA,MAAM,UAAgD;AAAA,EACrD,MAAM,MAAM;AAAA,EACZ,aAAa,CAAC,GAAG,GAAG,MAAM,aAAa,UAAU,GAAG,GAAG,GAAG,CAAC;AAAA,EAC3D,aAAa,CAAC,GAAG,GAAG,MAAM,aAAa,UAAU,GAAG,IAAI,GAAG,CAAC;AAAA,EAC5D,eAAe,CAAC,GAAG,GAAG,MAAM,aAAa,YAAY,GAAG,GAAG,GAAG,CAAC;AAAA,EAC/D,eAAe,CAAC,GAAG,GAAG,MAAM,aAAa,YAAY,GAAG,IAAI,GAAG,CAAC;AAAA,EAChE,eAAe,CAAC,GAAG,GAAG,MAAM,aAAa,mBAAmB,GAAG,GAAG,GAAG,CAAC;AAAA,EACtE,eAAe,CAAC,GAAG,GAAG,MAAM,aAAa,mBAAmB,GAAG,IAAI,GAAG,CAAC;AAAA,EACvE,eAAe,CAAC,GAAG,GAAG,MAAM,aAAa,mBAAmB,GAAG,KAAK,GAAG,CAAC;AAAA,EACxE,eAAe,CAAC,GAAG,GAAG,MAAM,aAAa,mBAAmB,GAAG,KAAK,GAAG,CAAC;AACzE;AAGO,SAAS,UAAU,QAAsB,WAAW,GAAG,QAAQ,SAAS;AAC9E,SAAO,QAAQ,MAAM,MAAE,+BAAiB,QAAQ,GAAG,OAAO,KAAK;AAChE;AAEO,SAAS,YAAY;AAC3B,QAAM,aAAS,4BAAU;AACzB,QAAM,gBAAY,kCAAa;AAE/B;AAAA,IACC;AAAA,IACA,MAAM;AACL,YAAM,EAAE,MAAM,SAAS,IAAI,OAAO,iBAAiB,EAAE;AAErD,UAAI,eAAe,SAAS,IAAI,GAAG;AAClC,kBAAU,MAAM,YAAY,eAAe,mBAAmB,IAAI,GAAG;AACrE;AAAA,MACD;AAEA,YAAM,EAAE,OAAO,IAAI,OAAO,gBAAgB,EAAE,OAAO,OAAO,aAAa,CAAC;AACxE,gBAAU,MAAM,YAAY,eAAe,UAAU,MAAM,UAAU,MAAM,CAAC;AAAA,IAC7E;AAAA,IACA,CAAC,QAAQ,SAAS;AAAA,EACnB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -34,16 +34,16 @@ module.exports = __toCommonJS(useDarkMode_exports);
|
|
|
34
34
|
var import_state_react = require("@tldraw/state-react");
|
|
35
35
|
var import_react = __toESM(require("react"), 1);
|
|
36
36
|
var import_debug_flags = require("../utils/debug-flags");
|
|
37
|
+
var import_useColorMode = require("./useColorMode");
|
|
37
38
|
var import_useContainer = require("./useContainer");
|
|
38
39
|
var import_useEditor = require("./useEditor");
|
|
39
|
-
var import_useIsDarkMode = require("./useIsDarkMode");
|
|
40
40
|
function useDarkMode() {
|
|
41
41
|
const editor = (0, import_useEditor.useEditor)();
|
|
42
42
|
const container = (0, import_useContainer.useContainer)();
|
|
43
|
-
const
|
|
43
|
+
const colorMode = (0, import_useColorMode.useColorMode)();
|
|
44
44
|
const forceSrgb = (0, import_state_react.useValue)(import_debug_flags.debugFlags.forceSrgb);
|
|
45
45
|
import_react.default.useEffect(() => {
|
|
46
|
-
if (
|
|
46
|
+
if (colorMode === "dark") {
|
|
47
47
|
container.setAttribute("data-color-mode", "dark");
|
|
48
48
|
container.classList.remove("tl-theme__light");
|
|
49
49
|
container.classList.add("tl-theme__dark");
|
|
@@ -57,6 +57,6 @@ function useDarkMode() {
|
|
|
57
57
|
} else {
|
|
58
58
|
container.classList.remove("tl-theme__force-sRGB");
|
|
59
59
|
}
|
|
60
|
-
}, [editor, container, forceSrgb,
|
|
60
|
+
}, [editor, container, forceSrgb, colorMode]);
|
|
61
61
|
}
|
|
62
62
|
//# sourceMappingURL=useDarkMode.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/hooks/useDarkMode.ts"],
|
|
4
|
-
"sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport React from 'react'\nimport { debugFlags } from '../utils/debug-flags'\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAyB;AACzB,mBAAkB;AAClB,yBAA2B;AAC3B,0BAA6B;AAC7B,
|
|
4
|
+
"sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport React from 'react'\nimport { debugFlags } from '../utils/debug-flags'\nimport { useColorMode } from './useColorMode'\nimport { useContainer } from './useContainer'\nimport { useEditor } from './useEditor'\n\nexport function useDarkMode() {\n\tconst editor = useEditor()\n\tconst container = useContainer()\n\tconst colorMode = useColorMode()\n\tconst forceSrgb = useValue(debugFlags.forceSrgb)\n\n\tReact.useEffect(() => {\n\t\tif (colorMode === 'dark') {\n\t\t\tcontainer.setAttribute('data-color-mode', 'dark')\n\t\t\tcontainer.classList.remove('tl-theme__light')\n\t\t\tcontainer.classList.add('tl-theme__dark')\n\t\t} else {\n\t\t\tcontainer.setAttribute('data-color-mode', 'light')\n\t\t\tcontainer.classList.remove('tl-theme__dark')\n\t\t\tcontainer.classList.add('tl-theme__light')\n\t\t}\n\t\tif (forceSrgb) {\n\t\t\tcontainer.classList.add('tl-theme__force-sRGB')\n\t\t} else {\n\t\t\tcontainer.classList.remove('tl-theme__force-sRGB')\n\t\t}\n\t}, [editor, container, forceSrgb, colorMode])\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAyB;AACzB,mBAAkB;AAClB,yBAA2B;AAC3B,0BAA6B;AAC7B,0BAA6B;AAC7B,uBAA0B;AAEnB,SAAS,cAAc;AAC7B,QAAM,aAAS,4BAAU;AACzB,QAAM,gBAAY,kCAAa;AAC/B,QAAM,gBAAY,kCAAa;AAC/B,QAAM,gBAAY,6BAAS,8BAAW,SAAS;AAE/C,eAAAA,QAAM,UAAU,MAAM;AACrB,QAAI,cAAc,QAAQ;AACzB,gBAAU,aAAa,mBAAmB,MAAM;AAChD,gBAAU,UAAU,OAAO,iBAAiB;AAC5C,gBAAU,UAAU,IAAI,gBAAgB;AAAA,IACzC,OAAO;AACN,gBAAU,aAAa,mBAAmB,OAAO;AACjD,gBAAU,UAAU,OAAO,gBAAgB;AAC3C,gBAAU,UAAU,IAAI,iBAAiB;AAAA,IAC1C;AACA,QAAI,WAAW;AACd,gBAAU,UAAU,IAAI,sBAAsB;AAAA,IAC/C,OAAO;AACN,gBAAU,UAAU,OAAO,sBAAsB;AAAA,IAClD;AAAA,EACD,GAAG,CAAC,QAAQ,WAAW,WAAW,SAAS,CAAC;AAC7C;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -31,39 +31,24 @@ __export(useGestureEvents_exports, {
|
|
|
31
31
|
useGestureEvents: () => useGestureEvents
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(useGestureEvents_exports);
|
|
34
|
-
var import_react = require("@use-gesture/react");
|
|
35
34
|
var React = __toESM(require("react"), 1);
|
|
35
|
+
var import_environment = require("../globals/environment");
|
|
36
36
|
var import_Vec = require("../primitives/Vec");
|
|
37
37
|
var import_dom = require("../utils/dom");
|
|
38
38
|
var import_keyboard = require("../utils/keyboard");
|
|
39
39
|
var import_normalizeWheel = require("../utils/normalizeWheel");
|
|
40
40
|
var import_useEditor = require("./useEditor");
|
|
41
|
-
const useGesture = (0, import_react.createUseGesture)([import_react.wheelAction, import_react.pinchAction]);
|
|
42
|
-
let lastWheelTime = void 0;
|
|
43
|
-
const isWheelEndEvent = (time) => {
|
|
44
|
-
if (lastWheelTime === void 0) {
|
|
45
|
-
lastWheelTime = time;
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
if (time - lastWheelTime > 120 && time - lastWheelTime < 160) {
|
|
49
|
-
lastWheelTime = time;
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
lastWheelTime = time;
|
|
53
|
-
return false;
|
|
54
|
-
};
|
|
55
41
|
function useGestureEvents(ref) {
|
|
56
42
|
const editor = (0, import_useEditor.useEditor)();
|
|
57
|
-
|
|
43
|
+
React.useEffect(() => {
|
|
44
|
+
const elm = ref.current;
|
|
45
|
+
if (!elm) return;
|
|
58
46
|
let pinchState = "not sure";
|
|
59
|
-
|
|
47
|
+
function onWheel(event) {
|
|
60
48
|
if (!editor.getInstanceState().isFocused) {
|
|
61
49
|
return;
|
|
62
50
|
}
|
|
63
51
|
pinchState = "not sure";
|
|
64
|
-
if (isWheelEndEvent(Date.now())) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
52
|
const editingShapeId = editor.getEditingShapeId();
|
|
68
53
|
if (editingShapeId) {
|
|
69
54
|
const shape = editor.getShape(editingShapeId);
|
|
@@ -93,37 +78,30 @@ function useGestureEvents(ref) {
|
|
|
93
78
|
accelKey: (0, import_keyboard.isAccelKey)(event)
|
|
94
79
|
};
|
|
95
80
|
editor.dispatch(info);
|
|
96
|
-
}
|
|
81
|
+
}
|
|
97
82
|
let initDistanceBetweenFingers = 1;
|
|
98
83
|
let initZoom = 1;
|
|
99
84
|
let currDistanceBetweenFingers = 0;
|
|
100
85
|
const initPointBetweenFingers = new import_Vec.Vec();
|
|
101
86
|
const prevPointBetweenFingers = new import_Vec.Vec();
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
editor.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
altKey: event.altKey,
|
|
121
|
-
ctrlKey: event.metaKey || event.ctrlKey,
|
|
122
|
-
metaKey: event.metaKey,
|
|
123
|
-
accelKey: (0, import_keyboard.isAccelKey)(event)
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
const updatePinchState = (isSafariTrackpadPinch) => {
|
|
87
|
+
let activeTouches = [];
|
|
88
|
+
function getScaleBounds() {
|
|
89
|
+
const baseZoom = editor.getBaseZoom();
|
|
90
|
+
const { zoomSteps, zoomSpeed } = editor.getCameraOptions();
|
|
91
|
+
const zoomMin = zoomSteps[0] * baseZoom;
|
|
92
|
+
const zoomMax = zoomSteps[zoomSteps.length - 1] * baseZoom;
|
|
93
|
+
return {
|
|
94
|
+
min: zoomMin ** (1 / zoomSpeed),
|
|
95
|
+
max: zoomMax ** (1 / zoomSpeed)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function getScaleFrom() {
|
|
99
|
+
const { zoomSpeed } = editor.getCameraOptions();
|
|
100
|
+
return editor.getZoomLevel() ** (1 / zoomSpeed);
|
|
101
|
+
}
|
|
102
|
+
let scaleOffset = 1;
|
|
103
|
+
let initScaleFrom = 1;
|
|
104
|
+
function updatePinchState(isSafariTrackpadPinch) {
|
|
127
105
|
if (isSafariTrackpadPinch) {
|
|
128
106
|
pinchState = "zooming";
|
|
129
107
|
}
|
|
@@ -148,100 +126,166 @@ function useGestureEvents(ref) {
|
|
|
148
126
|
break;
|
|
149
127
|
}
|
|
150
128
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
129
|
+
}
|
|
130
|
+
function dispatchPinchEvent(name, origin, delta, zoom, event) {
|
|
131
|
+
editor.dispatch({
|
|
132
|
+
type: "pinch",
|
|
133
|
+
name,
|
|
134
|
+
point: { x: origin.x, y: origin.y, z: zoom },
|
|
135
|
+
delta,
|
|
136
|
+
shiftKey: event.shiftKey,
|
|
137
|
+
altKey: event.altKey,
|
|
138
|
+
ctrlKey: event.metaKey || event.ctrlKey,
|
|
139
|
+
metaKey: event.metaKey,
|
|
140
|
+
accelKey: (0, import_keyboard.isAccelKey)(event)
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function getOriginAndDistance(t0, t1) {
|
|
144
|
+
const origin = {
|
|
145
|
+
x: (t0.clientX + t1.clientX) / 2,
|
|
146
|
+
y: (t0.clientY + t1.clientY) / 2
|
|
147
|
+
};
|
|
148
|
+
const distance = Math.hypot(t1.clientX - t0.clientX, t1.clientY - t0.clientY);
|
|
149
|
+
return { origin, distance };
|
|
150
|
+
}
|
|
151
|
+
function onTouchStart(event) {
|
|
156
152
|
if (!(event.target === elm || elm?.contains(event.target))) return;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
activeTouches = Array.from(event.touches);
|
|
154
|
+
if (activeTouches.length === 2) {
|
|
155
|
+
pinchState = "not sure";
|
|
156
|
+
const { origin, distance } = getOriginAndDistance(activeTouches[0], activeTouches[1]);
|
|
157
|
+
prevPointBetweenFingers.x = origin.x;
|
|
158
|
+
prevPointBetweenFingers.y = origin.y;
|
|
159
|
+
initPointBetweenFingers.x = origin.x;
|
|
160
|
+
initPointBetweenFingers.y = origin.y;
|
|
161
|
+
initDistanceBetweenFingers = Math.max(distance, 1);
|
|
162
|
+
currDistanceBetweenFingers = distance;
|
|
163
|
+
initZoom = editor.getZoomLevel();
|
|
164
|
+
initScaleFrom = getScaleFrom();
|
|
165
|
+
scaleOffset = initScaleFrom;
|
|
166
|
+
dispatchPinchEvent("pinch_start", origin, { x: 0, y: 0 }, editor.getZoomLevel(), event);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function onTouchMove(event) {
|
|
170
|
+
activeTouches = Array.from(event.touches);
|
|
171
|
+
if (activeTouches.length < 2) return;
|
|
172
|
+
const { origin, distance } = getOriginAndDistance(activeTouches[0], activeTouches[1]);
|
|
173
|
+
currDistanceBetweenFingers = distance;
|
|
174
|
+
const dx = origin.x - prevPointBetweenFingers.x;
|
|
175
|
+
const dy = origin.y - prevPointBetweenFingers.y;
|
|
176
|
+
prevPointBetweenFingers.x = origin.x;
|
|
177
|
+
prevPointBetweenFingers.y = origin.y;
|
|
178
|
+
updatePinchState(false);
|
|
179
|
+
const bounds = getScaleBounds();
|
|
180
|
+
const rawScale = initScaleFrom * (distance / initDistanceBetweenFingers);
|
|
181
|
+
scaleOffset = Math.min(bounds.max, Math.max(bounds.min, rawScale));
|
|
164
182
|
switch (pinchState) {
|
|
165
183
|
case "zooming": {
|
|
166
|
-
const currZoom =
|
|
167
|
-
|
|
168
|
-
type: "pinch",
|
|
169
|
-
name: "pinch",
|
|
170
|
-
point: { x: origin[0], y: origin[1], z: currZoom },
|
|
171
|
-
delta: { x: dx, y: dy },
|
|
172
|
-
shiftKey: event.shiftKey,
|
|
173
|
-
altKey: event.altKey,
|
|
174
|
-
ctrlKey: event.metaKey || event.ctrlKey,
|
|
175
|
-
metaKey: event.metaKey,
|
|
176
|
-
accelKey: (0, import_keyboard.isAccelKey)(event)
|
|
177
|
-
});
|
|
184
|
+
const currZoom = scaleOffset ** editor.getCameraOptions().zoomSpeed;
|
|
185
|
+
dispatchPinchEvent("pinch", origin, { x: dx, y: dy }, currZoom, event);
|
|
178
186
|
break;
|
|
179
187
|
}
|
|
180
188
|
case "panning": {
|
|
181
|
-
|
|
182
|
-
type: "pinch",
|
|
183
|
-
name: "pinch",
|
|
184
|
-
point: { x: origin[0], y: origin[1], z: initZoom },
|
|
185
|
-
delta: { x: dx, y: dy },
|
|
186
|
-
shiftKey: event.shiftKey,
|
|
187
|
-
altKey: event.altKey,
|
|
188
|
-
ctrlKey: event.metaKey || event.ctrlKey,
|
|
189
|
-
metaKey: event.metaKey,
|
|
190
|
-
accelKey: (0, import_keyboard.isAccelKey)(event)
|
|
191
|
-
});
|
|
189
|
+
dispatchPinchEvent("pinch", origin, { x: dx, y: dy }, initZoom, event);
|
|
192
190
|
break;
|
|
193
191
|
}
|
|
194
192
|
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
193
|
+
}
|
|
194
|
+
function onTouchEnd(event) {
|
|
195
|
+
const wasPinching = activeTouches.length >= 2;
|
|
196
|
+
activeTouches = Array.from(event.touches);
|
|
197
|
+
if (wasPinching && activeTouches.length < 2) {
|
|
198
|
+
const scale = scaleOffset ** editor.getCameraOptions().zoomSpeed;
|
|
199
|
+
const origin = { ...prevPointBetweenFingers };
|
|
200
|
+
pinchState = "not sure";
|
|
201
|
+
editor.timers.requestAnimationFrame(() => {
|
|
202
|
+
dispatchPinchEvent("pinch_end", origin, { x: origin.x, y: origin.y }, scale, event);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
let safariGestureInitialScale = 1;
|
|
207
|
+
function onGestureStart(event) {
|
|
208
|
+
const e = event;
|
|
209
|
+
if (!(e.target === elm || elm?.contains(e.target))) return;
|
|
210
|
+
(0, import_dom.preventDefault)(e);
|
|
211
|
+
e.stopPropagation();
|
|
212
|
+
pinchState = "not sure";
|
|
213
|
+
safariGestureInitialScale = getScaleFrom();
|
|
214
|
+
scaleOffset = safariGestureInitialScale;
|
|
215
|
+
initZoom = editor.getZoomLevel();
|
|
216
|
+
prevPointBetweenFingers.x = e.clientX;
|
|
217
|
+
prevPointBetweenFingers.y = e.clientY;
|
|
218
|
+
initPointBetweenFingers.x = e.clientX;
|
|
219
|
+
initPointBetweenFingers.y = e.clientY;
|
|
220
|
+
initDistanceBetweenFingers = 1;
|
|
221
|
+
currDistanceBetweenFingers = 1;
|
|
222
|
+
dispatchPinchEvent(
|
|
223
|
+
"pinch_start",
|
|
224
|
+
{ x: e.clientX, y: e.clientY },
|
|
225
|
+
{ x: 0, y: 0 },
|
|
226
|
+
editor.getZoomLevel(),
|
|
227
|
+
e
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
function onGestureChange(event) {
|
|
231
|
+
const e = event;
|
|
232
|
+
if (!(e.target === elm || elm?.contains(e.target))) return;
|
|
233
|
+
(0, import_dom.preventDefault)(e);
|
|
234
|
+
e.stopPropagation();
|
|
235
|
+
const dx = e.clientX - prevPointBetweenFingers.x;
|
|
236
|
+
const dy = e.clientY - prevPointBetweenFingers.y;
|
|
237
|
+
prevPointBetweenFingers.x = e.clientX;
|
|
238
|
+
prevPointBetweenFingers.y = e.clientY;
|
|
239
|
+
const bounds = getScaleBounds();
|
|
240
|
+
const rawScale = safariGestureInitialScale * e.scale;
|
|
241
|
+
scaleOffset = Math.min(bounds.max, Math.max(bounds.min, rawScale));
|
|
242
|
+
currDistanceBetweenFingers = e.scale * initDistanceBetweenFingers;
|
|
243
|
+
updatePinchState(true);
|
|
244
|
+
const currZoom = scaleOffset ** editor.getCameraOptions().zoomSpeed;
|
|
245
|
+
dispatchPinchEvent("pinch", { x: e.clientX, y: e.clientY }, { x: dx, y: dy }, currZoom, e);
|
|
246
|
+
}
|
|
247
|
+
function onGestureEnd(event) {
|
|
248
|
+
const e = event;
|
|
249
|
+
if (!(e.target === elm || elm?.contains(e.target))) return;
|
|
250
|
+
(0, import_dom.preventDefault)(e);
|
|
251
|
+
e.stopPropagation();
|
|
252
|
+
const scale = scaleOffset ** editor.getCameraOptions().zoomSpeed;
|
|
202
253
|
pinchState = "not sure";
|
|
203
254
|
editor.timers.requestAnimationFrame(() => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
ctrlKey: event.metaKey || event.ctrlKey,
|
|
212
|
-
metaKey: event.metaKey,
|
|
213
|
-
accelKey: (0, import_keyboard.isAccelKey)(event)
|
|
214
|
-
});
|
|
255
|
+
dispatchPinchEvent(
|
|
256
|
+
"pinch_end",
|
|
257
|
+
{ x: e.clientX, y: e.clientY },
|
|
258
|
+
{ x: e.clientX, y: e.clientY },
|
|
259
|
+
scale,
|
|
260
|
+
e
|
|
261
|
+
);
|
|
215
262
|
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
263
|
+
}
|
|
264
|
+
elm.addEventListener("wheel", onWheel, { passive: false });
|
|
265
|
+
const useGestureEvents2 = !import_environment.tlenv.isIos && "GestureEvent" in window;
|
|
266
|
+
if (useGestureEvents2) {
|
|
267
|
+
elm.addEventListener("gesturestart", onGestureStart);
|
|
268
|
+
elm.addEventListener("gesturechange", onGestureChange);
|
|
269
|
+
elm.addEventListener("gestureend", onGestureEnd);
|
|
270
|
+
} else {
|
|
271
|
+
elm.addEventListener("touchstart", onTouchStart);
|
|
272
|
+
elm.addEventListener("touchmove", onTouchMove);
|
|
273
|
+
elm.addEventListener("touchend", onTouchEnd);
|
|
274
|
+
elm.addEventListener("touchcancel", onTouchEnd);
|
|
275
|
+
}
|
|
276
|
+
return () => {
|
|
277
|
+
elm.removeEventListener("wheel", onWheel);
|
|
278
|
+
if (useGestureEvents2) {
|
|
279
|
+
elm.removeEventListener("gesturestart", onGestureStart);
|
|
280
|
+
elm.removeEventListener("gesturechange", onGestureChange);
|
|
281
|
+
elm.removeEventListener("gestureend", onGestureEnd);
|
|
282
|
+
} else {
|
|
283
|
+
elm.removeEventListener("touchstart", onTouchStart);
|
|
284
|
+
elm.removeEventListener("touchmove", onTouchMove);
|
|
285
|
+
elm.removeEventListener("touchend", onTouchEnd);
|
|
286
|
+
elm.removeEventListener("touchcancel", onTouchEnd);
|
|
287
|
+
}
|
|
222
288
|
};
|
|
223
289
|
}, [editor, ref]);
|
|
224
|
-
useGesture(events, {
|
|
225
|
-
target: ref,
|
|
226
|
-
eventOptions: { passive: false },
|
|
227
|
-
pinch: {
|
|
228
|
-
from: () => {
|
|
229
|
-
const { zoomSpeed } = editor.getCameraOptions();
|
|
230
|
-
const level = editor.getZoomLevel() ** (1 / zoomSpeed);
|
|
231
|
-
return [level, 0];
|
|
232
|
-
},
|
|
233
|
-
// Return the camera z to use when pinch starts
|
|
234
|
-
scaleBounds: () => {
|
|
235
|
-
const baseZoom = editor.getBaseZoom();
|
|
236
|
-
const { zoomSteps, zoomSpeed } = editor.getCameraOptions();
|
|
237
|
-
const zoomMin = zoomSteps[0] * baseZoom;
|
|
238
|
-
const zoomMax = zoomSteps[zoomSteps.length - 1] * baseZoom;
|
|
239
|
-
return {
|
|
240
|
-
max: zoomMax ** (1 / zoomSpeed),
|
|
241
|
-
min: zoomMin ** (1 / zoomSpeed)
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
290
|
}
|
|
247
291
|
//# sourceMappingURL=useGestureEvents.js.map
|