npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

y-tour

v1.0.1

Published

漫游式导航

Downloads

7

Readme

https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a88c07f29a244612b1a7c94a11110569~tplv-k3u1fbpfcp-zoom-crop-mark:3024:3024:3024:1702.awebp?

安装

npm install -s y-tour

使用

<template>
  <!-- ...
    模版里随便写些内容,加上class或id
  ... -->
  <!-- 使用组件 -->
  <Tour ref="tourRef" v-model:show="showTour" :steps="steps">
      <!-- 使用插槽 -->
      <template #title="data">
        {{data.title}}
      </template>
  </Tour>
</template>
<script setup lang="ts">
import {onMounted, reactive, Ref, ref} from "vue";
import {Step} from "y-tour/src/TourHandler";
// 引入组件
import Tour from "y-tour";

// 控制导航是否展示
const showTour = ref(false)
// 导航组件实例
const tourRef = ref()

// 定义步骤信息
const steps: Step[] = [{
  el: ()=>document.getElementsByClassName('first-but')[0] as HTMLElement,
  beforeActive:(run)=>{
    // 有些情况dom元素不在窗口内,需要先滚动滚动条,然后调用run方法
    document.getElementsByClassName('tour-text')[0].scrollTo({top: 0})
    run()
  },
  title: '下一步',
  description: '点击这里可进行下一步操作'
},{
  el: ()=>document.getElementsByClassName('step-two')[0] as HTMLElement,
  placement: 'top',
  beforeActive:(run, getRect)=>{
    const {targetRect} = getRect()
    let scroll = targetRect.bottom<0? 10-targetRect.bottom:targetRect.bottom
    document.getElementsByClassName('tour-text')[0].scrollTo({top: scroll})
    run()
  },
  title: '第二部',
  description: '点击这个进入第二步'
},{
  el: ()=>document.getElementsByClassName('logo')[0] as HTMLElement,
},{
  el: ()=>document.getElementsByClassName('step-aaa')[0] as HTMLElement,
  beforeActive:(run, getRect)=>{
    const {targetRect} = getRect()
    let scroll = targetRect.top<0? -targetRect.top-10:targetRect.top
    document.getElementsByClassName('tour-text')[0].scrollTo({top: scroll})
    run()
  },
  title: '取消',
  description: '点击这里可取消操作'
},{
  el: ()=>document.getElementsByClassName('four-but')[0] as HTMLElement,
  beforeActive:(run)=>{
    document.getElementsByClassName('tour-text')[0].scrollTo({top: 0})
    run()
  }
},{
  el: ()=>document.getElementsByClassName('five-step')[0] as HTMLElement,
  beforeActive:(run)=>{
    document.getElementsByClassName('tour-text')[0].scrollTo({top: 0})
    run()
  }
},]

// 必须等页面挂在完成后才可以开始导航,否则获取不到dom节点
onMounted(()=>{
  // 打开导航可以使用v-model:show,也可以直接调用组件的open方法
  showTour.value = true
  // tourRef.value.open()
})
</script>

属性

| 属性名 | 说明 | 类型 | 默认值 | | :------------------------ | :------------- | :-------- | :----- | | show / v-model:show | 是否显示 | boolean | false | | current / v-model:current | 当前步骤 | number | 0 | | steps | 步骤列表 | Step[] | [] | | mask | 是否显示遮罩层 | boolean | true |

Step

interface Step{
    el: ()=>HTMLElement,
    title?: string,
    description?: string,
    placement?: 'top'|'bottom'|'left'|'right',
    beforeActive?: (run: (rectMap?: RectMap)=>void, getRect: ()=>RectMap)=>void,
    afterActive?: ()=>void
}
  • beforeActive钩子函数的参数为 run函数和getRect函数。

  • 调用getRect可以获得这次窗口渲染的位置信息RectMap

  • 调用run函数才能渲染本次步骤

  • run函数接受RectMap作为参数

  • 可以调用getRect获取RectMap,并对其进行修改,最后调用run函数即可实现对渲染的结果的影响

事件

| 事件名 | 说明 | 类型 | | :----- | :----------- | :--------- | | open | 导航被打开 | Function | | close | 导航被关闭 | Function | | change | 步骤切换 | Function | | next | 点击了下一步 | Function | | last | 点击了上一步 | Function |

方法

| 方法名 | 说明 | 类型 | | :----- | :--------- | :--------- | | open | 打开导航 | Function | | close | 关闭导航 | Function | | last | 切换上一步 | Function | | next | 切换下一步 | Function |

插槽

| 名称 | 说明 | | :---------- | :----------- | | default | 覆盖整个弹窗 | | title | 覆盖标题 | | close | 覆盖关闭按钮 | | description | 覆盖描述 | | footer | 覆盖底部 |