@tldraw/editor 4.6.0-next.d8328a2dcc3d → 4.6.0-next.e0f85e824397

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 (110) hide show
  1. package/dist-cjs/index.d.ts +376 -98
  2. package/dist-cjs/index.js +12 -3
  3. package/dist-cjs/index.js.map +3 -3
  4. package/dist-cjs/lib/TldrawEditor.js +55 -12
  5. package/dist-cjs/lib/TldrawEditor.js.map +3 -3
  6. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +3 -3
  7. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +2 -2
  8. package/dist-cjs/lib/config/createTLStore.js +7 -0
  9. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  10. package/dist-cjs/lib/config/defaultAssets.js +36 -0
  11. package/dist-cjs/lib/config/defaultAssets.js.map +7 -0
  12. package/dist-cjs/lib/editor/Editor.js +200 -5
  13. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  14. package/dist-cjs/lib/editor/assets/AssetUtil.js +66 -0
  15. package/dist-cjs/lib/editor/assets/AssetUtil.js.map +7 -0
  16. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
  17. package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js +106 -0
  18. package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js.map +7 -0
  19. package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js +586 -0
  20. package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js.map +7 -0
  21. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +6 -4
  22. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  23. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +9 -0
  24. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  25. package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
  26. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  27. package/dist-cjs/lib/exports/getSvgJsx.js +12 -7
  28. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  29. package/dist-cjs/lib/globals/environment.js +18 -1
  30. package/dist-cjs/lib/globals/environment.js.map +2 -2
  31. package/dist-cjs/lib/hooks/{useIsDarkMode.js → useColorMode.js} +14 -10
  32. package/dist-cjs/lib/hooks/useColorMode.js.map +7 -0
  33. package/dist-cjs/lib/hooks/useCursor.js +3 -7
  34. package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
  35. package/dist-cjs/lib/hooks/useDarkMode.js +4 -4
  36. package/dist-cjs/lib/hooks/useDarkMode.js.map +2 -2
  37. package/dist-cjs/lib/utils/reparenting.js +2 -1
  38. package/dist-cjs/lib/utils/reparenting.js.map +2 -2
  39. package/dist-cjs/lib/utils/richText.js.map +2 -2
  40. package/dist-cjs/version.js +3 -3
  41. package/dist-cjs/version.js.map +1 -1
  42. package/dist-esm/index.d.mts +376 -98
  43. package/dist-esm/index.mjs +13 -6
  44. package/dist-esm/index.mjs.map +2 -2
  45. package/dist-esm/lib/TldrawEditor.mjs +58 -12
  46. package/dist-esm/lib/TldrawEditor.mjs.map +3 -3
  47. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +3 -3
  48. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +2 -2
  49. package/dist-esm/lib/config/createTLStore.mjs +10 -1
  50. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  51. package/dist-esm/lib/config/defaultAssets.mjs +16 -0
  52. package/dist-esm/lib/config/defaultAssets.mjs.map +7 -0
  53. package/dist-esm/lib/editor/Editor.mjs +200 -5
  54. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  55. package/dist-esm/lib/editor/assets/AssetUtil.mjs +46 -0
  56. package/dist-esm/lib/editor/assets/AssetUtil.mjs.map +7 -0
  57. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
  58. package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs +88 -0
  59. package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs.map +7 -0
  60. package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs +568 -0
  61. package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs.map +7 -0
  62. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +6 -4
  63. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  64. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +9 -0
  65. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  66. package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +2 -2
  67. package/dist-esm/lib/exports/getSvgJsx.mjs +12 -10
  68. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  69. package/dist-esm/lib/globals/environment.mjs +18 -1
  70. package/dist-esm/lib/globals/environment.mjs.map +2 -2
  71. package/dist-esm/lib/hooks/useColorMode.mjs +19 -0
  72. package/dist-esm/lib/hooks/useColorMode.mjs.map +7 -0
  73. package/dist-esm/lib/hooks/useCursor.mjs +3 -7
  74. package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
  75. package/dist-esm/lib/hooks/useDarkMode.mjs +4 -4
  76. package/dist-esm/lib/hooks/useDarkMode.mjs.map +2 -2
  77. package/dist-esm/lib/utils/reparenting.mjs +2 -1
  78. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  79. package/dist-esm/lib/utils/richText.mjs.map +2 -2
  80. package/dist-esm/version.mjs +3 -3
  81. package/dist-esm/version.mjs.map +1 -1
  82. package/editor.css +0 -33
  83. package/package.json +7 -7
  84. package/src/index.ts +8 -6
  85. package/src/lib/TldrawEditor.tsx +90 -13
  86. package/src/lib/components/default-components/CanvasShapeIndicators.tsx +3 -3
  87. package/src/lib/config/createTLStore.ts +22 -1
  88. package/src/lib/config/defaultAssets.ts +19 -0
  89. package/src/lib/editor/Editor.ts +285 -27
  90. package/src/lib/editor/assets/AssetUtil.ts +85 -0
  91. package/src/lib/editor/managers/FontManager/FontManager.test.ts +9 -2
  92. package/src/lib/editor/managers/FontManager/FontManager.ts +1 -67
  93. package/src/lib/editor/managers/ThemeManager/ThemeManager.ts +116 -0
  94. package/src/lib/editor/managers/ThemeManager/defaultThemes.ts +605 -0
  95. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +23 -29
  96. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +5 -3
  97. package/src/lib/editor/shapes/ShapeUtil.ts +26 -1
  98. package/src/lib/editor/types/SvgExportContext.tsx +5 -0
  99. package/src/lib/editor/types/external-content.ts +1 -0
  100. package/src/lib/exports/getSvgJsx.tsx +21 -15
  101. package/src/lib/globals/environment.ts +18 -0
  102. package/src/lib/hooks/{useIsDarkMode.ts → useColorMode.ts} +9 -5
  103. package/src/lib/hooks/useCursor.ts +3 -7
  104. package/src/lib/hooks/useDarkMode.ts +4 -4
  105. package/src/lib/utils/reparenting.ts +6 -2
  106. package/src/lib/utils/richText.ts +1 -1
  107. package/src/version.ts +3 -3
  108. package/dist-cjs/lib/hooks/useIsDarkMode.js.map +0 -7
  109. package/dist-esm/lib/hooks/useIsDarkMode.mjs +0 -15
  110. package/dist-esm/lib/hooks/useIsDarkMode.mjs.map +0 -7
@@ -57,9 +57,12 @@ import { TLCamera } from '@tldraw/tlschema';
57
57
  import { TLCreateShapePartial } from '@tldraw/tlschema';
58
58
  import { TLCursor } from '@tldraw/tlschema';
59
59
  import { TLCursorType } from '@tldraw/tlschema';
60
+ import { TLDefaultColor } from '@tldraw/tlschema';
61
+ import { TLDefaultColorStyle } from '@tldraw/tlschema';
60
62
  import { TLDefaultDashStyle } from '@tldraw/tlschema';
61
63
  import { TLDefaultHorizontalAlignStyle } from '@tldraw/tlschema';
62
64
  import { TLDocument } from '@tldraw/tlschema';
65
+ import { TLFontFace } from '@tldraw/tlschema';
63
66
  import { TLGroupShape } from '@tldraw/tlschema';
64
67
  import { TLHandle } from '@tldraw/tlschema';
65
68
  import { TLImageAsset } from '@tldraw/tlschema';
@@ -81,6 +84,11 @@ import { TLStore } from '@tldraw/tlschema';
81
84
  import { TLStoreProps } from '@tldraw/tlschema';
82
85
  import { TLStoreSchema } from '@tldraw/tlschema';
83
86
  import { TLStoreSnapshot } from '@tldraw/tlschema';
87
+ import { TLTheme } from '@tldraw/tlschema';
88
+ import { TLThemeColors } from '@tldraw/tlschema';
89
+ import { TLThemeId } from '@tldraw/tlschema';
90
+ import { TLThemes } from '@tldraw/tlschema';
91
+ import { TLUnknownAsset } from '@tldraw/tlschema';
84
92
  import { TLUnknownBinding } from '@tldraw/tlschema';
85
93
  import { TLUnknownShape } from '@tldraw/tlschema';
86
94
  import { TLUser } from '@tldraw/tlschema';
@@ -147,6 +155,51 @@ export declare class Arc2d extends Geometry2d {
147
155
  */
148
156
  export declare function areAnglesCompatible(a: number, b: number): boolean;
149
157
 
158
+ /**
159
+ * Abstract base class for defining asset-type-specific behavior.
160
+ *
161
+ * Each asset type (image, video, bookmark, etc.) has a corresponding AssetUtil that handles
162
+ * type-specific operations like determining supported MIME types and creating assets from files.
163
+ *
164
+ * @public
165
+ */
166
+ export declare abstract class AssetUtil<Asset extends TLAsset = TLAsset> {
167
+ editor: Editor;
168
+ /** Configure this asset util's {@link AssetUtil.options | `options`}. */
169
+ static configure<T extends TLAssetUtilConstructor<any, any>>(this: T, options: T extends new (...args: any[]) => {
170
+ options: infer Options;
171
+ } ? Partial<Options> : never): T;
172
+ constructor(editor: Editor);
173
+ /**
174
+ * Options for this asset util. Override this to provide customization options for your asset.
175
+ * Use {@link AssetUtil.configure} to customize existing asset utils.
176
+ */
177
+ options: {};
178
+ static props?: RecordProps<TLUnknownAsset>;
179
+ static migrations?: LegacyMigrations | MigrationSequence | TLPropsMigrations;
180
+ /**
181
+ * The type of the asset util, which should match the asset's type.
182
+ */
183
+ static type: string;
184
+ /**
185
+ * Get the default props for an asset of this type.
186
+ */
187
+ abstract getDefaultProps(): Asset['props'];
188
+ /**
189
+ * Get the MIME types that this asset type supports.
190
+ * Return an empty array if this asset type doesn't support files (e.g. bookmarks).
191
+ */
192
+ getSupportedMimeTypes(): readonly string[];
193
+ /**
194
+ * Check whether this asset type accepts a given MIME type.
195
+ */
196
+ acceptsMimeType(mimeType: string): boolean;
197
+ /**
198
+ * Create an asset from a file. Return null if this asset type can't handle the file.
199
+ */
200
+ getAssetFromFile(_file: File, _assetId: TLAssetId): Promise<Asset | null>;
201
+ }
202
+
150
203
  /** @public */
151
204
  export declare function average(A: VecLike, B: VecLike): string;
152
205
 
@@ -743,7 +796,7 @@ export declare function createTLSchemaFromUtils(opts: TLStoreSchemaOptions): Sto
743
796
  *
744
797
  * @public
745
798
  */
746
- export declare function createTLStore({ initialData, defaultName, id, assets, users, onMount, collaboration, ...rest }?: TLStoreOptions): TLStore;
799
+ export declare function createTLStore({ initialData, defaultName, id, assets, users, onMount, collaboration, themes, ...rest }?: TLStoreOptions): TLStore;
747
800
 
748
801
  /** @public */
749
802
  export declare class CubicBezier2d extends Polyline2d {
@@ -818,6 +871,13 @@ export declare interface DebugFlagDefaults<T> {
818
871
 
819
872
  /* Excluded from this release type: DEFAULT_CAMERA_OPTIONS */
820
873
 
874
+ /**
875
+ * The default theme definition containing color palettes for both light and dark modes.
876
+ *
877
+ * @public
878
+ */
879
+ export declare const DEFAULT_THEME: TLTheme;
880
+
821
881
  /** @public @react */
822
882
  export declare function DefaultBackground(): JSX.Element;
823
883
 
@@ -1043,7 +1103,7 @@ export declare class EdgeScrollManager {
1043
1103
  /** @public */
1044
1104
  export declare class Editor extends EventEmitter<TLEventMap> {
1045
1105
  readonly id: string;
1046
- constructor({ store, user, shapeUtils, bindingUtils, tools, getContainer, cameraOptions, initialState, autoFocus, inferDarkMode, options: _options, textOptions: _textOptions, getShapeVisibility, fontAssetUrls }: TLEditorOptions);
1106
+ constructor({ store, user, shapeUtils, bindingUtils, assetUtils: assetUtilConstructors, tools, getContainer, cameraOptions, initialState, autoFocus, options: _options, textOptions: _textOptions, getShapeVisibility, colorScheme, fontAssetUrls, themes, initialTheme }: TLEditorOptions);
1047
1107
  private readonly _getShapeVisibility?;
1048
1108
  private getIsShapeHiddenCache;
1049
1109
  isShapeHidden(shapeOrId: TLShape | TLShapeId): boolean;
@@ -1106,7 +1166,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1106
1166
  * @public
1107
1167
  */
1108
1168
  readonly snaps: SnapManager;
1109
- private readonly _spatialIndex;
1169
+ /* Excluded from this release type: _spatialIndex */
1110
1170
  /**
1111
1171
  * A manager for the any asynchronous events and making sure they're
1112
1172
  * cleaned up upon disposal.
@@ -1125,6 +1185,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1125
1185
  * @public
1126
1186
  */
1127
1187
  readonly user: UserPreferencesManager;
1188
+ /* Excluded from this release type: _themeManager */
1128
1189
  /**
1129
1190
  * A helper for measuring text.
1130
1191
  *
@@ -1175,6 +1236,83 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1175
1236
  * @public
1176
1237
  */
1177
1238
  dispose(): void;
1239
+ /**
1240
+ * Get the current color mode (`'light'` or `'dark'`), based on the user's dark mode preference.
1241
+ *
1242
+ * @public
1243
+ */
1244
+ getColorMode(): 'dark' | 'light';
1245
+ /**
1246
+ * Set the color mode. Note that this is a convenience method that passes the mode to
1247
+ * `user.updateUserPreferences`, which is the source of truth for the user's color mode preference.
1248
+ *
1249
+ * @public
1250
+ */
1251
+ setColorMode(mode: 'dark' | 'light'): this;
1252
+ /**
1253
+ * Get the id of the current theme.
1254
+ *
1255
+ * @public
1256
+ */
1257
+ getCurrentThemeId(): TLThemeId;
1258
+ /**
1259
+ * Get the current theme definition.
1260
+ *
1261
+ * @public
1262
+ */
1263
+ getCurrentTheme(): TLTheme;
1264
+ /**
1265
+ * Set the current theme by id.
1266
+ *
1267
+ * @public
1268
+ */
1269
+ setCurrentTheme(id: TLThemeId): this;
1270
+ /**
1271
+ * Get all registered theme definitions.
1272
+ *
1273
+ * @public
1274
+ */
1275
+ getThemes(): TLThemes;
1276
+ /**
1277
+ * Get a single theme definition by id.
1278
+ *
1279
+ * @public
1280
+ */
1281
+ getTheme(id: TLThemeId): TLTheme | undefined;
1282
+ /**
1283
+ * Replace all theme definitions, or update them via a callback that receives a deep copy.
1284
+ * The `'default'` theme must always be present in the result.
1285
+ *
1286
+ * @example
1287
+ * ```ts
1288
+ * // Replace all themes
1289
+ * editor.updateThemes({ default: myDefaultTheme, ocean: myOceanTheme })
1290
+ *
1291
+ * // Update via callback
1292
+ * editor.updateThemes((themes) => {
1293
+ * delete themes.ocean
1294
+ * return themes
1295
+ * })
1296
+ * ```
1297
+ *
1298
+ * @public
1299
+ */
1300
+ updateThemes(themes: ((themes: TLThemes) => TLThemes) | TLThemes): this;
1301
+ /**
1302
+ * Register or update a single theme definition. The theme is keyed by its `id` property.
1303
+ *
1304
+ * @example
1305
+ * ```ts
1306
+ * // Override a property on the default theme
1307
+ * editor.updateTheme({ ...editor.getTheme('default')!, fontSize: 24 })
1308
+ *
1309
+ * // Register a new theme
1310
+ * editor.updateTheme({ id: 'ocean', ...myOceanTheme })
1311
+ * ```
1312
+ *
1313
+ * @public
1314
+ */
1315
+ updateTheme(theme: TLTheme): this;
1178
1316
  /**
1179
1317
  * A map of shape utility classes (TLShapeUtils) by shape type.
1180
1318
  *
@@ -1183,6 +1321,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1183
1321
  shapeUtils: {
1184
1322
  readonly [K in string]?: ShapeUtil<TLShape>;
1185
1323
  };
1324
+ /* Excluded from this release type: _shapeUtilsByAssetType */
1186
1325
  styleProps: {
1187
1326
  [key: string]: Map<StyleProp<any>, string>;
1188
1327
  };
@@ -1214,6 +1353,15 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1214
1353
  hasShapeUtil(shape: TLShape | TLShapePartial<TLShape>): boolean;
1215
1354
  hasShapeUtil(type: TLShape['type']): boolean;
1216
1355
  hasShapeUtil<T extends ShapeUtil>(type: T extends ShapeUtil<infer R> ? R['type'] : string): boolean;
1356
+ /**
1357
+ * Get the shape util that handles the given asset type.
1358
+ * Returns the shape util whose {@link ShapeUtil.handledAssetTypes} includes
1359
+ * the given asset type, or undefined if none matches.
1360
+ *
1361
+ * @param assetType - The asset type string.
1362
+ * @public
1363
+ */
1364
+ getShapeUtilForAssetType(assetType: string): ShapeUtil | undefined;
1217
1365
  /**
1218
1366
  * A map of shape utility classes (TLShapeUtils) by shape type.
1219
1367
  *
@@ -1244,6 +1392,40 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1244
1392
  type: S['type'];
1245
1393
  } | S): BindingUtil<S>;
1246
1394
  getBindingUtil<T extends BindingUtil>(type: T extends BindingUtil<infer R> ? R['type'] : string): T;
1395
+ /**
1396
+ * A map of asset utility classes by asset type.
1397
+ *
1398
+ * @public
1399
+ */
1400
+ assetUtils: {
1401
+ readonly [K in string]?: AssetUtil<TLAsset>;
1402
+ };
1403
+ /**
1404
+ * Get an asset util from an asset or asset type.
1405
+ *
1406
+ * @param arg - An asset, asset type string, or object with type.
1407
+ *
1408
+ * @public
1409
+ */
1410
+ getAssetUtil<S extends TLAsset>(asset: {
1411
+ type: S['type'];
1412
+ } | S): AssetUtil<S>;
1413
+ getAssetUtil(type: string): AssetUtil;
1414
+ /**
1415
+ * Returns true if the editor has an asset util for the given asset type.
1416
+ *
1417
+ * @public
1418
+ */
1419
+ hasAssetUtil(arg: {
1420
+ type: string;
1421
+ } | string): boolean;
1422
+ /**
1423
+ * Get the asset util that accepts the given MIME type.
1424
+ * Returns null if no registered asset util accepts the MIME type.
1425
+ *
1426
+ * @public
1427
+ */
1428
+ getAssetUtilForMimeType(mimeType: string): AssetUtil | null;
1247
1429
  /**
1248
1430
  * A manager for the editor's history.
1249
1431
  *
@@ -4394,6 +4576,35 @@ export declare interface Geometry2dOptions extends TransformedGeometry2dOptions
4394
4576
  */
4395
4577
  export declare function getArcMeasure(A: number, B: number, sweepFlag: number, largeArcFlag: number): number;
4396
4578
 
4579
+ /**
4580
+ * Resolves a color style value to its actual CSS color string for a given theme and variant.
4581
+ * If the color is not a default theme color, returns the color value as-is.
4582
+ *
4583
+ * @param colors - The color palette for the current color mode (e.g. `theme.colors[colorMode]`)
4584
+ * @param color - The color style value to resolve
4585
+ * @param variant - Which variant of the color to return (solid, fill, pattern, etc.)
4586
+ * @returns The CSS color string for the specified color and variant
4587
+ *
4588
+ * @example
4589
+ * ```ts
4590
+ * import { getColorValue } from 'tldraw'
4591
+ *
4592
+ * const colors = editor.getCurrentTheme().colors[editor.getColorMode()]
4593
+ *
4594
+ * // Get the solid variant of red
4595
+ * const redSolid = getColorValue(colors, 'red', 'solid') // '#e03131'
4596
+ *
4597
+ * // Get the fill variant of blue
4598
+ * const blueFill = getColorValue(colors, 'blue', 'fill') // '#4465e9'
4599
+ *
4600
+ * // Custom color passes through unchanged
4601
+ * const customColor = getColorValue(colors, '#ff0000', 'solid') // '#ff0000'
4602
+ * ```
4603
+ *
4604
+ * @public
4605
+ */
4606
+ export declare function getColorValue(colors: TLThemeColors, color: string | TLDefaultColorStyle, variant: keyof TLDefaultColor): string;
4607
+
4397
4608
  /** @public */
4398
4609
  export declare function getCursor(cursor: TLCursorType, rotation?: number, color?: string): string;
4399
4610
 
@@ -5400,6 +5611,16 @@ export declare function resizeScaled(shape: TLBaseShape<any, {
5400
5611
  y: number;
5401
5612
  };
5402
5613
 
5614
+ /**
5615
+ * Resolve a partial set of user-provided themes into a complete `TLThemes`
5616
+ * record by merging with `DEFAULT_THEME`. The result is suitable for passing to
5617
+ * `registerColorsFromThemes`, `registerFontsFromThemes`, and the
5618
+ * `ThemeManager` constructor.
5619
+ *
5620
+ * @public
5621
+ */
5622
+ export declare function resolveThemes(themes?: Partial<TLThemes>): TLThemes;
5623
+
5403
5624
  /** @public */
5404
5625
  export declare type RichTextFontVisitor = (node: TiptapNode, state: RichTextFontVisitorState, addFont: (font: TLFontFace) => void) => RichTextFontVisitorState;
5405
5626
 
@@ -5681,12 +5902,32 @@ export declare abstract class ShapeUtil<Shape extends TLShape = TLShape> {
5681
5902
  * @public
5682
5903
  */
5683
5904
  static type: string;
5905
+ /**
5906
+ * The asset types that this shape can be created from.
5907
+ * When a file is dropped on the canvas, the editor finds the shape util
5908
+ * whose `handledAssetTypes` includes the asset's type and calls
5909
+ * {@link ShapeUtil.createShapeForAsset} to produce the shape.
5910
+ *
5911
+ * @public
5912
+ */
5913
+ static handledAssetTypes?: readonly string[];
5684
5914
  /**
5685
5915
  * Get the default props for a shape.
5686
5916
  *
5687
5917
  * @public
5688
5918
  */
5689
5919
  abstract getDefaultProps(): Shape['props'];
5920
+ /**
5921
+ * Create a shape partial for placing an asset on the canvas.
5922
+ * Only called for shapes whose constructor declares matching
5923
+ * {@link ShapeUtil.handledAssetTypes | `handledAssetTypes`}.
5924
+ *
5925
+ * @param asset - The asset to create a shape for.
5926
+ * @param position - Where to place the shape.
5927
+ * @returns A shape partial, or null if this shape can't be created for the asset.
5928
+ * @public
5929
+ */
5930
+ createShapeForAsset?(asset: TLAsset, position: VecModel): null | TLShapePartial;
5690
5931
  /**
5691
5932
  * Get the shape's geometry.
5692
5933
  *
@@ -6525,6 +6766,10 @@ export declare interface SvgExportContext {
6525
6766
  * Whether the export should be in dark mode.
6526
6767
  */
6527
6768
  readonly isDarkMode: boolean;
6769
+ /**
6770
+ * The color mode to use for this export.
6771
+ */
6772
+ readonly colorMode: 'dark' | 'light';
6528
6773
  /**
6529
6774
  * The scale of the export - how much CSS pixels will be scaled up/down by.
6530
6775
  */
@@ -6595,6 +6840,47 @@ export declare class TextManager {
6595
6840
  }[];
6596
6841
  }
6597
6842
 
6843
+ /**
6844
+ * Manages the editor's color themes.
6845
+ *
6846
+ * Stores named theme definitions (each containing light and dark color palettes
6847
+ * alongside shared properties like font size). The current theme is resolved by
6848
+ * combining the current theme name with the user's color mode preference.
6849
+ *
6850
+ * **Terminology:**
6851
+ * - **Theme** (`TLTheme`): A named set of colors and typographic values for both light and dark modes.
6852
+ * - **Color mode** (`'light' | 'dark'`): The resolved appearance mode, derived from the user's
6853
+ * `colorScheme` preference (`'light' | 'dark' | 'system'`). Access via `getColorMode()`.
6854
+ *
6855
+ * @public
6856
+ */
6857
+ export declare class ThemeManager {
6858
+ private readonly editor;
6859
+ private readonly _themes;
6860
+ private readonly _currentThemeId;
6861
+ constructor(editor: Editor, options: {
6862
+ initial: TLThemeId;
6863
+ themes: TLThemes;
6864
+ });
6865
+ /** Get the current color mode based on the user's dark mode preference. */
6866
+ getColorMode(): 'dark' | 'light';
6867
+ /** Get all registered theme definitions. */
6868
+ getThemes(): TLThemes;
6869
+ /** Get a single theme definition by id. */
6870
+ getTheme(id: TLThemeId): TLTheme | undefined;
6871
+ /** Get the id of the current theme. */
6872
+ getCurrentThemeId(): TLThemeId;
6873
+ getCurrentTheme(): TLTheme;
6874
+ /** Set the current theme by id. The theme must have been previously registered. */
6875
+ setCurrentTheme(id: TLThemeId): void;
6876
+ /** Replace all theme definitions, or update them via a callback that receives a deep copy. */
6877
+ updateThemes(themes: ((themes: TLThemes) => TLThemes) | TLThemes): void;
6878
+ /** Register or update a named theme definition. */
6879
+ updateTheme(theme: TLTheme): void;
6880
+ /** Clean up any resources held by the manager. */
6881
+ dispose(): void;
6882
+ }
6883
+
6598
6884
  /* Excluded from this release type: TickManager */
6599
6885
 
6600
6886
  /**
@@ -6613,12 +6899,23 @@ export declare type TiptapNode = Node_2;
6613
6899
  /** @public */
6614
6900
  export declare type TLAdjacentDirection = 'down' | 'left' | 'next' | 'prev' | 'right' | 'up';
6615
6901
 
6902
+ /** @public */
6903
+ export declare type TLAnyAssetUtilConstructor = TLAssetUtilConstructor<any>;
6904
+
6616
6905
  /** @public */
6617
6906
  export declare type TLAnyBindingUtilConstructor = TLBindingUtilConstructor<any>;
6618
6907
 
6619
6908
  /** @public */
6620
6909
  export declare type TLAnyShapeUtilConstructor = TLShapeUtilConstructor<any>;
6621
6910
 
6911
+ /** @public */
6912
+ export declare interface TLAssetUtilConstructor<T extends TLAsset = TLAsset, U extends AssetUtil<T> = AssetUtil<T>> {
6913
+ new (editor: Editor): U;
6914
+ type: T['type'];
6915
+ props?: RecordProps<T>;
6916
+ migrations?: LegacyMigrations | MigrationSequence | TLPropsMigrations;
6917
+ }
6918
+
6622
6919
  /** @public */
6623
6920
  export declare type TLBaseBoxShape = ExtractShapeByProps<{
6624
6921
  h: number;
@@ -6968,6 +7265,10 @@ export declare interface TldrawEditorBaseProps {
6968
7265
  * An array of binding utils to use in the editor.
6969
7266
  */
6970
7267
  bindingUtils?: readonly TLAnyBindingUtilConstructor[];
7268
+ /**
7269
+ * An array of asset utils to use in the editor.
7270
+ */
7271
+ assetUtils?: readonly TLAnyAssetUtilConstructor[];
6971
7272
  /**
6972
7273
  * An array of tools to add to the editor's state chart.
6973
7274
  */
@@ -6997,9 +7298,21 @@ export declare interface TldrawEditorBaseProps {
6997
7298
  */
6998
7299
  user?: TLCurrentUser;
6999
7300
  /**
7000
- * Whether to infer dark mode from the user's OS. Defaults to false.
7301
+ * The editor's color scheme. Defaults to `'light'`.
7302
+ *
7303
+ * - `'light'` - Always use light mode.
7304
+ * - `'dark'` - Always use dark mode.
7305
+ * - `'system'` - Follow the OS color scheme preference.
7306
+ */
7307
+ colorScheme?: 'dark' | 'light' | 'system';
7308
+ /**
7309
+ * Named themes for the editor.
7310
+ */
7311
+ themes?: Partial<TLThemes>;
7312
+ /**
7313
+ * The id of the initially active theme. Defaults to `'default'`.
7001
7314
  */
7002
- inferDarkMode?: boolean;
7315
+ initialTheme?: TLThemeId;
7003
7316
  /**
7004
7317
  * Camera options for the editor.
7005
7318
  *
@@ -7392,14 +7705,13 @@ export declare interface TLEditorOptions {
7392
7705
  */
7393
7706
  bindingUtils: readonly TLAnyBindingUtilConstructor[];
7394
7707
  /**
7395
- * An array of tools to use in the editor. These will be used to handle events and manage user interactions in the editor.
7708
+ * An array of asset utils to use in the editor. These will be used to handle asset-type-specific behavior.
7396
7709
  */
7397
- tools: readonly TLStateNodeConstructor[];
7710
+ assetUtils?: readonly TLAnyAssetUtilConstructor[];
7398
7711
  /**
7399
- * Should return a containing html element which has all the styles applied to the editor. If not
7400
- * given, the body element will be used.
7712
+ * An array of tools to use in the editor. These will be used to handle events and manage user interactions in the editor.
7401
7713
  */
7402
- getContainer(): HTMLElement;
7714
+ tools: readonly TLStateNodeConstructor[];
7403
7715
  /**
7404
7716
  * A user defined externally to replace the default user.
7405
7717
  */
@@ -7412,27 +7724,15 @@ export declare interface TLEditorOptions {
7412
7724
  * Whether to automatically focus the editor when it mounts.
7413
7725
  */
7414
7726
  autoFocus?: boolean;
7415
- /**
7416
- * Whether to infer dark mode from the user's system preferences. Defaults to false.
7417
- */
7418
- inferDarkMode?: boolean;
7419
- /**
7420
- * Options for the editor's camera.
7421
- *
7422
- * @deprecated Use `options.cameraOptions` instead. This will be removed in a future release.
7423
- */
7424
- cameraOptions?: Partial<TLCameraOptions>;
7425
- options?: Partial<TldrawOptions>;
7426
- /**
7427
- * Text options for the editor.
7428
- *
7429
- * @deprecated Use `options.text` instead. This prop will be removed in a future release.
7430
- */
7431
- textOptions?: TLTextOptions;
7432
7727
  licenseKey?: string;
7433
7728
  fontAssetUrls?: {
7434
7729
  [key: string]: string | undefined;
7435
7730
  };
7731
+ /**
7732
+ * Should return a containing html element which has all the styles applied to the editor. If not
7733
+ * given, the body element will be used.
7734
+ */
7735
+ getContainer(): HTMLElement;
7436
7736
  /**
7437
7737
  * Provides a way to hide shapes.
7438
7738
  *
@@ -7449,6 +7749,40 @@ export declare interface TLEditorOptions {
7449
7749
  * @param editor - The editor instance.
7450
7750
  */
7451
7751
  getShapeVisibility?(shape: TLShape, editor: Editor): 'hidden' | 'inherit' | 'visible' | null | undefined;
7752
+ /**
7753
+ * Named theme definitions for the editor. Each theme contains shared
7754
+ * properties (font size, line height, stroke width) and color palettes
7755
+ * for both light and dark modes.
7756
+ */
7757
+ themes?: Partial<TLThemes>;
7758
+ /**
7759
+ * The id of the initially active theme. Defaults to `'default'`.
7760
+ */
7761
+ initialTheme?: TLThemeId;
7762
+ /**
7763
+ * The editor's color scheme preference, controls the default color mode. Defaults to `'light'`.
7764
+ *
7765
+ * - `'light'` - Always use light mode.
7766
+ * - `'dark'` - Always use dark mode.
7767
+ * - `'system'` - Follow the OS color scheme preference.
7768
+ */
7769
+ colorScheme?: 'dark' | 'light' | 'system';
7770
+ /**
7771
+ * Additional configuration options for the tldraw editor.
7772
+ */
7773
+ options?: Partial<TldrawOptions>;
7774
+ /**
7775
+ * Options for the editor's camera.
7776
+ *
7777
+ * @deprecated Use `options.cameraOptions` instead. This will be removed in a future release.
7778
+ */
7779
+ cameraOptions?: Partial<TLCameraOptions>;
7780
+ /**
7781
+ * Text options for the editor.
7782
+ *
7783
+ * @deprecated Use `options.text` instead. This prop will be removed in a future release.
7784
+ */
7785
+ textOptions?: TLTextOptions;
7452
7786
  }
7453
7787
 
7454
7788
  /**
@@ -7507,6 +7841,7 @@ export declare const tlenv: {
7507
7841
  */
7508
7842
  export declare const tlenvReactive: Atom< {
7509
7843
  isCoarsePointer: boolean;
7844
+ supportsP3ColorSpace: boolean;
7510
7845
  }, unknown>;
7511
7846
 
7512
7847
  /** @public */
@@ -7635,6 +7970,7 @@ export declare interface TLFileReplaceExternalContent extends TLBaseExternalCont
7635
7970
  type: 'file-replace';
7636
7971
  file: File;
7637
7972
  shapeId: TLShapeId;
7973
+ /** @deprecated This field is no longer used by the default handler. It may be removed in a future version. */
7638
7974
  isImage: boolean;
7639
7975
  }
7640
7976
 
@@ -7645,72 +7981,6 @@ export declare interface TLFilesExternalContent extends TLBaseExternalContent {
7645
7981
  ignoreParent?: boolean;
7646
7982
  }
7647
7983
 
7648
- /**
7649
- * A font face that can be used in the editor. The properties of this are largely the same as the
7650
- * ones in the
7651
- * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face | css `@font-face` rule}.
7652
- * @public
7653
- */
7654
- export declare interface TLFontFace {
7655
- /**
7656
- * How this font can be referred to in CSS.
7657
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-family | `font-family`}.
7658
- */
7659
- readonly family: string;
7660
- /**
7661
- * The source of the font. This
7662
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src | `src`}.
7663
- */
7664
- readonly src: TLFontFaceSource;
7665
- /**
7666
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/ascent-override | `ascent-override`}.
7667
- */
7668
- readonly ascentOverride?: string;
7669
- /**
7670
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/descent-override | `descent-override`}.
7671
- */
7672
- readonly descentOverride?: string;
7673
- /**
7674
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch | `font-stretch`}.
7675
- */
7676
- readonly stretch?: string;
7677
- /**
7678
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-style | `font-style`}.
7679
- */
7680
- readonly style?: string;
7681
- /**
7682
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-weight | `font-weight`}.
7683
- */
7684
- readonly weight?: string;
7685
- /**
7686
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-feature-settings | `font-feature-settings`}.
7687
- */
7688
- readonly featureSettings?: string;
7689
- /**
7690
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/line-gap-override | `line-gap-override`}.
7691
- */
7692
- readonly lineGapOverride?: string;
7693
- /**
7694
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range | `unicode-range`}.
7695
- */
7696
- readonly unicodeRange?: string;
7697
- }
7698
-
7699
- /**
7700
- * Represents the `src` property of a {@link TLFontFace}.
7701
- * See {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src | `src`} for details of the properties here.
7702
- * @public
7703
- */
7704
- export declare interface TLFontFaceSource {
7705
- /**
7706
- * A URL from which to load the font. If the value here is a key in
7707
- * {@link tldraw#TLEditorAssetUrls.fonts}, the value from there will be used instead.
7708
- */
7709
- url: string;
7710
- format?: string;
7711
- tech?: string;
7712
- }
7713
-
7714
7984
  /** Additional options for the {@link ShapeUtil.getGeometry} method.
7715
7985
  *
7716
7986
  * @public
@@ -8344,6 +8614,7 @@ export declare interface TLShapeUtilConstructor<T extends TLShape, U extends Sha
8344
8614
  type: T['type'];
8345
8615
  props?: RecordProps<T>;
8346
8616
  migrations?: LegacyMigrations | MigrationSequence | TLPropsMigrations;
8617
+ handledAssetTypes?: readonly string[];
8347
8618
  }
8348
8619
 
8349
8620
  /** @public */
@@ -8383,6 +8654,12 @@ export declare interface TLStoreBaseOptions {
8383
8654
  defaultName?: string;
8384
8655
  /** How should this store upload & resolve assets? */
8385
8656
  assets?: TLAssetStore;
8657
+ /**
8658
+ * Named theme definitions. When provided, custom color names are automatically
8659
+ * registered before the store is constructed so persisted data with those
8660
+ * colors passes validation on load.
8661
+ */
8662
+ themes?: Partial<TLThemes>;
8386
8663
  /** How should this store resolve users for attribution? */
8387
8664
  users?: TLUserStore;
8388
8665
  /** Called when the store is connected to an {@link @tldraw/editor#Editor}. */
@@ -8404,6 +8681,7 @@ export declare type TLStoreOptions = TLStoreBaseOptions & {
8404
8681
 
8405
8682
  /** @public */
8406
8683
  export declare type TLStoreSchemaOptions = {
8684
+ assetUtils?: readonly TLAnyAssetUtilConstructor[];
8407
8685
  bindingUtils?: readonly TLAnyBindingUtilConstructor[];
8408
8686
  migrations?: readonly MigrationSequence[];
8409
8687
  records?: Record<string, CustomRecordInfo>;
@@ -8672,6 +8950,9 @@ export declare function uniq<T>(array: {
8672
8950
  readonly length: number;
8673
8951
  } | null | undefined): T[];
8674
8952
 
8953
+ /** @public */
8954
+ export declare function useColorMode(): 'dark' | 'light';
8955
+
8675
8956
  /** @public */
8676
8957
  export declare function useContainer(): HTMLElement;
8677
8958
 
@@ -8710,9 +8991,6 @@ export declare function useGlobalMenuIsOpen(id: string, onChange?: (isOpen: bool
8710
8991
  /** @public */
8711
8992
  export declare function useIsCropping(shapeId: TLShapeId): boolean;
8712
8993
 
8713
- /** @public */
8714
- export declare function useIsDarkMode(): boolean;
8715
-
8716
8994
  /** @public */
8717
8995
  export declare function useIsEditing(shapeId: TLShapeId): boolean;
8718
8996
 
@@ -8750,11 +9028,11 @@ export declare function usePresence(userId: string): null | TLInstancePresence;
8750
9028
  /** @public */
8751
9029
  export declare class UserPreferencesManager {
8752
9030
  private readonly user;
8753
- private readonly inferDarkMode;
9031
+ private readonly colorScheme;
8754
9032
  systemColorScheme: Atom<"dark" | "light", unknown>;
8755
9033
  disposables: Set<() => void>;
8756
9034
  dispose(): void;
8757
- constructor(user: TLCurrentUser, inferDarkMode: boolean);
9035
+ constructor(user: TLCurrentUser, colorScheme: 'dark' | 'light' | 'system');
8758
9036
  updateUserPreferences(userPreferences: Partial<TLUserPreferences>): void;
8759
9037
  getUserPreferences(): {
8760
9038
  animationSpeed: number;