@@ -80,8 +80,18 @@ const highlightClass = computed(() =>
8080const _Tooltip = ref <HTMLElement >();
8181const _Backdrop = ref <HTMLElement >();
8282
83+ // Constants for timing and positioning
84+ const TELEPORT_RENDER_DELAY = 100 ; // ms to wait for Vue Teleport to render DOM elements
85+ const SCROLL_DURATION = 500 ; // ms for smooth scroll animation
86+ const SCROLL_OFFSET = - 100 ; // px offset from top when scrolling to element
87+
88+ // Helper to check if tour was completed and saved to localStorage
89+ const isTourCompleted = (): boolean => {
90+ return localStorage .getItem (saveKey .value ) === ' true' ;
91+ };
92+
8393const startTour = async (): Promise <void > => {
84- if (localStorage . getItem ( saveKey . value ) === ' true ' ) return ;
94+ if (isTourCompleted () ) return ;
8595
8696 if (props .saveToLocalStorage === ' step' ) {
8797 const savedStep = localStorage .getItem (saveKey .value );
@@ -116,7 +126,7 @@ const startTour = async (): Promise<void> => {
116126
117127 // Wait for Teleport to render DOM elements, then cache references
118128 await new Promise ((resolve ) => {
119- teleportDelayTimer = setTimeout (resolve , 100 );
129+ teleportDelayTimer = setTimeout (resolve , TELEPORT_RENDER_DELAY );
120130 });
121131
122132 if (! _Tooltip .value ) {
@@ -144,11 +154,13 @@ const startTour = async (): Promise<void> => {
144154 await nextTick ();
145155
146156 if (! vTour .value ) {
157+ // Calculate margin: use prop margin, or increase to 14px if highlighting is enabled
158+ const shouldHighlight = props .highlight || currentStepData .highlight ;
159+ const calculatedMargin = props .margin || (shouldHighlight ? 14 : 8 );
160+
147161 vTour .value = createPopper (targetElement , _Tooltip .value , {
148162 position: currentStepData .placement || props .defaultPlacement ,
149- margin:
150- props .margin ||
151- (props .highlight || currentStepData .highlight ? 14 : 8 ),
163+ margin: calculatedMargin ,
152164 });
153165 }
154166
@@ -319,8 +331,8 @@ const updatePosition = async (): Promise<void> => {
319331 if (! props .noScroll && ! currentStepData .noScroll ) {
320332 await new Promise <void >((resolve ) => {
321333 jump (targetElement , {
322- duration: 500 ,
323- offset: - 100 ,
334+ duration: SCROLL_DURATION ,
335+ offset: SCROLL_OFFSET ,
324336 callback : () => resolve (),
325337 });
326338 });
@@ -347,9 +359,9 @@ const updateHighlight = (): void => {
347359 .forEach ((element ) => element .classList .remove (highlightClass .value ));
348360
349361 const currentStepData = getCurrentStep .value ;
350- if (! props .highlight && ! currentStepData ?.highlight ) return ;
351362
352- if (! currentStepData ) {
363+ // Check if highlighting is disabled or no step data
364+ if (! currentStepData || (! props .highlight && ! currentStepData .highlight )) {
353365 return ;
354366 }
355367
@@ -375,7 +387,7 @@ const updateBackdrop = (): void => {
375387
376388// Redraw layers for resize/scroll events - updates position without scrolling or events
377389const redrawLayers = (): void => {
378- if (localStorage . getItem ( saveKey . value ) === ' true ' ) return ;
390+ if (isTourCompleted () ) return ;
379391 if (! tourVisible .value ) return ; // Only redraw if tour is active
380392
381393 updateTooltipPosition ();
@@ -387,7 +399,7 @@ let startDelayTimer: ReturnType<typeof setTimeout> | undefined;
387399let teleportDelayTimer: ReturnType <typeof setTimeout > | undefined ;
388400
389401const onResizeEnd = (): void => {
390- if (localStorage . getItem ( saveKey . value ) === ' true ' ) return ;
402+ if (isTourCompleted () ) return ;
391403
392404 clearTimeout (resizeTimer );
393405 redrawLayers ();
@@ -425,7 +437,7 @@ getClipPath.value = '';
425437
426438// Scroll handling to update position during scroll
427439const onScroll = (): void => {
428- if (localStorage . getItem ( saveKey . value ) === ' true ' ) return ;
440+ if (isTourCompleted () ) return ;
429441 if (! tourVisible .value ) return ; // Only update if tour is active
430442
431443 redrawLayers ();
0 commit comments