@trailguide/core 0.1.1 → 0.1.3
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/dom.d.ts.map +1 -1
- package/dist/trailguide.d.ts.map +1 -1
- package/dist/trailguide.js +5 -5
- package/dist/trailguide.umd.js +3 -3
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/dom.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAOhE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAW9D;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAOhE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAW9D;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAO1D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI9C;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,qBAAqB,EACjE,GAAG,EAAE,CAAC,EACN,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,qBAAqB,CAAC,CAAC,CAAC,CAK1B"}
|
package/dist/trailguide.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trailguide.d.ts","sourceRoot":"","sources":["../src/trailguide.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAQ,iBAAiB,EAAa,MAAM,SAAS,CAAC;AAIzE,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAyB;IAGxC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,OAAO,CAA4B;IAG3C,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,UAAU,CAAwE;IAG1F,OAAO,CAAC,WAAW,CAA8C;gBAErD,OAAO,GAAE,iBAAsB;IAI3C,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAUzB,IAAI,IAAI,IAAI;IAWZ,IAAI,IAAI,IAAI;IAaZ,IAAI,IAAI,IAAI;IASZ,IAAI,IAAI,IAAI;IAOZ,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQ7B,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,aAAa;IA+CrB,OAAO,CAAC,QAAQ;IA2DhB,OAAO,CAAC,cAAc;IAiCtB,OAAO,CAAC,eAAe;YA+CT,aAAa;
|
|
1
|
+
{"version":3,"file":"trailguide.d.ts","sourceRoot":"","sources":["../src/trailguide.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAQ,iBAAiB,EAAa,MAAM,SAAS,CAAC;AAIzE,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAyB;IAGxC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,OAAO,CAA4B;IAG3C,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,UAAU,CAAwE;IAG1F,OAAO,CAAC,WAAW,CAA8C;gBAErD,OAAO,GAAE,iBAAsB;IAI3C,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAUzB,IAAI,IAAI,IAAI;IAWZ,IAAI,IAAI,IAAI;IAaZ,IAAI,IAAI,IAAI;IASZ,IAAI,IAAI,IAAI;IAOZ,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQ7B,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,aAAa;IA+CrB,OAAO,CAAC,QAAQ;IA2DhB,OAAO,CAAC,cAAc;IAiCtB,OAAO,CAAC,eAAe;YA+CT,aAAa;IA2C3B,OAAO,CAAC,YAAY;IAsBpB,OAAO,CAAC,OAAO;IAmBf,OAAO,CAAC,aAAa;CAetB;AAKD,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,UAAU,CAO3E;AAED,wBAAgB,IAAI,IAAI,IAAI,CAG3B;AAED,wBAAgB,IAAI,IAAI,IAAI,CAE3B;AAED,wBAAgB,IAAI,IAAI,IAAI,CAE3B;AAED,wBAAgB,IAAI,IAAI,IAAI,CAG3B"}
|
package/dist/trailguide.js
CHANGED
|
@@ -912,10 +912,9 @@ function Wt(t) {
|
|
|
912
912
|
return e.width > 0 && e.height > 0 && n.visibility !== "hidden" && n.display !== "none" && n.opacity !== "0";
|
|
913
913
|
}
|
|
914
914
|
function Me(t) {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
inline: "nearest"
|
|
915
|
+
const e = document.documentElement;
|
|
916
|
+
e.style.scrollBehavior = "auto", t.scrollIntoView({ block: "center", inline: "nearest" }), requestAnimationFrame(() => {
|
|
917
|
+
e.style.scrollBehavior = "";
|
|
919
918
|
});
|
|
920
919
|
}
|
|
921
920
|
function Ne(t) {
|
|
@@ -1008,7 +1007,7 @@ class Xe {
|
|
|
1008
1007
|
</defs>
|
|
1009
1008
|
<rect x="0" y="0" width="100%" height="100%" mask="url(#${n})" />
|
|
1010
1009
|
</svg>
|
|
1011
|
-
`, nt("div", "trailguide-highlight", this.overlay), this.tooltip = nt("div", "trailguide-tooltip"), this.tooltip.innerHTML = `
|
|
1010
|
+
`, nt("div", "trailguide-highlight", this.overlay), this.tooltip = nt("div", this.options.theme === "dark" ? "trailguide-tooltip dark" : "trailguide-tooltip"), this.tooltip.innerHTML = `
|
|
1012
1011
|
<div class="trailguide-tooltip-content">
|
|
1013
1012
|
<div class="trailguide-tooltip-header">
|
|
1014
1013
|
<h3 class="trailguide-tooltip-title"></h3>
|
|
@@ -1082,6 +1081,7 @@ class Xe {
|
|
|
1082
1081
|
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");
|
|
1083
1082
|
const { x: d, y: u, placement: h, middlewareData: f } = await qe(n, this.tooltip, {
|
|
1084
1083
|
placement: e.placement,
|
|
1084
|
+
strategy: "fixed",
|
|
1085
1085
|
middleware: [
|
|
1086
1086
|
Fe(12),
|
|
1087
1087
|
Be(),
|
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:"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=`
|
|
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,I)=>A in y?ti(y,A,{enumerable:!0,configurable:!0,writable:!0,value:I}):y[A]=I;var k=(y,A,I)=>ei(y,typeof A!="symbol"?A+"":A,I);const A=Math.min,I=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 I(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 kt=["left","right"],It=["right","left"],Ut=["top","bottom"],Qt=["bottom","top"];function Zt(t,e,n){switch(t){case"top":case"bottom":return n?e?It:kt:e?kt:It;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=I(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),s=I(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let r=-n.scrollLeft+ut(t);const l=-n.scrollTop;return $(i).direction==="rtl"&&(r+=I(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 ke(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 Ie(t){let{element:e,boundary:n,rootBoundary:i,strategy:o}=t;const r=[...n==="clippingAncestors"?ct(e)?[]:ke(e,this._c):[].concat(n),i],l=r[0],a=r.reduce((c,d)=>{const u=Nt(e,d,o);return c.top=I(u.top,c.top),c.right=A(u.right,c.right),c.bottom=A(u.bottom,c.bottom),c.left=I(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:Ie,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){const e=document.documentElement;e.style.scrollBehavior="auto",t.scrollIntoView({block:"center",inline:"nearest"}),requestAnimationFrame(()=>{e.style.scrollBehavior=""})}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={}){k(this,"trail",null);k(this,"currentStepIndex",0);k(this,"isActive",!1);k(this,"options",{});k(this,"overlay",null);k(this,"tooltip",null);k(this,"arrowEl",null);k(this,"cleanupFns",[]);k(this,"stepCleanupFns",[]);k(this,"instanceId",`trailguide-${Date.now()}-${Math.random().toString(36).slice(2,7)}`);k(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}">
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
</defs>
|
|
9
9
|
<rect x="0" y="0" width="100%" height="100%" mask="url(#${n})" />
|
|
10
10
|
</svg>
|
|
11
|
-
`,ft("div","trailguide-highlight",this.overlay),this.tooltip=ft("div","trailguide-tooltip"),this.tooltip.innerHTML=`
|
|
11
|
+
`,ft("div","trailguide-highlight",this.overlay),this.tooltip=ft("div",this.options.theme==="dark"?"trailguide-tooltip dark":"trailguide-tooltip"),this.tooltip.innerHTML=`
|
|
12
12
|
<div class="trailguide-tooltip-content">
|
|
13
13
|
<div class="trailguide-tooltip-header">
|
|
14
14
|
<h3 class="trailguide-tooltip-title"></h3>
|
|
@@ -27,4 +27,4 @@
|
|
|
27
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
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=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"})});
|
|
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,strategy:"fixed",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
|
@@ -21,6 +21,7 @@ export interface AnalyticsConfig {
|
|
|
21
21
|
debug?: boolean;
|
|
22
22
|
}
|
|
23
23
|
export interface TrailguideOptions {
|
|
24
|
+
theme?: 'light' | 'dark';
|
|
24
25
|
onComplete?: () => void;
|
|
25
26
|
onSkip?: () => void;
|
|
26
27
|
/** Fires when stop() is called while a tour is still active (e.g. user navigates away) */
|
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;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"}
|
|
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,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,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"}
|