@jump-section/core 1.0.22 → 1.0.23
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.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +24 -1
- package/dist/index.mjs +24 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,8 @@ interface ScrollOptions {
|
|
|
7
7
|
root?: HTMLElement | null;
|
|
8
8
|
/** Alt+ArrowDown/Up 키보드 네비게이션을 활성화합니다 */
|
|
9
9
|
keyboard?: boolean;
|
|
10
|
+
/** 디버그 모드를 활성화하여 섹션 경계 및 상태를 시각화합니다 */
|
|
11
|
+
debug?: boolean;
|
|
10
12
|
}
|
|
11
13
|
interface ActiveChangeMeta {
|
|
12
14
|
/** 이전에 활성화된 섹션 ID */
|
|
@@ -32,6 +34,7 @@ declare class ScrollManager {
|
|
|
32
34
|
private scrollHandler;
|
|
33
35
|
private popstateHandler;
|
|
34
36
|
private notifyScheduled;
|
|
37
|
+
private debugElements;
|
|
35
38
|
constructor(options?: ScrollOptions);
|
|
36
39
|
private get scrollRoot();
|
|
37
40
|
private get currentScrollTop();
|
|
@@ -42,7 +45,14 @@ declare class ScrollManager {
|
|
|
42
45
|
private handleIntersection;
|
|
43
46
|
private scheduleNotify;
|
|
44
47
|
private updateProgress;
|
|
45
|
-
|
|
48
|
+
private createDebugOverlay;
|
|
49
|
+
private updateDebugOverlays;
|
|
50
|
+
private updateDebugActiveState;
|
|
51
|
+
private removeDebugOverlay;
|
|
52
|
+
/**
|
|
53
|
+
* 섹션을 등록하고 IntersectionObserver로 감시합니다.
|
|
54
|
+
* @note `debug: true` 옵션 활성화 시, 오버레이 표시를 위해 `position` 스타일이 `relative`로 변경될 수 있습니다.
|
|
55
|
+
*/
|
|
46
56
|
registerSection(id: string, element: HTMLElement): void;
|
|
47
57
|
/** 섹션 등록을 해제하고 감시를 중지합니다 */
|
|
48
58
|
unregisterSection(id: string): void;
|
|
@@ -66,9 +76,13 @@ declare class ScrollManager {
|
|
|
66
76
|
scrollToLast(): Promise<void>;
|
|
67
77
|
/** 활성 섹션 변경 이벤트를 구독합니다 */
|
|
68
78
|
onActiveChange(callback: ActiveChangeCallback): () => void;
|
|
79
|
+
/** 활성 섹션 변경 구독을 해제합니다 */
|
|
80
|
+
offActiveChange(callback: ActiveChangeCallback): void;
|
|
69
81
|
private notifyListeners;
|
|
70
82
|
/** 특정 섹션의 스크롤 진행률 이벤트를 구독합니다 */
|
|
71
83
|
onProgressChange(sectionId: string, callback: ProgressCallback): () => void;
|
|
84
|
+
/** 특정 섹션의 스크롤 진행률 구독을 해제합니다 */
|
|
85
|
+
offProgressChange(sectionId: string, callback: ProgressCallback): void;
|
|
72
86
|
/** 등록된 모든 이벤트 리스너와 Observer를 해제하고 정리합니다 */
|
|
73
87
|
destroy(): void;
|
|
74
88
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ interface ScrollOptions {
|
|
|
7
7
|
root?: HTMLElement | null;
|
|
8
8
|
/** Alt+ArrowDown/Up 키보드 네비게이션을 활성화합니다 */
|
|
9
9
|
keyboard?: boolean;
|
|
10
|
+
/** 디버그 모드를 활성화하여 섹션 경계 및 상태를 시각화합니다 */
|
|
11
|
+
debug?: boolean;
|
|
10
12
|
}
|
|
11
13
|
interface ActiveChangeMeta {
|
|
12
14
|
/** 이전에 활성화된 섹션 ID */
|
|
@@ -32,6 +34,7 @@ declare class ScrollManager {
|
|
|
32
34
|
private scrollHandler;
|
|
33
35
|
private popstateHandler;
|
|
34
36
|
private notifyScheduled;
|
|
37
|
+
private debugElements;
|
|
35
38
|
constructor(options?: ScrollOptions);
|
|
36
39
|
private get scrollRoot();
|
|
37
40
|
private get currentScrollTop();
|
|
@@ -42,7 +45,14 @@ declare class ScrollManager {
|
|
|
42
45
|
private handleIntersection;
|
|
43
46
|
private scheduleNotify;
|
|
44
47
|
private updateProgress;
|
|
45
|
-
|
|
48
|
+
private createDebugOverlay;
|
|
49
|
+
private updateDebugOverlays;
|
|
50
|
+
private updateDebugActiveState;
|
|
51
|
+
private removeDebugOverlay;
|
|
52
|
+
/**
|
|
53
|
+
* 섹션을 등록하고 IntersectionObserver로 감시합니다.
|
|
54
|
+
* @note `debug: true` 옵션 활성화 시, 오버레이 표시를 위해 `position` 스타일이 `relative`로 변경될 수 있습니다.
|
|
55
|
+
*/
|
|
46
56
|
registerSection(id: string, element: HTMLElement): void;
|
|
47
57
|
/** 섹션 등록을 해제하고 감시를 중지합니다 */
|
|
48
58
|
unregisterSection(id: string): void;
|
|
@@ -66,9 +76,13 @@ declare class ScrollManager {
|
|
|
66
76
|
scrollToLast(): Promise<void>;
|
|
67
77
|
/** 활성 섹션 변경 이벤트를 구독합니다 */
|
|
68
78
|
onActiveChange(callback: ActiveChangeCallback): () => void;
|
|
79
|
+
/** 활성 섹션 변경 구독을 해제합니다 */
|
|
80
|
+
offActiveChange(callback: ActiveChangeCallback): void;
|
|
69
81
|
private notifyListeners;
|
|
70
82
|
/** 특정 섹션의 스크롤 진행률 이벤트를 구독합니다 */
|
|
71
83
|
onProgressChange(sectionId: string, callback: ProgressCallback): () => void;
|
|
84
|
+
/** 특정 섹션의 스크롤 진행률 구독을 해제합니다 */
|
|
85
|
+
offProgressChange(sectionId: string, callback: ProgressCallback): void;
|
|
72
86
|
/** 등록된 모든 이벤트 리스너와 Observer를 해제하고 정리합니다 */
|
|
73
87
|
destroy(): void;
|
|
74
88
|
}
|
package/dist/index.js
CHANGED
|
@@ -1 +1,24 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var f=Object.defineProperty;var v=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;var u=(l,e,t)=>e in l?f(l,e,{enumerable:true,configurable:true,writable:true,value:t}):l[e]=t,g=(l,e)=>{for(var t in e||(e={}))y.call(e,t)&&u(l,t,e[t]);if(v)for(var t of v(e))m.call(e,t)&&u(l,t,e[t]);return l};var r=(l,e,t)=>u(l,typeof e!="symbol"?e+"":e,t);var b=class{constructor(e={}){r(this,"sections",new Map);r(this,"disabledSections",new Set);r(this,"observer",null);r(this,"resizeObserver",null);r(this,"activeId",null);r(this,"previousId",null);r(this,"lastScrollY",0);r(this,"scrollDirection",null);r(this,"listeners",new Set);r(this,"progressListeners",new Map);r(this,"options");r(this,"keyboardHandler",null);r(this,"scrollHandler",null);r(this,"popstateHandler",null);r(this,"notifyScheduled",false);r(this,"debugElements",new Map);r(this,"handleIntersection",e=>{this.options.debug&&this.updateDebugOverlays(e);let t=e.filter(o=>o.isIntersecting);if(t.length===0){this.activeId!==null&&(this.previousId=this.activeId,this.activeId=null,this.scheduleNotify());return}let s=t.reduce((o,n)=>o.intersectionRatio>n.intersectionRatio?o:n),i;for(let[o,n]of this.sections)if(n===s.target){i=o;break}i=i!=null?i:s.target.id,!(!i||i===this.activeId||this.disabledSections.has(i))&&(this.previousId=this.activeId,this.activeId=i,this.scheduleNotify(),this.options.hash&&history.replaceState(null,"",`#${i}`));});this.options=g({offset:0,behavior:"smooth",hash:false,root:null,keyboard:false,debug:false},e),this.initObserver(),this.initScrollListener(),this.options.hash&&this.initHashSync(),this.options.keyboard&&this.initKeyboard();}get scrollRoot(){var e;return (e=this.options.root)!=null?e:window}get currentScrollTop(){return this.options.root?this.options.root.scrollTop:window.scrollY}initObserver(){var e;typeof window!="undefined"&&(this.observer=new IntersectionObserver(this.handleIntersection,{root:(e=this.options.root)!=null?e:null,rootMargin:"-20% 0px -60% 0px",threshold:[0,.1,.5,1]}),typeof ResizeObserver!="undefined"&&(this.resizeObserver=new ResizeObserver(()=>{this.sections.forEach(t=>{var s,i;(s=this.observer)==null||s.unobserve(t),(i=this.observer)==null||i.observe(t);});})));}initScrollListener(){typeof window!="undefined"&&(this.scrollHandler=()=>{let e=this.currentScrollTop;e!==this.lastScrollY&&(this.scrollDirection=e>this.lastScrollY?"down":"up",this.lastScrollY=e),this.updateProgress();},this.scrollRoot.addEventListener("scroll",this.scrollHandler,{passive:true}));}initHashSync(){typeof window!="undefined"&&(this.popstateHandler=()=>{let e=window.location.hash.slice(1);e&&this.sections.has(e)&&this.scrollTo(e);},window.addEventListener("popstate",this.popstateHandler));}initKeyboard(){typeof window!="undefined"&&(this.keyboardHandler=e=>{e.altKey&&(e.key==="ArrowDown"?(e.preventDefault(),this.scrollToNext()):e.key==="ArrowUp"&&(e.preventDefault(),this.scrollToPrev()));},document.addEventListener("keydown",this.keyboardHandler));}scheduleNotify(){this.notifyScheduled||(this.notifyScheduled=true,queueMicrotask(()=>{this.notifyScheduled=false,this.notifyListeners(),this.options.debug&&this.updateDebugActiveState();}));}updateProgress(){if(this.progressListeners.size===0)return;let e=this.currentScrollTop,t=this.options.root?this.options.root.clientHeight:window.innerHeight;this.progressListeners.forEach((s,i)=>{if(s.size===0)return;let o=this.sections.get(i);if(!o)return;let n=o.getBoundingClientRect(),a=this.options.root?n.top-this.options.root.getBoundingClientRect().top+this.options.root.scrollTop:n.top+e,c=o.offsetHeight||n.height;if(c===0)return;let h=(e-a+t*.2)/c,d=Math.max(0,Math.min(1,h));s.forEach(p=>p(d));});}createDebugOverlay(e,t){let s=document.createElement("div");s.id=`jump-section-debug-${e}`,s.style.cssText=`
|
|
2
|
+
position: absolute;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
border: 2px solid rgba(0, 100, 255, 0.5);
|
|
10
|
+
background: rgba(0, 100, 255, 0.1);
|
|
11
|
+
z-index: 9999;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
font-family: monospace;
|
|
16
|
+
font-size: 12px;
|
|
17
|
+
color: white;
|
|
18
|
+
text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
`,t.style.position=t.style.position==="static"?"relative":t.style.position;let i=document.createElement("span");return i.style.cssText=`
|
|
21
|
+
padding: 2px 5px;
|
|
22
|
+
background: rgba(0, 100, 255, 0.7);
|
|
23
|
+
border-radius: 3px;
|
|
24
|
+
`,i.textContent=`ID: ${e}`,s.appendChild(i),s}updateDebugOverlays(e){e.forEach(t=>{var h,d;let s=t.target,i=(d=(h=[...this.sections.entries()].find(([,p])=>p===s))==null?void 0:h[0])!=null?d:s.id;if(!i)return;let o=this.debugElements.get(i);o||(o=this.createDebugOverlay(i,s),s.appendChild(o),this.debugElements.set(i,o));let n=Math.round(t.intersectionRatio*100),a=i===this.activeId;o.style.borderColor=a?"rgba(0, 255, 0, 0.8)":t.isIntersecting?"rgba(255, 165, 0, 0.8)":"rgba(0, 100, 255, 0.5)",o.style.background=a?"rgba(0, 255, 0, 0.1)":t.isIntersecting?"rgba(255, 165, 0, 0.1)":"rgba(0, 100, 255, 0.1)";let c=o.querySelector("span");c&&(c.textContent=`ID: ${i} | Ratio: ${n}% ${a?"| ACTIVE":""}`,c.style.background=a?"rgba(0, 255, 0, 0.7)":t.isIntersecting?"rgba(255, 165, 0, 0.7)":"rgba(0, 100, 255, 0.7)");});}updateDebugActiveState(){this.debugElements.forEach((e,t)=>{let s=t===this.activeId,i=e.querySelector("span"),o=i.textContent||"",n=s?o.includes("| ACTIVE")?o:`${o} | ACTIVE`:o.replace(" | ACTIVE","");i&&(i.textContent=n,i.style.background=s?"rgba(0, 255, 0, 0.7)":"rgba(0, 100, 255, 0.7)"),e.style.borderColor=s?"rgba(0, 255, 0, 0.8)":"rgba(0, 100, 255, 0.5)",e.style.background=s?"rgba(0, 255, 0, 0.1)":"rgba(0, 100, 255, 0.1)";});}removeDebugOverlay(e){let t=this.debugElements.get(e);t&&(t.remove(),this.debugElements.delete(e));}registerSection(e,t){var s,i;if(typeof window!="undefined"&&t){if(this.sections.set(e,t),t.id||(t.id=e),(s=this.observer)==null||s.observe(t),(i=this.resizeObserver)==null||i.observe(t),this.options.debug){let o=this.createDebugOverlay(e,t);t.appendChild(o),this.debugElements.set(e,o);}this.options.hash&&window.location.hash===`#${e}`&&setTimeout(()=>this.scrollTo(e),0);}}unregisterSection(e){var s,i;let t=this.sections.get(e);t&&((s=this.observer)==null||s.unobserve(t),(i=this.resizeObserver)==null||i.unobserve(t)),this.sections.delete(e),this.disabledSections.delete(e),this.progressListeners.delete(e),this.options.debug&&this.removeDebugOverlay(e),this.activeId===e&&(this.previousId=this.activeId,this.activeId=null,this.scheduleNotify());}disableSection(e){var t;if(this.disabledSections.add(e),this.options.debug){let s=this.debugElements.get(e);if(s){s.style.borderStyle="dashed";let i=s.querySelector("span");i&&!((t=i.textContent)!=null&&t.includes("| DISABLED"))&&(i.textContent+=" | DISABLED");}}this.activeId===e&&(this.previousId=this.activeId,this.activeId=null,this.scheduleNotify());}enableSection(e){var t;if(this.disabledSections.delete(e),this.options.debug){let s=this.debugElements.get(e);if(s){s.style.borderStyle="solid";let i=s.querySelector("span");i&&(i.textContent=((t=i.textContent)==null?void 0:t.replace(" | DISABLED",""))||"");}}}getSections(){return [...this.sections.entries()].filter(([e])=>!this.disabledSections.has(e)).sort(([,e],[,t])=>{let s=e.getBoundingClientRect().top,i=t.getBoundingClientRect().top;return s-i}).map(([e])=>e)}getActiveId(){return this.activeId}scrollTo(e){var a;if(typeof window=="undefined")return Promise.resolve();let t=this.sections.get(e);if(!t)return console.warn(`[ScrollManager] Section with id "${e}" not found. Available sections: ${Array.from(this.sections.keys()).join(", ")}`),Promise.resolve();let s=t.getBoundingClientRect(),i=((a=this.options.root)==null?void 0:a.getBoundingClientRect())||{top:0},o=s.top+this.currentScrollTop-i.top+this.options.offset,n=this.options.root||window;return new Promise(c=>{let h=()=>{(Math.abs(this.currentScrollTop-o)<1||n===window&&window.innerHeight+window.scrollY>=document.body.offsetHeight||this.options.root&&this.options.root.clientHeight+this.options.root.scrollTop>=this.options.root.scrollHeight)&&(n.removeEventListener("scroll",h),clearTimeout(d),c());},d=setTimeout(()=>{n.removeEventListener("scroll",h),c();},1e3);this.options.behavior==="smooth"?n.addEventListener("scroll",h,{passive:true}):(clearTimeout(d),c()),this.options.root?this.options.root.scrollTo({top:o,behavior:this.options.behavior}):window.scrollTo({top:o,behavior:this.options.behavior});})}scrollToNext(){let e=this.getSections(),s=(this.activeId?e.indexOf(this.activeId):-1)+1;return s<e.length?this.scrollTo(e[s]):Promise.resolve()}scrollToPrev(){let e=this.getSections(),s=(this.activeId?e.indexOf(this.activeId):e.length)-1;return s>=0?this.scrollTo(e[s]):Promise.resolve()}scrollToFirst(){let e=this.getSections();return e.length>0?this.scrollTo(e[0]):Promise.resolve()}scrollToLast(){let e=this.getSections();return e.length>0?this.scrollTo(e[e.length-1]):Promise.resolve()}onActiveChange(e){return this.listeners.add(e),e(this.activeId,{previous:this.previousId,direction:this.scrollDirection}),()=>{this.listeners.delete(e);}}offActiveChange(e){this.listeners.delete(e);}notifyListeners(){if(this.activeId===null&&this.previousId===null)return;let e={previous:this.previousId,direction:this.scrollDirection};this.listeners.forEach(t=>t(this.activeId,e));}onProgressChange(e,t){var s;return this.progressListeners.has(e)||this.progressListeners.set(e,new Set),(s=this.progressListeners.get(e))==null||s.add(t),this.updateProgress(),()=>{var i;(i=this.progressListeners.get(e))==null||i.delete(t);}}offProgressChange(e,t){var s,i;(s=this.progressListeners.get(e))==null||s.delete(t),((i=this.progressListeners.get(e))==null?void 0:i.size)===0&&this.progressListeners.delete(e);}destroy(){var e,t;(e=this.observer)==null||e.disconnect(),(t=this.resizeObserver)==null||t.disconnect(),this.sections.forEach(s=>{var i,o;(i=this.observer)==null||i.unobserve(s),(o=this.resizeObserver)==null||o.unobserve(s);}),this.sections.clear(),this.disabledSections.clear(),this.listeners.clear(),this.progressListeners.clear(),this.debugElements.forEach(s=>s.remove()),this.debugElements.clear(),this.scrollHandler&&this.scrollRoot.removeEventListener("scroll",this.scrollHandler),this.popstateHandler&&window.removeEventListener("popstate",this.popstateHandler),this.keyboardHandler&&document.removeEventListener("keydown",this.keyboardHandler);}};exports.ScrollManager=b;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,24 @@
|
|
|
1
|
-
var
|
|
1
|
+
var f=Object.defineProperty;var v=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;var u=(l,e,t)=>e in l?f(l,e,{enumerable:true,configurable:true,writable:true,value:t}):l[e]=t,g=(l,e)=>{for(var t in e||(e={}))y.call(e,t)&&u(l,t,e[t]);if(v)for(var t of v(e))m.call(e,t)&&u(l,t,e[t]);return l};var r=(l,e,t)=>u(l,typeof e!="symbol"?e+"":e,t);var b=class{constructor(e={}){r(this,"sections",new Map);r(this,"disabledSections",new Set);r(this,"observer",null);r(this,"resizeObserver",null);r(this,"activeId",null);r(this,"previousId",null);r(this,"lastScrollY",0);r(this,"scrollDirection",null);r(this,"listeners",new Set);r(this,"progressListeners",new Map);r(this,"options");r(this,"keyboardHandler",null);r(this,"scrollHandler",null);r(this,"popstateHandler",null);r(this,"notifyScheduled",false);r(this,"debugElements",new Map);r(this,"handleIntersection",e=>{this.options.debug&&this.updateDebugOverlays(e);let t=e.filter(o=>o.isIntersecting);if(t.length===0){this.activeId!==null&&(this.previousId=this.activeId,this.activeId=null,this.scheduleNotify());return}let s=t.reduce((o,n)=>o.intersectionRatio>n.intersectionRatio?o:n),i;for(let[o,n]of this.sections)if(n===s.target){i=o;break}i=i!=null?i:s.target.id,!(!i||i===this.activeId||this.disabledSections.has(i))&&(this.previousId=this.activeId,this.activeId=i,this.scheduleNotify(),this.options.hash&&history.replaceState(null,"",`#${i}`));});this.options=g({offset:0,behavior:"smooth",hash:false,root:null,keyboard:false,debug:false},e),this.initObserver(),this.initScrollListener(),this.options.hash&&this.initHashSync(),this.options.keyboard&&this.initKeyboard();}get scrollRoot(){var e;return (e=this.options.root)!=null?e:window}get currentScrollTop(){return this.options.root?this.options.root.scrollTop:window.scrollY}initObserver(){var e;typeof window!="undefined"&&(this.observer=new IntersectionObserver(this.handleIntersection,{root:(e=this.options.root)!=null?e:null,rootMargin:"-20% 0px -60% 0px",threshold:[0,.1,.5,1]}),typeof ResizeObserver!="undefined"&&(this.resizeObserver=new ResizeObserver(()=>{this.sections.forEach(t=>{var s,i;(s=this.observer)==null||s.unobserve(t),(i=this.observer)==null||i.observe(t);});})));}initScrollListener(){typeof window!="undefined"&&(this.scrollHandler=()=>{let e=this.currentScrollTop;e!==this.lastScrollY&&(this.scrollDirection=e>this.lastScrollY?"down":"up",this.lastScrollY=e),this.updateProgress();},this.scrollRoot.addEventListener("scroll",this.scrollHandler,{passive:true}));}initHashSync(){typeof window!="undefined"&&(this.popstateHandler=()=>{let e=window.location.hash.slice(1);e&&this.sections.has(e)&&this.scrollTo(e);},window.addEventListener("popstate",this.popstateHandler));}initKeyboard(){typeof window!="undefined"&&(this.keyboardHandler=e=>{e.altKey&&(e.key==="ArrowDown"?(e.preventDefault(),this.scrollToNext()):e.key==="ArrowUp"&&(e.preventDefault(),this.scrollToPrev()));},document.addEventListener("keydown",this.keyboardHandler));}scheduleNotify(){this.notifyScheduled||(this.notifyScheduled=true,queueMicrotask(()=>{this.notifyScheduled=false,this.notifyListeners(),this.options.debug&&this.updateDebugActiveState();}));}updateProgress(){if(this.progressListeners.size===0)return;let e=this.currentScrollTop,t=this.options.root?this.options.root.clientHeight:window.innerHeight;this.progressListeners.forEach((s,i)=>{if(s.size===0)return;let o=this.sections.get(i);if(!o)return;let n=o.getBoundingClientRect(),a=this.options.root?n.top-this.options.root.getBoundingClientRect().top+this.options.root.scrollTop:n.top+e,c=o.offsetHeight||n.height;if(c===0)return;let h=(e-a+t*.2)/c,d=Math.max(0,Math.min(1,h));s.forEach(p=>p(d));});}createDebugOverlay(e,t){let s=document.createElement("div");s.id=`jump-section-debug-${e}`,s.style.cssText=`
|
|
2
|
+
position: absolute;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
border: 2px solid rgba(0, 100, 255, 0.5);
|
|
10
|
+
background: rgba(0, 100, 255, 0.1);
|
|
11
|
+
z-index: 9999;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
font-family: monospace;
|
|
16
|
+
font-size: 12px;
|
|
17
|
+
color: white;
|
|
18
|
+
text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
`,t.style.position=t.style.position==="static"?"relative":t.style.position;let i=document.createElement("span");return i.style.cssText=`
|
|
21
|
+
padding: 2px 5px;
|
|
22
|
+
background: rgba(0, 100, 255, 0.7);
|
|
23
|
+
border-radius: 3px;
|
|
24
|
+
`,i.textContent=`ID: ${e}`,s.appendChild(i),s}updateDebugOverlays(e){e.forEach(t=>{var h,d;let s=t.target,i=(d=(h=[...this.sections.entries()].find(([,p])=>p===s))==null?void 0:h[0])!=null?d:s.id;if(!i)return;let o=this.debugElements.get(i);o||(o=this.createDebugOverlay(i,s),s.appendChild(o),this.debugElements.set(i,o));let n=Math.round(t.intersectionRatio*100),a=i===this.activeId;o.style.borderColor=a?"rgba(0, 255, 0, 0.8)":t.isIntersecting?"rgba(255, 165, 0, 0.8)":"rgba(0, 100, 255, 0.5)",o.style.background=a?"rgba(0, 255, 0, 0.1)":t.isIntersecting?"rgba(255, 165, 0, 0.1)":"rgba(0, 100, 255, 0.1)";let c=o.querySelector("span");c&&(c.textContent=`ID: ${i} | Ratio: ${n}% ${a?"| ACTIVE":""}`,c.style.background=a?"rgba(0, 255, 0, 0.7)":t.isIntersecting?"rgba(255, 165, 0, 0.7)":"rgba(0, 100, 255, 0.7)");});}updateDebugActiveState(){this.debugElements.forEach((e,t)=>{let s=t===this.activeId,i=e.querySelector("span"),o=i.textContent||"",n=s?o.includes("| ACTIVE")?o:`${o} | ACTIVE`:o.replace(" | ACTIVE","");i&&(i.textContent=n,i.style.background=s?"rgba(0, 255, 0, 0.7)":"rgba(0, 100, 255, 0.7)"),e.style.borderColor=s?"rgba(0, 255, 0, 0.8)":"rgba(0, 100, 255, 0.5)",e.style.background=s?"rgba(0, 255, 0, 0.1)":"rgba(0, 100, 255, 0.1)";});}removeDebugOverlay(e){let t=this.debugElements.get(e);t&&(t.remove(),this.debugElements.delete(e));}registerSection(e,t){var s,i;if(typeof window!="undefined"&&t){if(this.sections.set(e,t),t.id||(t.id=e),(s=this.observer)==null||s.observe(t),(i=this.resizeObserver)==null||i.observe(t),this.options.debug){let o=this.createDebugOverlay(e,t);t.appendChild(o),this.debugElements.set(e,o);}this.options.hash&&window.location.hash===`#${e}`&&setTimeout(()=>this.scrollTo(e),0);}}unregisterSection(e){var s,i;let t=this.sections.get(e);t&&((s=this.observer)==null||s.unobserve(t),(i=this.resizeObserver)==null||i.unobserve(t)),this.sections.delete(e),this.disabledSections.delete(e),this.progressListeners.delete(e),this.options.debug&&this.removeDebugOverlay(e),this.activeId===e&&(this.previousId=this.activeId,this.activeId=null,this.scheduleNotify());}disableSection(e){var t;if(this.disabledSections.add(e),this.options.debug){let s=this.debugElements.get(e);if(s){s.style.borderStyle="dashed";let i=s.querySelector("span");i&&!((t=i.textContent)!=null&&t.includes("| DISABLED"))&&(i.textContent+=" | DISABLED");}}this.activeId===e&&(this.previousId=this.activeId,this.activeId=null,this.scheduleNotify());}enableSection(e){var t;if(this.disabledSections.delete(e),this.options.debug){let s=this.debugElements.get(e);if(s){s.style.borderStyle="solid";let i=s.querySelector("span");i&&(i.textContent=((t=i.textContent)==null?void 0:t.replace(" | DISABLED",""))||"");}}}getSections(){return [...this.sections.entries()].filter(([e])=>!this.disabledSections.has(e)).sort(([,e],[,t])=>{let s=e.getBoundingClientRect().top,i=t.getBoundingClientRect().top;return s-i}).map(([e])=>e)}getActiveId(){return this.activeId}scrollTo(e){var a;if(typeof window=="undefined")return Promise.resolve();let t=this.sections.get(e);if(!t)return console.warn(`[ScrollManager] Section with id "${e}" not found. Available sections: ${Array.from(this.sections.keys()).join(", ")}`),Promise.resolve();let s=t.getBoundingClientRect(),i=((a=this.options.root)==null?void 0:a.getBoundingClientRect())||{top:0},o=s.top+this.currentScrollTop-i.top+this.options.offset,n=this.options.root||window;return new Promise(c=>{let h=()=>{(Math.abs(this.currentScrollTop-o)<1||n===window&&window.innerHeight+window.scrollY>=document.body.offsetHeight||this.options.root&&this.options.root.clientHeight+this.options.root.scrollTop>=this.options.root.scrollHeight)&&(n.removeEventListener("scroll",h),clearTimeout(d),c());},d=setTimeout(()=>{n.removeEventListener("scroll",h),c();},1e3);this.options.behavior==="smooth"?n.addEventListener("scroll",h,{passive:true}):(clearTimeout(d),c()),this.options.root?this.options.root.scrollTo({top:o,behavior:this.options.behavior}):window.scrollTo({top:o,behavior:this.options.behavior});})}scrollToNext(){let e=this.getSections(),s=(this.activeId?e.indexOf(this.activeId):-1)+1;return s<e.length?this.scrollTo(e[s]):Promise.resolve()}scrollToPrev(){let e=this.getSections(),s=(this.activeId?e.indexOf(this.activeId):e.length)-1;return s>=0?this.scrollTo(e[s]):Promise.resolve()}scrollToFirst(){let e=this.getSections();return e.length>0?this.scrollTo(e[0]):Promise.resolve()}scrollToLast(){let e=this.getSections();return e.length>0?this.scrollTo(e[e.length-1]):Promise.resolve()}onActiveChange(e){return this.listeners.add(e),e(this.activeId,{previous:this.previousId,direction:this.scrollDirection}),()=>{this.listeners.delete(e);}}offActiveChange(e){this.listeners.delete(e);}notifyListeners(){if(this.activeId===null&&this.previousId===null)return;let e={previous:this.previousId,direction:this.scrollDirection};this.listeners.forEach(t=>t(this.activeId,e));}onProgressChange(e,t){var s;return this.progressListeners.has(e)||this.progressListeners.set(e,new Set),(s=this.progressListeners.get(e))==null||s.add(t),this.updateProgress(),()=>{var i;(i=this.progressListeners.get(e))==null||i.delete(t);}}offProgressChange(e,t){var s,i;(s=this.progressListeners.get(e))==null||s.delete(t),((i=this.progressListeners.get(e))==null?void 0:i.size)===0&&this.progressListeners.delete(e);}destroy(){var e,t;(e=this.observer)==null||e.disconnect(),(t=this.resizeObserver)==null||t.disconnect(),this.sections.forEach(s=>{var i,o;(i=this.observer)==null||i.unobserve(s),(o=this.resizeObserver)==null||o.unobserve(s);}),this.sections.clear(),this.disabledSections.clear(),this.listeners.clear(),this.progressListeners.clear(),this.debugElements.forEach(s=>s.remove()),this.debugElements.clear(),this.scrollHandler&&this.scrollRoot.removeEventListener("scroll",this.scrollHandler),this.popstateHandler&&window.removeEventListener("popstate",this.popstateHandler),this.keyboardHandler&&document.removeEventListener("keydown",this.keyboardHandler);}};export{b as ScrollManager};
|