-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wenqing
committed
Dec 1, 2023
1 parent
7e902a7
commit c3a8083
Showing
4 changed files
with
67 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),V=require("viewerjs"),P=(e,n=!0,a,l)=>{const o=t.ref(),c=t.ref(""),s=t.ref(!1),i=t.ref(!1),p=t.ref(!1),u=t.ref(!1),v=t.ref(),m=()=>{v.value=new IntersectionObserver(w=>{w.forEach(g=>{const{intersectionRatio:y,target:f}=g;if(y>0&&!f.classList.contains("lazy-loaded")){const r=new Image;u.value=!0,r.addEventListener("load",d=>{f.classList.add("lazy-loaded"),c.value=e,p.value=!0,s.value=!0,i.value=!1,u.value=!1,l&&l(d)}),r.addEventListener("error",d=>{f.classList.add("lazy-loaded"),p.value=!0,i.value=!0,s.value=!1,u.value=!1,a&&a(d)}),r.src=e}})},{threshold:[1]}),o.value&&v.value.observe(o.value)};return t.onMounted(()=>{n?m():c.value=e}),t.onUnmounted(()=>{var w;o.value&&((w=v.value)==null||w.unobserve(o.value))}),{lazySrc:c,lazyloadSuccess:s,lazyloadError:i,lazyloaded:p,lazyloading:u,lazyloadTrigger:o}};function _(e){return typeof e[0]=="string"}const L=t.defineComponent({props:{modelValue:{type:Boolean,default:!1},currentPreviewIndex:{type:Number,default:0},previewSrcList:{type:Array,default:()=>[]},viewerOptions:{type:Object,default:()=>({})},viewerTitle:{type:Function,default:void 0},zIndex:{type:[Number,String],default:2015}},emits:["update:modelValue","update:currentPreviewIndex","switch"],setup(e,{emit:n}){const{modelValue:a,previewSrcList:l,currentPreviewIndex:o}=t.toRefs(e),c=t.computed(()=>l.value&&l.value.length>0),s=t.ref(),i=()=>{var r;(r=s.value)==null||r.view(u.value)};t.watch(a,r=>{r&&i()});const p=t.computed(()=>c.value?_(l.value)?l.value.map(r=>({src:r,alt:r})):l.value:[]),u=t.computed({get(){return o.value},set(r){n("update:currentPreviewIndex",r)}}),v=t.computed(()=>l.value.length||0),m=()=>{const r=document.createElement("div");return p.value.forEach(d=>{const h=new Image;Object.keys(d).forEach(z=>{h[z]=d[z]}),r.appendChild(h)}),r.addEventListener("view",d=>{const h=d;u.value=h.detail.index,n("switch",u.value,s.value)}),r.addEventListener("hidden",d=>{console.log(d),n("update:modelValue",!1)}),r},w=t.computed(()=>e.viewerTitle?r=>e.viewerTitle(r,{index:u.value,total:v.value}):r=>`${r.alt} (${u.value+1}/${v.value})`),g=t.computed(()=>Object.assign({title:w.value,zIndex:e.zIndex},e.viewerOptions)),y=()=>{c.value&&(s.value=new V(m(),g.value),a.value&&i())},f=()=>{y()};return t.onMounted(()=>{f()}),t.onUnmounted(()=>{var r;(r=s.value)==null||r.destroy()}),{hasPreviewList:c,PreviewListLength:v,finalPreviewSrcList:p,viewer:s,handleImgView:i}}});const S=(e,n)=>{const a=e.__vccOpts||e;for(const[l,o]of n)a[l]=o;return a},E={class:"image-viewer"};function O(e,n,a,l,o,c){return t.openBlock(),t.createElementBlock("div",E)}const b=S(L,[["render",O],["__scopeId","data-v-2617510c"]]);const k=t.defineComponent({name:"PreviewableImage",components:{ImageViewer:b},props:{width:{type:String,default:void 0},height:{type:String,default:void 0},src:{type:String,default:""},alt:{type:String,default:""},referrerPolicy:{type:String,default:void 0},fit:{type:String,default:"fill"},zIndex:{type:[Number,String],default:2015},previewSrcList:{type:Array,default:()=>[]},currentPreviewIndex:{type:Number,default:0},viewerOptions:{type:Object,default:()=>({})},viewerTitle:{type:Function,default:void 0},lazy:{type:Boolean,default:!0}},emits:["switch","update:currentPreviewIndex","load","error"],setup(e,{emit:n}){const{previewSrcList:a,currentPreviewIndex:l}=t.toRefs(e),o=t.computed(()=>({"--img-object-fit":e.fit})),{lazySrc:c,lazyloadTrigger:s,lazyloading:i,lazyloadError:p,lazyloadSuccess:u}=P(e.src,e.lazy,r=>{n("load",r)},r=>{n("error",r)}),v=t.computed(()=>a.value&&a.value.length>0),m=t.computed(()=>!(!v.value||e.lazy&&!u.value)),w=t.ref(!1),g=()=>{v.value&&(w.value=!0)},y=t.computed({get(){return l.value},set(r){n("update:currentPreviewIndex",r)}});return{lazyloadTrigger:s,imgStyleVars:o,hasPreviewList:v,lazySrc:c,lazyloading:i,lazyloadError:p,lazyloadSuccess:u,showImageViewer:w,handleImgView:g,currentViewerIndex:y,handleSwitch:(r,d)=>{n("switch",r,d)},initViewer:m}}});const $={key:0,class:"previewable-image__placeholder"},B={key:1,class:"previewable-image__error"},T=["src","alt","referrerpolicy"];function N(e,n,a,l,o,c){const s=t.resolveComponent("ImageViewer");return t.openBlock(),t.createElementBlock("div",{ref:"lazyloadTrigger",class:"previewable-image",style:t.normalizeStyle([{width:e.width,height:e.height},e.imgStyleVars])},[e.lazy&&e.lazyloading?(t.openBlock(),t.createElementBlock("div",$,[t.renderSlot(e.$slots,"placeholder",{},()=>[t.createTextVNode("Loading...")])])):e.lazy&&e.lazyloadError?(t.openBlock(),t.createElementBlock("div",B,[t.renderSlot(e.$slots,"error",{},()=>[t.createTextVNode("Load Error")])])):(t.openBlock(),t.createElementBlock("img",{key:2,src:e.lazySrc,alt:e.alt,referrerpolicy:e.referrerPolicy,class:t.normalizeClass(["previewable-image__inner",{"previewable-image__preview":e.hasPreviewList}]),onClick:n[0]||(n[0]=(...i)=>e.handleImgView&&e.handleImgView(...i))},null,10,T)),e.initViewer?(t.openBlock(),t.createBlock(s,{key:3,modelValue:e.showImageViewer,"onUpdate:modelValue":n[1]||(n[1]=i=>e.showImageViewer=i),"current-preview-index":e.currentViewerIndex,"onUpdate:currentPreviewIndex":n[2]||(n[2]=i=>e.currentViewerIndex=i),"preview-src-list":e.previewSrcList,"viewer-options":e.viewerOptions,"viewer-title":e.viewerTitle,"z-index":e.zIndex,onSwitch:e.handleSwitch},null,8,["modelValue","current-preview-index","preview-src-list","viewer-options","viewer-title","z-index","onSwitch"])):t.createCommentVNode("",!0)],4)}const I=S(k,[["render",N]]),j=(e,n)=>{const a=Object.assign({componentName:I.name,defaultViewerOptions:{}},n);e.component(a.componentName,I),V.setDefaults(a.defaultViewerOptions)},x={install:j};exports.Viewer=V;exports.ImageViewer=b;exports.PreviewableImage=I;exports.default=x; | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),V=require("viewerjs"),P=(e,n=!0,a,l)=>{const o=t.ref(),d=t.ref(""),s=t.ref(!1),i=t.ref(!1),p=t.ref(!1),u=t.ref(!1),c=t.ref(),m=()=>{c.value=new IntersectionObserver(w=>{w.forEach(g=>{const{intersectionRatio:y,target:f}=g;if(y>0&&!f.classList.contains("lazy-loaded")){const r=new Image;u.value=!0,r.addEventListener("load",v=>{f.classList.add("lazy-loaded"),d.value=e,p.value=!0,s.value=!0,i.value=!1,u.value=!1,l&&l(v)}),r.addEventListener("error",v=>{f.classList.add("lazy-loaded"),p.value=!0,i.value=!0,s.value=!1,u.value=!1,a&&a(v)}),r.src=e}})},{threshold:[1]}),o.value&&c.value.observe(o.value)};return t.onMounted(()=>{n?m():d.value=e}),t.onUnmounted(()=>{var w;o.value&&((w=c.value)==null||w.unobserve(o.value))}),{lazySrc:d,lazyloadSuccess:s,lazyloadError:i,lazyloaded:p,lazyloading:u,lazyloadTrigger:o}};function _(e){return typeof e[0]=="string"}const L=t.defineComponent({props:{modelValue:{type:Boolean,default:!1},currentPreviewIndex:{type:Number,default:0},previewSrcList:{type:Array,default:()=>[]},viewerOptions:{type:Object,default:()=>({})},viewerTitle:{type:Function,default:void 0},zIndex:{type:[Number,String],default:2015}},emits:["update:modelValue","update:currentPreviewIndex","switch"],setup(e,{emit:n}){const{modelValue:a,previewSrcList:l,currentPreviewIndex:o}=t.toRefs(e),d=t.computed(()=>l.value&&l.value.length>0),s=t.ref(),i=()=>{var r;(r=s.value)==null||r.view(u.value)};t.watch(a,r=>{r&&i()});const p=t.computed(()=>d.value?_(l.value)?l.value.map(r=>({src:r,alt:r})):l.value:[]),u=t.computed({get(){return o.value},set(r){n("update:currentPreviewIndex",r)}}),c=t.computed(()=>l.value.length||0),m=()=>{const r=document.createElement("div");return p.value.forEach(v=>{const h=new Image;Object.keys(v).forEach(z=>{h[z]=v[z]}),r.appendChild(h)}),r.addEventListener("view",v=>{const h=v;u.value=h.detail.index,n("switch",u.value,s.value)}),r.addEventListener("hidden",()=>{n("update:modelValue",!1)}),r},w=t.computed(()=>e.viewerTitle?r=>e.viewerTitle(r,{index:u.value,total:c.value}):r=>`${r.alt} (${u.value+1}/${c.value})`),g=t.computed(()=>Object.assign({title:w.value,zIndex:e.zIndex},e.viewerOptions)),y=()=>{d.value&&(s.value=new V(m(),g.value),a.value&&i())},f=()=>{y()};return t.onMounted(()=>{f()}),t.onUnmounted(()=>{var r;(r=s.value)==null||r.destroy()}),{hasPreviewList:d,PreviewListLength:c,finalPreviewSrcList:p,viewer:s,handleImgView:i}}});const S=(e,n)=>{const a=e.__vccOpts||e;for(const[l,o]of n)a[l]=o;return a},E={class:"image-viewer"};function O(e,n,a,l,o,d){return t.openBlock(),t.createElementBlock("div",E)}const b=S(L,[["render",O],["__scopeId","data-v-def9c787"]]);const k=t.defineComponent({name:"PreviewableImage",components:{ImageViewer:b},props:{width:{type:String,default:void 0},height:{type:String,default:void 0},src:{type:String,default:""},alt:{type:String,default:""},referrerPolicy:{type:String,default:void 0},fit:{type:String,default:"fill"},zIndex:{type:[Number,String],default:2015},previewSrcList:{type:Array,default:()=>[]},currentPreviewIndex:{type:Number,default:0},viewerOptions:{type:Object,default:()=>({})},viewerTitle:{type:Function,default:void 0},lazy:{type:Boolean,default:!0}},emits:["switch","update:currentPreviewIndex","load","error"],setup(e,{emit:n}){const{previewSrcList:a,currentPreviewIndex:l}=t.toRefs(e),o=t.computed(()=>({"--img-object-fit":e.fit})),{lazySrc:d,lazyloadTrigger:s,lazyloading:i,lazyloadError:p,lazyloadSuccess:u}=P(e.src,e.lazy,r=>{n("load",r)},r=>{n("error",r)}),c=t.computed(()=>a.value&&a.value.length>0),m=t.computed(()=>!(!c.value||e.lazy&&!u.value)),w=t.ref(!1),g=()=>{c.value&&(w.value=!0)},y=t.computed({get(){return l.value},set(r){n("update:currentPreviewIndex",r)}});return{lazyloadTrigger:s,imgStyleVars:o,hasPreviewList:c,lazySrc:d,lazyloading:i,lazyloadError:p,lazyloadSuccess:u,showImageViewer:w,handleImgView:g,currentViewerIndex:y,handleSwitch:(r,v)=>{n("switch",r,v)},initViewer:m}}});const $={key:0,class:"previewable-image__placeholder"},B={key:1,class:"previewable-image__error"},T=["src","alt","referrerpolicy"];function N(e,n,a,l,o,d){const s=t.resolveComponent("ImageViewer");return t.openBlock(),t.createElementBlock("div",{ref:"lazyloadTrigger",class:"previewable-image",style:t.normalizeStyle([{width:e.width,height:e.height},e.imgStyleVars])},[e.lazy&&e.lazyloading?(t.openBlock(),t.createElementBlock("div",$,[t.renderSlot(e.$slots,"placeholder",{},()=>[t.createTextVNode("Loading...")])])):e.lazy&&e.lazyloadError?(t.openBlock(),t.createElementBlock("div",B,[t.renderSlot(e.$slots,"error",{},()=>[t.createTextVNode("Load Error")])])):(t.openBlock(),t.createElementBlock("img",{key:2,src:e.lazySrc,alt:e.alt,referrerpolicy:e.referrerPolicy,class:t.normalizeClass(["previewable-image__inner",{"previewable-image__preview":e.hasPreviewList}]),onClick:n[0]||(n[0]=(...i)=>e.handleImgView&&e.handleImgView(...i))},null,10,T)),e.initViewer?(t.openBlock(),t.createBlock(s,{key:3,modelValue:e.showImageViewer,"onUpdate:modelValue":n[1]||(n[1]=i=>e.showImageViewer=i),"current-preview-index":e.currentViewerIndex,"onUpdate:currentPreviewIndex":n[2]||(n[2]=i=>e.currentViewerIndex=i),"preview-src-list":e.previewSrcList,"viewer-options":e.viewerOptions,"viewer-title":e.viewerTitle,"z-index":e.zIndex,onSwitch:e.handleSwitch},null,8,["modelValue","current-preview-index","preview-src-list","viewer-options","viewer-title","z-index","onSwitch"])):t.createCommentVNode("",!0)],4)}const I=S(k,[["render",N]]),j=(e,n)=>{const a=Object.assign({componentName:I.name,defaultViewerOptions:{}},n);e.component(a.componentName,I),V.setDefaults(a.defaultViewerOptions)},x={install:j};exports.Viewer=V;exports.ImageViewer=b;exports.PreviewableImage=I;exports.default=x; |
Oops, something went wrong.