@bwp-web/canvas 0.7.1 → 0.8.0

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.cjs CHANGED
@@ -32,6 +32,7 @@ __export(index_exports, {
32
32
  FabricObject: () => import_fabric19.FabricObject,
33
33
  FixedSizeContent: () => FixedSizeContent,
34
34
  ObjectOverlay: () => ObjectOverlay,
35
+ OverlayBadge: () => OverlayBadge,
35
36
  OverlayContent: () => OverlayContent,
36
37
  Point: () => import_fabric19.Point,
37
38
  Polygon: () => import_fabric19.Polygon,
@@ -3103,7 +3104,6 @@ function ObjectOverlay({
3103
3104
  alignItems: "center",
3104
3105
  justifyContent: "center",
3105
3106
  zIndex: 1,
3106
- overflow: "hidden",
3107
3107
  ...sx
3108
3108
  },
3109
3109
  ...rest,
@@ -3244,6 +3244,7 @@ function FixedSizeContent({
3244
3244
  flexShrink: 0,
3245
3245
  width: "max-content",
3246
3246
  overflow: "hidden",
3247
+ alignItems: "center",
3247
3248
  "& > *": {
3248
3249
  maxWidth: "100%",
3249
3250
  overflow: "hidden",
@@ -3257,6 +3258,86 @@ function FixedSizeContent({
3257
3258
  );
3258
3259
  }
3259
3260
 
3261
+ // src/overlay/OverlayBadge.tsx
3262
+ var import_material4 = require("@mui/material");
3263
+ var import_react11 = require("react");
3264
+ var import_jsx_runtime5 = require("react/jsx-runtime");
3265
+ function toPx(v) {
3266
+ if (v === void 0) return void 0;
3267
+ return typeof v === "number" ? `${v}px` : v;
3268
+ }
3269
+ function OverlayBadge({
3270
+ children,
3271
+ maxScale = 2,
3272
+ minScale = 0.75,
3273
+ top,
3274
+ right,
3275
+ bottom,
3276
+ left,
3277
+ sx,
3278
+ ...rest
3279
+ }) {
3280
+ const ref = (0, import_react11.useRef)(null);
3281
+ const baseSize = (0, import_react11.useRef)(null);
3282
+ (0, import_react11.useEffect)(() => {
3283
+ const el = ref.current;
3284
+ if (!el) return;
3285
+ const ancestor = el.parentElement;
3286
+ if (!ancestor) return;
3287
+ function update() {
3288
+ requestAnimationFrame(() => {
3289
+ if (!el || !ancestor) return;
3290
+ const containerW = ancestor.clientWidth;
3291
+ const containerH = ancestor.clientHeight;
3292
+ if (containerW <= 0 || containerH <= 0) {
3293
+ el.style.transform = "";
3294
+ return;
3295
+ }
3296
+ if (!baseSize.current) {
3297
+ baseSize.current = { w: containerW, h: containerH };
3298
+ }
3299
+ const ratio = Math.min(
3300
+ containerW / baseSize.current.w,
3301
+ containerH / baseSize.current.h
3302
+ );
3303
+ const ownScale = Math.max(minScale, Math.min(ratio, maxScale));
3304
+ const overlayScale = parseFloat(
3305
+ getComputedStyle(el).getPropertyValue("--overlay-scale")
3306
+ ) || 1;
3307
+ el.style.transform = `scale(${ownScale / overlayScale})`;
3308
+ });
3309
+ }
3310
+ const observer = new ResizeObserver(update);
3311
+ observer.observe(ancestor);
3312
+ update();
3313
+ return () => {
3314
+ observer.disconnect();
3315
+ baseSize.current = null;
3316
+ };
3317
+ }, [maxScale, minScale]);
3318
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3319
+ import_material4.Stack,
3320
+ {
3321
+ ref,
3322
+ sx: {
3323
+ position: "absolute",
3324
+ top: toPx(top),
3325
+ right: toPx(right),
3326
+ bottom: toPx(bottom),
3327
+ left: toPx(left),
3328
+ transformOrigin: "center center",
3329
+ pointerEvents: "auto",
3330
+ width: "max-content",
3331
+ height: "max-content",
3332
+ flexShrink: 0,
3333
+ ...sx
3334
+ },
3335
+ ...rest,
3336
+ children
3337
+ }
3338
+ );
3339
+ }
3340
+
3260
3341
  // src/index.ts
3261
3342
  var import_fabric19 = require("fabric");
3262
3343
  // Annotate the CommonJS export names for ESM import in node:
@@ -3273,6 +3354,7 @@ var import_fabric19 = require("fabric");
3273
3354
  FabricObject,
3274
3355
  FixedSizeContent,
3275
3356
  ObjectOverlay,
3357
+ OverlayBadge,
3276
3358
  OverlayContent,
3277
3359
  Point,
3278
3360
  Polygon,