UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 11.1 kB
import e from"primevue/focustrap";import t from"primevue/icons/eye";import n from"primevue/icons/refresh";import o from"primevue/icons/searchminus";import i from"primevue/icons/searchplus";import r from"primevue/icons/times";import a from"primevue/icons/undo";import s from"primevue/portal";import{ZIndexUtils as l,DomHandler as c}from"primevue/utils";import u from"primevue/basecomponent";import{useStyle as p}from"primevue/usestyle";import{resolveComponent as m,resolveDirective as f,openBlock as v,createElementBlock as d,mergeProps as b,renderSlot as g,createElementVNode as h,createBlock as y,resolveDynamicComponent as w,createCommentVNode as k,createVNode as I,withCtx as C,withDirectives as O,normalizeProps as B,guardReactiveProps as L,Transition as z,normalizeClass as P,normalizeStyle as $}from"vue";var x=p("\n.p-image-mask {\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.p-image-preview-container {\n position: relative;\n display: inline-block;\n}\n\n.p-image-preview-indicator {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n opacity: 0;\n transition: opacity 0.3s;\n}\n\n.p-image-preview-container:hover > .p-image-preview-indicator {\n opacity: 1;\n cursor: pointer;\n}\n\n.p-image-preview-container > img {\n cursor: pointer;\n}\n\n.p-image-toolbar {\n position: absolute;\n top: 0;\n right: 0;\n display: flex;\n}\n\n.p-image-action.p-link {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.p-image-preview {\n transition: transform 0.15s;\n max-width: 100vw;\n max-height: 100vh;\n}\n\n.p-image-preview-enter-active {\n transition: all 150ms cubic-bezier(0, 0, 0.2, 1);\n}\n.p-image-preview-leave-active {\n transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);\n}\n.p-image-preview-enter-from,\n.p-image-preview-leave-to {\n opacity: 0;\n transform: scale(0.7);\n}\n",{name:"image",manual:!0}),S={name:"Image",extends:{name:"BaseImage",extends:u,props:{preview:{type:Boolean,default:!1},class:{type:null,default:null},style:{type:null,default:null},imageStyle:{type:null,default:null},imageClass:{type:null,default:null},previewButtonProps:{type:null,default:null},indicatorIcon:{type:String,default:void 0},zoomInDisabled:{type:Boolean,default:!1},zoomOutDisabled:{type:Boolean,default:!1}},css:{classes:{root:function(e){return["p-image p-component",{"p-image-preview-container":e.props.preview}]},image:function(e){return e.props.image},button:"p-image-preview-indicator",icon:"p-image-preview-icon",mask:"p-image-mask p-component-overlay p-component-overlay-enter",rotateRightButton:"p-image-action p-link",rotateLeftButton:"p-image-action p-link",zoomOutButton:function(e){return["p-image-action p-link",{"p-disabled":e.instance.isZoomOutDisabled}]},zoomInButton:function(e){return["p-image-action p-link",{"p-disabled":e.instance.isZoomInDisabled}]},closeButton:"p-image-action p-link",preview:"p-image-preview"},loadStyle:x.load},provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,emits:["show","hide","error"],mask:null,data:function(){return{maskVisible:!1,previewVisible:!1,rotate:0,scale:1}},beforeUnmount:function(){this.mask&&l.clear(this.container)},methods:{maskRef:function(e){this.mask=e},toolbarRef:function(e){this.toolbarRef=e},onImageClick:function(){var e=this;this.preview&&(c.addClass(document.body,"p-overflow-hidden"),this.maskVisible=!0,setTimeout((function(){e.previewVisible=!0}),25))},onPreviewImageClick:function(){this.previewClick=!0},onMaskClick:function(e){[e.target.classList].includes("p-image-action")||e.target.closest(".p-image-action")||(this.previewClick||(this.previewVisible=!1,this.rotate=0,this.scale=1),this.previewClick=!1)},onMaskKeydown:function(e){var t=this;if("Escape"===e.code)this.hidePreview(),setTimeout((function(){c.focus(t.$refs.previewButton)}),200),e.preventDefault()},onError:function(){this.$emit("error")},rotateRight:function(){this.rotate+=90,this.previewClick=!0},rotateLeft:function(){this.rotate-=90,this.previewClick=!0},zoomIn:function(){this.scale=this.scale+.1,this.previewClick=!0},zoomOut:function(){this.scale=this.scale-.1,this.previewClick=!0},onBeforeEnter:function(){l.set("modal",this.mask,this.$primevue.config.zIndex.modal)},onEnter:function(){this.focus(),this.$emit("show")},onBeforeLeave:function(){!this.isUnstyled&&c.addClass(this.mask,"p-component-overlay-leave")},onLeave:function(){this.$emit("hide")},onAfterLeave:function(e){l.clear(e),this.maskVisible=!1},focus:function(){var e=this.mask.querySelector("[autofocus]");e&&e.focus()},hidePreview:function(){this.previewVisible=!1,this.rotate=0,this.scale=1,c.removeClass(document.body,"p-overflow-hidden")}},computed:{containerClass:function(){return[this.cx("root"),this.class]},rotateClass:function(){return"p-image-preview-rotate-"+this.rotate},imagePreviewStyle:function(){return{transform:"rotate("+this.rotate+"deg) scale("+this.scale+")"}},isZoomInDisabled:function(){return this.zoomInDisabled||this.scale>=1.5},isZoomOutDisabled:function(){return this.zoomOutDisabled||this.scale<=.5},rightAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.rotateRight:void 0},leftAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.rotateLeft:void 0},zoomInAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.zoomIn:void 0},zoomOutAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.zoomOut:void 0},closeAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.close:void 0}},components:{Portal:s,EyeIcon:t,RefreshIcon:n,UndoIcon:a,SearchMinusIcon:o,SearchPlusIcon:i,TimesIcon:r},directives:{focustrap:e}};function E(e){return E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},E(e)}function j(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function A(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?j(Object(n),!0).forEach((function(t){D(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):j(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function D(e,t,n){return(t=R(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e){var t=V(e,"string");return"symbol"===E(t)?t:String(t)}function V(e,t){if("object"!==E(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!==E(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var M=["aria-modal"],Z=["aria-label"],T=["aria-label"],K=["disabled","aria-label"],U=["disabled","aria-label"],_=["aria-label"],q=["src"];S.render=function(e,t,n,o,i,r){var a=m("RefreshIcon"),s=m("UndoIcon"),l=m("SearchMinusIcon"),c=m("SearchPlusIcon"),u=m("TimesIcon"),p=m("Portal"),x=f("focustrap");return v(),d("span",b({class:r.containerClass,style:e.style},e.ptm("root"),{"data-pc-name":"image"}),[g(e.$slots,"image",{onError:r.onError},(function(){return[h("img",b({style:e.imageStyle,class:[e.cx("image"),e.imageClass],onError:t[0]||(t[0]=function(){return r.onError&&r.onError.apply(r,arguments)})},A(A({},e.$attrs),e.ptm("image"))),null,16)]})),e.preview?(v(),d("button",b({key:0,ref:"previewButton",type:"button",class:e.cx("button"),onClick:t[1]||(t[1]=function(){return r.onImageClick&&r.onImageClick.apply(r,arguments)})},A(A({},e.previewButtonProps),e.ptm("button"))),[g(e.$slots,"indicatoricon",{},(function(){return[(v(),y(w(e.indicatorIcon?"i":"EyeIcon"),b({class:e.cx("icon")},e.ptm("icon")),null,16,["class"]))]}))],16)):k("",!0),I(p,null,{default:C((function(){return[i.maskVisible?O((v(),d("div",b({key:0,ref:r.maskRef,role:"dialog",class:e.cx("mask"),"aria-modal":i.maskVisible,onClick:t[8]||(t[8]=function(){return r.onMaskClick&&r.onMaskClick.apply(r,arguments)}),onKeydown:t[9]||(t[9]=function(){return r.onMaskKeydown&&r.onMaskKeydown.apply(r,arguments)})},e.ptm("mask")),[h("div",b({class:"p-image-toolbar"},e.ptm("toolbar")),[h("button",b({class:e.cx("rotateRightButton"),onClick:t[2]||(t[2]=function(){return r.rotateRight&&r.rotateRight.apply(r,arguments)}),type:"button","aria-label":r.rightAriaLabel},e.ptm("rotateRightButton"),{"data-pc-group-section":"action"}),[g(e.$slots,"refresh",{},(function(){return[I(a,B(L(e.ptm("rotateRightIcon"))),null,16)]}))],16,Z),h("button",b({class:e.cx("rotateLeftButton"),onClick:t[3]||(t[3]=function(){return r.rotateLeft&&r.rotateLeft.apply(r,arguments)}),type:"button","aria-label":r.leftAriaLabel},e.ptm("rotateLeftButton"),{"data-pc-group-section":"action"}),[g(e.$slots,"undo",{},(function(){return[I(s,B(L(e.ptm("rotateLeftIcon"))),null,16)]}))],16,T),h("button",b({class:e.cx("zoomOutButton"),onClick:t[4]||(t[4]=function(){return r.zoomOut&&r.zoomOut.apply(r,arguments)}),type:"button",disabled:r.isZoomOutDisabled,"aria-label":r.zoomOutAriaLabel},e.ptm("zoomOutButton"),{"data-pc-group-section":"action"}),[g(e.$slots,"zoomout",{},(function(){return[I(l,B(L(e.ptm("zoomOutIcon"))),null,16)]}))],16,K),h("button",b({class:e.cx("zoomInButton"),onClick:t[5]||(t[5]=function(){return r.zoomIn&&r.zoomIn.apply(r,arguments)}),type:"button",disabled:r.isZoomInDisabled,"aria-label":r.zoomInAriaLabel},e.ptm("zoomInButton"),{"data-pc-group-section":"action"}),[g(e.$slots,"zoomin",{},(function(){return[I(c,B(L(e.ptm("zoomInIcon"))),null,16)]}))],16,U),h("button",b({class:e.cx("closeButton"),type:"button",onClick:t[6]||(t[6]=function(){return r.hidePreview&&r.hidePreview.apply(r,arguments)}),"aria-label":r.closeAriaLabel,autofocus:""},e.ptm("closeButton"),{"data-pc-group-section":"action"}),[g(e.$slots,"close",{},(function(){return[I(u,B(L(e.ptm("closeIcon"))),null,16)]}))],16,_)],16),I(z,b({name:"p-image-preview",onBeforeEnter:r.onBeforeEnter,onEnter:r.onEnter,onLeave:r.onLeave,onBeforeLeave:r.onBeforeLeave,onAfterLeave:r.onAfterLeave},e.ptm("transition")),{default:C((function(){return[i.previewVisible?(v(),d("div",B(b({key:0},e.ptm("previewContainer"))),[g(e.$slots,"preview",{class:P(e.cx("preview")),style:$(r.imagePreviewStyle),onClick:r.onPreviewImageClick},(function(){return[h("img",b({src:e.$attrs.src,class:e.cx("preview"),style:r.imagePreviewStyle,onClick:t[7]||(t[7]=function(){return r.onPreviewImageClick&&r.onPreviewImageClick.apply(r,arguments)})},e.ptm("preview")),null,16,q)]}))],16)):k("",!0)]})),_:3},16,["onBeforeEnter","onEnter","onLeave","onBeforeLeave","onAfterLeave"])],16,M)),[[x]]):k("",!0)]})),_:3})],16)};export{S as default};