@trailguide/core 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics.d.ts +1 -1
- package/dist/analytics.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/storage.d.ts +21 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/trailguide.d.ts +1 -0
- package/dist/trailguide.d.ts.map +1 -1
- package/dist/trailguide.js +486 -416
- package/dist/trailguide.umd.js +4 -4
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -7
- package/LICENSE +0 -21
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 Ge=Object.defineProperty;var Je=(y,A,O)=>A in y?Ge(y,A,{enumerable:!0,configurable:!0,writable:!0,value:O}):y[A]=O;var P=(y,A,O)=>Je(y,typeof A!="symbol"?A+"":A,O);const A=Math.min,O=Math.max,nt=Math.round,D=t=>({x:t,y:t}),Wt={left:"right",right:"left",bottom:"top",top:"bottom"},Ht={start:"end",end:"start"};function ut(t,e,n){return O(t,A(e,n))}function J(t,e){return typeof t=="function"?t(e):t}function W(t){return t.split("-")[0]}function U(t){return t.split("-")[1]}function St(t){return t==="x"?"y":"x"}function dt(t){return t==="y"?"height":"width"}const jt=new Set(["top","bottom"]);function M(t){return jt.has(W(t))?"y":"x"}function ht(t){return St(M(t))}function zt(t,e,n){n===void 0&&(n=!1);const i=U(t),o=ht(t),s=dt(o);let r=o==="x"?i===(n?"end":"start")?"right":"left":i==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(r=ot(r)),[r,ot(r)]}function Xt(t){const e=ot(t);return[pt(t),e,pt(e)]}function pt(t){return t.replace(/start|end/g,e=>Ht[e])}const At=["left","right"],Ct=["right","left"],Yt=["top","bottom"],Kt=["bottom","top"];function Gt(t,e,n){switch(t){case"top":case"bottom":return n?e?Ct:At:e?At:Ct;case"left":case"right":return e?Yt:Kt;default:return[]}}function Jt(t,e,n,i){const o=U(t);let s=Gt(W(t),n==="start",i);return o&&(s=s.map(r=>r+"-"+o),e&&(s=s.concat(s.map(pt)))),s}function ot(t){return t.replace(/left|right|bottom|top/g,e=>Wt[e])}function Ut(t){return{top:0,right:0,bottom:0,left:0,...t}}function Tt(t){return typeof t!="number"?Ut(t):{top:t,right:t,bottom:t,left:t}}function st(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 Et(t,e,n){let{reference:i,floating:o}=t;const s=M(e),r=ht(e),l=dt(r),c=W(e),a=s==="y",d=i.x+i.width/2-o.width/2,f=i.y+i.height/2-o.height/2,h=i[l]/2-o[l]/2;let u;switch(c){case"top":u={x:d,y:i.y-o.height};break;case"bottom":u={x:d,y:i.y+i.height};break;case"right":u={x:i.x+i.width,y:f};break;case"left":u={x:i.x-o.width,y:f};break;default:u={x:i.x,y:i.y}}switch(U(e)){case"start":u[r]-=h*(n&&a?-1:1);break;case"end":u[r]+=h*(n&&a?-1:1);break}return u}async function Qt(t,e){var n;e===void 0&&(e={});const{x:i,y:o,platform:s,rects:r,elements:l,strategy:c}=t,{boundary:a="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:u=0}=J(e,t),p=Tt(u),m=l[h?f==="floating"?"reference":"floating":f],w=st(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:a,rootBoundary:d,strategy:c})),b=f==="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},R=st(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:b,offsetParent:v,strategy:c}):b);return{top:(w.top-R.top+p.top)/S.y,bottom:(R.bottom-w.bottom+p.bottom)/S.y,left:(w.left-R.left+p.left)/S.x,right:(R.right-w.right+p.right)/S.x}}const Zt=async(t,e,n)=>{const{placement:i="bottom",strategy:o="absolute",middleware:s=[],platform:r}=n,l=s.filter(Boolean),c=await(r.isRTL==null?void 0:r.isRTL(e));let a=await r.getElementRects({reference:t,floating:e,strategy:o}),{x:d,y:f}=Et(a,i,c),h=i,u={},p=0;for(let m=0;m<l.length;m++){var g;const{name:w,fn:b}=l[m],{x:v,y:S,data:R,reset:T}=await b({x:d,y:f,initialPlacement:i,placement:h,strategy:o,middlewareData:u,rects:a,platform:{...r,detectOverflow:(g=r.detectOverflow)!=null?g:Qt},elements:{reference:t,floating:e}});d=v??d,f=S??f,u={...u,[w]:{...u[w],...R}},T&&p<=50&&(p++,typeof T=="object"&&(T.placement&&(h=T.placement),T.rects&&(a=T.rects===!0?await r.getElementRects({reference:t,floating:e,strategy:o}):T.rects),{x:d,y:f}=Et(a,h,c)),m=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:u}},te=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:i,placement:o,rects:s,platform:r,elements:l,middlewareData:c}=e,{element:a,padding:d=0}=J(t,e)||{};if(a==null)return{};const f=Tt(d),h={x:n,y:i},u=ht(o),p=dt(u),g=await r.getDimensions(a),m=u==="y",w=m?"top":"left",b=m?"bottom":"right",v=m?"clientHeight":"clientWidth",S=s.reference[p]+s.reference[u]-h[u]-s.floating[p],R=h[u]-s.reference[u],T=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a));let H=T?T[v]:0;(!H||!await(r.isElement==null?void 0:r.isElement(T)))&&(H=l.floating[v]||s.floating[p]);const tt=S/2-R/2,j=H/2-g[p]/2-1,_=A(f[w],j),et=A(f[b],j),z=_,it=H-g[p]-et,C=H/2-g[p]/2+tt,X=ut(z,C,it),q=!c.arrow&&U(o)!=null&&C!==X&&s.reference[p]/2-(C<z?_:et)-g[p]/2<0,$=q?C<z?C-z:C-it:0;return{[u]:h[u]+$,data:{[u]:X,centerOffset:C-X-$,...q&&{alignmentOffset:$}},reset:q}}}),ee=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:c,elements:a}=e,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:g=!0,...m}=J(t,e);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const w=W(o),b=M(l),v=W(l)===l,S=await(c.isRTL==null?void 0:c.isRTL(a.floating)),R=h||(v||!g?[ot(l)]:Xt(l)),T=p!=="none";!h&&T&&R.push(...Jt(l,g,p,S));const H=[l,...R],tt=await c.detectOverflow(e,m),j=[];let _=((i=s.flip)==null?void 0:i.overflows)||[];if(d&&j.push(tt[w]),f){const C=zt(o,r,S);j.push(tt[C[0]],tt[C[1]])}if(_=[..._,{placement:o,overflows:j}],!j.every(C=>C<=0)){var et,z;const C=(((et=s.flip)==null?void 0:et.index)||0)+1,X=H[C];if(X&&(!(f==="alignment"?b!==M(X):!1)||_.every(I=>M(I.placement)===b?I.overflows[0]>0:!0)))return{data:{index:C,overflows:_},reset:{placement:X}};let q=(z=_.filter($=>$.overflows[0]<=0).sort(($,I)=>$.overflows[1]-I.overflows[1])[0])==null?void 0:z.placement;if(!q)switch(u){case"bestFit":{var it;const $=(it=_.filter(I=>{if(T){const N=M(I.placement);return N===b||N==="y"}return!0}).map(I=>[I.placement,I.overflows.filter(N=>N>0).reduce((N,Ke)=>N+Ke,0)]).sort((I,N)=>I[1]-N[1])[0])==null?void 0:it[0];$&&(q=$);break}case"initialPlacement":q=l;break}if(o!==q)return{reset:{placement:q}}}return{}}}},ie=new Set(["left","top"]);async function ne(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=U(n),c=M(n)==="y",a=ie.has(r)?-1:1,d=s&&c?-1:1,f=J(e,t);let{mainAxis:h,crossAxis:u,alignmentAxis:p}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return l&&typeof p=="number"&&(u=l==="end"?p*-1:p),c?{x:u*d,y:h*a}:{x:h*a,y:u*d}}const oe=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,c=await ne(e,t);return r===((n=l.offset)==null?void 0:n.placement)&&(i=l.arrow)!=null&&i.alignmentOffset?{}:{x:o+c.x,y:s+c.y,data:{...c,placement:r}}}}},se=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:c={fn:w=>{let{x:b,y:v}=w;return{x:b,y:v}}},...a}=J(t,e),d={x:n,y:i},f=await s.detectOverflow(e,a),h=M(W(o)),u=St(h);let p=d[u],g=d[h];if(r){const w=u==="y"?"top":"left",b=u==="y"?"bottom":"right",v=p+f[w],S=p-f[b];p=ut(v,p,S)}if(l){const w=h==="y"?"top":"left",b=h==="y"?"bottom":"right",v=g+f[w],S=g-f[b];g=ut(v,g,S)}const m=c.fn({...e,[u]:p,[h]:g});return{...m,data:{x:m.x-n,y:m.y-i,enabled:{[u]:r,[h]:l}}}}}};function rt(){return typeof window<"u"}function Y(t){return Ot(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=(Ot(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Ot(t){return rt()?t instanceof Node||t instanceof E(t).Node:!1}function k(t){return rt()?t instanceof Element||t instanceof E(t).Element:!1}function F(t){return rt()?t instanceof HTMLElement||t instanceof E(t).HTMLElement:!1}function kt(t){return!rt()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof E(t).ShadowRoot}const re=new Set(["inline","contents"]);function Q(t){const{overflow:e,overflowX:n,overflowY:i,display:o}=L(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+n)&&!re.has(o)}const le=new Set(["table","td","th"]);function ce(t){return le.has(Y(t))}const ae=[":popover-open",":modal"];function lt(t){return ae.some(e=>{try{return t.matches(e)}catch{return!1}})}const fe=["transform","translate","scale","rotate","perspective"],ue=["transform","translate","scale","rotate","perspective","filter"],de=["paint","layout","strict","content"];function gt(t){const e=mt(),n=k(t)?L(t):t;return fe.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)||ue.some(i=>(n.willChange||"").includes(i))||de.some(i=>(n.contain||"").includes(i))}function he(t){let e=V(t);for(;F(e)&&!K(e);){if(gt(e))return e;if(lt(e))return null;e=V(e)}return null}function mt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const pe=new Set(["html","body","#document"]);function K(t){return pe.has(Y(t))}function L(t){return E(t).getComputedStyle(t)}function ct(t){return k(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function V(t){if(Y(t)==="html")return t;const e=t.assignedSlot||t.parentNode||kt(t)&&t.host||B(t);return kt(e)?e.host:e}function Lt(t){const e=V(t);return K(e)?t.ownerDocument?t.ownerDocument.body:t.body:F(e)&&Q(e)?e:Lt(e)}function Rt(t,e,n){var i;e===void 0&&(e=[]);const o=Lt(t),s=o===((i=t.ownerDocument)==null?void 0:i.body),r=E(o);return s?(yt(r),e.concat(r,r.visualViewport||[],Q(o)?o:[],[])):e.concat(o,Rt(o,[]))}function yt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function $t(t){const e=L(t);let n=parseFloat(e.width)||0,i=parseFloat(e.height)||0;const o=F(t),s=o?t.offsetWidth:n,r=o?t.offsetHeight:i,l=nt(n)!==s||nt(i)!==r;return l&&(n=s,i=r),{width:n,height:i,$:l}}function It(t){return k(t)?t:t.contextElement}function G(t){const e=It(t);if(!F(e))return D(1);const n=e.getBoundingClientRect(),{width:i,height:o,$:s}=$t(e);let r=(s?nt(n.width):n.width)/i,l=(s?nt(n.height):n.height)/o;return(!r||!Number.isFinite(r))&&(r=1),(!l||!Number.isFinite(l))&&(l=1),{x:r,y:l}}const ge=D(0);function Pt(t){const e=E(t);return!mt()||!e.visualViewport?ge:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function me(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==E(t)?!1:e}function Z(t,e,n,i){e===void 0&&(e=!1),n===void 0&&(n=!1);const o=t.getBoundingClientRect(),s=It(t);let r=D(1);e&&(i?k(i)&&(r=G(i)):r=G(t));const l=me(s,n,i)?Pt(s):D(0);let c=(o.left+l.x)/r.x,a=(o.top+l.y)/r.y,d=o.width/r.x,f=o.height/r.y;if(s){const h=E(s),u=i&&k(i)?E(i):i;let p=h,g=yt(p);for(;g&&i&&u!==p;){const m=G(g),w=g.getBoundingClientRect(),b=L(g),v=w.left+(g.clientLeft+parseFloat(b.paddingLeft))*m.x,S=w.top+(g.clientTop+parseFloat(b.paddingTop))*m.y;c*=m.x,a*=m.y,d*=m.x,f*=m.y,c+=v,a+=S,p=E(g),g=yt(p)}}return st({width:d,height:f,x:c,y:a})}function at(t,e){const n=ct(t).scrollLeft;return e?e.left+n:Z(B(t)).left+n}function Dt(t,e){const n=t.getBoundingClientRect(),i=n.left+e.scrollLeft-at(t,n),o=n.top+e.scrollTop;return{x:i,y:o}}function ye(t){let{elements:e,rect:n,offsetParent:i,strategy:o}=t;const s=o==="fixed",r=B(i),l=e?lt(e.floating):!1;if(i===r||l&&s)return n;let c={scrollLeft:0,scrollTop:0},a=D(1);const d=D(0),f=F(i);if((f||!f&&!s)&&((Y(i)!=="body"||Q(r))&&(c=ct(i)),F(i))){const u=Z(i);a=G(i),d.x=u.x+i.clientLeft,d.y=u.y+i.clientTop}const h=r&&!f&&!s?Dt(r,c):D(0);return{width:n.width*a.x,height:n.height*a.y,x:n.x*a.x-c.scrollLeft*a.x+d.x+h.x,y:n.y*a.y-c.scrollTop*a.y+d.y+h.y}}function we(t){return Array.from(t.getClientRects())}function xe(t){const e=B(t),n=ct(t),i=t.ownerDocument.body,o=O(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),s=O(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let r=-n.scrollLeft+at(t);const l=-n.scrollTop;return L(i).direction==="rtl"&&(r+=O(e.clientWidth,i.clientWidth)-o),{width:o,height:s,x:r,y:l}}const Ft=25;function be(t,e){const n=E(t),i=B(t),o=n.visualViewport;let s=i.clientWidth,r=i.clientHeight,l=0,c=0;if(o){s=o.width,r=o.height;const d=mt();(!d||d&&e==="fixed")&&(l=o.offsetLeft,c=o.offsetTop)}const a=at(i);if(a<=0){const d=i.ownerDocument,f=d.body,h=getComputedStyle(f),u=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,p=Math.abs(i.clientWidth-f.clientWidth-u);p<=Ft&&(s-=p)}else a<=Ft&&(s+=a);return{width:s,height:r,x:l,y:c}}const ve=new Set(["absolute","fixed"]);function Se(t,e){const n=Z(t,!0,e==="fixed"),i=n.top+t.clientTop,o=n.left+t.clientLeft,s=F(t)?G(t):D(1),r=t.clientWidth*s.x,l=t.clientHeight*s.y,c=o*s.x,a=i*s.y;return{width:r,height:l,x:c,y:a}}function Bt(t,e,n){let i;if(e==="viewport")i=be(t,n);else if(e==="document")i=xe(B(t));else if(k(e))i=Se(e,n);else{const o=Pt(t);i={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return st(i)}function _t(t,e){const n=V(t);return n===e||!k(n)||K(n)?!1:L(n).position==="fixed"||_t(n,e)}function Ae(t,e){const n=e.get(t);if(n)return n;let i=Rt(t,[]).filter(l=>k(l)&&Y(l)!=="body"),o=null;const s=L(t).position==="fixed";let r=s?V(t):t;for(;k(r)&&!K(r);){const l=L(r),c=gt(r);!c&&l.position==="fixed"&&(o=null),(s?!c&&!o:!c&&l.position==="static"&&!!o&&ve.has(o.position)||Q(r)&&!c&&_t(t,r))?i=i.filter(d=>d!==r):o=l,r=V(r)}return e.set(t,i),i}function Ce(t){let{element:e,boundary:n,rootBoundary:i,strategy:o}=t;const r=[...n==="clippingAncestors"?lt(e)?[]:Ae(e,this._c):[].concat(n),i],l=r[0],c=r.reduce((a,d)=>{const f=Bt(e,d,o);return a.top=O(f.top,a.top),a.right=A(f.right,a.right),a.bottom=A(f.bottom,a.bottom),a.left=O(f.left,a.left),a},Bt(e,l,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Te(t){const{width:e,height:n}=$t(t);return{width:e,height:n}}function Ee(t,e,n){const i=F(e),o=B(e),s=n==="fixed",r=Z(t,!0,s,e);let l={scrollLeft:0,scrollTop:0};const c=D(0);function a(){c.x=at(o)}if(i||!i&&!s)if((Y(e)!=="body"||Q(o))&&(l=ct(e)),i){const u=Z(e,!0,s,e);c.x=u.x+e.clientLeft,c.y=u.y+e.clientTop}else o&&a();s&&!i&&o&&a();const d=o&&!i&&!s?Dt(o,l):D(0),f=r.left+l.scrollLeft-c.x-d.x,h=r.top+l.scrollTop-c.y-d.y;return{x:f,y:h,width:r.width,height:r.height}}function wt(t){return L(t).position==="static"}function qt(t,e){if(!F(t)||L(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return B(t)===n&&(n=n.ownerDocument.body),n}function Mt(t,e){const n=E(t);if(lt(t))return n;if(!F(t)){let o=V(t);for(;o&&!K(o);){if(k(o)&&!wt(o))return o;o=V(o)}return n}let i=qt(t,e);for(;i&&ce(i)&&wt(i);)i=qt(i,e);return i&&K(i)&&wt(i)&&!gt(i)?n:i||he(t)||n}const Oe=async function(t){const e=this.getOffsetParent||Mt,n=this.getDimensions,i=await n(t.floating);return{reference:Ee(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function ke(t){return L(t).direction==="rtl"}const Le={convertOffsetParentRelativeRectToViewportRelativeRect:ye,getDocumentElement:B,getClippingRect:Ce,getOffsetParent:Mt,getElementRects:Oe,getClientRects:we,getDimensions:Te,getScale:G,isElement:k,isRTL:ke},Re=oe,$e=se,Ie=ee,Pe=te,De=(t,e,n)=>{const i=new Map,o={platform:Le,...n},s={...o.platform,_c:i};return Zt(t,e,{...o,platform:s})};function xt(t){try{return document.querySelector(t)}catch{return console.warn(`[Trailguide] Invalid selector: ${t}`),null}}function bt(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 Vt(t){t.scrollIntoView({behavior:"smooth",block:"center",inline:"center"})}function Fe(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 Be(){return`${Date.now()}-${Math.random().toString(36).slice(2,11)}`}let vt=null;function _e(){return vt||(vt=Be()),vt}async function qe(t,e){if(!t.endpoint)return;const n={...e,user_id:t.userId,session_id:_e(),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 Nt{constructor(e={}){P(this,"trail",null);P(this,"currentStepIndex",0);P(this,"isActive",!1);P(this,"options",{});P(this,"overlay",null);P(this,"tooltip",null);P(this,"arrowEl",null);P(this,"cleanupFns",[]);P(this,"stepCleanupFns",[]);P(this,"instanceId",`trailguide-${Date.now()}-${Math.random().toString(36).slice(2,7)}`);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(){this.isActive=!1,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:"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=`
|
|
2
2
|
<svg width="100%" height="100%">
|
|
3
3
|
<defs>
|
|
4
4
|
<mask id="${n}">
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
</div>
|
|
25
25
|
<div class="trailguide-tooltip-arrow"></div>
|
|
26
26
|
</div>
|
|
27
|
-
`,document.body.appendChild(this.tooltip),this.arrowEl=this.tooltip.querySelector(".trailguide-tooltip-arrow"),(i=this.tooltip.querySelector(".trailguide-tooltip-close"))==null||i.addEventListener("click",()=>this.skip()),(o=this.tooltip.querySelector(".trailguide-btn-prev"))==null||o.addEventListener("click",()=>this.prev()),(s=this.tooltip.querySelector(".trailguide-btn-next"))==null||s.addEventListener("click",()=>this.next())}showStep(){if(!this.trail||!this.overlay||!this.tooltip)return;this.stepCleanupFns.forEach(
|
|
28
|
-
<p style="color: #ef4444; margin: 0 0 8px 0;">Could not find: <code style="background: #fee2e2; padding: 2px 6px; border-radius: 4px; font-size: 12px;">${
|
|
27
|
+
`,document.body.appendChild(this.tooltip),this.arrowEl=this.tooltip.querySelector(".trailguide-tooltip-arrow"),(i=this.tooltip.querySelector(".trailguide-tooltip-close"))==null||i.addEventListener("click",()=>this.skip()),(o=this.tooltip.querySelector(".trailguide-btn-prev"))==null||o.addEventListener("click",()=>this.prev()),(s=this.tooltip.querySelector(".trailguide-btn-next"))==null||s.addEventListener("click",()=>this.next())}showStep(){var l,a;if(!this.trail||!this.overlay||!this.tooltip)return;this.stepTimerId!==null&&(clearTimeout(this.stepTimerId),this.stepTimerId=null),this.stepCleanupFns.forEach(c=>c()),this.stepCleanupFns=[],this.tooltip.style.transform="";const e=this.overlay.querySelector(".trailguide-spotlight"),n=this.overlay.querySelector(".trailguide-highlight");e&&(e.style.display=""),n&&(n.style.display="");const i=this.trail.steps[this.currentStepIndex];if(!i)return;this.emitAnalytics("step_viewed");const o=vt(i.target),s=!o,r=o?!St(o):!1;if(s||r){if(i.optional){this.currentStepIndex<this.trail.steps.length-1?(this.currentStepIndex++,this.showStep()):this.complete();return}const c=s?"element_not_found":"element_not_visible";(a=(l=this.options).onError)==null||a.call(l,i,c),console.warn(`[Trailguide] Target not found or not visible: ${i.target}`),this.showErrorState(i);return}jt(o),this.stepTimerId=setTimeout(()=>{var c,d;this.stepTimerId=null,this.isActive&&(this.updateSpotlight(o),this.updateTooltip(i,o),(d=(c=this.options).onStepChange)==null||d.call(c,i,this.currentStepIndex))},100)}showErrorState(e){var u,h;if(!this.tooltip||!this.trail)return;const n=(u=this.overlay)==null?void 0:u.querySelector(".trailguide-spotlight"),i=(h=this.overlay)==null?void 0:h.querySelector(".trailguide-highlight");n&&(n.style.display="none"),i&&(i.style.display="none");const o=this.tooltip.querySelector(".trailguide-tooltip-title"),s=this.tooltip.querySelector(".trailguide-tooltip-body"),r=this.tooltip.querySelector(".trailguide-tooltip-progress"),l=this.tooltip.querySelector(".trailguide-btn-prev"),a=this.tooltip.querySelector(".trailguide-btn-next"),c=this.currentStepIndex===0,d=this.currentStepIndex===this.trail.steps.length-1;o&&(o.textContent="Element Not Found"),s&&(s.innerHTML=`
|
|
28
|
+
<p style="color: #ef4444; margin: 0 0 8px 0;">Could not find: <code style="background: #fee2e2; padding: 2px 6px; border-radius: 4px; font-size: 12px;">${Me(e.target)}</code></p>
|
|
29
29
|
<p style="margin: 0; font-size: 13px; color: #6b7280;">The target element doesn't exist on this page. Press <kbd style="background: #f3f4f6; padding: 2px 6px; border-radius: 4px; font-size: 11px;">Esc</kbd> to close or skip to the next step.</p>
|
|
30
|
-
`),r&&(r.textContent=`${this.currentStepIndex+1} of ${this.trail.steps.length}`),l&&(l.style.display=
|
|
30
|
+
`),r&&(r.textContent=`${this.currentStepIndex+1} of ${this.trail.steps.length}`),l&&(l.style.display=c?"none":"block"),a&&(a.textContent=d?"Close":"Skip Step"),this.tooltip.style.left="50%",this.tooltip.style.top="50%",this.tooltip.style.transform="translate(-50%, -50%)"}updateSpotlight(e){if(!this.overlay)return;const n=e.getBoundingClientRect(),i=8,o=this.overlay.querySelector(".trailguide-cutout");o&&(o.setAttribute("x",String(n.left-i)),o.setAttribute("y",String(n.top-i)),o.setAttribute("width",String(n.width+i*2)),o.setAttribute("height",String(n.height+i*2)));const s=this.overlay.querySelector(".trailguide-highlight");s&&(s.style.top=`${n.top-i}px`,s.style.left=`${n.left-i}px`,s.style.width=`${n.width+i*2}px`,s.style.height=`${n.height+i*2}px`);const r=()=>{if(!this.isActive)return;const l=e.getBoundingClientRect();o&&(o.setAttribute("x",String(l.left-i)),o.setAttribute("y",String(l.top-i)),o.setAttribute("width",String(l.width+i*2)),o.setAttribute("height",String(l.height+i*2))),s&&(s.style.top=`${l.top-i}px`,s.style.left=`${l.left-i}px`,s.style.width=`${l.width+i*2}px`,s.style.height=`${l.height+i*2}px`)};window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),this.stepCleanupFns.push(()=>{window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)})}async updateTooltip(e,n){if(!this.tooltip||!this.trail||!this.arrowEl)return;const i=this.currentStepIndex===0,o=this.currentStepIndex===this.trail.steps.length-1,s=this.tooltip.querySelector(".trailguide-tooltip-title"),r=this.tooltip.querySelector(".trailguide-tooltip-body"),l=this.tooltip.querySelector(".trailguide-tooltip-progress"),a=this.tooltip.querySelector(".trailguide-btn-prev"),c=this.tooltip.querySelector(".trailguide-btn-next");s&&(s.textContent=e.title),r&&(r.textContent=e.content),l&&(l.textContent=`${this.currentStepIndex+1} of ${this.trail.steps.length}`),a&&(a.style.display=i?"none":"block"),c&&(c.textContent=o?"Finish":"Next");const{x:d,y:u,placement:h,middlewareData:f}=await qe(n,this.tooltip,{placement:e.placement,middleware:[Fe(12),Be(),De({padding:8}),_e({element:this.arrowEl})]});if(!(!this.tooltip||!this.isActive)&&(this.tooltip.style.left=`${d}px`,this.tooltip.style.top=`${u}px`,this.tooltip.dataset.placement=h,f.arrow&&this.arrowEl)){const{x:p,y:g}=f.arrow;this.arrowEl.style.left=p!=null?`${p}px`:"",this.arrowEl.style.top=g!=null?`${g}px`:""}}bindKeyboard(){const e=n=>{if(this.isActive)switch(n.key){case"ArrowRight":case"Enter":this.next();break;case"ArrowLeft":this.prev();break;case"Escape":this.skip();break}};window.addEventListener("keydown",e),this.cleanupFns.push(()=>window.removeEventListener("keydown",e))}cleanup(){var e,n;this.stepTimerId!==null&&(clearTimeout(this.stepTimerId),this.stepTimerId=null),this.stepCleanupFns.forEach(i=>i()),this.stepCleanupFns=[],this.cleanupFns.forEach(i=>i()),this.cleanupFns=[],(e=this.overlay)==null||e.remove(),(n=this.tooltip)==null||n.remove(),this.overlay=null,this.tooltip=null,this.arrowEl=null}emitAnalytics(e){if(!this.options.analytics||!this.trail)return;const n=this.trail.steps[this.currentStepIndex],i=this.options.analytics.trailId||this.trail.id;We(this.options.analytics,{event_type:e,trail_id:i,step_id:n==null?void 0:n.id,step_index:this.currentStepIndex})}}let x=null;function He(t,e){return x&&x.stop(),x=new Xt(e),x.start(t),x}function je(){x==null||x.stop(),x=null}function Xe(){x==null||x.next()}function ze(){x==null||x.prev()}function Ye(){x==null||x.skip(),x=null}const Ke={bgBase:"#0f172a",bgCard:"#1e293b",bgGlass:"rgba(255,255,255,0.06)",bgInput:"rgba(255,255,255,0.03)",textPrimary:"#f8fafc",textSecondary:"#e2e8f0",textTertiary:"#cbd5e1",textMuted:"#94a3b8",textFaint:"#64748b",borderSubtle:"rgba(255,255,255,0.06)",borderPanel:"rgba(255,255,255,0.08)",borderControl:"rgba(255,255,255,0.1)",accent:"#1a91a2",accentBg:"rgba(26,145,162,0.15)",accentBorder:"rgba(26,145,162,0.3)",error:"#ef4444",errorBg:"rgba(239,68,68,0.1)",errorBorder:"rgba(239,68,68,0.3)",errorLight:"rgba(248,113,113,0.1)",errorText:"#fca5a5",success:"#10b981",successBg:"rgba(16,185,129,0.1)",successBorder:"rgba(16,185,129,0.3)",successText:"#6ee7b7",warningBg:"rgba(234,179,8,0.1)",disabled:"#9ca3af",disabledBg:"#4b5563",shadowLight:"0 4px 12px rgba(0,0,0,0.15)",shadowMedium:"0 4px 20px rgba(0,0,0,0.4)",shadowOverlay:"rgba(0,0,0,0.3)"};function Ge(t){const e=[],n=[];return t.id||e.push({stepId:"",stepIndex:-1,type:"missing_required_field",message:'Trail is missing required "id" field'}),!t.steps||t.steps.length===0?(e.push({stepId:"",stepIndex:-1,type:"missing_required_field",message:"Trail has no steps"}),{valid:!1,errors:e,warnings:n}):(t.steps.forEach((i,o)=>{if(i.id||e.push({stepId:`step-${o}`,stepIndex:o,type:"missing_required_field",message:`Step ${o+1} is missing required "id" field`}),!i.target){e.push({stepId:i.id||`step-${o}`,stepIndex:o,type:"missing_required_field",message:`Step ${o+1} is missing required "target" field`});return}const s=vt(i.target);s?St(s)||n.push({stepId:i.id,stepIndex:o,type:"hidden_target",message:`Step ${o+1} ("${i.title}"): Target element exists but is hidden`,selector:i.target}):e.push({stepId:i.id,stepIndex:o,type:"missing_target",message:`Step ${o+1} ("${i.title}"): Target element not found`,selector:i.target}),i.target&&Je(i.target)&&n.push({stepId:i.id,stepIndex:o,type:"unstable_selector",message:`Step ${o+1}: Consider using data-trail-id for more stable targeting`,selector:i.target})}),{valid:e.length===0,errors:e,warnings:n})}function Je(t){return t.startsWith("#")||t.includes("[data-")?!1:!!(t.includes(":nth-child")||t.includes(":nth-of-type")||/^\.[a-z]+-[a-z0-9]+$/i.test(t))}function Ue(t){if(t.valid&&t.warnings.length===0){console.log("%c✓ Trail validation passed","color: green; font-weight: bold");return}t.errors.length>0&&(console.group("%c✗ Trail validation errors","color: red; font-weight: bold"),t.errors.forEach(e=>{console.error(`Step ${e.stepIndex+1}: ${e.message}`),e.selector&&console.error(` Selector: ${e.selector}`)}),console.groupEnd()),t.warnings.length>0&&(console.group("%c⚠ Trail validation warnings","color: orange; font-weight: bold"),t.warnings.forEach(e=>{console.warn(`Step ${e.stepIndex+1}: ${e.message}`),e.selector&&console.warn(` Selector: ${e.selector}`)}),console.groupEnd())}const Tt="trailguide:";function Ct(t){return`${Tt}completed:${t}`}function dt(t){return`${Tt}progress:${t}`}function H(){try{return typeof window<"u"?window.localStorage:null}catch{return null}}const Qe={hasCompleted(t){var e;return((e=H())==null?void 0:e.getItem(Ct(t)))==="true"},markCompleted(t){var e;(e=H())==null||e.setItem(Ct(t),"true")},getProgress(t){var i;const e=(i=H())==null?void 0:i.getItem(dt(t));if(e==null)return null;const n=parseInt(e,10);return isNaN(n)?null:n},saveProgress(t,e){var n;(n=H())==null||n.setItem(dt(t),String(e))},clearProgress(t){var e;(e=H())==null||e.removeItem(dt(t))},reset(t){const e=H();e==null||e.removeItem(Ct(t)),e==null||e.removeItem(dt(t))},resetAll(){const t=H();if(!t)return;const e=[];for(let n=0;n<t.length;n++){const i=t.key(n);i!=null&&i.startsWith(Tt)&&e.push(i)}e.forEach(n=>t.removeItem(n))}};y.Trailguide=Xt,y.findElement=vt,y.isElementVisible=St,y.logValidationResults=Ue,y.next=Xe,y.prev=ze,y.scrollToElement=jt,y.skip=Ye,y.start=He,y.stop=je,y.theme=Ke,y.tourStorage=Qe,y.validateTrail=Ge,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface Step {
|
|
|
5
5
|
placement: Placement;
|
|
6
6
|
title: string;
|
|
7
7
|
content: string;
|
|
8
|
+
/** When true, silently skip this step if the target element is not found or not visible */
|
|
9
|
+
optional?: boolean;
|
|
8
10
|
}
|
|
9
11
|
export interface Trail {
|
|
10
12
|
id: string;
|
|
@@ -21,7 +23,11 @@ export interface AnalyticsConfig {
|
|
|
21
23
|
export interface TrailguideOptions {
|
|
22
24
|
onComplete?: () => void;
|
|
23
25
|
onSkip?: () => void;
|
|
26
|
+
/** Fires when stop() is called while a tour is still active (e.g. user navigates away) */
|
|
27
|
+
onAbandoned?: () => void;
|
|
24
28
|
onStepChange?: (step: Step, index: number) => void;
|
|
29
|
+
/** Fires when a step's target element cannot be found or is not visible */
|
|
30
|
+
onError?: (step: Step, error: 'element_not_found' | 'element_not_visible') => void;
|
|
25
31
|
analytics?: AnalyticsConfig;
|
|
26
32
|
}
|
|
27
33
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAE5D,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAE5D,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,0FAA0F;IAC1F,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,2EAA2E;IAC3E,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,mBAAmB,GAAG,qBAAqB,KAAK,IAAI,CAAC;IACnF,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trailguide/core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Framework-agnostic product tours. Tutorials as code for any web app.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/trailguide.js",
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"dev": "vite build --watch",
|
|
22
|
+
"build": "vite build && tsc --emitDeclarationOnly",
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
24
|
+
},
|
|
20
25
|
"keywords": [
|
|
21
26
|
"product-tour",
|
|
22
27
|
"onboarding",
|
|
@@ -45,10 +50,5 @@
|
|
|
45
50
|
"typescript": "^5.4.0",
|
|
46
51
|
"vite": "^5.2.0",
|
|
47
52
|
"vite-plugin-dts": "^3.8.0"
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"dev": "vite build --watch",
|
|
51
|
-
"build": "vite build && tsc --emitDeclarationOnly",
|
|
52
|
-
"typecheck": "tsc --noEmit"
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Branden Langhals
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|