@mocanvas/editor 4.4.1 → 4.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +251 -245
- package/dist/index.js +79 -74
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -12250,251 +12250,6 @@ declare class WebGL2Backend implements RenderBackend {
|
|
|
12250
12250
|
*/
|
|
12251
12251
|
declare function createBackend(canvas: HTMLCanvasElement): RenderBackend;
|
|
12252
12252
|
|
|
12253
|
-
/**
|
|
12254
|
-
* What the `Canvas` component slot is handed.
|
|
12255
|
-
*
|
|
12256
|
-
* A host replacing the canvas gets only presentation: a class name and
|
|
12257
|
-
* children. It deliberately does *not* receive the editor as a prop — the
|
|
12258
|
-
* replacement is rendered inside the editor's provider and reads it with
|
|
12259
|
-
* `useEditor()`, so a slot cannot be rendered against a different editor than
|
|
12260
|
-
* the one it is inside of.
|
|
12261
|
-
*/
|
|
12262
|
-
interface TLCanvasComponentProps {
|
|
12263
|
-
className?: string;
|
|
12264
|
-
children?: ReactNode;
|
|
12265
|
-
}
|
|
12266
|
-
interface CanvasProps {
|
|
12267
|
-
editor: Editor;
|
|
12268
|
-
className?: string;
|
|
12269
|
-
style?: CSSProperties;
|
|
12270
|
-
/** Extra layers rendered above the canvas (UI, menus). */
|
|
12271
|
-
children?: ReactNode;
|
|
12272
|
-
/** Override the default selection/brush indicators. */
|
|
12273
|
-
components?: Partial<CanvasComponents>;
|
|
12274
|
-
/**
|
|
12275
|
-
* The overlay util that paints shape indicators onto the canvas layer.
|
|
12276
|
-
*
|
|
12277
|
-
* A *class*, not an instance — one is constructed per editor. Pass
|
|
12278
|
-
* `ShapeIndicatorCompositor.configure({ lineWidth })` to restyle, or a
|
|
12279
|
-
* subclass to control which shapes get an outline.
|
|
12280
|
-
*/
|
|
12281
|
-
indicatorOverlayUtil?: typeof ShapeIndicatorCompositor;
|
|
12282
|
-
}
|
|
12283
|
-
interface CanvasComponents {
|
|
12284
|
-
Indicators: (props: {
|
|
12285
|
-
editor: Editor;
|
|
12286
|
-
}) => ReactNode;
|
|
12287
|
-
Brush: (props: {
|
|
12288
|
-
editor: Editor;
|
|
12289
|
-
}) => ReactNode;
|
|
12290
|
-
Background: (props: {
|
|
12291
|
-
editor: Editor;
|
|
12292
|
-
}) => ReactNode;
|
|
12293
|
-
}
|
|
12294
|
-
/**
|
|
12295
|
-
* The canvas: a WebGL2 surface driven by the engine, a DOM overlay for shapes
|
|
12296
|
-
* that render through `ShapeUtil.component`, a 2D canvas overlay for shape
|
|
12297
|
-
* indicators, and an SVG layer for the selection handles, snap lines, the brush
|
|
12298
|
-
* — and for any util still on the deprecated `indicator()` hook.
|
|
12299
|
-
*/
|
|
12300
|
-
declare function Canvas({ editor, className, style, children, components, indicatorOverlayUtil }: CanvasProps): react.JSX.Element;
|
|
12301
|
-
/**
|
|
12302
|
-
* The outline to draw over one shape: whatever its util's `indicator()`
|
|
12303
|
-
* returns, or a rectangle around the shape's geometry bounds when the util has
|
|
12304
|
-
* no indicator (or returns nothing). Both are expressed in *shape-local*
|
|
12305
|
-
* coordinates; the caller wraps them in the shape's page transform.
|
|
12306
|
-
*
|
|
12307
|
-
* Pure and exported so a custom `Indicators` component can reuse the same rule
|
|
12308
|
-
* instead of guessing at it.
|
|
12309
|
-
*
|
|
12310
|
-
* @deprecated The SVG indicator layer only draws utils still on the deprecated
|
|
12311
|
-
* `indicator()` hook. A util that implements `getIndicatorPath` is stroked on
|
|
12312
|
-
* the canvas overlay by `ShapeIndicatorCompositor` instead.
|
|
12313
|
-
*/
|
|
12314
|
-
declare function getShapeIndicatorNode<T extends UnknownShape>(util: {
|
|
12315
|
-
indicator?(shape: T): ReactNode;
|
|
12316
|
-
}, shape: T, bounds: {
|
|
12317
|
-
x: number;
|
|
12318
|
-
y: number;
|
|
12319
|
-
w: number;
|
|
12320
|
-
h: number;
|
|
12321
|
-
} | undefined): ReactNode;
|
|
12322
|
-
|
|
12323
|
-
declare const EditorContext: react.Context<Editor | null>;
|
|
12324
|
-
/** The editor of the nearest `<EditorProvider>` / `<Canvas>`. */
|
|
12325
|
-
declare function useEditor(): Editor;
|
|
12326
|
-
declare function useMaybeEditor(): Editor | null;
|
|
12327
|
-
/** Props of {@link EditorProvider}. */
|
|
12328
|
-
interface EditorProviderProps {
|
|
12329
|
-
/** The editor every `useEditor()` below this point resolves to. */
|
|
12330
|
-
editor: Editor;
|
|
12331
|
-
children?: ReactNode;
|
|
12332
|
-
}
|
|
12333
|
-
/**
|
|
12334
|
-
* Publishes an editor to the React tree.
|
|
12335
|
-
*
|
|
12336
|
-
* Takes the editor as `editor` rather than a context provider's `value`, so a
|
|
12337
|
-
* test — or an app rendering chrome outside `<Canvas>` — writes
|
|
12338
|
-
* `<EditorProvider editor={editor}>` and never has to know that a context is
|
|
12339
|
-
* what is underneath. {@link EditorContext} is still exported for the rare
|
|
12340
|
-
* caller that wants the raw provider (to publish `null`, say).
|
|
12341
|
-
*/
|
|
12342
|
-
declare function EditorProvider({ editor, children }: EditorProviderProps): react.JSX.Element;
|
|
12343
|
-
|
|
12344
|
-
interface HTMLContainerProps extends HTMLAttributes<HTMLDivElement> {
|
|
12345
|
-
children?: ReactNode;
|
|
12346
|
-
ref?: Ref<HTMLDivElement>;
|
|
12347
|
-
}
|
|
12348
|
-
/**
|
|
12349
|
-
* The DOM body of a shape. Fills the shape's bounds; anything else — size,
|
|
12350
|
-
* pointer-events, overflow, a class of your own — is set through `style` and
|
|
12351
|
-
* `className`, which are merged over the defaults rather than replacing them.
|
|
12352
|
-
*/
|
|
12353
|
-
declare function HTMLContainer({ children, className, style, ...rest }: HTMLContainerProps): react.JSX.Element;
|
|
12354
|
-
interface SVGContainerProps extends SVGAttributes<SVGSVGElement> {
|
|
12355
|
-
children?: ReactNode;
|
|
12356
|
-
ref?: Ref<SVGSVGElement>;
|
|
12357
|
-
}
|
|
12358
|
-
/**
|
|
12359
|
-
* The SVG body of a shape: an `<svg>` filling the shape's bounds, whose user
|
|
12360
|
-
* space is the shape's own local coordinate space, so a `<path>` drawn at
|
|
12361
|
-
* `(0, 0)` sits at the shape's origin at any pan, zoom or rotation.
|
|
12362
|
-
*/
|
|
12363
|
-
declare function SVGContainer({ children, className, style, ...rest }: SVGContainerProps): react.JSX.Element;
|
|
12364
|
-
/**
|
|
12365
|
-
* Stop an event travelling any further up the tree.
|
|
12366
|
-
*
|
|
12367
|
-
* The canvas listens for pointer events on its container, so a click on a
|
|
12368
|
-
* piece of chrome rendered over it — a toolbar button, a menu, a panel —
|
|
12369
|
-
* would also start a canvas interaction. Hanging this on the chrome's root
|
|
12370
|
-
* (`onPointerDown={stopEventPropagation}`) keeps the two apart.
|
|
12371
|
-
*
|
|
12372
|
-
* Typed structurally rather than against `React.SyntheticEvent` so it can be
|
|
12373
|
-
* handed to a native listener, a React handler, or a test double alike.
|
|
12374
|
-
*/
|
|
12375
|
-
declare function stopEventPropagation(event: {
|
|
12376
|
-
stopPropagation(): void;
|
|
12377
|
-
}): void;
|
|
12378
|
-
|
|
12379
|
-
/**
|
|
12380
|
-
* The bridge from the theme to CSS: the canvas container stamps the theme's
|
|
12381
|
-
* surface colours as custom properties, and everything drawn in CSS or SVG
|
|
12382
|
-
* reads them.
|
|
12383
|
-
*
|
|
12384
|
-
* Only the *surface* half of a ramp is published — the colours that belong to
|
|
12385
|
-
* the canvas rather than to any one shape. A shape's paint comes from its
|
|
12386
|
-
* style props through `getDisplayValues`, not from a variable, because a
|
|
12387
|
-
* shape is drawn on the GPU where a CSS variable means nothing.
|
|
12388
|
-
*/
|
|
12389
|
-
/**
|
|
12390
|
-
* Which theme colour each custom property carries.
|
|
12391
|
-
*
|
|
12392
|
-
* The names are the ones `ui.css` already declares and `Canvas` already reads,
|
|
12393
|
-
* so an app that themed mocanvas by overriding the variables by hand keeps
|
|
12394
|
-
* working: the theme now writes the same variables it used to have to be told.
|
|
12395
|
-
*/
|
|
12396
|
-
declare const CANVAS_THEME_VARS: {
|
|
12397
|
-
readonly "--mocanvas-selection": "selectStroke";
|
|
12398
|
-
readonly "--mocanvas-selection-fg": "background";
|
|
12399
|
-
readonly "--mocanvas-brush-fill": "selectFill";
|
|
12400
|
-
readonly "--mocanvas-brush-stroke": "selectStroke";
|
|
12401
|
-
readonly "--mocanvas-snap": "hint";
|
|
12402
|
-
readonly "--mocanvas-background": "background";
|
|
12403
|
-
readonly "--mocanvas-surface": "solid";
|
|
12404
|
-
readonly "--mocanvas-text": "text";
|
|
12405
|
-
readonly "--mocanvas-grid": "grid";
|
|
12406
|
-
};
|
|
12407
|
-
/**
|
|
12408
|
-
* The camera, as custom properties.
|
|
12409
|
-
*
|
|
12410
|
-
* Separate from the colours because these change on every zoom rather than on
|
|
12411
|
-
* a theme swap, and because they are the two variables an app most often needs
|
|
12412
|
-
* in CSS: anything drawn in the DOM over a zooming canvas has to divide by the
|
|
12413
|
-
* zoom to keep a constant on-screen size. `@mocanvas/compat` maps tldraw's
|
|
12414
|
-
* `--tl-zoom` and `--tl-scale` onto them; without them every `calc()` in a
|
|
12415
|
-
* migrated stylesheet resolved to nothing and took its whole declaration with
|
|
12416
|
-
* it.
|
|
12417
|
-
*/
|
|
12418
|
-
declare function getCameraCssVars(zoom: number): CSSProperties;
|
|
12419
|
-
/** {@link getCameraCssVars} for an editor, tracked reactively. */
|
|
12420
|
-
declare function useCameraCssVars(editor: Editor): CSSProperties;
|
|
12421
|
-
/**
|
|
12422
|
-
* The custom properties for one resolved ramp.
|
|
12423
|
-
*
|
|
12424
|
-
* SEMANTICS-ASSUMED: `--mocanvas-selection-fg` is the fill of a solid
|
|
12425
|
-
* selection handle, and is mapped to the theme's `background`. A handle is a
|
|
12426
|
-
* chip of the page punched out of the selection stroke, so it has to match the
|
|
12427
|
-
* page it sits on or it reads as a light dot on a dark canvas — which is
|
|
12428
|
-
* exactly what the hard-coded `#ffffff` did before the theme existed.
|
|
12429
|
-
*
|
|
12430
|
-
* A colour the ramp does not carry is skipped rather than written as
|
|
12431
|
-
* `undefined`, so the literal fallback in `var(--x, …)` still applies.
|
|
12432
|
-
*/
|
|
12433
|
-
declare function getThemeCssVars(colors: TLThemeColors | undefined): CSSProperties;
|
|
12434
|
-
/**
|
|
12435
|
-
* The theme's custom properties for an editor, tracked reactively — swapping a
|
|
12436
|
-
* theme or flipping to dark restamps the container without anything being
|
|
12437
|
-
* invalidated by hand.
|
|
12438
|
-
*
|
|
12439
|
-
* Takes the editor rather than reading it from context, because the element
|
|
12440
|
-
* that carries the variables is the canvas container itself: the hook runs
|
|
12441
|
-
* above the provider that would supply it. The theme manager is read
|
|
12442
|
-
* defensively for the same reason `useColorMode` does — a stand-in editor in a
|
|
12443
|
-
* chrome test has no theme at all.
|
|
12444
|
-
*/
|
|
12445
|
-
declare function useThemeCssVars(editor: Editor): CSSProperties;
|
|
12446
|
-
|
|
12447
|
-
/**
|
|
12448
|
-
* Where an app self-hosts the files the UI loads at runtime.
|
|
12449
|
-
*
|
|
12450
|
-
* mocanvas itself needs none of them — its icons are inline SVG and it ships
|
|
12451
|
-
* no translation bundles — so the map is carried, not consumed: it exists so a
|
|
12452
|
-
* component an app drops into a chrome slot can ask for the same base paths
|
|
12453
|
-
* the host configured, instead of every such component growing a prop for it.
|
|
12454
|
-
*
|
|
12455
|
-
* Kept as nested string maps rather than a fixed shape because the categories
|
|
12456
|
-
* are the app's, not ours; the four named below are only the ones a
|
|
12457
|
-
* self-hosting setup usually has.
|
|
12458
|
-
*/
|
|
12459
|
-
interface TLAssetUrls {
|
|
12460
|
-
fonts?: Readonly<Record<string, string>>;
|
|
12461
|
-
icons?: Readonly<Record<string, string>>;
|
|
12462
|
-
embedIcons?: Readonly<Record<string, string>>;
|
|
12463
|
-
translations?: Readonly<Record<string, string>>;
|
|
12464
|
-
[category: string]: Readonly<Record<string, string>> | undefined;
|
|
12465
|
-
}
|
|
12466
|
-
/**
|
|
12467
|
-
* The editor's half of the map: the fonts the canvas loads.
|
|
12468
|
-
*
|
|
12469
|
-
* A separate name from {@link TLAssetUrls} because the editor package can only
|
|
12470
|
-
* promise what it itself uses — the UI layer adds icons and translations on
|
|
12471
|
-
* top, as {@link TLUiAssetUrls}.
|
|
12472
|
-
*/
|
|
12473
|
-
interface TLEditorAssetUrls extends TLAssetUrls {
|
|
12474
|
-
fonts?: Readonly<Record<string, string>>;
|
|
12475
|
-
}
|
|
12476
|
-
/**
|
|
12477
|
-
* The UI layer's half: the icons and translation bundles a self-hosting app
|
|
12478
|
-
* serves itself.
|
|
12479
|
-
*/
|
|
12480
|
-
interface TLUiAssetUrls extends TLEditorAssetUrls {
|
|
12481
|
-
icons?: Readonly<Record<string, string>>;
|
|
12482
|
-
embedIcons?: Readonly<Record<string, string>>;
|
|
12483
|
-
translations?: Readonly<Record<string, string>>;
|
|
12484
|
-
}
|
|
12485
|
-
interface AssetUrlsProviderProps {
|
|
12486
|
-
assetUrls: TLAssetUrls;
|
|
12487
|
-
children?: ReactNode;
|
|
12488
|
-
}
|
|
12489
|
-
/** Publishes an {@link TLAssetUrls} map to everything below it. */
|
|
12490
|
-
declare function AssetUrlsProvider({ assetUrls, children }: AssetUrlsProviderProps): react.JSX.Element;
|
|
12491
|
-
/**
|
|
12492
|
-
* The asset urls the host configured. Empty outside a provider — a component
|
|
12493
|
-
* that needs a file should fall back to its own default rather than fail,
|
|
12494
|
-
* because most mounts configure nothing at all.
|
|
12495
|
-
*/
|
|
12496
|
-
declare function useAssetUrls(): TLAssetUrls;
|
|
12497
|
-
|
|
12498
12253
|
/**
|
|
12499
12254
|
* The UI override surface: the types an app uses to replace mocanvas's chrome
|
|
12500
12255
|
* and to add its own tools to it.
|
|
@@ -12807,6 +12562,257 @@ interface TLUiOverrides {
|
|
|
12807
12562
|
*/
|
|
12808
12563
|
type TLUiTranslations = Record<string, Record<string, string>>;
|
|
12809
12564
|
|
|
12565
|
+
/**
|
|
12566
|
+
* What the `Canvas` component slot is handed.
|
|
12567
|
+
*
|
|
12568
|
+
* A host replacing the canvas gets only presentation: a class name and
|
|
12569
|
+
* children. It deliberately does *not* receive the editor as a prop — the
|
|
12570
|
+
* replacement is rendered inside the editor's provider and reads it with
|
|
12571
|
+
* `useEditor()`, so a slot cannot be rendered against a different editor than
|
|
12572
|
+
* the one it is inside of.
|
|
12573
|
+
*/
|
|
12574
|
+
interface TLCanvasComponentProps {
|
|
12575
|
+
className?: string;
|
|
12576
|
+
children?: ReactNode;
|
|
12577
|
+
}
|
|
12578
|
+
interface CanvasProps {
|
|
12579
|
+
editor: Editor;
|
|
12580
|
+
className?: string;
|
|
12581
|
+
style?: CSSProperties;
|
|
12582
|
+
/** Extra layers rendered above the canvas (UI, menus). */
|
|
12583
|
+
children?: ReactNode;
|
|
12584
|
+
/** Override the default selection/brush indicators. */
|
|
12585
|
+
components?: Partial<CanvasComponents>;
|
|
12586
|
+
/**
|
|
12587
|
+
* The overlay util that paints shape indicators onto the canvas layer.
|
|
12588
|
+
*
|
|
12589
|
+
* A *class*, not an instance — one is constructed per editor. Pass
|
|
12590
|
+
* `ShapeIndicatorCompositor.configure({ lineWidth })` to restyle, or a
|
|
12591
|
+
* subclass to control which shapes get an outline.
|
|
12592
|
+
*/
|
|
12593
|
+
indicatorOverlayUtil?: typeof ShapeIndicatorCompositor;
|
|
12594
|
+
}
|
|
12595
|
+
interface CanvasComponents {
|
|
12596
|
+
Indicators: (props: {
|
|
12597
|
+
editor: Editor;
|
|
12598
|
+
}) => ReactNode;
|
|
12599
|
+
Brush: (props: {
|
|
12600
|
+
editor: Editor;
|
|
12601
|
+
}) => ReactNode;
|
|
12602
|
+
Background: (props: {
|
|
12603
|
+
editor: Editor;
|
|
12604
|
+
}) => ReactNode;
|
|
12605
|
+
/**
|
|
12606
|
+
* The grid, behind the scene. Rendered only in grid mode, and handed the
|
|
12607
|
+
* camera and the document's step rather than reading them — see
|
|
12608
|
+
* `TLComponents.Grid`. `null` draws none; omitted uses {@link DefaultGrid}.
|
|
12609
|
+
*/
|
|
12610
|
+
Grid: ((props: TLGridProps) => ReactNode) | null;
|
|
12611
|
+
}
|
|
12612
|
+
/**
|
|
12613
|
+
* The canvas: a WebGL2 surface driven by the engine, a DOM overlay for shapes
|
|
12614
|
+
* that render through `ShapeUtil.component`, a 2D canvas overlay for shape
|
|
12615
|
+
* indicators, and an SVG layer for the selection handles, snap lines, the brush
|
|
12616
|
+
* — and for any util still on the deprecated `indicator()` hook.
|
|
12617
|
+
*/
|
|
12618
|
+
declare function Canvas({ editor, className, style, children, components, indicatorOverlayUtil }: CanvasProps): react.JSX.Element;
|
|
12619
|
+
/**
|
|
12620
|
+
* The outline to draw over one shape: whatever its util's `indicator()`
|
|
12621
|
+
* returns, or a rectangle around the shape's geometry bounds when the util has
|
|
12622
|
+
* no indicator (or returns nothing). Both are expressed in *shape-local*
|
|
12623
|
+
* coordinates; the caller wraps them in the shape's page transform.
|
|
12624
|
+
*
|
|
12625
|
+
* Pure and exported so a custom `Indicators` component can reuse the same rule
|
|
12626
|
+
* instead of guessing at it.
|
|
12627
|
+
*
|
|
12628
|
+
* @deprecated The SVG indicator layer only draws utils still on the deprecated
|
|
12629
|
+
* `indicator()` hook. A util that implements `getIndicatorPath` is stroked on
|
|
12630
|
+
* the canvas overlay by `ShapeIndicatorCompositor` instead.
|
|
12631
|
+
*/
|
|
12632
|
+
declare function getShapeIndicatorNode<T extends UnknownShape>(util: {
|
|
12633
|
+
indicator?(shape: T): ReactNode;
|
|
12634
|
+
}, shape: T, bounds: {
|
|
12635
|
+
x: number;
|
|
12636
|
+
y: number;
|
|
12637
|
+
w: number;
|
|
12638
|
+
h: number;
|
|
12639
|
+
} | undefined): ReactNode;
|
|
12640
|
+
|
|
12641
|
+
declare const EditorContext: react.Context<Editor | null>;
|
|
12642
|
+
/** The editor of the nearest `<EditorProvider>` / `<Canvas>`. */
|
|
12643
|
+
declare function useEditor(): Editor;
|
|
12644
|
+
declare function useMaybeEditor(): Editor | null;
|
|
12645
|
+
/** Props of {@link EditorProvider}. */
|
|
12646
|
+
interface EditorProviderProps {
|
|
12647
|
+
/** The editor every `useEditor()` below this point resolves to. */
|
|
12648
|
+
editor: Editor;
|
|
12649
|
+
children?: ReactNode;
|
|
12650
|
+
}
|
|
12651
|
+
/**
|
|
12652
|
+
* Publishes an editor to the React tree.
|
|
12653
|
+
*
|
|
12654
|
+
* Takes the editor as `editor` rather than a context provider's `value`, so a
|
|
12655
|
+
* test — or an app rendering chrome outside `<Canvas>` — writes
|
|
12656
|
+
* `<EditorProvider editor={editor}>` and never has to know that a context is
|
|
12657
|
+
* what is underneath. {@link EditorContext} is still exported for the rare
|
|
12658
|
+
* caller that wants the raw provider (to publish `null`, say).
|
|
12659
|
+
*/
|
|
12660
|
+
declare function EditorProvider({ editor, children }: EditorProviderProps): react.JSX.Element;
|
|
12661
|
+
|
|
12662
|
+
interface HTMLContainerProps extends HTMLAttributes<HTMLDivElement> {
|
|
12663
|
+
children?: ReactNode;
|
|
12664
|
+
ref?: Ref<HTMLDivElement>;
|
|
12665
|
+
}
|
|
12666
|
+
/**
|
|
12667
|
+
* The DOM body of a shape. Fills the shape's bounds; anything else — size,
|
|
12668
|
+
* pointer-events, overflow, a class of your own — is set through `style` and
|
|
12669
|
+
* `className`, which are merged over the defaults rather than replacing them.
|
|
12670
|
+
*/
|
|
12671
|
+
declare function HTMLContainer({ children, className, style, ...rest }: HTMLContainerProps): react.JSX.Element;
|
|
12672
|
+
interface SVGContainerProps extends SVGAttributes<SVGSVGElement> {
|
|
12673
|
+
children?: ReactNode;
|
|
12674
|
+
ref?: Ref<SVGSVGElement>;
|
|
12675
|
+
}
|
|
12676
|
+
/**
|
|
12677
|
+
* The SVG body of a shape: an `<svg>` filling the shape's bounds, whose user
|
|
12678
|
+
* space is the shape's own local coordinate space, so a `<path>` drawn at
|
|
12679
|
+
* `(0, 0)` sits at the shape's origin at any pan, zoom or rotation.
|
|
12680
|
+
*/
|
|
12681
|
+
declare function SVGContainer({ children, className, style, ...rest }: SVGContainerProps): react.JSX.Element;
|
|
12682
|
+
/**
|
|
12683
|
+
* Stop an event travelling any further up the tree.
|
|
12684
|
+
*
|
|
12685
|
+
* The canvas listens for pointer events on its container, so a click on a
|
|
12686
|
+
* piece of chrome rendered over it — a toolbar button, a menu, a panel —
|
|
12687
|
+
* would also start a canvas interaction. Hanging this on the chrome's root
|
|
12688
|
+
* (`onPointerDown={stopEventPropagation}`) keeps the two apart.
|
|
12689
|
+
*
|
|
12690
|
+
* Typed structurally rather than against `React.SyntheticEvent` so it can be
|
|
12691
|
+
* handed to a native listener, a React handler, or a test double alike.
|
|
12692
|
+
*/
|
|
12693
|
+
declare function stopEventPropagation(event: {
|
|
12694
|
+
stopPropagation(): void;
|
|
12695
|
+
}): void;
|
|
12696
|
+
|
|
12697
|
+
/**
|
|
12698
|
+
* The bridge from the theme to CSS: the canvas container stamps the theme's
|
|
12699
|
+
* surface colours as custom properties, and everything drawn in CSS or SVG
|
|
12700
|
+
* reads them.
|
|
12701
|
+
*
|
|
12702
|
+
* Only the *surface* half of a ramp is published — the colours that belong to
|
|
12703
|
+
* the canvas rather than to any one shape. A shape's paint comes from its
|
|
12704
|
+
* style props through `getDisplayValues`, not from a variable, because a
|
|
12705
|
+
* shape is drawn on the GPU where a CSS variable means nothing.
|
|
12706
|
+
*/
|
|
12707
|
+
/**
|
|
12708
|
+
* Which theme colour each custom property carries.
|
|
12709
|
+
*
|
|
12710
|
+
* The names are the ones `ui.css` already declares and `Canvas` already reads,
|
|
12711
|
+
* so an app that themed mocanvas by overriding the variables by hand keeps
|
|
12712
|
+
* working: the theme now writes the same variables it used to have to be told.
|
|
12713
|
+
*/
|
|
12714
|
+
declare const CANVAS_THEME_VARS: {
|
|
12715
|
+
readonly "--mocanvas-selection": "selectStroke";
|
|
12716
|
+
readonly "--mocanvas-selection-fg": "background";
|
|
12717
|
+
readonly "--mocanvas-brush-fill": "selectFill";
|
|
12718
|
+
readonly "--mocanvas-brush-stroke": "selectStroke";
|
|
12719
|
+
readonly "--mocanvas-snap": "hint";
|
|
12720
|
+
readonly "--mocanvas-background": "background";
|
|
12721
|
+
readonly "--mocanvas-surface": "solid";
|
|
12722
|
+
readonly "--mocanvas-text": "text";
|
|
12723
|
+
readonly "--mocanvas-grid": "grid";
|
|
12724
|
+
};
|
|
12725
|
+
/**
|
|
12726
|
+
* The camera, as custom properties.
|
|
12727
|
+
*
|
|
12728
|
+
* Separate from the colours because these change on every zoom rather than on
|
|
12729
|
+
* a theme swap, and because they are the two variables an app most often needs
|
|
12730
|
+
* in CSS: anything drawn in the DOM over a zooming canvas has to divide by the
|
|
12731
|
+
* zoom to keep a constant on-screen size. `@mocanvas/compat` maps tldraw's
|
|
12732
|
+
* `--tl-zoom` and `--tl-scale` onto them; without them every `calc()` in a
|
|
12733
|
+
* migrated stylesheet resolved to nothing and took its whole declaration with
|
|
12734
|
+
* it.
|
|
12735
|
+
*/
|
|
12736
|
+
declare function getCameraCssVars(zoom: number): CSSProperties;
|
|
12737
|
+
/** {@link getCameraCssVars} for an editor, tracked reactively. */
|
|
12738
|
+
declare function useCameraCssVars(editor: Editor): CSSProperties;
|
|
12739
|
+
/**
|
|
12740
|
+
* The custom properties for one resolved ramp.
|
|
12741
|
+
*
|
|
12742
|
+
* SEMANTICS-ASSUMED: `--mocanvas-selection-fg` is the fill of a solid
|
|
12743
|
+
* selection handle, and is mapped to the theme's `background`. A handle is a
|
|
12744
|
+
* chip of the page punched out of the selection stroke, so it has to match the
|
|
12745
|
+
* page it sits on or it reads as a light dot on a dark canvas — which is
|
|
12746
|
+
* exactly what the hard-coded `#ffffff` did before the theme existed.
|
|
12747
|
+
*
|
|
12748
|
+
* A colour the ramp does not carry is skipped rather than written as
|
|
12749
|
+
* `undefined`, so the literal fallback in `var(--x, …)` still applies.
|
|
12750
|
+
*/
|
|
12751
|
+
declare function getThemeCssVars(colors: TLThemeColors | undefined): CSSProperties;
|
|
12752
|
+
/**
|
|
12753
|
+
* The theme's custom properties for an editor, tracked reactively — swapping a
|
|
12754
|
+
* theme or flipping to dark restamps the container without anything being
|
|
12755
|
+
* invalidated by hand.
|
|
12756
|
+
*
|
|
12757
|
+
* Takes the editor rather than reading it from context, because the element
|
|
12758
|
+
* that carries the variables is the canvas container itself: the hook runs
|
|
12759
|
+
* above the provider that would supply it. The theme manager is read
|
|
12760
|
+
* defensively for the same reason `useColorMode` does — a stand-in editor in a
|
|
12761
|
+
* chrome test has no theme at all.
|
|
12762
|
+
*/
|
|
12763
|
+
declare function useThemeCssVars(editor: Editor): CSSProperties;
|
|
12764
|
+
|
|
12765
|
+
/**
|
|
12766
|
+
* Where an app self-hosts the files the UI loads at runtime.
|
|
12767
|
+
*
|
|
12768
|
+
* mocanvas itself needs none of them — its icons are inline SVG and it ships
|
|
12769
|
+
* no translation bundles — so the map is carried, not consumed: it exists so a
|
|
12770
|
+
* component an app drops into a chrome slot can ask for the same base paths
|
|
12771
|
+
* the host configured, instead of every such component growing a prop for it.
|
|
12772
|
+
*
|
|
12773
|
+
* Kept as nested string maps rather than a fixed shape because the categories
|
|
12774
|
+
* are the app's, not ours; the four named below are only the ones a
|
|
12775
|
+
* self-hosting setup usually has.
|
|
12776
|
+
*/
|
|
12777
|
+
interface TLAssetUrls {
|
|
12778
|
+
fonts?: Readonly<Record<string, string>>;
|
|
12779
|
+
icons?: Readonly<Record<string, string>>;
|
|
12780
|
+
embedIcons?: Readonly<Record<string, string>>;
|
|
12781
|
+
translations?: Readonly<Record<string, string>>;
|
|
12782
|
+
[category: string]: Readonly<Record<string, string>> | undefined;
|
|
12783
|
+
}
|
|
12784
|
+
/**
|
|
12785
|
+
* The editor's half of the map: the fonts the canvas loads.
|
|
12786
|
+
*
|
|
12787
|
+
* A separate name from {@link TLAssetUrls} because the editor package can only
|
|
12788
|
+
* promise what it itself uses — the UI layer adds icons and translations on
|
|
12789
|
+
* top, as {@link TLUiAssetUrls}.
|
|
12790
|
+
*/
|
|
12791
|
+
interface TLEditorAssetUrls extends TLAssetUrls {
|
|
12792
|
+
fonts?: Readonly<Record<string, string>>;
|
|
12793
|
+
}
|
|
12794
|
+
/**
|
|
12795
|
+
* The UI layer's half: the icons and translation bundles a self-hosting app
|
|
12796
|
+
* serves itself.
|
|
12797
|
+
*/
|
|
12798
|
+
interface TLUiAssetUrls extends TLEditorAssetUrls {
|
|
12799
|
+
icons?: Readonly<Record<string, string>>;
|
|
12800
|
+
embedIcons?: Readonly<Record<string, string>>;
|
|
12801
|
+
translations?: Readonly<Record<string, string>>;
|
|
12802
|
+
}
|
|
12803
|
+
interface AssetUrlsProviderProps {
|
|
12804
|
+
assetUrls: TLAssetUrls;
|
|
12805
|
+
children?: ReactNode;
|
|
12806
|
+
}
|
|
12807
|
+
/** Publishes an {@link TLAssetUrls} map to everything below it. */
|
|
12808
|
+
declare function AssetUrlsProvider({ assetUrls, children }: AssetUrlsProviderProps): react.JSX.Element;
|
|
12809
|
+
/**
|
|
12810
|
+
* The asset urls the host configured. Empty outside a provider — a component
|
|
12811
|
+
* that needs a file should fall back to its own default rather than fail,
|
|
12812
|
+
* because most mounts configure nothing at all.
|
|
12813
|
+
*/
|
|
12814
|
+
declare function useAssetUrls(): TLAssetUrls;
|
|
12815
|
+
|
|
12810
12816
|
/**
|
|
12811
12817
|
* Resolving a UI string id through an app's `TLUiOverrides.translations`.
|
|
12812
12818
|
*
|