@jump-section/core 1.0.0
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 +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +32 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface ScrollOptions {
|
|
2
|
+
offset?: number;
|
|
3
|
+
behavior?: ScrollBehavior;
|
|
4
|
+
}
|
|
5
|
+
type ActiveChangeCallback = (id: string | null) => void;
|
|
6
|
+
declare class ScrollManager {
|
|
7
|
+
private sections;
|
|
8
|
+
private observer;
|
|
9
|
+
private activeId;
|
|
10
|
+
private listeners;
|
|
11
|
+
private options;
|
|
12
|
+
constructor(options?: ScrollOptions);
|
|
13
|
+
private initObserver;
|
|
14
|
+
private handleIntersection;
|
|
15
|
+
registerSection(id: string, element: HTMLElement): void;
|
|
16
|
+
unregisterSection(id: string): void;
|
|
17
|
+
scrollTo(id: string): void;
|
|
18
|
+
onActiveChange(callback: ActiveChangeCallback): () => boolean;
|
|
19
|
+
private notifyListeners;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { type ActiveChangeCallback, ScrollManager, type ScrollOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface ScrollOptions {
|
|
2
|
+
offset?: number;
|
|
3
|
+
behavior?: ScrollBehavior;
|
|
4
|
+
}
|
|
5
|
+
type ActiveChangeCallback = (id: string | null) => void;
|
|
6
|
+
declare class ScrollManager {
|
|
7
|
+
private sections;
|
|
8
|
+
private observer;
|
|
9
|
+
private activeId;
|
|
10
|
+
private listeners;
|
|
11
|
+
private options;
|
|
12
|
+
constructor(options?: ScrollOptions);
|
|
13
|
+
private initObserver;
|
|
14
|
+
private handleIntersection;
|
|
15
|
+
registerSection(id: string, element: HTMLElement): void;
|
|
16
|
+
unregisterSection(id: string): void;
|
|
17
|
+
scrollTo(id: string): void;
|
|
18
|
+
onActiveChange(callback: ActiveChangeCallback): () => boolean;
|
|
19
|
+
private notifyListeners;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { type ActiveChangeCallback, ScrollManager, type ScrollOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var p=Object.defineProperty;var h=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,d=Object.prototype.propertyIsEnumerable;var c=(i,e,t)=>e in i?p(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t,a=(i,e)=>{for(var t in e||(e={}))b.call(e,t)&&c(i,t,e[t]);if(h)for(var t of h(e))d.call(e,t)&&c(i,t,e[t]);return i};var s=(i,e,t)=>c(i,typeof e!="symbol"?e+"":e,t);var v=class{constructor(e={}){s(this,"sections",new Map);s(this,"observer",null);s(this,"activeId",null);s(this,"listeners",new Set);s(this,"options");s(this,"handleIntersection",e=>{let t=e.filter(n=>n.isIntersecting);if(t.length>0){let r=t.reduce((o,l)=>o.intersectionRatio>l.intersectionRatio?o:l).target.id;r&&r!==this.activeId&&(this.activeId=r,this.notifyListeners());}});this.options=a({offset:0,behavior:"smooth"},e),this.initObserver();}initObserver(){typeof window!="undefined"&&(this.observer=new IntersectionObserver(this.handleIntersection,{rootMargin:"-20% 0px -60% 0px",threshold:[0,.1,.5,1]}));}registerSection(e,t){t&&(this.sections.set(e,t),this.observer||(this.observer=new IntersectionObserver(this.handleIntersection,{rootMargin:"-10% 0px -80% 0px",threshold:0})),t.id||(t.id=e),this.observer.observe(t));}unregisterSection(e){let t=this.sections.get(e);t&&this.observer&&this.observer.unobserve(t),this.sections.delete(e);}scrollTo(e){let t=this.sections.get(e);if(!t){console.warn(`[ScrollManager] Section with id "${e}" not found.`);return}let{offset:n,behavior:r}=this.options,o=t.getBoundingClientRect().top+window.scrollY;window.scrollTo({top:o+(n||0),behavior:r||"smooth"});}onActiveChange(e){return this.listeners.add(e),e(this.activeId),()=>this.listeners.delete(e)}notifyListeners(){this.listeners.forEach(e=>e(this.activeId));}destroy(){this.observer&&this.observer.disconnect(),this.sections.clear(),this.listeners.clear();}};exports.ScrollManager=v;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=Object.defineProperty;var h=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,d=Object.prototype.propertyIsEnumerable;var c=(i,e,t)=>e in i?p(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t,a=(i,e)=>{for(var t in e||(e={}))b.call(e,t)&&c(i,t,e[t]);if(h)for(var t of h(e))d.call(e,t)&&c(i,t,e[t]);return i};var s=(i,e,t)=>c(i,typeof e!="symbol"?e+"":e,t);var v=class{constructor(e={}){s(this,"sections",new Map);s(this,"observer",null);s(this,"activeId",null);s(this,"listeners",new Set);s(this,"options");s(this,"handleIntersection",e=>{let t=e.filter(n=>n.isIntersecting);if(t.length>0){let r=t.reduce((o,l)=>o.intersectionRatio>l.intersectionRatio?o:l).target.id;r&&r!==this.activeId&&(this.activeId=r,this.notifyListeners());}});this.options=a({offset:0,behavior:"smooth"},e),this.initObserver();}initObserver(){typeof window!="undefined"&&(this.observer=new IntersectionObserver(this.handleIntersection,{rootMargin:"-20% 0px -60% 0px",threshold:[0,.1,.5,1]}));}registerSection(e,t){t&&(this.sections.set(e,t),this.observer||(this.observer=new IntersectionObserver(this.handleIntersection,{rootMargin:"-10% 0px -80% 0px",threshold:0})),t.id||(t.id=e),this.observer.observe(t));}unregisterSection(e){let t=this.sections.get(e);t&&this.observer&&this.observer.unobserve(t),this.sections.delete(e);}scrollTo(e){let t=this.sections.get(e);if(!t){console.warn(`[ScrollManager] Section with id "${e}" not found.`);return}let{offset:n,behavior:r}=this.options,o=t.getBoundingClientRect().top+window.scrollY;window.scrollTo({top:o+(n||0),behavior:r||"smooth"});}onActiveChange(e){return this.listeners.add(e),e(this.activeId),()=>this.listeners.delete(e)}notifyListeners(){this.listeners.forEach(e=>e(this.activeId));}destroy(){this.observer&&this.observer.disconnect(),this.sections.clear(),this.listeners.clear();}};export{v as ScrollManager};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jump-section/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Core scroll management library for jump-section",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"scroll",
|
|
7
|
+
"navigation",
|
|
8
|
+
"section",
|
|
9
|
+
"jump"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/bae080311/jump-section.git",
|
|
14
|
+
"directory": "packages/core"
|
|
15
|
+
},
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"author": "k_jin.0",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"module": "dist/index.mjs",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"test": "vitest run --environment jsdom"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|