canvu-react 0.4.46 → 0.4.48
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/{asset-hydration-Dc7fsnTG.d.ts → asset-hydration-BSjiek7Q.d.ts} +2 -2
- package/dist/{asset-hydration-Cy_2FyV5.d.cts → asset-hydration-F6aM5C7x.d.cts} +2 -2
- package/dist/{asset-store-TzOPvlgn.d.cts → asset-store-35ysK28r.d.cts} +1 -1
- package/dist/{asset-store-DQPRZEcy.d.ts → asset-store-D_FjW_CN.d.ts} +1 -1
- package/dist/chatbot.d.cts +6 -6
- package/dist/chatbot.d.ts +6 -6
- package/dist/index.cjs +49 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -9
- package/dist/index.d.ts +53 -9
- package/dist/index.js +49 -1
- package/dist/index.js.map +1 -1
- package/dist/{link-item-DwzXOwU5.d.cts → link-item-BMV3VUCr.d.cts} +1 -1
- package/dist/{link-item-IW4GTnxl.d.ts → link-item-COoNNvCu.d.ts} +1 -1
- package/dist/native.cjs +104 -51
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.cts +6 -6
- package/dist/native.d.ts +6 -6
- package/dist/native.js +104 -51
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +259 -18
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +29 -13
- package/dist/react.d.ts +29 -13
- package/dist/react.js +259 -18
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs +3 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +8 -8
- package/dist/realtime.d.ts +8 -8
- package/dist/realtime.js +3 -1
- package/dist/realtime.js.map +1 -1
- package/dist/realtimeNative.d.cts +4 -4
- package/dist/realtimeNative.d.ts +4 -4
- package/dist/{shape-builders-Cyh8zvDG.d.ts → shape-builders-BCOAG0pS.d.ts} +1 -1
- package/dist/{shape-builders-CKEMjivV.d.cts → shape-builders-BmLS8CNh.d.cts} +1 -1
- package/dist/tldraw.cjs +3 -1
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.d.cts +1 -1
- package/dist/tldraw.d.ts +1 -1
- package/dist/tldraw.js +3 -1
- package/dist/tldraw.js.map +1 -1
- package/dist/{types-BUPc2Zgw.d.cts → types-6HszqSa5.d.cts} +1 -1
- package/dist/{types-B7xZAKVJ.d.ts → types-BAEHaIYO.d.ts} +43 -6
- package/dist/{types-B82WiQQh.d.ts → types-BMMPUak7.d.ts} +1 -1
- package/dist/{types-BQUbxMgz.d.cts → types-BOQLWyCw.d.cts} +1 -1
- package/dist/{types-CYtq9Pr9.d.ts → types-BtWbGOqh.d.ts} +1 -1
- package/dist/{types-BCCvY6ie.d.cts → types-fJNwEnHf.d.cts} +35 -1
- package/dist/{types-BCCvY6ie.d.ts → types-fJNwEnHf.d.ts} +35 -1
- package/dist/{types-C4wI3Jyc.d.cts → types-uzeExFkd.d.cts} +43 -6
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { C as Camera2D } from './shape-builders-
|
|
2
|
-
export { a as Camera2DOptions, D as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildRectSvg, k as computeFreehandSvgPayload, l as createArchitecturalCloudItem, m as createDrawDotItem, n as createEllipseItem, o as createFreehandStrokeItem, p as createImageFromVectorTrace, q as createImageItem, r as createLineItem, s as createRectangleItem, t as createShapeId, u as createTextItem, v as lineEndpointsToLocal, w as rebuildItemSvg, x as resolveStrokeStyle } from './shape-builders-
|
|
3
|
-
import { V as VectorSceneItem, A as ArrowEndpointBinding, R as Rect } from './types-
|
|
4
|
-
export { a as ArrowBindings, b as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-
|
|
5
|
-
export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-
|
|
6
|
-
export { C as CanvuLinkData, D as DEFAULT_LINK_CARD_SIZE, L as LINK_PLUGIN_KEY, b as buildLinkCardSvg, c as createLinkItem, g as getLinkData, i as isLinkItem } from './link-item-
|
|
7
|
-
import './asset-store-
|
|
1
|
+
import { C as Camera2D } from './shape-builders-BmLS8CNh.cjs';
|
|
2
|
+
export { a as Camera2DOptions, D as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildRectSvg, k as computeFreehandSvgPayload, l as createArchitecturalCloudItem, m as createDrawDotItem, n as createEllipseItem, o as createFreehandStrokeItem, p as createImageFromVectorTrace, q as createImageItem, r as createLineItem, s as createRectangleItem, t as createShapeId, u as createTextItem, v as lineEndpointsToLocal, w as rebuildItemSvg, x as resolveStrokeStyle } from './shape-builders-BmLS8CNh.cjs';
|
|
3
|
+
import { V as VectorSceneItem, A as ArrowEndpointBinding, C as CustomShapeResizeHandles, R as Rect } from './types-fJNwEnHf.cjs';
|
|
4
|
+
export { a as ArrowBindings, b as ResizeHandleId, c as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-fJNwEnHf.cjs';
|
|
5
|
+
export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-F6aM5C7x.cjs';
|
|
6
|
+
export { C as CanvuLinkData, D as DEFAULT_LINK_CARD_SIZE, L as LINK_PLUGIN_KEY, b as buildLinkCardSvg, c as createLinkItem, g as getLinkData, i as isLinkItem } from './link-item-BMV3VUCr.cjs';
|
|
7
|
+
import './asset-store-35ysK28r.cjs';
|
|
8
8
|
|
|
9
9
|
type EncodeCanvasToBlobOptions = {
|
|
10
10
|
mimeType?: string;
|
|
@@ -181,6 +181,10 @@ type SvgVectorRendererOptions = {
|
|
|
181
181
|
*/
|
|
182
182
|
pointerEventsNone?: boolean;
|
|
183
183
|
};
|
|
184
|
+
type SvgVectorRendererInteractionState = {
|
|
185
|
+
selectedIds?: readonly string[];
|
|
186
|
+
hoveredItemId?: string | null;
|
|
187
|
+
};
|
|
184
188
|
/**
|
|
185
189
|
* Renders vector scene items into a single SVG: camera as an outer `<g>` transform,
|
|
186
190
|
* so geometry stays sharp at any zoom (no fixed-resolution raster).
|
|
@@ -196,9 +200,19 @@ declare class SvgVectorRenderer {
|
|
|
196
200
|
private readonly svg;
|
|
197
201
|
private readonly rootG;
|
|
198
202
|
private readonly itemNodeCache;
|
|
203
|
+
private selectedIds;
|
|
204
|
+
private hoveredItemId;
|
|
199
205
|
private liveOverlay;
|
|
200
206
|
private readonly resizeObserver;
|
|
201
207
|
constructor(options: SvgVectorRendererOptions);
|
|
208
|
+
/**
|
|
209
|
+
* Updates interaction attributes on item groups for CSS hooks.
|
|
210
|
+
*
|
|
211
|
+
* Use `[data-canvu-selected="true"]` and `[data-canvu-hovered="true"]`
|
|
212
|
+
* for animations in interactive canvases where the scene SVG may ignore
|
|
213
|
+
* pointer events.
|
|
214
|
+
*/
|
|
215
|
+
setInteractionState(state: SvgVectorRendererInteractionState): void;
|
|
202
216
|
/**
|
|
203
217
|
* Reads container size, culls items, and updates the SVG (incrementally when possible).
|
|
204
218
|
*/
|
|
@@ -214,6 +228,7 @@ declare class SvgVectorRenderer {
|
|
|
214
228
|
renderLiveItem(item: VectorSceneItem | null): void;
|
|
215
229
|
private keepLiveOverlayOnTop;
|
|
216
230
|
private syncVisibleItems;
|
|
231
|
+
private applyInteractionAttributes;
|
|
217
232
|
destroy(): void;
|
|
218
233
|
/** Toggle whether the scene SVG receives pointer events (vs overlay handling them). */
|
|
219
234
|
setPointerEventsNone(value: boolean): void;
|
|
@@ -240,6 +255,27 @@ type CreateCustomShapeContent = {
|
|
|
240
255
|
/** Returns inner SVG for the given box size (same coordinate range as `bounds`). */
|
|
241
256
|
render: (size: CustomShapeSize) => string;
|
|
242
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* Optional behavior and styling hooks for {@link createCustomShapeItem}.
|
|
260
|
+
*/
|
|
261
|
+
type CreateCustomShapeOptions = {
|
|
262
|
+
/**
|
|
263
|
+
* Controls which resize handles are visible and active for the custom shape.
|
|
264
|
+
*
|
|
265
|
+
* Defaults to `"all"`. Use `"corners"` for corner-only resize, explicit handle ids such
|
|
266
|
+
* as `["se"]` for constrained tools, or an empty array to hide resize dots while keeping
|
|
267
|
+
* selection and rotation available.
|
|
268
|
+
*/
|
|
269
|
+
resizeHandles?: CustomShapeResizeHandles;
|
|
270
|
+
/**
|
|
271
|
+
* CSS class applied to the outer rendered SVG `<g>`.
|
|
272
|
+
*
|
|
273
|
+
* Useful for custom animations and styling. In interactive canvases, prefer
|
|
274
|
+
* `[data-canvu-hovered="true"]` over `:hover` because the scene SVG often has
|
|
275
|
+
* `pointer-events: none` while Canvu owns hit-testing in a separate layer.
|
|
276
|
+
*/
|
|
277
|
+
svgClassName?: string;
|
|
278
|
+
};
|
|
243
279
|
/**
|
|
244
280
|
* Replaces `{{w}}`, `{{h}}`, `{{width}}`, and `{{height}}` in a string with the given dimensions.
|
|
245
281
|
* Use this if you build SVG strings yourself and want the same rules as {@link createCustomShapeItem}.
|
|
@@ -268,8 +304,16 @@ declare function buildCustomShapeChildrenSvg(inner: string, intrinsic: CustomSha
|
|
|
268
304
|
* svg: `<rect width="{{w}}" height="{{h}}" rx="8" fill="#e0e7ff" stroke="#6366f1" />`,
|
|
269
305
|
* });
|
|
270
306
|
* ```
|
|
307
|
+
*
|
|
308
|
+
* @example One resize handle and a CSS animation hook
|
|
309
|
+
* ```ts
|
|
310
|
+
* createCustomShapeItem(id, rect, { svg }, {
|
|
311
|
+
* resizeHandles: ["se"],
|
|
312
|
+
* svgClassName: "sticky-note",
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
271
315
|
*/
|
|
272
|
-
declare function createCustomShapeItem(id: string, bounds: Rect, content: CreateCustomShapeContent): VectorSceneItem;
|
|
316
|
+
declare function createCustomShapeItem(id: string, bounds: Rect, content: CreateCustomShapeContent, options?: CreateCustomShapeOptions): VectorSceneItem;
|
|
273
317
|
|
|
274
318
|
/**
|
|
275
319
|
* Deep-clones an item with a new id. Rebuilds SVG where the id is embedded (arrow, text, custom).
|
|
@@ -329,4 +373,4 @@ declare const DEFAULT_TEXT_FONT_SIZE = 18;
|
|
|
329
373
|
*/
|
|
330
374
|
declare function buildTextSvg(content: string, _width: number, _height: number, fillColor?: string, fontSize?: number): string;
|
|
331
375
|
|
|
332
|
-
export { ARROW_BIND_SNAP_PX, type ApplePencilNavOptions, ArrowEndpointBinding, Camera2D, type CreateCustomShapeContent, type CustomShapeSize, DEFAULT_TEXT_FONT_SIZE, type EncodeCanvasToBlobOptions, type LoadRasterImageFileOptions, MANAGED_KEY, MAX_RASTER_EMBED_DIMENSION, type RasterEmbedMode, type RasterSceneSource, Rect, SvgVectorRenderer, type SvgVectorRendererOptions, VectorScene, VectorSceneItem, type ViewportInputOptions, addManagedImage, attachApplePencilNavigation, attachViewportInput, bakeArrowItemToAbsolute, buildCustomShapeChildrenSvg, buildTextSvg, cloneVectorSceneItemWithNewId, cloneVectorSceneItemsWithNewIds, collectEraserTargetsAtWorldPoint, copyManagedImage, createCustomShapeItem, cullItemsByViewport, deleteManagedImage, encodeCanvasToBlob, expandCustomShapeTemplate, formatCameraTransform, formatItemPlacementTransform, hitTestWorldPoint, isArrowBindTarget, isManagedImage, itemHitTestWorldPoint, loadImageFileAsRasterSceneSource, markImageAsManaged, reorderManagedImages, resolveArrowBindingsInScene, restackManagedImages, rotateManagedImage, snapArrowEndpointToShape };
|
|
376
|
+
export { ARROW_BIND_SNAP_PX, type ApplePencilNavOptions, ArrowEndpointBinding, Camera2D, type CreateCustomShapeContent, type CreateCustomShapeOptions, CustomShapeResizeHandles, type CustomShapeSize, DEFAULT_TEXT_FONT_SIZE, type EncodeCanvasToBlobOptions, type LoadRasterImageFileOptions, MANAGED_KEY, MAX_RASTER_EMBED_DIMENSION, type RasterEmbedMode, type RasterSceneSource, Rect, SvgVectorRenderer, type SvgVectorRendererOptions, VectorScene, VectorSceneItem, type ViewportInputOptions, addManagedImage, attachApplePencilNavigation, attachViewportInput, bakeArrowItemToAbsolute, buildCustomShapeChildrenSvg, buildTextSvg, cloneVectorSceneItemWithNewId, cloneVectorSceneItemsWithNewIds, collectEraserTargetsAtWorldPoint, copyManagedImage, createCustomShapeItem, cullItemsByViewport, deleteManagedImage, encodeCanvasToBlob, expandCustomShapeTemplate, formatCameraTransform, formatItemPlacementTransform, hitTestWorldPoint, isArrowBindTarget, isManagedImage, itemHitTestWorldPoint, loadImageFileAsRasterSceneSource, markImageAsManaged, reorderManagedImages, resolveArrowBindingsInScene, restackManagedImages, rotateManagedImage, snapArrowEndpointToShape };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { C as Camera2D } from './shape-builders-
|
|
2
|
-
export { a as Camera2DOptions, D as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildRectSvg, k as computeFreehandSvgPayload, l as createArchitecturalCloudItem, m as createDrawDotItem, n as createEllipseItem, o as createFreehandStrokeItem, p as createImageFromVectorTrace, q as createImageItem, r as createLineItem, s as createRectangleItem, t as createShapeId, u as createTextItem, v as lineEndpointsToLocal, w as rebuildItemSvg, x as resolveStrokeStyle } from './shape-builders-
|
|
3
|
-
import { V as VectorSceneItem, A as ArrowEndpointBinding, R as Rect } from './types-
|
|
4
|
-
export { a as ArrowBindings, b as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-
|
|
5
|
-
export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-
|
|
6
|
-
export { C as CanvuLinkData, D as DEFAULT_LINK_CARD_SIZE, L as LINK_PLUGIN_KEY, b as buildLinkCardSvg, c as createLinkItem, g as getLinkData, i as isLinkItem } from './link-item-
|
|
7
|
-
import './asset-store-
|
|
1
|
+
import { C as Camera2D } from './shape-builders-BCOAG0pS.js';
|
|
2
|
+
export { a as Camera2DOptions, D as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildRectSvg, k as computeFreehandSvgPayload, l as createArchitecturalCloudItem, m as createDrawDotItem, n as createEllipseItem, o as createFreehandStrokeItem, p as createImageFromVectorTrace, q as createImageItem, r as createLineItem, s as createRectangleItem, t as createShapeId, u as createTextItem, v as lineEndpointsToLocal, w as rebuildItemSvg, x as resolveStrokeStyle } from './shape-builders-BCOAG0pS.js';
|
|
3
|
+
import { V as VectorSceneItem, A as ArrowEndpointBinding, C as CustomShapeResizeHandles, R as Rect } from './types-fJNwEnHf.js';
|
|
4
|
+
export { a as ArrowBindings, b as ResizeHandleId, c as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-fJNwEnHf.js';
|
|
5
|
+
export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-BSjiek7Q.js';
|
|
6
|
+
export { C as CanvuLinkData, D as DEFAULT_LINK_CARD_SIZE, L as LINK_PLUGIN_KEY, b as buildLinkCardSvg, c as createLinkItem, g as getLinkData, i as isLinkItem } from './link-item-COoNNvCu.js';
|
|
7
|
+
import './asset-store-D_FjW_CN.js';
|
|
8
8
|
|
|
9
9
|
type EncodeCanvasToBlobOptions = {
|
|
10
10
|
mimeType?: string;
|
|
@@ -181,6 +181,10 @@ type SvgVectorRendererOptions = {
|
|
|
181
181
|
*/
|
|
182
182
|
pointerEventsNone?: boolean;
|
|
183
183
|
};
|
|
184
|
+
type SvgVectorRendererInteractionState = {
|
|
185
|
+
selectedIds?: readonly string[];
|
|
186
|
+
hoveredItemId?: string | null;
|
|
187
|
+
};
|
|
184
188
|
/**
|
|
185
189
|
* Renders vector scene items into a single SVG: camera as an outer `<g>` transform,
|
|
186
190
|
* so geometry stays sharp at any zoom (no fixed-resolution raster).
|
|
@@ -196,9 +200,19 @@ declare class SvgVectorRenderer {
|
|
|
196
200
|
private readonly svg;
|
|
197
201
|
private readonly rootG;
|
|
198
202
|
private readonly itemNodeCache;
|
|
203
|
+
private selectedIds;
|
|
204
|
+
private hoveredItemId;
|
|
199
205
|
private liveOverlay;
|
|
200
206
|
private readonly resizeObserver;
|
|
201
207
|
constructor(options: SvgVectorRendererOptions);
|
|
208
|
+
/**
|
|
209
|
+
* Updates interaction attributes on item groups for CSS hooks.
|
|
210
|
+
*
|
|
211
|
+
* Use `[data-canvu-selected="true"]` and `[data-canvu-hovered="true"]`
|
|
212
|
+
* for animations in interactive canvases where the scene SVG may ignore
|
|
213
|
+
* pointer events.
|
|
214
|
+
*/
|
|
215
|
+
setInteractionState(state: SvgVectorRendererInteractionState): void;
|
|
202
216
|
/**
|
|
203
217
|
* Reads container size, culls items, and updates the SVG (incrementally when possible).
|
|
204
218
|
*/
|
|
@@ -214,6 +228,7 @@ declare class SvgVectorRenderer {
|
|
|
214
228
|
renderLiveItem(item: VectorSceneItem | null): void;
|
|
215
229
|
private keepLiveOverlayOnTop;
|
|
216
230
|
private syncVisibleItems;
|
|
231
|
+
private applyInteractionAttributes;
|
|
217
232
|
destroy(): void;
|
|
218
233
|
/** Toggle whether the scene SVG receives pointer events (vs overlay handling them). */
|
|
219
234
|
setPointerEventsNone(value: boolean): void;
|
|
@@ -240,6 +255,27 @@ type CreateCustomShapeContent = {
|
|
|
240
255
|
/** Returns inner SVG for the given box size (same coordinate range as `bounds`). */
|
|
241
256
|
render: (size: CustomShapeSize) => string;
|
|
242
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* Optional behavior and styling hooks for {@link createCustomShapeItem}.
|
|
260
|
+
*/
|
|
261
|
+
type CreateCustomShapeOptions = {
|
|
262
|
+
/**
|
|
263
|
+
* Controls which resize handles are visible and active for the custom shape.
|
|
264
|
+
*
|
|
265
|
+
* Defaults to `"all"`. Use `"corners"` for corner-only resize, explicit handle ids such
|
|
266
|
+
* as `["se"]` for constrained tools, or an empty array to hide resize dots while keeping
|
|
267
|
+
* selection and rotation available.
|
|
268
|
+
*/
|
|
269
|
+
resizeHandles?: CustomShapeResizeHandles;
|
|
270
|
+
/**
|
|
271
|
+
* CSS class applied to the outer rendered SVG `<g>`.
|
|
272
|
+
*
|
|
273
|
+
* Useful for custom animations and styling. In interactive canvases, prefer
|
|
274
|
+
* `[data-canvu-hovered="true"]` over `:hover` because the scene SVG often has
|
|
275
|
+
* `pointer-events: none` while Canvu owns hit-testing in a separate layer.
|
|
276
|
+
*/
|
|
277
|
+
svgClassName?: string;
|
|
278
|
+
};
|
|
243
279
|
/**
|
|
244
280
|
* Replaces `{{w}}`, `{{h}}`, `{{width}}`, and `{{height}}` in a string with the given dimensions.
|
|
245
281
|
* Use this if you build SVG strings yourself and want the same rules as {@link createCustomShapeItem}.
|
|
@@ -268,8 +304,16 @@ declare function buildCustomShapeChildrenSvg(inner: string, intrinsic: CustomSha
|
|
|
268
304
|
* svg: `<rect width="{{w}}" height="{{h}}" rx="8" fill="#e0e7ff" stroke="#6366f1" />`,
|
|
269
305
|
* });
|
|
270
306
|
* ```
|
|
307
|
+
*
|
|
308
|
+
* @example One resize handle and a CSS animation hook
|
|
309
|
+
* ```ts
|
|
310
|
+
* createCustomShapeItem(id, rect, { svg }, {
|
|
311
|
+
* resizeHandles: ["se"],
|
|
312
|
+
* svgClassName: "sticky-note",
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
271
315
|
*/
|
|
272
|
-
declare function createCustomShapeItem(id: string, bounds: Rect, content: CreateCustomShapeContent): VectorSceneItem;
|
|
316
|
+
declare function createCustomShapeItem(id: string, bounds: Rect, content: CreateCustomShapeContent, options?: CreateCustomShapeOptions): VectorSceneItem;
|
|
273
317
|
|
|
274
318
|
/**
|
|
275
319
|
* Deep-clones an item with a new id. Rebuilds SVG where the id is embedded (arrow, text, custom).
|
|
@@ -329,4 +373,4 @@ declare const DEFAULT_TEXT_FONT_SIZE = 18;
|
|
|
329
373
|
*/
|
|
330
374
|
declare function buildTextSvg(content: string, _width: number, _height: number, fillColor?: string, fontSize?: number): string;
|
|
331
375
|
|
|
332
|
-
export { ARROW_BIND_SNAP_PX, type ApplePencilNavOptions, ArrowEndpointBinding, Camera2D, type CreateCustomShapeContent, type CustomShapeSize, DEFAULT_TEXT_FONT_SIZE, type EncodeCanvasToBlobOptions, type LoadRasterImageFileOptions, MANAGED_KEY, MAX_RASTER_EMBED_DIMENSION, type RasterEmbedMode, type RasterSceneSource, Rect, SvgVectorRenderer, type SvgVectorRendererOptions, VectorScene, VectorSceneItem, type ViewportInputOptions, addManagedImage, attachApplePencilNavigation, attachViewportInput, bakeArrowItemToAbsolute, buildCustomShapeChildrenSvg, buildTextSvg, cloneVectorSceneItemWithNewId, cloneVectorSceneItemsWithNewIds, collectEraserTargetsAtWorldPoint, copyManagedImage, createCustomShapeItem, cullItemsByViewport, deleteManagedImage, encodeCanvasToBlob, expandCustomShapeTemplate, formatCameraTransform, formatItemPlacementTransform, hitTestWorldPoint, isArrowBindTarget, isManagedImage, itemHitTestWorldPoint, loadImageFileAsRasterSceneSource, markImageAsManaged, reorderManagedImages, resolveArrowBindingsInScene, restackManagedImages, rotateManagedImage, snapArrowEndpointToShape };
|
|
376
|
+
export { ARROW_BIND_SNAP_PX, type ApplePencilNavOptions, ArrowEndpointBinding, Camera2D, type CreateCustomShapeContent, type CreateCustomShapeOptions, CustomShapeResizeHandles, type CustomShapeSize, DEFAULT_TEXT_FONT_SIZE, type EncodeCanvasToBlobOptions, type LoadRasterImageFileOptions, MANAGED_KEY, MAX_RASTER_EMBED_DIMENSION, type RasterEmbedMode, type RasterSceneSource, Rect, SvgVectorRenderer, type SvgVectorRendererOptions, VectorScene, VectorSceneItem, type ViewportInputOptions, addManagedImage, attachApplePencilNavigation, attachViewportInput, bakeArrowItemToAbsolute, buildCustomShapeChildrenSvg, buildTextSvg, cloneVectorSceneItemWithNewId, cloneVectorSceneItemsWithNewIds, collectEraserTargetsAtWorldPoint, copyManagedImage, createCustomShapeItem, cullItemsByViewport, deleteManagedImage, encodeCanvasToBlob, expandCustomShapeTemplate, formatCameraTransform, formatItemPlacementTransform, hitTestWorldPoint, isArrowBindTarget, isManagedImage, itemHitTestWorldPoint, loadImageFileAsRasterSceneSource, markImageAsManaged, reorderManagedImages, resolveArrowBindingsInScene, restackManagedImages, rotateManagedImage, snapArrowEndpointToShape };
|
package/dist/index.js
CHANGED
|
@@ -967,7 +967,7 @@ function buildCustomShapeChildrenSvg(inner, intrinsic, bounds) {
|
|
|
967
967
|
const sy = b.height / intrinsic.height;
|
|
968
968
|
return `<g transform="scale(${sx},${sy})">${inner}</g>`;
|
|
969
969
|
}
|
|
970
|
-
function createCustomShapeItem(id, bounds, content) {
|
|
970
|
+
function createCustomShapeItem(id, bounds, content, options = {}) {
|
|
971
971
|
const r = normalizeRect(bounds);
|
|
972
972
|
const intrinsic = { width: r.width, height: r.height };
|
|
973
973
|
const inner = resolveCustomInner(content, intrinsic);
|
|
@@ -979,6 +979,8 @@ function createCustomShapeItem(id, bounds, content) {
|
|
|
979
979
|
toolKind: "custom",
|
|
980
980
|
customIntrinsicSize: intrinsic,
|
|
981
981
|
customInnerSvg: inner,
|
|
982
|
+
...options.resizeHandles !== void 0 ? { customResizeHandles: options.resizeHandles } : {},
|
|
983
|
+
...options.svgClassName ? { svgClassName: options.svgClassName } : {},
|
|
982
984
|
childrenSvg: buildCustomShapeChildrenSvg(inner, intrinsic, r)
|
|
983
985
|
};
|
|
984
986
|
}
|
|
@@ -2806,6 +2808,14 @@ function formatItemPlacementTransform(item) {
|
|
|
2806
2808
|
const cy = r.height / 2;
|
|
2807
2809
|
return `translate(${item.x}, ${item.y}) translate(${cx}, ${cy}) rotate(${deg}) translate(${-cx}, ${-cy})`;
|
|
2808
2810
|
}
|
|
2811
|
+
function itemClassName(item) {
|
|
2812
|
+
const kind = item.toolKind ?? "unknown";
|
|
2813
|
+
const classes = [`canvu-item`, `canvu-item--${kind}`];
|
|
2814
|
+
if (item.svgClassName) {
|
|
2815
|
+
classes.push(item.svgClassName);
|
|
2816
|
+
}
|
|
2817
|
+
return classes.join(" ");
|
|
2818
|
+
}
|
|
2809
2819
|
var SvgVectorRenderer = class {
|
|
2810
2820
|
container;
|
|
2811
2821
|
scene;
|
|
@@ -2813,6 +2823,8 @@ var SvgVectorRenderer = class {
|
|
|
2813
2823
|
svg;
|
|
2814
2824
|
rootG;
|
|
2815
2825
|
itemNodeCache = /* @__PURE__ */ new Map();
|
|
2826
|
+
selectedIds = /* @__PURE__ */ new Set();
|
|
2827
|
+
hoveredItemId = null;
|
|
2816
2828
|
liveOverlay = null;
|
|
2817
2829
|
resizeObserver;
|
|
2818
2830
|
constructor(options) {
|
|
@@ -2833,6 +2845,20 @@ var SvgVectorRenderer = class {
|
|
|
2833
2845
|
this.resizeObserver = new ResizeObserver(() => this.render());
|
|
2834
2846
|
this.resizeObserver.observe(this.container);
|
|
2835
2847
|
}
|
|
2848
|
+
/**
|
|
2849
|
+
* Updates interaction attributes on item groups for CSS hooks.
|
|
2850
|
+
*
|
|
2851
|
+
* Use `[data-canvu-selected="true"]` and `[data-canvu-hovered="true"]`
|
|
2852
|
+
* for animations in interactive canvases where the scene SVG may ignore
|
|
2853
|
+
* pointer events.
|
|
2854
|
+
*/
|
|
2855
|
+
setInteractionState(state) {
|
|
2856
|
+
this.selectedIds = new Set(state.selectedIds ?? []);
|
|
2857
|
+
this.hoveredItemId = state.hoveredItemId ?? null;
|
|
2858
|
+
for (const [id, cached] of this.itemNodeCache) {
|
|
2859
|
+
this.applyInteractionAttributes(cached.g, id);
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2836
2862
|
/**
|
|
2837
2863
|
* Reads container size, culls items, and updates the SVG (incrementally when possible).
|
|
2838
2864
|
*/
|
|
@@ -2869,6 +2895,7 @@ var SvgVectorRenderer = class {
|
|
|
2869
2895
|
if (!this.liveOverlay) {
|
|
2870
2896
|
const g = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
2871
2897
|
g.setAttribute("data-live-overlay", "true");
|
|
2898
|
+
g.setAttribute("data-canvu-item", "true");
|
|
2872
2899
|
this.liveOverlay = {
|
|
2873
2900
|
g,
|
|
2874
2901
|
lastChildrenSvg: "",
|
|
@@ -2878,6 +2905,11 @@ var SvgVectorRenderer = class {
|
|
|
2878
2905
|
}
|
|
2879
2906
|
const cached = this.liveOverlay;
|
|
2880
2907
|
const t = formatItemPlacementTransform(item);
|
|
2908
|
+
cached.g.setAttribute("class", itemClassName(item));
|
|
2909
|
+
cached.g.setAttribute("data-item-id", item.id);
|
|
2910
|
+
cached.g.setAttribute("data-tool-kind", item.toolKind ?? "");
|
|
2911
|
+
cached.g.setAttribute("data-canvu-selected", "false");
|
|
2912
|
+
cached.g.setAttribute("data-canvu-hovered", "false");
|
|
2881
2913
|
if (cached.lastTransform !== t) {
|
|
2882
2914
|
cached.g.setAttribute("transform", t);
|
|
2883
2915
|
cached.lastTransform = t;
|
|
@@ -2908,6 +2940,7 @@ var SvgVectorRenderer = class {
|
|
|
2908
2940
|
let cached = this.itemNodeCache.get(item.id);
|
|
2909
2941
|
if (!cached) {
|
|
2910
2942
|
const g2 = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
2943
|
+
g2.setAttribute("data-canvu-item", "true");
|
|
2911
2944
|
g2.setAttribute("data-item-id", item.id);
|
|
2912
2945
|
cached = {
|
|
2913
2946
|
g: g2,
|
|
@@ -2917,6 +2950,11 @@ var SvgVectorRenderer = class {
|
|
|
2917
2950
|
this.itemNodeCache.set(item.id, cached);
|
|
2918
2951
|
}
|
|
2919
2952
|
const { g } = cached;
|
|
2953
|
+
g.setAttribute("class", itemClassName(item));
|
|
2954
|
+
g.setAttribute("data-canvu-item", "true");
|
|
2955
|
+
g.setAttribute("data-item-id", item.id);
|
|
2956
|
+
g.setAttribute("data-tool-kind", item.toolKind ?? "");
|
|
2957
|
+
this.applyInteractionAttributes(g, item.id);
|
|
2920
2958
|
const t = formatItemPlacementTransform(item);
|
|
2921
2959
|
if (cached.lastTransform !== t) {
|
|
2922
2960
|
g.setAttribute("transform", t);
|
|
@@ -2933,6 +2971,16 @@ var SvgVectorRenderer = class {
|
|
|
2933
2971
|
previousNode = g;
|
|
2934
2972
|
}
|
|
2935
2973
|
}
|
|
2974
|
+
applyInteractionAttributes(g, itemId) {
|
|
2975
|
+
g.setAttribute(
|
|
2976
|
+
"data-canvu-selected",
|
|
2977
|
+
this.selectedIds.has(itemId) ? "true" : "false"
|
|
2978
|
+
);
|
|
2979
|
+
g.setAttribute(
|
|
2980
|
+
"data-canvu-hovered",
|
|
2981
|
+
this.hoveredItemId === itemId ? "true" : "false"
|
|
2982
|
+
);
|
|
2983
|
+
}
|
|
2936
2984
|
destroy() {
|
|
2937
2985
|
this.resizeObserver.disconnect();
|
|
2938
2986
|
this.itemNodeCache.clear();
|