@bwp-web/canvas 0.6.2 → 0.7.1

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.
@@ -0,0 +1,51 @@
1
+ import { StackProps } from '@mui/material';
2
+ import { type ReactNode } from 'react';
3
+ export interface FixedSizeContentProps extends StackProps {
4
+ children?: ReactNode;
5
+ /**
6
+ * When `true` (default), content is collapsed (`display: none`) if showing
7
+ * it would cause `OverlayContent` to shrink below its natural size
8
+ * vertically. Horizontal overflow is always handled by truncation (ellipsis).
9
+ * When `false`, no automatic hiding is applied.
10
+ */
11
+ hideOnOverflow?: boolean;
12
+ /**
13
+ * Horizontal padding in pixels subtracted from the available width when
14
+ * calculating the truncation `maxWidth`. Default: 4
15
+ */
16
+ truncationPadding?: number;
17
+ }
18
+ /**
19
+ * Keeps children at their natural CSS pixel size inside an `OverlayContent`,
20
+ * counter-scaling against `OverlayContent`'s fit-to-container transform.
21
+ * Icons and other siblings still scale to fill the object bounds as usual,
22
+ * while text wrapped in `FixedSizeContent` stays at a constant screen size.
23
+ *
24
+ * Text that overflows horizontally is truncated with an ellipsis. When
25
+ * `hideOnOverflow` is `true` (default), the element is fully collapsed
26
+ * (`display: none`) as soon as the overlay container is too short to fit
27
+ * both the fixed-size content and its siblings at natural size, so
28
+ * `OverlayContent` recalculates its scale using only the remaining siblings.
29
+ * Once there is enough room again (e.g. zooming in), the element reappears.
30
+ *
31
+ * Uses the `--overlay-scale` CSS custom property set by `OverlayContent`.
32
+ * When used outside `OverlayContent` (e.g. directly inside `ObjectOverlay`),
33
+ * the fallback of 1 means no counter-scaling is applied and children render
34
+ * at their natural size.
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * <ObjectOverlay canvasRef={canvasRef} object={obj}>
39
+ * <OverlayContent>
40
+ * <Stack alignItems="center">
41
+ * <MyIcon /> {// scales to fit}
42
+ * <FixedSizeContent>
43
+ * <Typography noWrap>Always 14px, truncates</Typography>
44
+ * </FixedSizeContent>
45
+ * </Stack>
46
+ * </OverlayContent>
47
+ * </ObjectOverlay>
48
+ * ```
49
+ */
50
+ export declare function FixedSizeContent({ children, hideOnOverflow, truncationPadding, sx, ...rest }: FixedSizeContentProps): import("react/jsx-runtime").JSX.Element;
51
+ //# sourceMappingURL=FixedSizeContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FixedSizeContent.d.ts","sourceRoot":"","sources":["../../src/overlay/FixedSizeContent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1D,MAAM,WAAW,qBAAsB,SAAQ,UAAU;IACvD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,cAAqB,EACrB,iBAAqB,EACrB,EAAE,EACF,GAAG,IAAI,EACR,EAAE,qBAAqB,2CA+FvB"}
@@ -0,0 +1,33 @@
1
+ import { type RefObject, type ReactNode } from 'react';
2
+ import type { StackProps } from '@mui/material';
3
+ import type { Canvas as FabricCanvas, FabricObject } from 'fabric';
4
+ export interface ObjectOverlayProps extends StackProps {
5
+ /** Ref to the Fabric canvas instance. */
6
+ canvasRef: RefObject<FabricCanvas | null>;
7
+ /** The Fabric object to overlay. When `null`/`undefined`, nothing renders. */
8
+ object: FabricObject | null | undefined;
9
+ children?: ReactNode;
10
+ }
11
+ /**
12
+ * A MUI `Stack` positioned absolutely over a Fabric canvas object, sized to
13
+ * the object's screen-space dimensions and kept in sync with pan, zoom, move,
14
+ * scale, and rotate transforms.
15
+ *
16
+ * Default styles: `position: absolute`, `pointerEvents: none`,
17
+ * `alignItems: center`, `justifyContent: center`, `zIndex: 1`.
18
+ * All can be overridden via the `sx` prop.
19
+ *
20
+ * Must be rendered inside a container that is `position: relative` and wraps
21
+ * the `<Canvas>` component (e.g. the `canvasOverlay` slot of `DemoLayout`).
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * <ObjectOverlay canvasRef={canvasRef} object={deskObj}>
26
+ * <OverlayContent>
27
+ * <MyLabel>{desk.name}</MyLabel>
28
+ * </OverlayContent>
29
+ * </ObjectOverlay>
30
+ * ```
31
+ */
32
+ export declare function ObjectOverlay({ canvasRef, object, sx, children, ...rest }: ObjectOverlayProps): import("react/jsx-runtime").JSX.Element | null;
33
+ //# sourceMappingURL=ObjectOverlay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectOverlay.d.ts","sourceRoot":"","sources":["../../src/overlay/ObjectOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGnE,MAAM,WAAW,kBAAmB,SAAQ,UAAU;IACpD,yCAAyC;IACzC,SAAS,EAAE,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC1C,8EAA8E;IAC9E,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,MAAM,EACN,EAAE,EACF,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,kBAAkB,kDAgEpB"}
@@ -0,0 +1,26 @@
1
+ import { StackProps } from '@mui/material';
2
+ import { type ReactNode } from 'react';
3
+ export interface OverlayContentProps extends StackProps {
4
+ children?: ReactNode;
5
+ /** Padding in pixels between the content and the parent bounds. Default: 4 */
6
+ padding?: number;
7
+ /** Maximum scale factor applied to the content. Default: 2 */
8
+ maxScale?: number;
9
+ }
10
+ /**
11
+ * Scales its children to fit within the parent's bounds (typically an
12
+ * `ObjectOverlay`). Content is measured at its natural size then scaled
13
+ * down or up (capped at `maxScale`) to fill the available space while
14
+ * maintaining aspect ratio.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * <ObjectOverlay canvasRef={canvasRef} object={obj}>
19
+ * <OverlayContent padding={4} maxScale={2}>
20
+ * <MyBadge>{label}</MyBadge>
21
+ * </OverlayContent>
22
+ * </ObjectOverlay>
23
+ * ```
24
+ */
25
+ export declare function OverlayContent({ children, padding, maxScale, sx, ...rest }: OverlayContentProps): import("react/jsx-runtime").JSX.Element;
26
+ //# sourceMappingURL=OverlayContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OverlayContent.d.ts","sourceRoot":"","sources":["../../src/overlay/OverlayContent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1D,MAAM,WAAW,mBAAoB,SAAQ,UAAU;IACrD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,OAAW,EACX,QAAY,EACZ,EAAE,EACF,GAAG,IAAI,EACR,EAAE,mBAAmB,2CA0ErB"}
@@ -0,0 +1,7 @@
1
+ export { ObjectOverlay } from './ObjectOverlay';
2
+ export type { ObjectOverlayProps } from './ObjectOverlay';
3
+ export { OverlayContent } from './OverlayContent';
4
+ export type { OverlayContentProps } from './OverlayContent';
5
+ export { FixedSizeContent } from './FixedSizeContent';
6
+ export type { FixedSizeContentProps } from './FixedSizeContent';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/overlay/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bwp-web/canvas",
3
- "version": "0.6.2",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -1,50 +0,0 @@
1
- import { type RefObject } from 'react';
2
- import type { Canvas as FabricCanvas, FabricObject } from 'fabric';
3
- export interface UseObjectOverlayOptions {
4
- /**
5
- * Scale the overlay container to the object's actual dimensions and apply
6
- * a CSS `scale(zoom)` transform so content inside lays out in canvas units.
7
- * Pass `false` to opt out and receive screen-space pixel dimensions instead.
8
- * Default: true.
9
- */
10
- autoScaleContent?: boolean;
11
- /**
12
- * CSS selector for a text element inside the overlay. When
13
- * `autoScaleContent` is enabled and the computed scale drops below a
14
- * threshold, elements matching this selector are hidden (via
15
- * `display: none`) so only icons remain visible.
16
- * Default: undefined (no text hiding).
17
- */
18
- textSelector?: string;
19
- /**
20
- * Minimum content scale at which `textSelector` elements remain visible.
21
- * Below this threshold, matched elements are hidden.
22
- * Default: 0.5.
23
- */
24
- textMinScale?: number;
25
- }
26
- /**
27
- * Position a DOM element over a Fabric canvas object, kept in sync with
28
- * pan, zoom, move, scale, and rotate transforms.
29
- *
30
- * Returns a ref to attach to the overlay container element. The element
31
- * must be positioned absolutely within a relative-positioned parent that
32
- * wraps the `<Canvas>` component.
33
- *
34
- * @example
35
- * ```tsx
36
- * const overlayRef = useObjectOverlay(canvasRef, object, {
37
- * autoScaleContent: true,
38
- * textSelector: '.desk-text',
39
- * });
40
- *
41
- * return (
42
- * <div ref={overlayRef} style={{ position: 'absolute', pointerEvents: 'none' }}>
43
- * <CanvasDeskIcon />
44
- * <span className="desk-text">{name}</span>
45
- * </div>
46
- * );
47
- * ```
48
- */
49
- export declare function useObjectOverlay(canvasRef: RefObject<FabricCanvas | null>, object: FabricObject | null | undefined, options?: UseObjectOverlayOptions): RefObject<HTMLDivElement | null>;
50
- //# sourceMappingURL=useObjectOverlay.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useObjectOverlay.d.ts","sourceRoot":"","sources":["../../src/hooks/useObjectOverlay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGnE,MAAM,WAAW,uBAAuB;IACtC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,EACzC,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,EACvC,OAAO,CAAC,EAAE,uBAAuB,GAChC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CA+ElC"}