@tldraw/editor 3.9.0 → 3.10.0-canary.3bf31007c5a7

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 (131) hide show
  1. package/dist-cjs/index.d.ts +232 -3
  2. package/dist-cjs/index.js +9 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +32 -6
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/LiveCollaborators.js +5 -0
  7. package/dist-cjs/lib/components/LiveCollaborators.js.map +2 -2
  8. package/dist-cjs/lib/components/Shape.js +7 -0
  9. package/dist-cjs/lib/components/Shape.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultBrush.js.map +2 -2
  11. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
  12. package/dist-cjs/lib/components/default-components/DefaultCursor.js.map +2 -2
  13. package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
  14. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  15. package/dist-cjs/lib/editor/Editor.js +63 -7
  16. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  17. package/dist-cjs/lib/editor/managers/FontManager.js +166 -0
  18. package/dist-cjs/lib/editor/managers/FontManager.js.map +7 -0
  19. package/dist-cjs/lib/editor/managers/TextManager.js +23 -17
  20. package/dist-cjs/lib/editor/managers/TextManager.js.map +2 -2
  21. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +11 -0
  22. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  23. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  24. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  25. package/dist-cjs/lib/exports/FontEmbedder.js +7 -2
  26. package/dist-cjs/lib/exports/FontEmbedder.js.map +2 -2
  27. package/dist-cjs/lib/exports/StyleEmbedder.js +1 -1
  28. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  29. package/dist-cjs/lib/exports/exportToSvg.js +3 -2
  30. package/dist-cjs/lib/exports/exportToSvg.js.map +2 -2
  31. package/dist-cjs/lib/exports/getSvgJsx.js +18 -1
  32. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  33. package/dist-cjs/lib/exports/parseCss.js +1 -0
  34. package/dist-cjs/lib/exports/parseCss.js.map +2 -2
  35. package/dist-cjs/lib/hooks/useCanvasEvents.js +2 -2
  36. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  37. package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js +1 -1
  38. package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js.map +2 -2
  39. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +48 -0
  40. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +7 -0
  41. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  42. package/dist-cjs/lib/hooks/useViewportHeight.js +56 -0
  43. package/dist-cjs/lib/hooks/useViewportHeight.js.map +7 -0
  44. package/dist-cjs/lib/options.js +2 -1
  45. package/dist-cjs/lib/options.js.map +2 -2
  46. package/dist-cjs/lib/utils/dom.js +1 -1
  47. package/dist-cjs/lib/utils/dom.js.map +2 -2
  48. package/dist-cjs/lib/utils/richText.js +46 -0
  49. package/dist-cjs/lib/utils/richText.js.map +7 -0
  50. package/dist-cjs/version.js +3 -3
  51. package/dist-cjs/version.js.map +1 -1
  52. package/dist-esm/index.d.mts +232 -3
  53. package/dist-esm/index.mjs +13 -1
  54. package/dist-esm/index.mjs.map +2 -2
  55. package/dist-esm/lib/TldrawEditor.mjs +33 -7
  56. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  57. package/dist-esm/lib/components/LiveCollaborators.mjs +5 -0
  58. package/dist-esm/lib/components/LiveCollaborators.mjs.map +2 -2
  59. package/dist-esm/lib/components/Shape.mjs +8 -1
  60. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  61. package/dist-esm/lib/components/default-components/DefaultBrush.mjs.map +2 -2
  62. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
  63. package/dist-esm/lib/components/default-components/DefaultCursor.mjs.map +2 -2
  64. package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
  65. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  66. package/dist-esm/lib/editor/Editor.mjs +71 -8
  67. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  68. package/dist-esm/lib/editor/managers/FontManager.mjs +152 -0
  69. package/dist-esm/lib/editor/managers/FontManager.mjs.map +7 -0
  70. package/dist-esm/lib/editor/managers/TextManager.mjs +23 -17
  71. package/dist-esm/lib/editor/managers/TextManager.mjs.map +2 -2
  72. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +11 -0
  73. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  74. package/dist-esm/lib/exports/FontEmbedder.mjs +7 -2
  75. package/dist-esm/lib/exports/FontEmbedder.mjs.map +2 -2
  76. package/dist-esm/lib/exports/StyleEmbedder.mjs +1 -1
  77. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  78. package/dist-esm/lib/exports/exportToSvg.mjs +3 -2
  79. package/dist-esm/lib/exports/exportToSvg.mjs.map +2 -2
  80. package/dist-esm/lib/exports/getSvgJsx.mjs +19 -2
  81. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  82. package/dist-esm/lib/exports/parseCss.mjs +1 -0
  83. package/dist-esm/lib/exports/parseCss.mjs.map +2 -2
  84. package/dist-esm/lib/hooks/useCanvasEvents.mjs +2 -2
  85. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  86. package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs +1 -1
  87. package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs.map +2 -2
  88. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +28 -0
  89. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +7 -0
  90. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  91. package/dist-esm/lib/hooks/useViewportHeight.mjs +36 -0
  92. package/dist-esm/lib/hooks/useViewportHeight.mjs.map +7 -0
  93. package/dist-esm/lib/options.mjs +2 -1
  94. package/dist-esm/lib/options.mjs.map +2 -2
  95. package/dist-esm/lib/utils/dom.mjs +1 -1
  96. package/dist-esm/lib/utils/dom.mjs.map +2 -2
  97. package/dist-esm/lib/utils/richText.mjs +26 -0
  98. package/dist-esm/lib/utils/richText.mjs.map +7 -0
  99. package/dist-esm/version.mjs +3 -3
  100. package/dist-esm/version.mjs.map +1 -1
  101. package/editor.css +127 -13
  102. package/package.json +10 -7
  103. package/src/index.ts +15 -0
  104. package/src/lib/TldrawEditor.tsx +52 -4
  105. package/src/lib/components/LiveCollaborators.tsx +5 -0
  106. package/src/lib/components/Shape.tsx +9 -1
  107. package/src/lib/components/default-components/DefaultBrush.tsx +1 -0
  108. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -0
  109. package/src/lib/components/default-components/DefaultCursor.tsx +1 -0
  110. package/src/lib/components/default-components/DefaultScribble.tsx +1 -0
  111. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +1 -0
  112. package/src/lib/editor/Editor.ts +91 -6
  113. package/src/lib/editor/managers/FontManager.ts +251 -0
  114. package/src/lib/editor/managers/TextManager.ts +42 -17
  115. package/src/lib/editor/shapes/ShapeUtil.ts +13 -0
  116. package/src/lib/editor/types/emit-types.ts +1 -0
  117. package/src/lib/editor/types/external-content.ts +1 -0
  118. package/src/lib/exports/FontEmbedder.ts +13 -1
  119. package/src/lib/exports/StyleEmbedder.ts +1 -1
  120. package/src/lib/exports/exportToSvg.tsx +4 -3
  121. package/src/lib/exports/getSvgJsx.tsx +22 -2
  122. package/src/lib/exports/parseCss.ts +1 -0
  123. package/src/lib/hooks/useCanvasEvents.ts +2 -1
  124. package/src/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.ts +1 -0
  125. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +29 -0
  126. package/src/lib/hooks/usePassThroughWheelEvents.ts +0 -1
  127. package/src/lib/hooks/useViewportHeight.ts +37 -0
  128. package/src/lib/options.ts +7 -0
  129. package/src/lib/utils/dom.ts +1 -1
  130. package/src/lib/utils/richText.ts +72 -0
  131. package/src/version.ts +3 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/options.ts"],
4
- "sourcesContent": ["import { ComponentType, Fragment } from 'react'\n\n/**\n * Options for configuring tldraw. For defaults, see {@link defaultTldrawOptions}.\n *\n * @example\n * ```tsx\n * const options: Partial<TldrawOptions> = {\n * maxPages: 3,\n * maxShapesPerPage: 1000,\n * }\n *\n * function MyTldrawComponent() {\n * return <Tldraw options={options} />\n * }\n * ```\n *\n * @public\n */\nexport interface TldrawOptions {\n\treadonly maxShapesPerPage: number\n\treadonly maxFilesAtOnce: number\n\treadonly maxPages: number\n\treadonly animationMediumMs: number\n\treadonly followChaseViewportSnap: number\n\treadonly doubleClickDurationMs: number\n\treadonly multiClickDurationMs: number\n\treadonly coarseDragDistanceSquared: number\n\treadonly dragDistanceSquared: number\n\treadonly defaultSvgPadding: number\n\treadonly cameraSlideFriction: number\n\treadonly gridSteps: readonly {\n\t\treadonly min: number\n\t\treadonly mid: number\n\t\treadonly step: number\n\t}[]\n\treadonly collaboratorInactiveTimeoutMs: number\n\treadonly collaboratorIdleTimeoutMs: number\n\treadonly collaboratorCheckIntervalMs: number\n\treadonly cameraMovingTimeoutMs: number\n\treadonly hitTestMargin: number\n\treadonly edgeScrollDelay: number\n\treadonly edgeScrollEaseDuration: number\n\treadonly edgeScrollSpeed: number\n\treadonly edgeScrollDistance: number\n\treadonly coarsePointerWidth: number\n\treadonly coarseHandleRadius: number\n\treadonly handleRadius: number\n\treadonly longPressDurationMs: number\n\treadonly textShadowLod: number\n\treadonly adjacentShapeMargin: number\n\treadonly flattenImageBoundsExpand: number\n\treadonly flattenImageBoundsPadding: number\n\treadonly laserDelayMs: number\n\treadonly maxExportDelayMs: number\n\t/**\n\t * How long should previews created by {@link Editor.createTemporaryAssetPreview} last before\n\t * they expire? Defaults to 3 minutes.\n\t */\n\treadonly temporaryAssetPreviewLifetimeMs: number\n\treadonly actionShortcutsLocation: 'menu' | 'toolbar' | 'swap'\n\treadonly createTextOnCanvasDoubleClick: boolean\n\t/**\n\t * The react provider to use when exporting an image. This is useful if your shapes depend on\n\t * external context providers. By default, this is `React.Fragment`.\n\t */\n\treadonly exportProvider: ComponentType<{ children: React.ReactNode }>\n\t/**\n\t * By default, the toolbar items are accessible via number shortcuts according to their order. To disable this, set this option to false.\n\t */\n\treadonly enableToolbarKeyboardShortcuts: boolean\n}\n\n/** @public */\nexport const defaultTldrawOptions = {\n\tmaxShapesPerPage: 4000,\n\tmaxFilesAtOnce: 100,\n\tmaxPages: 40,\n\tanimationMediumMs: 320,\n\tfollowChaseViewportSnap: 2,\n\tdoubleClickDurationMs: 450,\n\tmultiClickDurationMs: 200,\n\tcoarseDragDistanceSquared: 36, // 6 squared\n\tdragDistanceSquared: 16, // 4 squared\n\tdefaultSvgPadding: 32,\n\tcameraSlideFriction: 0.09,\n\tgridSteps: [\n\t\t{ min: -1, mid: 0.15, step: 64 },\n\t\t{ min: 0.05, mid: 0.375, step: 16 },\n\t\t{ min: 0.15, mid: 1, step: 4 },\n\t\t{ min: 0.7, mid: 2.5, step: 1 },\n\t],\n\tcollaboratorInactiveTimeoutMs: 60000,\n\tcollaboratorIdleTimeoutMs: 3000,\n\tcollaboratorCheckIntervalMs: 1200,\n\tcameraMovingTimeoutMs: 64,\n\thitTestMargin: 8,\n\tedgeScrollDelay: 200,\n\tedgeScrollEaseDuration: 200,\n\tedgeScrollSpeed: 25,\n\tedgeScrollDistance: 8,\n\tcoarsePointerWidth: 12,\n\tcoarseHandleRadius: 20,\n\thandleRadius: 12,\n\tlongPressDurationMs: 500,\n\ttextShadowLod: 0.35,\n\tadjacentShapeMargin: 10,\n\tflattenImageBoundsExpand: 64,\n\tflattenImageBoundsPadding: 16,\n\tlaserDelayMs: 1200,\n\tmaxExportDelayMs: 5000,\n\ttemporaryAssetPreviewLifetimeMs: 180000,\n\tactionShortcutsLocation: 'swap',\n\tcreateTextOnCanvasDoubleClick: true,\n\texportProvider: Fragment,\n\tenableToolbarKeyboardShortcuts: true,\n} as const satisfies TldrawOptions\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwC;AA0EjC,MAAM,uBAAuB;AAAA,EACnC,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,yBAAyB;AAAA,EACzB,uBAAuB;AAAA,EACvB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA;AAAA,EAC3B,qBAAqB;AAAA;AAAA,EACrB,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,WAAW;AAAA,IACV,EAAE,KAAK,IAAI,KAAK,MAAM,MAAM,GAAG;AAAA,IAC/B,EAAE,KAAK,MAAM,KAAK,OAAO,MAAM,GAAG;AAAA,IAClC,EAAE,KAAK,MAAM,KAAK,GAAG,MAAM,EAAE;AAAA,IAC7B,EAAE,KAAK,KAAK,KAAK,KAAK,MAAM,EAAE;AAAA,EAC/B;AAAA,EACA,+BAA+B;AAAA,EAC/B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,uBAAuB;AAAA,EACvB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,wBAAwB;AAAA,EACxB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,qBAAqB;AAAA,EACrB,eAAe;AAAA,EACf,qBAAqB;AAAA,EACrB,0BAA0B;AAAA,EAC1B,2BAA2B;AAAA,EAC3B,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,iCAAiC;AAAA,EACjC,yBAAyB;AAAA,EACzB,+BAA+B;AAAA,EAC/B,gBAAgB;AAAA,EAChB,gCAAgC;AACjC;",
4
+ "sourcesContent": ["import { ComponentType, Fragment } from 'react'\n\n/**\n * Options for configuring tldraw. For defaults, see {@link defaultTldrawOptions}.\n *\n * @example\n * ```tsx\n * const options: Partial<TldrawOptions> = {\n * maxPages: 3,\n * maxShapesPerPage: 1000,\n * }\n *\n * function MyTldrawComponent() {\n * return <Tldraw options={options} />\n * }\n * ```\n *\n * @public\n */\nexport interface TldrawOptions {\n\treadonly maxShapesPerPage: number\n\treadonly maxFilesAtOnce: number\n\treadonly maxPages: number\n\treadonly animationMediumMs: number\n\treadonly followChaseViewportSnap: number\n\treadonly doubleClickDurationMs: number\n\treadonly multiClickDurationMs: number\n\treadonly coarseDragDistanceSquared: number\n\treadonly dragDistanceSquared: number\n\treadonly defaultSvgPadding: number\n\treadonly cameraSlideFriction: number\n\treadonly gridSteps: readonly {\n\t\treadonly min: number\n\t\treadonly mid: number\n\t\treadonly step: number\n\t}[]\n\treadonly collaboratorInactiveTimeoutMs: number\n\treadonly collaboratorIdleTimeoutMs: number\n\treadonly collaboratorCheckIntervalMs: number\n\treadonly cameraMovingTimeoutMs: number\n\treadonly hitTestMargin: number\n\treadonly edgeScrollDelay: number\n\treadonly edgeScrollEaseDuration: number\n\treadonly edgeScrollSpeed: number\n\treadonly edgeScrollDistance: number\n\treadonly coarsePointerWidth: number\n\treadonly coarseHandleRadius: number\n\treadonly handleRadius: number\n\treadonly longPressDurationMs: number\n\treadonly textShadowLod: number\n\treadonly adjacentShapeMargin: number\n\treadonly flattenImageBoundsExpand: number\n\treadonly flattenImageBoundsPadding: number\n\treadonly laserDelayMs: number\n\treadonly maxExportDelayMs: number\n\t/**\n\t * How long should previews created by {@link Editor.createTemporaryAssetPreview} last before\n\t * they expire? Defaults to 3 minutes.\n\t */\n\treadonly temporaryAssetPreviewLifetimeMs: number\n\treadonly actionShortcutsLocation: 'menu' | 'toolbar' | 'swap'\n\treadonly createTextOnCanvasDoubleClick: boolean\n\t/**\n\t * The react provider to use when exporting an image. This is useful if your shapes depend on\n\t * external context providers. By default, this is `React.Fragment`.\n\t */\n\treadonly exportProvider: ComponentType<{ children: React.ReactNode }>\n\t/**\n\t * By default, the toolbar items are accessible via number shortcuts according to their order. To disable this, set this option to false.\n\t */\n\treadonly enableToolbarKeyboardShortcuts: boolean\n\t/**\n\t * The maximum number of fonts that will be loaded while blocking the main rendering of the\n\t * canvas. If there are more than this number of fonts needed, we'll just show the canvas right\n\t * away and let the fonts load in in the background.\n\t */\n\treadonly maxFontsToLoadBeforeRender: number\n}\n\n/** @public */\nexport const defaultTldrawOptions = {\n\tmaxShapesPerPage: 4000,\n\tmaxFilesAtOnce: 100,\n\tmaxPages: 40,\n\tanimationMediumMs: 320,\n\tfollowChaseViewportSnap: 2,\n\tdoubleClickDurationMs: 450,\n\tmultiClickDurationMs: 200,\n\tcoarseDragDistanceSquared: 36, // 6 squared\n\tdragDistanceSquared: 16, // 4 squared\n\tdefaultSvgPadding: 32,\n\tcameraSlideFriction: 0.09,\n\tgridSteps: [\n\t\t{ min: -1, mid: 0.15, step: 64 },\n\t\t{ min: 0.05, mid: 0.375, step: 16 },\n\t\t{ min: 0.15, mid: 1, step: 4 },\n\t\t{ min: 0.7, mid: 2.5, step: 1 },\n\t],\n\tcollaboratorInactiveTimeoutMs: 60000,\n\tcollaboratorIdleTimeoutMs: 3000,\n\tcollaboratorCheckIntervalMs: 1200,\n\tcameraMovingTimeoutMs: 64,\n\thitTestMargin: 8,\n\tedgeScrollDelay: 200,\n\tedgeScrollEaseDuration: 200,\n\tedgeScrollSpeed: 25,\n\tedgeScrollDistance: 8,\n\tcoarsePointerWidth: 12,\n\tcoarseHandleRadius: 20,\n\thandleRadius: 12,\n\tlongPressDurationMs: 500,\n\ttextShadowLod: 0.35,\n\tadjacentShapeMargin: 10,\n\tflattenImageBoundsExpand: 64,\n\tflattenImageBoundsPadding: 16,\n\tlaserDelayMs: 1200,\n\tmaxExportDelayMs: 5000,\n\ttemporaryAssetPreviewLifetimeMs: 180000,\n\tactionShortcutsLocation: 'swap',\n\tcreateTextOnCanvasDoubleClick: true,\n\texportProvider: Fragment,\n\tenableToolbarKeyboardShortcuts: true,\n\tmaxFontsToLoadBeforeRender: Infinity,\n} as const satisfies TldrawOptions\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwC;AAgFjC,MAAM,uBAAuB;AAAA,EACnC,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,yBAAyB;AAAA,EACzB,uBAAuB;AAAA,EACvB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA;AAAA,EAC3B,qBAAqB;AAAA;AAAA,EACrB,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,WAAW;AAAA,IACV,EAAE,KAAK,IAAI,KAAK,MAAM,MAAM,GAAG;AAAA,IAC/B,EAAE,KAAK,MAAM,KAAK,OAAO,MAAM,GAAG;AAAA,IAClC,EAAE,KAAK,MAAM,KAAK,GAAG,MAAM,EAAE;AAAA,IAC7B,EAAE,KAAK,KAAK,KAAK,KAAK,MAAM,EAAE;AAAA,EAC/B;AAAA,EACA,+BAA+B;AAAA,EAC/B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,uBAAuB;AAAA,EACvB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,wBAAwB;AAAA,EACxB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,qBAAqB;AAAA,EACrB,eAAe;AAAA,EACf,qBAAqB;AAAA,EACrB,0BAA0B;AAAA,EAC1B,2BAA2B;AAAA,EAC3B,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,iCAAiC;AAAA,EACjC,yBAAyB;AAAA,EACzB,+BAA+B;AAAA,EAC/B,gBAAgB;AAAA,EAChB,gCAAgC;AAAA,EAChC,4BAA4B;AAC7B;",
6
6
  "names": []
7
7
  }
@@ -72,6 +72,6 @@ const setStyleProperty = (elm, property, value) => {
72
72
  const INPUTS = ["input", "select", "button", "textarea"];
73
73
  function activeElementShouldCaptureKeys() {
74
74
  const { activeElement } = document;
75
- return !!(activeElement && (activeElement.getAttribute("contenteditable") || INPUTS.indexOf(activeElement.tagName.toLowerCase()) > -1));
75
+ return !!(activeElement && (activeElement.isContentEditable || INPUTS.indexOf(activeElement.tagName.toLowerCase()) > -1));
76
76
  }
77
77
  //# sourceMappingURL=dom.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/utils/dom.ts"],
4
- "sourcesContent": ["/*\nThis is used to facilitate double clicking and pointer capture on elements.\n\nThe events in this file are possibly set on individual SVG elements, \nsuch as handles or corner handles, rather than on HTML elements or \nSVGSVGElements. Raw SVG elemnets do not support pointerCapture in \nmost cases, meaning that in order for pointer capture to work, we \nneed to crawl up the DOM tree to find the nearest HTML element. Then,\nin order for that element to also call the `onPointerUp` event from\nthis file, we need to manually set that event on that element and\nlater remove it when the pointerup occurs. This is a potential leak\nif the user clicks on a handle but the pointerup does not fire for\nwhatever reason.\n*/\n\nimport React from 'react'\nimport { debugFlags, pointerCaptureTrackingObject } from './debug-flags'\n\n/** @public */\nexport function loopToHtmlElement(elm: Element): HTMLElement {\n\tif (elm instanceof HTMLElement) return elm\n\tif (elm.parentElement) return loopToHtmlElement(elm.parentElement)\n\telse throw Error('Could not find a parent element of an HTML type!')\n}\n\n/**\n * This function calls `event.preventDefault()` for you. Why is that useful?\n *\n * Beacuase if you enable `window.preventDefaultLogging = true` it'll log out a message when it\n * happens. Because we use console.warn rather than (log) you'll get a stack trace in the inspector\n * telling you exactly where it happened. This is important because `e.preventDefault()` is the\n * source of many bugs, but unfortuantly it can't be avoided because it also stops a lot of default\n * behaviour which doesn't make sense in our UI\n *\n * @param event - To prevent default on\n * @public\n */\nexport function preventDefault(event: React.BaseSyntheticEvent | Event) {\n\tevent.preventDefault()\n\tif (debugFlags.logPreventDefaults.get()) {\n\t\tconsole.warn('preventDefault called on event:', event)\n\t}\n}\n\n/** @public */\nexport function setPointerCapture(\n\telement: Element,\n\tevent: React.PointerEvent<Element> | PointerEvent\n) {\n\telement.setPointerCapture(event.pointerId)\n\tif (debugFlags.logPointerCaptures.get()) {\n\t\tconst trackingObj = pointerCaptureTrackingObject.get()\n\t\ttrackingObj.set(element, (trackingObj.get(element) ?? 0) + 1)\n\t\tconsole.warn('setPointerCapture called on element:', element, event)\n\t}\n}\n\n/** @public */\nexport function releasePointerCapture(\n\telement: Element,\n\tevent: React.PointerEvent<Element> | PointerEvent\n) {\n\tif (!element.hasPointerCapture(event.pointerId)) {\n\t\treturn\n\t}\n\n\telement.releasePointerCapture(event.pointerId)\n\tif (debugFlags.logPointerCaptures.get()) {\n\t\tconst trackingObj = pointerCaptureTrackingObject.get()\n\t\tif (trackingObj.get(element) === 1) {\n\t\t\ttrackingObj.delete(element)\n\t\t} else if (trackingObj.has(element)) {\n\t\t\ttrackingObj.set(element, trackingObj.get(element)! - 1)\n\t\t} else {\n\t\t\tconsole.warn('Release without capture')\n\t\t}\n\t\tconsole.warn('releasePointerCapture called on element:', element, event)\n\t}\n}\n\n/** @public */\nexport const stopEventPropagation = (e: any) => e.stopPropagation()\n\n/** @internal */\nexport const setStyleProperty = (\n\telm: HTMLElement | null,\n\tproperty: string,\n\tvalue: string | number\n) => {\n\tif (!elm) return\n\telm.style.setProperty(property, value as string)\n}\n\nconst INPUTS = ['input', 'select', 'button', 'textarea']\n\n/** @internal */\nexport function activeElementShouldCaptureKeys() {\n\tconst { activeElement } = document\n\treturn !!(\n\t\tactiveElement &&\n\t\t(activeElement.getAttribute('contenteditable') ||\n\t\t\tINPUTS.indexOf(activeElement.tagName.toLowerCase()) > -1)\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,yBAAyD;AAGlD,SAAS,kBAAkB,KAA2B;AAC5D,MAAI,eAAe,YAAa,QAAO;AACvC,MAAI,IAAI,cAAe,QAAO,kBAAkB,IAAI,aAAa;AAAA,MAC5D,OAAM,MAAM,kDAAkD;AACpE;AAcO,SAAS,eAAe,OAAyC;AACvE,QAAM,eAAe;AACrB,MAAI,8BAAW,mBAAmB,IAAI,GAAG;AACxC,YAAQ,KAAK,mCAAmC,KAAK;AAAA,EACtD;AACD;AAGO,SAAS,kBACf,SACA,OACC;AACD,UAAQ,kBAAkB,MAAM,SAAS;AACzC,MAAI,8BAAW,mBAAmB,IAAI,GAAG;AACxC,UAAM,cAAc,gDAA6B,IAAI;AACrD,gBAAY,IAAI,UAAU,YAAY,IAAI,OAAO,KAAK,KAAK,CAAC;AAC5D,YAAQ,KAAK,wCAAwC,SAAS,KAAK;AAAA,EACpE;AACD;AAGO,SAAS,sBACf,SACA,OACC;AACD,MAAI,CAAC,QAAQ,kBAAkB,MAAM,SAAS,GAAG;AAChD;AAAA,EACD;AAEA,UAAQ,sBAAsB,MAAM,SAAS;AAC7C,MAAI,8BAAW,mBAAmB,IAAI,GAAG;AACxC,UAAM,cAAc,gDAA6B,IAAI;AACrD,QAAI,YAAY,IAAI,OAAO,MAAM,GAAG;AACnC,kBAAY,OAAO,OAAO;AAAA,IAC3B,WAAW,YAAY,IAAI,OAAO,GAAG;AACpC,kBAAY,IAAI,SAAS,YAAY,IAAI,OAAO,IAAK,CAAC;AAAA,IACvD,OAAO;AACN,cAAQ,KAAK,yBAAyB;AAAA,IACvC;AACA,YAAQ,KAAK,4CAA4C,SAAS,KAAK;AAAA,EACxE;AACD;AAGO,MAAM,uBAAuB,CAAC,MAAW,EAAE,gBAAgB;AAG3D,MAAM,mBAAmB,CAC/B,KACA,UACA,UACI;AACJ,MAAI,CAAC,IAAK;AACV,MAAI,MAAM,YAAY,UAAU,KAAe;AAChD;AAEA,MAAM,SAAS,CAAC,SAAS,UAAU,UAAU,UAAU;AAGhD,SAAS,iCAAiC;AAChD,QAAM,EAAE,cAAc,IAAI;AAC1B,SAAO,CAAC,EACP,kBACC,cAAc,aAAa,iBAAiB,KAC5C,OAAO,QAAQ,cAAc,QAAQ,YAAY,CAAC,IAAI;AAEzD;",
4
+ "sourcesContent": ["/*\nThis is used to facilitate double clicking and pointer capture on elements.\n\nThe events in this file are possibly set on individual SVG elements, \nsuch as handles or corner handles, rather than on HTML elements or \nSVGSVGElements. Raw SVG elemnets do not support pointerCapture in \nmost cases, meaning that in order for pointer capture to work, we \nneed to crawl up the DOM tree to find the nearest HTML element. Then,\nin order for that element to also call the `onPointerUp` event from\nthis file, we need to manually set that event on that element and\nlater remove it when the pointerup occurs. This is a potential leak\nif the user clicks on a handle but the pointerup does not fire for\nwhatever reason.\n*/\n\nimport React from 'react'\nimport { debugFlags, pointerCaptureTrackingObject } from './debug-flags'\n\n/** @public */\nexport function loopToHtmlElement(elm: Element): HTMLElement {\n\tif (elm instanceof HTMLElement) return elm\n\tif (elm.parentElement) return loopToHtmlElement(elm.parentElement)\n\telse throw Error('Could not find a parent element of an HTML type!')\n}\n\n/**\n * This function calls `event.preventDefault()` for you. Why is that useful?\n *\n * Beacuase if you enable `window.preventDefaultLogging = true` it'll log out a message when it\n * happens. Because we use console.warn rather than (log) you'll get a stack trace in the inspector\n * telling you exactly where it happened. This is important because `e.preventDefault()` is the\n * source of many bugs, but unfortuantly it can't be avoided because it also stops a lot of default\n * behaviour which doesn't make sense in our UI\n *\n * @param event - To prevent default on\n * @public\n */\nexport function preventDefault(event: React.BaseSyntheticEvent | Event) {\n\tevent.preventDefault()\n\tif (debugFlags.logPreventDefaults.get()) {\n\t\tconsole.warn('preventDefault called on event:', event)\n\t}\n}\n\n/** @public */\nexport function setPointerCapture(\n\telement: Element,\n\tevent: React.PointerEvent<Element> | PointerEvent\n) {\n\telement.setPointerCapture(event.pointerId)\n\tif (debugFlags.logPointerCaptures.get()) {\n\t\tconst trackingObj = pointerCaptureTrackingObject.get()\n\t\ttrackingObj.set(element, (trackingObj.get(element) ?? 0) + 1)\n\t\tconsole.warn('setPointerCapture called on element:', element, event)\n\t}\n}\n\n/** @public */\nexport function releasePointerCapture(\n\telement: Element,\n\tevent: React.PointerEvent<Element> | PointerEvent\n) {\n\tif (!element.hasPointerCapture(event.pointerId)) {\n\t\treturn\n\t}\n\n\telement.releasePointerCapture(event.pointerId)\n\tif (debugFlags.logPointerCaptures.get()) {\n\t\tconst trackingObj = pointerCaptureTrackingObject.get()\n\t\tif (trackingObj.get(element) === 1) {\n\t\t\ttrackingObj.delete(element)\n\t\t} else if (trackingObj.has(element)) {\n\t\t\ttrackingObj.set(element, trackingObj.get(element)! - 1)\n\t\t} else {\n\t\t\tconsole.warn('Release without capture')\n\t\t}\n\t\tconsole.warn('releasePointerCapture called on element:', element, event)\n\t}\n}\n\n/** @public */\nexport const stopEventPropagation = (e: any) => e.stopPropagation()\n\n/** @internal */\nexport const setStyleProperty = (\n\telm: HTMLElement | null,\n\tproperty: string,\n\tvalue: string | number\n) => {\n\tif (!elm) return\n\telm.style.setProperty(property, value as string)\n}\n\nconst INPUTS = ['input', 'select', 'button', 'textarea']\n\n/** @internal */\nexport function activeElementShouldCaptureKeys() {\n\tconst { activeElement } = document\n\treturn !!(\n\t\tactiveElement &&\n\t\t((activeElement as HTMLElement).isContentEditable ||\n\t\t\tINPUTS.indexOf(activeElement.tagName.toLowerCase()) > -1)\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,yBAAyD;AAGlD,SAAS,kBAAkB,KAA2B;AAC5D,MAAI,eAAe,YAAa,QAAO;AACvC,MAAI,IAAI,cAAe,QAAO,kBAAkB,IAAI,aAAa;AAAA,MAC5D,OAAM,MAAM,kDAAkD;AACpE;AAcO,SAAS,eAAe,OAAyC;AACvE,QAAM,eAAe;AACrB,MAAI,8BAAW,mBAAmB,IAAI,GAAG;AACxC,YAAQ,KAAK,mCAAmC,KAAK;AAAA,EACtD;AACD;AAGO,SAAS,kBACf,SACA,OACC;AACD,UAAQ,kBAAkB,MAAM,SAAS;AACzC,MAAI,8BAAW,mBAAmB,IAAI,GAAG;AACxC,UAAM,cAAc,gDAA6B,IAAI;AACrD,gBAAY,IAAI,UAAU,YAAY,IAAI,OAAO,KAAK,KAAK,CAAC;AAC5D,YAAQ,KAAK,wCAAwC,SAAS,KAAK;AAAA,EACpE;AACD;AAGO,SAAS,sBACf,SACA,OACC;AACD,MAAI,CAAC,QAAQ,kBAAkB,MAAM,SAAS,GAAG;AAChD;AAAA,EACD;AAEA,UAAQ,sBAAsB,MAAM,SAAS;AAC7C,MAAI,8BAAW,mBAAmB,IAAI,GAAG;AACxC,UAAM,cAAc,gDAA6B,IAAI;AACrD,QAAI,YAAY,IAAI,OAAO,MAAM,GAAG;AACnC,kBAAY,OAAO,OAAO;AAAA,IAC3B,WAAW,YAAY,IAAI,OAAO,GAAG;AACpC,kBAAY,IAAI,SAAS,YAAY,IAAI,OAAO,IAAK,CAAC;AAAA,IACvD,OAAO;AACN,cAAQ,KAAK,yBAAyB;AAAA,IACvC;AACA,YAAQ,KAAK,4CAA4C,SAAS,KAAK;AAAA,EACxE;AACD;AAGO,MAAM,uBAAuB,CAAC,MAAW,EAAE,gBAAgB;AAG3D,MAAM,mBAAmB,CAC/B,KACA,UACA,UACI;AACJ,MAAI,CAAC,IAAK;AACV,MAAI,MAAM,YAAY,UAAU,KAAe;AAChD;AAEA,MAAM,SAAS,CAAC,SAAS,UAAU,UAAU,UAAU;AAGhD,SAAS,iCAAiC;AAChD,QAAM,EAAE,cAAc,IAAI;AAC1B,SAAO,CAAC,EACP,kBACE,cAA8B,qBAC/B,OAAO,QAAQ,cAAc,QAAQ,YAAY,CAAC,IAAI;AAEzD;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var richText_exports = {};
20
+ __export(richText_exports, {
21
+ getFontsFromRichText: () => getFontsFromRichText
22
+ });
23
+ module.exports = __toCommonJS(richText_exports);
24
+ var import_core = require("@tiptap/core");
25
+ var import_model = require("@tiptap/pm/model");
26
+ var import_utils = require("@tldraw/utils");
27
+ function getFontsFromRichText(editor, richText, initialState) {
28
+ const { tipTapConfig, addFontsFromNode } = editor.getTextOptions();
29
+ (0, import_utils.assert)(tipTapConfig, "textOptions.tipTapConfig must be set to use rich text");
30
+ (0, import_utils.assert)(addFontsFromNode, "textOptions.addFontsFromNode must be set to use rich text");
31
+ const schema = (0, import_core.getSchema)(tipTapConfig.extensions ?? []);
32
+ const rootNode = import_model.Node.fromJSON(schema, richText);
33
+ const fonts = /* @__PURE__ */ new Set();
34
+ function addFont(font) {
35
+ fonts.add(font);
36
+ }
37
+ function visit(node, state) {
38
+ state = addFontsFromNode(node, state, addFont);
39
+ for (const child of node.children) {
40
+ visit(child, state);
41
+ }
42
+ }
43
+ visit(rootNode, initialState);
44
+ return Array.from(fonts);
45
+ }
46
+ //# sourceMappingURL=richText.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/utils/richText.ts"],
4
+ "sourcesContent": ["import { getSchema, JSONContent, Editor as TTEditor } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\nimport { EditorProviderProps } from '@tiptap/react'\nimport { TLRichText } from '@tldraw/tlschema'\nimport { assert } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { TLFontFace } from '../editor/managers/FontManager'\n\n/**\n * This is the TipTap editor! Docs are {@link https://tiptap.dev/docs}.\n *\n * @public\n */\nexport type TiptapEditor = TTEditor\n\n/**\n * A TipTap node. See {@link https://tiptap.dev/docs}.\n * @public\n */\nexport type TiptapNode = Node\n\n/** @public */\nexport interface TLTextOptions {\n\ttipTapConfig?: EditorProviderProps\n\taddFontsFromNode?: RichTextFontVisitor\n}\n\n/** @public */\nexport interface RichTextFontVisitorState {\n\treadonly family: string\n\treadonly weight: string\n\treadonly style: string\n}\n\n/** @public */\nexport type RichTextFontVisitor = (\n\tnode: TiptapNode,\n\tstate: RichTextFontVisitorState,\n\taddFont: (font: TLFontFace) => void\n) => RichTextFontVisitorState\n\n/** @public */\nexport function getFontsFromRichText(\n\teditor: Editor,\n\trichText: TLRichText,\n\tinitialState: RichTextFontVisitorState\n) {\n\tconst { tipTapConfig, addFontsFromNode } = editor.getTextOptions()\n\tassert(tipTapConfig, 'textOptions.tipTapConfig must be set to use rich text')\n\tassert(addFontsFromNode, 'textOptions.addFontsFromNode must be set to use rich text')\n\n\tconst schema = getSchema(tipTapConfig.extensions ?? [])\n\tconst rootNode = Node.fromJSON(schema, richText as JSONContent)\n\n\tconst fonts = new Set<TLFontFace>()\n\n\tfunction addFont(font: TLFontFace) {\n\t\tfonts.add(font)\n\t}\n\n\tfunction visit(node: TiptapNode, state: RichTextFontVisitorState) {\n\t\tstate = addFontsFromNode!(node, state, addFont)\n\n\t\tfor (const child of node.children) {\n\t\t\tvisit(child, state)\n\t\t}\n\t}\n\n\tvisit(rootNode, initialState)\n\n\treturn Array.from(fonts)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2D;AAC3D,mBAAqB;AAGrB,mBAAuB;AAsChB,SAAS,qBACf,QACA,UACA,cACC;AACD,QAAM,EAAE,cAAc,iBAAiB,IAAI,OAAO,eAAe;AACjE,2BAAO,cAAc,uDAAuD;AAC5E,2BAAO,kBAAkB,2DAA2D;AAEpF,QAAM,aAAS,uBAAU,aAAa,cAAc,CAAC,CAAC;AACtD,QAAM,WAAW,kBAAK,SAAS,QAAQ,QAAuB;AAE9D,QAAM,QAAQ,oBAAI,IAAgB;AAElC,WAAS,QAAQ,MAAkB;AAClC,UAAM,IAAI,IAAI;AAAA,EACf;AAEA,WAAS,MAAM,MAAkB,OAAiC;AACjE,YAAQ,iBAAkB,MAAM,OAAO,OAAO;AAE9C,eAAW,SAAS,KAAK,UAAU;AAClC,YAAM,OAAO,KAAK;AAAA,IACnB;AAAA,EACD;AAEA,QAAM,UAAU,YAAY;AAE5B,SAAO,MAAM,KAAK,KAAK;AACxB;",
6
+ "names": []
7
+ }
@@ -22,10 +22,10 @@ __export(version_exports, {
22
22
  version: () => version
23
23
  });
24
24
  module.exports = __toCommonJS(version_exports);
25
- const version = "3.9.0";
25
+ const version = "3.10.0-canary.3bf31007c5a7";
26
26
  const publishDates = {
27
27
  major: "2024-09-13T14:36:29.063Z",
28
- minor: "2025-03-03T11:42:22.746Z",
29
- patch: "2025-03-03T11:42:22.746Z"
28
+ minor: "2025-03-03T14:30:27.310Z",
29
+ patch: "2025-03-03T14:30:27.310Z"
30
30
  };
31
31
  //# sourceMappingURL=version.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.9.0'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-03-03T11:42:22.746Z',\n\tpatch: '2025-03-03T11:42:22.746Z',\n}\n"],
4
+ "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.10.0-canary.3bf31007c5a7'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-03-03T14:30:27.310Z',\n\tpatch: '2025-03-03T14:30:27.310Z',\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -7,6 +7,8 @@ import { ComponentType } from 'react';
7
7
  import { Computed } from '@tldraw/state';
8
8
  import { computed } from '@tldraw/state';
9
9
  import { Dispatch } from 'react';
10
+ import { Editor as Editor_2 } from '@tiptap/core';
11
+ import { EditorProviderProps } from '@tiptap/react';
10
12
  import { EffectScheduler } from '@tldraw/state';
11
13
  import { EMPTY_ARRAY } from '@tldraw/state';
12
14
  import EventEmitter from 'eventemitter3';
@@ -18,6 +20,7 @@ import { JSX as JSX_2 } from 'react/jsx-runtime';
18
20
  import { LegacyMigrations } from '@tldraw/store';
19
21
  import { MigrationSequence } from '@tldraw/store';
20
22
  import { NamedExoticComponent } from 'react';
23
+ import { Node as Node_2 } from '@tiptap/pm/model';
21
24
  import { PerformanceTracker } from '@tldraw/utils';
22
25
  import { PointerEventHandler } from 'react';
23
26
  import { react } from '@tldraw/state';
@@ -66,6 +69,7 @@ import { TLPageId } from '@tldraw/tlschema';
66
69
  import { TLParentId } from '@tldraw/tlschema';
67
70
  import { TLPropsMigrations } from '@tldraw/tlschema';
68
71
  import { TLRecord } from '@tldraw/tlschema';
72
+ import { TLRichText } from '@tldraw/tlschema';
69
73
  import { TLScribble } from '@tldraw/tlschema';
70
74
  import { TLShape } from '@tldraw/tlschema';
71
75
  import { TLShapeCrop } from '@tldraw/tlschema';
@@ -884,6 +888,7 @@ export declare const defaultTldrawOptions: {
884
888
  readonly longPressDurationMs: 500;
885
889
  readonly maxExportDelayMs: 5000;
886
890
  readonly maxFilesAtOnce: 100;
891
+ readonly maxFontsToLoadBeforeRender: number;
887
892
  readonly maxPages: 40;
888
893
  readonly maxShapesPerPage: 4000;
889
894
  readonly multiClickDurationMs: 200;
@@ -979,7 +984,8 @@ export declare class EdgeScrollManager {
979
984
 
980
985
  /** @public */
981
986
  export declare class Editor extends EventEmitter<TLEventMap> {
982
- constructor({ store, user, shapeUtils, bindingUtils, tools, getContainer, cameraOptions, initialState, autoFocus, inferDarkMode, options, isShapeHidden, }: TLEditorOptions);
987
+ readonly id: string;
988
+ constructor({ store, user, shapeUtils, bindingUtils, tools, getContainer, cameraOptions, textOptions, initialState, autoFocus, inferDarkMode, options, isShapeHidden, fontAssetUrls, }: TLEditorOptions);
983
989
  private readonly _isShapeHiddenPredicate?;
984
990
  private getIsShapeHiddenCache;
985
991
  isShapeHidden(shapeOrId: TLShape | TLShapeId): boolean;
@@ -1040,6 +1046,12 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1040
1046
  * @public
1041
1047
  */
1042
1048
  readonly textMeasure: TextManager;
1049
+ /**
1050
+ * A utility for managing the set of fonts that should be rendered in the document.
1051
+ *
1052
+ * @public
1053
+ */
1054
+ readonly fonts: FontManager;
1043
1055
  /**
1044
1056
  * A manager for the editor's environment.
1045
1057
  *
@@ -1679,6 +1691,26 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1679
1691
  * @public
1680
1692
  */
1681
1693
  setEditingShape(shape: null | TLShape | TLShapeId): this;
1694
+ private _currentRichTextEditor;
1695
+ /**
1696
+ * The current editing shape's text editor.
1697
+ *
1698
+ * @public
1699
+ */
1700
+ getRichTextEditor(): null | TiptapEditor;
1701
+ /**
1702
+ * Set the current editing shape's rich text editor.
1703
+ *
1704
+ * @example
1705
+ * ```ts
1706
+ * editor.setRichTextEditor(richTextEditorView)
1707
+ * ```
1708
+ *
1709
+ * @param textEditor - The text editor to set as the current editing shape's text editor.
1710
+ *
1711
+ * @public
1712
+ */
1713
+ setRichTextEditor(textEditor: null | TiptapEditor): this;
1682
1714
  /**
1683
1715
  * The current hovered shape id.
1684
1716
  *
@@ -1779,6 +1811,17 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1779
1811
  * @public
1780
1812
  */
1781
1813
  setCroppingShape(shape: null | TLShape | TLShapeId): this;
1814
+ private _textOptions;
1815
+ /**
1816
+ * Get the current text options.
1817
+ *
1818
+ * @example
1819
+ * ```ts
1820
+ * editor.getTextOptions()
1821
+ * ```
1822
+ *
1823
+ * @public */
1824
+ getTextOptions(): TLTextOptions;
1782
1825
  /* Excluded from this release type: _unsafe_getCameraId */
1783
1826
  /**
1784
1827
  * The current camera.
@@ -3186,7 +3229,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
3186
3229
  * @example
3187
3230
  * ```ts
3188
3231
  * editor.createShape(myShape)
3189
- * editor.createShape({ id: 'box1', type: 'text', props: { text: "ok" } })
3232
+ * editor.createShape({ id: 'box1', type: 'text', props: { richText: toRichText("ok") } })
3190
3233
  * ```
3191
3234
  *
3192
3235
  * @param shape - The shape (or shape partial) to create.
@@ -3200,7 +3243,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
3200
3243
  * @example
3201
3244
  * ```ts
3202
3245
  * editor.createShapes([myShape])
3203
- * editor.createShapes([{ id: 'box1', type: 'text', props: { text: "ok" } }])
3246
+ * editor.createShapes([{ id: 'box1', type: 'text', props: { richText: toRichText("ok") } }])
3204
3247
  * ```
3205
3248
  *
3206
3249
  * @param shapes - The shapes (or shape partials) to create.
@@ -3959,6 +4002,27 @@ export declare const EVENT_NAME_MAP: Record<Exclude<TLEventName, TLPinchEventNam
3959
4002
 
3960
4003
  /* Excluded from this release type: featureFlags */
3961
4004
 
4005
+ /** @public */
4006
+ export declare class FontManager {
4007
+ private readonly editor;
4008
+ private readonly assetUrls?;
4009
+ constructor(editor: Editor, assetUrls?: {
4010
+ [key: string]: string | undefined;
4011
+ } | undefined);
4012
+ private readonly shapeFontFacesCache;
4013
+ private readonly shapeFontLoadStateCache;
4014
+ getShapeFontFaces(shape: TLShape | TLShapeId): TLFontFace[];
4015
+ trackFontsForShape(shape: TLShape | TLShapeId): void;
4016
+ loadRequiredFontsForCurrentPage(limit?: number): Promise<void>;
4017
+ private readonly fontStates;
4018
+ private getFontState;
4019
+ ensureFontIsLoaded(font: TLFontFace): Promise<void>;
4020
+ private fontsToLoad;
4021
+ requestFonts(fonts: TLFontFace[]): void;
4022
+ private findOrCreateFontFace;
4023
+ toEmbeddedCssDeclaration(font: TLFontFace): Promise<string>;
4024
+ }
4025
+
3962
4026
  /** @public */
3963
4027
  export declare interface GapsSnapIndicator {
3964
4028
  id: string;
@@ -4031,6 +4095,9 @@ export declare function getCursor(cursor: TLCursorType, rotation?: number, color
4031
4095
  /** @public */
4032
4096
  export declare function getDefaultCdnBaseUrl(): string;
4033
4097
 
4098
+ /** @public */
4099
+ export declare function getFontsFromRichText(editor: Editor, richText: TLRichText, initialState: RichTextFontVisitorState): TLFontFace[];
4100
+
4034
4101
  /** @public */
4035
4102
  export declare function getFreshUserPreferences(): TLUserPreferences;
4036
4103
 
@@ -4715,6 +4782,16 @@ export declare function resizeScaled(shape: TLBaseShape<any, {
4715
4782
  y: number;
4716
4783
  };
4717
4784
 
4785
+ /** @public */
4786
+ export declare type RichTextFontVisitor = (node: TiptapNode, state: RichTextFontVisitorState, addFont: (font: TLFontFace) => void) => RichTextFontVisitorState;
4787
+
4788
+ /** @public */
4789
+ export declare interface RichTextFontVisitorState {
4790
+ readonly family: string;
4791
+ readonly weight: string;
4792
+ readonly style: string;
4793
+ }
4794
+
4718
4795
  /** @public */
4719
4796
  export declare const ROTATE_CORNER_TO_SELECTION_CORNER: {
4720
4797
  readonly bottom_left_rotate: "bottom_left";
@@ -4897,6 +4974,14 @@ export declare abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknown
4897
4974
  * @public
4898
4975
  */
4899
4976
  abstract indicator(shape: Shape): any;
4977
+ /**
4978
+ * Get the font faces that should be rendered in the document in order for this shape to render
4979
+ * correctly.
4980
+ *
4981
+ * @param shape - The shape.
4982
+ * @public
4983
+ */
4984
+ getFontFaces(shape: Shape): TLFontFace[];
4900
4985
  /**
4901
4986
  * Whether the shape can be snapped to by another shape.
4902
4987
  *
@@ -5554,6 +5639,24 @@ export declare class TextManager {
5554
5639
  }): BoxModel & {
5555
5640
  scrollWidth: number;
5556
5641
  };
5642
+ measureHtml(html: string, opts: {
5643
+ /**
5644
+ * When maxWidth is a number, the text will be wrapped to that maxWidth. When maxWidth
5645
+ * is null, the text will be measured without wrapping, but explicit line breaks and
5646
+ * space are preserved.
5647
+ */
5648
+ maxWidth: null | number;
5649
+ disableOverflowWrapBreaking?: boolean;
5650
+ fontFamily: string;
5651
+ fontSize: number;
5652
+ fontStyle: string;
5653
+ fontWeight: string;
5654
+ lineHeight: number;
5655
+ minWidth?: null | number;
5656
+ padding: string;
5657
+ }): BoxModel & {
5658
+ scrollWidth: number;
5659
+ };
5557
5660
  /**
5558
5661
  * Given an html element, measure the position of each span of unbroken
5559
5662
  * word/white-space characters within any text nodes it contains.
@@ -5581,6 +5684,19 @@ export declare class TextManager {
5581
5684
  }[];
5582
5685
  }
5583
5686
 
5687
+ /**
5688
+ * This is the TipTap editor! Docs are {@link https://tiptap.dev/docs}.
5689
+ *
5690
+ * @public
5691
+ */
5692
+ export declare type TiptapEditor = Editor_2;
5693
+
5694
+ /**
5695
+ * A TipTap node. See {@link https://tiptap.dev/docs}.
5696
+ * @public
5697
+ */
5698
+ export declare type TiptapNode = Node_2;
5699
+
5584
5700
  /** @public */
5585
5701
  export declare type TLAnyBindingUtilConstructor = TLBindingUtilConstructor<any>;
5586
5702
 
@@ -5621,6 +5737,7 @@ export declare interface TLBindingUtilConstructor<T extends TLUnknownBinding, U
5621
5737
 
5622
5738
  /** @public */
5623
5739
  export declare interface TLBrushProps {
5740
+ userId?: string;
5624
5741
  brush: BoxModel;
5625
5742
  color?: string;
5626
5743
  opacity?: number;
@@ -5748,6 +5865,7 @@ export declare type TLClickState = 'idle' | 'overflow' | 'pendingDouble' | 'pend
5748
5865
 
5749
5866
  /** @public */
5750
5867
  export declare interface TLCollaboratorHintProps {
5868
+ userId: string;
5751
5869
  className?: string;
5752
5870
  point: VecModel;
5753
5871
  viewport: Box;
@@ -5794,6 +5912,7 @@ export declare interface TLCropInfo<T extends TLShape> {
5794
5912
 
5795
5913
  /** @public */
5796
5914
  export declare interface TLCursorProps {
5915
+ userId: string;
5797
5916
  className?: string;
5798
5917
  point: null | VecModel;
5799
5918
  zoom: number;
@@ -5904,6 +6023,10 @@ export declare interface TldrawEditorBaseProps {
5904
6023
  * Camera options for the editor.
5905
6024
  */
5906
6025
  cameraOptions?: Partial<TLCameraOptions>;
6026
+ /**
6027
+ * Text options for the editor.
6028
+ */
6029
+ textOptions?: TLTextOptions;
5907
6030
  /**
5908
6031
  * Options for the editor.
5909
6032
  */
@@ -5924,6 +6047,14 @@ export declare interface TldrawEditorBaseProps {
5924
6047
  * remain in the store and participate in all other operations.
5925
6048
  */
5926
6049
  isShapeHidden?(shape: TLShape, editor: Editor): boolean;
6050
+ /**
6051
+ * The URLs for the fonts to use in the editor.
6052
+ */
6053
+ assetUrls?: {
6054
+ fonts?: {
6055
+ [key: string]: string | undefined;
6056
+ };
6057
+ };
5927
6058
  }
5928
6059
 
5929
6060
  /**
@@ -6047,6 +6178,12 @@ export declare interface TldrawOptions {
6047
6178
  * By default, the toolbar items are accessible via number shortcuts according to their order. To disable this, set this option to false.
6048
6179
  */
6049
6180
  readonly enableToolbarKeyboardShortcuts: boolean;
6181
+ /**
6182
+ * The maximum number of fonts that will be loaded while blocking the main rendering of the
6183
+ * canvas. If there are more than this number of fonts needed, we'll just show the canvas right
6184
+ * away and let the fonts load in in the background.
6185
+ */
6186
+ readonly maxFontsToLoadBeforeRender: number;
6050
6187
  }
6051
6188
 
6052
6189
  /** @public */
@@ -6124,8 +6261,12 @@ export declare interface TLEditorOptions {
6124
6261
  * Options for the editor's camera.
6125
6262
  */
6126
6263
  cameraOptions?: Partial<TLCameraOptions>;
6264
+ textOptions?: TLTextOptions;
6127
6265
  options?: Partial<TldrawOptions>;
6128
6266
  licenseKey?: string;
6267
+ fontAssetUrls?: {
6268
+ [key: string]: string | undefined;
6269
+ };
6129
6270
  /**
6130
6271
  * A predicate that should return true if the given shape should be hidden.
6131
6272
  * @param shape - The shape to check.
@@ -6240,6 +6381,13 @@ export declare interface TLEventMap {
6240
6381
  'select-all-text': [{
6241
6382
  shapeId: TLShapeId;
6242
6383
  }];
6384
+ 'place-caret': [{
6385
+ point: {
6386
+ x: number;
6387
+ y: number;
6388
+ };
6389
+ shapeId: TLShapeId;
6390
+ }];
6243
6391
  }
6244
6392
 
6245
6393
  /** @public */
@@ -6289,6 +6437,72 @@ export declare interface TLFilesExternalContent extends TLBaseExternalContent {
6289
6437
  ignoreParent: boolean;
6290
6438
  }
6291
6439
 
6440
+ /**
6441
+ * A font face that can be used in the editor. The properties of this are largely the same as the
6442
+ * ones in the
6443
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face | css `@font-face` rule}.
6444
+ * @public
6445
+ */
6446
+ export declare interface TLFontFace {
6447
+ /**
6448
+ * How this font can be referred to in CSS.
6449
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-family | `font-family`}.
6450
+ */
6451
+ readonly family: string;
6452
+ /**
6453
+ * The source of the font. This
6454
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src | `src`}.
6455
+ */
6456
+ readonly src: TLFontFaceSource;
6457
+ /**
6458
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/ascent-override | `ascent-override`}.
6459
+ */
6460
+ readonly ascentOverride?: string;
6461
+ /**
6462
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/descent-override | `descent-override`}.
6463
+ */
6464
+ readonly descentOverride?: string;
6465
+ /**
6466
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch | `font-stretch`}.
6467
+ */
6468
+ readonly stretch?: string;
6469
+ /**
6470
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-style | `font-style`}.
6471
+ */
6472
+ readonly style?: string;
6473
+ /**
6474
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-weight | `font-weight`}.
6475
+ */
6476
+ readonly weight?: string;
6477
+ /**
6478
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-feature-settings | `font-feature-settings`}.
6479
+ */
6480
+ readonly featureSettings?: string;
6481
+ /**
6482
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/line-gap-override | `line-gap-override`}.
6483
+ */
6484
+ readonly lineGapOverride?: string;
6485
+ /**
6486
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range | `unicode-range`}.
6487
+ */
6488
+ readonly unicodeRange?: string;
6489
+ }
6490
+
6491
+ /**
6492
+ * Represents the `src` property of a {@link TLFontFace}.
6493
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src | `src`} for details of the properties here.
6494
+ * @public
6495
+ */
6496
+ export declare interface TLFontFaceSource {
6497
+ /**
6498
+ * A URL from which to load the font. If the value here is a key in
6499
+ * {@link tldraw#TLEditorAssetUrls.fonts}, the value from there will be used instead.
6500
+ */
6501
+ url: string;
6502
+ format?: string;
6503
+ tech?: string;
6504
+ }
6505
+
6292
6506
  /** Additional options for the {@link ShapeUtil.getGeometry} method.
6293
6507
  *
6294
6508
  * @public
@@ -6696,6 +6910,7 @@ export declare type TLResizeShapeOptions = Partial<{
6696
6910
 
6697
6911
  /** @public */
6698
6912
  export declare interface TLScribbleProps {
6913
+ userId?: string;
6699
6914
  scribble: TLScribble;
6700
6915
  zoom: number;
6701
6916
  color?: string;
@@ -6755,6 +6970,7 @@ export declare type TLShapeIndicatorErrorFallbackComponent = ComponentType<{
6755
6970
 
6756
6971
  /** @public */
6757
6972
  export declare interface TLShapeIndicatorProps {
6973
+ userId?: string;
6758
6974
  shapeId: TLShapeId;
6759
6975
  color?: string | undefined;
6760
6976
  opacity?: number;
@@ -6939,6 +7155,7 @@ export declare interface TLSvgTextExternalContent extends TLBaseExternalContent
6939
7155
  export declare interface TLTextExternalContent extends TLBaseExternalContent {
6940
7156
  type: 'text';
6941
7157
  text: string;
7158
+ html?: string;
6942
7159
  }
6943
7160
 
6944
7161
  /** @public */
@@ -6948,6 +7165,12 @@ export declare interface TLTextExternalContentSource {
6948
7165
  subtype: 'html' | 'json' | 'text' | 'url';
6949
7166
  }
6950
7167
 
7168
+ /** @public */
7169
+ export declare interface TLTextOptions {
7170
+ tipTapConfig?: EditorProviderProps;
7171
+ addFontsFromNode?: RichTextFontVisitor;
7172
+ }
7173
+
6951
7174
  /** @public */
6952
7175
  export declare type TLTickEvent = (info: TLTickEventInfo) => void;
6953
7176
 
@@ -7119,6 +7342,9 @@ export declare function useMaybeEditor(): Editor | null;
7119
7342
 
7120
7343
  /* Excluded from this release type: useOnMount */
7121
7344
 
7345
+ /** @public */
7346
+ export declare function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement>): void;
7347
+
7122
7348
  /** @public */
7123
7349
  export declare function usePassThroughWheelEvents(ref: RefObject<HTMLElement>): void;
7124
7350
 
@@ -7230,6 +7456,9 @@ export declare function useUniqueSafeId(suffix?: string): SafeId;
7230
7456
 
7231
7457
  export { useValue }
7232
7458
 
7459
+ /** @public */
7460
+ export declare function useViewportHeight(): number;
7461
+
7233
7462
  /* Excluded from this release type: ValidLicenseKeyResult */
7234
7463
 
7235
7464
  /** @public */