@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/charts.d.ts CHANGED
@@ -246,6 +246,15 @@ interface AtomixGlassProps extends React.HTMLAttributes<HTMLDivElement> {
246
246
  * @default false
247
247
  */
248
248
  disableResponsiveBreakpoints?: boolean;
249
+ /**
250
+ * Priority level for rendering and performance scheduling
251
+ *
252
+ * Controls the rendering priority of the glass effect, allowing for performance
253
+ * optimization in complex scenes. Higher priority elements are rendered first.
254
+ *
255
+ * @default undefined
256
+ */
257
+ priority?: number;
249
258
  }
250
259
  /**
251
260
  * Common component size options
package/dist/charts.js CHANGED
@@ -529,6 +529,10 @@ const _reduceInstanceProperty = getDefaultExportFromCjs((function(it) {
529
529
  MIN_BLUR: .1,
530
530
  MOUSE_INFLUENCE_DIVISOR: 100,
531
531
  EDGE_FADE_PIXELS: 2,
532
+ // Elasticity physics constants
533
+ ELASTICITY_TRANSLATION_FACTOR: .1,
534
+ ELASTICITY_DISTANCE_THRESHOLD: 200,
535
+ ELASTICITY_COMPRESSION_FACTOR: .3,
532
536
  // Note: This default must match the SCSS variable --atomix-radius-md
533
537
  // @see src/styles/01-settings/_settings.global.scss
534
538
  DEFAULT_CORNER_RADIUS: 16,
@@ -2081,9 +2085,21 @@ class {
2081
2085
  y: this.lastEvent.clientY
2082
2086
  },
2083
2087
  // Notify all subscribers
2084
- this.listeners.forEach((callback => {
2088
+ this.listeners.forEach((listener => {
2085
2089
  try {
2086
- callback(this.position);
2090
+ // If the listener has an element, calculate distance-based attenuation
2091
+ if (listener.element) {
2092
+ const elementRect = listener.element.getBoundingClientRect(), elementCenter = {
2093
+ x: elementRect.left + elementRect.width / 2,
2094
+ y: elementRect.top + elementRect.height / 2
2095
+ }, distance = this.calculateDistance(this.position, elementCenter), maxDistance = listener.maxDistance || 300, attenuation = Math.max(0, 1 - distance / maxDistance), attenuatedRelativePosition = {
2096
+ x: (this.position.x - elementCenter.x) / elementRect.width * 100 * attenuation,
2097
+ y: (this.position.y - elementCenter.y) / elementRect.height * 100 * attenuation
2098
+ };
2099
+ listener.callback(attenuatedRelativePosition);
2100
+ } else
2101
+ // Send original position for listeners without distance-based attenuation
2102
+ listener.callback(this.position);
2087
2103
  } catch (error) {
2088
2104
  console.error("GlobalMouseTracker: Error in subscriber callback", error);
2089
2105
  }
@@ -2094,10 +2110,17 @@ class {
2094
2110
  /**
2095
2111
  * Subscribe to mouse position updates
2096
2112
  * @param callback Function to call when mouse position changes
2113
+ * @param element Optional element for distance-based attenuation
2114
+ * @param maxDistance Optional maximum distance for full effect
2097
2115
  * @returns Unsubscribe function
2098
- */ subscribe(callback) {
2116
+ */ subscribe(callback, element, maxDistance) {
2117
+ const listener = {
2118
+ callback: callback,
2119
+ element: element,
2120
+ maxDistance: maxDistance
2121
+ };
2099
2122
  // Return unsubscribe function
2100
- return this.listeners.add(callback),
2123
+ return this.listeners.add(listener),
2101
2124
  // Start tracking if this is the first subscriber
2102
2125
  1 === this.listeners.size && this.startTracking(),
2103
2126
  // Immediately notify with current position
@@ -2108,9 +2131,13 @@ class {
2108
2131
  /**
2109
2132
  * Unsubscribe from mouse position updates
2110
2133
  */ unsubscribe(callback) {
2111
- this.listeners.delete(callback),
2134
+ // Find and remove the listener with the given callback
2135
+ for (const listener of this.listeners) if (listener.callback === callback) {
2136
+ this.listeners.delete(listener);
2137
+ break;
2138
+ }
2112
2139
  // Stop tracking if no more subscribers
2113
- 0 === this.listeners.size && this.stopTracking();
2140
+ 0 === this.listeners.size && this.stopTracking();
2114
2141
  }
2115
2142
  /**
2116
2143
  * Start tracking mouse movement
@@ -2129,6 +2156,12 @@ class {
2129
2156
  null !== this.rafId && (cancelAnimationFrame(this.rafId), this.rafId = null), this.lastEvent = null);
2130
2157
  }
2131
2158
  /**
2159
+ * Calculate distance between two points
2160
+ */ calculateDistance(point1, point2) {
2161
+ const dx = point1.x - point2.x, dy = point1.y - point2.y;
2162
+ return Math.sqrt(dx * dx + dy * dy);
2163
+ }
2164
+ /**
2132
2165
  * Get current mouse position (synchronous)
2133
2166
  */ getPosition() {
2134
2167
  return {
@@ -2413,7 +2446,8 @@ const {CONSTANTS: CONSTANTS} = ATOMIX_GLASS, backgroundDetectionCache = new Weak
2413
2446
  * Composable hook for AtomixGlass component logic
2414
2447
  * Manages all state, calculations, and event handlers
2415
2448
  */
2416
- 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:
2449
+ 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:
2450
+ // Default priority
2417
2451
  // Phase 1: Animation System Props
2418
2452
  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}) {
2419
2453
  // State
@@ -2810,7 +2844,8 @@ withTimeAnimation = ATOMIX_GLASS.DEFAULTS.WITH_TIME_ANIMATION, animationSpeed: a
2810
2844
  useEffect((() => {
2811
2845
  if (externalGlobalMousePosition && externalMouseOffset) return;
2812
2846
  if (effectiveWithoutEffects) return;
2813
- const unsubscribe = globalMouseTracker.subscribe(handleGlobalMousePosition);
2847
+ const unsubscribe = globalMouseTracker.subscribe(handleGlobalMousePosition, glassRef.current || void 0, 300);
2848
+ // 300px max distance for full effect
2814
2849
  // Initial start
2815
2850
  startLerpLoop();
2816
2851
  const container = mouseContainer?.current || glassRef.current;