vue-3-fullscreen-image-directive-plugin
Advanced tools
Comparing version 1.0.2 to 1.0.4
@@ -1,3 +0,3 @@ | ||
import { defineComponent as k, useCssVars as y, ref as w, onMounted as C, openBlock as r, createBlock as _, Transition as b, withCtx as x, createElementBlock as u, createElementVNode as t, createCommentVNode as m, pushScopeId as B, popScopeId as I, createApp as O, h as E } from "vue"; | ||
const h = (e) => (B("data-v-6a2154a7"), e = e(), I(), e), F = { class: "icons" }, U = /* @__PURE__ */ h(() => /* @__PURE__ */ t("svg", { | ||
import { defineComponent as O, useCssVars as D, ref as y, computed as _, onMounted as L, openBlock as s, createBlock as b, Transition as j, withCtx as A, createElementBlock as i, createElementVNode as t, createCommentVNode as v, TransitionGroup as R, normalizeClass as B, Fragment as U, renderList as P, pushScopeId as N, popScopeId as S, createApp as T, h as H } from "vue"; | ||
const h = (o) => (N("data-v-93357dc8"), o = o(), S(), o), V = { class: "icons" }, M = /* @__PURE__ */ h(() => /* @__PURE__ */ t("svg", { | ||
xmlns: "http://www.w3.org/2000/svg", | ||
@@ -19,5 +19,5 @@ viewBox: "0 0 24 24", | ||
}) | ||
], -1)), L = [ | ||
U | ||
], R = /* @__PURE__ */ h(() => /* @__PURE__ */ t("svg", { | ||
], -1)), q = [ | ||
M | ||
], z = /* @__PURE__ */ h(() => /* @__PURE__ */ t("svg", { | ||
xmlns: "http://www.w3.org/2000/svg", | ||
@@ -43,10 +43,38 @@ viewBox: "0 0 24 24", | ||
}) | ||
], -1)), j = [ | ||
R | ||
], A = { class: "image-container" }, D = ["src", "alt"], H = /* @__PURE__ */ k({ | ||
], -1)), G = [ | ||
z | ||
], K = ["disabled"], W = /* @__PURE__ */ h(() => /* @__PURE__ */ t("svg", { | ||
xmlns: "http://www.w3.org/2000/svg", | ||
viewBox: "0 0 24 24", | ||
fill: "none", | ||
stroke: "currentColor", | ||
"stroke-width": "2", | ||
"stroke-linecap": "round", | ||
"stroke-linejoin": "round" | ||
}, [ | ||
/* @__PURE__ */ t("polyline", { points: "15 18 9 12 15 6" }) | ||
], -1)), J = [ | ||
W | ||
], Q = ["src", "alt"], X = ["disabled"], Y = /* @__PURE__ */ h(() => /* @__PURE__ */ t("svg", { | ||
xmlns: "http://www.w3.org/2000/svg", | ||
viewBox: "0 0 24 24", | ||
fill: "none", | ||
stroke: "currentColor", | ||
"stroke-width": "2", | ||
"stroke-linecap": "round", | ||
"stroke-linejoin": "round" | ||
}, [ | ||
/* @__PURE__ */ t("polyline", { points: "9 6 15 12 9 18" }) | ||
], -1)), Z = [ | ||
Y | ||
], $ = { | ||
key: 1, | ||
class: "image-container" | ||
}, ee = ["src", "alt"], oe = /* @__PURE__ */ O({ | ||
__name: "FullscreenImage", | ||
props: { | ||
imageUrl: {}, | ||
anchor: {}, | ||
animation: { default: "fade" }, | ||
imageAlt: {}, | ||
imageAlt: { default: "" }, | ||
withDownload: { type: Boolean, default: !0 }, | ||
@@ -58,36 +86,43 @@ withClose: { type: Boolean, default: !0 }, | ||
maxHeight: { default: "80vh" }, | ||
maxWidth: { default: "80vw" } | ||
maxWidth: { default: "80vw" }, | ||
backdropColor: { default: "rgba(0, 0, 0, 0.7)" } | ||
}, | ||
emits: ["close"], | ||
setup(e, { emit: c }) { | ||
y((o) => ({ | ||
"451bdd16": o.maxHeight | ||
setup(o, { emit: c }) { | ||
D((e) => ({ | ||
"08ac7e39": e.backdropColor, | ||
"06c3e192": e.maxHeight | ||
})); | ||
const n = e, i = c, l = w(!1), s = () => { | ||
l.value = !0, setTimeout(() => { | ||
i("close"); | ||
const l = o, u = c, n = y(0), a = y(!1), d = () => { | ||
a.value = !0, setTimeout(() => { | ||
u("close"); | ||
}, 500); | ||
}, f = async () => { | ||
}, m = async (e) => { | ||
e.preventDefault(), e.stopPropagation(); | ||
try { | ||
const p = await (await fetch(n.imageUrl)).blob(), a = document.createElement("a"); | ||
a.href = window.URL.createObjectURL(p), a.download = "image", a.style.display = "none", document.body.appendChild(a), a.click(), document.body.removeChild(a), window.URL.revokeObjectURL(a.href); | ||
} catch (o) { | ||
console.error("Error downloading image:", o); | ||
const p = Array.isArray(l.imageUrl) ? l.imageUrl[n.value] : l.imageUrl, g = await (await fetch(p)).blob(), r = document.createElement("a"); | ||
r.href = window.URL.createObjectURL(g), r.download = "image", r.style.display = "none", document.body.appendChild(r), r.click(), document.body.removeChild(r), window.URL.revokeObjectURL(r.href); | ||
} catch (p) { | ||
console.error("Error downloading image:", p); | ||
} | ||
}, g = (o) => { | ||
n.withCloseOnEscape && o.key === "Escape" && s(); | ||
}, v = () => { | ||
n.closeOnClikOutside && s(); | ||
}, d = w(); | ||
return C(() => { | ||
n.withFocusOnClose && d.value && d.value.focus(); | ||
}), (o, p) => (r(), _(b, { | ||
name: o.animation, | ||
}, x = (e) => { | ||
l.withCloseOnEscape && e.key === "Escape" && d(); | ||
}, I = () => { | ||
l.closeOnClikOutside && d(); | ||
}, f = _(() => n.value === 0), C = _(() => n.value === l.imageUrl.length - 1), E = () => { | ||
n.value--; | ||
}, F = () => { | ||
n.value++; | ||
}, w = y(); | ||
return L(() => { | ||
l.withFocusOnClose && w.value && w.value.focus(); | ||
}), (e, p) => (s(), b(j, { | ||
name: e.animation, | ||
appear: "" | ||
}, { | ||
default: x(() => [ | ||
o.imageUrl && !l.value ? (r(), u("div", { | ||
default: A(() => [ | ||
e.imageUrl && !a.value ? (s(), i("div", { | ||
key: 0, | ||
class: "fullscreen-image", | ||
onKeydown: g, | ||
onKeydown: x, | ||
tabindex: "0", | ||
@@ -100,30 +135,60 @@ role: "dialog", | ||
class: "backdrop", | ||
onClick: v | ||
onClick: I | ||
}, [ | ||
t("div", F, [ | ||
o.withDownload ? (r(), u("button", { | ||
t("div", V, [ | ||
e.withDownload ? (s(), i("button", { | ||
key: 0, | ||
tabindex: "0", | ||
class: "icon download-icon", | ||
onClick: f, | ||
onClick: m, | ||
title: "close" | ||
}, L)) : m("", !0), | ||
o.withClose ? (r(), u("button", { | ||
}, q)) : v("", !0), | ||
e.withClose ? (s(), i("button", { | ||
key: 1, | ||
ref_key: "closeButtonRef", | ||
ref: d, | ||
ref: w, | ||
tabindex: "0", | ||
class: "icon close-icon", | ||
onClick: s, | ||
onClick: d, | ||
title: "download" | ||
}, j, 512)) : m("", !0) | ||
}, G, 512)) : v("", !0) | ||
]) | ||
]), | ||
t("div", A, [ | ||
Array.isArray(e.imageUrl) ? (s(), b(R, { | ||
key: 0, | ||
name: "list", | ||
tag: "div", | ||
class: "image-container" | ||
}, { | ||
default: A(() => [ | ||
t("button", { | ||
key: "previouus", | ||
disabled: f.value, | ||
class: B(["icon", f.value && "icon--disabled"]), | ||
onClick: E | ||
}, J, 10, K), | ||
(s(!0), i(U, null, P(e.imageUrl, (k, g) => (s(), i(U, { | ||
key: k + g | ||
}, [ | ||
n.value === g ? (s(), i("img", { | ||
key: 0, | ||
src: k, | ||
alt: Array.isArray(e.imageAlt) ? e.imageAlt[n.value] : e.imageAlt | ||
}, null, 8, Q)) : v("", !0) | ||
], 64))), 128)), | ||
t("button", { | ||
key: "neeext", | ||
disabled: C.value, | ||
class: B(["icon", C.value && "icon--disabled"]), | ||
onClick: F | ||
}, Z, 10, X) | ||
]), | ||
_: 1 | ||
})) : (s(), i("div", $, [ | ||
t("img", { | ||
src: o.imageUrl, | ||
alt: o.imageAlt | ||
}, null, 8, D) | ||
]) | ||
], 32)) : m("", !0) | ||
src: e.imageUrl, | ||
alt: Array.isArray(e.imageAlt) ? e.imageAlt[n.value] : e.imageAlt | ||
}, null, 8, ee) | ||
])) | ||
], 32)) : v("", !0) | ||
]), | ||
@@ -133,30 +198,31 @@ _: 1 | ||
} | ||
}), S = (e, c) => { | ||
const n = e.__vccOpts || e; | ||
for (const [i, l] of c) | ||
n[i] = l; | ||
return n; | ||
}, V = /* @__PURE__ */ S(H, [["__scopeId", "data-v-6a2154a7"]]), M = { | ||
mounted(e, c) { | ||
const n = () => { | ||
const l = O({ | ||
}), te = (o, c) => { | ||
const l = o.__vccOpts || o; | ||
for (const [u, n] of c) | ||
l[u] = n; | ||
return l; | ||
}, ne = /* @__PURE__ */ te(oe, [["__scopeId", "data-v-93357dc8"]]), le = { | ||
mounted(o, c) { | ||
const l = () => { | ||
var m; | ||
const n = T({ | ||
render() { | ||
return E(V, { ...c.value, onClose: () => i(l, s) }); | ||
return H(ne, { ...c.value, onClose: () => u(n, a) }); | ||
} | ||
}), s = document.createElement("div"); | ||
document.body.appendChild(s), l.mount(s); | ||
}, i = (l, s) => { | ||
l.unmount(), s.remove(); | ||
}), a = document.createElement("div"), d = document.querySelector(((m = c.value) == null ? void 0 : m.anchor) || "body"); | ||
d && (d.appendChild(a), n.mount(a)); | ||
}, u = (n, a) => { | ||
n.unmount(), a.remove(); | ||
}; | ||
e.style.cursor = "pointer", e.addEventListener("click", n), e.openFullscreenImage = n; | ||
o.style.cursor = "pointer", o.addEventListener("click", l), o.openFullscreenImage = l; | ||
}, | ||
beforeUnmount(e) { | ||
e.removeEventListener("click", e.openFullscreenImage); | ||
beforeUnmount(o) { | ||
o.removeEventListener("click", o.openFullscreenImage); | ||
} | ||
}; | ||
function P(e) { | ||
e.directive("fullscreen-image", M); | ||
function ae(o) { | ||
o.directive("fullscreen-image", le); | ||
} | ||
export { | ||
P as fullscreenImagePlugin | ||
ae as fullscreenImagePlugin | ||
}; |
{ | ||
"name": "vue-3-fullscreen-image-directive-plugin", | ||
"version": "1.0.2", | ||
"version": "1.0.4", | ||
"description": "Vue 3 plugin to open an image in a modal on click", | ||
@@ -13,3 +13,8 @@ "keywords": [ | ||
"vue-3", | ||
"directive" | ||
"directive", | ||
"panorama", | ||
"viewer", | ||
"image lightbox", | ||
"gallery", | ||
"vuejs" | ||
], | ||
@@ -33,3 +38,3 @@ "homepage": "https://gitlab.com/totol.toolsuite/vue-3-fullscreen-image", | ||
".": { | ||
"types": "./dist/types.d.ts", | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/vue-3-fullscreen-image.js", | ||
@@ -36,0 +41,0 @@ "require": "./dist/vue-3-fullscreen-image.umd.cjs" |
# Vue 3 Fullscreen Image Directive Plugin | ||
A lightweight Vue.js plugin for creating a fullscreen image modal with customizable options. | ||
A lightweight Vue.js plugin for creating a fullscreen image modal with customizable options, that support panorama display. | ||
![Demo](https://i.imgur.com/pTAguLR.gif) | ||
## Features | ||
@@ -11,2 +9,4 @@ | ||
- **Panorama Support:** Now supports panorama images! Pass an array of `imageUrl` to create a panorama view. | ||
- **Accessible:** We prioritize accessibility to ensure that our package can be easily used by everyone, including users with disabilities. | ||
@@ -36,3 +36,3 @@ | ||
import { fullscreenImagePlugin } from './fullscreen-image-plugin' | ||
import 'vue-3-fullscreen-image-directive-plugin/style.css' | ||
import 'vue-3-fullscreen-image-directive-plugin/style.css' // Don't forget to import the style | ||
@@ -45,2 +45,6 @@ createApp(App).use(fullscreenImagePlugin).mount('#app') | ||
#### Single Image | ||
![Demo single](https://i.imgur.com/pTAguLR.gif) | ||
```vue | ||
@@ -53,3 +57,3 @@ <template> | ||
}" | ||
src="https://placehold.co/200x400" | ||
src="https://placehold.co/200x400" | ||
/> | ||
@@ -59,2 +63,18 @@ </template> | ||
#### Panorama Images | ||
![Demo panorama](https://i.imgur.com/h8Z9jNQ.gif) | ||
```vue | ||
<template> | ||
<img v-fullscreen-image="{ | ||
imageUrl: ['https://placehold.co/2000x4000', 'https://placehold.co/1100x1100'], | ||
withDownload: true, | ||
animation: 'blur', | ||
}" | ||
src="https://placehold.co/200x400" | ||
/> | ||
</template> | ||
``` | ||
### Directive Options | ||
@@ -65,2 +85,3 @@ | ||
|imageUrl | (string, required) | The URL of the image to display | | ||
|anchor | (string, optional, default: 'body') | Selector for the element to which the modal will be mounted. | | ||
|animation | (string, optional, default: 'fade') | Animation type ('fade', 'blur', 'none'). | | ||
@@ -75,2 +96,3 @@ |imageAlt | (string, optional) | Alt text for the image. | | ||
|maxWidth | (string, optional, default: '80vw') | Maximum width of the image container. | | ||
|backdropColor | (string, optional, default: 'rgba(0, 0, 0, 0.7)') | Color of the modal backdrop. | | ||
@@ -77,0 +99,0 @@ ## Author |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22253
336
98
9
3