@tldraw/editor 3.16.0-canary.6074088f67bd → 3.16.0-canary.62bc202550a3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist-cjs/index.d.ts +5 -101
  2. package/dist-cjs/index.js +1 -5
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +0 -4
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/editor/Editor.js +3 -99
  7. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  8. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  9. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
  10. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
  11. package/dist-cjs/lib/license/LicenseManager.js +17 -22
  12. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  13. package/dist-cjs/lib/license/LicenseProvider.js +5 -0
  14. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  15. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  16. package/dist-cjs/lib/primitives/Vec.js +0 -4
  17. package/dist-cjs/lib/primitives/Vec.js.map +2 -2
  18. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +26 -18
  19. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  20. package/dist-cjs/lib/primitives/geometry/Group2d.js +3 -0
  21. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  22. package/dist-cjs/lib/utils/reparenting.js +2 -35
  23. package/dist-cjs/lib/utils/reparenting.js.map +3 -3
  24. package/dist-cjs/version.js +3 -3
  25. package/dist-cjs/version.js.map +1 -1
  26. package/dist-esm/index.d.mts +5 -101
  27. package/dist-esm/index.mjs +1 -5
  28. package/dist-esm/index.mjs.map +2 -2
  29. package/dist-esm/lib/TldrawEditor.mjs +0 -4
  30. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  31. package/dist-esm/lib/editor/Editor.mjs +3 -99
  32. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  33. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
  34. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
  35. package/dist-esm/lib/license/LicenseManager.mjs +17 -22
  36. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  37. package/dist-esm/lib/license/LicenseProvider.mjs +5 -0
  38. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  39. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  40. package/dist-esm/lib/primitives/Vec.mjs +0 -4
  41. package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
  42. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +29 -19
  43. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  44. package/dist-esm/lib/primitives/geometry/Group2d.mjs +3 -0
  45. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  46. package/dist-esm/lib/utils/reparenting.mjs +3 -40
  47. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  48. package/dist-esm/version.mjs +3 -3
  49. package/dist-esm/version.mjs.map +1 -1
  50. package/package.json +7 -7
  51. package/src/index.ts +1 -9
  52. package/src/lib/TldrawEditor.tsx +0 -11
  53. package/src/lib/editor/Editor.ts +1 -125
  54. package/src/lib/editor/types/misc-types.ts +0 -6
  55. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
  56. package/src/lib/license/LicenseManager.test.ts +58 -51
  57. package/src/lib/license/LicenseManager.ts +32 -24
  58. package/src/lib/license/LicenseProvider.tsx +8 -0
  59. package/src/lib/license/useLicenseManagerState.ts +2 -2
  60. package/src/lib/primitives/Vec.ts +0 -5
  61. package/src/lib/primitives/geometry/Geometry2d.ts +49 -19
  62. package/src/lib/primitives/geometry/Group2d.ts +4 -0
  63. package/src/lib/utils/reparenting.ts +3 -69
  64. package/src/version.ts +3 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/editor/types/misc-types.ts"],
4
- "sourcesContent": ["import { BoxModel, TLShape } from '@tldraw/tlschema'\nimport { Box } from '../../primitives/Box'\nimport { VecLike } from '../../primitives/Vec'\n\n/** @public */\nexport type RequiredKeys<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>\n/** @public */\nexport type OptionalKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\n\n/** @public */\nexport type TLExportType = 'svg' | 'png' | 'jpeg' | 'webp'\n\n/** @public */\nexport interface TLSvgExportOptions {\n\t/**\n\t * The bounding box, in page coordinates, of the area being exported.\n\t */\n\tbounds?: Box\n\t/**\n\t * The logical scale of the export. This scales the resulting size of the SVG being generated.\n\t */\n\tscale?: number\n\t/**\n\t * When exporting an SVG, the expected pixel ratio of the export will be passed in to\n\t * {@link @tldraw/tlschema#TLAssetStore.resolve} as the `dpr` property, so that assets can be\n\t * downscaled to the appropriate resolution.\n\t *\n\t * When exporting to a bitmap image format, the size of the resulting image will be multiplied\n\t * by this number.\n\t *\n\t * For SVG exports, this defaults to undefined - which means we'll request original-quality\n\t * assets. For bitmap exports, this defaults to 2.\n\t */\n\tpixelRatio?: number\n\n\t/**\n\t * Should the background color be included in the export? If false, the generated image will be\n\t * transparent (if exporting to a format that supports transparency).\n\t */\n\tbackground?: boolean\n\n\t/**\n\t * How much padding to include around the bounds of exports? Defaults to 32px.\n\t */\n\tpadding?: number\n\n\t/**\n\t * Should the export be rendered in dark mode (true) or light mode (false)? Defaults to the\n\t * current instance's dark mode setting.\n\t */\n\tdarkMode?: boolean\n\n\t/**\n\t * The\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio | `preserveAspectRatio` }\n\t * attribute of the SVG element.\n\t */\n\tpreserveAspectRatio?: React.SVGAttributes<SVGSVGElement>['preserveAspectRatio']\n}\n\n/** @public */\nexport interface TLImageExportOptions extends TLSvgExportOptions {\n\t/**\n\t * If the export is being converted to a lossy bitmap format (e.g. jpeg), this is the quality of\n\t * the export. This is a number between 0 and 1.\n\t */\n\tquality?: number\n\n\t/**\n\t * The format to export as. Defaults to 'png'.\n\t */\n\tformat?: TLExportType\n}\n\n/**\n * @public\n * @deprecated use {@link TLImageExportOptions} instead\n */\nexport type TLSvgOptions = TLImageExportOptions\n\n/** @public */\nexport interface TLCameraMoveOptions {\n\t/** Whether to move the camera immediately, rather than on the next tick. */\n\timmediate?: boolean\n\t/** Whether to force the camera to move, even if the user's camera options have locked the camera. */\n\tforce?: boolean\n\t/** Whether to reset the camera to its default position and zoom. */\n\treset?: boolean\n\t/** An (optional) animation to use. */\n\tanimation?: {\n\t\t/** The time the animation should take to arrive at the specified camera coordinates. */\n\t\tduration?: number\n\t\t/** An easing function to apply to the animation's progress from start to end. */\n\t\teasing?(t: number): number\n\t}\n}\n\n/** @public */\nexport interface TLCameraOptions {\n\t/** Whether the camera is locked. */\n\tisLocked: boolean\n\t/** The speed of a scroll wheel / trackpad pan. Default is 1. */\n\tpanSpeed: number\n\t/** The speed of a scroll wheel / trackpad zoom. Default is 1. */\n\tzoomSpeed: number\n\t/** The steps that a user can zoom between with zoom in / zoom out. The first and last value will determine the min and max zoom. */\n\tzoomSteps: number[]\n\t/** Controls whether the wheel pans or zooms.\n\t *\n\t * - `zoom`: The wheel will zoom in and out.\n\t * - `pan`: The wheel will pan the camera.\n\t * - `none`: The wheel will do nothing.\n\t */\n\twheelBehavior: 'zoom' | 'pan' | 'none'\n\t/** The camera constraints. */\n\tconstraints?: TLCameraConstraints\n}\n\n/** @public */\nexport interface TLCameraConstraints {\n\t/** The bounds (in page space) of the constrained space */\n\tbounds: BoxModel\n\t/** The padding inside of the viewport (in screen space) */\n\tpadding: VecLike\n\t/** The origin for placement. Used to position the bounds within the viewport when an axis is fixed or contained and zoom is below the axis fit. */\n\torigin: VecLike\n\t/** The camera's initial zoom, used also when the camera is reset.\n\t *\n\t * - `default`: Sets the initial zoom to 100%.\n\t * - `fit-x`: The x axis will completely fill the viewport bounds.\n\t * - `fit-y`: The y axis will completely fill the viewport bounds.\n\t * - `fit-min`: The smaller axis will completely fill the viewport bounds.\n\t * - `fit-max`: The larger axis will completely fill the viewport bounds.\n\t * - `fit-x-100`: The x axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-y-100`: The y axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-min-100`: The smaller axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-max-100`: The larger axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t */\n\tinitialZoom:\n\t\t| 'fit-min'\n\t\t| 'fit-max'\n\t\t| 'fit-x'\n\t\t| 'fit-y'\n\t\t| 'fit-min-100'\n\t\t| 'fit-max-100'\n\t\t| 'fit-x-100'\n\t\t| 'fit-y-100'\n\t\t| 'default'\n\t/** The camera's base for its zoom steps.\n\t *\n\t * - `default`: Sets the initial zoom to 100%.\n\t * - `fit-x`: The x axis will completely fill the viewport bounds.\n\t * - `fit-y`: The y axis will completely fill the viewport bounds.\n\t * - `fit-min`: The smaller axis will completely fill the viewport bounds.\n\t * - `fit-max`: The larger axis will completely fill the viewport bounds.\n\t * - `fit-x-100`: The x axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-y-100`: The y axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-min-100`: The smaller axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-max-100`: The larger axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t */\n\tbaseZoom:\n\t\t| 'fit-min'\n\t\t| 'fit-max'\n\t\t| 'fit-x'\n\t\t| 'fit-y'\n\t\t| 'fit-min-100'\n\t\t| 'fit-max-100'\n\t\t| 'fit-x-100'\n\t\t| 'fit-y-100'\n\t\t| 'default'\n\t/** The behavior for the constraints for both axes or each axis individually.\n\t *\n\t * - `free`: The bounds are ignored when moving the camera.\n\t * - 'fixed': The bounds will be positioned within the viewport based on the origin\n\t * - `contain`: The 'fixed' behavior will be used when the zoom is below the zoom level at which the bounds would fill the viewport; and when above this zoom, the bounds will use the 'inside' behavior.\n\t * - `inside`: The bounds will stay completely within the viewport.\n\t * - `outside`: The bounds will stay touching the viewport.\n\t */\n\tbehavior:\n\t\t| 'free'\n\t\t| 'fixed'\n\t\t| 'inside'\n\t\t| 'outside'\n\t\t| 'contain'\n\t\t| {\n\t\t\t\tx: 'free' | 'fixed' | 'inside' | 'outside' | 'contain'\n\t\t\t\ty: 'free' | 'fixed' | 'inside' | 'outside' | 'contain'\n\t\t }\n}\n\n/** @public */\nexport interface TLUpdatePointerOptions {\n\t/** Whether to update the pointer immediately, rather than on the next tick. */\n\timmediate?: boolean\n\t/**\n\t * The point, in screen-space, to update the pointer to. Defaults to the position of the last\n\t * pointer event.\n\t */\n\tpoint?: VecLike\n\tpointerId?: number\n\tctrlKey?: boolean\n\taltKey?: boolean\n\tshiftKey?: boolean\n\tmetaKey?: boolean\n\taccelKey?: boolean\n\tisPen?: boolean\n\tbutton?: number\n}\n\n/**\n * Options to {@link Editor.getShapeAtPoint}.\n *\n * @public\n */\nexport interface TLGetShapeAtPointOptions {\n\t/**\n\t * The margin to apply to the shape.\n\t * If a number, it will be applied to both the inside and outside of the shape.\n\t * If an array, the first element will be applied to the inside of the shape, and the second element will be applied to the outside.\n\t *\n\t * @example\n\t * ```ts\n\t * // Get the shape at the center of the screen\n\t * const shape = editor.getShapeAtProps({\n\t * margin: 10,\n\t * })\n\t *\n\t * // Get the shape at the center of the screen with a 10px inner margin and a 5px outer margin\n\t * const shape = editor.getShapeAtProps({\n\t * margin: [10, 5],\n\t * })\n\t * ```\n\t */\n\tmargin?: number | [number, number]\n\t/**\n\t * Whether to register hits inside of shapes (beyond the margin), such as the inside of a solid shape.\n\t */\n\thitInside?: boolean\n\t/**\n\t * Whether to register hits on locked shapes.\n\t */\n\thitLocked?: boolean\n\t/**\n\t * Whether to register hits on labels.\n\t */\n\thitLabels?: boolean\n\t/**\n\t * Whether to only return hits on shapes that are currently being rendered.\n\t * todo: rename this to hitCulled or hitNotRendering\n\t */\n\trenderingOnly?: boolean\n\t/**\n\t * Whether to register hits on the inside of frame shapes.\n\t * todo: rename this to hitInsideFrames\n\t */\n\thitFrameInside?: boolean\n\t/**\n\t * A filter function to apply to the shapes.\n\t */\n\tfilter?(shape: TLShape): boolean\n}\n"],
4
+ "sourcesContent": ["import { BoxModel, TLShape } from '@tldraw/tlschema'\nimport { Box } from '../../primitives/Box'\nimport { VecLike } from '../../primitives/Vec'\n\n/** @public */\nexport type RequiredKeys<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>\n/** @public */\nexport type OptionalKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\n\n/** @public */\nexport type TLExportType = 'svg' | 'png' | 'jpeg' | 'webp'\n\n/** @public */\nexport interface TLSvgExportOptions {\n\t/**\n\t * The bounding box, in page coordinates, of the area being exported.\n\t */\n\tbounds?: Box\n\t/**\n\t * The logical scale of the export. This scales the resulting size of the SVG being generated.\n\t */\n\tscale?: number\n\t/**\n\t * When exporting an SVG, the expected pixel ratio of the export will be passed in to\n\t * {@link @tldraw/tlschema#TLAssetStore.resolve} as the `dpr` property, so that assets can be\n\t * downscaled to the appropriate resolution.\n\t *\n\t * When exporting to a bitmap image format, the size of the resulting image will be multiplied\n\t * by this number.\n\t *\n\t * For SVG exports, this defaults to undefined - which means we'll request original-quality\n\t * assets. For bitmap exports, this defaults to 2.\n\t */\n\tpixelRatio?: number\n\n\t/**\n\t * Should the background color be included in the export? If false, the generated image will be\n\t * transparent (if exporting to a format that supports transparency).\n\t */\n\tbackground?: boolean\n\n\t/**\n\t * How much padding to include around the bounds of exports? Defaults to 32px.\n\t */\n\tpadding?: number\n\n\t/**\n\t * Should the export be rendered in dark mode (true) or light mode (false)? Defaults to the\n\t * current instance's dark mode setting.\n\t */\n\tdarkMode?: boolean\n\n\t/**\n\t * The\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio | `preserveAspectRatio` }\n\t * attribute of the SVG element.\n\t */\n\tpreserveAspectRatio?: React.SVGAttributes<SVGSVGElement>['preserveAspectRatio']\n}\n\n/** @public */\nexport interface TLImageExportOptions extends TLSvgExportOptions {\n\t/**\n\t * If the export is being converted to a lossy bitmap format (e.g. jpeg), this is the quality of\n\t * the export. This is a number between 0 and 1.\n\t */\n\tquality?: number\n\n\t/**\n\t * The format to export as. Defaults to 'png'.\n\t */\n\tformat?: TLExportType\n}\n\n/** @public */\nexport interface TLCameraMoveOptions {\n\t/** Whether to move the camera immediately, rather than on the next tick. */\n\timmediate?: boolean\n\t/** Whether to force the camera to move, even if the user's camera options have locked the camera. */\n\tforce?: boolean\n\t/** Whether to reset the camera to its default position and zoom. */\n\treset?: boolean\n\t/** An (optional) animation to use. */\n\tanimation?: {\n\t\t/** The time the animation should take to arrive at the specified camera coordinates. */\n\t\tduration?: number\n\t\t/** An easing function to apply to the animation's progress from start to end. */\n\t\teasing?(t: number): number\n\t}\n}\n\n/** @public */\nexport interface TLCameraOptions {\n\t/** Whether the camera is locked. */\n\tisLocked: boolean\n\t/** The speed of a scroll wheel / trackpad pan. Default is 1. */\n\tpanSpeed: number\n\t/** The speed of a scroll wheel / trackpad zoom. Default is 1. */\n\tzoomSpeed: number\n\t/** The steps that a user can zoom between with zoom in / zoom out. The first and last value will determine the min and max zoom. */\n\tzoomSteps: number[]\n\t/** Controls whether the wheel pans or zooms.\n\t *\n\t * - `zoom`: The wheel will zoom in and out.\n\t * - `pan`: The wheel will pan the camera.\n\t * - `none`: The wheel will do nothing.\n\t */\n\twheelBehavior: 'zoom' | 'pan' | 'none'\n\t/** The camera constraints. */\n\tconstraints?: TLCameraConstraints\n}\n\n/** @public */\nexport interface TLCameraConstraints {\n\t/** The bounds (in page space) of the constrained space */\n\tbounds: BoxModel\n\t/** The padding inside of the viewport (in screen space) */\n\tpadding: VecLike\n\t/** The origin for placement. Used to position the bounds within the viewport when an axis is fixed or contained and zoom is below the axis fit. */\n\torigin: VecLike\n\t/** The camera's initial zoom, used also when the camera is reset.\n\t *\n\t * - `default`: Sets the initial zoom to 100%.\n\t * - `fit-x`: The x axis will completely fill the viewport bounds.\n\t * - `fit-y`: The y axis will completely fill the viewport bounds.\n\t * - `fit-min`: The smaller axis will completely fill the viewport bounds.\n\t * - `fit-max`: The larger axis will completely fill the viewport bounds.\n\t * - `fit-x-100`: The x axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-y-100`: The y axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-min-100`: The smaller axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-max-100`: The larger axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t */\n\tinitialZoom:\n\t\t| 'fit-min'\n\t\t| 'fit-max'\n\t\t| 'fit-x'\n\t\t| 'fit-y'\n\t\t| 'fit-min-100'\n\t\t| 'fit-max-100'\n\t\t| 'fit-x-100'\n\t\t| 'fit-y-100'\n\t\t| 'default'\n\t/** The camera's base for its zoom steps.\n\t *\n\t * - `default`: Sets the initial zoom to 100%.\n\t * - `fit-x`: The x axis will completely fill the viewport bounds.\n\t * - `fit-y`: The y axis will completely fill the viewport bounds.\n\t * - `fit-min`: The smaller axis will completely fill the viewport bounds.\n\t * - `fit-max`: The larger axis will completely fill the viewport bounds.\n\t * - `fit-x-100`: The x axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-y-100`: The y axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-min-100`: The smaller axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t * - `fit-max-100`: The larger axis will completely fill the viewport bounds, or 100% zoom, whichever is smaller.\n\t */\n\tbaseZoom:\n\t\t| 'fit-min'\n\t\t| 'fit-max'\n\t\t| 'fit-x'\n\t\t| 'fit-y'\n\t\t| 'fit-min-100'\n\t\t| 'fit-max-100'\n\t\t| 'fit-x-100'\n\t\t| 'fit-y-100'\n\t\t| 'default'\n\t/** The behavior for the constraints for both axes or each axis individually.\n\t *\n\t * - `free`: The bounds are ignored when moving the camera.\n\t * - 'fixed': The bounds will be positioned within the viewport based on the origin\n\t * - `contain`: The 'fixed' behavior will be used when the zoom is below the zoom level at which the bounds would fill the viewport; and when above this zoom, the bounds will use the 'inside' behavior.\n\t * - `inside`: The bounds will stay completely within the viewport.\n\t * - `outside`: The bounds will stay touching the viewport.\n\t */\n\tbehavior:\n\t\t| 'free'\n\t\t| 'fixed'\n\t\t| 'inside'\n\t\t| 'outside'\n\t\t| 'contain'\n\t\t| {\n\t\t\t\tx: 'free' | 'fixed' | 'inside' | 'outside' | 'contain'\n\t\t\t\ty: 'free' | 'fixed' | 'inside' | 'outside' | 'contain'\n\t\t }\n}\n\n/** @public */\nexport interface TLUpdatePointerOptions {\n\t/** Whether to update the pointer immediately, rather than on the next tick. */\n\timmediate?: boolean\n\t/**\n\t * The point, in screen-space, to update the pointer to. Defaults to the position of the last\n\t * pointer event.\n\t */\n\tpoint?: VecLike\n\tpointerId?: number\n\tctrlKey?: boolean\n\taltKey?: boolean\n\tshiftKey?: boolean\n\tmetaKey?: boolean\n\taccelKey?: boolean\n\tisPen?: boolean\n\tbutton?: number\n}\n\n/**\n * Options to {@link Editor.getShapeAtPoint}.\n *\n * @public\n */\nexport interface TLGetShapeAtPointOptions {\n\t/**\n\t * The margin to apply to the shape.\n\t * If a number, it will be applied to both the inside and outside of the shape.\n\t * If an array, the first element will be applied to the inside of the shape, and the second element will be applied to the outside.\n\t *\n\t * @example\n\t * ```ts\n\t * // Get the shape at the center of the screen\n\t * const shape = editor.getShapeAtProps({\n\t * margin: 10,\n\t * })\n\t *\n\t * // Get the shape at the center of the screen with a 10px inner margin and a 5px outer margin\n\t * const shape = editor.getShapeAtProps({\n\t * margin: [10, 5],\n\t * })\n\t * ```\n\t */\n\tmargin?: number | [number, number]\n\t/**\n\t * Whether to register hits inside of shapes (beyond the margin), such as the inside of a solid shape.\n\t */\n\thitInside?: boolean\n\t/**\n\t * Whether to register hits on locked shapes.\n\t */\n\thitLocked?: boolean\n\t/**\n\t * Whether to register hits on labels.\n\t */\n\thitLabels?: boolean\n\t/**\n\t * Whether to only return hits on shapes that are currently being rendered.\n\t * todo: rename this to hitCulled or hitNotRendering\n\t */\n\trenderingOnly?: boolean\n\t/**\n\t * Whether to register hits on the inside of frame shapes.\n\t * todo: rename this to hitInsideFrames\n\t */\n\thitFrameInside?: boolean\n\t/**\n\t * A filter function to apply to the shapes.\n\t */\n\tfilter?(shape: TLShape): boolean\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -24,11 +24,14 @@ module.exports = __toCommonJS(usePassThroughMouseOverEvents_exports);
24
24
  var import_react = require("react");
25
25
  var import_dom = require("../utils/dom");
26
26
  var import_useContainer = require("./useContainer");
27
+ var import_useEditor = require("./useEditor");
27
28
  function usePassThroughMouseOverEvents(ref) {
28
29
  if (!ref) throw Error("usePassThroughWheelEvents must be passed a ref");
29
30
  const container = (0, import_useContainer.useContainer)();
31
+ const editor = (0, import_useEditor.useMaybeEditor)();
30
32
  (0, import_react.useEffect)(() => {
31
33
  function onMouseOver(e) {
34
+ if (!editor?.getInstanceState().isFocused) return;
32
35
  if (e.isSpecialRedispatchedEvent) return;
33
36
  (0, import_dom.preventDefault)(e);
34
37
  const cvs = container.querySelector(".tl-canvas");
@@ -43,6 +46,6 @@ function usePassThroughMouseOverEvents(ref) {
43
46
  return () => {
44
47
  elm.removeEventListener("mouseover", onMouseOver);
45
48
  };
46
- }, [container, ref]);
49
+ }, [container, editor, ref]);
47
50
  }
48
51
  //# sourceMappingURL=usePassThroughMouseOverEvents.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/hooks/usePassThroughMouseOverEvents.ts"],
4
- "sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\n\n/** @public */\nexport function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\n\tuseEffect(() => {\n\t\tfunction onMouseOver(e: MouseEvent) {\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\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 PointerEvent(e.type, 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('mouseover', onMouseOver, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('mouseover', onMouseOver)\n\t\t}\n\t}, [container, ref])\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,iBAA+B;AAC/B,0BAA6B;AAGtB,SAAS,8BAA8B,KAA6B;AAC1E,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,gBAAY,kCAAa;AAE/B,8BAAU,MAAM;AACf,aAAS,YAAY,GAAe;AACnC,UAAK,EAAU,2BAA4B;AAC3C,qCAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,aAAa,EAAE,MAAM,CAAQ;AACjD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,aAAa,aAAa,EAAE,SAAS,MAAM,CAAC;AACjE,WAAO,MAAM;AACZ,UAAI,oBAAoB,aAAa,WAAW;AAAA,IACjD;AAAA,EACD,GAAG,CAAC,WAAW,GAAG,CAAC;AACpB;",
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 usePassThroughMouseOverEvents(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 onMouseOver(e: MouseEvent) {\n\t\t\tif (!editor?.getInstanceState().isFocused) return\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\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 PointerEvent(e.type, 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('mouseover', onMouseOver, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('mouseover', onMouseOver)\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,8BAA8B,KAA6B;AAC1E,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,gBAAY,kCAAa;AAC/B,QAAM,aAAS,iCAAe;AAE9B,8BAAU,MAAM;AACf,aAAS,YAAY,GAAe;AACnC,UAAI,CAAC,QAAQ,iBAAiB,EAAE,UAAW;AAC3C,UAAK,EAAU,2BAA4B;AAC3C,qCAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,aAAa,EAAE,MAAM,CAAQ;AACjD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,aAAa,aAAa,EAAE,SAAS,MAAM,CAAC;AACjE,WAAO,MAAM;AACZ,UAAI,oBAAoB,aAAa,WAAW;AAAA,IACjD;AAAA,EACD,GAAG,CAAC,WAAW,QAAQ,GAAG,CAAC;AAC5B;",
6
6
  "names": []
7
7
  }
@@ -21,7 +21,7 @@ __export(LicenseManager_exports, {
21
21
  FLAGS: () => FLAGS,
22
22
  LicenseManager: () => LicenseManager,
23
23
  PROPERTIES: () => PROPERTIES,
24
- isEditorUnlicensed: () => isEditorUnlicensed
24
+ getLicenseState: () => getLicenseState
25
25
  });
26
26
  module.exports = __toCommonJS(LicenseManager_exports);
27
27
  var import_state = require("@tldraw/state");
@@ -51,10 +51,7 @@ class LicenseManager {
51
51
  isDevelopment;
52
52
  isTest;
53
53
  isCryptoAvailable;
54
- state = (0, import_state.atom)(
55
- "license state",
56
- "pending"
57
- );
54
+ state = (0, import_state.atom)("license state", "pending");
58
55
  verbose = true;
59
56
  constructor(licenseKey, testPublicKey, testEnvironment) {
60
57
  this.isTest = process.env.NODE_ENV === "test";
@@ -62,17 +59,14 @@ class LicenseManager {
62
59
  this.publicKey = testPublicKey || this.publicKey;
63
60
  this.isCryptoAvailable = !!crypto.subtle;
64
61
  this.getLicenseFromKey(licenseKey).then((result) => {
65
- const isUnlicensed = isEditorUnlicensed(result);
66
- if (!this.isDevelopment && isUnlicensed) {
62
+ const licenseState = getLicenseState(result);
63
+ if (!this.isDevelopment && licenseState === "unlicensed") {
67
64
  (0, import_utils.fetch)(WATERMARK_TRACK_SRC);
68
65
  }
69
- if (isUnlicensed) {
70
- this.state.set("unlicensed");
71
- } else if (result.isLicensedWithWatermark) {
72
- this.state.set("licensed-with-watermark");
73
- } else {
74
- this.state.set("licensed");
75
- }
66
+ this.state.set(licenseState);
67
+ }).catch((error) => {
68
+ console.error("License validation failed:", error);
69
+ this.state.set("unlicensed");
76
70
  });
77
71
  }
78
72
  getIsDevelopment(testEnvironment) {
@@ -270,15 +264,16 @@ class LicenseManager {
270
264
  }
271
265
  static className = "tl-watermark_SEE-LICENSE";
272
266
  }
273
- function isEditorUnlicensed(result) {
274
- if (!result.isLicenseParseable) return true;
275
- if (!result.isDomainValid && !result.isDevelopment) return true;
267
+ function getLicenseState(result) {
268
+ if (!result.isLicenseParseable) return "unlicensed";
269
+ if (!result.isDomainValid && !result.isDevelopment) return "unlicensed";
276
270
  if (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {
277
- if (result.isInternalLicense) {
278
- throw new Error("License: Internal license expired.");
279
- }
280
- return true;
271
+ const internalExpired = result.isInternalLicense && result.isDomainValid;
272
+ return internalExpired ? "internal-expired" : "unlicensed";
273
+ }
274
+ if (result.isLicensedWithWatermark) {
275
+ return "licensed-with-watermark";
281
276
  }
282
- return false;
277
+ return "licensed";
283
278
  }
284
279
  //# sourceMappingURL=LicenseManager.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/license/LicenseManager.ts"],
4
- "sourcesContent": ["import { atom } from '@tldraw/state'\nimport { fetch } from '@tldraw/utils'\nimport { publishDates } from '../../version'\nimport { getDefaultCdnBaseUrl } from '../utils/assets'\nimport { importPublicKey, str2ab } from '../utils/licensing'\n\nconst GRACE_PERIOD_DAYS = 5\n\nexport const FLAGS = {\n\tANNUAL_LICENSE: 0x1,\n\tPERPETUAL_LICENSE: 0x2,\n\tINTERNAL_LICENSE: 0x4,\n\tWITH_WATERMARK: 0x8,\n}\nconst HIGHEST_FLAG = Math.max(...Object.values(FLAGS))\n\nexport const PROPERTIES = {\n\tID: 0,\n\tHOSTS: 1,\n\tFLAGS: 2,\n\tEXPIRY_DATE: 3,\n}\nconst NUMBER_OF_KNOWN_PROPERTIES = Object.keys(PROPERTIES).length\n\nconst LICENSE_EMAIL = 'sales@tldraw.com'\n\nconst WATERMARK_TRACK_SRC = `${getDefaultCdnBaseUrl()}/watermarks/watermark-track.svg`\n\n/** @internal */\nexport interface LicenseInfo {\n\tid: string\n\thosts: string[]\n\tflags: number\n\texpiryDate: string\n}\n/** @internal */\nexport type InvalidLicenseReason =\n\t| 'invalid-license-key'\n\t| 'no-key-provided'\n\t| 'has-key-development-mode'\n\n/** @internal */\nexport type LicenseFromKeyResult = InvalidLicenseKeyResult | ValidLicenseKeyResult\n\n/** @internal */\nexport interface InvalidLicenseKeyResult {\n\tisLicenseParseable: false\n\treason: InvalidLicenseReason\n}\n\n/** @internal */\nexport interface ValidLicenseKeyResult {\n\tisLicenseParseable: true\n\tlicense: LicenseInfo\n\tisDevelopment: boolean\n\tisDomainValid: boolean\n\texpiryDate: Date\n\tisAnnualLicense: boolean\n\tisAnnualLicenseExpired: boolean\n\tisPerpetualLicense: boolean\n\tisPerpetualLicenseExpired: boolean\n\tisInternalLicense: boolean\n\tisLicensedWithWatermark: boolean\n}\n\n/** @internal */\nexport type TestEnvironment = 'development' | 'production'\n\n/** @internal */\nexport class LicenseManager {\n\tprivate publicKey =\n\t\t'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ'\n\tpublic isDevelopment: boolean\n\tpublic isTest: boolean\n\tpublic isCryptoAvailable: boolean\n\tstate = atom<'pending' | 'licensed' | 'licensed-with-watermark' | 'unlicensed'>(\n\t\t'license state',\n\t\t'pending'\n\t)\n\tpublic verbose = true\n\n\tconstructor(\n\t\tlicenseKey: string | undefined,\n\t\ttestPublicKey?: string,\n\t\ttestEnvironment?: TestEnvironment\n\t) {\n\t\tthis.isTest = process.env.NODE_ENV === 'test'\n\t\tthis.isDevelopment = this.getIsDevelopment(testEnvironment)\n\t\tthis.publicKey = testPublicKey || this.publicKey\n\t\tthis.isCryptoAvailable = !!crypto.subtle\n\n\t\tthis.getLicenseFromKey(licenseKey).then((result) => {\n\t\t\tconst isUnlicensed = isEditorUnlicensed(result)\n\n\t\t\tif (!this.isDevelopment && isUnlicensed) {\n\t\t\t\tfetch(WATERMARK_TRACK_SRC)\n\t\t\t}\n\n\t\t\tif (isUnlicensed) {\n\t\t\t\tthis.state.set('unlicensed')\n\t\t\t} else if ((result as ValidLicenseKeyResult).isLicensedWithWatermark) {\n\t\t\t\tthis.state.set('licensed-with-watermark')\n\t\t\t} else {\n\t\t\t\tthis.state.set('licensed')\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate getIsDevelopment(testEnvironment?: TestEnvironment) {\n\t\tif (testEnvironment === 'development') return true\n\t\tif (testEnvironment === 'production') return false\n\n\t\t// If we are using https on a non-localhost domain we assume it's a production env and a development one otherwise\n\t\treturn (\n\t\t\t!['https:', 'vscode-webview:'].includes(window.location.protocol) ||\n\t\t\twindow.location.hostname === 'localhost'\n\t\t)\n\t}\n\n\tprivate async extractLicenseKey(licenseKey: string): Promise<LicenseInfo> {\n\t\tconst [data, signature] = licenseKey.split('.')\n\t\tconst [prefix, encodedData] = data.split('/')\n\n\t\tif (!prefix.startsWith('tldraw-')) {\n\t\t\tthrow new Error(`Unsupported prefix '${prefix}'`)\n\t\t}\n\n\t\tconst publicCryptoKey = await importPublicKey(this.publicKey)\n\n\t\tlet isVerified\n\t\ttry {\n\t\t\tisVerified = await crypto.subtle.verify(\n\t\t\t\t{\n\t\t\t\t\tname: 'ECDSA',\n\t\t\t\t\thash: { name: 'SHA-256' },\n\t\t\t\t},\n\t\t\t\tpublicCryptoKey,\n\t\t\t\tnew Uint8Array(str2ab(atob(signature))),\n\t\t\t\tnew Uint8Array(str2ab(atob(encodedData)))\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tthrow new Error('Could not perform signature validation')\n\t\t}\n\n\t\tif (!isVerified) {\n\t\t\tthrow new Error('Invalid signature')\n\t\t}\n\n\t\tlet decodedData: any\n\t\ttry {\n\t\t\tdecodedData = JSON.parse(atob(encodedData))\n\t\t} catch {\n\t\t\tthrow new Error('Could not parse object')\n\t\t}\n\t\tif (decodedData.length > NUMBER_OF_KNOWN_PROPERTIES) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'License key contains some unknown properties.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\n\t\treturn {\n\t\t\tid: decodedData[PROPERTIES.ID],\n\t\t\thosts: decodedData[PROPERTIES.HOSTS],\n\t\t\tflags: decodedData[PROPERTIES.FLAGS],\n\t\t\texpiryDate: decodedData[PROPERTIES.EXPIRY_DATE],\n\t\t}\n\t}\n\n\tasync getLicenseFromKey(licenseKey?: string): Promise<LicenseFromKeyResult> {\n\t\tif (!licenseKey) {\n\t\t\tif (!this.isDevelopment) {\n\t\t\t\tthis.outputNoLicenseKeyProvided()\n\t\t\t}\n\n\t\t\treturn { isLicenseParseable: false, reason: 'no-key-provided' }\n\t\t}\n\n\t\tif (this.isDevelopment && !this.isCryptoAvailable) {\n\t\t\tif (this.verbose) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t'tldraw: you seem to be in a development environment that does not support crypto. License not verified.'\n\t\t\t\t)\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log('You should check that this works in production separately.')\n\t\t\t}\n\t\t\t// We can't parse the license if we are in development mode since crypto\n\t\t\t// is not available on http\n\t\t\treturn { isLicenseParseable: false, reason: 'has-key-development-mode' }\n\t\t}\n\n\t\t// Borrowed idea from AG Grid:\n\t\t// Copying from various sources (like PDFs) can include zero-width characters.\n\t\t// This helps makes sure the key validation doesn't fail.\n\t\tlet cleanedLicenseKey = licenseKey.replace(/[\\u200B-\\u200D\\uFEFF]/g, '')\n\t\tcleanedLicenseKey = cleanedLicenseKey.replace(/\\r?\\n|\\r/g, '')\n\n\t\ttry {\n\t\t\tconst licenseInfo = await this.extractLicenseKey(cleanedLicenseKey)\n\t\t\tconst expiryDate = new Date(licenseInfo.expiryDate)\n\t\t\tconst isAnnualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.ANNUAL_LICENSE)\n\t\t\tconst isPerpetualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.PERPETUAL_LICENSE)\n\n\t\t\tconst result: ValidLicenseKeyResult = {\n\t\t\t\tlicense: licenseInfo,\n\t\t\t\tisLicenseParseable: true,\n\t\t\t\tisDevelopment: this.isDevelopment,\n\t\t\t\tisDomainValid: this.isDomainValid(licenseInfo),\n\t\t\t\texpiryDate,\n\t\t\t\tisAnnualLicense,\n\t\t\t\tisAnnualLicenseExpired: isAnnualLicense && this.isAnnualLicenseExpired(expiryDate),\n\t\t\t\tisPerpetualLicense,\n\t\t\t\tisPerpetualLicenseExpired: isPerpetualLicense && this.isPerpetualLicenseExpired(expiryDate),\n\t\t\t\tisInternalLicense: this.isFlagEnabled(licenseInfo.flags, FLAGS.INTERNAL_LICENSE),\n\t\t\t\tisLicensedWithWatermark: this.isFlagEnabled(licenseInfo.flags, FLAGS.WITH_WATERMARK),\n\t\t\t}\n\t\t\tthis.outputLicenseInfoIfNeeded(result)\n\n\t\t\treturn result\n\t\t} catch (e: any) {\n\t\t\tthis.outputInvalidLicenseKey(e.message)\n\t\t\t// If the license can't be parsed, it's invalid\n\t\t\treturn { isLicenseParseable: false, reason: 'invalid-license-key' }\n\t\t}\n\t}\n\n\tprivate isDomainValid(licenseInfo: LicenseInfo) {\n\t\tconst currentHostname = window.location.hostname.toLowerCase()\n\n\t\treturn licenseInfo.hosts.some((host) => {\n\t\t\tconst normalizedHost = host.toLowerCase().trim()\n\n\t\t\t// Allow the domain if listed and www variations, 'example.com' allows 'example.com' and 'www.example.com'\n\t\t\tif (\n\t\t\t\tnormalizedHost === currentHostname ||\n\t\t\t\t`www.${normalizedHost}` === currentHostname ||\n\t\t\t\tnormalizedHost === `www.${currentHostname}`\n\t\t\t) {\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// If host is '*', we allow all domains.\n\t\t\tif (host === '*') {\n\t\t\t\t// All domains allowed.\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// Glob testing, we only support '*.somedomain.com' right now.\n\t\t\tif (host.includes('*')) {\n\t\t\t\tconst globToRegex = new RegExp(host.replace(/\\*/g, '.*?'))\n\t\t\t\treturn globToRegex.test(currentHostname) || globToRegex.test(`www.${currentHostname}`)\n\t\t\t}\n\n\t\t\t// VSCode support\n\t\t\tif (window.location.protocol === 'vscode-webview:') {\n\t\t\t\tconst currentUrl = new URL(window.location.href)\n\t\t\t\tconst extensionId = currentUrl.searchParams.get('extensionId')\n\t\t\t\tif (normalizedHost === extensionId) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false\n\t\t})\n\t}\n\n\tprivate getExpirationDateWithoutGracePeriod(expiryDate: Date) {\n\t\treturn new Date(expiryDate.getFullYear(), expiryDate.getMonth(), expiryDate.getDate())\n\t}\n\n\tprivate getExpirationDateWithGracePeriod(expiryDate: Date) {\n\t\treturn new Date(\n\t\t\texpiryDate.getFullYear(),\n\t\t\texpiryDate.getMonth(),\n\t\t\texpiryDate.getDate() + GRACE_PERIOD_DAYS + 1 // Add 1 day to include the expiration day\n\t\t)\n\t}\n\n\tprivate isAnnualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst isExpired = new Date() >= expiration\n\t\t// If it is not expired yet (including the grace period), but after the expiry date we warn the users\n\t\tif (!isExpired && new Date() >= this.getExpirationDateWithoutGracePeriod(expiryDate)) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'tldraw license is about to expire, you are in a grace period.',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} if you would like to renew your license.`,\n\t\t\t])\n\t\t}\n\t\treturn isExpired\n\t}\n\n\tprivate isPerpetualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst dates = {\n\t\t\tmajor: new Date(publishDates.major),\n\t\t\tminor: new Date(publishDates.minor),\n\t\t}\n\t\t// We allow patch releases, but the major and minor releases should be within the expiration date\n\t\treturn dates.major >= expiration || dates.minor >= expiration\n\t}\n\n\tprivate isFlagEnabled(flags: number, flag: number) {\n\t\treturn (flags & flag) === flag\n\t}\n\n\tprivate outputNoLicenseKeyProvided() {\n\t\t// Noop, we don't need to show this message.\n\t\t// this.outputMessages([\n\t\t// \t'No tldraw license key provided!',\n\t\t// \t`Please reach out to ${LICENSE_EMAIL} if you would like to license tldraw or if you'd like a trial.`,\n\t\t// ])\n\t}\n\n\tprivate outputInvalidLicenseKey(msg: string) {\n\t\tthis.outputMessages(['Invalid tldraw license key', `Reason: ${msg}`])\n\t}\n\n\tprivate outputLicenseInfoIfNeeded(result: ValidLicenseKeyResult) {\n\t\tif (result.isAnnualLicenseExpired) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'Your tldraw license has expired!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to renew.`,\n\t\t\t])\n\t\t}\n\n\t\tif (!result.isDomainValid && !result.isDevelopment) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'This tldraw license key is not valid for this domain!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} if you would like to use tldraw on other domains.`,\n\t\t\t])\n\t\t}\n\t\t// If we added a new flag it will be twice the value of the currently highest flag.\n\t\t// And if all the current flags are on we would get the `HIGHEST_FLAG * 2 - 1`, so anything higher than that means there are new flags.\n\t\tif (result.license.flags >= HIGHEST_FLAG * 2) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'This tldraw license contains some unknown flags.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\t}\n\n\tprivate outputMessages(messages: string[]) {\n\t\tif (this.isTest) return\n\t\tif (this.verbose) {\n\t\t\tthis.outputDelimiter()\n\t\t\tfor (const message of messages) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t`%c${message}`,\n\t\t\t\t\t`color: white; background: crimson; padding: 2px; border-radius: 3px;`\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis.outputDelimiter()\n\t\t}\n\t}\n\n\tprivate outputDelimiter() {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.log(\n\t\t\t'%c-------------------------------------------------------------------',\n\t\t\t`color: white; background: crimson; padding: 2px; border-radius: 3px;`\n\t\t)\n\t}\n\n\tstatic className = 'tl-watermark_SEE-LICENSE'\n}\n\nexport function isEditorUnlicensed(result: LicenseFromKeyResult) {\n\tif (!result.isLicenseParseable) return true\n\tif (!result.isDomainValid && !result.isDevelopment) return true\n\tif (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {\n\t\tif (result.isInternalLicense) {\n\t\t\tthrow new Error('License: Internal license expired.')\n\t\t}\n\t\treturn true\n\t}\n\n\treturn false\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqB;AACrB,mBAAsB;AACtB,qBAA6B;AAC7B,oBAAqC;AACrC,uBAAwC;AAExC,MAAM,oBAAoB;AAEnB,MAAM,QAAQ;AAAA,EACpB,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,gBAAgB;AACjB;AACA,MAAM,eAAe,KAAK,IAAI,GAAG,OAAO,OAAO,KAAK,CAAC;AAE9C,MAAM,aAAa;AAAA,EACzB,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,OAAO;AAAA,EACP,aAAa;AACd;AACA,MAAM,6B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port { publishDates } from '../../version'\nimport { getDefaultCdnBaseUrl } from '../utils/assets'\nimport { importPublicKey, str2ab } from '../utils/licensing'\n\nconst GRACE_PERIOD_DAYS = 5\n\nexport const FLAGS = {\n\tANNUAL_LICENSE: 0x1,\n\tPERPETUAL_LICENSE: 0x2,\n\tINTERNAL_LICENSE: 0x4,\n\tWITH_WATERMARK: 0x8,\n}\nconst HIGHEST_FLAG = Math.max(...Object.values(FLAGS))\n\nexport const PROPERTIES = {\n\tID: 0,\n\tHOSTS: 1,\n\tFLAGS: 2,\n\tEXPIRY_DATE: 3,\n}\nconst NUMBER_OF_KNOWN_PROPERTIES = Object.keys(PROPERTIES).length\n\nconst LICENSE_EMAIL = 'sales@tldraw.com'\n\nconst WATERMARK_TRACK_SRC = `${getDefaultCdnBaseUrl()}/watermarks/watermark-track.svg`\n\n/** @internal */\nexport interface LicenseInfo {\n\tid: string\n\thosts: string[]\n\tflags: number\n\texpiryDate: string\n}\n\n/** @internal */\nexport type LicenseState =\n\t| 'pending'\n\t| 'licensed'\n\t| 'licensed-with-watermark'\n\t| 'unlicensed'\n\t| 'internal-expired'\n/** @internal */\nexport type InvalidLicenseReason =\n\t| 'invalid-license-key'\n\t| 'no-key-provided'\n\t| 'has-key-development-mode'\n\n/** @internal */\nexport type LicenseFromKeyResult = InvalidLicenseKeyResult | ValidLicenseKeyResult\n\n/** @internal */\nexport interface InvalidLicenseKeyResult {\n\tisLicenseParseable: false\n\treason: InvalidLicenseReason\n}\n\n/** @internal */\nexport interface ValidLicenseKeyResult {\n\tisLicenseParseable: true\n\tlicense: LicenseInfo\n\tisDevelopment: boolean\n\tisDomainValid: boolean\n\texpiryDate: Date\n\tisAnnualLicense: boolean\n\tisAnnualLicenseExpired: boolean\n\tisPerpetualLicense: boolean\n\tisPerpetualLicenseExpired: boolean\n\tisInternalLicense: boolean\n\tisLicensedWithWatermark: boolean\n}\n\n/** @internal */\nexport type TestEnvironment = 'development' | 'production'\n\n/** @internal */\nexport class LicenseManager {\n\tprivate publicKey =\n\t\t'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ'\n\tpublic isDevelopment: boolean\n\tpublic isTest: boolean\n\tpublic isCryptoAvailable: boolean\n\tstate = atom<LicenseState>('license state', 'pending')\n\tpublic verbose = true\n\n\tconstructor(\n\t\tlicenseKey: string | undefined,\n\t\ttestPublicKey?: string,\n\t\ttestEnvironment?: TestEnvironment\n\t) {\n\t\tthis.isTest = process.env.NODE_ENV === 'test'\n\t\tthis.isDevelopment = this.getIsDevelopment(testEnvironment)\n\t\tthis.publicKey = testPublicKey || this.publicKey\n\t\tthis.isCryptoAvailable = !!crypto.subtle\n\n\t\tthis.getLicenseFromKey(licenseKey)\n\t\t\t.then((result) => {\n\t\t\t\tconst licenseState = getLicenseState(result)\n\n\t\t\t\tif (!this.isDevelopment && licenseState === 'unlicensed') {\n\t\t\t\t\tfetch(WATERMARK_TRACK_SRC)\n\t\t\t\t}\n\n\t\t\t\tthis.state.set(licenseState)\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error('License validation failed:', error)\n\t\t\t\tthis.state.set('unlicensed')\n\t\t\t})\n\t}\n\n\tprivate getIsDevelopment(testEnvironment?: TestEnvironment) {\n\t\tif (testEnvironment === 'development') return true\n\t\tif (testEnvironment === 'production') return false\n\n\t\t// If we are using https on a non-localhost domain we assume it's a production env and a development one otherwise\n\t\treturn (\n\t\t\t!['https:', 'vscode-webview:'].includes(window.location.protocol) ||\n\t\t\twindow.location.hostname === 'localhost'\n\t\t)\n\t}\n\n\tprivate async extractLicenseKey(licenseKey: string): Promise<LicenseInfo> {\n\t\tconst [data, signature] = licenseKey.split('.')\n\t\tconst [prefix, encodedData] = data.split('/')\n\n\t\tif (!prefix.startsWith('tldraw-')) {\n\t\t\tthrow new Error(`Unsupported prefix '${prefix}'`)\n\t\t}\n\n\t\tconst publicCryptoKey = await importPublicKey(this.publicKey)\n\n\t\tlet isVerified\n\t\ttry {\n\t\t\tisVerified = await crypto.subtle.verify(\n\t\t\t\t{\n\t\t\t\t\tname: 'ECDSA',\n\t\t\t\t\thash: { name: 'SHA-256' },\n\t\t\t\t},\n\t\t\t\tpublicCryptoKey,\n\t\t\t\tnew Uint8Array(str2ab(atob(signature))),\n\t\t\t\tnew Uint8Array(str2ab(atob(encodedData)))\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tthrow new Error('Could not perform signature validation')\n\t\t}\n\n\t\tif (!isVerified) {\n\t\t\tthrow new Error('Invalid signature')\n\t\t}\n\n\t\tlet decodedData: any\n\t\ttry {\n\t\t\tdecodedData = JSON.parse(atob(encodedData))\n\t\t} catch {\n\t\t\tthrow new Error('Could not parse object')\n\t\t}\n\t\tif (decodedData.length > NUMBER_OF_KNOWN_PROPERTIES) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'License key contains some unknown properties.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\n\t\treturn {\n\t\t\tid: decodedData[PROPERTIES.ID],\n\t\t\thosts: decodedData[PROPERTIES.HOSTS],\n\t\t\tflags: decodedData[PROPERTIES.FLAGS],\n\t\t\texpiryDate: decodedData[PROPERTIES.EXPIRY_DATE],\n\t\t}\n\t}\n\n\tasync getLicenseFromKey(licenseKey?: string): Promise<LicenseFromKeyResult> {\n\t\tif (!licenseKey) {\n\t\t\tif (!this.isDevelopment) {\n\t\t\t\tthis.outputNoLicenseKeyProvided()\n\t\t\t}\n\n\t\t\treturn { isLicenseParseable: false, reason: 'no-key-provided' }\n\t\t}\n\n\t\tif (this.isDevelopment && !this.isCryptoAvailable) {\n\t\t\tif (this.verbose) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t'tldraw: you seem to be in a development environment that does not support crypto. License not verified.'\n\t\t\t\t)\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log('You should check that this works in production separately.')\n\t\t\t}\n\t\t\t// We can't parse the license if we are in development mode since crypto\n\t\t\t// is not available on http\n\t\t\treturn { isLicenseParseable: false, reason: 'has-key-development-mode' }\n\t\t}\n\n\t\t// Borrowed idea from AG Grid:\n\t\t// Copying from various sources (like PDFs) can include zero-width characters.\n\t\t// This helps makes sure the key validation doesn't fail.\n\t\tlet cleanedLicenseKey = licenseKey.replace(/[\\u200B-\\u200D\\uFEFF]/g, '')\n\t\tcleanedLicenseKey = cleanedLicenseKey.replace(/\\r?\\n|\\r/g, '')\n\n\t\ttry {\n\t\t\tconst licenseInfo = await this.extractLicenseKey(cleanedLicenseKey)\n\t\t\tconst expiryDate = new Date(licenseInfo.expiryDate)\n\t\t\tconst isAnnualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.ANNUAL_LICENSE)\n\t\t\tconst isPerpetualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.PERPETUAL_LICENSE)\n\n\t\t\tconst result: ValidLicenseKeyResult = {\n\t\t\t\tlicense: licenseInfo,\n\t\t\t\tisLicenseParseable: true,\n\t\t\t\tisDevelopment: this.isDevelopment,\n\t\t\t\tisDomainValid: this.isDomainValid(licenseInfo),\n\t\t\t\texpiryDate,\n\t\t\t\tisAnnualLicense,\n\t\t\t\tisAnnualLicenseExpired: isAnnualLicense && this.isAnnualLicenseExpired(expiryDate),\n\t\t\t\tisPerpetualLicense,\n\t\t\t\tisPerpetualLicenseExpired: isPerpetualLicense && this.isPerpetualLicenseExpired(expiryDate),\n\t\t\t\tisInternalLicense: this.isFlagEnabled(licenseInfo.flags, FLAGS.INTERNAL_LICENSE),\n\t\t\t\tisLicensedWithWatermark: this.isFlagEnabled(licenseInfo.flags, FLAGS.WITH_WATERMARK),\n\t\t\t}\n\t\t\tthis.outputLicenseInfoIfNeeded(result)\n\n\t\t\treturn result\n\t\t} catch (e: any) {\n\t\t\tthis.outputInvalidLicenseKey(e.message)\n\t\t\t// If the license can't be parsed, it's invalid\n\t\t\treturn { isLicenseParseable: false, reason: 'invalid-license-key' }\n\t\t}\n\t}\n\n\tprivate isDomainValid(licenseInfo: LicenseInfo) {\n\t\tconst currentHostname = window.location.hostname.toLowerCase()\n\n\t\treturn licenseInfo.hosts.some((host) => {\n\t\t\tconst normalizedHost = host.toLowerCase().trim()\n\n\t\t\t// Allow the domain if listed and www variations, 'example.com' allows 'example.com' and 'www.example.com'\n\t\t\tif (\n\t\t\t\tnormalizedHost === currentHostname ||\n\t\t\t\t`www.${normalizedHost}` === currentHostname ||\n\t\t\t\tnormalizedHost === `www.${currentHostname}`\n\t\t\t) {\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// If host is '*', we allow all domains.\n\t\t\tif (host === '*') {\n\t\t\t\t// All domains allowed.\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// Glob testing, we only support '*.somedomain.com' right now.\n\t\t\tif (host.includes('*')) {\n\t\t\t\tconst globToRegex = new RegExp(host.replace(/\\*/g, '.*?'))\n\t\t\t\treturn globToRegex.test(currentHostname) || globToRegex.test(`www.${currentHostname}`)\n\t\t\t}\n\n\t\t\t// VSCode support\n\t\t\tif (window.location.protocol === 'vscode-webview:') {\n\t\t\t\tconst currentUrl = new URL(window.location.href)\n\t\t\t\tconst extensionId = currentUrl.searchParams.get('extensionId')\n\t\t\t\tif (normalizedHost === extensionId) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false\n\t\t})\n\t}\n\n\tprivate getExpirationDateWithoutGracePeriod(expiryDate: Date) {\n\t\treturn new Date(expiryDate.getFullYear(), expiryDate.getMonth(), expiryDate.getDate())\n\t}\n\n\tprivate getExpirationDateWithGracePeriod(expiryDate: Date) {\n\t\treturn new Date(\n\t\t\texpiryDate.getFullYear(),\n\t\t\texpiryDate.getMonth(),\n\t\t\texpiryDate.getDate() + GRACE_PERIOD_DAYS + 1 // Add 1 day to include the expiration day\n\t\t)\n\t}\n\n\tprivate isAnnualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst isExpired = new Date() >= expiration\n\t\t// If it is not expired yet (including the grace period), but after the expiry date we warn the users\n\t\tif (!isExpired && new Date() >= this.getExpirationDateWithoutGracePeriod(expiryDate)) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'tldraw license is about to expire, you are in a grace period.',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} if you would like to renew your license.`,\n\t\t\t])\n\t\t}\n\t\treturn isExpired\n\t}\n\n\tprivate isPerpetualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst dates = {\n\t\t\tmajor: new Date(publishDates.major),\n\t\t\tminor: new Date(publishDates.minor),\n\t\t}\n\t\t// We allow patch releases, but the major and minor releases should be within the expiration date\n\t\treturn dates.major >= expiration || dates.minor >= expiration\n\t}\n\n\tprivate isFlagEnabled(flags: number, flag: number) {\n\t\treturn (flags & flag) === flag\n\t}\n\n\tprivate outputNoLicenseKeyProvided() {\n\t\t// Noop, we don't need to show this message.\n\t\t// this.outputMessages([\n\t\t// \t'No tldraw license key provided!',\n\t\t// \t`Please reach out to ${LICENSE_EMAIL} if you would like to license tldraw or if you'd like a trial.`,\n\t\t// ])\n\t}\n\n\tprivate outputInvalidLicenseKey(msg: string) {\n\t\tthis.outputMessages(['Invalid tldraw license key', `Reason: ${msg}`])\n\t}\n\n\tprivate outputLicenseInfoIfNeeded(result: ValidLicenseKeyResult) {\n\t\tif (result.isAnnualLicenseExpired) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'Your tldraw license has expired!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to renew.`,\n\t\t\t])\n\t\t}\n\n\t\tif (!result.isDomainValid && !result.isDevelopment) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'This tldraw license key is not valid for this domain!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} if you would like to use tldraw on other domains.`,\n\t\t\t])\n\t\t}\n\t\t// If we added a new flag it will be twice the value of the currently highest flag.\n\t\t// And if all the current flags are on we would get the `HIGHEST_FLAG * 2 - 1`, so anything higher than that means there are new flags.\n\t\tif (result.license.flags >= HIGHEST_FLAG * 2) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'This tldraw license contains some unknown flags.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\t}\n\n\tprivate outputMessages(messages: string[]) {\n\t\tif (this.isTest) return\n\t\tif (this.verbose) {\n\t\t\tthis.outputDelimiter()\n\t\t\tfor (const message of messages) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t`%c${message}`,\n\t\t\t\t\t`color: white; background: crimson; padding: 2px; border-radius: 3px;`\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis.outputDelimiter()\n\t\t}\n\t}\n\n\tprivate outputDelimiter() {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.log(\n\t\t\t'%c-------------------------------------------------------------------',\n\t\t\t`color: white; background: crimson; padding: 2px; border-radius: 3px;`\n\t\t)\n\t}\n\n\tstatic className = 'tl-watermark_SEE-LICENSE'\n}\n\nexport function getLicenseState(result: LicenseFromKeyResult): LicenseState {\n\tif (!result.isLicenseParseable) return 'unlicensed'\n\tif (!result.isDomainValid && !result.isDevelopment) return 'unlicensed'\n\tif (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {\n\t\t// Check if it's an expired internal license with valid domain\n\t\tconst internalExpired = result.isInternalLicense && result.isDomainValid\n\t\treturn internalExpired ? 'internal-expired' : 'unlicensed'\n\t}\n\n\t// License is valid, determine if it has watermark\n\tif (result.isLicensedWithWatermark) {\n\t\treturn 'licensed-with-watermark'\n\t}\n\n\treturn 'licensed'\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;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;AAAA,EACD;AAAA,EAEA,OAAO,YAAY;AACpB;AAEO,SAAS,gBAAgB,QAA4C;AAC3E,MAAI,CAAC,OAAO,mBAAoB,QAAO;AACvC,MAAI,CAAC,OAAO,iBAAiB,CAAC,OAAO,cAAe,QAAO;AAC3D,MAAI,OAAO,6BAA6B,OAAO,wBAAwB;AAEtE,UAAM,kBAAkB,OAAO,qBAAqB,OAAO;AAC3D,WAAO,kBAAkB,qBAAqB;AAAA,EAC/C;AAGA,MAAI,OAAO,yBAAyB;AACnC,WAAO;AAAA,EACR;AAEA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -24,6 +24,7 @@ __export(LicenseProvider_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(LicenseProvider_exports);
26
26
  var import_jsx_runtime = require("react/jsx-runtime");
27
+ var import_state_react = require("@tldraw/state-react");
27
28
  var import_react = require("react");
28
29
  var import_LicenseManager = require("./LicenseManager");
29
30
  const LicenseContext = (0, import_react.createContext)({});
@@ -33,6 +34,10 @@ function LicenseProvider({
33
34
  children
34
35
  }) {
35
36
  const [licenseManager] = (0, import_react.useState)(() => new import_LicenseManager.LicenseManager(licenseKey));
37
+ const licenseState = (0, import_state_react.useValue)(licenseManager.state);
38
+ if (licenseState === "internal-expired") {
39
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-testid": "tl-license-expired", style: { display: "none" } });
40
+ }
36
41
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LicenseContext.Provider, { value: licenseManager, children });
37
42
  }
38
43
  //# sourceMappingURL=LicenseProvider.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/license/LicenseProvider.tsx"],
4
- "sourcesContent": ["import { createContext, ReactNode, useContext, useState } from 'react'\nimport { LicenseManager } from './LicenseManager'\n\n/** @internal */\nexport const LicenseContext = createContext({} as LicenseManager)\n\n/** @internal */\nexport const useLicenseContext = () => useContext(LicenseContext)\n\n/** @internal */\nexport function LicenseProvider({\n\tlicenseKey,\n\tchildren,\n}: {\n\tlicenseKey?: string\n\tchildren: ReactNode\n}) {\n\tconst [licenseManager] = useState(() => new LicenseManager(licenseKey))\n\treturn <LicenseContext.Provider value={licenseManager}>{children}</LicenseContext.Provider>\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBQ;AAlBR,mBAA+D;AAC/D,4BAA+B;AAGxB,MAAM,qBAAiB,4BAAc,CAAC,CAAmB;AAGzD,MAAM,oBAAoB,UAAM,yBAAW,cAAc;AAGzD,SAAS,gBAAgB;AAAA,EAC/B;AAAA,EACA;AACD,GAGG;AACF,QAAM,CAAC,cAAc,QAAI,uBAAS,MAAM,IAAI,qCAAe,UAAU,CAAC;AACtE,SAAO,4CAAC,eAAe,UAAf,EAAwB,OAAO,gBAAiB,UAAS;AAClE;",
4
+ "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { createContext, ReactNode, useContext, useState } from 'react'\nimport { LicenseManager } from './LicenseManager'\n\n/** @internal */\nexport const LicenseContext = createContext({} as LicenseManager)\n\n/** @internal */\nexport const useLicenseContext = () => useContext(LicenseContext)\n\n/** @internal */\nexport function LicenseProvider({\n\tlicenseKey,\n\tchildren,\n}: {\n\tlicenseKey?: string\n\tchildren: ReactNode\n}) {\n\tconst [licenseManager] = useState(() => new LicenseManager(licenseKey))\n\tconst licenseState = useValue(licenseManager.state)\n\n\t// If internal license has expired, don't render the editor at all\n\tif (licenseState === 'internal-expired') {\n\t\treturn <div data-testid=\"tl-license-expired\" style={{ display: 'none' }} />\n\t}\n\n\treturn <LicenseContext.Provider value={licenseManager}>{children}</LicenseContext.Provider>\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBS;AAvBT,yBAAyB;AACzB,mBAA+D;AAC/D,4BAA+B;AAGxB,MAAM,qBAAiB,4BAAc,CAAC,CAAmB;AAGzD,MAAM,oBAAoB,UAAM,yBAAW,cAAc;AAGzD,SAAS,gBAAgB;AAAA,EAC/B;AAAA,EACA;AACD,GAGG;AACF,QAAM,CAAC,cAAc,QAAI,uBAAS,MAAM,IAAI,qCAAe,UAAU,CAAC;AACtE,QAAM,mBAAe,6BAAS,eAAe,KAAK;AAGlD,MAAI,iBAAiB,oBAAoB;AACxC,WAAO,4CAAC,SAAI,eAAY,sBAAqB,OAAO,EAAE,SAAS,OAAO,GAAG;AAAA,EAC1E;AAEA,SAAO,4CAAC,eAAe,UAAf,EAAwB,OAAO,gBAAiB,UAAS;AAClE;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/license/useLicenseManagerState.ts"],
4
- "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { LicenseManager } from './LicenseManager'\n\n/** @internal */\nexport function useLicenseManagerState(licenseManager: LicenseManager) {\n\treturn useValue('watermarkState', () => licenseManager.state.get(), [licenseManager])\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAyB;AAIlB,SAAS,uBAAuB,gBAAgC;AACtE,aAAO,6BAAS,kBAAkB,MAAM,eAAe,MAAM,IAAI,GAAG,CAAC,cAAc,CAAC;AACrF;",
4
+ "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { LicenseManager, LicenseState } from './LicenseManager'\n\n/** @internal */\nexport function useLicenseManagerState(licenseManager: LicenseManager): LicenseState {\n\treturn useValue('watermarkState', () => licenseManager.state.get(), [licenseManager])\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAyB;AAIlB,SAAS,uBAAuB,gBAA8C;AACpF,aAAO,6BAAS,kBAAkB,MAAM,eAAe,MAAM,IAAI,GAAG,CAAC,cAAc,CAAC;AACrF;",
6
6
  "names": []
7
7
  }
@@ -208,10 +208,6 @@ class Vec {
208
208
  equalsXY(x, y) {
209
209
  return Vec.EqualsXY(this, x, y);
210
210
  }
211
- /** @deprecated use `uni` instead */
212
- norm() {
213
- return this.uni();
214
- }
215
211
  toFixed() {
216
212
  this.x = (0, import_utils.toFixed)(this.x);
217
213
  this.y = (0, import_utils.toFixed)(this.y);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/primitives/Vec.ts"],
4
- "sourcesContent": ["import { VecModel } from '@tldraw/tlschema'\nimport { EASINGS } from './easings'\nimport { clamp, toFixed } from './utils'\n\n/** @public */\nexport type VecLike = Vec | VecModel\n\n/** @public */\nexport class Vec {\n\tconstructor(\n\t\tpublic x = 0,\n\t\tpublic y = 0,\n\t\tpublic z = 1\n\t) {}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget pressure() {\n\t\treturn this.z\n\t}\n\n\tset(x = this.x, y = this.y, z = this.z) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.z = z\n\t\treturn this\n\t}\n\n\tsetTo({ x = 0, y = 0, z = 1 }: VecLike) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.z = z\n\t\treturn this\n\t}\n\n\trot(r: number) {\n\t\tif (r === 0) return this\n\t\tconst { x, y } = this\n\t\tconst s = Math.sin(r)\n\t\tconst c = Math.cos(r)\n\t\tthis.x = x * c - y * s\n\t\tthis.y = x * s + y * c\n\t\treturn this\n\t}\n\n\trotWith(C: VecLike, r: number) {\n\t\tif (r === 0) return this\n\t\tconst x = this.x - C.x\n\t\tconst y = this.y - C.y\n\t\tconst s = Math.sin(r)\n\t\tconst c = Math.cos(r)\n\t\tthis.x = C.x + (x * c - y * s)\n\t\tthis.y = C.y + (x * s + y * c)\n\t\treturn this\n\t}\n\n\tclone(): Vec {\n\t\tconst { x, y, z } = this\n\t\treturn new Vec(x, y, z)\n\t}\n\n\tsub(V: VecLike) {\n\t\tthis.x -= V.x\n\t\tthis.y -= V.y\n\t\treturn this\n\t}\n\n\tsubXY(x: number, y: number) {\n\t\tthis.x -= x\n\t\tthis.y -= y\n\t\treturn this\n\t}\n\n\tsubScalar(n: number) {\n\t\tthis.x -= n\n\t\tthis.y -= n\n\t\t// this.z -= n\n\n\t\treturn this\n\t}\n\n\tadd(V: VecLike) {\n\t\tthis.x += V.x\n\t\tthis.y += V.y\n\t\treturn this\n\t}\n\n\taddXY(x: number, y: number) {\n\t\tthis.x += x\n\t\tthis.y += y\n\t\treturn this\n\t}\n\n\taddScalar(n: number) {\n\t\tthis.x += n\n\t\tthis.y += n\n\t\t// this.z += n\n\n\t\treturn this\n\t}\n\n\tclamp(min: number, max?: number) {\n\t\tthis.x = Math.max(this.x, min)\n\t\tthis.y = Math.max(this.y, min)\n\t\tif (max !== undefined) {\n\t\t\tthis.x = Math.min(this.x, max)\n\t\t\tthis.y = Math.min(this.y, max)\n\t\t}\n\t\treturn this\n\t}\n\n\tdiv(t: number) {\n\t\tthis.x /= t\n\t\tthis.y /= t\n\t\t// this.z /= t\n\t\treturn this\n\t}\n\n\tdivV(V: VecLike) {\n\t\tthis.x /= V.x\n\t\tthis.y /= V.y\n\t\t// this.z /= V.z\n\t\treturn this\n\t}\n\n\tmul(t: number) {\n\t\tthis.x *= t\n\t\tthis.y *= t\n\t\t// this.z *= t\n\t\treturn this\n\t}\n\n\tmulV(V: VecLike) {\n\t\tthis.x *= V.x\n\t\tthis.y *= V.y\n\t\t// this.z *= V.z\n\t\treturn this\n\t}\n\n\tabs() {\n\t\tthis.x = Math.abs(this.x)\n\t\tthis.y = Math.abs(this.y)\n\t\treturn this\n\t}\n\n\tnudge(B: VecLike, distance: number) {\n\t\tconst tan = Vec.Tan(B, this)\n\t\treturn this.add(tan.mul(distance))\n\t}\n\n\tneg() {\n\t\tthis.x *= -1\n\t\tthis.y *= -1\n\t\t// this.z *= -1\n\t\treturn this\n\t}\n\n\tcross(V: VecLike) {\n\t\tthis.x = this.y * V.z! - this.z * V.y\n\t\tthis.y = this.z * V.x - this.x * V.z!\n\t\t// this.z = this.x * V.y - this.y * V.x\n\t\treturn this\n\t}\n\n\tdpr(V: VecLike): number {\n\t\treturn Vec.Dpr(this, V)\n\t}\n\n\tcpr(V: VecLike) {\n\t\treturn Vec.Cpr(this, V)\n\t}\n\n\tlen2(): number {\n\t\treturn Vec.Len2(this)\n\t}\n\n\tlen(): number {\n\t\treturn Vec.Len(this)\n\t}\n\n\tpry(V: VecLike): number {\n\t\treturn Vec.Pry(this, V)\n\t}\n\n\tper() {\n\t\tconst { x, y } = this\n\t\tthis.x = y\n\t\tthis.y = -x\n\t\treturn this\n\t}\n\n\tuni() {\n\t\tconst l = this.len()\n\t\tif (l === 0) return this\n\t\tthis.x /= l\n\t\tthis.y /= l\n\t\treturn this\n\t}\n\n\ttan(V: VecLike): Vec {\n\t\treturn this.sub(V).uni()\n\t}\n\n\tdist(V: VecLike): number {\n\t\treturn Vec.Dist(this, V)\n\t}\n\n\tdistanceToLineSegment(A: VecLike, B: VecLike): number {\n\t\treturn Vec.DistanceToLineSegment(A, B, this)\n\t}\n\n\tslope(B: VecLike): number {\n\t\treturn Vec.Slope(this, B)\n\t}\n\n\tsnapToGrid(gridSize: number) {\n\t\tthis.x = Math.round(this.x / gridSize) * gridSize\n\t\tthis.y = Math.round(this.y / gridSize) * gridSize\n\t\treturn this\n\t}\n\n\tangle(B: VecLike): number {\n\t\treturn Vec.Angle(this, B)\n\t}\n\n\ttoAngle() {\n\t\treturn Vec.ToAngle(this)\n\t}\n\n\tlrp(B: VecLike, t: number): Vec {\n\t\tthis.x = this.x + (B.x - this.x) * t\n\t\tthis.y = this.y + (B.y - this.y) * t\n\t\treturn this\n\t}\n\n\tequals(B: VecLike) {\n\t\treturn Vec.Equals(this, B)\n\t}\n\n\tequalsXY(x: number, y: number) {\n\t\treturn Vec.EqualsXY(this, x, y)\n\t}\n\n\t/** @deprecated use `uni` instead */\n\tnorm() {\n\t\treturn this.uni()\n\t}\n\n\ttoFixed() {\n\t\tthis.x = toFixed(this.x)\n\t\tthis.y = toFixed(this.y)\n\t\treturn this\n\t}\n\n\ttoString() {\n\t\treturn Vec.ToString(Vec.ToFixed(this))\n\t}\n\n\ttoJson(): VecModel {\n\t\treturn Vec.ToJson(this)\n\t}\n\n\ttoArray(): number[] {\n\t\treturn Vec.ToArray(this)\n\t}\n\n\tstatic Add(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(A.x + B.x, A.y + B.y)\n\t}\n\n\tstatic AddXY(A: VecLike, x: number, y: number): Vec {\n\t\treturn new Vec(A.x + x, A.y + y)\n\t}\n\n\tstatic Sub(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(A.x - B.x, A.y - B.y)\n\t}\n\n\tstatic SubXY(A: VecLike, x: number, y: number): Vec {\n\t\treturn new Vec(A.x - x, A.y - y)\n\t}\n\n\tstatic AddScalar(A: VecLike, n: number): Vec {\n\t\treturn new Vec(A.x + n, A.y + n)\n\t}\n\n\tstatic SubScalar(A: VecLike, n: number): Vec {\n\t\treturn new Vec(A.x - n, A.y - n)\n\t}\n\n\tstatic Div(A: VecLike, t: number): Vec {\n\t\treturn new Vec(A.x / t, A.y / t)\n\t}\n\n\tstatic Mul(A: VecLike, t: number): Vec {\n\t\treturn new Vec(A.x * t, A.y * t)\n\t}\n\n\tstatic DivV(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(A.x / B.x, A.y / B.y)\n\t}\n\n\tstatic MulV(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(A.x * B.x, A.y * B.y)\n\t}\n\n\tstatic Neg(A: VecLike): Vec {\n\t\treturn new Vec(-A.x, -A.y)\n\t}\n\n\t/**\n\t * Get the perpendicular vector to A.\n\t */\n\tstatic Per(A: VecLike): Vec {\n\t\treturn new Vec(A.y, -A.x)\n\t}\n\n\tstatic Abs(A: VecLike): Vec {\n\t\treturn new Vec(Math.abs(A.x), Math.abs(A.y))\n\t}\n\n\t// Get the distance between two points.\n\tstatic Dist(A: VecLike, B: VecLike): number {\n\t\treturn ((A.y - B.y) ** 2 + (A.x - B.x) ** 2) ** 0.5\n\t}\n\n\t// Get the Manhattan distance between two points.\n\tstatic ManhattanDist(A: VecLike, B: VecLike): number {\n\t\treturn Math.abs(A.x - B.x) + Math.abs(A.y - B.y)\n\t}\n\n\t// Get whether a distance between two points is less than a number. This is faster to calulate than using `Vec.Dist(a, b) < n`.\n\tstatic DistMin(A: VecLike, B: VecLike, n: number): boolean {\n\t\treturn (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y) < n ** 2\n\t}\n\n\t// Get the squared distance between two points. This is faster to calculate (no square root) so useful for \"minimum distance\" checks where the actual measurement does not matter.\n\tstatic Dist2(A: VecLike, B: VecLike): number {\n\t\treturn (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)\n\t}\n\n\t/**\n\t * Dot product of two vectors which is used to calculate the angle between them.\n\t */\n\tstatic Dpr(A: VecLike, B: VecLike): number {\n\t\treturn A.x * B.x + A.y * B.y\n\t}\n\n\tstatic Cross(A: VecLike, V: VecLike) {\n\t\treturn new Vec(\n\t\t\tA.y * V.z! - A.z! * V.y,\n\t\t\tA.z! * V.x - A.x * V.z!\n\t\t\t// A.z = A.x * V.y - A.y * V.x\n\t\t)\n\t}\n\n\t/**\n\t * Cross product of two vectors which is used to calculate the area of a parallelogram.\n\t */\n\tstatic Cpr(A: VecLike, B: VecLike) {\n\t\treturn A.x * B.y - B.x * A.y\n\t}\n\n\tstatic Len2(A: VecLike): number {\n\t\treturn A.x * A.x + A.y * A.y\n\t}\n\n\tstatic Len(A: VecLike): number {\n\t\treturn (A.x * A.x + A.y * A.y) ** 0.5\n\t}\n\n\t/**\n\t * Get the projection of A onto B.\n\t */\n\tstatic Pry(A: VecLike, B: VecLike): number {\n\t\treturn Vec.Dpr(A, B) / Vec.Len(B)\n\t}\n\n\t/**\n\t * Get the unit vector of A.\n\t */\n\tstatic Uni(A: VecLike) {\n\t\tconst l = Vec.Len(A)\n\t\treturn new Vec(l === 0 ? 0 : A.x / l, l === 0 ? 0 : A.y / l)\n\t}\n\n\tstatic Tan(A: VecLike, B: VecLike): Vec {\n\t\treturn Vec.Uni(Vec.Sub(A, B))\n\t}\n\n\tstatic Min(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(Math.min(A.x, B.x), Math.min(A.y, B.y))\n\t}\n\n\tstatic Max(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(Math.max(A.x, B.x), Math.max(A.y, B.y))\n\t}\n\n\tstatic From({ x, y, z = 1 }: VecModel) {\n\t\treturn new Vec(x, y, z)\n\t}\n\n\tstatic FromArray(v: number[]): Vec {\n\t\treturn new Vec(v[0], v[1])\n\t}\n\n\tstatic Rot(A: VecLike, r = 0): Vec {\n\t\tconst s = Math.sin(r)\n\t\tconst c = Math.cos(r)\n\t\treturn new Vec(A.x * c - A.y * s, A.x * s + A.y * c)\n\t}\n\n\tstatic RotWith(A: VecLike, C: VecLike, r: number): Vec {\n\t\tconst x = A.x - C.x\n\t\tconst y = A.y - C.y\n\t\tconst s = Math.sin(r)\n\t\tconst c = Math.cos(r)\n\t\treturn new Vec(C.x + (x * c - y * s), C.y + (x * s + y * c))\n\t}\n\n\t/**\n\t * Get the nearest point on a line with a known unit vector that passes through point A\n\t *\n\t * ```ts\n\t * Vec.nearestPointOnLineThroughPoint(A, u, Point)\n\t * ```\n\t *\n\t * @param A - Any point on the line\n\t * @param u - The unit vector for the line.\n\t * @param P - A point not on the line to test.\n\t */\n\tstatic NearestPointOnLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): Vec {\n\t\treturn Vec.Mul(u, Vec.Sub(P, A).pry(u)).add(A)\n\t}\n\n\tstatic NearestPointOnLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp = true): Vec {\n\t\tif (Vec.Equals(A, P)) return Vec.From(P)\n\t\tif (Vec.Equals(B, P)) return Vec.From(P)\n\n\t\tconst u = Vec.Tan(B, A)\n\t\tconst C = Vec.Add(A, Vec.Mul(u, Vec.Sub(P, A).pry(u)))\n\n\t\tif (clamp) {\n\t\t\tif (C.x < Math.min(A.x, B.x)) return Vec.Cast(A.x < B.x ? A : B)\n\t\t\tif (C.x > Math.max(A.x, B.x)) return Vec.Cast(A.x > B.x ? A : B)\n\t\t\tif (C.y < Math.min(A.y, B.y)) return Vec.Cast(A.y < B.y ? A : B)\n\t\t\tif (C.y > Math.max(A.y, B.y)) return Vec.Cast(A.y > B.y ? A : B)\n\t\t}\n\n\t\treturn C\n\t}\n\n\tstatic DistanceToLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): number {\n\t\treturn Vec.Dist(P, Vec.NearestPointOnLineThroughPoint(A, u, P))\n\t}\n\n\tstatic DistanceToLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp = true): number {\n\t\treturn Vec.Dist(P, Vec.NearestPointOnLineSegment(A, B, P, clamp))\n\t}\n\n\tstatic Snap(A: VecLike, step = 1) {\n\t\treturn new Vec(Math.round(A.x / step) * step, Math.round(A.y / step) * step)\n\t}\n\n\tstatic Cast(A: VecLike): Vec {\n\t\tif (A instanceof Vec) return A\n\t\treturn Vec.From(A)\n\t}\n\n\tstatic Slope(A: VecLike, B: VecLike): number {\n\t\tif (A.x === B.y) return NaN\n\t\treturn (A.y - B.y) / (A.x - B.x)\n\t}\n\n\tstatic IsNaN(A: VecLike): boolean {\n\t\treturn isNaN(A.x) || isNaN(A.y)\n\t}\n\n\t/**\n\t * Get the angle from position A to position B.\n\t */\n\tstatic Angle(A: VecLike, B: VecLike): number {\n\t\treturn Math.atan2(B.y - A.y, B.x - A.x)\n\t}\n\n\t/**\n\t * Get the angle between vector A and vector B. This will return the smallest angle between the\n\t * two vectors, between -\u03C0 and \u03C0. The sign indicates direction of angle.\n\t */\n\tstatic AngleBetween(A: VecLike, B: VecLike): number {\n\t\tconst p = A.x * B.x + A.y * B.y\n\t\tconst n = Math.sqrt(\n\t\t\t(Math.pow(A.x, 2) + Math.pow(A.y, 2)) * (Math.pow(B.x, 2) + Math.pow(B.y, 2))\n\t\t)\n\t\tconst sign = A.x * B.y - A.y * B.x < 0 ? -1 : 1\n\t\tconst angle = sign * Math.acos(clamp(p / n, -1, 1))\n\n\t\treturn angle\n\t}\n\n\t/**\n\t * Linearly interpolate between two points.\n\t * @param A - The first point.\n\t * @param B - The second point.\n\t * @param t - The interpolation value between 0 and 1.\n\t * @returns The interpolated point.\n\t */\n\tstatic Lrp(A: VecLike, B: VecLike, t: number): Vec {\n\t\treturn Vec.Sub(B, A).mul(t).add(A)\n\t}\n\n\tstatic Med(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec((A.x + B.x) / 2, (A.y + B.y) / 2)\n\t}\n\n\tstatic Equals(A: VecLike, B: VecLike): boolean {\n\t\treturn Math.abs(A.x - B.x) < 0.0001 && Math.abs(A.y - B.y) < 0.0001\n\t}\n\n\tstatic EqualsXY(A: VecLike, x: number, y: number): boolean {\n\t\treturn A.x === x && A.y === y\n\t}\n\n\tstatic Clockwise(A: VecLike, B: VecLike, C: VecLike): boolean {\n\t\treturn (C.x - A.x) * (B.y - A.y) - (B.x - A.x) * (C.y - A.y) < 0\n\t}\n\n\tstatic Rescale(A: VecLike, n: number) {\n\t\tconst l = Vec.Len(A)\n\t\treturn new Vec((n * A.x) / l, (n * A.y) / l)\n\t}\n\n\tstatic ScaleWithOrigin(A: VecLike, scale: number, origin: VecLike) {\n\t\treturn Vec.Sub(A, origin).mul(scale).add(origin)\n\t}\n\n\tstatic ToFixed(A: VecLike) {\n\t\treturn new Vec(toFixed(A.x), toFixed(A.y))\n\t}\n\n\tstatic ToInt(A: VecLike) {\n\t\treturn new Vec(\n\t\t\tparseInt(A.x.toFixed(0)),\n\t\t\tparseInt(A.y.toFixed(0)),\n\t\t\tparseInt((A.z ?? 0).toFixed(0))\n\t\t)\n\t}\n\n\tstatic ToCss(A: VecLike) {\n\t\treturn `${A.x},${A.y}`\n\t}\n\n\tstatic Nudge(A: VecLike, B: VecLike, distance: number) {\n\t\treturn Vec.Add(A, Vec.Tan(B, A).mul(distance))\n\t}\n\n\tstatic ToString(A: VecLike) {\n\t\treturn `${A.x}, ${A.y}`\n\t}\n\n\tstatic ToAngle(A: VecLike) {\n\t\tlet r = Math.atan2(A.y, A.x)\n\t\tif (r < 0) r += Math.PI * 2\n\n\t\treturn r\n\t}\n\n\tstatic FromAngle(r: number, length = 1) {\n\t\treturn new Vec(Math.cos(r) * length, Math.sin(r) * length)\n\t}\n\n\tstatic ToArray(A: VecLike) {\n\t\treturn [A.x, A.y, A.z!]\n\t}\n\n\tstatic ToJson(A: VecLike) {\n\t\tconst { x, y, z } = A\n\t\treturn { x, y, z }\n\t}\n\n\tstatic Average(arr: VecLike[]) {\n\t\tconst len = arr.length\n\t\tconst avg = new Vec(0, 0)\n\t\tif (len === 0) {\n\t\t\treturn avg\n\t\t}\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tavg.add(arr[i])\n\t\t}\n\t\treturn avg.div(len)\n\t}\n\n\tstatic Clamp(A: Vec, min: number, max?: number) {\n\t\tif (max === undefined) {\n\t\t\treturn new Vec(Math.min(Math.max(A.x, min)), Math.min(Math.max(A.y, min)))\n\t\t}\n\n\t\treturn new Vec(Math.min(Math.max(A.x, min), max), Math.min(Math.max(A.y, min), max))\n\t}\n\n\t/**\n\t * Get an array of points (with simulated pressure) between two points.\n\t *\n\t * @param A - The first point.\n\t * @param B - The second point.\n\t * @param steps - The number of points to return.\n\t */\n\tstatic PointsBetween(A: VecModel, B: VecModel, steps = 6): Vec[] {\n\t\tconst results: Vec[] = []\n\n\t\tfor (let i = 0; i < steps; i++) {\n\t\t\tconst t = EASINGS.easeInQuad(i / (steps - 1))\n\t\t\tconst point = Vec.Lrp(A, B, t)\n\t\t\tpoint.z = Math.min(1, 0.5 + Math.abs(0.5 - ease(t)) * 0.65)\n\t\t\tresults.push(point)\n\t\t}\n\n\t\treturn results\n\t}\n\n\tstatic SnapToGrid(A: VecLike, gridSize = 8) {\n\t\treturn new Vec(Math.round(A.x / gridSize) * gridSize, Math.round(A.y / gridSize) * gridSize)\n\t}\n}\n\nconst ease = (t: number) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t)\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAwB;AACxB,mBAA+B;AAMxB,MAAM,IAAI;AAAA,EAChB,YACQ,IAAI,GACJ,IAAI,GACJ,IAAI,GACV;AAHM;AACA;AACA;AAAA,EACL;AAAA;AAAA,EAGH,IAAI,WAAW;AACd,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,IAAI,IAAI,KAAK,GAAG,IAAI,KAAK,GAAG,IAAI,KAAK,GAAG;AACvC,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI;AACT,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,GAAY;AACvC,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI;AACT,WAAO;AAAA,EACR;AAAA,EAEA,IAAI,GAAW;AACd,QAAI,MAAM,EAAG,QAAO;AACpB,UAAM,EAAE,GAAG,EAAE,IAAI;AACjB,UAAM,IAAI,KAAK,IAAI,CAAC;AACpB,UAAM,IAAI,KAAK,IAAI,CAAC;AACpB,SAAK,IAAI,IAAI,IAAI,IAAI;AACrB,SAAK,IAAI,IAAI,IAAI,IAAI;AACrB,WAAO;AAAA,EACR;AAAA,EAEA,QAAQ,GAAY,GAAW;AAC9B,QAAI,MAAM,EAAG,QAAO;AACpB,UAAM,IAAI,KAAK,IAAI,EAAE;AACrB,UAAM,IAAI,KAAK,IAAI,EAAE;AACrB,UAAM,IAAI,KAAK,IAAI,CAAC;AACpB,UAAM,IAAI,KAAK,IAAI,CAAC;AACpB,SAAK,IAAI,EAAE,KAAK,IAAI,IAAI,IAAI;AAC5B,SAAK,IAAI,EAAE,KAAK,IAAI,IAA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Q,IAAI,IAAI,GAAG,GAAG,CAAC;AAC7B,YAAM,IAAI,KAAK,IAAI,GAAG,MAAM,KAAK,IAAI,MAAM,KAAK,CAAC,CAAC,IAAI,IAAI;AAC1D,cAAQ,KAAK,KAAK;AAAA,IACnB;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,OAAO,WAAW,GAAY,WAAW,GAAG;AAC3C,WAAO,IAAI,IAAI,KAAK,MAAM,EAAE,IAAI,QAAQ,IAAI,UAAU,KAAK,MAAM,EAAE,IAAI,QAAQ,IAAI,QAAQ;AAAA,EAC5F;AACD;AAEA,MAAM,OAAO,CAAC,MAAe,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,KAAK;",
4
+ "sourcesContent": ["import { VecModel } from '@tldraw/tlschema'\nimport { EASINGS } from './easings'\nimport { clamp, toFixed } from './utils'\n\n/** @public */\nexport type VecLike = Vec | VecModel\n\n/** @public */\nexport class Vec {\n\tconstructor(\n\t\tpublic x = 0,\n\t\tpublic y = 0,\n\t\tpublic z = 1\n\t) {}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget pressure() {\n\t\treturn this.z\n\t}\n\n\tset(x = this.x, y = this.y, z = this.z) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.z = z\n\t\treturn this\n\t}\n\n\tsetTo({ x = 0, y = 0, z = 1 }: VecLike) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.z = z\n\t\treturn this\n\t}\n\n\trot(r: number) {\n\t\tif (r === 0) return this\n\t\tconst { x, y } = this\n\t\tconst s = Math.sin(r)\n\t\tconst c = Math.cos(r)\n\t\tthis.x = x * c - y * s\n\t\tthis.y = x * s + y * c\n\t\treturn this\n\t}\n\n\trotWith(C: VecLike, r: number) {\n\t\tif (r === 0) return this\n\t\tconst x = this.x - C.x\n\t\tconst y = this.y - C.y\n\t\tconst s = Math.sin(r)\n\t\tconst c = Math.cos(r)\n\t\tthis.x = C.x + (x * c - y * s)\n\t\tthis.y = C.y + (x * s + y * c)\n\t\treturn this\n\t}\n\n\tclone(): Vec {\n\t\tconst { x, y, z } = this\n\t\treturn new Vec(x, y, z)\n\t}\n\n\tsub(V: VecLike) {\n\t\tthis.x -= V.x\n\t\tthis.y -= V.y\n\t\treturn this\n\t}\n\n\tsubXY(x: number, y: number) {\n\t\tthis.x -= x\n\t\tthis.y -= y\n\t\treturn this\n\t}\n\n\tsubScalar(n: number) {\n\t\tthis.x -= n\n\t\tthis.y -= n\n\t\t// this.z -= n\n\n\t\treturn this\n\t}\n\n\tadd(V: VecLike) {\n\t\tthis.x += V.x\n\t\tthis.y += V.y\n\t\treturn this\n\t}\n\n\taddXY(x: number, y: number) {\n\t\tthis.x += x\n\t\tthis.y += y\n\t\treturn this\n\t}\n\n\taddScalar(n: number) {\n\t\tthis.x += n\n\t\tthis.y += n\n\t\t// this.z += n\n\n\t\treturn this\n\t}\n\n\tclamp(min: number, max?: number) {\n\t\tthis.x = Math.max(this.x, min)\n\t\tthis.y = Math.max(this.y, min)\n\t\tif (max !== undefined) {\n\t\t\tthis.x = Math.min(this.x, max)\n\t\t\tthis.y = Math.min(this.y, max)\n\t\t}\n\t\treturn this\n\t}\n\n\tdiv(t: number) {\n\t\tthis.x /= t\n\t\tthis.y /= t\n\t\t// this.z /= t\n\t\treturn this\n\t}\n\n\tdivV(V: VecLike) {\n\t\tthis.x /= V.x\n\t\tthis.y /= V.y\n\t\t// this.z /= V.z\n\t\treturn this\n\t}\n\n\tmul(t: number) {\n\t\tthis.x *= t\n\t\tthis.y *= t\n\t\t// this.z *= t\n\t\treturn this\n\t}\n\n\tmulV(V: VecLike) {\n\t\tthis.x *= V.x\n\t\tthis.y *= V.y\n\t\t// this.z *= V.z\n\t\treturn this\n\t}\n\n\tabs() {\n\t\tthis.x = Math.abs(this.x)\n\t\tthis.y = Math.abs(this.y)\n\t\treturn this\n\t}\n\n\tnudge(B: VecLike, distance: number) {\n\t\tconst tan = Vec.Tan(B, this)\n\t\treturn this.add(tan.mul(distance))\n\t}\n\n\tneg() {\n\t\tthis.x *= -1\n\t\tthis.y *= -1\n\t\t// this.z *= -1\n\t\treturn this\n\t}\n\n\tcross(V: VecLike) {\n\t\tthis.x = this.y * V.z! - this.z * V.y\n\t\tthis.y = this.z * V.x - this.x * V.z!\n\t\t// this.z = this.x * V.y - this.y * V.x\n\t\treturn this\n\t}\n\n\tdpr(V: VecLike): number {\n\t\treturn Vec.Dpr(this, V)\n\t}\n\n\tcpr(V: VecLike) {\n\t\treturn Vec.Cpr(this, V)\n\t}\n\n\tlen2(): number {\n\t\treturn Vec.Len2(this)\n\t}\n\n\tlen(): number {\n\t\treturn Vec.Len(this)\n\t}\n\n\tpry(V: VecLike): number {\n\t\treturn Vec.Pry(this, V)\n\t}\n\n\tper() {\n\t\tconst { x, y } = this\n\t\tthis.x = y\n\t\tthis.y = -x\n\t\treturn this\n\t}\n\n\tuni() {\n\t\tconst l = this.len()\n\t\tif (l === 0) return this\n\t\tthis.x /= l\n\t\tthis.y /= l\n\t\treturn this\n\t}\n\n\ttan(V: VecLike): Vec {\n\t\treturn this.sub(V).uni()\n\t}\n\n\tdist(V: VecLike): number {\n\t\treturn Vec.Dist(this, V)\n\t}\n\n\tdistanceToLineSegment(A: VecLike, B: VecLike): number {\n\t\treturn Vec.DistanceToLineSegment(A, B, this)\n\t}\n\n\tslope(B: VecLike): number {\n\t\treturn Vec.Slope(this, B)\n\t}\n\n\tsnapToGrid(gridSize: number) {\n\t\tthis.x = Math.round(this.x / gridSize) * gridSize\n\t\tthis.y = Math.round(this.y / gridSize) * gridSize\n\t\treturn this\n\t}\n\n\tangle(B: VecLike): number {\n\t\treturn Vec.Angle(this, B)\n\t}\n\n\ttoAngle() {\n\t\treturn Vec.ToAngle(this)\n\t}\n\n\tlrp(B: VecLike, t: number): Vec {\n\t\tthis.x = this.x + (B.x - this.x) * t\n\t\tthis.y = this.y + (B.y - this.y) * t\n\t\treturn this\n\t}\n\n\tequals(B: VecLike) {\n\t\treturn Vec.Equals(this, B)\n\t}\n\n\tequalsXY(x: number, y: number) {\n\t\treturn Vec.EqualsXY(this, x, y)\n\t}\n\n\ttoFixed() {\n\t\tthis.x = toFixed(this.x)\n\t\tthis.y = toFixed(this.y)\n\t\treturn this\n\t}\n\n\ttoString() {\n\t\treturn Vec.ToString(Vec.ToFixed(this))\n\t}\n\n\ttoJson(): VecModel {\n\t\treturn Vec.ToJson(this)\n\t}\n\n\ttoArray(): number[] {\n\t\treturn Vec.ToArray(this)\n\t}\n\n\tstatic Add(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(A.x + B.x, A.y + B.y)\n\t}\n\n\tstatic AddXY(A: VecLike, x: number, y: number): Vec {\n\t\treturn new Vec(A.x + x, A.y + y)\n\t}\n\n\tstatic Sub(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(A.x - B.x, A.y - B.y)\n\t}\n\n\tstatic SubXY(A: VecLike, x: number, y: number): Vec {\n\t\treturn new Vec(A.x - x, A.y - y)\n\t}\n\n\tstatic AddScalar(A: VecLike, n: number): Vec {\n\t\treturn new Vec(A.x + n, A.y + n)\n\t}\n\n\tstatic SubScalar(A: VecLike, n: number): Vec {\n\t\treturn new Vec(A.x - n, A.y - n)\n\t}\n\n\tstatic Div(A: VecLike, t: number): Vec {\n\t\treturn new Vec(A.x / t, A.y / t)\n\t}\n\n\tstatic Mul(A: VecLike, t: number): Vec {\n\t\treturn new Vec(A.x * t, A.y * t)\n\t}\n\n\tstatic DivV(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(A.x / B.x, A.y / B.y)\n\t}\n\n\tstatic MulV(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(A.x * B.x, A.y * B.y)\n\t}\n\n\tstatic Neg(A: VecLike): Vec {\n\t\treturn new Vec(-A.x, -A.y)\n\t}\n\n\t/**\n\t * Get the perpendicular vector to A.\n\t */\n\tstatic Per(A: VecLike): Vec {\n\t\treturn new Vec(A.y, -A.x)\n\t}\n\n\tstatic Abs(A: VecLike): Vec {\n\t\treturn new Vec(Math.abs(A.x), Math.abs(A.y))\n\t}\n\n\t// Get the distance between two points.\n\tstatic Dist(A: VecLike, B: VecLike): number {\n\t\treturn ((A.y - B.y) ** 2 + (A.x - B.x) ** 2) ** 0.5\n\t}\n\n\t// Get the Manhattan distance between two points.\n\tstatic ManhattanDist(A: VecLike, B: VecLike): number {\n\t\treturn Math.abs(A.x - B.x) + Math.abs(A.y - B.y)\n\t}\n\n\t// Get whether a distance between two points is less than a number. This is faster to calulate than using `Vec.Dist(a, b) < n`.\n\tstatic DistMin(A: VecLike, B: VecLike, n: number): boolean {\n\t\treturn (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y) < n ** 2\n\t}\n\n\t// Get the squared distance between two points. This is faster to calculate (no square root) so useful for \"minimum distance\" checks where the actual measurement does not matter.\n\tstatic Dist2(A: VecLike, B: VecLike): number {\n\t\treturn (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)\n\t}\n\n\t/**\n\t * Dot product of two vectors which is used to calculate the angle between them.\n\t */\n\tstatic Dpr(A: VecLike, B: VecLike): number {\n\t\treturn A.x * B.x + A.y * B.y\n\t}\n\n\tstatic Cross(A: VecLike, V: VecLike) {\n\t\treturn new Vec(\n\t\t\tA.y * V.z! - A.z! * V.y,\n\t\t\tA.z! * V.x - A.x * V.z!\n\t\t\t// A.z = A.x * V.y - A.y * V.x\n\t\t)\n\t}\n\n\t/**\n\t * Cross product of two vectors which is used to calculate the area of a parallelogram.\n\t */\n\tstatic Cpr(A: VecLike, B: VecLike) {\n\t\treturn A.x * B.y - B.x * A.y\n\t}\n\n\tstatic Len2(A: VecLike): number {\n\t\treturn A.x * A.x + A.y * A.y\n\t}\n\n\tstatic Len(A: VecLike): number {\n\t\treturn (A.x * A.x + A.y * A.y) ** 0.5\n\t}\n\n\t/**\n\t * Get the projection of A onto B.\n\t */\n\tstatic Pry(A: VecLike, B: VecLike): number {\n\t\treturn Vec.Dpr(A, B) / Vec.Len(B)\n\t}\n\n\t/**\n\t * Get the unit vector of A.\n\t */\n\tstatic Uni(A: VecLike) {\n\t\tconst l = Vec.Len(A)\n\t\treturn new Vec(l === 0 ? 0 : A.x / l, l === 0 ? 0 : A.y / l)\n\t}\n\n\tstatic Tan(A: VecLike, B: VecLike): Vec {\n\t\treturn Vec.Uni(Vec.Sub(A, B))\n\t}\n\n\tstatic Min(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(Math.min(A.x, B.x), Math.min(A.y, B.y))\n\t}\n\n\tstatic Max(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec(Math.max(A.x, B.x), Math.max(A.y, B.y))\n\t}\n\n\tstatic From({ x, y, z = 1 }: VecModel) {\n\t\treturn new Vec(x, y, z)\n\t}\n\n\tstatic FromArray(v: number[]): Vec {\n\t\treturn new Vec(v[0], v[1])\n\t}\n\n\tstatic Rot(A: VecLike, r = 0): Vec {\n\t\tconst s = Math.sin(r)\n\t\tconst c = Math.cos(r)\n\t\treturn new Vec(A.x * c - A.y * s, A.x * s + A.y * c)\n\t}\n\n\tstatic RotWith(A: VecLike, C: VecLike, r: number): Vec {\n\t\tconst x = A.x - C.x\n\t\tconst y = A.y - C.y\n\t\tconst s = Math.sin(r)\n\t\tconst c = Math.cos(r)\n\t\treturn new Vec(C.x + (x * c - y * s), C.y + (x * s + y * c))\n\t}\n\n\t/**\n\t * Get the nearest point on a line with a known unit vector that passes through point A\n\t *\n\t * ```ts\n\t * Vec.nearestPointOnLineThroughPoint(A, u, Point)\n\t * ```\n\t *\n\t * @param A - Any point on the line\n\t * @param u - The unit vector for the line.\n\t * @param P - A point not on the line to test.\n\t */\n\tstatic NearestPointOnLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): Vec {\n\t\treturn Vec.Mul(u, Vec.Sub(P, A).pry(u)).add(A)\n\t}\n\n\tstatic NearestPointOnLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp = true): Vec {\n\t\tif (Vec.Equals(A, P)) return Vec.From(P)\n\t\tif (Vec.Equals(B, P)) return Vec.From(P)\n\n\t\tconst u = Vec.Tan(B, A)\n\t\tconst C = Vec.Add(A, Vec.Mul(u, Vec.Sub(P, A).pry(u)))\n\n\t\tif (clamp) {\n\t\t\tif (C.x < Math.min(A.x, B.x)) return Vec.Cast(A.x < B.x ? A : B)\n\t\t\tif (C.x > Math.max(A.x, B.x)) return Vec.Cast(A.x > B.x ? A : B)\n\t\t\tif (C.y < Math.min(A.y, B.y)) return Vec.Cast(A.y < B.y ? A : B)\n\t\t\tif (C.y > Math.max(A.y, B.y)) return Vec.Cast(A.y > B.y ? A : B)\n\t\t}\n\n\t\treturn C\n\t}\n\n\tstatic DistanceToLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): number {\n\t\treturn Vec.Dist(P, Vec.NearestPointOnLineThroughPoint(A, u, P))\n\t}\n\n\tstatic DistanceToLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp = true): number {\n\t\treturn Vec.Dist(P, Vec.NearestPointOnLineSegment(A, B, P, clamp))\n\t}\n\n\tstatic Snap(A: VecLike, step = 1) {\n\t\treturn new Vec(Math.round(A.x / step) * step, Math.round(A.y / step) * step)\n\t}\n\n\tstatic Cast(A: VecLike): Vec {\n\t\tif (A instanceof Vec) return A\n\t\treturn Vec.From(A)\n\t}\n\n\tstatic Slope(A: VecLike, B: VecLike): number {\n\t\tif (A.x === B.y) return NaN\n\t\treturn (A.y - B.y) / (A.x - B.x)\n\t}\n\n\tstatic IsNaN(A: VecLike): boolean {\n\t\treturn isNaN(A.x) || isNaN(A.y)\n\t}\n\n\t/**\n\t * Get the angle from position A to position B.\n\t */\n\tstatic Angle(A: VecLike, B: VecLike): number {\n\t\treturn Math.atan2(B.y - A.y, B.x - A.x)\n\t}\n\n\t/**\n\t * Get the angle between vector A and vector B. This will return the smallest angle between the\n\t * two vectors, between -\u03C0 and \u03C0. The sign indicates direction of angle.\n\t */\n\tstatic AngleBetween(A: VecLike, B: VecLike): number {\n\t\tconst p = A.x * B.x + A.y * B.y\n\t\tconst n = Math.sqrt(\n\t\t\t(Math.pow(A.x, 2) + Math.pow(A.y, 2)) * (Math.pow(B.x, 2) + Math.pow(B.y, 2))\n\t\t)\n\t\tconst sign = A.x * B.y - A.y * B.x < 0 ? -1 : 1\n\t\tconst angle = sign * Math.acos(clamp(p / n, -1, 1))\n\n\t\treturn angle\n\t}\n\n\t/**\n\t * Linearly interpolate between two points.\n\t * @param A - The first point.\n\t * @param B - The second point.\n\t * @param t - The interpolation value between 0 and 1.\n\t * @returns The interpolated point.\n\t */\n\tstatic Lrp(A: VecLike, B: VecLike, t: number): Vec {\n\t\treturn Vec.Sub(B, A).mul(t).add(A)\n\t}\n\n\tstatic Med(A: VecLike, B: VecLike): Vec {\n\t\treturn new Vec((A.x + B.x) / 2, (A.y + B.y) / 2)\n\t}\n\n\tstatic Equals(A: VecLike, B: VecLike): boolean {\n\t\treturn Math.abs(A.x - B.x) < 0.0001 && Math.abs(A.y - B.y) < 0.0001\n\t}\n\n\tstatic EqualsXY(A: VecLike, x: number, y: number): boolean {\n\t\treturn A.x === x && A.y === y\n\t}\n\n\tstatic Clockwise(A: VecLike, B: VecLike, C: VecLike): boolean {\n\t\treturn (C.x - A.x) * (B.y - A.y) - (B.x - A.x) * (C.y - A.y) < 0\n\t}\n\n\tstatic Rescale(A: VecLike, n: number) {\n\t\tconst l = Vec.Len(A)\n\t\treturn new Vec((n * A.x) / l, (n * A.y) / l)\n\t}\n\n\tstatic ScaleWithOrigin(A: VecLike, scale: number, origin: VecLike) {\n\t\treturn Vec.Sub(A, origin).mul(scale).add(origin)\n\t}\n\n\tstatic ToFixed(A: VecLike) {\n\t\treturn new Vec(toFixed(A.x), toFixed(A.y))\n\t}\n\n\tstatic ToInt(A: VecLike) {\n\t\treturn new Vec(\n\t\t\tparseInt(A.x.toFixed(0)),\n\t\t\tparseInt(A.y.toFixed(0)),\n\t\t\tparseInt((A.z ?? 0).toFixed(0))\n\t\t)\n\t}\n\n\tstatic ToCss(A: VecLike) {\n\t\treturn `${A.x},${A.y}`\n\t}\n\n\tstatic Nudge(A: VecLike, B: VecLike, distance: number) {\n\t\treturn Vec.Add(A, Vec.Tan(B, A).mul(distance))\n\t}\n\n\tstatic ToString(A: VecLike) {\n\t\treturn `${A.x}, ${A.y}`\n\t}\n\n\tstatic ToAngle(A: VecLike) {\n\t\tlet r = Math.atan2(A.y, A.x)\n\t\tif (r < 0) r += Math.PI * 2\n\n\t\treturn r\n\t}\n\n\tstatic FromAngle(r: number, length = 1) {\n\t\treturn new Vec(Math.cos(r) * length, Math.sin(r) * length)\n\t}\n\n\tstatic ToArray(A: VecLike) {\n\t\treturn [A.x, A.y, A.z!]\n\t}\n\n\tstatic ToJson(A: VecLike) {\n\t\tconst { x, y, z } = A\n\t\treturn { x, y, z }\n\t}\n\n\tstatic Average(arr: VecLike[]) {\n\t\tconst len = arr.length\n\t\tconst avg = new Vec(0, 0)\n\t\tif (len === 0) {\n\t\t\treturn avg\n\t\t}\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tavg.add(arr[i])\n\t\t}\n\t\treturn avg.div(len)\n\t}\n\n\tstatic Clamp(A: Vec, min: number, max?: number) {\n\t\tif (max === undefined) {\n\t\t\treturn new Vec(Math.min(Math.max(A.x, min)), Math.min(Math.max(A.y, min)))\n\t\t}\n\n\t\treturn new Vec(Math.min(Math.max(A.x, min), max), Math.min(Math.max(A.y, min), max))\n\t}\n\n\t/**\n\t * Get an array of points (with simulated pressure) between two points.\n\t *\n\t * @param A - The first point.\n\t * @param B - The second point.\n\t * @param steps - The number of points to return.\n\t */\n\tstatic PointsBetween(A: VecModel, B: VecModel, steps = 6): Vec[] {\n\t\tconst results: Vec[] = []\n\n\t\tfor (let i = 0; i < steps; i++) {\n\t\t\tconst t = EASINGS.easeInQuad(i / (steps - 1))\n\t\t\tconst point = Vec.Lrp(A, B, t)\n\t\t\tpoint.z = Math.min(1, 0.5 + Math.abs(0.5 - ease(t)) * 0.65)\n\t\t\tresults.push(point)\n\t\t}\n\n\t\treturn results\n\t}\n\n\tstatic SnapToGrid(A: VecLike, gridSize = 8) {\n\t\treturn new Vec(Math.round(A.x / gridSize) * gridSize, Math.round(A.y / gridSize) * gridSize)\n\t}\n}\n\nconst ease = (t: number) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAwB;AACxB,mBAA+B;AAMxB,MAAM,IAAI;AAAA,EAChB,YACQ,IAAI,GACJ,IAAI,GACJ,IAAI,GACV;AAHM;AACA;AACA;AAAA,EACL;AAAA;AAAA,EAGH,IAAI,WAAW;AACd,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,IAAI,IAAI,KAAK,GAAG,IAAI,KAAK,GAAG,IAAI,KAAK,GAAG;AACvC,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI;AACT,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,GAAY;AACvC,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI;AACT,WAAO;AAAA,EACR;AAAA,EAEA,IAAI,GAAW;AACd,QAAI,MAAM,EAAG,QAAO;AACpB,UAAM,EAAE,GAAG,EAAE,IAAI;AACjB,UAAM,IAAI,KAAK,IAAI,CAAC;AACpB,UAAM,IAAI,KAAK,IAAI,CAAC;AACpB,SAAK,IAAI,IAAI,IAAI,IAAI;AACrB,SAAK,IAAI,IAAI,IAAI,IAAI;AACrB,WAAO;AAAA,EACR;AAAA,EAEA,QAAQ,GAAY,GAAW;AAC9B,QAAI,MAAM,EAAG,QAAO;AACpB,UAAM,IAAI,KAAK,IAAI,EAAE;AACrB,UAAM,IAAI,KAAK,IAAI,EAAE;AACrB,UAAM,IAAI,KAAK,IAAI,CAAC;AACpB,UAAM,IAAI,KAAK,IAAI,CAAC;AACpB,SAAK,IA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AC5C,YAAM,QAAQ,IAAI,IAAI,GAAG,GAAG,CAAC;AAC7B,YAAM,IAAI,KAAK,IAAI,GAAG,MAAM,KAAK,IAAI,MAAM,KAAK,CAAC,CAAC,IAAI,IAAI;AAC1D,cAAQ,KAAK,KAAK;AAAA,IACnB;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,OAAO,WAAW,GAAY,WAAW,GAAG;AAC3C,WAAO,IAAI,IAAI,KAAK,MAAM,EAAE,IAAI,QAAQ,IAAI,UAAU,KAAK,MAAM,EAAE,IAAI,QAAQ,IAAI,QAAQ;AAAA,EAC5F;AACD;AAEA,MAAM,OAAO,CAAC,MAAe,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,KAAK;",
6
6
  "names": ["clamp"]
7
7
  }
@@ -166,28 +166,36 @@ class Geometry2d {
166
166
  const distanceAlongRoute = closestSegment.distanceToStart + import_Vec.Vec.Dist(closestSegment.start, closestSegment.nearestPoint);
167
167
  return distanceAlongRoute / length;
168
168
  }
169
- /** @deprecated Iterate the vertices instead. */
170
- nearestPointOnLineSegment(A, B) {
171
- const { vertices } = this;
172
- let nearest;
173
- let dist = Infinity;
174
- let d, p, q;
175
- for (let i = 0; i < vertices.length; i++) {
176
- p = vertices[i];
177
- q = import_Vec.Vec.NearestPointOnLineSegment(A, B, p, true);
178
- d = import_Vec.Vec.Dist2(p, q);
179
- if (d < dist) {
180
- dist = d;
181
- nearest = q;
182
- }
183
- }
184
- if (!nearest) throw Error("nearest point not found");
185
- return nearest;
186
- }
187
169
  isPointInBounds(point, margin = 0) {
188
170
  const { bounds } = this;
189
171
  return !(point.x < bounds.minX - margin || point.y < bounds.minY - margin || point.x > bounds.maxX + margin || point.y > bounds.maxY + margin);
190
172
  }
173
+ overlapsPolygon(_polygon) {
174
+ const polygon = _polygon.map((v) => import_Vec.Vec.From(v));
175
+ const { vertices, center, isFilled, isEmptyLabel, isClosed } = this;
176
+ if (isEmptyLabel) return false;
177
+ if (vertices.some((v) => (0, import_utils2.pointInPolygon)(v, polygon))) {
178
+ return true;
179
+ }
180
+ if (isClosed) {
181
+ if (isFilled) {
182
+ if ((0, import_utils2.pointInPolygon)(center, polygon)) {
183
+ return true;
184
+ }
185
+ if (polygon.every((v) => (0, import_utils2.pointInPolygon)(v, vertices))) {
186
+ return true;
187
+ }
188
+ }
189
+ if ((0, import_intersect.polygonsIntersect)(polygon, vertices)) {
190
+ return true;
191
+ }
192
+ } else {
193
+ if ((0, import_intersect.polygonIntersectsPolyline)(polygon, vertices)) {
194
+ return true;
195
+ }
196
+ }
197
+ return false;
198
+ }
191
199
  transform(transform, opts) {
192
200
  return new TransformedGeometry2d(this, transform, opts);
193
201
  }