@trailguide/core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/trailguide.js +2 -2
- package/dist/trailguide.umd.js +1 -1
- package/package.json +5 -2
package/dist/trailguide.js
CHANGED
package/dist/trailguide.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(y,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(y=typeof globalThis<"u"?globalThis:y||self,A(y.Trailguide={}))})(this,function(y){"use strict";var ti=Object.defineProperty;var ei=(y,A,k)=>A in y?ti(y,A,{enumerable:!0,configurable:!0,writable:!0,value:k}):y[A]=k;var I=(y,A,k)=>ei(y,typeof A!="symbol"?A+"":A,k);const A=Math.min,k=Math.max,ot=Math.round,F=t=>({x:t,y:t}),zt={left:"right",right:"left",bottom:"top",top:"bottom"},Yt={start:"end",end:"start"};function ht(t,e,n){return k(t,A(e,n))}function U(t,e){return typeof t=="function"?t(e):t}function W(t){return t.split("-")[0]}function Q(t){return t.split("-")[1]}function Et(t){return t==="x"?"y":"x"}function pt(t){return t==="y"?"height":"width"}const Kt=new Set(["top","bottom"]);function M(t){return Kt.has(W(t))?"y":"x"}function gt(t){return Et(M(t))}function Gt(t,e,n){n===void 0&&(n=!1);const i=Q(t),o=gt(t),s=pt(o);let r=o==="x"?i===(n?"end":"start")?"right":"left":i==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(r=st(r)),[r,st(r)]}function Jt(t){const e=st(t);return[mt(t),e,mt(e)]}function mt(t){return t.replace(/start|end/g,e=>Yt[e])}const It=["left","right"],kt=["right","left"],Ut=["top","bottom"],Qt=["bottom","top"];function Zt(t,e,n){switch(t){case"top":case"bottom":return n?e?kt:It:e?It:kt;case"left":case"right":return e?Ut:Qt;default:return[]}}function te(t,e,n,i){const o=Q(t);let s=Zt(W(t),n==="start",i);return o&&(s=s.map(r=>r+"-"+o),e&&(s=s.concat(s.map(mt)))),s}function st(t){return t.replace(/left|right|bottom|top/g,e=>zt[e])}function ee(t){return{top:0,right:0,bottom:0,left:0,...t}}function Ot(t){return typeof t!="number"?ee(t):{top:t,right:t,bottom:t,left:t}}function rt(t){const{x:e,y:n,width:i,height:o}=t;return{width:i,height:o,top:n,left:e,right:e+i,bottom:n+o,x:e,y:n}}function $t(t,e,n){let{reference:i,floating:o}=t;const s=M(e),r=gt(e),l=pt(r),a=W(e),c=s==="y",d=i.x+i.width/2-o.width/2,u=i.y+i.height/2-o.height/2,h=i[l]/2-o[l]/2;let f;switch(a){case"top":f={x:d,y:i.y-o.height};break;case"bottom":f={x:d,y:i.y+i.height};break;case"right":f={x:i.x+i.width,y:u};break;case"left":f={x:i.x-o.width,y:u};break;default:f={x:i.x,y:i.y}}switch(Q(e)){case"start":f[r]-=h*(n&&c?-1:1);break;case"end":f[r]+=h*(n&&c?-1:1);break}return f}async function ie(t,e){var n;e===void 0&&(e={});const{x:i,y:o,platform:s,rects:r,elements:l,strategy:a}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:u="floating",altBoundary:h=!1,padding:f=0}=U(e,t),p=Ot(f),m=l[h?u==="floating"?"reference":"floating":u],w=rt(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(m)))==null||n?m:m.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:c,rootBoundary:d,strategy:a})),b=u==="floating"?{x:i,y:o,width:r.floating.width,height:r.floating.height}:r.reference,v=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),S=await(s.isElement==null?void 0:s.isElement(v))?await(s.getScale==null?void 0:s.getScale(v))||{x:1,y:1}:{x:1,y:1},L=rt(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:b,offsetParent:v,strategy:a}):b);return{top:(w.top-L.top+p.top)/S.y,bottom:(L.bottom-w.bottom+p.bottom)/S.y,left:(w.left-L.left+p.left)/S.x,right:(L.right-w.right+p.right)/S.x}}const ne=async(t,e,n)=>{const{placement:i="bottom",strategy:o="absolute",middleware:s=[],platform:r}=n,l=s.filter(Boolean),a=await(r.isRTL==null?void 0:r.isRTL(e));let c=await r.getElementRects({reference:t,floating:e,strategy:o}),{x:d,y:u}=$t(c,i,a),h=i,f={},p=0;for(let m=0;m<l.length;m++){var g;const{name:w,fn:b}=l[m],{x:v,y:S,data:L,reset:C}=await b({x:d,y:u,initialPlacement:i,placement:h,strategy:o,middlewareData:f,rects:c,platform:{...r,detectOverflow:(g=r.detectOverflow)!=null?g:ie},elements:{reference:t,floating:e}});d=v??d,u=S??u,f={...f,[w]:{...f[w],...L}},C&&p<=50&&(p++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(c=C.rects===!0?await r.getElementRects({reference:t,floating:e,strategy:o}):C.rects),{x:d,y:u}=$t(c,h,a)),m=-1)}return{x:d,y:u,placement:h,strategy:o,middlewareData:f}},oe=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:i,placement:o,rects:s,platform:r,elements:l,middlewareData:a}=e,{element:c,padding:d=0}=U(t,e)||{};if(c==null)return{};const u=Ot(d),h={x:n,y:i},f=gt(o),p=pt(f),g=await r.getDimensions(c),m=f==="y",w=m?"top":"left",b=m?"bottom":"right",v=m?"clientHeight":"clientWidth",S=s.reference[p]+s.reference[f]-h[f]-s.floating[p],L=h[f]-s.reference[f],C=await(r.getOffsetParent==null?void 0:r.getOffsetParent(c));let j=C?C[v]:0;(!j||!await(r.isElement==null?void 0:r.isElement(C)))&&(j=l.floating[v]||s.floating[p]);const et=S/2-L/2,X=j/2-g[p]/2-1,_=A(u[w],X),it=A(u[b],X),z=_,nt=j-g[p]-it,T=j/2-g[p]/2+et,Y=ht(z,T,nt),q=!a.arrow&&Q(o)!=null&&T!==Y&&s.reference[p]/2-(T<z?_:it)-g[p]/2<0,R=q?T<z?T-z:T-nt:0;return{[f]:h[f]+R,data:{[f]:Y,centerOffset:T-Y-R,...q&&{alignmentOffset:R}},reset:q}}}),se=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,i;const{placement:o,middlewareData:s,rects:r,initialPlacement:l,platform:a,elements:c}=e,{mainAxis:d=!0,crossAxis:u=!0,fallbackPlacements:h,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:g=!0,...m}=U(t,e);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const w=W(o),b=M(l),v=W(l)===l,S=await(a.isRTL==null?void 0:a.isRTL(c.floating)),L=h||(v||!g?[st(l)]:Jt(l)),C=p!=="none";!h&&C&&L.push(...te(l,g,p,S));const j=[l,...L],et=await a.detectOverflow(e,m),X=[];let _=((i=s.flip)==null?void 0:i.overflows)||[];if(d&&X.push(et[w]),u){const T=Gt(o,r,S);X.push(et[T[0]],et[T[1]])}if(_=[..._,{placement:o,overflows:X}],!X.every(T=>T<=0)){var it,z;const T=(((it=s.flip)==null?void 0:it.index)||0)+1,Y=j[T];if(Y&&(!(u==="alignment"?b!==M(Y):!1)||_.every(P=>M(P.placement)===b?P.overflows[0]>0:!0)))return{data:{index:T,overflows:_},reset:{placement:Y}};let q=(z=_.filter(R=>R.overflows[0]<=0).sort((R,P)=>R.overflows[1]-P.overflows[1])[0])==null?void 0:z.placement;if(!q)switch(f){case"bestFit":{var nt;const R=(nt=_.filter(P=>{if(C){const V=M(P.placement);return V===b||V==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(V=>V>0).reduce((V,Ze)=>V+Ze,0)]).sort((P,V)=>P[1]-V[1])[0])==null?void 0:nt[0];R&&(q=R);break}case"initialPlacement":q=l;break}if(o!==q)return{reset:{placement:q}}}return{}}}},re=new Set(["left","top"]);async function le(t,e){const{placement:n,platform:i,elements:o}=t,s=await(i.isRTL==null?void 0:i.isRTL(o.floating)),r=W(n),l=Q(n),a=M(n)==="y",c=re.has(r)?-1:1,d=s&&a?-1:1,u=U(e,t);let{mainAxis:h,crossAxis:f,alignmentAxis:p}=typeof u=="number"?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return l&&typeof p=="number"&&(f=l==="end"?p*-1:p),a?{x:f*d,y:h*c}:{x:h*c,y:f*d}}const ce=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,i;const{x:o,y:s,placement:r,middlewareData:l}=e,a=await le(e,t);return r===((n=l.offset)==null?void 0:n.placement)&&(i=l.arrow)!=null&&i.alignmentOffset?{}:{x:o+a.x,y:s+a.y,data:{...a,placement:r}}}}},ae=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:i,placement:o,platform:s}=e,{mainAxis:r=!0,crossAxis:l=!1,limiter:a={fn:w=>{let{x:b,y:v}=w;return{x:b,y:v}}},...c}=U(t,e),d={x:n,y:i},u=await s.detectOverflow(e,c),h=M(W(o)),f=Et(h);let p=d[f],g=d[h];if(r){const w=f==="y"?"top":"left",b=f==="y"?"bottom":"right",v=p+u[w],S=p-u[b];p=ht(v,p,S)}if(l){const w=h==="y"?"top":"left",b=h==="y"?"bottom":"right",v=g+u[w],S=g-u[b];g=ht(v,g,S)}const m=a.fn({...e,[f]:p,[h]:g});return{...m,data:{x:m.x-n,y:m.y-i,enabled:{[f]:r,[h]:l}}}}}};function lt(){return typeof window<"u"}function K(t){return Lt(t)?(t.nodeName||"").toLowerCase():"#document"}function E(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function B(t){var e;return(e=(Lt(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Lt(t){return lt()?t instanceof Node||t instanceof E(t).Node:!1}function O(t){return lt()?t instanceof Element||t instanceof E(t).Element:!1}function D(t){return lt()?t instanceof HTMLElement||t instanceof E(t).HTMLElement:!1}function Rt(t){return!lt()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof E(t).ShadowRoot}const ue=new Set(["inline","contents"]);function Z(t){const{overflow:e,overflowX:n,overflowY:i,display:o}=$(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+n)&&!ue.has(o)}const fe=new Set(["table","td","th"]);function de(t){return fe.has(K(t))}const he=[":popover-open",":modal"];function ct(t){return he.some(e=>{try{return t.matches(e)}catch{return!1}})}const pe=["transform","translate","scale","rotate","perspective"],ge=["transform","translate","scale","rotate","perspective","filter"],me=["paint","layout","strict","content"];function yt(t){const e=wt(),n=O(t)?$(t):t;return pe.some(i=>n[i]?n[i]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||ge.some(i=>(n.willChange||"").includes(i))||me.some(i=>(n.contain||"").includes(i))}function ye(t){let e=N(t);for(;D(e)&&!G(e);){if(yt(e))return e;if(ct(e))return null;e=N(e)}return null}function wt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const we=new Set(["html","body","#document"]);function G(t){return we.has(K(t))}function $(t){return E(t).getComputedStyle(t)}function at(t){return O(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function N(t){if(K(t)==="html")return t;const e=t.assignedSlot||t.parentNode||Rt(t)&&t.host||B(t);return Rt(e)?e.host:e}function Pt(t){const e=N(t);return G(e)?t.ownerDocument?t.ownerDocument.body:t.body:D(e)&&Z(e)?e:Pt(e)}function Ft(t,e,n){var i;e===void 0&&(e=[]);const o=Pt(t),s=o===((i=t.ownerDocument)==null?void 0:i.body),r=E(o);return s?(xt(r),e.concat(r,r.visualViewport||[],Z(o)?o:[],[])):e.concat(o,Ft(o,[]))}function xt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Dt(t){const e=$(t);let n=parseFloat(e.width)||0,i=parseFloat(e.height)||0;const o=D(t),s=o?t.offsetWidth:n,r=o?t.offsetHeight:i,l=ot(n)!==s||ot(i)!==r;return l&&(n=s,i=r),{width:n,height:i,$:l}}function Bt(t){return O(t)?t:t.contextElement}function J(t){const e=Bt(t);if(!D(e))return F(1);const n=e.getBoundingClientRect(),{width:i,height:o,$:s}=Dt(e);let r=(s?ot(n.width):n.width)/i,l=(s?ot(n.height):n.height)/o;return(!r||!Number.isFinite(r))&&(r=1),(!l||!Number.isFinite(l))&&(l=1),{x:r,y:l}}const xe=F(0);function _t(t){const e=E(t);return!wt()||!e.visualViewport?xe:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function be(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==E(t)?!1:e}function tt(t,e,n,i){e===void 0&&(e=!1),n===void 0&&(n=!1);const o=t.getBoundingClientRect(),s=Bt(t);let r=F(1);e&&(i?O(i)&&(r=J(i)):r=J(t));const l=be(s,n,i)?_t(s):F(0);let a=(o.left+l.x)/r.x,c=(o.top+l.y)/r.y,d=o.width/r.x,u=o.height/r.y;if(s){const h=E(s),f=i&&O(i)?E(i):i;let p=h,g=xt(p);for(;g&&i&&f!==p;){const m=J(g),w=g.getBoundingClientRect(),b=$(g),v=w.left+(g.clientLeft+parseFloat(b.paddingLeft))*m.x,S=w.top+(g.clientTop+parseFloat(b.paddingTop))*m.y;a*=m.x,c*=m.y,d*=m.x,u*=m.y,a+=v,c+=S,p=E(g),g=xt(p)}}return rt({width:d,height:u,x:a,y:c})}function ut(t,e){const n=at(t).scrollLeft;return e?e.left+n:tt(B(t)).left+n}function qt(t,e){const n=t.getBoundingClientRect(),i=n.left+e.scrollLeft-ut(t,n),o=n.top+e.scrollTop;return{x:i,y:o}}function ve(t){let{elements:e,rect:n,offsetParent:i,strategy:o}=t;const s=o==="fixed",r=B(i),l=e?ct(e.floating):!1;if(i===r||l&&s)return n;let a={scrollLeft:0,scrollTop:0},c=F(1);const d=F(0),u=D(i);if((u||!u&&!s)&&((K(i)!=="body"||Z(r))&&(a=at(i)),D(i))){const f=tt(i);c=J(i),d.x=f.x+i.clientLeft,d.y=f.y+i.clientTop}const h=r&&!u&&!s?qt(r,a):F(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-a.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-a.scrollTop*c.y+d.y+h.y}}function Se(t){return Array.from(t.getClientRects())}function Ae(t){const e=B(t),n=at(t),i=t.ownerDocument.body,o=k(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),s=k(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let r=-n.scrollLeft+ut(t);const l=-n.scrollTop;return $(i).direction==="rtl"&&(r+=k(e.clientWidth,i.clientWidth)-o),{width:o,height:s,x:r,y:l}}const Mt=25;function Te(t,e){const n=E(t),i=B(t),o=n.visualViewport;let s=i.clientWidth,r=i.clientHeight,l=0,a=0;if(o){s=o.width,r=o.height;const d=wt();(!d||d&&e==="fixed")&&(l=o.offsetLeft,a=o.offsetTop)}const c=ut(i);if(c<=0){const d=i.ownerDocument,u=d.body,h=getComputedStyle(u),f=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,p=Math.abs(i.clientWidth-u.clientWidth-f);p<=Mt&&(s-=p)}else c<=Mt&&(s+=c);return{width:s,height:r,x:l,y:a}}const Ce=new Set(["absolute","fixed"]);function Ee(t,e){const n=tt(t,!0,e==="fixed"),i=n.top+t.clientTop,o=n.left+t.clientLeft,s=D(t)?J(t):F(1),r=t.clientWidth*s.x,l=t.clientHeight*s.y,a=o*s.x,c=i*s.y;return{width:r,height:l,x:a,y:c}}function Nt(t,e,n){let i;if(e==="viewport")i=Te(t,n);else if(e==="document")i=Ae(B(t));else if(O(e))i=Ee(e,n);else{const o=_t(t);i={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return rt(i)}function Vt(t,e){const n=N(t);return n===e||!O(n)||G(n)?!1:$(n).position==="fixed"||Vt(n,e)}function Ie(t,e){const n=e.get(t);if(n)return n;let i=Ft(t,[]).filter(l=>O(l)&&K(l)!=="body"),o=null;const s=$(t).position==="fixed";let r=s?N(t):t;for(;O(r)&&!G(r);){const l=$(r),a=yt(r);!a&&l.position==="fixed"&&(o=null),(s?!a&&!o:!a&&l.position==="static"&&!!o&&Ce.has(o.position)||Z(r)&&!a&&Vt(t,r))?i=i.filter(d=>d!==r):o=l,r=N(r)}return e.set(t,i),i}function ke(t){let{element:e,boundary:n,rootBoundary:i,strategy:o}=t;const r=[...n==="clippingAncestors"?ct(e)?[]:Ie(e,this._c):[].concat(n),i],l=r[0],a=r.reduce((c,d)=>{const u=Nt(e,d,o);return c.top=k(u.top,c.top),c.right=A(u.right,c.right),c.bottom=A(u.bottom,c.bottom),c.left=k(u.left,c.left),c},Nt(e,l,o));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}}function Oe(t){const{width:e,height:n}=Dt(t);return{width:e,height:n}}function $e(t,e,n){const i=D(e),o=B(e),s=n==="fixed",r=tt(t,!0,s,e);let l={scrollLeft:0,scrollTop:0};const a=F(0);function c(){a.x=ut(o)}if(i||!i&&!s)if((K(e)!=="body"||Z(o))&&(l=at(e)),i){const f=tt(e,!0,s,e);a.x=f.x+e.clientLeft,a.y=f.y+e.clientTop}else o&&c();s&&!i&&o&&c();const d=o&&!i&&!s?qt(o,l):F(0),u=r.left+l.scrollLeft-a.x-d.x,h=r.top+l.scrollTop-a.y-d.y;return{x:u,y:h,width:r.width,height:r.height}}function bt(t){return $(t).position==="static"}function Wt(t,e){if(!D(t)||$(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return B(t)===n&&(n=n.ownerDocument.body),n}function Ht(t,e){const n=E(t);if(ct(t))return n;if(!D(t)){let o=N(t);for(;o&&!G(o);){if(O(o)&&!bt(o))return o;o=N(o)}return n}let i=Wt(t,e);for(;i&&de(i)&&bt(i);)i=Wt(i,e);return i&&G(i)&&bt(i)&&!yt(i)?n:i||ye(t)||n}const Le=async function(t){const e=this.getOffsetParent||Ht,n=this.getDimensions,i=await n(t.floating);return{reference:$e(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function Re(t){return $(t).direction==="rtl"}const Pe={convertOffsetParentRelativeRectToViewportRelativeRect:ve,getDocumentElement:B,getClippingRect:ke,getOffsetParent:Ht,getElementRects:Le,getClientRects:Se,getDimensions:Oe,getScale:J,isElement:O,isRTL:Re},Fe=ce,De=ae,Be=se,_e=oe,qe=(t,e,n)=>{const i=new Map,o={platform:Pe,...n},s={...o.platform,_c:i};return ne(t,e,{...o,platform:s})};function vt(t){try{return document.querySelector(t)}catch{return console.warn(`[Trailguide] Invalid selector: ${t}`),null}}function St(t){const e=t.getBoundingClientRect(),n=window.getComputedStyle(t);return e.width>0&&e.height>0&&n.visibility!=="hidden"&&n.display!=="none"&&n.opacity!=="0"}function jt(t){t.scrollIntoView({behavior:"smooth",block:"center",inline:"center"})}function Me(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}function ft(t,e,n){const i=document.createElement(t);return e&&(i.className=e),n&&n.appendChild(i),i}function Ne(){return`${Date.now()}-${Math.random().toString(36).slice(2,11)}`}let At=null;function Ve(){return At||(At=Ne()),At}async function We(t,e){if(!t.endpoint)return;const n={...e,user_id:t.userId,session_id:Ve(),timestamp:new Date().toISOString()};try{const i=await fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});t.debug&&(i.ok?console.log("[Trailguide Analytics]",n):console.error(`[Trailguide Analytics] Server error: ${i.status}`))}catch(i){t.debug&&console.error("[Trailguide Analytics] Failed:",i)}}class Xt{constructor(e={}){I(this,"trail",null);I(this,"currentStepIndex",0);I(this,"isActive",!1);I(this,"options",{});I(this,"overlay",null);I(this,"tooltip",null);I(this,"arrowEl",null);I(this,"cleanupFns",[]);I(this,"stepCleanupFns",[]);I(this,"instanceId",`trailguide-${Date.now()}-${Math.random().toString(36).slice(2,7)}`);I(this,"stepTimerId",null);this.options=e}start(e){this.trail=e,this.currentStepIndex=0,this.isActive=!0,this.createOverlay(),this.showStep(),this.bindKeyboard(),this.emitAnalytics("trail_started")}stop(){var e,n;this.isActive?(this.emitAnalytics("trail_abandoned"),this.isActive=!1,this.cleanup(),(n=(e=this.options).onAbandoned)==null||n.call(e)):this.cleanup()}next(){!this.trail||!this.isActive||(this.emitAnalytics("step_completed"),this.currentStepIndex<this.trail.steps.length-1?(this.currentStepIndex++,this.showStep()):this.complete())}prev(){!this.trail||!this.isActive||this.currentStepIndex>0&&(this.currentStepIndex--,this.showStep())}skip(){var e,n;this.emitAnalytics("trail_skipped"),this.isActive=!1,this.cleanup(),(n=(e=this.options).onSkip)==null||n.call(e)}goToStep(e){!this.trail||!this.isActive||e>=0&&e<this.trail.steps.length&&(this.currentStepIndex=e,this.showStep())}complete(){var e,n;this.emitAnalytics("trail_completed"),this.isActive=!1,this.cleanup(),(n=(e=this.options).onComplete)==null||n.call(e)}createOverlay(){var i,o,s;this.overlay=ft("div","trailguide-overlay"),document.body.appendChild(this.overlay);const e=ft("div","trailguide-spotlight",this.overlay),n=`${this.instanceId}-mask`;e.innerHTML=`
|
|
1
|
+
(function(y,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(y=typeof globalThis<"u"?globalThis:y||self,A(y.Trailguide={}))})(this,function(y){"use strict";var ti=Object.defineProperty;var ei=(y,A,k)=>A in y?ti(y,A,{enumerable:!0,configurable:!0,writable:!0,value:k}):y[A]=k;var I=(y,A,k)=>ei(y,typeof A!="symbol"?A+"":A,k);const A=Math.min,k=Math.max,ot=Math.round,F=t=>({x:t,y:t}),zt={left:"right",right:"left",bottom:"top",top:"bottom"},Yt={start:"end",end:"start"};function ht(t,e,n){return k(t,A(e,n))}function U(t,e){return typeof t=="function"?t(e):t}function W(t){return t.split("-")[0]}function Q(t){return t.split("-")[1]}function Et(t){return t==="x"?"y":"x"}function pt(t){return t==="y"?"height":"width"}const Kt=new Set(["top","bottom"]);function M(t){return Kt.has(W(t))?"y":"x"}function gt(t){return Et(M(t))}function Gt(t,e,n){n===void 0&&(n=!1);const i=Q(t),o=gt(t),s=pt(o);let r=o==="x"?i===(n?"end":"start")?"right":"left":i==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(r=st(r)),[r,st(r)]}function Jt(t){const e=st(t);return[mt(t),e,mt(e)]}function mt(t){return t.replace(/start|end/g,e=>Yt[e])}const It=["left","right"],kt=["right","left"],Ut=["top","bottom"],Qt=["bottom","top"];function Zt(t,e,n){switch(t){case"top":case"bottom":return n?e?kt:It:e?It:kt;case"left":case"right":return e?Ut:Qt;default:return[]}}function te(t,e,n,i){const o=Q(t);let s=Zt(W(t),n==="start",i);return o&&(s=s.map(r=>r+"-"+o),e&&(s=s.concat(s.map(mt)))),s}function st(t){return t.replace(/left|right|bottom|top/g,e=>zt[e])}function ee(t){return{top:0,right:0,bottom:0,left:0,...t}}function Ot(t){return typeof t!="number"?ee(t):{top:t,right:t,bottom:t,left:t}}function rt(t){const{x:e,y:n,width:i,height:o}=t;return{width:i,height:o,top:n,left:e,right:e+i,bottom:n+o,x:e,y:n}}function $t(t,e,n){let{reference:i,floating:o}=t;const s=M(e),r=gt(e),l=pt(r),a=W(e),c=s==="y",d=i.x+i.width/2-o.width/2,u=i.y+i.height/2-o.height/2,h=i[l]/2-o[l]/2;let f;switch(a){case"top":f={x:d,y:i.y-o.height};break;case"bottom":f={x:d,y:i.y+i.height};break;case"right":f={x:i.x+i.width,y:u};break;case"left":f={x:i.x-o.width,y:u};break;default:f={x:i.x,y:i.y}}switch(Q(e)){case"start":f[r]-=h*(n&&c?-1:1);break;case"end":f[r]+=h*(n&&c?-1:1);break}return f}async function ie(t,e){var n;e===void 0&&(e={});const{x:i,y:o,platform:s,rects:r,elements:l,strategy:a}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:u="floating",altBoundary:h=!1,padding:f=0}=U(e,t),p=Ot(f),m=l[h?u==="floating"?"reference":"floating":u],w=rt(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(m)))==null||n?m:m.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:c,rootBoundary:d,strategy:a})),b=u==="floating"?{x:i,y:o,width:r.floating.width,height:r.floating.height}:r.reference,v=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),S=await(s.isElement==null?void 0:s.isElement(v))?await(s.getScale==null?void 0:s.getScale(v))||{x:1,y:1}:{x:1,y:1},L=rt(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:b,offsetParent:v,strategy:a}):b);return{top:(w.top-L.top+p.top)/S.y,bottom:(L.bottom-w.bottom+p.bottom)/S.y,left:(w.left-L.left+p.left)/S.x,right:(L.right-w.right+p.right)/S.x}}const ne=async(t,e,n)=>{const{placement:i="bottom",strategy:o="absolute",middleware:s=[],platform:r}=n,l=s.filter(Boolean),a=await(r.isRTL==null?void 0:r.isRTL(e));let c=await r.getElementRects({reference:t,floating:e,strategy:o}),{x:d,y:u}=$t(c,i,a),h=i,f={},p=0;for(let m=0;m<l.length;m++){var g;const{name:w,fn:b}=l[m],{x:v,y:S,data:L,reset:C}=await b({x:d,y:u,initialPlacement:i,placement:h,strategy:o,middlewareData:f,rects:c,platform:{...r,detectOverflow:(g=r.detectOverflow)!=null?g:ie},elements:{reference:t,floating:e}});d=v??d,u=S??u,f={...f,[w]:{...f[w],...L}},C&&p<=50&&(p++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(c=C.rects===!0?await r.getElementRects({reference:t,floating:e,strategy:o}):C.rects),{x:d,y:u}=$t(c,h,a)),m=-1)}return{x:d,y:u,placement:h,strategy:o,middlewareData:f}},oe=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:i,placement:o,rects:s,platform:r,elements:l,middlewareData:a}=e,{element:c,padding:d=0}=U(t,e)||{};if(c==null)return{};const u=Ot(d),h={x:n,y:i},f=gt(o),p=pt(f),g=await r.getDimensions(c),m=f==="y",w=m?"top":"left",b=m?"bottom":"right",v=m?"clientHeight":"clientWidth",S=s.reference[p]+s.reference[f]-h[f]-s.floating[p],L=h[f]-s.reference[f],C=await(r.getOffsetParent==null?void 0:r.getOffsetParent(c));let j=C?C[v]:0;(!j||!await(r.isElement==null?void 0:r.isElement(C)))&&(j=l.floating[v]||s.floating[p]);const et=S/2-L/2,X=j/2-g[p]/2-1,_=A(u[w],X),it=A(u[b],X),z=_,nt=j-g[p]-it,T=j/2-g[p]/2+et,Y=ht(z,T,nt),q=!a.arrow&&Q(o)!=null&&T!==Y&&s.reference[p]/2-(T<z?_:it)-g[p]/2<0,R=q?T<z?T-z:T-nt:0;return{[f]:h[f]+R,data:{[f]:Y,centerOffset:T-Y-R,...q&&{alignmentOffset:R}},reset:q}}}),se=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,i;const{placement:o,middlewareData:s,rects:r,initialPlacement:l,platform:a,elements:c}=e,{mainAxis:d=!0,crossAxis:u=!0,fallbackPlacements:h,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:g=!0,...m}=U(t,e);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const w=W(o),b=M(l),v=W(l)===l,S=await(a.isRTL==null?void 0:a.isRTL(c.floating)),L=h||(v||!g?[st(l)]:Jt(l)),C=p!=="none";!h&&C&&L.push(...te(l,g,p,S));const j=[l,...L],et=await a.detectOverflow(e,m),X=[];let _=((i=s.flip)==null?void 0:i.overflows)||[];if(d&&X.push(et[w]),u){const T=Gt(o,r,S);X.push(et[T[0]],et[T[1]])}if(_=[..._,{placement:o,overflows:X}],!X.every(T=>T<=0)){var it,z;const T=(((it=s.flip)==null?void 0:it.index)||0)+1,Y=j[T];if(Y&&(!(u==="alignment"?b!==M(Y):!1)||_.every(P=>M(P.placement)===b?P.overflows[0]>0:!0)))return{data:{index:T,overflows:_},reset:{placement:Y}};let q=(z=_.filter(R=>R.overflows[0]<=0).sort((R,P)=>R.overflows[1]-P.overflows[1])[0])==null?void 0:z.placement;if(!q)switch(f){case"bestFit":{var nt;const R=(nt=_.filter(P=>{if(C){const V=M(P.placement);return V===b||V==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(V=>V>0).reduce((V,Ze)=>V+Ze,0)]).sort((P,V)=>P[1]-V[1])[0])==null?void 0:nt[0];R&&(q=R);break}case"initialPlacement":q=l;break}if(o!==q)return{reset:{placement:q}}}return{}}}},re=new Set(["left","top"]);async function le(t,e){const{placement:n,platform:i,elements:o}=t,s=await(i.isRTL==null?void 0:i.isRTL(o.floating)),r=W(n),l=Q(n),a=M(n)==="y",c=re.has(r)?-1:1,d=s&&a?-1:1,u=U(e,t);let{mainAxis:h,crossAxis:f,alignmentAxis:p}=typeof u=="number"?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return l&&typeof p=="number"&&(f=l==="end"?p*-1:p),a?{x:f*d,y:h*c}:{x:h*c,y:f*d}}const ce=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,i;const{x:o,y:s,placement:r,middlewareData:l}=e,a=await le(e,t);return r===((n=l.offset)==null?void 0:n.placement)&&(i=l.arrow)!=null&&i.alignmentOffset?{}:{x:o+a.x,y:s+a.y,data:{...a,placement:r}}}}},ae=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:i,placement:o,platform:s}=e,{mainAxis:r=!0,crossAxis:l=!1,limiter:a={fn:w=>{let{x:b,y:v}=w;return{x:b,y:v}}},...c}=U(t,e),d={x:n,y:i},u=await s.detectOverflow(e,c),h=M(W(o)),f=Et(h);let p=d[f],g=d[h];if(r){const w=f==="y"?"top":"left",b=f==="y"?"bottom":"right",v=p+u[w],S=p-u[b];p=ht(v,p,S)}if(l){const w=h==="y"?"top":"left",b=h==="y"?"bottom":"right",v=g+u[w],S=g-u[b];g=ht(v,g,S)}const m=a.fn({...e,[f]:p,[h]:g});return{...m,data:{x:m.x-n,y:m.y-i,enabled:{[f]:r,[h]:l}}}}}};function lt(){return typeof window<"u"}function K(t){return Lt(t)?(t.nodeName||"").toLowerCase():"#document"}function E(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function B(t){var e;return(e=(Lt(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Lt(t){return lt()?t instanceof Node||t instanceof E(t).Node:!1}function O(t){return lt()?t instanceof Element||t instanceof E(t).Element:!1}function D(t){return lt()?t instanceof HTMLElement||t instanceof E(t).HTMLElement:!1}function Rt(t){return!lt()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof E(t).ShadowRoot}const ue=new Set(["inline","contents"]);function Z(t){const{overflow:e,overflowX:n,overflowY:i,display:o}=$(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+n)&&!ue.has(o)}const fe=new Set(["table","td","th"]);function de(t){return fe.has(K(t))}const he=[":popover-open",":modal"];function ct(t){return he.some(e=>{try{return t.matches(e)}catch{return!1}})}const pe=["transform","translate","scale","rotate","perspective"],ge=["transform","translate","scale","rotate","perspective","filter"],me=["paint","layout","strict","content"];function yt(t){const e=wt(),n=O(t)?$(t):t;return pe.some(i=>n[i]?n[i]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||ge.some(i=>(n.willChange||"").includes(i))||me.some(i=>(n.contain||"").includes(i))}function ye(t){let e=N(t);for(;D(e)&&!G(e);){if(yt(e))return e;if(ct(e))return null;e=N(e)}return null}function wt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const we=new Set(["html","body","#document"]);function G(t){return we.has(K(t))}function $(t){return E(t).getComputedStyle(t)}function at(t){return O(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function N(t){if(K(t)==="html")return t;const e=t.assignedSlot||t.parentNode||Rt(t)&&t.host||B(t);return Rt(e)?e.host:e}function Pt(t){const e=N(t);return G(e)?t.ownerDocument?t.ownerDocument.body:t.body:D(e)&&Z(e)?e:Pt(e)}function Ft(t,e,n){var i;e===void 0&&(e=[]);const o=Pt(t),s=o===((i=t.ownerDocument)==null?void 0:i.body),r=E(o);return s?(xt(r),e.concat(r,r.visualViewport||[],Z(o)?o:[],[])):e.concat(o,Ft(o,[]))}function xt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Dt(t){const e=$(t);let n=parseFloat(e.width)||0,i=parseFloat(e.height)||0;const o=D(t),s=o?t.offsetWidth:n,r=o?t.offsetHeight:i,l=ot(n)!==s||ot(i)!==r;return l&&(n=s,i=r),{width:n,height:i,$:l}}function Bt(t){return O(t)?t:t.contextElement}function J(t){const e=Bt(t);if(!D(e))return F(1);const n=e.getBoundingClientRect(),{width:i,height:o,$:s}=Dt(e);let r=(s?ot(n.width):n.width)/i,l=(s?ot(n.height):n.height)/o;return(!r||!Number.isFinite(r))&&(r=1),(!l||!Number.isFinite(l))&&(l=1),{x:r,y:l}}const xe=F(0);function _t(t){const e=E(t);return!wt()||!e.visualViewport?xe:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function be(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==E(t)?!1:e}function tt(t,e,n,i){e===void 0&&(e=!1),n===void 0&&(n=!1);const o=t.getBoundingClientRect(),s=Bt(t);let r=F(1);e&&(i?O(i)&&(r=J(i)):r=J(t));const l=be(s,n,i)?_t(s):F(0);let a=(o.left+l.x)/r.x,c=(o.top+l.y)/r.y,d=o.width/r.x,u=o.height/r.y;if(s){const h=E(s),f=i&&O(i)?E(i):i;let p=h,g=xt(p);for(;g&&i&&f!==p;){const m=J(g),w=g.getBoundingClientRect(),b=$(g),v=w.left+(g.clientLeft+parseFloat(b.paddingLeft))*m.x,S=w.top+(g.clientTop+parseFloat(b.paddingTop))*m.y;a*=m.x,c*=m.y,d*=m.x,u*=m.y,a+=v,c+=S,p=E(g),g=xt(p)}}return rt({width:d,height:u,x:a,y:c})}function ut(t,e){const n=at(t).scrollLeft;return e?e.left+n:tt(B(t)).left+n}function qt(t,e){const n=t.getBoundingClientRect(),i=n.left+e.scrollLeft-ut(t,n),o=n.top+e.scrollTop;return{x:i,y:o}}function ve(t){let{elements:e,rect:n,offsetParent:i,strategy:o}=t;const s=o==="fixed",r=B(i),l=e?ct(e.floating):!1;if(i===r||l&&s)return n;let a={scrollLeft:0,scrollTop:0},c=F(1);const d=F(0),u=D(i);if((u||!u&&!s)&&((K(i)!=="body"||Z(r))&&(a=at(i)),D(i))){const f=tt(i);c=J(i),d.x=f.x+i.clientLeft,d.y=f.y+i.clientTop}const h=r&&!u&&!s?qt(r,a):F(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-a.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-a.scrollTop*c.y+d.y+h.y}}function Se(t){return Array.from(t.getClientRects())}function Ae(t){const e=B(t),n=at(t),i=t.ownerDocument.body,o=k(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),s=k(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let r=-n.scrollLeft+ut(t);const l=-n.scrollTop;return $(i).direction==="rtl"&&(r+=k(e.clientWidth,i.clientWidth)-o),{width:o,height:s,x:r,y:l}}const Mt=25;function Te(t,e){const n=E(t),i=B(t),o=n.visualViewport;let s=i.clientWidth,r=i.clientHeight,l=0,a=0;if(o){s=o.width,r=o.height;const d=wt();(!d||d&&e==="fixed")&&(l=o.offsetLeft,a=o.offsetTop)}const c=ut(i);if(c<=0){const d=i.ownerDocument,u=d.body,h=getComputedStyle(u),f=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,p=Math.abs(i.clientWidth-u.clientWidth-f);p<=Mt&&(s-=p)}else c<=Mt&&(s+=c);return{width:s,height:r,x:l,y:a}}const Ce=new Set(["absolute","fixed"]);function Ee(t,e){const n=tt(t,!0,e==="fixed"),i=n.top+t.clientTop,o=n.left+t.clientLeft,s=D(t)?J(t):F(1),r=t.clientWidth*s.x,l=t.clientHeight*s.y,a=o*s.x,c=i*s.y;return{width:r,height:l,x:a,y:c}}function Nt(t,e,n){let i;if(e==="viewport")i=Te(t,n);else if(e==="document")i=Ae(B(t));else if(O(e))i=Ee(e,n);else{const o=_t(t);i={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return rt(i)}function Vt(t,e){const n=N(t);return n===e||!O(n)||G(n)?!1:$(n).position==="fixed"||Vt(n,e)}function Ie(t,e){const n=e.get(t);if(n)return n;let i=Ft(t,[]).filter(l=>O(l)&&K(l)!=="body"),o=null;const s=$(t).position==="fixed";let r=s?N(t):t;for(;O(r)&&!G(r);){const l=$(r),a=yt(r);!a&&l.position==="fixed"&&(o=null),(s?!a&&!o:!a&&l.position==="static"&&!!o&&Ce.has(o.position)||Z(r)&&!a&&Vt(t,r))?i=i.filter(d=>d!==r):o=l,r=N(r)}return e.set(t,i),i}function ke(t){let{element:e,boundary:n,rootBoundary:i,strategy:o}=t;const r=[...n==="clippingAncestors"?ct(e)?[]:Ie(e,this._c):[].concat(n),i],l=r[0],a=r.reduce((c,d)=>{const u=Nt(e,d,o);return c.top=k(u.top,c.top),c.right=A(u.right,c.right),c.bottom=A(u.bottom,c.bottom),c.left=k(u.left,c.left),c},Nt(e,l,o));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}}function Oe(t){const{width:e,height:n}=Dt(t);return{width:e,height:n}}function $e(t,e,n){const i=D(e),o=B(e),s=n==="fixed",r=tt(t,!0,s,e);let l={scrollLeft:0,scrollTop:0};const a=F(0);function c(){a.x=ut(o)}if(i||!i&&!s)if((K(e)!=="body"||Z(o))&&(l=at(e)),i){const f=tt(e,!0,s,e);a.x=f.x+e.clientLeft,a.y=f.y+e.clientTop}else o&&c();s&&!i&&o&&c();const d=o&&!i&&!s?qt(o,l):F(0),u=r.left+l.scrollLeft-a.x-d.x,h=r.top+l.scrollTop-a.y-d.y;return{x:u,y:h,width:r.width,height:r.height}}function bt(t){return $(t).position==="static"}function Wt(t,e){if(!D(t)||$(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return B(t)===n&&(n=n.ownerDocument.body),n}function Ht(t,e){const n=E(t);if(ct(t))return n;if(!D(t)){let o=N(t);for(;o&&!G(o);){if(O(o)&&!bt(o))return o;o=N(o)}return n}let i=Wt(t,e);for(;i&&de(i)&&bt(i);)i=Wt(i,e);return i&&G(i)&&bt(i)&&!yt(i)?n:i||ye(t)||n}const Le=async function(t){const e=this.getOffsetParent||Ht,n=this.getDimensions,i=await n(t.floating);return{reference:$e(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function Re(t){return $(t).direction==="rtl"}const Pe={convertOffsetParentRelativeRectToViewportRelativeRect:ve,getDocumentElement:B,getClippingRect:ke,getOffsetParent:Ht,getElementRects:Le,getClientRects:Se,getDimensions:Oe,getScale:J,isElement:O,isRTL:Re},Fe=ce,De=ae,Be=se,_e=oe,qe=(t,e,n)=>{const i=new Map,o={platform:Pe,...n},s={...o.platform,_c:i};return ne(t,e,{...o,platform:s})};function vt(t){try{return document.querySelector(t)}catch{return console.warn(`[Trailguide] Invalid selector: ${t}`),null}}function St(t){const e=t.getBoundingClientRect(),n=window.getComputedStyle(t);return e.width>0&&e.height>0&&n.visibility!=="hidden"&&n.display!=="none"&&n.opacity!=="0"}function jt(t){t.scrollIntoView({behavior:"instant",block:"center",inline:"nearest"})}function Me(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}function ft(t,e,n){const i=document.createElement(t);return e&&(i.className=e),n&&n.appendChild(i),i}function Ne(){return`${Date.now()}-${Math.random().toString(36).slice(2,11)}`}let At=null;function Ve(){return At||(At=Ne()),At}async function We(t,e){if(!t.endpoint)return;const n={...e,user_id:t.userId,session_id:Ve(),timestamp:new Date().toISOString()};try{const i=await fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});t.debug&&(i.ok?console.log("[Trailguide Analytics]",n):console.error(`[Trailguide Analytics] Server error: ${i.status}`))}catch(i){t.debug&&console.error("[Trailguide Analytics] Failed:",i)}}class Xt{constructor(e={}){I(this,"trail",null);I(this,"currentStepIndex",0);I(this,"isActive",!1);I(this,"options",{});I(this,"overlay",null);I(this,"tooltip",null);I(this,"arrowEl",null);I(this,"cleanupFns",[]);I(this,"stepCleanupFns",[]);I(this,"instanceId",`trailguide-${Date.now()}-${Math.random().toString(36).slice(2,7)}`);I(this,"stepTimerId",null);this.options=e}start(e){this.trail=e,this.currentStepIndex=0,this.isActive=!0,this.createOverlay(),this.showStep(),this.bindKeyboard(),this.emitAnalytics("trail_started")}stop(){var e,n;this.isActive?(this.emitAnalytics("trail_abandoned"),this.isActive=!1,this.cleanup(),(n=(e=this.options).onAbandoned)==null||n.call(e)):this.cleanup()}next(){!this.trail||!this.isActive||(this.emitAnalytics("step_completed"),this.currentStepIndex<this.trail.steps.length-1?(this.currentStepIndex++,this.showStep()):this.complete())}prev(){!this.trail||!this.isActive||this.currentStepIndex>0&&(this.currentStepIndex--,this.showStep())}skip(){var e,n;this.emitAnalytics("trail_skipped"),this.isActive=!1,this.cleanup(),(n=(e=this.options).onSkip)==null||n.call(e)}goToStep(e){!this.trail||!this.isActive||e>=0&&e<this.trail.steps.length&&(this.currentStepIndex=e,this.showStep())}complete(){var e,n;this.emitAnalytics("trail_completed"),this.isActive=!1,this.cleanup(),(n=(e=this.options).onComplete)==null||n.call(e)}createOverlay(){var i,o,s;this.overlay=ft("div","trailguide-overlay"),document.body.appendChild(this.overlay);const e=ft("div","trailguide-spotlight",this.overlay),n=`${this.instanceId}-mask`;e.innerHTML=`
|
|
2
2
|
<svg width="100%" height="100%">
|
|
3
3
|
<defs>
|
|
4
4
|
<mask id="${n}">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trailguide/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Framework-agnostic product tours. Tutorials as code for any web app.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/trailguide.js",
|
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"dev": "vite build --watch",
|
|
22
22
|
"build": "vite build && tsc --emitDeclarationOnly",
|
|
23
|
-
"typecheck": "tsc --noEmit"
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage"
|
|
24
27
|
},
|
|
25
28
|
"keywords": [
|
|
26
29
|
"product-tour",
|