@shohojdhara/atomix 0.6.0 → 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/heavy.d.ts CHANGED
@@ -245,6 +245,15 @@ interface AtomixGlassProps extends React.HTMLAttributes<HTMLDivElement> {
245
245
  * @default false
246
246
  */
247
247
  disableResponsiveBreakpoints?: boolean;
248
+ /**
249
+ * Priority level for rendering and performance scheduling
250
+ *
251
+ * Controls the rendering priority of the glass effect, allowing for performance
252
+ * optimization in complex scenes. Higher priority elements are rendered first.
253
+ *
254
+ * @default undefined
255
+ */
256
+ priority?: number;
248
257
  }
249
258
  /**
250
259
  * Base component properties interface
package/dist/heavy.js CHANGED
@@ -92,6 +92,10 @@ import { Pause, Play, SkipBack, SkipForward, SpeakerX, SpeakerHigh, Gear, Downlo
92
92
  MIN_BLUR: .1,
93
93
  MOUSE_INFLUENCE_DIVISOR: 100,
94
94
  EDGE_FADE_PIXELS: 2,
95
+ // Elasticity physics constants
96
+ ELASTICITY_TRANSLATION_FACTOR: .1,
97
+ ELASTICITY_DISTANCE_THRESHOLD: 200,
98
+ ELASTICITY_COMPRESSION_FACTOR: .3,
95
99
  // Note: This default must match the SCSS variable --atomix-radius-md
96
100
  // @see src/styles/01-settings/_settings.global.scss
97
101
  DEFAULT_CORNER_RADIUS: 16,
@@ -785,9 +789,21 @@ class {
785
789
  y: this.lastEvent.clientY
786
790
  },
787
791
  // Notify all subscribers
788
- this.listeners.forEach((callback => {
792
+ this.listeners.forEach((listener => {
789
793
  try {
790
- callback(this.position);
794
+ // If the listener has an element, calculate distance-based attenuation
795
+ if (listener.element) {
796
+ const elementRect = listener.element.getBoundingClientRect(), elementCenter = {
797
+ x: elementRect.left + elementRect.width / 2,
798
+ y: elementRect.top + elementRect.height / 2
799
+ }, distance = this.calculateDistance(this.position, elementCenter), maxDistance = listener.maxDistance || 300, attenuation = Math.max(0, 1 - distance / maxDistance), attenuatedRelativePosition = {
800
+ x: (this.position.x - elementCenter.x) / elementRect.width * 100 * attenuation,
801
+ y: (this.position.y - elementCenter.y) / elementRect.height * 100 * attenuation
802
+ };
803
+ listener.callback(attenuatedRelativePosition);
804
+ } else
805
+ // Send original position for listeners without distance-based attenuation
806
+ listener.callback(this.position);
791
807
  } catch (error) {
792
808
  console.error("GlobalMouseTracker: Error in subscriber callback", error);
793
809
  }
@@ -798,10 +814,17 @@ class {
798
814
  /**
799
815
  * Subscribe to mouse position updates
800
816
  * @param callback Function to call when mouse position changes
817
+ * @param element Optional element for distance-based attenuation
818
+ * @param maxDistance Optional maximum distance for full effect
801
819
  * @returns Unsubscribe function
802
- */ subscribe(callback) {
820
+ */ subscribe(callback, element, maxDistance) {
821
+ const listener = {
822
+ callback: callback,
823
+ element: element,
824
+ maxDistance: maxDistance
825
+ };
803
826
  // Return unsubscribe function
804
- return this.listeners.add(callback),
827
+ return this.listeners.add(listener),
805
828
  // Start tracking if this is the first subscriber
806
829
  1 === this.listeners.size && this.startTracking(),
807
830
  // Immediately notify with current position
@@ -812,9 +835,13 @@ class {
812
835
  /**
813
836
  * Unsubscribe from mouse position updates
814
837
  */ unsubscribe(callback) {
815
- this.listeners.delete(callback),
838
+ // Find and remove the listener with the given callback
839
+ for (const listener of this.listeners) if (listener.callback === callback) {
840
+ this.listeners.delete(listener);
841
+ break;
842
+ }
816
843
  // Stop tracking if no more subscribers
817
- 0 === this.listeners.size && this.stopTracking();
844
+ 0 === this.listeners.size && this.stopTracking();
818
845
  }
819
846
  /**
820
847
  * Start tracking mouse movement
@@ -833,6 +860,12 @@ class {
833
860
  null !== this.rafId && (cancelAnimationFrame(this.rafId), this.rafId = null), this.lastEvent = null);
834
861
  }
835
862
  /**
863
+ * Calculate distance between two points
864
+ */ calculateDistance(point1, point2) {
865
+ const dx = point1.x - point2.x, dy = point1.y - point2.y;
866
+ return Math.sqrt(dx * dx + dy * dy);
867
+ }
868
+ /**
836
869
  * Get current mouse position (synchronous)
837
870
  */ getPosition() {
838
871
  return {
@@ -1117,7 +1150,8 @@ const {CONSTANTS: CONSTANTS} = ATOMIX_GLASS, backgroundDetectionCache = new Weak
1117
1150
  * Composable hook for AtomixGlass component logic
1118
1151
  * Manages all state, calculations, and event handlers
1119
1152
  */
1120
- 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:
1153
+ 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:
1154
+ // Default priority
1121
1155
  // Phase 1: Animation System Props
1122
1156
  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}) {
1123
1157
  // State
@@ -1514,7 +1548,8 @@ withTimeAnimation = ATOMIX_GLASS.DEFAULTS.WITH_TIME_ANIMATION, animationSpeed: a
1514
1548
  useEffect((() => {
1515
1549
  if (externalGlobalMousePosition && externalMouseOffset) return;
1516
1550
  if (effectiveWithoutEffects) return;
1517
- const unsubscribe = globalMouseTracker.subscribe(handleGlobalMousePosition);
1551
+ const unsubscribe = globalMouseTracker.subscribe(handleGlobalMousePosition, glassRef.current || void 0, 300);
1552
+ // 300px max distance for full effect
1518
1553
  // Initial start
1519
1554
  startLerpLoop();
1520
1555
  const container = mouseContainer?.current || glassRef.current;