MCPcopy Index your code
hub / github.com/GuoQichen/vue-pswipe

github.com/GuoQichen/vue-pswipe @v0.15.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.15.3 ↗ · + Follow
96 symbols 199 edges 19 files 0 documented · 0% updated 3y ago★ 1064 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

vue-pswipe npm Build Status codecov

a Vue plugin for PhotoSwipe without set image size

online example

Edit Vue Template

install

npm install vue-pswipe

usage

// main.js
import Photoswipe from 'vue-pswipe'

Vue.use(Photoswipe, options)

see complete options

you can set v-pswp directive in element to mark as clickable

<Photoswipe>
    <img 
        :src="https://github.com/GuoQichen/vue-pswipe/raw/v0.15.3/imageSrc"
        v-pswp="imageSrc"
    />
</Photoswipe>

props

Property Type Description Default
options object original PhotoSwipe options, see complete options -
auto boolean automatically collect all img tags without the need for the v-pswp directive false
bubble boolean allow click event bubbling false
lazy boolean lazy loading image, you can set to false to preload all image true
rotate boolean add a rotate action button to the top bar, allow user to rotate the current image false

directive

v-pswp: object|string

use for mark current element as gallery item, accept image src or options object

Directive Options:

interface PswpDirectiveOptions {
    /**
     * path to image
     */
    src: string
    /**
     * image size, 'width x height', eg: '100x100'
     */
    size?: string
    /**
     * small image placeholder,
     * main (large) image loads on top of it,
     * if you skip this parameter - grey rectangle will be displayed,
     * try to define this property only when small image was loaded before
     */
    msrc?: string
    /**
     * used by Default PhotoSwipe UI
     * if you skip it, there won't be any caption
     */
    title?: string
    /**
     * to make URLs to a single image look like this: http://example.com/#&gid=1&pid=custom-first-id
     * instead of: http://example.com/#&gid=1&pid=1
     * enable options history: true, galleryPIDs: true and add pid (unique picture identifier) 
     */
    pid?: string | number
}

event

beforeOpen

emit after click thumbnail, if listen to this event, next function must be called to resolve this hook

Parameters: - event: - index: current image index - target: the target that triggers effective click event - next:

must be called to resolve the hook. `next(false)` will abort open PhotoSwipe

opened

emit after photoswipe init, you can get current active photoswipe instance by parameter

Parameters: - pswp:

current photoswipe instance

original PhotoSwipe event

support all original PhotoSwipe events, see original event, eg:

<Photoswipe @beforeChange="handleBeforeChange">
    <img 
        :src="https://github.com/GuoQichen/vue-pswipe/raw/v0.15.3/imageSrc"
        v-pswp="imageSrc"
    />
</Photoswipe>

custom html

In addition to using the <Photoswipe> tag, you can also use Vue.prototype.$Pswp.open(params) to directly open a PhotoSwipe. This is especially useful in the case of Custom HTML Content in Slides.

<template>
    <button @click="handleClick">open</button>
</template>
<script>
export default {
    methods: {
        handleClick() {
            this.$Pswp.open({
                items: [
                    {
                        html: '

hello vue-pswipe

'
                    }
                ]
            })
        }
    }
}
</script>

Vue.prototyp.$Pswp.open:

type Open = (params: {
    items: PswpItem[],
    options?: PswpOptions
}) => pswp

dynamic import

But cannot use vue.prototype.$Pswp.open()

<script>
export default {
    components: {
        Photoswipe: () => import('vue-pswipe')
            .then(({ Photoswipe }) => Photoswipe)
    } 
}
</script>

example

npm run dev

License

MIT

Extension points exported contracts — how you extend this code

$Pswp (Interface)
(no doc)
types/vue.d.ts
PswpDirectiveOptions (Interface)
(no doc)
src/type.ts
ImageComponent (Interface)
(no doc)
tests/unit/global.spec.ts
Vue (Interface)
(no doc)
types/vue.d.ts
PswpItem (Interface)
(no doc)
src/type.ts
createDirectivePswpArgs (Interface)
(no doc)
tests/unit/global.spec.ts
ManualImgItem (Interface)
(no doc)
src/type.ts
Window (Interface)
(no doc)
tests/unit/mock.d.ts

Core symbols most depended-on inside this repo

createPswp
called by 14
tests/unit/util.ts
isDef
called by 5
src/utils.ts
isImg
called by 4
src/utils.ts
createPswpUI
called by 4
tests/unit/util.ts
mount
called by 3
src/utils.ts
getScale
called by 3
src/utils.ts
setSize
called by 2
src/utils.ts
upperFirst
called by 2
src/utils.ts

Shape

Function 80
Interface 16

Languages

TypeScript100%

Modules by API surface

src/utils.ts49 symbols
tests/unit/util.ts15 symbols
src/type.ts10 symbols
tests/unit/photoswipe.spec.ts6 symbols
tests/unit/global.spec.ts5 symbols
tests/unit/pswpUI.spec.ts4 symbols
types/vue.d.ts2 symbols
src/main.ts2 symbols
src/config.ts2 symbols
tests/unit/mock.d.ts1 symbols

For agents

$ claude mcp add vue-pswipe \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact