@chekinapp/ui 0.0.104 → 0.0.105

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
@@ -3096,23 +3096,40 @@ function useLoadMore({
3096
3096
  threshold = 0.1,
3097
3097
  rootMargin
3098
3098
  }) {
3099
- const loadMoreRef = (0, import_react17.useRef)(null);
3099
+ const elementRef = (0, import_react17.useRef)(null);
3100
+ const observerRef = (0, import_react17.useRef)(null);
3101
+ const handleLoadMore = useEvent(onLoadMore);
3102
+ const cleanupObserver = (0, import_react17.useCallback)(() => {
3103
+ observerRef.current?.disconnect();
3104
+ observerRef.current = null;
3105
+ }, []);
3106
+ const observeElement = (0, import_react17.useCallback)(
3107
+ (element) => {
3108
+ cleanupObserver();
3109
+ if (!element || typeof IntersectionObserver === "undefined") return;
3110
+ const observer = new IntersectionObserver(
3111
+ (entries) => {
3112
+ const entry = entries[0];
3113
+ if (!entry?.isIntersecting || !hasNextPage || loading || disabled) return;
3114
+ handleLoadMore();
3115
+ },
3116
+ { threshold, rootMargin }
3117
+ );
3118
+ observer.observe(element);
3119
+ observerRef.current = observer;
3120
+ },
3121
+ [cleanupObserver, disabled, handleLoadMore, hasNextPage, loading, rootMargin, threshold]
3122
+ );
3123
+ const loadMoreRef = (0, import_react17.useCallback)(
3124
+ (element) => {
3125
+ elementRef.current = element;
3126
+ observeElement(element);
3127
+ },
3128
+ [observeElement]
3129
+ );
3100
3130
  (0, import_react17.useEffect)(() => {
3101
- const element = loadMoreRef.current;
3102
- if (!element) return;
3103
- const observer = new IntersectionObserver(
3104
- (entries) => {
3105
- if (entries[0].isIntersecting && hasNextPage && !loading && !disabled) {
3106
- onLoadMore();
3107
- }
3108
- },
3109
- { threshold, rootMargin }
3110
- );
3111
- observer.observe(element);
3112
- return () => {
3113
- observer.disconnect();
3114
- };
3115
- }, [hasNextPage, loading, disabled, onLoadMore, threshold, rootMargin]);
3131
+ return cleanupObserver;
3132
+ }, [cleanupObserver]);
3116
3133
  return [loadMoreRef];
3117
3134
  }
3118
3135
 
@@ -9238,7 +9255,13 @@ var SIGNATURE_PROPS = {
9238
9255
  throttle: 16
9239
9256
  };
9240
9257
  var ASPECT_RATIO = 330 / 190;
9241
- function getTrimmedCanvasData(canvas, padding = 10) {
9258
+ function getCanvasPixelPadding(canvas, padding) {
9259
+ if (!Number.isFinite(padding) || padding <= 0) return 0;
9260
+ const cssWidth = canvas.getBoundingClientRect().width;
9261
+ const scale = cssWidth > 0 ? canvas.width / cssWidth : 1;
9262
+ return Math.round(padding * scale);
9263
+ }
9264
+ function getTrimmedCanvas(canvas, padding = 10) {
9242
9265
  const ctx = canvas.getContext("2d");
9243
9266
  if (!ctx) return null;
9244
9267
  const { width, height } = canvas;
@@ -9254,18 +9277,19 @@ function getTrimmedCanvasData(canvas, padding = 10) {
9254
9277
  const alpha = data[(y * width + x) * 4 + 3];
9255
9278
  if (alpha > 0) {
9256
9279
  hasContent = true;
9257
- minX = Math.min(minX, x);
9258
- minY = Math.min(minY, y);
9259
- maxX = Math.max(maxX, x);
9260
- maxY = Math.max(maxY, y);
9280
+ if (x < minX) minX = x;
9281
+ if (y < minY) minY = y;
9282
+ if (x > maxX) maxX = x;
9283
+ if (y > maxY) maxY = y;
9261
9284
  }
9262
9285
  }
9263
9286
  }
9264
9287
  if (!hasContent) return null;
9265
- minX = Math.max(0, minX - padding);
9266
- minY = Math.max(0, minY - padding);
9267
- maxX = Math.min(width - 1, maxX + padding);
9268
- maxY = Math.min(height - 1, maxY + padding);
9288
+ const pixelPadding = getCanvasPixelPadding(canvas, padding);
9289
+ minX = Math.max(0, minX - pixelPadding);
9290
+ minY = Math.max(0, minY - pixelPadding);
9291
+ maxX = Math.min(width - 1, maxX + pixelPadding);
9292
+ maxY = Math.min(height - 1, maxY + pixelPadding);
9269
9293
  const trimmedWidth = maxX - minX + 1;
9270
9294
  const trimmedHeight = maxY - minY + 1;
9271
9295
  const trimmedCanvas = document.createElement("canvas");
@@ -9284,10 +9308,7 @@ function getTrimmedCanvasData(canvas, padding = 10) {
9284
9308
  trimmedWidth,
9285
9309
  trimmedHeight
9286
9310
  );
9287
- return {
9288
- canvas: trimmedCanvas,
9289
- bounds: { x: minX, y: minY, width: trimmedWidth, height: trimmedHeight }
9290
- };
9311
+ return trimmedCanvas;
9291
9312
  }
9292
9313
  var SignatureCanvas = (0, import_react74.forwardRef)(
9293
9314
  ({ onClear, onEnd, onEnable, className, enabled }, ref) => {
@@ -9352,9 +9373,9 @@ var SignatureCanvas = (0, import_react74.forwardRef)(
9352
9373
  toTrimmedDataURL: (type = "image/png", encoderOptions, padding = 10) => {
9353
9374
  const canvas = canvasRef.current?.getCanvas();
9354
9375
  if (!canvas) return "";
9355
- const trimmed = getTrimmedCanvasData(canvas, padding);
9376
+ const trimmed = getTrimmedCanvas(canvas, padding);
9356
9377
  if (!trimmed) return "";
9357
- return trimmed.canvas.toDataURL(type, encoderOptions);
9378
+ return trimmed.toDataURL(type, encoderOptions);
9358
9379
  },
9359
9380
  getCanvas: (...args) => canvasRef.current?.getCanvas(...args)
9360
9381
  }));