@lemoncat7/dsh-theme-xiaohei 0.3.1 → 0.3.3

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/lib/gaze.js CHANGED
@@ -43,14 +43,14 @@ export function installXiaoheiGaze(doc = typeof document === 'undefined' ? undef
43
43
  gaze.style.setProperty('--xiaohei-gaze-y', `${currentY.toFixed(3)}px`);
44
44
  };
45
45
  const wake = () => {
46
- if (disposed || frameId !== 0 || gaze === undefined)
46
+ if (disposed || doc.hidden || frameId !== 0 || gaze === undefined)
47
47
  return;
48
48
  setMoving(true);
49
49
  frameId = win.requestAnimationFrame(tick);
50
50
  };
51
51
  const tick = (time) => {
52
52
  frameId = 0;
53
- if (disposed || gaze === undefined || mascot === undefined)
53
+ if (disposed || doc.hidden || gaze === undefined || mascot === undefined)
54
54
  return;
55
55
  const target = resolveGazeTarget(doc, mascot, pointer, portalActive, behaviorDisabled());
56
56
  const elapsed = lastFrameTime === 0 ? 16 : Math.min(48, Math.max(1, time - lastFrameTime));
@@ -107,6 +107,17 @@ export function installXiaoheiGaze(doc = typeof document === 'undefined' ? undef
107
107
  };
108
108
  const onPreferenceChange = () => wake();
109
109
  const onStateChange = () => wake();
110
+ const onVisibilityChange = () => {
111
+ if (doc.hidden) {
112
+ if (frameId !== 0)
113
+ win.cancelAnimationFrame(frameId);
114
+ frameId = 0;
115
+ lastFrameTime = 0;
116
+ setMoving(false);
117
+ }
118
+ else
119
+ wake();
120
+ };
110
121
  const unsubscribeHostDom = subscribeXiaoheiHostDom(doc, attach);
111
122
  const stateObserver = new win.MutationObserver(onStateChange);
112
123
  stateObserver.observe(doc.documentElement, {
@@ -114,6 +125,7 @@ export function installXiaoheiGaze(doc = typeof document === 'undefined' ? undef
114
125
  attributeFilter: ['data-xiaohei-state'],
115
126
  });
116
127
  doc.addEventListener('pointermove', onPointerMove, { passive: true });
128
+ doc.addEventListener('visibilitychange', onVisibilityChange);
117
129
  doc.addEventListener('pointerleave', clearPointer);
118
130
  doc.addEventListener(XIAOHEI_PORTAL_ACTIVITY_EVENT, onPortalActivity);
119
131
  win.addEventListener('blur', clearPointer);
@@ -127,6 +139,7 @@ export function installXiaoheiGaze(doc = typeof document === 'undefined' ? undef
127
139
  unsubscribeHostDom();
128
140
  stateObserver.disconnect();
129
141
  doc.removeEventListener('pointermove', onPointerMove);
142
+ doc.removeEventListener('visibilitychange', onVisibilityChange);
130
143
  doc.removeEventListener('pointerleave', clearPointer);
131
144
  doc.removeEventListener(XIAOHEI_PORTAL_ACTIVITY_EVENT, onPortalActivity);
132
145
  win.removeEventListener('blur', clearPointer);
@@ -0,0 +1,4 @@
1
+ /** Generated by scripts/embed-assets.mjs. */
2
+ import type { CharacterMotionCatalog } from './scene/character-motion-types.js';
3
+ export declare const CHARACTER_MOTION: CharacterMotionCatalog;
4
+ //# sourceMappingURL=generated-character-motion.d.ts.map