onboard-engine 1.4.3 → 1.5.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/README.md CHANGED
@@ -60,14 +60,16 @@ const onboardingConfig: OnboardingConfig = {
60
60
  description: 'Let us show you around the dashboard.',
61
61
  attribute: 'welcome-header',
62
62
  urlMatch: '/',
63
+ urlBase: '/',
63
64
  navigate: '/home',
64
65
  },
65
66
  {
66
67
  title: 'Create Project',
67
68
  description: 'Click here to start a new project.',
68
69
  attribute: 'create-btn',
69
- navigate: '/dashboard',
70
70
  urlMatch: '/home',
71
+ urlBase: '/home',
72
+ navigate: '/dashboard',
71
73
  click: true, // Clicks the button automatically when moving to the next step
72
74
  subSteps: [
73
75
  {
@@ -141,6 +143,7 @@ Add the `data-onboarding-id` attribute to the elements you want to highlight. Th
141
143
  | `description` | `string` | Description text in the tooltip. |
142
144
  | `attribute` | `string` | The `data-onboarding-id` value to target. |
143
145
  | `urlMatch` | `string` \| `RegExp` | **Required**. Checks if current URL matches to active this step. Supports `*` wildcards in strings (e.g., `"/user/*"`). <br/>**Note:** `RegExp` objects cannot be passed from Server Components in Next.js. Use string wildcards or define config in a Client Component. |
146
+ | `urlBase` | `string` | **Required**. The base URL for this step. If `inOrder` is true, the user will be navigated here if they are on a non-matching page. |
144
147
  | `navigate` | `string` | URL to navigate to when this step is completed (next button clicked). |
145
148
  | `click` | `boolean` | If `true`, clicks the element when the step activates. |
146
149
  | `subSteps` | `OnboardingSubStep[]` | Nested steps for complex workflows. |
package/dist/index.d.mts CHANGED
@@ -11,7 +11,8 @@ interface OnboardingStep {
11
11
  title: string;
12
12
  description: string;
13
13
  attribute: string;
14
- urlMatch: string | RegExp;
14
+ urlMatch: string;
15
+ urlBase: string;
15
16
  navigate?: string;
16
17
  subSteps?: OnboardingSubStep[];
17
18
  click?: boolean;
@@ -42,6 +43,8 @@ interface OnboardingState {
42
43
  currentStepIndex: number;
43
44
  currentSubStepIndex: number | null;
44
45
  isActive: boolean;
46
+ completedSteps: number[];
47
+ subStepProgress: Record<number, number | null>;
45
48
  }
46
49
 
47
50
  interface OnboardingContextType {
package/dist/index.d.ts CHANGED
@@ -11,7 +11,8 @@ interface OnboardingStep {
11
11
  title: string;
12
12
  description: string;
13
13
  attribute: string;
14
- urlMatch: string | RegExp;
14
+ urlMatch: string;
15
+ urlBase: string;
15
16
  navigate?: string;
16
17
  subSteps?: OnboardingSubStep[];
17
18
  click?: boolean;
@@ -42,6 +43,8 @@ interface OnboardingState {
42
43
  currentStepIndex: number;
43
44
  currentSubStepIndex: number | null;
44
45
  isActive: boolean;
46
+ completedSteps: number[];
47
+ subStepProgress: Record<number, number | null>;
45
48
  }
46
49
 
47
50
  interface OnboardingContextType {
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- "use strict";"use client";var G=Object.create;var $=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var et=(n,s)=>{for(var f in s)$(n,f,{get:s[f],enumerable:!0})},X=(n,s,f,k)=>{if(s&&typeof s=="object"||typeof s=="function")for(let h of V(s))!tt.call(n,h)&&h!==f&&$(n,h,{get:()=>s[h],enumerable:!(k=Q(s,h))||k.enumerable});return n};var nt=(n,s,f)=>(f=n!=null?G(Z(n)):{},X(s||!n||!n.__esModule?$(f,"default",{value:n,enumerable:!0}):f,n)),ot=n=>X($({},"__esModule",{value:!0}),n);var dt={};et(dt,{OnboardingProvider:()=>at,useOnboarding:()=>F});module.exports=ot(dt);var c=require("react"),B=nt(require("js-cookie"));var b=require("react"),Y=require("react-dom");var l=require("react/jsx-runtime"),rt=()=>(0,l.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,l.jsx)("path",{d:"M15 18l-6-6 6-6"})}),it=()=>(0,l.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,l.jsx)("path",{d:"M9 18l6-6-6-6"})}),st=()=>(0,l.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,l.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,l.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),q=()=>{let{config:n,currentStep:s,nextStep:f,prevStep:k,finish:h,isFirstStep:w,isLastStep:o}=F(),[r,x]=(0,b.useState)(null),[M,y]=(0,b.useState)({top:0,left:0}),[P,W]=(0,b.useState)({x:0,y:0}),N=(0,b.useRef)(!1),A=(0,b.useRef)({x:0,y:0}),v=(0,b.useRef)(null),[T,j]=(0,b.useState)(s);s!==T&&(j(s),W({x:0,y:0}));let D=(0,b.useRef)(()=>{}),O=(0,b.useCallback)(e=>{if(!N.current)return;let g=e.clientX-A.current.x,S=e.clientY-A.current.y;W({x:g,y:S})},[]),t=(0,b.useCallback)(()=>{N.current=!1,v.current&&(v.current.style.transition="top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)",v.current.style.cursor=n.metadata.draggable?"grab":"auto"),window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",D.current)},[n.metadata.draggable,O]);(0,b.useEffect)(()=>{D.current=t},[t]);let a=e=>{n.metadata.draggable&&(e.stopPropagation(),e.preventDefault(),N.current=!0,A.current={x:e.clientX-P.x,y:e.clientY-P.y},v.current&&(v.current.style.transition="none",v.current.style.cursor="grabbing"),window.addEventListener("pointermove",O),window.addEventListener("pointerup",t))},u=(0,b.useCallback)(e=>{let H=e.top,m=window.innerHeight-e.bottom,_=e.left,K=window.innerWidth-e.right,E=0,z=0;return m>232?(E=e.bottom+12,z=Math.max(20,Math.min(window.innerWidth-300-20,e.left+e.width/2-300/2))):H>232?(E=e.top-200-12,z=Math.max(20,Math.min(window.innerWidth-300-20,e.left+e.width/2-300/2))):K>332?(E=Math.max(20,Math.min(window.innerHeight-200-20,e.top+e.height/2-200/2)),z=e.right+12):_>332?(E=Math.max(20,Math.min(window.innerHeight-200-20,e.top+e.height/2-200/2)),z=e.left-300-12):(E=window.innerHeight/2-200/2,z=window.innerWidth/2-300/2),{top:E+window.scrollY,left:z+window.scrollX}},[]),d=(0,b.useCallback)(()=>{if(!s)return;let e=document.querySelector(`[data-onboarding-id="${s.attribute}"]`);if(e){let g=e.getBoundingClientRect(),S=n.style?.padding||0,L={top:g.top-S,bottom:g.bottom+S,left:g.left-S,right:g.right+S,width:g.width+S*2,height:g.height+S*2},R={top:L.top+window.scrollY,left:L.left+window.scrollX,width:L.width,height:L.height},H=u(L);x(m=>m&&m.top===R.top&&m.left===R.left&&m.width===R.width&&m.height===R.height?m:R),y(m=>m.top===H.top&&m.left===H.left?m:H)}else x(null)},[s,u,n.style]);if((0,b.useEffect)(()=>{d(),window.addEventListener("resize",d),window.addEventListener("scroll",d);let e=new MutationObserver(d);e.observe(document.body,{childList:!0,subtree:!0,attributes:!0});let g=null;if(typeof ResizeObserver<"u"){g=new ResizeObserver(d),g.observe(document.body);let S=s?.attribute?document.querySelector(`[data-onboarding-id="${s.attribute}"]`):null;S&&g.observe(S)}return()=>{window.removeEventListener("resize",d),window.removeEventListener("scroll",d),window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",t),e.disconnect(),g&&g.disconnect()}},[d,s?.attribute,O,t]),!s||!r)return null;let i={...n.style?.background,transition:"all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)"},p=e=>{e.stopPropagation()},I=(0,l.jsxs)("div",{className:"onboard-overlay-container",children:[(0,l.jsx)("div",{style:{height:r.top,...i},className:"onboard-overlay-mask onboard-mask-top",onPointerDown:p,onMouseDown:p,onClick:p}),(0,l.jsx)("div",{style:{top:r.top+r.height,height:`calc(100vh - ${r.top+r.height}px)`,...i},className:"onboard-overlay-mask onboard-mask-bottom",onPointerDown:p,onMouseDown:p,onClick:p}),(0,l.jsx)("div",{style:{top:r.top,height:r.height,width:r.left,...i},className:"onboard-overlay-mask onboard-mask-left",onPointerDown:p,onMouseDown:p,onClick:p}),(0,l.jsx)("div",{style:{top:r.top,height:r.height,left:r.left+r.width,width:`calc(100% - ${r.left+r.width}px)`,...i},className:"onboard-overlay-mask",onPointerDown:p,onMouseDown:p,onClick:p}),(0,l.jsxs)("div",{ref:v,className:"onboard-tooltip",onPointerDown:a,style:{zIndex:1e6,...n.style?.container,top:M.top+P.y,left:M.left+P.x,transition:"top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)",cursor:n.metadata.draggable?"grab":"auto",touchAction:"none"},onMouseDown:p,onClick:p,children:[(0,l.jsxs)("div",{className:"onboard-tooltip-header",children:[(0,l.jsx)("h3",{className:"onboard-tooltip-title",children:s.title}),(0,l.jsx)("button",{onClick:e=>{e.stopPropagation(),h()},className:"onboard-close-button",children:(0,l.jsx)(st,{})})]}),(0,l.jsx)("p",{className:"onboard-tooltip-description",children:s.description}),(0,l.jsxs)("div",{className:"onboard-tooltip-footer",children:[(0,l.jsxs)("button",{onClick:e=>{e.stopPropagation(),k()},disabled:w,className:"onboard-button-ghost",style:{background:"none",border:"none",cursor:w?"not-allowed":"pointer",...n.style?.prev},children:[(0,l.jsx)(rt,{}),"Prev"]}),o?(0,l.jsx)("button",{onClick:e=>{e.stopPropagation(),h()},className:"onboard-button-primary",style:{border:"none",cursor:"pointer",...n.style?.finish},children:"Finish"}):(0,l.jsxs)("button",{onClick:e=>{e.stopPropagation(),f()},className:"onboard-button-primary",style:{border:"none",cursor:"pointer",...w?n.style?.start:{},...w?{}:n.style?.next},children:[w&&n.style?.start?"Start":"Next",!(w&&n.style?.start)&&(0,l.jsx)(it,{})]})]})]})]});return typeof document<"u"?(0,Y.createPortal)(I,document.body):null};var C=require("react/jsx-runtime"),J=(0,c.createContext)(void 0),U="onboarding_state",at=({config:n,ssr:s=!1,onNavigate:f,children:k})=>{let[h,w]=(0,c.useState)(!s),[o,r]=(0,c.useState)({currentStepIndex:0,currentSubStepIndex:null,isActive:!0}),x=(0,c.useRef)(n),M=(0,c.useRef)(f);(0,c.useEffect)(()=>{x.current=n,M.current=f},[n,f]);let y=(0,c.useCallback)(t=>{t&&(M.current?M.current(t):window.location.href=t)},[]),P=(t,a)=>{if(t.urlMatch instanceof RegExp)return t.urlMatch.test(a);if(typeof t.urlMatch=="string"&&t.urlMatch.includes("*")){let u=t.urlMatch.replace(/[.+?^${}()|[\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(`^${u}$`).test(a)}return a===t.urlMatch};(0,c.useEffect)(()=>{s&&w(!0);let t=x.current,a=window.location.pathname,u=-1;t.metadata.inOrder===!1&&(u=t.steps.findIndex(i=>P(i,a)));let d=B.default.get(U);if(d)try{let i=JSON.parse(d);if(t.metadata.inOrder===!1)u!==-1?i.currentStepIndex===u?r(i):r({currentStepIndex:u,currentSubStepIndex:null,isActive:!0}):r({...i,isActive:!1});else if(r(i),t.metadata.inOrder!==!1){let p=t.steps[i.currentStepIndex];if(p&&i.isActive){let I;if(i.currentStepIndex>0){let e=t.steps[i.currentStepIndex-1];e.navigate&&(I=e.navigate)}!I&&typeof p.urlMatch=="string"&&(I=p.urlMatch),I&&window.location.pathname!==I&&y(I),t.metadata.simulateClicksOnNavigate&&i.currentSubStepIndex!==null&&p.click&&setTimeout(()=>{let e=document.querySelector(`[data-onboarding-id="${p.attribute}"]`);e&&e.click()},500)}}}catch(i){console.error("Failed to parse onboarding state from cookie",i),u!==-1&&r({currentStepIndex:u,currentSubStepIndex:null,isActive:!0})}else if(u!==-1)r({currentStepIndex:u,currentSubStepIndex:null,isActive:!0});else if(t.metadata.inOrder===!1)r(i=>({...i,isActive:!1}));else{let i=t.steps[0];i&&typeof i.urlMatch=="string"&&window.location.pathname!==i.urlMatch&&y(i.urlMatch)}},[s,y]),(0,c.useEffect)(()=>{h&&B.default.set(U,JSON.stringify(o),{expires:365})},[o,h]);let W=(0,c.useMemo)(()=>{let t=n.steps[o.currentStepIndex];return t?o.currentSubStepIndex!==null&&t.subSteps&&t.subSteps[o.currentSubStepIndex]||t:null},[n.steps,o.currentStepIndex,o.currentSubStepIndex]),N=o.currentStepIndex===0&&o.currentSubStepIndex===null,A=(0,c.useMemo)(()=>{let t=n.steps.length,a=o.currentStepIndex===t-1,u=n.steps[o.currentStepIndex],d=u?.subSteps&&u.subSteps.length>0;return a?d?o.currentSubStepIndex===u.subSteps.length-1:!0:!1},[n.steps,o.currentStepIndex,o.currentSubStepIndex]),v=(0,c.useCallback)(()=>{let t=x.current,a=t.steps[o.currentStepIndex],u=o.currentSubStepIndex!==null&&a.subSteps?a.subSteps[o.currentSubStepIndex]:a;if(u.click){let d=document.querySelector(`[data-onboarding-id="${u.attribute}"]`);d&&d.click()}if(a.subSteps&&(o.currentSubStepIndex===null||o.currentSubStepIndex<a.subSteps.length-1)){let d=o.currentSubStepIndex===null?0:o.currentSubStepIndex+1,i=a.subSteps[d];r(p=>({...p,currentSubStepIndex:d})),i.navigate&&y(i.navigate);return}if(o.currentStepIndex<t.steps.length-1){let d=o.currentStepIndex+1,i=t.steps[d];r({currentStepIndex:d,currentSubStepIndex:null,isActive:!0}),i.navigate&&y(i.navigate)}else r(d=>({...d,isActive:!1})),t.onOnboardingComplete&&t.onOnboardingComplete()},[o.currentStepIndex,o.currentSubStepIndex,y]),T=(0,c.useCallback)(()=>{let t=x.current;if(o.currentSubStepIndex!==null&&o.currentSubStepIndex>0){r(a=>({...a,currentSubStepIndex:a.currentSubStepIndex-1}));return}if(o.currentStepIndex>0&&o.currentSubStepIndex===0){r(a=>({...a,currentSubStepIndex:null}));return}if(o.currentStepIndex>0){let a=o.currentStepIndex-1,u=t.steps[a],d=u.subSteps?u.subSteps.length-1:null;r({currentStepIndex:a,currentSubStepIndex:d,isActive:!0})}},[o.currentStepIndex,o.currentSubStepIndex]),j=(0,c.useCallback)(()=>{r(t=>({...t,isActive:!1})),x.current.onOnboardingComplete&&x.current.onOnboardingComplete()},[]),D=(0,c.useCallback)((t,a=null)=>{r({currentStepIndex:t,currentSubStepIndex:a,isActive:!0})},[]),O={config:n,state:o,nextStep:v,prevStep:T,finish:j,goToStep:D,currentStep:W,isFirstStep:N,isLastStep:A};return h?(0,C.jsxs)(J.Provider,{value:O,children:[k,o.isActive&&(0,C.jsx)(q,{})]}):(0,C.jsx)(C.Fragment,{children:k})},F=()=>{let n=(0,c.useContext)(J);if(n===void 0)throw new Error("useOnboarding must be used within an OnboardingProvider");return n};0&&(module.exports={OnboardingProvider,useOnboarding});
2
+ "use strict";"use client";var tt=Object.create;var J=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var ot=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var it=(r,a)=>{for(var v in a)J(r,v,{get:a[v],enumerable:!0})},_=(r,a,v,z)=>{if(a&&typeof a=="object"||typeof a=="function")for(let y of nt(a))!rt.call(r,y)&&y!==v&&J(r,y,{get:()=>a[y],enumerable:!(z=et(a,y))||z.enumerable});return r};var st=(r,a,v)=>(v=r!=null?tt(ot(r)):{},_(a||!r||!r.__esModule?J(v,"default",{value:r,enumerable:!0}):v,r)),at=r=>_(J({},"__esModule",{value:!0}),r);var bt={};it(bt,{OnboardingProvider:()=>pt,useOnboarding:()=>K});module.exports=at(bt);var c=require("react"),T=st(require("js-cookie"));var h=require("react"),G=require("react-dom");var b=require("react/jsx-runtime"),ut=()=>(0,b.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,b.jsx)("path",{d:"M15 18l-6-6 6-6"})}),lt=()=>(0,b.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,b.jsx)("path",{d:"M9 18l6-6-6-6"})}),ct=()=>(0,b.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,b.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),Q=()=>{let{config:r,currentStep:a,nextStep:v,prevStep:z,finish:y,isFirstStep:N,isLastStep:p}=K(),[g,f]=(0,h.useState)(null),[j,B]=(0,h.useState)({top:0,left:0}),[H,k]=(0,h.useState)({x:0,y:0}),A=(0,h.useRef)(!1),E=(0,h.useRef)({x:0,y:0}),C=(0,h.useRef)(null);(0,h.useEffect)(()=>{k({x:0,y:0})},[a]);let R=(0,h.useRef)(()=>{}),O=(0,h.useCallback)(i=>{if(!A.current)return;let m=i.clientX-E.current.x,P=i.clientY-E.current.y;k({x:m,y:P})},[]),I=(0,h.useCallback)(()=>{A.current=!1,C.current&&(C.current.style.transition="top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)",C.current.style.cursor=r.metadata.draggable?"grab":"auto"),window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",R.current)},[r.metadata.draggable,O]);(0,h.useEffect)(()=>{R.current=I},[I]);let F=i=>{r.metadata.draggable&&(i.stopPropagation(),i.preventDefault(),A.current=!0,E.current={x:i.clientX-H.x,y:i.clientY-H.y},C.current&&(C.current.style.transition="none",C.current.style.cursor="grabbing"),window.addEventListener("pointermove",O),window.addEventListener("pointerup",I))},X=(0,h.useCallback)(i=>{let o=i.top,n=window.innerHeight-i.bottom,u=i.left,l=window.innerWidth-i.right,d=0,s=0;return n>232?(d=i.bottom+12,s=Math.max(20,Math.min(window.innerWidth-300-20,i.left+i.width/2-300/2))):o>232?(d=i.top-200-12,s=Math.max(20,Math.min(window.innerWidth-300-20,i.left+i.width/2-300/2))):l>332?(d=Math.max(20,Math.min(window.innerHeight-200-20,i.top+i.height/2-200/2)),s=i.right+12):u>332?(d=Math.max(20,Math.min(window.innerHeight-200-20,i.top+i.height/2-200/2)),s=i.left-300-12):(d=window.innerHeight/2-200/2,s=window.innerWidth/2-300/2),{top:d+window.scrollY,left:s+window.scrollX}},[]),M=(0,h.useCallback)(()=>{if(!a)return;let i=document.querySelector(`[data-onboarding-id="${a.attribute}"]`);if(i){let m=i.getBoundingClientRect(),P=r.style?.padding||0,e={top:m.top-P,bottom:m.bottom+P,left:m.left-P,right:m.right+P,width:m.width+P*2,height:m.height+P*2},t={top:e.top+window.scrollY,left:e.left+window.scrollX,width:e.width,height:e.height},o=X(e);f(n=>n&&n.top===t.top&&n.left===t.left&&n.width===t.width&&n.height===t.height?n:t),B(n=>n.top===o.top&&n.left===o.left?n:o)}else f(null)},[a,X,r.style]);if((0,h.useEffect)(()=>{M(),window.addEventListener("resize",M),window.addEventListener("scroll",M);let i=new MutationObserver(M);i.observe(document.body,{childList:!0,subtree:!0,attributes:!0});let m=null;if(typeof ResizeObserver<"u"){m=new ResizeObserver(M),m.observe(document.body);let P=a?.attribute?document.querySelector(`[data-onboarding-id="${a.attribute}"]`):null;P&&m.observe(P)}return()=>{window.removeEventListener("resize",M),window.removeEventListener("scroll",M),window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",I),i.disconnect(),m&&m.disconnect()}},[M,a?.attribute,O,I]),!a||!g)return null;let D={...r.style?.background,transition:"all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)"},w=i=>{i.stopPropagation()},Y=(0,b.jsxs)("div",{className:"onboard-overlay-container",children:[(0,b.jsx)("div",{style:{height:g.top,...D},className:"onboard-overlay-mask onboard-mask-top",onPointerDown:w,onMouseDown:w,onClick:w}),(0,b.jsx)("div",{style:{top:g.top+g.height,height:`calc(100vh - ${g.top+g.height}px)`,...D},className:"onboard-overlay-mask onboard-mask-bottom",onPointerDown:w,onMouseDown:w,onClick:w}),(0,b.jsx)("div",{style:{top:g.top,height:g.height,width:g.left,...D},className:"onboard-overlay-mask onboard-mask-left",onPointerDown:w,onMouseDown:w,onClick:w}),(0,b.jsx)("div",{style:{top:g.top,height:g.height,left:g.left+g.width,width:`calc(100% - ${g.left+g.width}px)`,...D},className:"onboard-overlay-mask",onPointerDown:w,onMouseDown:w,onClick:w}),(0,b.jsxs)("div",{ref:C,className:"onboard-tooltip",onPointerDown:F,style:{zIndex:1e6,...r.style?.container,top:j.top+H.y,left:j.left+H.x,transition:"top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)",cursor:r.metadata.draggable?"grab":"auto",touchAction:"none"},onMouseDown:w,onClick:w,children:[(0,b.jsxs)("div",{className:"onboard-tooltip-header",children:[(0,b.jsx)("h3",{className:"onboard-tooltip-title",children:a.title}),(0,b.jsx)("button",{onClick:i=>{i.stopPropagation(),y()},className:"onboard-close-button",children:(0,b.jsx)(ct,{})})]}),(0,b.jsx)("p",{className:"onboard-tooltip-description",children:a.description}),(0,b.jsxs)("div",{className:"onboard-tooltip-footer",children:[(0,b.jsxs)("button",{onClick:i=>{i.stopPropagation(),z()},disabled:N,className:"onboard-button-ghost",style:{background:"none",border:"none",cursor:N?"not-allowed":"pointer",...r.style?.prev},children:[(0,b.jsx)(ut,{}),"Prev"]}),p?(0,b.jsx)("button",{onClick:i=>{i.stopPropagation(),v()},className:"onboard-button-primary",style:{border:"none",cursor:"pointer",...r.style?.finish},children:"Finish"}):(0,b.jsxs)("button",{onClick:i=>{i.stopPropagation(),v()},className:"onboard-button-primary",style:{border:"none",cursor:"pointer",...N?r.style?.start:{},...N?{}:r.style?.next},children:[N&&r.style?.start?"Start":"Next",!(N&&r.style?.start)&&(0,b.jsx)(lt,{})]})]})]})]});return typeof document<"u"?(0,G.createPortal)(Y,document.body):null};var W=require("react/jsx-runtime"),V=(0,c.createContext)(void 0),$="onboarding_state",dt=()=>{if(typeof window<"u"){let r=T.default.get($);if(r)try{let a=JSON.parse(r);if(a&&typeof a=="object")return{currentStepIndex:a.currentStepIndex??0,currentSubStepIndex:a.currentSubStepIndex??null,isActive:a.isActive??!0,completedSteps:a.completedSteps??[],subStepProgress:a.subStepProgress??{}}}catch{}}return{currentStepIndex:0,currentSubStepIndex:null,isActive:!0,completedSteps:[],subStepProgress:{}}},pt=({config:r,ssr:a=!1,onNavigate:v,children:z})=>{let[y,N]=(0,c.useState)(!a),[p,g]=(0,c.useState)(dt),[f,j]=(0,c.useState)(typeof window<"u"?window.location.pathname:""),[B,H]=(0,c.useState)(!1),k=(0,c.useRef)(r),A=(0,c.useRef)(v),E=(0,c.useRef)(""),C=(0,c.useRef)(typeof window<"u"?window.location.pathname:""),R=(0,c.useRef)(!1);(0,c.useEffect)(()=>{f!==C.current&&(C.current=f,E.current="")},[f]),(0,c.useEffect)(()=>{k.current=r,A.current=v},[r,v]),(0,c.useEffect)(()=>{if(typeof window>"u")return;let e=()=>{let u=window.location.pathname;j(u)};window.addEventListener("popstate",e);let t=window.history.pushState,o=window.history.replaceState;window.history.pushState=function(...u){t.apply(this,u),e()},window.history.replaceState=function(...u){o.apply(this,u),e()},window.addEventListener("locationchange",e);let n=setInterval(e,200);return()=>{window.removeEventListener("popstate",e),window.history.pushState=t,window.history.replaceState=o,window.removeEventListener("locationchange",e),clearInterval(n)}},[]);let O=(0,c.useCallback)(e=>{e&&(A.current?A.current(e):window.location.href=e)},[]),I=(0,c.useCallback)((e,t)=>{if(!e?.urlMatch||!t)return!1;let o=!1;if(e.urlMatch.includes("*")){let n=e.urlMatch.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\\\*/g,".*");o=new RegExp(`^${n}$`).test(t)}else o=t===e.urlMatch;return o},[]),F=(0,c.useCallback)((e,t)=>{let o=k.current,n=[],u=window.location.pathname,l=(s,x=-1)=>{if(x!==null&&(s.click&&n.push(s.attribute),s.subSteps)){let S=x===-1?s.subSteps.length:x;for(let L=0;L<S;L++)s.subSteps[L].click&&n.push(s.subSteps[L].attribute)}};for(let s=0;s<=e;s++){let x=o.steps[s];I(x,u)&&(s<e?l(x):t!==null&&l(x,t))}if(n.length===0)return;let d=s=>{if(s>=n.length)return;let x=n[s],S=document.querySelector(`[data-onboarding-id="${x}"]`);S&&S.click(),setTimeout(()=>d(s+1),500)};setTimeout(()=>d(0),500)},[I,f]);(0,c.useEffect)(()=>{if(a&&!y){N(!0);return}let e=k.current,t=e.metadata.inOrder!==!1;g(o=>{if(!o.isActive)return o;let n={...o},u=!1;if(t){let l=e.steps.findIndex((d,s)=>!o.completedSteps.includes(s));if(l!==-1){l!==o.currentStepIndex&&(n.currentStepIndex=l,n.currentSubStepIndex=o.subStepProgress[l]??null,u=!0);let d=e.steps[l];I(d,f)||d.urlBase&&f!==d.urlBase&&O(d.urlBase)}}else{let l=e.steps.findIndex((d,s)=>I(d,f)&&!o.completedSteps.includes(s));l!==-1&&l!==o.currentStepIndex&&(n.currentStepIndex=l,n.currentSubStepIndex=o.subStepProgress[l]??null,u=!0)}return u?n:o})},[a,y,f,O,I]),(0,c.useEffect)(()=>{if(!p.isActive||!y)return;let e=k.current,t=e.steps[p.currentStepIndex],o=`${f}-${p.currentStepIndex}-${p.currentSubStepIndex}`;if(E.current===o)return;let n=R.current;if(R.current=!1,n&&f===C.current){E.current=o;return}t&&I(t,f)&&e.metadata.simulateClicksOnNavigate&&E.current!==o&&(E.current=o,C.current=f,F(p.currentStepIndex,p.currentSubStepIndex))},[p.currentStepIndex,p.currentSubStepIndex,p.isActive,f,y,I,F]),(0,c.useEffect)(()=>{y&&T.default.set($,JSON.stringify(p),{expires:365})},[p,y]);let X=(0,c.useMemo)(()=>{let e=r.steps[p.currentStepIndex];if(!e)return null;let t=I(e,f);if(p.currentSubStepIndex!==null&&e.subSteps){let o=e.subSteps[p.currentSubStepIndex];return t||B?o||e:null}return t?e:null},[r.steps,p.currentStepIndex,p.currentSubStepIndex,f,I,B]),M=p.currentStepIndex===0&&p.currentSubStepIndex===null,D=(0,c.useMemo)(()=>{let e=r.steps.length,t=r.steps[p.currentStepIndex],o=t?.subSteps&&t.subSteps.length>0;return p.currentStepIndex===e-1?o?p.currentSubStepIndex===t.subSteps.length-1:!0:!1},[r.steps,p.currentStepIndex,p.currentSubStepIndex]),w=(0,c.useCallback)(()=>{let e=k.current;R.current=!0,g(t=>{let{currentStepIndex:o,currentSubStepIndex:n,completedSteps:u}=t,l=e.steps[o];if(!l)return t;let d=n!==null&&l.subSteps?l.subSteps[n]:l;if(d.click){let S=document.querySelector(`[data-onboarding-id="${d.attribute}"]`);S&&S.click()}let s,x;if(l.subSteps&&(n===null||n<l.subSteps.length-1)){let S=n===null?0:n+1,L=l.subSteps[S];H(!0),setTimeout(()=>H(!1),1e3),x=d.navigate||L.navigate,!x&&n===null&&(x=l.navigate),s={...t,currentSubStepIndex:S,subStepProgress:{...t.subStepProgress,[o]:S}}}else{let S=o;if(o<e.steps.length-1){let L=o+1,q=e.steps[L],U=t.subStepProgress[L]??null,Z=U!==null&&q.subSteps?q.subSteps[U]:null;x=d.navigate||q.navigate||Z?.navigate,s={...t,currentStepIndex:L,currentSubStepIndex:U,completedSteps:u.includes(S)?u:[...u,S],subStepProgress:{...t.subStepProgress,[S]:n}}}else e.onOnboardingComplete&&e.onOnboardingComplete(),x=d.navigate||l.navigate,s={...t,isActive:!1,completedSteps:u.includes(S)?u:[...u,S],subStepProgress:{...t.subStepProgress,[S]:n}}}return T.default.set($,JSON.stringify(s),{expires:365}),x&&O(x),s})},[O]),Y=(0,c.useCallback)(()=>{let e=k.current;R.current=!0,g(t=>{let o,n;if(t.currentSubStepIndex!==null&&t.currentSubStepIndex>0){let u=t.currentSubStepIndex-1;n=e.steps[t.currentStepIndex].subSteps[u].navigate,o={...t,currentSubStepIndex:u,subStepProgress:{...t.subStepProgress,[t.currentStepIndex]:u}}}else if(t.currentStepIndex>0&&t.currentSubStepIndex===0)n=e.steps[t.currentStepIndex].navigate,o={...t,currentSubStepIndex:null,subStepProgress:{...t.subStepProgress,[t.currentStepIndex]:null}};else if(t.currentStepIndex>0){let u=t.currentStepIndex-1,l=e.steps[u],d=t.subStepProgress[u]??(l.subSteps?l.subSteps.length-1:null),s=d!==null&&l.subSteps?l.subSteps[d]:null;n=l.navigate||s?.navigate,o={...t,currentStepIndex:u,currentSubStepIndex:d,isActive:!0,subStepProgress:{...t.subStepProgress,[u]:d}}}else return t;return T.default.set($,JSON.stringify(o),{expires:365}),n&&O(n),o})},[O]),i=(0,c.useCallback)(()=>{g(e=>({...e,isActive:!1})),k.current.onOnboardingComplete&&k.current.onOnboardingComplete()},[]),m=(0,c.useCallback)((e,t=null)=>{let o=k.current;R.current=!0,g(n=>{let u=o.steps[e],l=t!==null&&u.subSteps?u.subSteps[t]:null,d=u.navigate||l?.navigate,s={...n,currentStepIndex:e,currentSubStepIndex:t,isActive:!0,subStepProgress:{...n.subStepProgress,[e]:t}};return T.default.set($,JSON.stringify(s),{expires:365}),d&&O(d),s})},[O]),P={config:r,state:p,nextStep:w,prevStep:Y,finish:i,goToStep:m,currentStep:X,isFirstStep:M,isLastStep:D};return y?(0,W.jsxs)(V.Provider,{value:P,children:[z,p.isActive&&(0,W.jsx)(Q,{})]}):(0,W.jsx)(W.Fragment,{children:z})},K=()=>{let r=(0,c.useContext)(V);if(r===void 0)throw new Error("useOnboarding must be used within an OnboardingProvider");return r};0&&(module.exports={OnboardingProvider,useOnboarding});
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/components/OnboardingProvider.tsx","../src/components/OnboardingOverlay.tsx"],"sourcesContent":["'use client';\n\nimport './styles.css';\nexport * from './components/OnboardingProvider';\nexport * from './types';\n","'use client';\n\nimport React, {\n createContext,\n useContext,\n useEffect,\n useState,\n useCallback,\n useMemo,\n useRef,\n} from 'react';\nimport Cookies from 'js-cookie';\nimport { OnboardingConfig, OnboardingState, OnboardingStep, OnboardingSubStep } from '../types';\nimport { OnboardingOverlay } from './OnboardingOverlay';\n\ninterface OnboardingContextType {\n config: OnboardingConfig;\n state: OnboardingState;\n nextStep: () => void;\n prevStep: () => void;\n finish: () => void;\n goToStep: (stepIndex: number, subStepIndex?: number | null) => void;\n currentStep: OnboardingStep | OnboardingSubStep | null;\n isFirstStep: boolean;\n isLastStep: boolean;\n}\n\nconst OnboardingContext = createContext<OnboardingContextType | undefined>(undefined);\n\nconst COOKIE_NAME = 'onboarding_state';\n\nexport const OnboardingProvider: React.FC<{\n config: OnboardingConfig;\n ssr?: boolean;\n onNavigate?: (url: string) => void;\n children: React.ReactNode;\n}> = ({ config, ssr = false, onNavigate, children }) => {\n const [isMounted, setIsMounted] = useState(!ssr);\n const [state, setState] = useState<OnboardingState>({\n currentStepIndex: 0,\n currentSubStepIndex: null,\n isActive: true,\n });\n\n const configRef = useRef(config);\n const onNavigateRef = useRef(onNavigate);\n\n useEffect(() => {\n configRef.current = config;\n onNavigateRef.current = onNavigate;\n }, [config, onNavigate]);\n\n const handleNavigation = useCallback((link?: string) => {\n if (!link) return;\n\n if (onNavigateRef.current) {\n onNavigateRef.current(link);\n } else {\n window.location.href = link;\n }\n }, []);\n\n const isMatch = (step: OnboardingStep, path: string) => {\n if (step.urlMatch instanceof RegExp) return step.urlMatch.test(path);\n\n if (typeof step.urlMatch === 'string' && step.urlMatch.includes('*')) {\n const pattern = step.urlMatch.replace(/[.+?^${}()|[\\\\]/g, '\\\\$&').replace(/\\*/g, '.*');\n return new RegExp(`^${pattern}$`).test(path);\n }\n\n return path === step.urlMatch;\n };\n\n useEffect(() => {\n if (ssr) {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setIsMounted(true);\n }\n\n const currentConfig = configRef.current;\n const currentPath = window.location.pathname;\n let matchedStepIndex = -1;\n\n if ((currentConfig.metadata.inOrder as boolean | undefined) === false) {\n matchedStepIndex = currentConfig.steps.findIndex((step) => isMatch(step, currentPath));\n }\n\n const savedState = Cookies.get(COOKIE_NAME);\n if (savedState) {\n try {\n const parsed: OnboardingState = JSON.parse(savedState);\n\n if ((currentConfig.metadata.inOrder as boolean | undefined) === false) {\n if (matchedStepIndex !== -1) {\n if (parsed.currentStepIndex === matchedStepIndex) {\n setState(parsed);\n } else {\n setState({\n currentStepIndex: matchedStepIndex,\n currentSubStepIndex: null,\n isActive: true,\n });\n }\n } else {\n setState({ ...parsed, isActive: false });\n }\n } else {\n setState(parsed);\n\n if ((currentConfig.metadata.inOrder as boolean | undefined) !== false) {\n const step = currentConfig.steps[parsed.currentStepIndex];\n if (step && parsed.isActive) {\n let targetUrl: string | undefined;\n\n if (parsed.currentStepIndex > 0) {\n const prevStep = currentConfig.steps[parsed.currentStepIndex - 1];\n if (prevStep.navigate) {\n targetUrl = prevStep.navigate;\n }\n }\n\n if (!targetUrl && typeof step.urlMatch === 'string') {\n targetUrl = step.urlMatch;\n }\n\n if (targetUrl && window.location.pathname !== targetUrl) {\n handleNavigation(targetUrl);\n }\n\n if (currentConfig.metadata.simulateClicksOnNavigate) {\n if (parsed.currentSubStepIndex !== null && step.click) {\n setTimeout(() => {\n const element = document.querySelector(\n `[data-onboarding-id=\"${step.attribute}\"]`,\n ) as HTMLElement;\n if (element) {\n element.click();\n }\n }, 500);\n }\n }\n }\n }\n }\n } catch (e) {\n console.error('Failed to parse onboarding state from cookie', e);\n if (matchedStepIndex !== -1) {\n setState({\n currentStepIndex: matchedStepIndex,\n currentSubStepIndex: null,\n isActive: true,\n });\n }\n }\n } else if (matchedStepIndex !== -1) {\n setState({\n currentStepIndex: matchedStepIndex,\n currentSubStepIndex: null,\n isActive: true,\n });\n } else if ((currentConfig.metadata.inOrder as boolean | undefined) === false) {\n setState((prev) => ({ ...prev, isActive: false }));\n } else {\n const step = currentConfig.steps[0];\n if (step && typeof step.urlMatch === 'string' && window.location.pathname !== step.urlMatch) {\n handleNavigation(step.urlMatch);\n }\n }\n }, [ssr, handleNavigation]);\n\n useEffect(() => {\n if (isMounted) {\n Cookies.set(COOKIE_NAME, JSON.stringify(state), { expires: 365 });\n }\n }, [state, isMounted]);\n\n const currentStep = useMemo(() => {\n const step = config.steps[state.currentStepIndex];\n if (!step) return null;\n if (state.currentSubStepIndex !== null && step.subSteps) {\n return step.subSteps[state.currentSubStepIndex] || step;\n }\n return step;\n }, [config.steps, state.currentStepIndex, state.currentSubStepIndex]);\n\n const isFirstStep = state.currentStepIndex === 0 && state.currentSubStepIndex === null;\n const isLastStep = useMemo(() => {\n const totalSteps = config.steps.length;\n const isLastMainStep = state.currentStepIndex === totalSteps - 1;\n const step = config.steps[state.currentStepIndex];\n const hasSubSteps = step?.subSteps && step.subSteps.length > 0;\n\n if (isLastMainStep) {\n if (hasSubSteps) {\n return state.currentSubStepIndex === step.subSteps!.length - 1;\n }\n return true;\n }\n return false;\n }, [config.steps, state.currentStepIndex, state.currentSubStepIndex]);\n\n const nextStep = useCallback(() => {\n const currentConfig = configRef.current;\n const stepObj = currentConfig.steps[state.currentStepIndex];\n const currentActiveStep =\n state.currentSubStepIndex !== null && stepObj.subSteps\n ? stepObj.subSteps[state.currentSubStepIndex]\n : stepObj;\n\n if (currentActiveStep.click) {\n const element = document.querySelector(\n `[data-onboarding-id=\"${currentActiveStep.attribute}\"]`,\n ) as HTMLElement;\n if (element) {\n element.click();\n }\n }\n\n if (\n stepObj.subSteps &&\n (state.currentSubStepIndex === null ||\n state.currentSubStepIndex < stepObj.subSteps.length - 1)\n ) {\n const nextSubIndex = state.currentSubStepIndex === null ? 0 : state.currentSubStepIndex + 1;\n const nextSubStep = stepObj.subSteps[nextSubIndex];\n setState((prev) => ({ ...prev, currentSubStepIndex: nextSubIndex }));\n\n if (nextSubStep.navigate) handleNavigation(nextSubStep.navigate);\n return;\n }\n\n if (state.currentStepIndex < currentConfig.steps.length - 1) {\n const nextIndex = state.currentStepIndex + 1;\n const nextStepObj = currentConfig.steps[nextIndex];\n setState({\n currentStepIndex: nextIndex,\n currentSubStepIndex: null,\n isActive: true,\n });\n\n if (nextStepObj.navigate) handleNavigation(nextStepObj.navigate);\n } else {\n setState((prev) => ({ ...prev, isActive: false }));\n if (currentConfig.onOnboardingComplete) {\n currentConfig.onOnboardingComplete();\n }\n }\n }, [state.currentStepIndex, state.currentSubStepIndex, handleNavigation]);\n\n const prevStep = useCallback(() => {\n const currentConfig = configRef.current;\n\n if (state.currentSubStepIndex !== null && state.currentSubStepIndex > 0) {\n setState((prev) => ({ ...prev, currentSubStepIndex: prev.currentSubStepIndex! - 1 }));\n return;\n }\n\n if (state.currentStepIndex > 0 && state.currentSubStepIndex === 0) {\n setState((prev) => ({ ...prev, currentSubStepIndex: null }));\n return;\n }\n\n if (state.currentStepIndex > 0) {\n const prevIndex = state.currentStepIndex - 1;\n const prevStepObj = currentConfig.steps[prevIndex];\n const prevSubStepIndex = prevStepObj.subSteps ? prevStepObj.subSteps.length - 1 : null;\n\n setState({\n currentStepIndex: prevIndex,\n currentSubStepIndex: prevSubStepIndex,\n isActive: true,\n });\n }\n }, [state.currentStepIndex, state.currentSubStepIndex]);\n\n const finish = useCallback(() => {\n setState((prev) => ({ ...prev, isActive: false }));\n if (configRef.current.onOnboardingComplete) {\n configRef.current.onOnboardingComplete();\n }\n }, []);\n\n const goToStep = useCallback((stepIndex: number, subStepIndex: number | null = null) => {\n setState({\n currentStepIndex: stepIndex,\n currentSubStepIndex: subStepIndex,\n isActive: true,\n });\n }, []);\n\n const value = {\n config,\n state,\n nextStep,\n prevStep,\n finish,\n goToStep,\n currentStep,\n isFirstStep,\n isLastStep,\n };\n\n if (!isMounted) return <>{children}</>;\n\n return (\n <OnboardingContext.Provider value={value}>\n {children}\n {state.isActive && <OnboardingOverlay />}\n </OnboardingContext.Provider>\n );\n};\n\nexport const useOnboarding = () => {\n const context = useContext(OnboardingContext);\n if (context === undefined) {\n throw new Error('useOnboarding must be used within an OnboardingProvider');\n }\n return context;\n};\n","'use client';\n\nimport React, { useState, useEffect, useCallback, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport { useOnboarding } from './OnboardingProvider';\n\nconst ChevronLeftIcon = () => (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M15 18l-6-6 6-6\" />\n </svg>\n);\n\nconst ChevronRightIcon = () => (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M9 18l6-6-6-6\" />\n </svg>\n);\n\nconst XIcon = () => (\n <svg\n width=\"18\"\n height=\"18\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" />\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" />\n </svg>\n);\n\nexport const OnboardingOverlay: React.FC = () => {\n const { config, currentStep, nextStep, prevStep, finish, isFirstStep, isLastStep } =\n useOnboarding();\n const [coords, setCoords] = useState<{\n top: number;\n left: number;\n width: number;\n height: number;\n } | null>(null);\n const [position, setPosition] = useState<{ top: number; left: number }>({ top: 0, left: 0 });\n const [dragOffset, setDragOffset] = useState<{ x: number; y: number }>({ x: 0, y: 0 });\n const isDragging = useRef(false);\n const dragStart = useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n const tooltipRef = useRef<HTMLDivElement>(null);\n\n // Reset drag offset when step changes\n const [prevStepRef, setPrevStepRef] = useState(currentStep);\n if (currentStep !== prevStepRef) {\n setPrevStepRef(currentStep);\n setDragOffset({ x: 0, y: 0 });\n }\n\n const handlePointerUpRef = useRef<() => void>(() => {});\n\n const handlePointerMove = useCallback((e: PointerEvent) => {\n if (!isDragging.current) return;\n\n const newX = e.clientX - dragStart.current.x;\n const newY = e.clientY - dragStart.current.y;\n\n setDragOffset({ x: newX, y: newY });\n }, []);\n\n const handlePointerUp = useCallback(() => {\n isDragging.current = false;\n\n if (tooltipRef.current) {\n tooltipRef.current.style.transition =\n 'top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)';\n tooltipRef.current.style.cursor = config.metadata.draggable ? 'grab' : 'auto';\n }\n\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUpRef.current);\n }, [config.metadata.draggable, handlePointerMove]);\n\n useEffect(() => {\n handlePointerUpRef.current = handlePointerUp;\n }, [handlePointerUp]);\n\n const handlePointerDown = (e: React.PointerEvent) => {\n if (!config.metadata.draggable) return;\n e.stopPropagation();\n e.preventDefault();\n isDragging.current = true;\n dragStart.current = { x: e.clientX - dragOffset.x, y: e.clientY - dragOffset.y };\n\n if (tooltipRef.current) {\n tooltipRef.current.style.transition = 'none';\n tooltipRef.current.style.cursor = 'grabbing';\n }\n\n window.addEventListener('pointermove', handlePointerMove);\n window.addEventListener('pointerup', handlePointerUp);\n };\n\n const calculateBestPosition = useCallback(\n (rect: {\n top: number;\n bottom: number;\n left: number;\n right: number;\n width: number;\n height: number;\n }) => {\n const tooltipWidth = 300;\n const tooltipHeight = 200;\n const gap = 12;\n const padding = 20;\n\n const spaceAbove = rect.top;\n const spaceBelow = window.innerHeight - rect.bottom;\n const spaceLeft = rect.left;\n const spaceRight = window.innerWidth - rect.right;\n\n let top = 0;\n let left = 0;\n\n if (spaceBelow > tooltipHeight + gap + padding) {\n top = rect.bottom + gap;\n left = Math.max(\n padding,\n Math.min(\n window.innerWidth - tooltipWidth - padding,\n rect.left + rect.width / 2 - tooltipWidth / 2,\n ),\n );\n } else if (spaceAbove > tooltipHeight + gap + padding) {\n top = rect.top - tooltipHeight - gap;\n left = Math.max(\n padding,\n Math.min(\n window.innerWidth - tooltipWidth - padding,\n rect.left + rect.width / 2 - tooltipWidth / 2,\n ),\n );\n } else if (spaceRight > tooltipWidth + gap + padding) {\n top = Math.max(\n padding,\n Math.min(\n window.innerHeight - tooltipHeight - padding,\n rect.top + rect.height / 2 - tooltipHeight / 2,\n ),\n );\n left = rect.right + gap;\n } else if (spaceLeft > tooltipWidth + gap + padding) {\n top = Math.max(\n padding,\n Math.min(\n window.innerHeight - tooltipHeight - padding,\n rect.top + rect.height / 2 - tooltipHeight / 2,\n ),\n );\n left = rect.left - tooltipWidth - gap;\n } else {\n top = window.innerHeight / 2 - tooltipHeight / 2;\n left = window.innerWidth / 2 - tooltipWidth / 2;\n }\n\n return { top: top + window.scrollY, left: left + window.scrollX };\n },\n [],\n );\n\n const updateCoords = useCallback(() => {\n if (!currentStep) return;\n\n const element = document.querySelector(\n `[data-onboarding-id=\"${currentStep.attribute}\"]`,\n ) as HTMLElement;\n if (element) {\n const rect = element.getBoundingClientRect();\n const padding = config.style?.padding || 0;\n\n const paddedRect = {\n top: rect.top - padding,\n bottom: rect.bottom + padding,\n left: rect.left - padding,\n right: rect.right + padding,\n width: rect.width + padding * 2,\n height: rect.height + padding * 2,\n };\n\n const newCoords = {\n top: paddedRect.top + window.scrollY,\n left: paddedRect.left + window.scrollX,\n width: paddedRect.width,\n height: paddedRect.height,\n };\n\n const newPosition = calculateBestPosition(paddedRect);\n\n setCoords((prev) => {\n if (\n prev &&\n prev.top === newCoords.top &&\n prev.left === newCoords.left &&\n prev.width === newCoords.width &&\n prev.height === newCoords.height\n ) {\n return prev;\n }\n return newCoords;\n });\n\n setPosition((prev) => {\n if (prev.top === newPosition.top && prev.left === newPosition.left) {\n return prev;\n }\n return newPosition;\n });\n } else {\n setCoords(null);\n }\n }, [currentStep, calculateBestPosition, config.style]);\n\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n updateCoords();\n window.addEventListener('resize', updateCoords);\n window.addEventListener('scroll', updateCoords);\n\n const observer = new MutationObserver(updateCoords);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true });\n\n let resizeObserver: ResizeObserver | null = null;\n if (typeof ResizeObserver !== 'undefined') {\n resizeObserver = new ResizeObserver(updateCoords);\n resizeObserver.observe(document.body);\n\n const element = currentStep?.attribute\n ? document.querySelector(`[data-onboarding-id=\"${currentStep.attribute}\"]`)\n : null;\n if (element) {\n resizeObserver.observe(element);\n }\n }\n\n return () => {\n window.removeEventListener('resize', updateCoords);\n window.removeEventListener('scroll', updateCoords);\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUp);\n observer.disconnect();\n if (resizeObserver) resizeObserver.disconnect();\n };\n }, [updateCoords, currentStep?.attribute, handlePointerMove, handlePointerUp]);\n\n if (!currentStep || !coords) return null;\n\n const maskStyle = {\n ...config.style?.background,\n transition: 'all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)',\n };\n\n const stopPropagation = (e: React.PointerEvent | React.MouseEvent) => {\n e.stopPropagation();\n };\n\n const overlayContent = (\n <div className=\"onboard-overlay-container\">\n <div\n style={{ height: coords.top, ...maskStyle }}\n className=\"onboard-overlay-mask onboard-mask-top\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{\n top: coords.top + coords.height,\n height: `calc(100vh - ${coords.top + coords.height}px)`,\n ...maskStyle,\n }}\n className=\"onboard-overlay-mask onboard-mask-bottom\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{ top: coords.top, height: coords.height, width: coords.left, ...maskStyle }}\n className=\"onboard-overlay-mask onboard-mask-left\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{\n top: coords.top,\n height: coords.height,\n left: coords.left + coords.width,\n width: `calc(100% - ${coords.left + coords.width}px)`,\n ...maskStyle,\n }}\n className=\"onboard-overlay-mask\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n\n <div\n ref={tooltipRef}\n className=\"onboard-tooltip\"\n onPointerDown={handlePointerDown}\n style={{\n zIndex: 1000000,\n ...config.style?.container,\n top: position.top + dragOffset.y,\n left: position.left + dragOffset.x,\n transition:\n 'top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)',\n cursor: config.metadata.draggable ? 'grab' : 'auto',\n touchAction: 'none',\n }}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n >\n <div className=\"onboard-tooltip-header\">\n <h3 className=\"onboard-tooltip-title\">{currentStep.title}</h3>\n <button\n onClick={(e) => {\n e.stopPropagation();\n finish();\n }}\n className=\"onboard-close-button\"\n >\n <XIcon />\n </button>\n </div>\n <p className=\"onboard-tooltip-description\">{currentStep.description}</p>\n\n <div className=\"onboard-tooltip-footer\">\n <button\n onClick={(e) => {\n e.stopPropagation();\n prevStep();\n }}\n disabled={isFirstStep}\n className=\"onboard-button-ghost\"\n style={{\n background: 'none',\n border: 'none',\n cursor: isFirstStep ? 'not-allowed' : 'pointer',\n ...config.style?.prev,\n }}\n >\n <ChevronLeftIcon />\n Prev\n </button>\n\n {isLastStep ? (\n <button\n onClick={(e) => {\n e.stopPropagation();\n finish();\n }}\n className=\"onboard-button-primary\"\n style={{ border: 'none', cursor: 'pointer', ...config.style?.finish }}\n >\n Finish\n </button>\n ) : (\n <button\n onClick={(e) => {\n e.stopPropagation();\n nextStep();\n }}\n className=\"onboard-button-primary\"\n style={{\n border: 'none',\n cursor: 'pointer',\n ...(isFirstStep ? config.style?.start : {}),\n ...(!isFirstStep ? config.style?.next : {}),\n }}\n >\n {isFirstStep && config.style?.start ? 'Start' : 'Next'}\n {!(isFirstStep && config.style?.start) && <ChevronRightIcon />}\n </button>\n )}\n </div>\n </div>\n </div>\n );\n\n return typeof document !== 'undefined' ? createPortal(overlayContent, document.body) : null;\n};\n"],"mappings":";4kBAAA,IAAAA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Z,OAAA/C,EACA,MAAAM,EACA,SAAA2B,EACA,SAAAV,EACA,OAAAoB,EACA,SAAAC,EACA,YAAAjB,EACA,YAAAC,EACA,WAAAC,CACF,EAEA,OAAKzB,KAGH,QAACP,EAAkB,SAAlB,CAA2B,MAAOkD,EAChC,UAAA5C,EACAG,EAAM,aAAY,OAAC0C,EAAA,EAAkB,GACxC,KANqB,mBAAG,SAAA7C,EAAS,CAQrC,EAEa8C,EAAgB,IAAM,CACjC,IAAMC,KAAU,cAAWrD,CAAiB,EAC5C,GAAIqD,IAAY,OACd,MAAM,IAAI,MAAM,yDAAyD,EAE3E,OAAOA,CACT","names":["index_exports","__export","OnboardingProvider","useOnboarding","__toCommonJS","import_react","import_js_cookie","import_react","import_react_dom","import_jsx_runtime","ChevronLeftIcon","ChevronRightIcon","XIcon","OnboardingOverlay","config","currentStep","nextStep","prevStep","finish","isFirstStep","isLastStep","useOnboarding","coords","setCoords","position","setPosition","dragOffset","setDragOffset","isDragging","dragStart","tooltipRef","prevStepRef","setPrevStepRef","handlePointerUpRef","handlePointerMove","newX","newY","handlePointerUp","handlePointerDown","calculateBestPosition","rect","spaceAbove","spaceBelow","spaceLeft","spaceRight","top","left","updateCoords","element","padding","paddedRect","newCoords","newPosition","prev","observer","resizeObserver","maskStyle","stopPropagation","overlayContent","import_jsx_runtime","OnboardingContext","COOKIE_NAME","OnboardingProvider","config","ssr","onNavigate","children","isMounted","setIsMounted","state","setState","configRef","onNavigateRef","handleNavigation","link","isMatch","step","path","pattern","currentConfig","currentPath","matchedStepIndex","savedState","Cookies","parsed","targetUrl","prevStep","element","e","prev","currentStep","isFirstStep","isLastStep","totalSteps","isLastMainStep","hasSubSteps","nextStep","stepObj","currentActiveStep","nextSubIndex","nextSubStep","nextIndex","nextStepObj","prevIndex","prevStepObj","prevSubStepIndex","finish","goToStep","stepIndex","subStepIndex","value","OnboardingOverlay","useOnboarding","context"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/components/OnboardingProvider.tsx","../src/components/OnboardingOverlay.tsx"],"sourcesContent":["'use client';\n\nimport './styles.css';\nexport * from './components/OnboardingProvider';\nexport * from './types';\n","'use client';\n\nimport React, {\n createContext,\n useContext,\n useEffect,\n useState,\n useCallback,\n useMemo,\n useRef,\n} from 'react';\nimport Cookies from 'js-cookie';\nimport { OnboardingConfig, OnboardingState, OnboardingStep, OnboardingSubStep } from '../types';\nimport { OnboardingOverlay } from './OnboardingOverlay';\n\ninterface OnboardingContextType {\n config: OnboardingConfig;\n state: OnboardingState;\n nextStep: () => void;\n prevStep: () => void;\n finish: () => void;\n goToStep: (stepIndex: number, subStepIndex?: number | null) => void;\n currentStep: OnboardingStep | OnboardingSubStep | null;\n isFirstStep: boolean;\n isLastStep: boolean;\n}\n\nconst OnboardingContext = createContext<OnboardingContextType | undefined>(undefined);\n\nconst COOKIE_NAME = 'onboarding_state';\n\nconst getInitialState = (): OnboardingState => {\n if (typeof window !== 'undefined') {\n const saved = Cookies.get(COOKIE_NAME);\n if (saved) {\n try {\n const parsed = JSON.parse(saved);\n if (parsed && typeof parsed === 'object') {\n return {\n currentStepIndex: parsed.currentStepIndex ?? 0,\n currentSubStepIndex: parsed.currentSubStepIndex ?? null,\n isActive: parsed.isActive ?? true,\n completedSteps: parsed.completedSteps ?? [],\n subStepProgress: parsed.subStepProgress ?? {},\n };\n }\n } catch {\n // Ignore\n }\n }\n }\n return {\n currentStepIndex: 0,\n currentSubStepIndex: null,\n isActive: true,\n completedSteps: [],\n subStepProgress: {},\n };\n};\n\nexport const OnboardingProvider: React.FC<{\n config: OnboardingConfig;\n ssr?: boolean;\n onNavigate?: (url: string) => void;\n children: React.ReactNode;\n}> = ({ config, ssr = false, onNavigate, children }) => {\n const [isMounted, setIsMounted] = useState(!ssr);\n const [state, setState] = useState<OnboardingState>(getInitialState);\n const [currentPath, setCurrentPath] = useState(\n typeof window !== 'undefined' ? window.location.pathname : '',\n );\n const [isTransitioning, setIsTransitioning] = useState(false);\n\n const configRef = useRef(config);\n const onNavigateRef = useRef(onNavigate);\n const lastSimulatedKey = useRef<string>('');\n const lastPathForSimulation = useRef<string>(\n typeof window !== 'undefined' ? window.location.pathname : '',\n );\n const wasInternalAction = useRef(false);\n\n useEffect(() => {\n if (currentPath !== lastPathForSimulation.current) {\n lastPathForSimulation.current = currentPath;\n lastSimulatedKey.current = ''; // Reset simulation tracking on path change\n }\n }, [currentPath]);\n\n useEffect(() => {\n configRef.current = config;\n onNavigateRef.current = onNavigate;\n }, [config, onNavigate]);\n\n useEffect(() => {\n if (typeof window === 'undefined') return;\n\n const handlePathChange = () => {\n const newPath = window.location.pathname;\n setCurrentPath(newPath);\n };\n\n window.addEventListener('popstate', handlePathChange);\n\n const originalPushState = window.history.pushState;\n const originalReplaceState = window.history.replaceState;\n\n window.history.pushState = function (...args) {\n originalPushState.apply(this, args);\n handlePathChange();\n };\n\n window.history.replaceState = function (...args) {\n originalReplaceState.apply(this, args);\n handlePathChange();\n };\n\n window.addEventListener('locationchange', handlePathChange);\n const interval = setInterval(handlePathChange, 200);\n\n return () => {\n window.removeEventListener('popstate', handlePathChange);\n window.history.pushState = originalPushState;\n window.history.replaceState = originalReplaceState;\n window.removeEventListener('locationchange', handlePathChange);\n clearInterval(interval);\n };\n }, []);\n\n const handleNavigation = useCallback((link?: string) => {\n if (!link) return;\n if (onNavigateRef.current) {\n onNavigateRef.current(link);\n } else {\n window.location.href = link;\n }\n }, []);\n\n const isMatch = useCallback((step: OnboardingStep, path: string) => {\n if (!step?.urlMatch || !path) return false;\n\n let match = false;\n if (step.urlMatch.includes('*')) {\n const pattern = step.urlMatch\n .replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&') // Escape special regex chars\n .replace(/\\\\\\*/g, '.*'); // Convert escaped * back to .*\n match = new RegExp(`^${pattern}$`).test(path);\n } else {\n match = path === step.urlMatch;\n }\n return match;\n }, []);\n\n const simulateClicks = useCallback(\n (stepIndex: number, subStepIndex: number | null) => {\n const currentConfig = configRef.current;\n const actions: string[] = [];\n const path = window.location.pathname;\n const collectStepClicks = (step: OnboardingStep, upToSubStep: number | null = -1) => {\n if (upToSubStep === null) {\n // We are arriving at the main step itself. No sub-steps. \n // In this case, we don't click the step's attribute because arriving there \n // should show it. Re-clicking might close it if it's a toggle.\n return;\n }\n\n if (step.click) actions.push(step.attribute);\n if (step.subSteps) {\n const limit = upToSubStep === -1 ? step.subSteps.length : upToSubStep;\n for (let i = 0; i < limit; i++) {\n if (step.subSteps[i].click) actions.push(step.subSteps[i].attribute);\n }\n }\n };\n\n for (let i = 0; i <= stepIndex; i++) {\n const step = currentConfig.steps[i];\n if (isMatch(step, path)) {\n if (i < stepIndex) collectStepClicks(step);\n else if (subStepIndex !== null) {\n // We are arriving at a sub-step. Replay clicks leading to it.\n collectStepClicks(step, subStepIndex);\n }\n }\n }\n\n if (actions.length === 0) return;\n\n const performClick = (index: number) => {\n if (index >= actions.length) return;\n const attr = actions[index];\n const element = document.querySelector(`[data-onboarding-id=\"${attr}\"]`) as HTMLElement;\n if (element) element.click();\n setTimeout(() => performClick(index + 1), 500);\n };\n\n setTimeout(() => performClick(0), 500);\n },\n [isMatch, currentPath],\n );\n\n // Reconcile state with path\n useEffect(() => {\n if (ssr && !isMounted) {\n setIsMounted(true);\n return;\n }\n\n const currentConfig = configRef.current;\n const isInOrder = (currentConfig.metadata.inOrder as boolean | undefined) !== false;\n\n // Use functional update to avoid depending on 'state'\n setState((prev) => {\n if (!prev.isActive) return prev;\n\n const nextState = { ...prev };\n let changed = false;\n\n if (!isInOrder) {\n const matchedIndex = currentConfig.steps.findIndex(\n (step, index) => isMatch(step, currentPath) && !prev.completedSteps.includes(index),\n );\n\n if (matchedIndex !== -1 && matchedIndex !== prev.currentStepIndex) {\n nextState.currentStepIndex = matchedIndex;\n nextState.currentSubStepIndex = prev.subStepProgress[matchedIndex] ?? null;\n changed = true;\n }\n } else {\n const firstUnfinishedIndex = currentConfig.steps.findIndex(\n (_, i) => !prev.completedSteps.includes(i),\n );\n\n if (firstUnfinishedIndex !== -1) {\n if (firstUnfinishedIndex !== prev.currentStepIndex) {\n nextState.currentStepIndex = firstUnfinishedIndex;\n nextState.currentSubStepIndex = prev.subStepProgress[firstUnfinishedIndex] ?? null;\n changed = true;\n }\n\n const step = currentConfig.steps[firstUnfinishedIndex];\n if (!isMatch(step, currentPath)) {\n if (step.urlBase && currentPath !== step.urlBase) {\n handleNavigation(step.urlBase);\n }\n }\n }\n }\n\n return changed ? nextState : prev;\n });\n }, [ssr, isMounted, currentPath, handleNavigation, isMatch]);\n\n // Handle click simulation separately\n useEffect(() => {\n if (!state.isActive || !isMounted) return;\n const currentConfig = configRef.current;\n const step = currentConfig.steps[state.currentStepIndex];\n\n const simKey = `${currentPath}-${state.currentStepIndex}-${state.currentSubStepIndex}`;\n\n // Skip if we already simulated this exact state\n if (lastSimulatedKey.current === simKey) {\n return;\n }\n\n const internal = wasInternalAction.current;\n wasInternalAction.current = false;\n\n // Skip if path is same and it was an internal action (Next/Prev/GoTo)\n // because manual progression handles its own clicks.\n if (internal && currentPath === lastPathForSimulation.current) {\n lastSimulatedKey.current = simKey;\n return;\n }\n\n if (step && isMatch(step, currentPath) && currentConfig.metadata.simulateClicksOnNavigate) {\n if (lastSimulatedKey.current !== simKey) {\n lastSimulatedKey.current = simKey;\n lastPathForSimulation.current = currentPath;\n simulateClicks(state.currentStepIndex, state.currentSubStepIndex);\n }\n }\n }, [\n state.currentStepIndex,\n state.currentSubStepIndex,\n state.isActive,\n currentPath,\n isMounted,\n isMatch,\n simulateClicks,\n ]);\n\n // Persist state to cookies\n useEffect(() => {\n if (isMounted) {\n Cookies.set(COOKIE_NAME, JSON.stringify(state), { expires: 365 });\n }\n }, [state, isMounted]);\n\n const currentStep = useMemo(() => {\n const step = config.steps[state.currentStepIndex];\n if (!step) return null;\n\n const isUrlMatch = isMatch(step, currentPath);\n\n if (state.currentSubStepIndex !== null && step.subSteps) {\n const subStep = step.subSteps[state.currentSubStepIndex];\n if (isUrlMatch || isTransitioning) {\n return subStep || step;\n }\n return null;\n }\n\n if (!isUrlMatch) return null;\n\n return step;\n }, [\n config.steps,\n state.currentStepIndex,\n state.currentSubStepIndex,\n currentPath,\n isMatch,\n isTransitioning,\n ]);\n\n const isFirstStep = state.currentStepIndex === 0 && state.currentSubStepIndex === null;\n const isLastStep = useMemo(() => {\n const totalSteps = config.steps.length;\n const step = config.steps[state.currentStepIndex];\n const hasSubSteps = step?.subSteps && step.subSteps.length > 0;\n\n if (state.currentStepIndex === totalSteps - 1) {\n if (hasSubSteps) return state.currentSubStepIndex === step.subSteps!.length - 1;\n return true;\n }\n return false;\n }, [config.steps, state.currentStepIndex, state.currentSubStepIndex]);\n\n const nextStep = useCallback(() => {\n const currentConfig = configRef.current;\n wasInternalAction.current = true;\n\n setState((prev) => {\n const { currentStepIndex, currentSubStepIndex, completedSteps } = prev;\n const stepObj = currentConfig.steps[currentStepIndex];\n if (!stepObj) return prev;\n\n const currentActiveStep =\n currentSubStepIndex !== null && stepObj.subSteps\n ? stepObj.subSteps[currentSubStepIndex]\n : stepObj;\n\n if (currentActiveStep.click) {\n const element = document.querySelector(\n `[data-onboarding-id=\"${currentActiveStep.attribute}\"]`,\n ) as HTMLElement;\n if (element) element.click();\n }\n\n let nextState: OnboardingState;\n let navTo: string | undefined;\n\n if (\n stepObj.subSteps &&\n (currentSubStepIndex === null || currentSubStepIndex < stepObj.subSteps.length - 1)\n ) {\n const nextSubIndex = currentSubStepIndex === null ? 0 : currentSubStepIndex + 1;\n const nextSubStep = stepObj.subSteps[nextSubIndex];\n\n setIsTransitioning(true);\n setTimeout(() => setIsTransitioning(false), 1000);\n\n navTo = currentActiveStep.navigate || nextSubStep.navigate;\n if (!navTo && currentSubStepIndex === null) navTo = stepObj.navigate;\n\n nextState = {\n ...prev,\n currentSubStepIndex: nextSubIndex,\n subStepProgress: {\n ...prev.subStepProgress,\n [currentStepIndex]: nextSubIndex,\n },\n };\n } else {\n const stepIndexToComplete = currentStepIndex;\n if (currentStepIndex < currentConfig.steps.length - 1) {\n const nextIndex = currentStepIndex + 1;\n const nextStepObj = currentConfig.steps[nextIndex];\n const targetSubStepIndex = prev.subStepProgress[nextIndex] ?? null;\n const targetSubStep =\n targetSubStepIndex !== null && nextStepObj.subSteps\n ? nextStepObj.subSteps[targetSubStepIndex]\n : null;\n\n navTo = currentActiveStep.navigate || nextStepObj.navigate || targetSubStep?.navigate;\n\n nextState = {\n ...prev,\n currentStepIndex: nextIndex,\n currentSubStepIndex: targetSubStepIndex,\n completedSteps: completedSteps.includes(stepIndexToComplete)\n ? completedSteps\n : [...completedSteps, stepIndexToComplete],\n subStepProgress: {\n ...prev.subStepProgress,\n [stepIndexToComplete]: currentSubStepIndex,\n },\n };\n } else {\n if (currentConfig.onOnboardingComplete) currentConfig.onOnboardingComplete();\n\n navTo = currentActiveStep.navigate || stepObj.navigate;\n\n nextState = {\n ...prev,\n isActive: false,\n completedSteps: completedSteps.includes(stepIndexToComplete)\n ? completedSteps\n : [...completedSteps, stepIndexToComplete],\n subStepProgress: {\n ...prev.subStepProgress,\n [stepIndexToComplete]: currentSubStepIndex,\n },\n };\n }\n }\n\n Cookies.set(COOKIE_NAME, JSON.stringify(nextState), { expires: 365 });\n if (navTo) handleNavigation(navTo);\n return nextState;\n });\n }, [handleNavigation]);\n\n const prevStep = useCallback(() => {\n const currentConfig = configRef.current;\n wasInternalAction.current = true;\n setState((prev) => {\n let nextState: OnboardingState;\n let navTo: string | undefined;\n\n if (prev.currentSubStepIndex !== null && prev.currentSubStepIndex > 0) {\n const nextSubIndex = prev.currentSubStepIndex - 1;\n const nextSubStep = currentConfig.steps[prev.currentStepIndex].subSteps![nextSubIndex];\n navTo = nextSubStep.navigate;\n\n nextState = {\n ...prev,\n currentSubStepIndex: nextSubIndex,\n subStepProgress: {\n ...prev.subStepProgress,\n [prev.currentStepIndex]: nextSubIndex,\n },\n };\n } else if (prev.currentStepIndex > 0 && prev.currentSubStepIndex === 0) {\n const stepObj = currentConfig.steps[prev.currentStepIndex];\n navTo = stepObj.navigate;\n\n nextState = {\n ...prev,\n currentSubStepIndex: null,\n subStepProgress: {\n ...prev.subStepProgress,\n [prev.currentStepIndex]: null,\n },\n };\n } else if (prev.currentStepIndex > 0) {\n const prevIndex = prev.currentStepIndex - 1;\n const prevStepObj = currentConfig.steps[prevIndex];\n const prevSubStepIndex =\n prev.subStepProgress[prevIndex] ??\n (prevStepObj.subSteps ? prevStepObj.subSteps.length - 1 : null);\n const prevSubStep =\n prevSubStepIndex !== null && prevStepObj.subSteps\n ? prevStepObj.subSteps[prevSubStepIndex]\n : null;\n\n navTo = prevStepObj.navigate || prevSubStep?.navigate;\n\n nextState = {\n ...prev,\n currentStepIndex: prevIndex,\n currentSubStepIndex: prevSubStepIndex,\n isActive: true,\n subStepProgress: {\n ...prev.subStepProgress,\n [prevIndex]: prevSubStepIndex,\n },\n };\n } else {\n return prev;\n }\n\n Cookies.set(COOKIE_NAME, JSON.stringify(nextState), { expires: 365 });\n if (navTo) handleNavigation(navTo);\n return nextState;\n });\n }, [handleNavigation]);\n\n const finish = useCallback(() => {\n setState((prev) => ({ ...prev, isActive: false }));\n if (configRef.current.onOnboardingComplete) configRef.current.onOnboardingComplete();\n }, []);\n\n const goToStep = useCallback(\n (stepIndex: number, subStepIndex: number | null = null) => {\n const currentConfig = configRef.current;\n wasInternalAction.current = true;\n setState((prev) => {\n const nextStepObj = currentConfig.steps[stepIndex];\n const targetSubStep =\n subStepIndex !== null && nextStepObj.subSteps\n ? nextStepObj.subSteps[subStepIndex]\n : null;\n\n const navTo = nextStepObj.navigate || targetSubStep?.navigate;\n\n const nextState = {\n ...prev,\n currentStepIndex: stepIndex,\n currentSubStepIndex: subStepIndex,\n isActive: true,\n subStepProgress: {\n ...prev.subStepProgress,\n [stepIndex]: subStepIndex,\n },\n };\n\n Cookies.set(COOKIE_NAME, JSON.stringify(nextState), { expires: 365 });\n if (navTo) handleNavigation(navTo);\n return nextState;\n });\n },\n [handleNavigation],\n );\n\n const value = {\n config,\n state,\n nextStep,\n prevStep,\n finish,\n goToStep,\n currentStep,\n isFirstStep,\n isLastStep,\n };\n\n if (!isMounted) return <>{children}</>;\n\n return (\n <OnboardingContext.Provider value={value}>\n {children}\n {state.isActive && <OnboardingOverlay />}\n </OnboardingContext.Provider>\n );\n};\n\nexport const useOnboarding = () => {\n const context = useContext(OnboardingContext);\n if (context === undefined)\n throw new Error('useOnboarding must be used within an OnboardingProvider');\n return context;\n};\n","'use client';\n\nimport React, { useState, useEffect, useCallback, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport { useOnboarding } from './OnboardingProvider';\n\nconst ChevronLeftIcon = () => (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M15 18l-6-6 6-6\" />\n </svg>\n);\n\nconst ChevronRightIcon = () => (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M9 18l6-6-6-6\" />\n </svg>\n);\n\nconst XIcon = () => (\n <svg\n width=\"18\"\n height=\"18\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" />\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" />\n </svg>\n);\n\nexport const OnboardingOverlay: React.FC = () => {\n const { config, currentStep, nextStep, prevStep, finish, isFirstStep, isLastStep } =\n useOnboarding();\n const [coords, setCoords] = useState<{\n top: number;\n left: number;\n width: number;\n height: number;\n } | null>(null);\n const [position, setPosition] = useState<{ top: number; left: number }>({ top: 0, left: 0 });\n const [dragOffset, setDragOffset] = useState<{ x: number; y: number }>({ x: 0, y: 0 });\n const isDragging = useRef(false);\n const dragStart = useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n const tooltipRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setDragOffset({ x: 0, y: 0 });\n }, [currentStep]);\n\n const handlePointerUpRef = useRef<() => void>(() => {});\n\n const handlePointerMove = useCallback((e: PointerEvent) => {\n if (!isDragging.current) return;\n\n const newX = e.clientX - dragStart.current.x;\n const newY = e.clientY - dragStart.current.y;\n\n setDragOffset({ x: newX, y: newY });\n }, []);\n\n const handlePointerUp = useCallback(() => {\n isDragging.current = false;\n\n if (tooltipRef.current) {\n tooltipRef.current.style.transition =\n 'top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)';\n tooltipRef.current.style.cursor = config.metadata.draggable ? 'grab' : 'auto';\n }\n\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUpRef.current);\n }, [config.metadata.draggable, handlePointerMove]);\n\n useEffect(() => {\n handlePointerUpRef.current = handlePointerUp;\n }, [handlePointerUp]);\n\n const handlePointerDown = (e: React.PointerEvent) => {\n if (!config.metadata.draggable) return;\n e.stopPropagation();\n e.preventDefault();\n isDragging.current = true;\n dragStart.current = { x: e.clientX - dragOffset.x, y: e.clientY - dragOffset.y };\n\n if (tooltipRef.current) {\n tooltipRef.current.style.transition = 'none';\n tooltipRef.current.style.cursor = 'grabbing';\n }\n\n window.addEventListener('pointermove', handlePointerMove);\n window.addEventListener('pointerup', handlePointerUp);\n };\n\n const calculateBestPosition = useCallback(\n (rect: {\n top: number;\n bottom: number;\n left: number;\n right: number;\n width: number;\n height: number;\n }) => {\n const tooltipWidth = 300;\n const tooltipHeight = 200;\n const gap = 12;\n const padding = 20;\n\n const spaceAbove = rect.top;\n const spaceBelow = window.innerHeight - rect.bottom;\n const spaceLeft = rect.left;\n const spaceRight = window.innerWidth - rect.right;\n\n let top = 0;\n let left = 0;\n\n if (spaceBelow > tooltipHeight + gap + padding) {\n top = rect.bottom + gap;\n left = Math.max(\n padding,\n Math.min(\n window.innerWidth - tooltipWidth - padding,\n rect.left + rect.width / 2 - tooltipWidth / 2,\n ),\n );\n } else if (spaceAbove > tooltipHeight + gap + padding) {\n top = rect.top - tooltipHeight - gap;\n left = Math.max(\n padding,\n Math.min(\n window.innerWidth - tooltipWidth - padding,\n rect.left + rect.width / 2 - tooltipWidth / 2,\n ),\n );\n } else if (spaceRight > tooltipWidth + gap + padding) {\n top = Math.max(\n padding,\n Math.min(\n window.innerHeight - tooltipHeight - padding,\n rect.top + rect.height / 2 - tooltipHeight / 2,\n ),\n );\n left = rect.right + gap;\n } else if (spaceLeft > tooltipWidth + gap + padding) {\n top = Math.max(\n padding,\n Math.min(\n window.innerHeight - tooltipHeight - padding,\n rect.top + rect.height / 2 - tooltipHeight / 2,\n ),\n );\n left = rect.left - tooltipWidth - gap;\n } else {\n top = window.innerHeight / 2 - tooltipHeight / 2;\n left = window.innerWidth / 2 - tooltipWidth / 2;\n }\n\n return { top: top + window.scrollY, left: left + window.scrollX };\n },\n [],\n );\n\n const updateCoords = useCallback(() => {\n if (!currentStep) return;\n\n const element = document.querySelector(\n `[data-onboarding-id=\"${currentStep.attribute}\"]`,\n ) as HTMLElement;\n if (element) {\n const rect = element.getBoundingClientRect();\n const padding = config.style?.padding || 0;\n\n const paddedRect = {\n top: rect.top - padding,\n bottom: rect.bottom + padding,\n left: rect.left - padding,\n right: rect.right + padding,\n width: rect.width + padding * 2,\n height: rect.height + padding * 2,\n };\n\n const newCoords = {\n top: paddedRect.top + window.scrollY,\n left: paddedRect.left + window.scrollX,\n width: paddedRect.width,\n height: paddedRect.height,\n };\n\n const newPosition = calculateBestPosition(paddedRect);\n\n setCoords((prev) => {\n if (\n prev &&\n prev.top === newCoords.top &&\n prev.left === newCoords.left &&\n prev.width === newCoords.width &&\n prev.height === newCoords.height\n ) {\n return prev;\n }\n return newCoords;\n });\n\n setPosition((prev) => {\n if (prev.top === newPosition.top && prev.left === newPosition.left) {\n return prev;\n }\n return newPosition;\n });\n } else {\n setCoords(null);\n }\n }, [currentStep, calculateBestPosition, config.style]);\n\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n updateCoords();\n window.addEventListener('resize', updateCoords);\n window.addEventListener('scroll', updateCoords);\n\n const observer = new MutationObserver(updateCoords);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true });\n\n let resizeObserver: ResizeObserver | null = null;\n if (typeof ResizeObserver !== 'undefined') {\n resizeObserver = new ResizeObserver(updateCoords);\n resizeObserver.observe(document.body);\n\n const element = currentStep?.attribute\n ? document.querySelector(`[data-onboarding-id=\"${currentStep.attribute}\"]`)\n : null;\n if (element) {\n resizeObserver.observe(element);\n }\n }\n\n return () => {\n window.removeEventListener('resize', updateCoords);\n window.removeEventListener('scroll', updateCoords);\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUp);\n observer.disconnect();\n if (resizeObserver) resizeObserver.disconnect();\n };\n }, [updateCoords, currentStep?.attribute, handlePointerMove, handlePointerUp]);\n\n if (!currentStep || !coords) return null;\n\n const maskStyle = {\n ...config.style?.background,\n transition: 'all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)',\n };\n\n const stopPropagation = (e: React.PointerEvent | React.MouseEvent) => {\n e.stopPropagation();\n };\n\n const overlayContent = (\n <div className=\"onboard-overlay-container\">\n <div\n style={{ height: coords.top, ...maskStyle }}\n className=\"onboard-overlay-mask onboard-mask-top\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{\n top: coords.top + coords.height,\n height: `calc(100vh - ${coords.top + coords.height}px)`,\n ...maskStyle,\n }}\n className=\"onboard-overlay-mask onboard-mask-bottom\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{ top: coords.top, height: coords.height, width: coords.left, ...maskStyle }}\n className=\"onboard-overlay-mask onboard-mask-left\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{\n top: coords.top,\n height: coords.height,\n left: coords.left + coords.width,\n width: `calc(100% - ${coords.left + coords.width}px)`,\n ...maskStyle,\n }}\n className=\"onboard-overlay-mask\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n\n <div\n ref={tooltipRef}\n className=\"onboard-tooltip\"\n onPointerDown={handlePointerDown}\n style={{\n zIndex: 1000000,\n ...config.style?.container,\n top: position.top + dragOffset.y,\n left: position.left + dragOffset.x,\n transition:\n 'top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)',\n cursor: config.metadata.draggable ? 'grab' : 'auto',\n touchAction: 'none',\n }}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n >\n <div className=\"onboard-tooltip-header\">\n <h3 className=\"onboard-tooltip-title\">{currentStep.title}</h3>\n <button\n onClick={(e) => {\n e.stopPropagation();\n finish();\n }}\n className=\"onboard-close-button\"\n >\n <XIcon />\n </button>\n </div>\n <p className=\"onboard-tooltip-description\">{currentStep.description}</p>\n\n <div className=\"onboard-tooltip-footer\">\n <button\n onClick={(e) => {\n e.stopPropagation();\n prevStep();\n }}\n disabled={isFirstStep}\n className=\"onboard-button-ghost\"\n style={{\n background: 'none',\n border: 'none',\n cursor: isFirstStep ? 'not-allowed' : 'pointer',\n ...config.style?.prev,\n }}\n >\n <ChevronLeftIcon />\n Prev\n </button>\n\n {isLastStep ? (\n <button\n onClick={(e) => {\n e.stopPropagation();\n nextStep();\n }}\n className=\"onboard-button-primary\"\n style={{ border: 'none', cursor: 'pointer', ...config.style?.finish }}\n >\n Finish\n </button>\n ) : (\n <button\n onClick={(e) => {\n e.stopPropagation();\n nextStep();\n }}\n className=\"onboard-button-primary\"\n style={{\n border: 'none',\n cursor: 'pointer',\n ...(isFirstStep ? config.style?.start : {}),\n ...(!isFirstStep ? config.style?.next : {}),\n }}\n >\n {isFirstStep && config.style?.start ? 'Start' : 'Next'}\n {!(isFirstStep && config.style?.start) && <ChevronRightIcon />}\n </button>\n )}\n </div>\n </div>\n </div>\n );\n\n return typeof document !== 'undefined' ? createPortal(overlayContent, document.body) : null;\n};\n"],"mappings":";olBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,wBAAAE,GAAA,kBAAAC,IAAA,eAAAC,GAAAJ,ICEA,IAAAK,EAQO,iBACPC,EAAoB,yBCTpB,IAAAC,EAAgE,iBAChEC,EAA6B,qBAczB,IAAAC,EAAA,6BAXEC,GAAkB,OACtB,OAAC,OACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,OAAO,eACP,YAAY,IACZ,cAAc,QACd,eAAe,QAEf,mBAAC,QAAK,EAAE,kBAAkB,EAC5B,EAGIC,GAAmB,OACvB,OAAC,OACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,OAAO,eACP,YAAY,IACZ,cAAc,QACd,eAAe,QAEf,mBAAC,QAAK,EAAE,gBAAgB,EAC1B,EAGIC,GAAQ,OACZ,QAAC,OACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,OAAO,eACP,YAAY,IACZ,cAAc,QACd,eAAe,QAEf,oBAAC,QAAK,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,KACpC,OAAC,QAAK,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,GACtC,EAGWC,EAA8B,IAAM,CAC/C,GAAM,CAAE,OAAAC,EAAQ,YAAAC,EAAa,SAAAC,EAAU,SAAAC,EAAU,OAAAC,EAAQ,YAAAC,EAAa,WAAAC,CAAW,EAC/EC,EAAc,EACV,CAACC,EAAQC,CAAS,KAAI,YAKlB,IAAI,EACR,CAACC,EAAUC,CAA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ACA,MAAAM,EACA,SAAAqD,EACA,SAAAc,EACA,OAAAK,EACA,SAAAC,EACA,YAAA3B,EACA,YAAAG,EACA,WAAAC,CACF,EAEA,OAAKpD,KAGH,QAACX,EAAkB,SAAlB,CAA2B,MAAOuF,EAChC,UAAA7E,EACAG,EAAM,aAAY,OAAC2E,EAAA,EAAkB,GACxC,KANqB,mBAAG,SAAA9E,EAAS,CAQrC,EAEa+E,EAAgB,IAAM,CACjC,IAAMC,KAAU,cAAW1F,CAAiB,EAC5C,GAAI0F,IAAY,OACd,MAAM,IAAI,MAAM,yDAAyD,EAC3E,OAAOA,CACT","names":["index_exports","__export","OnboardingProvider","useOnboarding","__toCommonJS","import_react","import_js_cookie","import_react","import_react_dom","import_jsx_runtime","ChevronLeftIcon","ChevronRightIcon","XIcon","OnboardingOverlay","config","currentStep","nextStep","prevStep","finish","isFirstStep","isLastStep","useOnboarding","coords","setCoords","position","setPosition","dragOffset","setDragOffset","isDragging","dragStart","tooltipRef","handlePointerUpRef","handlePointerMove","e","newX","newY","handlePointerUp","handlePointerDown","calculateBestPosition","rect","spaceAbove","spaceBelow","spaceLeft","spaceRight","top","left","updateCoords","element","padding","paddedRect","newCoords","newPosition","prev","observer","resizeObserver","maskStyle","stopPropagation","overlayContent","import_jsx_runtime","OnboardingContext","COOKIE_NAME","getInitialState","saved","Cookies","parsed","OnboardingProvider","config","ssr","onNavigate","children","isMounted","setIsMounted","state","setState","currentPath","setCurrentPath","isTransitioning","setIsTransitioning","configRef","onNavigateRef","lastSimulatedKey","lastPathForSimulation","wasInternalAction","handlePathChange","newPath","originalPushState","originalReplaceState","args","interval","handleNavigation","link","isMatch","step","path","match","pattern","simulateClicks","stepIndex","subStepIndex","currentConfig","actions","collectStepClicks","upToSubStep","limit","i","performClick","index","attr","element","isInOrder","prev","nextState","changed","firstUnfinishedIndex","_","matchedIndex","simKey","internal","currentStep","isUrlMatch","subStep","isFirstStep","isLastStep","totalSteps","hasSubSteps","nextStep","currentStepIndex","currentSubStepIndex","completedSteps","stepObj","currentActiveStep","navTo","nextSubIndex","nextSubStep","stepIndexToComplete","nextIndex","nextStepObj","targetSubStepIndex","targetSubStep","prevStep","prevIndex","prevStepObj","prevSubStepIndex","prevSubStep","finish","goToStep","value","OnboardingOverlay","useOnboarding","context"]}
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- "use client";import{createContext as it,useContext as st,useEffect as B,useState as U,useCallback as N,useMemo as J,useRef as _}from"react";import K from"js-cookie";import{useState as D,useEffect as X,useCallback as $,useRef as T}from"react";import{createPortal as et}from"react-dom";import{jsx as u,jsxs as w}from"react/jsx-runtime";var nt=()=>u("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:u("path",{d:"M15 18l-6-6 6-6"})}),ot=()=>u("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:u("path",{d:"M9 18l6-6-6-6"})}),rt=()=>w("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[u("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),u("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),Y=()=>{let{config:i,currentStep:c,nextStep:L,prevStep:A,finish:y,isFirstStep:S,isLastStep:n}=q(),[o,f]=D(null),[I,m]=D({top:0,left:0}),[k,H]=D({x:0,y:0}),R=T(!1),E=T({x:0,y:0}),h=T(null),[j,F]=D(c);c!==j&&(F(c),H({x:0,y:0}));let W=T(()=>{}),v=$(e=>{if(!R.current)return;let p=e.clientX-E.current.x,b=e.clientY-E.current.y;H({x:p,y:b})},[]),t=$(()=>{R.current=!1,h.current&&(h.current.style.transition="top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)",h.current.style.cursor=i.metadata.draggable?"grab":"auto"),window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",W.current)},[i.metadata.draggable,v]);X(()=>{W.current=t},[t]);let s=e=>{i.metadata.draggable&&(e.stopPropagation(),e.preventDefault(),R.current=!0,E.current={x:e.clientX-k.x,y:e.clientY-k.y},h.current&&(h.current.style.transition="none",h.current.style.cursor="grabbing"),window.addEventListener("pointermove",v),window.addEventListener("pointerup",t))},d=$(e=>{let z=e.top,g=window.innerHeight-e.bottom,Z=e.left,tt=window.innerWidth-e.right,M=0,P=0;return g>232?(M=e.bottom+12,P=Math.max(20,Math.min(window.innerWidth-300-20,e.left+e.width/2-300/2))):z>232?(M=e.top-200-12,P=Math.max(20,Math.min(window.innerWidth-300-20,e.left+e.width/2-300/2))):tt>332?(M=Math.max(20,Math.min(window.innerHeight-200-20,e.top+e.height/2-200/2)),P=e.right+12):Z>332?(M=Math.max(20,Math.min(window.innerHeight-200-20,e.top+e.height/2-200/2)),P=e.left-300-12):(M=window.innerHeight/2-200/2,P=window.innerWidth/2-300/2),{top:M+window.scrollY,left:P+window.scrollX}},[]),a=$(()=>{if(!c)return;let e=document.querySelector(`[data-onboarding-id="${c.attribute}"]`);if(e){let p=e.getBoundingClientRect(),b=i.style?.padding||0,O={top:p.top-b,bottom:p.bottom+b,left:p.left-b,right:p.right+b,width:p.width+b*2,height:p.height+b*2},C={top:O.top+window.scrollY,left:O.left+window.scrollX,width:O.width,height:O.height},z=d(O);f(g=>g&&g.top===C.top&&g.left===C.left&&g.width===C.width&&g.height===C.height?g:C),m(g=>g.top===z.top&&g.left===z.left?g:z)}else f(null)},[c,d,i.style]);if(X(()=>{a(),window.addEventListener("resize",a),window.addEventListener("scroll",a);let e=new MutationObserver(a);e.observe(document.body,{childList:!0,subtree:!0,attributes:!0});let p=null;if(typeof ResizeObserver<"u"){p=new ResizeObserver(a),p.observe(document.body);let b=c?.attribute?document.querySelector(`[data-onboarding-id="${c.attribute}"]`):null;b&&p.observe(b)}return()=>{window.removeEventListener("resize",a),window.removeEventListener("scroll",a),window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",t),e.disconnect(),p&&p.disconnect()}},[a,c?.attribute,v,t]),!c||!o)return null;let r={...i.style?.background,transition:"all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)"},l=e=>{e.stopPropagation()},x=w("div",{className:"onboard-overlay-container",children:[u("div",{style:{height:o.top,...r},className:"onboard-overlay-mask onboard-mask-top",onPointerDown:l,onMouseDown:l,onClick:l}),u("div",{style:{top:o.top+o.height,height:`calc(100vh - ${o.top+o.height}px)`,...r},className:"onboard-overlay-mask onboard-mask-bottom",onPointerDown:l,onMouseDown:l,onClick:l}),u("div",{style:{top:o.top,height:o.height,width:o.left,...r},className:"onboard-overlay-mask onboard-mask-left",onPointerDown:l,onMouseDown:l,onClick:l}),u("div",{style:{top:o.top,height:o.height,left:o.left+o.width,width:`calc(100% - ${o.left+o.width}px)`,...r},className:"onboard-overlay-mask",onPointerDown:l,onMouseDown:l,onClick:l}),w("div",{ref:h,className:"onboard-tooltip",onPointerDown:s,style:{zIndex:1e6,...i.style?.container,top:I.top+k.y,left:I.left+k.x,transition:"top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)",cursor:i.metadata.draggable?"grab":"auto",touchAction:"none"},onMouseDown:l,onClick:l,children:[w("div",{className:"onboard-tooltip-header",children:[u("h3",{className:"onboard-tooltip-title",children:c.title}),u("button",{onClick:e=>{e.stopPropagation(),y()},className:"onboard-close-button",children:u(rt,{})})]}),u("p",{className:"onboard-tooltip-description",children:c.description}),w("div",{className:"onboard-tooltip-footer",children:[w("button",{onClick:e=>{e.stopPropagation(),A()},disabled:S,className:"onboard-button-ghost",style:{background:"none",border:"none",cursor:S?"not-allowed":"pointer",...i.style?.prev},children:[u(nt,{}),"Prev"]}),n?u("button",{onClick:e=>{e.stopPropagation(),y()},className:"onboard-button-primary",style:{border:"none",cursor:"pointer",...i.style?.finish},children:"Finish"}):w("button",{onClick:e=>{e.stopPropagation(),L()},className:"onboard-button-primary",style:{border:"none",cursor:"pointer",...S?i.style?.start:{},...S?{}:i.style?.next},children:[S&&i.style?.start?"Start":"Next",!(S&&i.style?.start)&&u(ot,{})]})]})]})]});return typeof document<"u"?et(x,document.body):null};import{Fragment as at,jsx as Q,jsxs as dt}from"react/jsx-runtime";var V=it(void 0),G="onboarding_state",wt=({config:i,ssr:c=!1,onNavigate:L,children:A})=>{let[y,S]=U(!c),[n,o]=U({currentStepIndex:0,currentSubStepIndex:null,isActive:!0}),f=_(i),I=_(L);B(()=>{f.current=i,I.current=L},[i,L]);let m=N(t=>{t&&(I.current?I.current(t):window.location.href=t)},[]),k=(t,s)=>{if(t.urlMatch instanceof RegExp)return t.urlMatch.test(s);if(typeof t.urlMatch=="string"&&t.urlMatch.includes("*")){let d=t.urlMatch.replace(/[.+?^${}()|[\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(`^${d}$`).test(s)}return s===t.urlMatch};B(()=>{c&&S(!0);let t=f.current,s=window.location.pathname,d=-1;t.metadata.inOrder===!1&&(d=t.steps.findIndex(r=>k(r,s)));let a=K.get(G);if(a)try{let r=JSON.parse(a);if(t.metadata.inOrder===!1)d!==-1?r.currentStepIndex===d?o(r):o({currentStepIndex:d,currentSubStepIndex:null,isActive:!0}):o({...r,isActive:!1});else if(o(r),t.metadata.inOrder!==!1){let l=t.steps[r.currentStepIndex];if(l&&r.isActive){let x;if(r.currentStepIndex>0){let e=t.steps[r.currentStepIndex-1];e.navigate&&(x=e.navigate)}!x&&typeof l.urlMatch=="string"&&(x=l.urlMatch),x&&window.location.pathname!==x&&m(x),t.metadata.simulateClicksOnNavigate&&r.currentSubStepIndex!==null&&l.click&&setTimeout(()=>{let e=document.querySelector(`[data-onboarding-id="${l.attribute}"]`);e&&e.click()},500)}}}catch(r){console.error("Failed to parse onboarding state from cookie",r),d!==-1&&o({currentStepIndex:d,currentSubStepIndex:null,isActive:!0})}else if(d!==-1)o({currentStepIndex:d,currentSubStepIndex:null,isActive:!0});else if(t.metadata.inOrder===!1)o(r=>({...r,isActive:!1}));else{let r=t.steps[0];r&&typeof r.urlMatch=="string"&&window.location.pathname!==r.urlMatch&&m(r.urlMatch)}},[c,m]),B(()=>{y&&K.set(G,JSON.stringify(n),{expires:365})},[n,y]);let H=J(()=>{let t=i.steps[n.currentStepIndex];return t?n.currentSubStepIndex!==null&&t.subSteps&&t.subSteps[n.currentSubStepIndex]||t:null},[i.steps,n.currentStepIndex,n.currentSubStepIndex]),R=n.currentStepIndex===0&&n.currentSubStepIndex===null,E=J(()=>{let t=i.steps.length,s=n.currentStepIndex===t-1,d=i.steps[n.currentStepIndex],a=d?.subSteps&&d.subSteps.length>0;return s?a?n.currentSubStepIndex===d.subSteps.length-1:!0:!1},[i.steps,n.currentStepIndex,n.currentSubStepIndex]),h=N(()=>{let t=f.current,s=t.steps[n.currentStepIndex],d=n.currentSubStepIndex!==null&&s.subSteps?s.subSteps[n.currentSubStepIndex]:s;if(d.click){let a=document.querySelector(`[data-onboarding-id="${d.attribute}"]`);a&&a.click()}if(s.subSteps&&(n.currentSubStepIndex===null||n.currentSubStepIndex<s.subSteps.length-1)){let a=n.currentSubStepIndex===null?0:n.currentSubStepIndex+1,r=s.subSteps[a];o(l=>({...l,currentSubStepIndex:a})),r.navigate&&m(r.navigate);return}if(n.currentStepIndex<t.steps.length-1){let a=n.currentStepIndex+1,r=t.steps[a];o({currentStepIndex:a,currentSubStepIndex:null,isActive:!0}),r.navigate&&m(r.navigate)}else o(a=>({...a,isActive:!1})),t.onOnboardingComplete&&t.onOnboardingComplete()},[n.currentStepIndex,n.currentSubStepIndex,m]),j=N(()=>{let t=f.current;if(n.currentSubStepIndex!==null&&n.currentSubStepIndex>0){o(s=>({...s,currentSubStepIndex:s.currentSubStepIndex-1}));return}if(n.currentStepIndex>0&&n.currentSubStepIndex===0){o(s=>({...s,currentSubStepIndex:null}));return}if(n.currentStepIndex>0){let s=n.currentStepIndex-1,d=t.steps[s],a=d.subSteps?d.subSteps.length-1:null;o({currentStepIndex:s,currentSubStepIndex:a,isActive:!0})}},[n.currentStepIndex,n.currentSubStepIndex]),F=N(()=>{o(t=>({...t,isActive:!1})),f.current.onOnboardingComplete&&f.current.onOnboardingComplete()},[]),W=N((t,s=null)=>{o({currentStepIndex:t,currentSubStepIndex:s,isActive:!0})},[]),v={config:i,state:n,nextStep:h,prevStep:j,finish:F,goToStep:W,currentStep:H,isFirstStep:R,isLastStep:E};return y?dt(V.Provider,{value:v,children:[A,n.isActive&&Q(Y,{})]}):Q(at,{children:A})},q=()=>{let i=st(V);if(i===void 0)throw new Error("useOnboarding must be used within an OnboardingProvider");return i};export{wt as OnboardingProvider,q as useOnboarding};
2
+ "use client";import{createContext as lt,useContext as ct,useEffect as W,useState as U,useCallback as z,useMemo as et,useRef as D}from"react";import T from"js-cookie";import{useState as Q,useEffect as V,useCallback as Y,useRef as q}from"react";import{createPortal as it}from"react-dom";import{jsx as h,jsxs as R}from"react/jsx-runtime";var st=()=>h("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:h("path",{d:"M15 18l-6-6 6-6"})}),at=()=>h("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:h("path",{d:"M9 18l6-6-6-6"})}),ut=()=>R("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[h("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),h("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),Z=()=>{let{config:l,currentStep:d,nextStep:H,prevStep:j,finish:k,isFirstStep:M,isLastStep:c}=tt(),[p,b]=Q(null),[B,F]=Q({top:0,left:0}),[E,y]=Q({x:0,y:0}),N=q(!1),C=q({x:0,y:0}),I=q(null);V(()=>{y({x:0,y:0})},[d]);let L=q(()=>{}),w=Y(r=>{if(!N.current)return;let f=r.clientX-C.current.x,v=r.clientY-C.current.y;y({x:f,y:v})},[]),x=Y(()=>{N.current=!1,I.current&&(I.current.style.transition="top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)",I.current.style.cursor=l.metadata.draggable?"grab":"auto"),window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",L.current)},[l.metadata.draggable,w]);V(()=>{L.current=x},[x]);let X=r=>{l.metadata.draggable&&(r.stopPropagation(),r.preventDefault(),N.current=!0,C.current={x:r.clientX-E.x,y:r.clientY-E.y},I.current&&(I.current.style.transition="none",I.current.style.cursor="grabbing"),window.addEventListener("pointermove",w),window.addEventListener("pointerup",x))},J=Y(r=>{let o=r.top,n=window.innerHeight-r.bottom,s=r.left,a=window.innerWidth-r.right,u=0,i=0;return n>232?(u=r.bottom+12,i=Math.max(20,Math.min(window.innerWidth-300-20,r.left+r.width/2-300/2))):o>232?(u=r.top-200-12,i=Math.max(20,Math.min(window.innerWidth-300-20,r.left+r.width/2-300/2))):a>332?(u=Math.max(20,Math.min(window.innerHeight-200-20,r.top+r.height/2-200/2)),i=r.right+12):s>332?(u=Math.max(20,Math.min(window.innerHeight-200-20,r.top+r.height/2-200/2)),i=r.left-300-12):(u=window.innerHeight/2-200/2,i=window.innerWidth/2-300/2),{top:u+window.scrollY,left:i+window.scrollX}},[]),O=Y(()=>{if(!d)return;let r=document.querySelector(`[data-onboarding-id="${d.attribute}"]`);if(r){let f=r.getBoundingClientRect(),v=l.style?.padding||0,e={top:f.top-v,bottom:f.bottom+v,left:f.left-v,right:f.right+v,width:f.width+v*2,height:f.height+v*2},t={top:e.top+window.scrollY,left:e.left+window.scrollX,width:e.width,height:e.height},o=J(e);b(n=>n&&n.top===t.top&&n.left===t.left&&n.width===t.width&&n.height===t.height?n:t),F(n=>n.top===o.top&&n.left===o.left?n:o)}else b(null)},[d,J,l.style]);if(V(()=>{O(),window.addEventListener("resize",O),window.addEventListener("scroll",O);let r=new MutationObserver(O);r.observe(document.body,{childList:!0,subtree:!0,attributes:!0});let f=null;if(typeof ResizeObserver<"u"){f=new ResizeObserver(O),f.observe(document.body);let v=d?.attribute?document.querySelector(`[data-onboarding-id="${d.attribute}"]`):null;v&&f.observe(v)}return()=>{window.removeEventListener("resize",O),window.removeEventListener("scroll",O),window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",x),r.disconnect(),f&&f.disconnect()}},[O,d?.attribute,w,x]),!d||!p)return null;let A={...l.style?.background,transition:"all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)"},m=r=>{r.stopPropagation()},K=R("div",{className:"onboard-overlay-container",children:[h("div",{style:{height:p.top,...A},className:"onboard-overlay-mask onboard-mask-top",onPointerDown:m,onMouseDown:m,onClick:m}),h("div",{style:{top:p.top+p.height,height:`calc(100vh - ${p.top+p.height}px)`,...A},className:"onboard-overlay-mask onboard-mask-bottom",onPointerDown:m,onMouseDown:m,onClick:m}),h("div",{style:{top:p.top,height:p.height,width:p.left,...A},className:"onboard-overlay-mask onboard-mask-left",onPointerDown:m,onMouseDown:m,onClick:m}),h("div",{style:{top:p.top,height:p.height,left:p.left+p.width,width:`calc(100% - ${p.left+p.width}px)`,...A},className:"onboard-overlay-mask",onPointerDown:m,onMouseDown:m,onClick:m}),R("div",{ref:I,className:"onboard-tooltip",onPointerDown:X,style:{zIndex:1e6,...l.style?.container,top:B.top+E.y,left:B.left+E.x,transition:"top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)",cursor:l.metadata.draggable?"grab":"auto",touchAction:"none"},onMouseDown:m,onClick:m,children:[R("div",{className:"onboard-tooltip-header",children:[h("h3",{className:"onboard-tooltip-title",children:d.title}),h("button",{onClick:r=>{r.stopPropagation(),k()},className:"onboard-close-button",children:h(ut,{})})]}),h("p",{className:"onboard-tooltip-description",children:d.description}),R("div",{className:"onboard-tooltip-footer",children:[R("button",{onClick:r=>{r.stopPropagation(),j()},disabled:M,className:"onboard-button-ghost",style:{background:"none",border:"none",cursor:M?"not-allowed":"pointer",...l.style?.prev},children:[h(st,{}),"Prev"]}),c?h("button",{onClick:r=>{r.stopPropagation(),H()},className:"onboard-button-primary",style:{border:"none",cursor:"pointer",...l.style?.finish},children:"Finish"}):R("button",{onClick:r=>{r.stopPropagation(),H()},className:"onboard-button-primary",style:{border:"none",cursor:"pointer",...M?l.style?.start:{},...M?{}:l.style?.next},children:[M&&l.style?.start?"Start":"Next",!(M&&l.style?.start)&&h(at,{})]})]})]})]});return typeof document<"u"?it(K,document.body):null};import{Fragment as pt,jsx as nt,jsxs as bt}from"react/jsx-runtime";var ot=lt(void 0),$="onboarding_state",dt=()=>{if(typeof window<"u"){let l=T.get($);if(l)try{let d=JSON.parse(l);if(d&&typeof d=="object")return{currentStepIndex:d.currentStepIndex??0,currentSubStepIndex:d.currentSubStepIndex??null,isActive:d.isActive??!0,completedSteps:d.completedSteps??[],subStepProgress:d.subStepProgress??{}}}catch{}}return{currentStepIndex:0,currentSubStepIndex:null,isActive:!0,completedSteps:[],subStepProgress:{}}},kt=({config:l,ssr:d=!1,onNavigate:H,children:j})=>{let[k,M]=U(!d),[c,p]=U(dt),[b,B]=U(typeof window<"u"?window.location.pathname:""),[F,E]=U(!1),y=D(l),N=D(H),C=D(""),I=D(typeof window<"u"?window.location.pathname:""),L=D(!1);W(()=>{b!==I.current&&(I.current=b,C.current="")},[b]),W(()=>{y.current=l,N.current=H},[l,H]),W(()=>{if(typeof window>"u")return;let e=()=>{let s=window.location.pathname;B(s)};window.addEventListener("popstate",e);let t=window.history.pushState,o=window.history.replaceState;window.history.pushState=function(...s){t.apply(this,s),e()},window.history.replaceState=function(...s){o.apply(this,s),e()},window.addEventListener("locationchange",e);let n=setInterval(e,200);return()=>{window.removeEventListener("popstate",e),window.history.pushState=t,window.history.replaceState=o,window.removeEventListener("locationchange",e),clearInterval(n)}},[]);let w=z(e=>{e&&(N.current?N.current(e):window.location.href=e)},[]),x=z((e,t)=>{if(!e?.urlMatch||!t)return!1;let o=!1;if(e.urlMatch.includes("*")){let n=e.urlMatch.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\\\*/g,".*");o=new RegExp(`^${n}$`).test(t)}else o=t===e.urlMatch;return o},[]),X=z((e,t)=>{let o=y.current,n=[],s=window.location.pathname,a=(i,S=-1)=>{if(S!==null&&(i.click&&n.push(i.attribute),i.subSteps)){let g=S===-1?i.subSteps.length:S;for(let P=0;P<g;P++)i.subSteps[P].click&&n.push(i.subSteps[P].attribute)}};for(let i=0;i<=e;i++){let S=o.steps[i];x(S,s)&&(i<e?a(S):t!==null&&a(S,t))}if(n.length===0)return;let u=i=>{if(i>=n.length)return;let S=n[i],g=document.querySelector(`[data-onboarding-id="${S}"]`);g&&g.click(),setTimeout(()=>u(i+1),500)};setTimeout(()=>u(0),500)},[x,b]);W(()=>{if(d&&!k){M(!0);return}let e=y.current,t=e.metadata.inOrder!==!1;p(o=>{if(!o.isActive)return o;let n={...o},s=!1;if(t){let a=e.steps.findIndex((u,i)=>!o.completedSteps.includes(i));if(a!==-1){a!==o.currentStepIndex&&(n.currentStepIndex=a,n.currentSubStepIndex=o.subStepProgress[a]??null,s=!0);let u=e.steps[a];x(u,b)||u.urlBase&&b!==u.urlBase&&w(u.urlBase)}}else{let a=e.steps.findIndex((u,i)=>x(u,b)&&!o.completedSteps.includes(i));a!==-1&&a!==o.currentStepIndex&&(n.currentStepIndex=a,n.currentSubStepIndex=o.subStepProgress[a]??null,s=!0)}return s?n:o})},[d,k,b,w,x]),W(()=>{if(!c.isActive||!k)return;let e=y.current,t=e.steps[c.currentStepIndex],o=`${b}-${c.currentStepIndex}-${c.currentSubStepIndex}`;if(C.current===o)return;let n=L.current;if(L.current=!1,n&&b===I.current){C.current=o;return}t&&x(t,b)&&e.metadata.simulateClicksOnNavigate&&C.current!==o&&(C.current=o,I.current=b,X(c.currentStepIndex,c.currentSubStepIndex))},[c.currentStepIndex,c.currentSubStepIndex,c.isActive,b,k,x,X]),W(()=>{k&&T.set($,JSON.stringify(c),{expires:365})},[c,k]);let J=et(()=>{let e=l.steps[c.currentStepIndex];if(!e)return null;let t=x(e,b);if(c.currentSubStepIndex!==null&&e.subSteps){let o=e.subSteps[c.currentSubStepIndex];return t||F?o||e:null}return t?e:null},[l.steps,c.currentStepIndex,c.currentSubStepIndex,b,x,F]),O=c.currentStepIndex===0&&c.currentSubStepIndex===null,A=et(()=>{let e=l.steps.length,t=l.steps[c.currentStepIndex],o=t?.subSteps&&t.subSteps.length>0;return c.currentStepIndex===e-1?o?c.currentSubStepIndex===t.subSteps.length-1:!0:!1},[l.steps,c.currentStepIndex,c.currentSubStepIndex]),m=z(()=>{let e=y.current;L.current=!0,p(t=>{let{currentStepIndex:o,currentSubStepIndex:n,completedSteps:s}=t,a=e.steps[o];if(!a)return t;let u=n!==null&&a.subSteps?a.subSteps[n]:a;if(u.click){let g=document.querySelector(`[data-onboarding-id="${u.attribute}"]`);g&&g.click()}let i,S;if(a.subSteps&&(n===null||n<a.subSteps.length-1)){let g=n===null?0:n+1,P=a.subSteps[g];E(!0),setTimeout(()=>E(!1),1e3),S=u.navigate||P.navigate,!S&&n===null&&(S=a.navigate),i={...t,currentSubStepIndex:g,subStepProgress:{...t.subStepProgress,[o]:g}}}else{let g=o;if(o<e.steps.length-1){let P=o+1,_=e.steps[P],G=t.subStepProgress[P]??null,rt=G!==null&&_.subSteps?_.subSteps[G]:null;S=u.navigate||_.navigate||rt?.navigate,i={...t,currentStepIndex:P,currentSubStepIndex:G,completedSteps:s.includes(g)?s:[...s,g],subStepProgress:{...t.subStepProgress,[g]:n}}}else e.onOnboardingComplete&&e.onOnboardingComplete(),S=u.navigate||a.navigate,i={...t,isActive:!1,completedSteps:s.includes(g)?s:[...s,g],subStepProgress:{...t.subStepProgress,[g]:n}}}return T.set($,JSON.stringify(i),{expires:365}),S&&w(S),i})},[w]),K=z(()=>{let e=y.current;L.current=!0,p(t=>{let o,n;if(t.currentSubStepIndex!==null&&t.currentSubStepIndex>0){let s=t.currentSubStepIndex-1;n=e.steps[t.currentStepIndex].subSteps[s].navigate,o={...t,currentSubStepIndex:s,subStepProgress:{...t.subStepProgress,[t.currentStepIndex]:s}}}else if(t.currentStepIndex>0&&t.currentSubStepIndex===0)n=e.steps[t.currentStepIndex].navigate,o={...t,currentSubStepIndex:null,subStepProgress:{...t.subStepProgress,[t.currentStepIndex]:null}};else if(t.currentStepIndex>0){let s=t.currentStepIndex-1,a=e.steps[s],u=t.subStepProgress[s]??(a.subSteps?a.subSteps.length-1:null),i=u!==null&&a.subSteps?a.subSteps[u]:null;n=a.navigate||i?.navigate,o={...t,currentStepIndex:s,currentSubStepIndex:u,isActive:!0,subStepProgress:{...t.subStepProgress,[s]:u}}}else return t;return T.set($,JSON.stringify(o),{expires:365}),n&&w(n),o})},[w]),r=z(()=>{p(e=>({...e,isActive:!1})),y.current.onOnboardingComplete&&y.current.onOnboardingComplete()},[]),f=z((e,t=null)=>{let o=y.current;L.current=!0,p(n=>{let s=o.steps[e],a=t!==null&&s.subSteps?s.subSteps[t]:null,u=s.navigate||a?.navigate,i={...n,currentStepIndex:e,currentSubStepIndex:t,isActive:!0,subStepProgress:{...n.subStepProgress,[e]:t}};return T.set($,JSON.stringify(i),{expires:365}),u&&w(u),i})},[w]),v={config:l,state:c,nextStep:m,prevStep:K,finish:r,goToStep:f,currentStep:J,isFirstStep:O,isLastStep:A};return k?bt(ot.Provider,{value:v,children:[j,c.isActive&&nt(Z,{})]}):nt(pt,{children:j})},tt=()=>{let l=ct(ot);if(l===void 0)throw new Error("useOnboarding must be used within an OnboardingProvider");return l};export{kt as OnboardingProvider,tt as useOnboarding};
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/OnboardingProvider.tsx","../src/components/OnboardingOverlay.tsx"],"sourcesContent":["'use client';\n\nimport React, {\n createContext,\n useContext,\n useEffect,\n useState,\n useCallback,\n useMemo,\n useRef,\n} from 'react';\nimport Cookies from 'js-cookie';\nimport { OnboardingConfig, OnboardingState, OnboardingStep, OnboardingSubStep } from '../types';\nimport { OnboardingOverlay } from './OnboardingOverlay';\n\ninterface OnboardingContextType {\n config: OnboardingConfig;\n state: OnboardingState;\n nextStep: () => void;\n prevStep: () => void;\n finish: () => void;\n goToStep: (stepIndex: number, subStepIndex?: number | null) => void;\n currentStep: OnboardingStep | OnboardingSubStep | null;\n isFirstStep: boolean;\n isLastStep: boolean;\n}\n\nconst OnboardingContext = createContext<OnboardingContextType | undefined>(undefined);\n\nconst COOKIE_NAME = 'onboarding_state';\n\nexport const OnboardingProvider: React.FC<{\n config: OnboardingConfig;\n ssr?: boolean;\n onNavigate?: (url: string) => void;\n children: React.ReactNode;\n}> = ({ config, ssr = false, onNavigate, children }) => {\n const [isMounted, setIsMounted] = useState(!ssr);\n const [state, setState] = useState<OnboardingState>({\n currentStepIndex: 0,\n currentSubStepIndex: null,\n isActive: true,\n });\n\n const configRef = useRef(config);\n const onNavigateRef = useRef(onNavigate);\n\n useEffect(() => {\n configRef.current = config;\n onNavigateRef.current = onNavigate;\n }, [config, onNavigate]);\n\n const handleNavigation = useCallback((link?: string) => {\n if (!link) return;\n\n if (onNavigateRef.current) {\n onNavigateRef.current(link);\n } else {\n window.location.href = link;\n }\n }, []);\n\n const isMatch = (step: OnboardingStep, path: string) => {\n if (step.urlMatch instanceof RegExp) return step.urlMatch.test(path);\n\n if (typeof step.urlMatch === 'string' && step.urlMatch.includes('*')) {\n const pattern = step.urlMatch.replace(/[.+?^${}()|[\\\\]/g, '\\\\$&').replace(/\\*/g, '.*');\n return new RegExp(`^${pattern}$`).test(path);\n }\n\n return path === step.urlMatch;\n };\n\n useEffect(() => {\n if (ssr) {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setIsMounted(true);\n }\n\n const currentConfig = configRef.current;\n const currentPath = window.location.pathname;\n let matchedStepIndex = -1;\n\n if ((currentConfig.metadata.inOrder as boolean | undefined) === false) {\n matchedStepIndex = currentConfig.steps.findIndex((step) => isMatch(step, currentPath));\n }\n\n const savedState = Cookies.get(COOKIE_NAME);\n if (savedState) {\n try {\n const parsed: OnboardingState = JSON.parse(savedState);\n\n if ((currentConfig.metadata.inOrder as boolean | undefined) === false) {\n if (matchedStepIndex !== -1) {\n if (parsed.currentStepIndex === matchedStepIndex) {\n setState(parsed);\n } else {\n setState({\n currentStepIndex: matchedStepIndex,\n currentSubStepIndex: null,\n isActive: true,\n });\n }\n } else {\n setState({ ...parsed, isActive: false });\n }\n } else {\n setState(parsed);\n\n if ((currentConfig.metadata.inOrder as boolean | undefined) !== false) {\n const step = currentConfig.steps[parsed.currentStepIndex];\n if (step && parsed.isActive) {\n let targetUrl: string | undefined;\n\n if (parsed.currentStepIndex > 0) {\n const prevStep = currentConfig.steps[parsed.currentStepIndex - 1];\n if (prevStep.navigate) {\n targetUrl = prevStep.navigate;\n }\n }\n\n if (!targetUrl && typeof step.urlMatch === 'string') {\n targetUrl = step.urlMatch;\n }\n\n if (targetUrl && window.location.pathname !== targetUrl) {\n handleNavigation(targetUrl);\n }\n\n if (currentConfig.metadata.simulateClicksOnNavigate) {\n if (parsed.currentSubStepIndex !== null && step.click) {\n setTimeout(() => {\n const element = document.querySelector(\n `[data-onboarding-id=\"${step.attribute}\"]`,\n ) as HTMLElement;\n if (element) {\n element.click();\n }\n }, 500);\n }\n }\n }\n }\n }\n } catch (e) {\n console.error('Failed to parse onboarding state from cookie', e);\n if (matchedStepIndex !== -1) {\n setState({\n currentStepIndex: matchedStepIndex,\n currentSubStepIndex: null,\n isActive: true,\n });\n }\n }\n } else if (matchedStepIndex !== -1) {\n setState({\n currentStepIndex: matchedStepIndex,\n currentSubStepIndex: null,\n isActive: true,\n });\n } else if ((currentConfig.metadata.inOrder as boolean | undefined) === false) {\n setState((prev) => ({ ...prev, isActive: false }));\n } else {\n const step = currentConfig.steps[0];\n if (step && typeof step.urlMatch === 'string' && window.location.pathname !== step.urlMatch) {\n handleNavigation(step.urlMatch);\n }\n }\n }, [ssr, handleNavigation]);\n\n useEffect(() => {\n if (isMounted) {\n Cookies.set(COOKIE_NAME, JSON.stringify(state), { expires: 365 });\n }\n }, [state, isMounted]);\n\n const currentStep = useMemo(() => {\n const step = config.steps[state.currentStepIndex];\n if (!step) return null;\n if (state.currentSubStepIndex !== null && step.subSteps) {\n return step.subSteps[state.currentSubStepIndex] || step;\n }\n return step;\n }, [config.steps, state.currentStepIndex, state.currentSubStepIndex]);\n\n const isFirstStep = state.currentStepIndex === 0 && state.currentSubStepIndex === null;\n const isLastStep = useMemo(() => {\n const totalSteps = config.steps.length;\n const isLastMainStep = state.currentStepIndex === totalSteps - 1;\n const step = config.steps[state.currentStepIndex];\n const hasSubSteps = step?.subSteps && step.subSteps.length > 0;\n\n if (isLastMainStep) {\n if (hasSubSteps) {\n return state.currentSubStepIndex === step.subSteps!.length - 1;\n }\n return true;\n }\n return false;\n }, [config.steps, state.currentStepIndex, state.currentSubStepIndex]);\n\n const nextStep = useCallback(() => {\n const currentConfig = configRef.current;\n const stepObj = currentConfig.steps[state.currentStepIndex];\n const currentActiveStep =\n state.currentSubStepIndex !== null && stepObj.subSteps\n ? stepObj.subSteps[state.currentSubStepIndex]\n : stepObj;\n\n if (currentActiveStep.click) {\n const element = document.querySelector(\n `[data-onboarding-id=\"${currentActiveStep.attribute}\"]`,\n ) as HTMLElement;\n if (element) {\n element.click();\n }\n }\n\n if (\n stepObj.subSteps &&\n (state.currentSubStepIndex === null ||\n state.currentSubStepIndex < stepObj.subSteps.length - 1)\n ) {\n const nextSubIndex = state.currentSubStepIndex === null ? 0 : state.currentSubStepIndex + 1;\n const nextSubStep = stepObj.subSteps[nextSubIndex];\n setState((prev) => ({ ...prev, currentSubStepIndex: nextSubIndex }));\n\n if (nextSubStep.navigate) handleNavigation(nextSubStep.navigate);\n return;\n }\n\n if (state.currentStepIndex < currentConfig.steps.length - 1) {\n const nextIndex = state.currentStepIndex + 1;\n const nextStepObj = currentConfig.steps[nextIndex];\n setState({\n currentStepIndex: nextIndex,\n currentSubStepIndex: null,\n isActive: true,\n });\n\n if (nextStepObj.navigate) handleNavigation(nextStepObj.navigate);\n } else {\n setState((prev) => ({ ...prev, isActive: false }));\n if (currentConfig.onOnboardingComplete) {\n currentConfig.onOnboardingComplete();\n }\n }\n }, [state.currentStepIndex, state.currentSubStepIndex, handleNavigation]);\n\n const prevStep = useCallback(() => {\n const currentConfig = configRef.current;\n\n if (state.currentSubStepIndex !== null && state.currentSubStepIndex > 0) {\n setState((prev) => ({ ...prev, currentSubStepIndex: prev.currentSubStepIndex! - 1 }));\n return;\n }\n\n if (state.currentStepIndex > 0 && state.currentSubStepIndex === 0) {\n setState((prev) => ({ ...prev, currentSubStepIndex: null }));\n return;\n }\n\n if (state.currentStepIndex > 0) {\n const prevIndex = state.currentStepIndex - 1;\n const prevStepObj = currentConfig.steps[prevIndex];\n const prevSubStepIndex = prevStepObj.subSteps ? prevStepObj.subSteps.length - 1 : null;\n\n setState({\n currentStepIndex: prevIndex,\n currentSubStepIndex: prevSubStepIndex,\n isActive: true,\n });\n }\n }, [state.currentStepIndex, state.currentSubStepIndex]);\n\n const finish = useCallback(() => {\n setState((prev) => ({ ...prev, isActive: false }));\n if (configRef.current.onOnboardingComplete) {\n configRef.current.onOnboardingComplete();\n }\n }, []);\n\n const goToStep = useCallback((stepIndex: number, subStepIndex: number | null = null) => {\n setState({\n currentStepIndex: stepIndex,\n currentSubStepIndex: subStepIndex,\n isActive: true,\n });\n }, []);\n\n const value = {\n config,\n state,\n nextStep,\n prevStep,\n finish,\n goToStep,\n currentStep,\n isFirstStep,\n isLastStep,\n };\n\n if (!isMounted) return <>{children}</>;\n\n return (\n <OnboardingContext.Provider value={value}>\n {children}\n {state.isActive && <OnboardingOverlay />}\n </OnboardingContext.Provider>\n );\n};\n\nexport const useOnboarding = () => {\n const context = useContext(OnboardingContext);\n if (context === undefined) {\n throw new Error('useOnboarding must be used within an OnboardingProvider');\n }\n return context;\n};\n","'use client';\n\nimport React, { useState, useEffect, useCallback, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport { useOnboarding } from './OnboardingProvider';\n\nconst ChevronLeftIcon = () => (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M15 18l-6-6 6-6\" />\n </svg>\n);\n\nconst ChevronRightIcon = () => (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M9 18l6-6-6-6\" />\n </svg>\n);\n\nconst XIcon = () => (\n <svg\n width=\"18\"\n height=\"18\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" />\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" />\n </svg>\n);\n\nexport const OnboardingOverlay: React.FC = () => {\n const { config, currentStep, nextStep, prevStep, finish, isFirstStep, isLastStep } =\n useOnboarding();\n const [coords, setCoords] = useState<{\n top: number;\n left: number;\n width: number;\n height: number;\n } | null>(null);\n const [position, setPosition] = useState<{ top: number; left: number }>({ top: 0, left: 0 });\n const [dragOffset, setDragOffset] = useState<{ x: number; y: number }>({ x: 0, y: 0 });\n const isDragging = useRef(false);\n const dragStart = useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n const tooltipRef = useRef<HTMLDivElement>(null);\n\n // Reset drag offset when step changes\n const [prevStepRef, setPrevStepRef] = useState(currentStep);\n if (currentStep !== prevStepRef) {\n setPrevStepRef(currentStep);\n setDragOffset({ x: 0, y: 0 });\n }\n\n const handlePointerUpRef = useRef<() => void>(() => {});\n\n const handlePointerMove = useCallback((e: PointerEvent) => {\n if (!isDragging.current) return;\n\n const newX = e.clientX - dragStart.current.x;\n const newY = e.clientY - dragStart.current.y;\n\n setDragOffset({ x: newX, y: newY });\n }, []);\n\n const handlePointerUp = useCallback(() => {\n isDragging.current = false;\n\n if (tooltipRef.current) {\n tooltipRef.current.style.transition =\n 'top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)';\n tooltipRef.current.style.cursor = config.metadata.draggable ? 'grab' : 'auto';\n }\n\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUpRef.current);\n }, [config.metadata.draggable, handlePointerMove]);\n\n useEffect(() => {\n handlePointerUpRef.current = handlePointerUp;\n }, [handlePointerUp]);\n\n const handlePointerDown = (e: React.PointerEvent) => {\n if (!config.metadata.draggable) return;\n e.stopPropagation();\n e.preventDefault();\n isDragging.current = true;\n dragStart.current = { x: e.clientX - dragOffset.x, y: e.clientY - dragOffset.y };\n\n if (tooltipRef.current) {\n tooltipRef.current.style.transition = 'none';\n tooltipRef.current.style.cursor = 'grabbing';\n }\n\n window.addEventListener('pointermove', handlePointerMove);\n window.addEventListener('pointerup', handlePointerUp);\n };\n\n const calculateBestPosition = useCallback(\n (rect: {\n top: number;\n bottom: number;\n left: number;\n right: number;\n width: number;\n height: number;\n }) => {\n const tooltipWidth = 300;\n const tooltipHeight = 200;\n const gap = 12;\n const padding = 20;\n\n const spaceAbove = rect.top;\n const spaceBelow = window.innerHeight - rect.bottom;\n const spaceLeft = rect.left;\n const spaceRight = window.innerWidth - rect.right;\n\n let top = 0;\n let left = 0;\n\n if (spaceBelow > tooltipHeight + gap + padding) {\n top = rect.bottom + gap;\n left = Math.max(\n padding,\n Math.min(\n window.innerWidth - tooltipWidth - padding,\n rect.left + rect.width / 2 - tooltipWidth / 2,\n ),\n );\n } else if (spaceAbove > tooltipHeight + gap + padding) {\n top = rect.top - tooltipHeight - gap;\n left = Math.max(\n padding,\n Math.min(\n window.innerWidth - tooltipWidth - padding,\n rect.left + rect.width / 2 - tooltipWidth / 2,\n ),\n );\n } else if (spaceRight > tooltipWidth + gap + padding) {\n top = Math.max(\n padding,\n Math.min(\n window.innerHeight - tooltipHeight - padding,\n rect.top + rect.height / 2 - tooltipHeight / 2,\n ),\n );\n left = rect.right + gap;\n } else if (spaceLeft > tooltipWidth + gap + padding) {\n top = Math.max(\n padding,\n Math.min(\n window.innerHeight - tooltipHeight - padding,\n rect.top + rect.height / 2 - tooltipHeight / 2,\n ),\n );\n left = rect.left - tooltipWidth - gap;\n } else {\n top = window.innerHeight / 2 - tooltipHeight / 2;\n left = window.innerWidth / 2 - tooltipWidth / 2;\n }\n\n return { top: top + window.scrollY, left: left + window.scrollX };\n },\n [],\n );\n\n const updateCoords = useCallback(() => {\n if (!currentStep) return;\n\n const element = document.querySelector(\n `[data-onboarding-id=\"${currentStep.attribute}\"]`,\n ) as HTMLElement;\n if (element) {\n const rect = element.getBoundingClientRect();\n const padding = config.style?.padding || 0;\n\n const paddedRect = {\n top: rect.top - padding,\n bottom: rect.bottom + padding,\n left: rect.left - padding,\n right: rect.right + padding,\n width: rect.width + padding * 2,\n height: rect.height + padding * 2,\n };\n\n const newCoords = {\n top: paddedRect.top + window.scrollY,\n left: paddedRect.left + window.scrollX,\n width: paddedRect.width,\n height: paddedRect.height,\n };\n\n const newPosition = calculateBestPosition(paddedRect);\n\n setCoords((prev) => {\n if (\n prev &&\n prev.top === newCoords.top &&\n prev.left === newCoords.left &&\n prev.width === newCoords.width &&\n prev.height === newCoords.height\n ) {\n return prev;\n }\n return newCoords;\n });\n\n setPosition((prev) => {\n if (prev.top === newPosition.top && prev.left === newPosition.left) {\n return prev;\n }\n return newPosition;\n });\n } else {\n setCoords(null);\n }\n }, [currentStep, calculateBestPosition, config.style]);\n\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n updateCoords();\n window.addEventListener('resize', updateCoords);\n window.addEventListener('scroll', updateCoords);\n\n const observer = new MutationObserver(updateCoords);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true });\n\n let resizeObserver: ResizeObserver | null = null;\n if (typeof ResizeObserver !== 'undefined') {\n resizeObserver = new ResizeObserver(updateCoords);\n resizeObserver.observe(document.body);\n\n const element = currentStep?.attribute\n ? document.querySelector(`[data-onboarding-id=\"${currentStep.attribute}\"]`)\n : null;\n if (element) {\n resizeObserver.observe(element);\n }\n }\n\n return () => {\n window.removeEventListener('resize', updateCoords);\n window.removeEventListener('scroll', updateCoords);\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUp);\n observer.disconnect();\n if (resizeObserver) resizeObserver.disconnect();\n };\n }, [updateCoords, currentStep?.attribute, handlePointerMove, handlePointerUp]);\n\n if (!currentStep || !coords) return null;\n\n const maskStyle = {\n ...config.style?.background,\n transition: 'all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)',\n };\n\n const stopPropagation = (e: React.PointerEvent | React.MouseEvent) => {\n e.stopPropagation();\n };\n\n const overlayContent = (\n <div className=\"onboard-overlay-container\">\n <div\n style={{ height: coords.top, ...maskStyle }}\n className=\"onboard-overlay-mask onboard-mask-top\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{\n top: coords.top + coords.height,\n height: `calc(100vh - ${coords.top + coords.height}px)`,\n ...maskStyle,\n }}\n className=\"onboard-overlay-mask onboard-mask-bottom\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{ top: coords.top, height: coords.height, width: coords.left, ...maskStyle }}\n className=\"onboard-overlay-mask onboard-mask-left\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{\n top: coords.top,\n height: coords.height,\n left: coords.left + coords.width,\n width: `calc(100% - ${coords.left + coords.width}px)`,\n ...maskStyle,\n }}\n className=\"onboard-overlay-mask\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n\n <div\n ref={tooltipRef}\n className=\"onboard-tooltip\"\n onPointerDown={handlePointerDown}\n style={{\n zIndex: 1000000,\n ...config.style?.container,\n top: position.top + dragOffset.y,\n left: position.left + dragOffset.x,\n transition:\n 'top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)',\n cursor: config.metadata.draggable ? 'grab' : 'auto',\n touchAction: 'none',\n }}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n >\n <div className=\"onboard-tooltip-header\">\n <h3 className=\"onboard-tooltip-title\">{currentStep.title}</h3>\n <button\n onClick={(e) => {\n e.stopPropagation();\n finish();\n }}\n className=\"onboard-close-button\"\n >\n <XIcon />\n </button>\n </div>\n <p className=\"onboard-tooltip-description\">{currentStep.description}</p>\n\n <div className=\"onboard-tooltip-footer\">\n <button\n onClick={(e) => {\n e.stopPropagation();\n prevStep();\n }}\n disabled={isFirstStep}\n className=\"onboard-button-ghost\"\n style={{\n background: 'none',\n border: 'none',\n cursor: isFirstStep ? 'not-allowed' : 'pointer',\n ...config.style?.prev,\n }}\n >\n <ChevronLeftIcon />\n Prev\n </button>\n\n {isLastStep ? (\n <button\n onClick={(e) => {\n e.stopPropagation();\n finish();\n }}\n className=\"onboard-button-primary\"\n style={{ border: 'none', cursor: 'pointer', ...config.style?.finish }}\n >\n Finish\n </button>\n ) : (\n <button\n onClick={(e) => {\n e.stopPropagation();\n nextStep();\n }}\n className=\"onboard-button-primary\"\n style={{\n border: 'none',\n cursor: 'pointer',\n ...(isFirstStep ? config.style?.start : {}),\n ...(!isFirstStep ? config.style?.next : {}),\n }}\n >\n {isFirstStep && config.style?.start ? 'Start' : 'Next'}\n {!(isFirstStep && config.style?.start) && <ChevronRightIcon />}\n </button>\n )}\n </div>\n </div>\n </div>\n );\n\n return typeof document !== 'undefined' ? createPortal(overlayContent, document.body) : null;\n};\n"],"mappings":";aAEA,OACE,iBAAAA,GACA,cAAAC,GACA,aAAAC,EACA,YAAAC,EACA,eAAAC,EACA,WAAAC,EACA,UAAAC,MACK,QACP,OAAOC,MAAa,YCTpB,OAAgB,YAAAC,EAAU,aAAAC,EAAW,eAAAC,EAAa,UAAAC,MAAc,QAChE,OAAS,gBAAAC,OAAoB,YAczB,cAAAC,EAoBF,QAAAC,MApBE,oBAXJ,IAAMC,GAAkB,IACtBF,EAAC,OACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,OAAO,eACP,YAAY,IACZ,cAAc,QACd,eAAe,QAEf,SAAAA,EAAC,QAAK,EAAE,kBAAkB,EAC5B,EAGIG,GAAmB,IACvBH,EAAC,OACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,OAAO,eACP,YAAY,IACZ,cAAc,QACd,eAAe,QAEf,SAAAA,EAAC,QAAK,EAAE,gBAAgB,EAC1B,EAGII,GAAQ,IACZH,EAAC,OACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,OAAO,eACP,YAAY,IACZ,cAAc,QACd,eAAe,QAEf,UAAAD,EAAC,QAAK,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,EACpCA,EAAC,QAAK,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,GACtC,EAGWK,EAA8B,IAAM,CAC/C,GAAM,CAAE,OAAAC,EAAQ,YAAAC,EAAa,SAAAC,EAAU,SAAAC,EAAU,OAAAC,EAAQ,YAAAC,EAAa,WAAAC,CAAW,EAC/EC,EAAc,EACV,CAACC,EAAQC,CAAS,EAAIC,EAKlB,IAAI,EACR,CAACC,EAAUC,CAAW,EAAIF,EAAwC,CAAE,IAAK,EAAG,KAAM,CAAE,C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kBA,EAAM,mBAAmB,CAAC,EAEhDyC,EAASlC,EAAY,IAAM,CAC/BN,EAAUsB,IAAU,CAAE,GAAGA,EAAM,SAAU,EAAM,EAAE,EAC7CrB,EAAU,QAAQ,sBACpBA,EAAU,QAAQ,qBAAqB,CAE3C,EAAG,CAAC,CAAC,EAECwC,EAAWnC,EAAY,CAACoC,EAAmBC,EAA8B,OAAS,CACtF3C,EAAS,CACP,iBAAkB0C,EAClB,oBAAqBC,EACrB,SAAU,EACZ,CAAC,CACH,EAAG,CAAC,CAAC,EAECC,EAAQ,CACZ,OAAApD,EACA,MAAAO,EACA,SAAA+B,EACA,SAAAX,EACA,OAAAqB,EACA,SAAAC,EACA,YAAAlB,EACA,YAAAE,EACA,WAAAC,CACF,EAEA,OAAK9B,EAGHT,GAACC,EAAkB,SAAlB,CAA2B,MAAOwD,EAChC,UAAAjD,EACAI,EAAM,UAAYb,EAAC2D,EAAA,EAAkB,GACxC,EANqB3D,EAAAD,GAAA,CAAG,SAAAU,EAAS,CAQrC,EAEamD,EAAgB,IAAM,CACjC,IAAMC,EAAUC,GAAW5D,CAAiB,EAC5C,GAAI2D,IAAY,OACd,MAAM,IAAI,MAAM,yDAAyD,EAE3E,OAAOA,CACT","names":["createContext","useContext","useEffect","useState","useCallback","useMemo","useRef","Cookies","useState","useEffect","useCallback","useRef","createPortal","jsx","jsxs","ChevronLeftIcon","ChevronRightIcon","XIcon","OnboardingOverlay","config","currentStep","nextStep","prevStep","finish","isFirstStep","isLastStep","useOnboarding","coords","setCoords","useState","position","setPosition","dragOffset","setDragOffset","isDragging","useRef","dragStart","tooltipRef","prevStepRef","setPrevStepRef","handlePointerUpRef","handlePointerMove","useCallback","newX","newY","handlePointerUp","useEffect","handlePointerDown","calculateBestPosition","rect","spaceAbove","spaceBelow","spaceLeft","spaceRight","top","left","updateCoords","element","padding","paddedRect","newCoords","newPosition","prev","observer","resizeObserver","maskStyle","stopPropagation","overlayContent","createPortal","Fragment","jsx","jsxs","OnboardingContext","createContext","COOKIE_NAME","OnboardingProvider","config","ssr","onNavigate","children","isMounted","setIsMounted","useState","state","setState","configRef","useRef","onNavigateRef","useEffect","handleNavigation","useCallback","link","isMatch","step","path","pattern","currentConfig","currentPath","matchedStepIndex","savedState","Cookies","parsed","targetUrl","prevStep","element","e","prev","currentStep","useMemo","isFirstStep","isLastStep","totalSteps","isLastMainStep","hasSubSteps","nextStep","stepObj","currentActiveStep","nextSubIndex","nextSubStep","nextIndex","nextStepObj","prevIndex","prevStepObj","prevSubStepIndex","finish","goToStep","stepIndex","subStepIndex","value","OnboardingOverlay","useOnboarding","context","useContext"]}
1
+ {"version":3,"sources":["../src/components/OnboardingProvider.tsx","../src/components/OnboardingOverlay.tsx"],"sourcesContent":["'use client';\n\nimport React, {\n createContext,\n useContext,\n useEffect,\n useState,\n useCallback,\n useMemo,\n useRef,\n} from 'react';\nimport Cookies from 'js-cookie';\nimport { OnboardingConfig, OnboardingState, OnboardingStep, OnboardingSubStep } from '../types';\nimport { OnboardingOverlay } from './OnboardingOverlay';\n\ninterface OnboardingContextType {\n config: OnboardingConfig;\n state: OnboardingState;\n nextStep: () => void;\n prevStep: () => void;\n finish: () => void;\n goToStep: (stepIndex: number, subStepIndex?: number | null) => void;\n currentStep: OnboardingStep | OnboardingSubStep | null;\n isFirstStep: boolean;\n isLastStep: boolean;\n}\n\nconst OnboardingContext = createContext<OnboardingContextType | undefined>(undefined);\n\nconst COOKIE_NAME = 'onboarding_state';\n\nconst getInitialState = (): OnboardingState => {\n if (typeof window !== 'undefined') {\n const saved = Cookies.get(COOKIE_NAME);\n if (saved) {\n try {\n const parsed = JSON.parse(saved);\n if (parsed && typeof parsed === 'object') {\n return {\n currentStepIndex: parsed.currentStepIndex ?? 0,\n currentSubStepIndex: parsed.currentSubStepIndex ?? null,\n isActive: parsed.isActive ?? true,\n completedSteps: parsed.completedSteps ?? [],\n subStepProgress: parsed.subStepProgress ?? {},\n };\n }\n } catch {\n // Ignore\n }\n }\n }\n return {\n currentStepIndex: 0,\n currentSubStepIndex: null,\n isActive: true,\n completedSteps: [],\n subStepProgress: {},\n };\n};\n\nexport const OnboardingProvider: React.FC<{\n config: OnboardingConfig;\n ssr?: boolean;\n onNavigate?: (url: string) => void;\n children: React.ReactNode;\n}> = ({ config, ssr = false, onNavigate, children }) => {\n const [isMounted, setIsMounted] = useState(!ssr);\n const [state, setState] = useState<OnboardingState>(getInitialState);\n const [currentPath, setCurrentPath] = useState(\n typeof window !== 'undefined' ? window.location.pathname : '',\n );\n const [isTransitioning, setIsTransitioning] = useState(false);\n\n const configRef = useRef(config);\n const onNavigateRef = useRef(onNavigate);\n const lastSimulatedKey = useRef<string>('');\n const lastPathForSimulation = useRef<string>(\n typeof window !== 'undefined' ? window.location.pathname : '',\n );\n const wasInternalAction = useRef(false);\n\n useEffect(() => {\n if (currentPath !== lastPathForSimulation.current) {\n lastPathForSimulation.current = currentPath;\n lastSimulatedKey.current = ''; // Reset simulation tracking on path change\n }\n }, [currentPath]);\n\n useEffect(() => {\n configRef.current = config;\n onNavigateRef.current = onNavigate;\n }, [config, onNavigate]);\n\n useEffect(() => {\n if (typeof window === 'undefined') return;\n\n const handlePathChange = () => {\n const newPath = window.location.pathname;\n setCurrentPath(newPath);\n };\n\n window.addEventListener('popstate', handlePathChange);\n\n const originalPushState = window.history.pushState;\n const originalReplaceState = window.history.replaceState;\n\n window.history.pushState = function (...args) {\n originalPushState.apply(this, args);\n handlePathChange();\n };\n\n window.history.replaceState = function (...args) {\n originalReplaceState.apply(this, args);\n handlePathChange();\n };\n\n window.addEventListener('locationchange', handlePathChange);\n const interval = setInterval(handlePathChange, 200);\n\n return () => {\n window.removeEventListener('popstate', handlePathChange);\n window.history.pushState = originalPushState;\n window.history.replaceState = originalReplaceState;\n window.removeEventListener('locationchange', handlePathChange);\n clearInterval(interval);\n };\n }, []);\n\n const handleNavigation = useCallback((link?: string) => {\n if (!link) return;\n if (onNavigateRef.current) {\n onNavigateRef.current(link);\n } else {\n window.location.href = link;\n }\n }, []);\n\n const isMatch = useCallback((step: OnboardingStep, path: string) => {\n if (!step?.urlMatch || !path) return false;\n\n let match = false;\n if (step.urlMatch.includes('*')) {\n const pattern = step.urlMatch\n .replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&') // Escape special regex chars\n .replace(/\\\\\\*/g, '.*'); // Convert escaped * back to .*\n match = new RegExp(`^${pattern}$`).test(path);\n } else {\n match = path === step.urlMatch;\n }\n return match;\n }, []);\n\n const simulateClicks = useCallback(\n (stepIndex: number, subStepIndex: number | null) => {\n const currentConfig = configRef.current;\n const actions: string[] = [];\n const path = window.location.pathname;\n const collectStepClicks = (step: OnboardingStep, upToSubStep: number | null = -1) => {\n if (upToSubStep === null) {\n // We are arriving at the main step itself. No sub-steps. \n // In this case, we don't click the step's attribute because arriving there \n // should show it. Re-clicking might close it if it's a toggle.\n return;\n }\n\n if (step.click) actions.push(step.attribute);\n if (step.subSteps) {\n const limit = upToSubStep === -1 ? step.subSteps.length : upToSubStep;\n for (let i = 0; i < limit; i++) {\n if (step.subSteps[i].click) actions.push(step.subSteps[i].attribute);\n }\n }\n };\n\n for (let i = 0; i <= stepIndex; i++) {\n const step = currentConfig.steps[i];\n if (isMatch(step, path)) {\n if (i < stepIndex) collectStepClicks(step);\n else if (subStepIndex !== null) {\n // We are arriving at a sub-step. Replay clicks leading to it.\n collectStepClicks(step, subStepIndex);\n }\n }\n }\n\n if (actions.length === 0) return;\n\n const performClick = (index: number) => {\n if (index >= actions.length) return;\n const attr = actions[index];\n const element = document.querySelector(`[data-onboarding-id=\"${attr}\"]`) as HTMLElement;\n if (element) element.click();\n setTimeout(() => performClick(index + 1), 500);\n };\n\n setTimeout(() => performClick(0), 500);\n },\n [isMatch, currentPath],\n );\n\n // Reconcile state with path\n useEffect(() => {\n if (ssr && !isMounted) {\n setIsMounted(true);\n return;\n }\n\n const currentConfig = configRef.current;\n const isInOrder = (currentConfig.metadata.inOrder as boolean | undefined) !== false;\n\n // Use functional update to avoid depending on 'state'\n setState((prev) => {\n if (!prev.isActive) return prev;\n\n const nextState = { ...prev };\n let changed = false;\n\n if (!isInOrder) {\n const matchedIndex = currentConfig.steps.findIndex(\n (step, index) => isMatch(step, currentPath) && !prev.completedSteps.includes(index),\n );\n\n if (matchedIndex !== -1 && matchedIndex !== prev.currentStepIndex) {\n nextState.currentStepIndex = matchedIndex;\n nextState.currentSubStepIndex = prev.subStepProgress[matchedIndex] ?? null;\n changed = true;\n }\n } else {\n const firstUnfinishedIndex = currentConfig.steps.findIndex(\n (_, i) => !prev.completedSteps.includes(i),\n );\n\n if (firstUnfinishedIndex !== -1) {\n if (firstUnfinishedIndex !== prev.currentStepIndex) {\n nextState.currentStepIndex = firstUnfinishedIndex;\n nextState.currentSubStepIndex = prev.subStepProgress[firstUnfinishedIndex] ?? null;\n changed = true;\n }\n\n const step = currentConfig.steps[firstUnfinishedIndex];\n if (!isMatch(step, currentPath)) {\n if (step.urlBase && currentPath !== step.urlBase) {\n handleNavigation(step.urlBase);\n }\n }\n }\n }\n\n return changed ? nextState : prev;\n });\n }, [ssr, isMounted, currentPath, handleNavigation, isMatch]);\n\n // Handle click simulation separately\n useEffect(() => {\n if (!state.isActive || !isMounted) return;\n const currentConfig = configRef.current;\n const step = currentConfig.steps[state.currentStepIndex];\n\n const simKey = `${currentPath}-${state.currentStepIndex}-${state.currentSubStepIndex}`;\n\n // Skip if we already simulated this exact state\n if (lastSimulatedKey.current === simKey) {\n return;\n }\n\n const internal = wasInternalAction.current;\n wasInternalAction.current = false;\n\n // Skip if path is same and it was an internal action (Next/Prev/GoTo)\n // because manual progression handles its own clicks.\n if (internal && currentPath === lastPathForSimulation.current) {\n lastSimulatedKey.current = simKey;\n return;\n }\n\n if (step && isMatch(step, currentPath) && currentConfig.metadata.simulateClicksOnNavigate) {\n if (lastSimulatedKey.current !== simKey) {\n lastSimulatedKey.current = simKey;\n lastPathForSimulation.current = currentPath;\n simulateClicks(state.currentStepIndex, state.currentSubStepIndex);\n }\n }\n }, [\n state.currentStepIndex,\n state.currentSubStepIndex,\n state.isActive,\n currentPath,\n isMounted,\n isMatch,\n simulateClicks,\n ]);\n\n // Persist state to cookies\n useEffect(() => {\n if (isMounted) {\n Cookies.set(COOKIE_NAME, JSON.stringify(state), { expires: 365 });\n }\n }, [state, isMounted]);\n\n const currentStep = useMemo(() => {\n const step = config.steps[state.currentStepIndex];\n if (!step) return null;\n\n const isUrlMatch = isMatch(step, currentPath);\n\n if (state.currentSubStepIndex !== null && step.subSteps) {\n const subStep = step.subSteps[state.currentSubStepIndex];\n if (isUrlMatch || isTransitioning) {\n return subStep || step;\n }\n return null;\n }\n\n if (!isUrlMatch) return null;\n\n return step;\n }, [\n config.steps,\n state.currentStepIndex,\n state.currentSubStepIndex,\n currentPath,\n isMatch,\n isTransitioning,\n ]);\n\n const isFirstStep = state.currentStepIndex === 0 && state.currentSubStepIndex === null;\n const isLastStep = useMemo(() => {\n const totalSteps = config.steps.length;\n const step = config.steps[state.currentStepIndex];\n const hasSubSteps = step?.subSteps && step.subSteps.length > 0;\n\n if (state.currentStepIndex === totalSteps - 1) {\n if (hasSubSteps) return state.currentSubStepIndex === step.subSteps!.length - 1;\n return true;\n }\n return false;\n }, [config.steps, state.currentStepIndex, state.currentSubStepIndex]);\n\n const nextStep = useCallback(() => {\n const currentConfig = configRef.current;\n wasInternalAction.current = true;\n\n setState((prev) => {\n const { currentStepIndex, currentSubStepIndex, completedSteps } = prev;\n const stepObj = currentConfig.steps[currentStepIndex];\n if (!stepObj) return prev;\n\n const currentActiveStep =\n currentSubStepIndex !== null && stepObj.subSteps\n ? stepObj.subSteps[currentSubStepIndex]\n : stepObj;\n\n if (currentActiveStep.click) {\n const element = document.querySelector(\n `[data-onboarding-id=\"${currentActiveStep.attribute}\"]`,\n ) as HTMLElement;\n if (element) element.click();\n }\n\n let nextState: OnboardingState;\n let navTo: string | undefined;\n\n if (\n stepObj.subSteps &&\n (currentSubStepIndex === null || currentSubStepIndex < stepObj.subSteps.length - 1)\n ) {\n const nextSubIndex = currentSubStepIndex === null ? 0 : currentSubStepIndex + 1;\n const nextSubStep = stepObj.subSteps[nextSubIndex];\n\n setIsTransitioning(true);\n setTimeout(() => setIsTransitioning(false), 1000);\n\n navTo = currentActiveStep.navigate || nextSubStep.navigate;\n if (!navTo && currentSubStepIndex === null) navTo = stepObj.navigate;\n\n nextState = {\n ...prev,\n currentSubStepIndex: nextSubIndex,\n subStepProgress: {\n ...prev.subStepProgress,\n [currentStepIndex]: nextSubIndex,\n },\n };\n } else {\n const stepIndexToComplete = currentStepIndex;\n if (currentStepIndex < currentConfig.steps.length - 1) {\n const nextIndex = currentStepIndex + 1;\n const nextStepObj = currentConfig.steps[nextIndex];\n const targetSubStepIndex = prev.subStepProgress[nextIndex] ?? null;\n const targetSubStep =\n targetSubStepIndex !== null && nextStepObj.subSteps\n ? nextStepObj.subSteps[targetSubStepIndex]\n : null;\n\n navTo = currentActiveStep.navigate || nextStepObj.navigate || targetSubStep?.navigate;\n\n nextState = {\n ...prev,\n currentStepIndex: nextIndex,\n currentSubStepIndex: targetSubStepIndex,\n completedSteps: completedSteps.includes(stepIndexToComplete)\n ? completedSteps\n : [...completedSteps, stepIndexToComplete],\n subStepProgress: {\n ...prev.subStepProgress,\n [stepIndexToComplete]: currentSubStepIndex,\n },\n };\n } else {\n if (currentConfig.onOnboardingComplete) currentConfig.onOnboardingComplete();\n\n navTo = currentActiveStep.navigate || stepObj.navigate;\n\n nextState = {\n ...prev,\n isActive: false,\n completedSteps: completedSteps.includes(stepIndexToComplete)\n ? completedSteps\n : [...completedSteps, stepIndexToComplete],\n subStepProgress: {\n ...prev.subStepProgress,\n [stepIndexToComplete]: currentSubStepIndex,\n },\n };\n }\n }\n\n Cookies.set(COOKIE_NAME, JSON.stringify(nextState), { expires: 365 });\n if (navTo) handleNavigation(navTo);\n return nextState;\n });\n }, [handleNavigation]);\n\n const prevStep = useCallback(() => {\n const currentConfig = configRef.current;\n wasInternalAction.current = true;\n setState((prev) => {\n let nextState: OnboardingState;\n let navTo: string | undefined;\n\n if (prev.currentSubStepIndex !== null && prev.currentSubStepIndex > 0) {\n const nextSubIndex = prev.currentSubStepIndex - 1;\n const nextSubStep = currentConfig.steps[prev.currentStepIndex].subSteps![nextSubIndex];\n navTo = nextSubStep.navigate;\n\n nextState = {\n ...prev,\n currentSubStepIndex: nextSubIndex,\n subStepProgress: {\n ...prev.subStepProgress,\n [prev.currentStepIndex]: nextSubIndex,\n },\n };\n } else if (prev.currentStepIndex > 0 && prev.currentSubStepIndex === 0) {\n const stepObj = currentConfig.steps[prev.currentStepIndex];\n navTo = stepObj.navigate;\n\n nextState = {\n ...prev,\n currentSubStepIndex: null,\n subStepProgress: {\n ...prev.subStepProgress,\n [prev.currentStepIndex]: null,\n },\n };\n } else if (prev.currentStepIndex > 0) {\n const prevIndex = prev.currentStepIndex - 1;\n const prevStepObj = currentConfig.steps[prevIndex];\n const prevSubStepIndex =\n prev.subStepProgress[prevIndex] ??\n (prevStepObj.subSteps ? prevStepObj.subSteps.length - 1 : null);\n const prevSubStep =\n prevSubStepIndex !== null && prevStepObj.subSteps\n ? prevStepObj.subSteps[prevSubStepIndex]\n : null;\n\n navTo = prevStepObj.navigate || prevSubStep?.navigate;\n\n nextState = {\n ...prev,\n currentStepIndex: prevIndex,\n currentSubStepIndex: prevSubStepIndex,\n isActive: true,\n subStepProgress: {\n ...prev.subStepProgress,\n [prevIndex]: prevSubStepIndex,\n },\n };\n } else {\n return prev;\n }\n\n Cookies.set(COOKIE_NAME, JSON.stringify(nextState), { expires: 365 });\n if (navTo) handleNavigation(navTo);\n return nextState;\n });\n }, [handleNavigation]);\n\n const finish = useCallback(() => {\n setState((prev) => ({ ...prev, isActive: false }));\n if (configRef.current.onOnboardingComplete) configRef.current.onOnboardingComplete();\n }, []);\n\n const goToStep = useCallback(\n (stepIndex: number, subStepIndex: number | null = null) => {\n const currentConfig = configRef.current;\n wasInternalAction.current = true;\n setState((prev) => {\n const nextStepObj = currentConfig.steps[stepIndex];\n const targetSubStep =\n subStepIndex !== null && nextStepObj.subSteps\n ? nextStepObj.subSteps[subStepIndex]\n : null;\n\n const navTo = nextStepObj.navigate || targetSubStep?.navigate;\n\n const nextState = {\n ...prev,\n currentStepIndex: stepIndex,\n currentSubStepIndex: subStepIndex,\n isActive: true,\n subStepProgress: {\n ...prev.subStepProgress,\n [stepIndex]: subStepIndex,\n },\n };\n\n Cookies.set(COOKIE_NAME, JSON.stringify(nextState), { expires: 365 });\n if (navTo) handleNavigation(navTo);\n return nextState;\n });\n },\n [handleNavigation],\n );\n\n const value = {\n config,\n state,\n nextStep,\n prevStep,\n finish,\n goToStep,\n currentStep,\n isFirstStep,\n isLastStep,\n };\n\n if (!isMounted) return <>{children}</>;\n\n return (\n <OnboardingContext.Provider value={value}>\n {children}\n {state.isActive && <OnboardingOverlay />}\n </OnboardingContext.Provider>\n );\n};\n\nexport const useOnboarding = () => {\n const context = useContext(OnboardingContext);\n if (context === undefined)\n throw new Error('useOnboarding must be used within an OnboardingProvider');\n return context;\n};\n","'use client';\n\nimport React, { useState, useEffect, useCallback, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport { useOnboarding } from './OnboardingProvider';\n\nconst ChevronLeftIcon = () => (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M15 18l-6-6 6-6\" />\n </svg>\n);\n\nconst ChevronRightIcon = () => (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M9 18l6-6-6-6\" />\n </svg>\n);\n\nconst XIcon = () => (\n <svg\n width=\"18\"\n height=\"18\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" />\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" />\n </svg>\n);\n\nexport const OnboardingOverlay: React.FC = () => {\n const { config, currentStep, nextStep, prevStep, finish, isFirstStep, isLastStep } =\n useOnboarding();\n const [coords, setCoords] = useState<{\n top: number;\n left: number;\n width: number;\n height: number;\n } | null>(null);\n const [position, setPosition] = useState<{ top: number; left: number }>({ top: 0, left: 0 });\n const [dragOffset, setDragOffset] = useState<{ x: number; y: number }>({ x: 0, y: 0 });\n const isDragging = useRef(false);\n const dragStart = useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n const tooltipRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setDragOffset({ x: 0, y: 0 });\n }, [currentStep]);\n\n const handlePointerUpRef = useRef<() => void>(() => {});\n\n const handlePointerMove = useCallback((e: PointerEvent) => {\n if (!isDragging.current) return;\n\n const newX = e.clientX - dragStart.current.x;\n const newY = e.clientY - dragStart.current.y;\n\n setDragOffset({ x: newX, y: newY });\n }, []);\n\n const handlePointerUp = useCallback(() => {\n isDragging.current = false;\n\n if (tooltipRef.current) {\n tooltipRef.current.style.transition =\n 'top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)';\n tooltipRef.current.style.cursor = config.metadata.draggable ? 'grab' : 'auto';\n }\n\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUpRef.current);\n }, [config.metadata.draggable, handlePointerMove]);\n\n useEffect(() => {\n handlePointerUpRef.current = handlePointerUp;\n }, [handlePointerUp]);\n\n const handlePointerDown = (e: React.PointerEvent) => {\n if (!config.metadata.draggable) return;\n e.stopPropagation();\n e.preventDefault();\n isDragging.current = true;\n dragStart.current = { x: e.clientX - dragOffset.x, y: e.clientY - dragOffset.y };\n\n if (tooltipRef.current) {\n tooltipRef.current.style.transition = 'none';\n tooltipRef.current.style.cursor = 'grabbing';\n }\n\n window.addEventListener('pointermove', handlePointerMove);\n window.addEventListener('pointerup', handlePointerUp);\n };\n\n const calculateBestPosition = useCallback(\n (rect: {\n top: number;\n bottom: number;\n left: number;\n right: number;\n width: number;\n height: number;\n }) => {\n const tooltipWidth = 300;\n const tooltipHeight = 200;\n const gap = 12;\n const padding = 20;\n\n const spaceAbove = rect.top;\n const spaceBelow = window.innerHeight - rect.bottom;\n const spaceLeft = rect.left;\n const spaceRight = window.innerWidth - rect.right;\n\n let top = 0;\n let left = 0;\n\n if (spaceBelow > tooltipHeight + gap + padding) {\n top = rect.bottom + gap;\n left = Math.max(\n padding,\n Math.min(\n window.innerWidth - tooltipWidth - padding,\n rect.left + rect.width / 2 - tooltipWidth / 2,\n ),\n );\n } else if (spaceAbove > tooltipHeight + gap + padding) {\n top = rect.top - tooltipHeight - gap;\n left = Math.max(\n padding,\n Math.min(\n window.innerWidth - tooltipWidth - padding,\n rect.left + rect.width / 2 - tooltipWidth / 2,\n ),\n );\n } else if (spaceRight > tooltipWidth + gap + padding) {\n top = Math.max(\n padding,\n Math.min(\n window.innerHeight - tooltipHeight - padding,\n rect.top + rect.height / 2 - tooltipHeight / 2,\n ),\n );\n left = rect.right + gap;\n } else if (spaceLeft > tooltipWidth + gap + padding) {\n top = Math.max(\n padding,\n Math.min(\n window.innerHeight - tooltipHeight - padding,\n rect.top + rect.height / 2 - tooltipHeight / 2,\n ),\n );\n left = rect.left - tooltipWidth - gap;\n } else {\n top = window.innerHeight / 2 - tooltipHeight / 2;\n left = window.innerWidth / 2 - tooltipWidth / 2;\n }\n\n return { top: top + window.scrollY, left: left + window.scrollX };\n },\n [],\n );\n\n const updateCoords = useCallback(() => {\n if (!currentStep) return;\n\n const element = document.querySelector(\n `[data-onboarding-id=\"${currentStep.attribute}\"]`,\n ) as HTMLElement;\n if (element) {\n const rect = element.getBoundingClientRect();\n const padding = config.style?.padding || 0;\n\n const paddedRect = {\n top: rect.top - padding,\n bottom: rect.bottom + padding,\n left: rect.left - padding,\n right: rect.right + padding,\n width: rect.width + padding * 2,\n height: rect.height + padding * 2,\n };\n\n const newCoords = {\n top: paddedRect.top + window.scrollY,\n left: paddedRect.left + window.scrollX,\n width: paddedRect.width,\n height: paddedRect.height,\n };\n\n const newPosition = calculateBestPosition(paddedRect);\n\n setCoords((prev) => {\n if (\n prev &&\n prev.top === newCoords.top &&\n prev.left === newCoords.left &&\n prev.width === newCoords.width &&\n prev.height === newCoords.height\n ) {\n return prev;\n }\n return newCoords;\n });\n\n setPosition((prev) => {\n if (prev.top === newPosition.top && prev.left === newPosition.left) {\n return prev;\n }\n return newPosition;\n });\n } else {\n setCoords(null);\n }\n }, [currentStep, calculateBestPosition, config.style]);\n\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n updateCoords();\n window.addEventListener('resize', updateCoords);\n window.addEventListener('scroll', updateCoords);\n\n const observer = new MutationObserver(updateCoords);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true });\n\n let resizeObserver: ResizeObserver | null = null;\n if (typeof ResizeObserver !== 'undefined') {\n resizeObserver = new ResizeObserver(updateCoords);\n resizeObserver.observe(document.body);\n\n const element = currentStep?.attribute\n ? document.querySelector(`[data-onboarding-id=\"${currentStep.attribute}\"]`)\n : null;\n if (element) {\n resizeObserver.observe(element);\n }\n }\n\n return () => {\n window.removeEventListener('resize', updateCoords);\n window.removeEventListener('scroll', updateCoords);\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUp);\n observer.disconnect();\n if (resizeObserver) resizeObserver.disconnect();\n };\n }, [updateCoords, currentStep?.attribute, handlePointerMove, handlePointerUp]);\n\n if (!currentStep || !coords) return null;\n\n const maskStyle = {\n ...config.style?.background,\n transition: 'all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)',\n };\n\n const stopPropagation = (e: React.PointerEvent | React.MouseEvent) => {\n e.stopPropagation();\n };\n\n const overlayContent = (\n <div className=\"onboard-overlay-container\">\n <div\n style={{ height: coords.top, ...maskStyle }}\n className=\"onboard-overlay-mask onboard-mask-top\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{\n top: coords.top + coords.height,\n height: `calc(100vh - ${coords.top + coords.height}px)`,\n ...maskStyle,\n }}\n className=\"onboard-overlay-mask onboard-mask-bottom\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{ top: coords.top, height: coords.height, width: coords.left, ...maskStyle }}\n className=\"onboard-overlay-mask onboard-mask-left\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n <div\n style={{\n top: coords.top,\n height: coords.height,\n left: coords.left + coords.width,\n width: `calc(100% - ${coords.left + coords.width}px)`,\n ...maskStyle,\n }}\n className=\"onboard-overlay-mask\"\n onPointerDown={stopPropagation}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n />\n\n <div\n ref={tooltipRef}\n className=\"onboard-tooltip\"\n onPointerDown={handlePointerDown}\n style={{\n zIndex: 1000000,\n ...config.style?.container,\n top: position.top + dragOffset.y,\n left: position.left + dragOffset.x,\n transition:\n 'top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.1, 0.25, 1)',\n cursor: config.metadata.draggable ? 'grab' : 'auto',\n touchAction: 'none',\n }}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n >\n <div className=\"onboard-tooltip-header\">\n <h3 className=\"onboard-tooltip-title\">{currentStep.title}</h3>\n <button\n onClick={(e) => {\n e.stopPropagation();\n finish();\n }}\n className=\"onboard-close-button\"\n >\n <XIcon />\n </button>\n </div>\n <p className=\"onboard-tooltip-description\">{currentStep.description}</p>\n\n <div className=\"onboard-tooltip-footer\">\n <button\n onClick={(e) => {\n e.stopPropagation();\n prevStep();\n }}\n disabled={isFirstStep}\n className=\"onboard-button-ghost\"\n style={{\n background: 'none',\n border: 'none',\n cursor: isFirstStep ? 'not-allowed' : 'pointer',\n ...config.style?.prev,\n }}\n >\n <ChevronLeftIcon />\n Prev\n </button>\n\n {isLastStep ? (\n <button\n onClick={(e) => {\n e.stopPropagation();\n nextStep();\n }}\n className=\"onboard-button-primary\"\n style={{ border: 'none', cursor: 'pointer', ...config.style?.finish }}\n >\n Finish\n </button>\n ) : (\n <button\n onClick={(e) => {\n e.stopPropagation();\n nextStep();\n }}\n className=\"onboard-button-primary\"\n style={{\n border: 'none',\n cursor: 'pointer',\n ...(isFirstStep ? config.style?.start : {}),\n ...(!isFirstStep ? config.style?.next : {}),\n }}\n >\n {isFirstStep && config.style?.start ? 'Start' : 'Next'}\n {!(isFirstStep && config.style?.start) && <ChevronRightIcon />}\n </button>\n )}\n </div>\n </div>\n </div>\n );\n\n return typeof document !== 'undefined' ? createPortal(overlayContent, document.body) : null;\n};\n"],"mappings":";aAEA,OACE,iBAAAA,GACA,cAAAC,GACA,aAAAC,EACA,YAAAC,EACA,eAAAC,EACA,WAAAC,GACA,UAAAC,MACK,QACP,OAAOC,MAAa,YCTpB,OAAgB,YAAAC,EAAU,aAAAC,EAAW,eAAAC,EAAa,UAAAC,MAAc,QAChE,OAAS,gBAAAC,OAAoB,YAczB,cAAAC,EAoBF,QAAAC,MApBE,oBAXJ,IAAMC,GAAkB,IACtBF,EAAC,OACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,OAAO,eACP,YAAY,IACZ,cAAc,QACd,eAAe,QAEf,SAAAA,EAAC,QAAK,EAAE,kBAAkB,EAC5B,EAGIG,GAAmB,IACvBH,EAAC,OACC,MAAM,KACN,OAAO,KACP,QAAQ,YACR,KAAK,OACL,OAAO,eACP,YAAY,IACZ,cAAc,QACd,eAAe,QAEf,SAAAA,EAAC,QAAK,EAAE,gBAAgB,EAC1B,EAGII,GAAQ,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EAAmBC,EAA8B,OAAS,CACzD,IAAMC,EAAgBxB,EAAU,QAChCK,EAAkB,QAAU,GAC5BV,EAAUwC,GAAS,CACjB,IAAM2B,EAActC,EAAc,MAAMF,CAAS,EAC3C0C,EACJzC,IAAiB,MAAQuC,EAAY,SACjCA,EAAY,SAASvC,CAAY,EACjC,KAEAkC,EAAQK,EAAY,UAAYE,GAAe,SAE/C5B,EAAY,CAChB,GAAGD,EACH,iBAAkBb,EAClB,oBAAqBC,EACrB,SAAU,GACV,gBAAiB,CACf,GAAGY,EAAK,gBACR,CAACb,CAAS,EAAGC,CACf,CACF,EAEA,OAAAvC,EAAQ,IAAIH,EAAa,KAAK,UAAUuD,CAAS,EAAG,CAAE,QAAS,GAAI,CAAC,EAChEqB,GAAO5C,EAAiB4C,CAAK,EAC1BrB,CACT,CAAC,CACH,EACA,CAACvB,CAAgB,CACnB,EAEM2D,EAAQ,CACZ,OAAArF,EACA,MAAAO,EACA,SAAAyD,EACA,SAAAc,EACA,OAAAK,EACA,SAAAC,EACA,YAAA5B,EACA,YAAAI,EACA,WAAAC,CACF,EAEA,OAAKzD,EAGHb,GAACC,GAAkB,SAAlB,CAA2B,MAAO6F,EAChC,UAAAlF,EACAI,EAAM,UAAYjB,GAACgG,EAAA,EAAkB,GACxC,EANqBhG,GAAAD,GAAA,CAAG,SAAAc,EAAS,CAQrC,EAEaoF,GAAgB,IAAM,CACjC,IAAMC,EAAUC,GAAWjG,EAAiB,EAC5C,GAAIgG,IAAY,OACd,MAAM,IAAI,MAAM,yDAAyD,EAC3E,OAAOA,CACT","names":["createContext","useContext","useEffect","useState","useCallback","useMemo","useRef","Cookies","useState","useEffect","useCallback","useRef","createPortal","jsx","jsxs","ChevronLeftIcon","ChevronRightIcon","XIcon","OnboardingOverlay","config","currentStep","nextStep","prevStep","finish","isFirstStep","isLastStep","useOnboarding","coords","setCoords","useState","position","setPosition","dragOffset","setDragOffset","isDragging","useRef","dragStart","tooltipRef","useEffect","handlePointerUpRef","handlePointerMove","useCallback","e","newX","newY","handlePointerUp","handlePointerDown","calculateBestPosition","rect","spaceAbove","spaceBelow","spaceLeft","spaceRight","top","left","updateCoords","element","padding","paddedRect","newCoords","newPosition","prev","observer","resizeObserver","maskStyle","stopPropagation","overlayContent","createPortal","Fragment","jsx","jsxs","OnboardingContext","createContext","COOKIE_NAME","getInitialState","saved","Cookies","parsed","OnboardingProvider","config","ssr","onNavigate","children","isMounted","setIsMounted","useState","state","setState","currentPath","setCurrentPath","isTransitioning","setIsTransitioning","configRef","useRef","onNavigateRef","lastSimulatedKey","lastPathForSimulation","wasInternalAction","useEffect","handlePathChange","newPath","originalPushState","originalReplaceState","args","interval","handleNavigation","useCallback","link","isMatch","step","path","match","pattern","simulateClicks","stepIndex","subStepIndex","currentConfig","actions","collectStepClicks","upToSubStep","limit","i","performClick","index","attr","element","isInOrder","prev","nextState","changed","firstUnfinishedIndex","_","matchedIndex","simKey","internal","currentStep","useMemo","isUrlMatch","subStep","isFirstStep","isLastStep","totalSteps","hasSubSteps","nextStep","currentStepIndex","currentSubStepIndex","completedSteps","stepObj","currentActiveStep","navTo","nextSubIndex","nextSubStep","stepIndexToComplete","nextIndex","nextStepObj","targetSubStepIndex","targetSubStep","prevStep","prevIndex","prevStepObj","prevSubStepIndex","prevSubStep","finish","goToStep","value","OnboardingOverlay","useOnboarding","context","useContext"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onboard-engine",
3
- "version": "1.4.3",
3
+ "version": "1.5.2",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -53,16 +53,16 @@
53
53
  },
54
54
  "homepage": "https://github.com/Forsrobin/onboard-engine#readme",
55
55
  "peerDependencies": {
56
- "react": ">=18",
57
- "react-dom": ">=18"
56
+ "react": ">=18.0.0 || ^19.0.0",
57
+ "react-dom": ">=18.0.0 || ^19.0.0"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@testing-library/jest-dom": "^6.6.3",
61
61
  "@testing-library/react": "^16.2.0",
62
62
  "@types/js-cookie": "^3.0.6",
63
63
  "@types/node": "^22.10.6",
64
- "@types/react": "^19.0.7",
65
- "@types/react-dom": "^19.0.3",
64
+ "@types/react": "^19.2.0",
65
+ "@types/react-dom": "^19.2.0",
66
66
  "@typescript-eslint/eslint-plugin": "^8.53.0",
67
67
  "@typescript-eslint/parser": "^8.53.0",
68
68
  "@vitejs/plugin-react": "^4.3.4",
@@ -71,6 +71,8 @@
71
71
  "eslint-plugin-react-hooks": "^7.0.1",
72
72
  "jsdom": "^26.0.0",
73
73
  "prettier": "^3.8.0",
74
+ "react": "^19.2.0",
75
+ "react-dom": "^19.2.0",
74
76
  "tsup": "^8.3.5",
75
77
  "typescript": "^5.7.3",
76
78
  "vitest": "^4.0.17"