@shohojdhara/atomix 0.6.1 → 0.6.2

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.js CHANGED
@@ -1777,6 +1777,10 @@ const THEME_COLORS = [ "primary", "secondary", "success", "info", "warning", "er
1777
1777
  MIN_BLUR: .1,
1778
1778
  MOUSE_INFLUENCE_DIVISOR: 100,
1779
1779
  EDGE_FADE_PIXELS: 2,
1780
+ // Elasticity physics constants
1781
+ ELASTICITY_TRANSLATION_FACTOR: .1,
1782
+ ELASTICITY_DISTANCE_THRESHOLD: 200,
1783
+ ELASTICITY_COMPRESSION_FACTOR: .3,
1780
1784
  // Note: This default must match the SCSS variable --atomix-radius-md
1781
1785
  // @see src/styles/01-settings/_settings.global.scss
1782
1786
  DEFAULT_CORNER_RADIUS: 16,
@@ -2531,9 +2535,21 @@ class {
2531
2535
  y: this.lastEvent.clientY
2532
2536
  },
2533
2537
  // Notify all subscribers
2534
- this.listeners.forEach((callback => {
2538
+ this.listeners.forEach((listener => {
2535
2539
  try {
2536
- callback(this.position);
2540
+ // If the listener has an element, calculate distance-based attenuation
2541
+ if (listener.element) {
2542
+ const elementRect = listener.element.getBoundingClientRect(), elementCenter = {
2543
+ x: elementRect.left + elementRect.width / 2,
2544
+ y: elementRect.top + elementRect.height / 2
2545
+ }, distance = this.calculateDistance(this.position, elementCenter), maxDistance = listener.maxDistance || 300, attenuation = Math.max(0, 1 - distance / maxDistance), attenuatedRelativePosition = {
2546
+ x: (this.position.x - elementCenter.x) / elementRect.width * 100 * attenuation,
2547
+ y: (this.position.y - elementCenter.y) / elementRect.height * 100 * attenuation
2548
+ };
2549
+ listener.callback(attenuatedRelativePosition);
2550
+ } else
2551
+ // Send original position for listeners without distance-based attenuation
2552
+ listener.callback(this.position);
2537
2553
  } catch (error) {
2538
2554
  console.error("GlobalMouseTracker: Error in subscriber callback", error);
2539
2555
  }
@@ -2544,10 +2560,17 @@ class {
2544
2560
  /**
2545
2561
  * Subscribe to mouse position updates
2546
2562
  * @param callback Function to call when mouse position changes
2563
+ * @param element Optional element for distance-based attenuation
2564
+ * @param maxDistance Optional maximum distance for full effect
2547
2565
  * @returns Unsubscribe function
2548
- */ subscribe(callback) {
2566
+ */ subscribe(callback, element, maxDistance) {
2567
+ const listener = {
2568
+ callback: callback,
2569
+ element: element,
2570
+ maxDistance: maxDistance
2571
+ };
2549
2572
  // Return unsubscribe function
2550
- return this.listeners.add(callback),
2573
+ return this.listeners.add(listener),
2551
2574
  // Start tracking if this is the first subscriber
2552
2575
  1 === this.listeners.size && this.startTracking(),
2553
2576
  // Immediately notify with current position
@@ -2558,9 +2581,13 @@ class {
2558
2581
  /**
2559
2582
  * Unsubscribe from mouse position updates
2560
2583
  */ unsubscribe(callback) {
2561
- this.listeners.delete(callback),
2584
+ // Find and remove the listener with the given callback
2585
+ for (const listener of this.listeners) if (listener.callback === callback) {
2586
+ this.listeners.delete(listener);
2587
+ break;
2588
+ }
2562
2589
  // Stop tracking if no more subscribers
2563
- 0 === this.listeners.size && this.stopTracking();
2590
+ 0 === this.listeners.size && this.stopTracking();
2564
2591
  }
2565
2592
  /**
2566
2593
  * Start tracking mouse movement
@@ -2579,6 +2606,12 @@ class {
2579
2606
  null !== this.rafId && (cancelAnimationFrame(this.rafId), this.rafId = null), this.lastEvent = null);
2580
2607
  }
2581
2608
  /**
2609
+ * Calculate distance between two points
2610
+ */ calculateDistance(point1, point2) {
2611
+ const dx = point1.x - point2.x, dy = point1.y - point2.y;
2612
+ return Math.sqrt(dx * dx + dy * dy);
2613
+ }
2614
+ /**
2582
2615
  * Get current mouse position (synchronous)
2583
2616
  */ getPosition() {
2584
2617
  return {
@@ -2863,7 +2896,8 @@ const {CONSTANTS: CONSTANTS} = ATOMIX_GLASS, backgroundDetectionCache = new Weak
2863
2896
  * Composable hook for AtomixGlass component logic
2864
2897
  * Manages all state, calculations, and event handlers
2865
2898
  */
2866
- function useAtomixGlass({glassRef: glassRef, contentRef: contentRef, wrapperRef: wrapperRef, borderRadius: borderRadius, globalMousePosition: externalGlobalMousePosition, mouseOffset: externalMouseOffset, mouseContainer: mouseContainer, overLight: overLight = ATOMIX_GLASS.DEFAULTS.OVER_LIGHT, reducedMotion: reducedMotion = !1, highContrast: highContrast = !1, withoutEffects: withoutEffects = !1, elasticity: elasticity = .05, onClick: onClick, debugBorderRadius: debugBorderRadius = !1, debugOverLight: debugOverLight = !1, children: children, blurAmount: blurAmount, saturation: saturation, padding: padding, withLiquidBlur: withLiquidBlur, isFixedOrSticky: isFixedOrSticky = !1, withTimeAnimation:
2899
+ function useAtomixGlass({glassRef: glassRef, contentRef: contentRef, wrapperRef: wrapperRef, borderRadius: borderRadius, globalMousePosition: externalGlobalMousePosition, mouseOffset: externalMouseOffset, mouseContainer: mouseContainer, overLight: overLight = ATOMIX_GLASS.DEFAULTS.OVER_LIGHT, reducedMotion: reducedMotion = !1, highContrast: highContrast = !1, withoutEffects: withoutEffects = !1, elasticity: elasticity = ATOMIX_GLASS.DEFAULTS.ELASTICITY, onClick: onClick, debugBorderRadius: debugBorderRadius = !1, debugOverLight: debugOverLight = !1, children: children, blurAmount: blurAmount, saturation: saturation, padding: padding, withLiquidBlur: withLiquidBlur, isFixedOrSticky: isFixedOrSticky = !1, priority: priority = 1, withTimeAnimation:
2900
+ // Default priority
2867
2901
  // Phase 1: Animation System Props
2868
2902
  withTimeAnimation = ATOMIX_GLASS.DEFAULTS.WITH_TIME_ANIMATION, animationSpeed: animationSpeed = ATOMIX_GLASS.DEFAULTS.ANIMATION_SPEED, withMultiLayerDistortion: withMultiLayerDistortion = ATOMIX_GLASS.DEFAULTS.WITH_MULTI_LAYER_DISTORTION, distortionOctaves: distortionOctaves = ATOMIX_GLASS.DEFAULTS.DISTORTION_OCTAVES, distortionLacunarity: distortionLacunarity = ATOMIX_GLASS.DEFAULTS.DISTORTION_LACUNARITY, distortionGain: distortionGain = ATOMIX_GLASS.DEFAULTS.DISTORTION_GAIN, distortionQuality: distortionQuality = ATOMIX_GLASS.DEFAULTS.DISTORTION_QUALITY}) {
2869
2903
  // State
@@ -3260,7 +3294,8 @@ withTimeAnimation = ATOMIX_GLASS.DEFAULTS.WITH_TIME_ANIMATION, animationSpeed: a
3260
3294
  React.useEffect((() => {
3261
3295
  if (externalGlobalMousePosition && externalMouseOffset) return;
3262
3296
  if (effectiveWithoutEffects) return;
3263
- const unsubscribe = globalMouseTracker.subscribe(handleGlobalMousePosition);
3297
+ const unsubscribe = globalMouseTracker.subscribe(handleGlobalMousePosition, glassRef.current || void 0, 300);
3298
+ // 300px max distance for full effect
3264
3299
  // Initial start
3265
3300
  startLerpLoop();
3266
3301
  const container = mouseContainer?.current || glassRef.current;