LCOV - code coverage report
Current view: top level - src/platform/onboarding - TourSpotlight.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 87.2 % 47 41
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2           25 :   <div
       3              :     data-testid="coach-overlay"
       4              :     class="pointer-events-none fixed inset-0 z-tour"
       5              :   >
       6              :     <svg
       7              :       v-if="useMaskScrim"
       8              :       aria-hidden="true"
       9              :       class="pointer-events-none absolute inset-0 size-full"
      10              :     >
      11              :       <mask :id="maskId">
      12              :         <rect width="100%" height="100%" fill="white" />
      13              :         <rect
      14              :           v-if="scrimHole"
      15              :           data-testid="coach-mask-hole"
      16              :           v-bind="scrimHole"
      17              :           rx="12"
      18              :           fill="black"
      19              :           :class="
      20              :             !targetMoves &&
      21              :             'motion-safe:transition-[x,y,width,height] motion-safe:duration-300'
      22              :           "
      23              :         />
      24              :       </mask>
      25              :       <rect
      26              :         width="100%"
      27              :         height="100%"
      28              :         class="fill-black/60"
      29              :         :mask="`url(#${maskId})`"
      30              :       />
      31              :       <path
      32              :         v-if="step.interactive"
      33              :         data-testid="coach-hit-region"
      34              :         :d="hitRegion"
      35              :         fill="transparent"
      36              :         fill-rule="evenodd"
      37              :         class="pointer-events-auto"
      38              :       />
      39              :     </svg>
      40              :     <div
      41              :       v-if="!step.interactive"
      42              :       data-testid="coach-blocker"
      43              :       :class="
      44              :         cn(
      45              :           'pointer-events-auto absolute inset-0',
      46              :           !useMaskScrim && !targetRect && 'bg-black/60'
      47              :         )
      48              :       "
      49              :     />
      50              :     <div
      51              :       aria-hidden="true"
      52              :       data-testid="coach-spotlight"
      53              :       :class="
      54              :         cn(
      55              :           'pointer-events-none absolute rounded-xl outline-2 outline-white',
      56              :           !targetMoves &&
      57              :             'motion-safe:transition-[left,top,width,height,opacity] motion-safe:duration-300',
      58              :           !useMaskScrim &&
      59              :             'shadow-[0_0_0_9999px_color-mix(in_srgb,var(--color-black)_60%,transparent)]'
      60              :         )
      61              :       "
      62              :       :style="spotlightStyle"
      63              :     />
      64              :     <FocusScope
      65              :       as-child
      66              :       :trapped="!waitingForTarget && !step.interactive"
      67              :       loop
      68              :       @mount-auto-focus.prevent
      69              :     >
      70              :       <div
      71              :         ref="cardRef"
      72              :         data-testid="coach-card"
      73              :         role="dialog"
      74              :         :aria-modal="!step.interactive"
      75              :         :aria-labelledby="titleId"
      76              :         :aria-describedby="`${subtitleId} ${bodyId}`"
      77              :         :aria-busy="!stepSettled"
      78              :         tabindex="-1"
      79              :         :class="
      80              :           cn(
      81              :             'absolute motion-safe:duration-300',
      82              :             glides
      83              :               ? 'motion-safe:transition-[left,top,opacity]'
      84              :               : 'motion-safe:transition-opacity',
      85              :             cardVisible ? 'pointer-events-auto' : 'pointer-events-none'
      86              :           )
      87              :         "
      88              :         :style="cardStyle"
      89              :       >
      90              :         <i
      91              :           v-if="cursorClass"
      92              :           data-testid="coach-cursor"
      93              :           :class="
      94              :             cn(
      95              :               'absolute icon-[lucide--mouse-pointer-2] text-foreground drop-shadow-md',
      96              :               cursorClass
      97              :             )
      98              :           "
      99              :           aria-hidden="true"
     100              :         />
     101              :         <CoachmarkCard
     102              :           class="max-h-[calc(100vh-var(--comfy-topbar-height)-2rem)] overflow-y-auto"
     103              :           :subtitle="
     104              :             t('onboardingCoachmarks.stepLabel', {
     105              :               current: countedStepIdx + 1,
     106              :               total: countedStepsTotal
     107              :             })
     108              :           "
     109              :           :subtitle-id="subtitleId"
     110              :           :title
     111              :           :title-id="titleId"
     112              :           :message="body"
     113              :           :message-id="bodyId"
     114              :         >
     115              :           <template #actions>
     116              :             <Button
     117              :               v-if="showSkip"
     118              :               ref="skipButton"
     119              :               variant="textonly"
     120              :               size="md"
     121              :               @click="emit('skip')"
     122              :             >
     123              :               {{ skipLabel }}
     124              :             </Button>
     125              :             <div class="ml-auto flex items-center gap-3">
     126              :               <Button
     127              :                 v-if="canGoBack"
     128              :                 variant="secondary"
     129              :                 size="md"
     130              :                 class="border border-solid"
     131              :                 @click="emit('back')"
     132              :               >
     133              :                 <i class="icon-[lucide--arrow-left]" />
     134              :                 {{ backLabel }}
     135              :               </Button>
     136              :               <Button
     137              :                 v-if="!step.selfAdvancing"
     138              :                 ref="primaryButton"
     139              :                 variant="inverted"
     140              :                 size="md"
     141              :                 :disabled="waitingForTarget"
     142              :                 @click="emit('advance')"
     143              :               >
     144              :                 {{ primaryLabel }}
     145              :                 <i v-if="!isLast" class="icon-[lucide--arrow-right]" />
     146              :               </Button>
     147              :             </div>
     148              :           </template>
     149              :         </CoachmarkCard>
     150              :       </div>
     151              :     </FocusScope>
     152              :   </div>
     153              : </template>
     154              : 
     155              : <script setup lang="ts">
     156              : import { cn } from '@comfyorg/tailwind-utils'
     157              : import { useEventListener, useWindowSize } from '@vueuse/core'
     158              : import { FocusScope } from 'reka-ui'
     159              : import { computed, nextTick, ref, useId, useTemplateRef, watch } from 'vue'
     160              : import { useI18n } from 'vue-i18n'
     161              : 
     162              : import Button from '@comfyorg/design-system/button/Button'
     163              : 
     164              : import CoachmarkCard from '@comfyorg/design-system/card/CoachmarkCard'
     165              : import {
     166              :   CARD_WIDTH,
     167              :   SPOTLIGHT_PAD,
     168              :   VIEWPORT_MARGIN,
     169              :   CARD_GLIDE_MS,
     170              :   clampSpotlightRect,
     171              :   cursorEdgeClass,
     172              :   hitRegionPath,
     173              :   noTargetCardLeft
     174              : } from './coachmarkLayout'
     175              : import type { SpotlightStep } from './onboardingTours'
     176              : import { useCoachmarkTarget } from './useCoachmarkTarget'
     177              : 
     178              : const {
     179              :   step,
     180              :   title,
     181              :   body,
     182              :   isLast,
     183              :   canGoBack,
     184              :   primaryLabel,
     185              :   skipLabel,
     186              :   backLabel,
     187              :   countedStepIdx,
     188              :   countedStepsTotal,
     189              :   waitingForTarget,
     190              :   stepSettled
     191              : } = defineProps<{
     192              :   step: SpotlightStep
     193              :   title: string
     194              :   body: string
     195              :   isLast: boolean
     196              :   canGoBack: boolean
     197              :   primaryLabel: string
     198              :   skipLabel: string
     199              :   backLabel: string
     200              :   countedStepIdx: number
     201              :   countedStepsTotal: number
     202              :   waitingForTarget: boolean
     203              :   stepSettled: boolean
     204              : }>()
     205              : 
     206            3 : const emit = defineEmits<{
     207              :   advance: []
     208              :   back: []
     209              :   skip: []
     210              : }>()
     211              : 
     212            3 : const { t } = useI18n()
     213            3 : const bodyId = useId()
     214            3 : const subtitleId = useId()
     215            3 : const titleId = useId()
     216              : 
     217            3 : const cardRef = ref<HTMLElement | null>(null)
     218            3 : const { width: windowWidth, height: windowHeight } = useWindowSize()
     219              : 
     220            3 : const {
     221              :   targetRect,
     222              :   hasTarget,
     223              :   targetMoves,
     224              :   floatingStyles,
     225              :   isPositioned,
     226              :   placement
     227              : } = useCoachmarkTarget(() => step, cardRef)
     228              : 
     229              : // Last step's "Done" already dismisses, so hide Skip there.
     230            3 : const showSkip = computed(() => !isLast)
     231              : 
     232            3 : const primaryButton =
     233              :   useTemplateRef<InstanceType<typeof Button>>('primaryButton')
     234            3 : const skipButton = useTemplateRef<InstanceType<typeof Button>>('skipButton')
     235              : 
     236            7 : async function focusPrimary() {
     237            7 :   await nextTick()
     238              :   const el = (primaryButton.value?.$el ??
     239              :     skipButton.value?.$el ??
     240              :     cardRef.value) as HTMLElement | undefined
     241            7 :   el?.focus()
     242              : }
     243              : 
     244            3 : useEventListener(
     245              :   window,
     246              :   'keydown',
     247              :   (e: KeyboardEvent) => {
     248            6 :     if (e.key !== 'Escape') return
     249            0 :     e.preventDefault()
     250            0 :     e.stopPropagation()
     251            0 :     emit('skip')
     252              :   },
     253              :   { capture: true }
     254              : )
     255              : 
     256            3 : watch(
     257              :   [() => step, () => waitingForTarget],
     258              :   () => {
     259            8 :     if (!waitingForTarget) void focusPrimary()
     260              :   },
     261              :   { immediate: true }
     262              : )
     263              : 
     264           17 : function viewport() {
     265           17 :   return { width: windowWidth.value, height: windowHeight.value }
     266              : }
     267              : 
     268            3 : const maskId = useId()
     269              : 
     270            3 : const useMaskScrim = computed(() => !!step.interactive)
     271              : 
     272            3 : const scrimHole = computed(() =>
     273              :   targetRect.value
     274              :     ? clampSpotlightRect(targetRect.value, SPOTLIGHT_PAD, viewport())
     275              :     : null
     276              : )
     277              : 
     278            3 : const spotlightStyle = computed(() => {
     279           20 :   const hole = scrimHole.value
     280           20 :   if (!hole?.width || !hole.height) return { opacity: '0' }
     281           17 :   return {
     282              :     left: `${hole.x}px`,
     283              :     top: `${hole.y}px`,
     284              :     width: `${hole.width}px`,
     285              :     height: `${hole.height}px`,
     286              :     opacity: '1'
     287              :   }
     288              : })
     289              : 
     290            3 : const hitRegion = computed(() => hitRegionPath(viewport(), scrimHole.value))
     291              : 
     292              : /**
     293              :  * The card travels to a new target, then rides it — a transition lags a target
     294              :  * that moves every frame. Only a change arms travel; the first card makes none.
     295              :  */
     296            3 : const glides = ref(false)
     297            3 : watch([() => step, targetMoves], ([, moves], _previous, onCleanup) => {
     298            4 :   glides.value = true
     299            4 :   if (!moves) return
     300            0 :   const timer = setTimeout(() => (glides.value = false), CARD_GLIDE_MS)
     301            0 :   onCleanup(() => clearTimeout(timer))
     302              : })
     303              : 
     304              : /** Hidden until Floating UI has placed it, so it fades in already sited. */
     305            3 : const cardVisible = computed(() => !hasTarget.value || isPositioned.value)
     306              : 
     307            3 : const cardStyle = computed(() => {
     308           13 :   const width = `${CARD_WIDTH}px`
     309           13 :   const maxWidth = `calc(100vw - ${VIEWPORT_MARGIN * 2}px)`
     310           13 :   const opacity = cardVisible.value ? '1' : '0'
     311           13 :   if (!hasTarget.value) {
     312            0 :     return {
     313              :       width,
     314              :       maxWidth,
     315              :       left: `${noTargetCardLeft(windowWidth.value)}px`,
     316              :       top: '30%',
     317              :       opacity
     318              :     }
     319              :   }
     320           13 :   return { ...floatingStyles.value, width, maxWidth, opacity }
     321              : })
     322              : 
     323            3 : const cursorClass = computed(() =>
     324              :   step.cursor && hasTarget.value ? cursorEdgeClass(placement.value) : ''
     325              : )
     326              : </script>
        

Generated by: LCOV version 2.0-1