ew-viewer 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/CHANGELOG.zh-CN.md +32 -0
- package/LICENSE +21 -0
- package/README.md +123 -2
- package/README.zh-CN.md +124 -0
- package/dist/icons.d.ts +15 -0
- package/dist/index.cjs +33 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.iife.js +36 -0
- package/dist/index.js +559 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/template.d.ts +4 -0
- package/dist/internal/utils.d.ts +2 -0
- package/dist/style.css +172 -0
- package/dist/types.d.ts +64 -0
- package/dist/viewer.d.ts +113 -0
- package/package.json +61 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var EWViewer=function(){"use strict";var Se=Object.defineProperty;var Fe=(g,f,v)=>f in g?Se(g,f,{enumerable:!0,configurable:!0,writable:!0,value:v}):g[f]=v;var o=(g,f,v)=>Fe(g,typeof f!="symbol"?f+"":f,v);/*!
|
|
2
|
+
* @ew-color-picker/utils
|
|
3
|
+
* (c) 2024-2026 eveningwater(854806732@qq.com)
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/var g=function(){return g=Object.assign||function(e){for(var t,s=1,n=arguments.length;s<n;s++){t=arguments[s];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},g.apply(this,arguments)};function f(i,e,t){if(t||arguments.length===2)for(var s=0,n=e.length,r;s<n;s++)(r||!(s in e))&&(r||(r=Array.prototype.slice.call(e,0,s)),r[s]=e[s]);return i.concat(r||Array.prototype.slice.call(e))}typeof SuppressedError=="function"&&SuppressedError;var v=typeof window<"u",M=v&&navigator.userAgent.toLowerCase();M&&M.match(/(iPhone|iPod|Android|ios)/i);var P=!1;if(v){var K="test-passive";try{var H={};Object.defineProperty(H,"passive",{get:function(){P=!0}}),window.addEventListener(K,function(){},H)}catch{}}var A=["warn","error","log"],S={log:{icon:"📝",color:"#4CAF50",bgColor:"#E8F5E8",borderColor:"#4CAF50"},warn:{icon:"⚠️",color:"#FF9800",bgColor:"#FFF3E0",borderColor:"#FF9800"},error:{icon:"❌",color:"#F44336",bgColor:"#FFEBEE",borderColor:"#F44336"}},Q=function(i){var e=S[i];return"color: ".concat(e.color,"; background: ").concat(e.bgColor,"; padding: 2px 6px; border-radius: 4px; border-left: 3px solid ").concat(e.borderColor,"; font-weight: bold;")},B=function(i,e,t){var s=t[0],n=typeof s=="string"&&s.includes("%c");return n?f(["".concat(e," ").concat(s)],t.slice(1),!0):f(["%c".concat(e),Q(i)],t,!0)},_=function(i){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];var s="".concat(S[i].icon," [ewColorPicker ").concat(i.toUpperCase(),"] ").concat(new Date().toLocaleTimeString());return B(i,s,e)},F=function(){},D={log:F,warn:F,error:F};A.forEach(function(i){D[i]=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];{var s=_.apply(void 0,f([i],e,!1));console[i].apply(console,s)}}});var ee=D.warn,te=function(i){i===void 0&&(i={});var e=i.prefix,t=i.timestamp,s=t===void 0?!0:t;i.dev;var n={};return A.forEach(function(r){n[r]=function(){for(var l=[],a=0;a<arguments.length;a++)l[a]=arguments[a];var d=[S[r].icon,e?"[".concat(e,"]"):"",r.toUpperCase(),s?new Date().toLocaleTimeString():""].filter(Boolean).join(" ");console[r].apply(console,B(r,d,l))}}),n},N=Object.prototype.toString,ie=Object.prototype.hasOwnProperty,se=function(i){return i===null},T=function(i){return typeof i=="string"},E=function(i){return typeof i=="number"},x=function(i){return typeof i=="number"&&!Number.isNaN(i)},V=function(i){return typeof i=="boolean"},ne=function(i){return N.call(i).slice(8,-1).toLowerCase()==="object"},re=function(i){return N.call(i).slice(8,-1).toLowerCase()==="array"},j=function(i){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];if(se(i))return{};if(Object.assign)return Object.assign.apply(Object,f([i],e,!1));for(var s=Object(i),n=0,r=e.length;n<r;n++){var l=e[n];if(l)for(var a in l)ie.call(l,a)&&(s[a]=l[a])}return s},c=function(i){return i?" ".concat(i):""},W=function(i,e){var t=new RegExp("(^|\\s)"+e+"(\\s|$)");return t.test(i.className)},L=function(i,e){for(var t=Y(e),s=0,n=t;s<n.length;s++){var r=n[s];if(r&&!W(i,r)){var l=i.className.split(" ").filter(Boolean);l.push(r),i.className=l.join(" ")}}},R=function(i,e){var t=Y(e).filter(function(n){return W(i,n)});if(t.length!==0){var s=new RegExp("(^|\\s)("+t.join("|")+")(\\s|$)","g");i.className=i.className.replace(s," ").replace(/\s+/g," ").trim()}},oe=function(i){return i instanceof HTMLElement},q=function(i){return typeof window>"u"||!i?!1:typeof HTMLElement<"u"&&i instanceof HTMLElement||typeof HTMLCollection<"u"&&i instanceof HTMLCollection||typeof NodeList<"u"&&i instanceof NodeList?!0:typeof i=="object"&&i.nodeType===1},Y=function(i){return i?(re(i)?i:[i]).filter(Boolean):[]},m=function(i,e){return e===void 0&&(e=document),e.querySelector(i)},ae=function(i){if(T(i)){var e=m(i);return e||(ee("[ewColorPicker warning]: Cannot find element with selector: ".concat(i)),document.body)}return oe(i)?i:document.body},C=function(i,e,t,s){if(!(!i||!e||!t)){if(typeof s=="object"&&s!==null){i.addEventListener(e,t,g({passive:!1},s));return}if(!P){i.addEventListener(e,t,!!s);return}i.addEventListener(e,t,{passive:!1,capture:!!s})}},U;(function(i){i.Pre="pre",i.Post="post"})(U||(U={}));const w=te({prefix:"ew-viewer",timestamp:!1}),le=i=>`<svg t="1697700092492" class="add-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="900" width="78" height="78"><path d="M560.064 149.952a48 48 0 0 0-96 0V464H150.016a48 48 0 0 0 0 96H464v313.984a48 48 0 0 0 96 0V560h314.048a48 48 0 0 0 0-96H560V149.952z" p-id="901" fill="#ffffff"></path></svg>`,ce=i=>`<svg t="1697700199963" class="reduce-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1256" width="78" height="78"><path d="M922.048 512a48 48 0 0 0-48-48H149.952a48 48 0 1 0 0 96h724.096a48 48 0 0 0 48-48z" p-id="1257" fill="#ffffff"></path></svg>`,he=i=>`<svg t="1690189203554" class="close-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2272" fill="currentColor"><path d="M504.224 470.288l207.84-207.84a16 16 0 0 1 22.608 0l11.328 11.328a16 16 0 0 1 0 22.624l-207.84 207.824 207.84 207.84a16 16 0 0 1 0 22.608l-11.328 11.328a16 16 0 0 1-22.624 0l-207.824-207.84-207.84 207.84a16 16 0 0 1-22.608 0l-11.328-11.328a16 16 0 0 1 0-22.624l207.84-207.824-207.84-207.84a16 16 0 0 1 0-22.608l11.328-11.328a16 16 0 0 1 22.624 0l207.824 207.84z" p-id="2273"></path></svg>`,fe=i=>`<svg t="1697700658302" class="one-to-one-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7084" width="78" height="78"><path d="M904.405333 149.333333v725.333334h-85.333333V250.346667l-66.24 33.152L714.666667 207.146667 830.336 149.333333h74.069333z m-608 0v725.333334h-85.333333V250.346667L144.853333 283.498667 106.666667 207.146667 222.336 149.333333h74.069333z m288 448v106.666667h-106.666666v-106.666667h106.666666z m0-277.333333v106.666667h-106.666666v-106.666667h106.666666z" fill="#ffffff" p-id="7085"></path></svg>`,ue=i=>`<svg t="1697712563708" class="arrow-up-down-icon${i}" viewBox="0 0 1088 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="20575" width="78" height="78"><path d="M513.344 253.504V768H323.968l244.416 255.424L825.344 768H640V253.504h185.344L566.848 6.72 319.424 253.504h193.92z" fill="#ffffff" p-id="20576"></path></svg>`,ge=i=>`<svg t="1697712627137" class="arrow-left-right-icon${i}" viewBox="0 0 1088 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="21609" width="78" height="78"><path d="M320 576h516.224v183.296l246.4-244.48-246.4-256.832L832 448H320l-7.296-190.08L65.92 516.48l246.784 247.424L320 576z" fill="#ffffff" p-id="21610"></path></svg>`,me=i=>`<svg t="1697712701928" class="flip-left-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="25120" width="78" height="78"><path d="M672 418H144c-17.7 0-32 14.3-32 32v414c0 17.7 14.3 32 32 32h528c17.7 0 32-14.3 32-32V450c0-17.7-14.3-32-32-32z m-44 402H188V494h440v326z" p-id="25121" fill="#ffffff"></path><path d="M819.3 328.5c-78.8-100.7-196-153.6-314.6-154.2l-0.2-64c0-6.5-7.6-10.1-12.6-6.1l-128 101c-4 3.1-3.9 9.1 0 12.3L492 318.6c5.1 4 12.7 0.4 12.6-6.1v-63.9c12.9 0.1 25.9 0.9 38.8 2.5 42.1 5.2 82.1 18.2 119 38.7 38.1 21.2 71.2 49.7 98.4 84.3 27.1 34.7 46.7 73.7 58.1 115.8 11 40.7 14 82.7 8.9 124.8-0.7 5.4-1.4 10.8-2.4 16.1h74.9c14.8-103.6-11.3-213-81-302.3z" p-id="25122" fill="#ffffff"></path></svg>`,de=i=>`<svg t="1697712744122" class="flip-right-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="25323" width="78" height="78"><path d="M480.5 251.2c13-1.6 25.9-2.4 38.8-2.5v63.9c0 6.5 7.5 10.1 12.6 6.1L660 217.6c4-3.2 4-9.2 0-12.3l-128-101c-5.1-4-12.6-0.4-12.6 6.1l-0.2 64c-118.6 0.5-235.8 53.4-314.6 154.2-69.6 89.2-95.7 198.6-81.1 302.4h74.9c-0.9-5.3-1.7-10.7-2.4-16.1-5.1-42.1-2.1-84.1 8.9-124.8 11.4-42.2 31-81.1 58.1-115.8 27.2-34.7 60.3-63.2 98.4-84.3 37-20.6 76.9-33.6 119.1-38.8z" p-id="25324" fill="#ffffff"></path><path d="M880 418H352c-17.7 0-32 14.3-32 32v414c0 17.7 14.3 32 32 32h528c17.7 0 32-14.3 32-32V450c0-17.7-14.3-32-32-32z m-44 402H396V494h440v326z" p-id="25325" fill="#ffffff"></path></svg>`,ve=i=>`<svg t="1697787947316" class="arrow-left-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="900" width="78" height="78"><path d="M290.56 550.464a54.4 54.4 0 0 1 0-76.928l379.52-379.52a48 48 0 1 1 67.84 67.904L387.84 512l350.08 350.08a48 48 0 1 1-67.84 67.84L290.56 550.464z" p-id="901" fill="#ffffff"></path></svg>`,we=i=>`<svg t="1697772815002" class="arrow-right-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="900" width="78" height="78"><path d="M733.44 550.464a54.4 54.4 0 0 0 0-76.928l-379.52-379.52A48 48 0 0 0 286.08 161.92L636.16 512l-350.08 350.08a48 48 0 1 0 67.84 67.84l379.52-379.456z" p-id="901" fill="#ffffff"></path></svg>`,pe=i=>`<svg t="1697773227169" class="reset-icon${i}" viewBox="0 0 1278 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2019" width="78" height="78"><path d="M1272.447024 472.907505l-150.052574 149.245613a32.021415 32.021415 0 0 1-44.681788 0L928.777033 472.906505c-17.717123-20.478986-5.895708-27.925618 6.45368-39.716035h136.525243A441.782135 441.782135 0 0 0 253.257466 304.732828L178.791151 275.257287a521.555187 521.555187 0 0 1 973.731808 157.934183h113.56338a26.653681 26.653681 0 0 1 6.360685 39.716035zM202.713967 440.946087l150.022575 149.556598a26.622682 26.622682 0 0 1-6.45468 39.717034H216.366292a442.247112 442.247112 0 0 0 789.701915 120.700026l75.213278 29.787526A521.555187 521.555187 0 0 1 134.513343 630.219719h-118.994111c-12.411386-11.791416-24.170804-19.238048-6.453681-39.717034l148.935629-149.556598a32.641385 32.641385 0 0 1 44.712787 0z" fill="#ffffff" p-id="2020"></path></svg>`,Ie=i=>`<svg t="1697787617768" class="fullscreen-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3046" width="78" height="78"><path d="M213.333333 213.333333h213.333334V128H170.666667a42.666667 42.666667 0 0 0-42.666667 42.666667v256h85.333333V213.333333zM170.666667 896h256v-85.333333H213.333333v-213.333334H128v256a42.666667 42.666667 0 0 0 42.666667 42.666667z m725.333333-42.666667v-256h-85.333333v213.333334h-213.333334v85.333333h256a42.666667 42.666667 0 0 0 42.666667-42.666667zM597.333333 213.333333h213.333334v213.333334h85.333333V170.666667a42.666667 42.666667 0 0 0-42.666667-42.666667h-256v85.333333z" fill="#ffffff" p-id="3047"></path></svg>`,$e=i=>`<svg t="1697800175999" class="play-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9820" width="78" height="78"><path d="M852.5 533.9L279 864.7c-11.9 6.9-27.2 2.8-34.1-9.1-2.2-3.8-3.3-8.1-3.3-12.5V181.5c0-13.8 11.2-24.9 24.9-24.9 4.4 0 8.7 1.2 12.5 3.3l573.4 330.8c11.9 6.9 16 22.1 9.1 34.1-2.1 3.8-5.2 6.9-9 9.1z" p-id="9821" fill="#ffffff"></path></svg>`,be=i=>`<svg t="1697799289205" class="pause-icon${i}" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8597" width="78" height="78"><path d="M209.645253 863.934444l201.049992 0 0-703.866842L209.645253 160.067602 209.645253 863.934444zM611.804588 863.934444l201.113437 0 0-703.866842L611.804588 160.067602 611.804588 863.934444z" p-id="8598" fill="#ffffff"></path></svg>`;function ye(i){const e=document.createElement("div");return e.innerHTML=i,e.firstElementChild}function p(i,e){return V(i)&&i&&T(e)&&e?e:""}const Te=450,xe=new Set(["mask","content","footer","title","toolbar","thumb","close"]),Ce={isClickOutside:!0,previewMode:"bg",showCloseBtn:!0,showCloseBtnIcon:he(c("ew-viewer-close-icon")),closeTime:200,zoomOnWheeling:!0,autoSize:!0,minImageRatio:.1,maxImageRatio:1,showToolBar:!0,zoomInIcon:le(c("ew-viewer-zoom-in-icon")),zoomOutIcon:ce(c("ew-viewer-zoom-out-icon")),oneToOneIcon:fe(c("ew-viewer-one-to-one-icon")),currentImageIndex:0,autoOpen:!1,flipLeftIcon:ge(c("ew-viewer-flip-left-icon")),flipRightIcon:ue(c("ew-viewer-flip-right-icon")),rotateLeftIcon:me(c("ew-viewer-rotate-left-icon")),rotateRightIcon:de(c("ew-viewer-rotate-right-icon")),resetIcon:pe(c("ew-viewer-reset-icon")),prevIcon:ve(c("ew-viewer-prev-icon")),nextIcon:we(c("ew-viewer-next-icon")),fullscreenIcon:Ie(c("ew-viewer-fullscreen-icon")),playIcon:$e(c("ew-viewer-play-icon")),pauseIcon:be(c("ew-viewer-pause-icon")),minRotate:-1/0,maxRotate:1/0,loop:!0,zIndex:2e3};function Z(i,e){if(!e)return j({},i);const t=e,s={};return Object.keys(t).forEach(n=>{t[n]!==void 0&&(s[n]=t[n])}),j({},i,s)}function Ee(i){if(T(i))return i.trim()||null;if(q(i)){const e=i;return(e.getAttribute?.("src")??e.src)||null}return null}function Le(i){return new Promise(e=>{const t=new Image;t.onload=()=>e({naturalWidth:t.naturalWidth,naturalHeight:t.naturalHeight,scaleWidth:0,scaleHeight:0,scaleX:0,scaleY:0,rotate:0}),t.onerror=()=>e(null),t.src=i})}function O(i){const e=Number(i);return x(e)&&e>0&&e<=1?e:.9}function X(i){return i.fullscreenElement||i.webkitFullscreenElement||i.mozFullScreenElement||i.msFullscreenElement||null}function G(i){return i?.closest?.("[data-ew-role]")?.getAttribute("data-ew-role")??null}class Re{constructor(e){o(this,"config",Z(Ce));o(this,"options");o(this,"imageDataList",[]);o(this,"imageStyle",[]);o(this,"currentImageIndex",0);o(this,"computedImageRatio",.9);o(this,"wheeling",!1);o(this,"isClickZoomIn",!1);o(this,"isClickZoomOut",!1);o(this,"isClickOneToOne",!1);o(this,"fullScreenStatus",!1);o(this,"isPlaying",!1);o(this,"$dom",{});o(this,"ac",null);o(this,"timers",new Set);o(this,"carouselTimer",null);o(this,"rafId",null);o(this,"pendingOpen",null);o(this,"seq",0);o(this,"slidePos",1);o(this,"handleRootClick",e=>{const t=G(e.target);if(t!=="fullscreen"){if(this.fullScreenStatus){this.exitFullscreen(),this.fullScreenStatus=!1;return}this.config.isClickOutside&&t!==null&&xe.has(t)&&this.close()}});o(this,"handleResize",()=>{if(this.rafId===null){if(typeof requestAnimationFrame!="function"){this.setImageStyle();return}this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.setImageStyle()})}});o(this,"handleWheel",e=>{e.preventDefault(),!this.wheeling&&(this.wheeling=!0,this.setTimer(()=>{this.wheeling=!1},150),this.viewedImageHandler(e.deltaY<0))});o(this,"handleThumbClick",e=>{e.stopPropagation();const t=e.target;if(!t?.className?.includes?.("ew-viewer-thumb-img"))return;const s=Number(t.getAttribute("data-index"));x(s)&&(this.currentImageIndex=s,this.changeThumbImage(),this.slideTo(s),this.setImageStyle())});o(this,"handleToolbarClick",e=>{const t=this.currentMeta();if(!t)return;const{minRotate:s,maxRotate:n}=this.config;switch(G(e.target)){case"zoom-in":if(this.isClickZoomIn)return;this.isClickZoomIn=!0,this.setTimer(()=>{this.isClickZoomIn=!1},50),this.viewedImageHandler(!0);break;case"zoom-out":if(this.isClickZoomOut)return;this.isClickZoomOut=!0,this.setTimer(()=>{this.isClickZoomOut=!1},50),this.viewedImageHandler(!1);break;case"one-to-one":{if(this.isClickOneToOne)return;this.isClickOneToOne=!0,this.setTimer(()=>{this.isClickOneToOne=!1},50),this.viewedImageHandler(this.computedImageRatio===1?.5:1);break}case"rotate-left":t.rotate-=90,E(s)&&s!==-1/0&&t.rotate<=s&&(t.rotate=s),this.setImageStyle();break;case"rotate-right":t.rotate+=90,E(n)&&n!==1/0&&t.rotate>=n&&(t.rotate=n),this.setImageStyle();break;case"flip-horizontal":t.scaleX=t.scaleX===-1?0:-1,this.setImageStyle();break;case"flip-vertical":t.scaleY=t.scaleY===-1?0:-1,this.setImageStyle();break;case"reset":this.resetImage();break;case"prev":this.manualGo(-1);break;case"next":this.manualGo(1);break;case"fullscreen":this.fullScreenStatus=!this.fullScreenStatus,this.fullScreenStatus?this.requestFullscreen():this.exitFullscreen();break;case"play":this.togglePlay();break}});if(!v){w.warn("EWViewer 只能在浏览器环境中使用");return}this.computedImageRatio=O(this.config.imageRatio),this.reload(e)}reload(e){const t=++this.seq;this.init(e).then(s=>{t!==this.seq||!s||this.render()})}async resolveImages(e){const t=e.map(Ee).filter(a=>!!a);if(t.length===0)return w.warn("传入的图片地址不合法"),!1;const s=await Promise.all(t.map(Le)),n=[],r=[];if(s.forEach((a,d)=>{if(!a){w.warn(`图片加载失败,已忽略:${t[d]}`);return}n.push(t[d]),r.push(a)}),n.length===0)return!1;this.imageDataList=n,this.imageStyle=r;const l=this.config.currentImageIndex;return this.currentImageIndex=x(l)&&l>=0&&l<n.length?l:0,!0}async init(e){if(T(e)||q(e))return this.resolveImages([e]);if(Array.isArray(e))return this.resolveImages(e);if(ne(e)){const{img:t,...s}=e;return this.config=Z(this.config,s),this.validateRatio(),this.computedImageRatio=O(this.config.imageRatio),t==null?(w.warn("未提供 img 参数"),!1):this.resolveImages(Array.isArray(t)?t:[t])}return w.warn("传入的参数不合法"),!1}validateRatio(){const{minImageRatio:e,maxImageRatio:t}=this.config;this.rangeRation(e)||(this.config.minImageRatio=.1,w.warn("minImageRatio 应在 0 到 1 之间")),this.rangeRation(t)||(this.config.maxImageRatio=1,w.warn("maxImageRatio 应在 0 到 1 之间")),this.config.minImageRatio>this.config.maxImageRatio&&w.warn("minImageRatio 不应大于 maxImageRatio")}rangeRation(e){return E(e)?e>=0&&e<=1:!1}async render(){this.teardown();const e=ae(this.config.container),t=this.currentMeta();if(!e||!t)return;const{previewMode:s,showCloseBtn:n,showCloseBtnIcon:r,showToolBar:l}=this.config,a=this.imageDataList[this.currentImageIndex]??"",d=`${Math.floor(this.computedImageRatio*100)}%`,h=this.imageDataList.length>1,I=`
|
|
6
|
+
<div class="ew-viewer-zoom-in" data-ew-role="zoom-in">${this.config.zoomInIcon}</div>
|
|
7
|
+
<div class="ew-viewer-zoom-out" data-ew-role="zoom-out">${this.config.zoomOutIcon}</div>
|
|
8
|
+
<div class="ew-viewer-one-to-one" data-ew-role="one-to-one">${this.config.oneToOneIcon}</div>
|
|
9
|
+
<div class="ew-viewer-reset" data-ew-role="reset">${this.config.resetIcon}</div>
|
|
10
|
+
<div class="ew-viewer-fullscreen" data-ew-role="fullscreen">${this.config.fullscreenIcon}</div>
|
|
11
|
+
${p(h,`<div class="ew-viewer-prev" data-ew-role="prev">${this.config.prevIcon}</div>`)}
|
|
12
|
+
${p(h,`<div class="ew-viewer-play" data-ew-role="play">${this.isPlaying?this.config.pauseIcon:this.config.playIcon}</div>`)}
|
|
13
|
+
${p(h,`<div class="ew-viewer-next" data-ew-role="next">${this.config.nextIcon}</div>`)}
|
|
14
|
+
<div class="ew-viewer-rotate-left" data-ew-role="rotate-left">${this.config.rotateLeftIcon}</div>
|
|
15
|
+
<div class="ew-viewer-rotate-right" data-ew-role="rotate-right">${this.config.rotateRightIcon}</div>
|
|
16
|
+
<div class="ew-viewer-flip-horizontal" data-ew-role="flip-horizontal">${this.config.flipLeftIcon}</div>
|
|
17
|
+
<div class="ew-viewer-flip-vertical" data-ew-role="flip-vertical">${this.config.flipRightIcon}</div>
|
|
18
|
+
`,b=(y,$,ke=!1)=>`
|
|
19
|
+
<div class="ew-viewer-img-box${c($===this.currentImageIndex?"show":"")}" data-index="${$}" data-ew-role="image"${ke?' data-clone="true"':""}>
|
|
20
|
+
${s==="bg"?`<div class="ew-viewer-bg-img" style="background-image:url(${y});"></div>`:`<img src="${y}" class="ew-viewer-img" />`}
|
|
21
|
+
</div>`,z=this.imageDataList.map((y,$)=>b(y,$)).join(""),k=`<div class="ew-viewer-track">
|
|
22
|
+
${p(h,b(this.imageDataList[this.imageDataList.length-1],this.imageDataList.length-1,!0))}
|
|
23
|
+
${z}
|
|
24
|
+
${p(h,b(this.imageDataList[0],0,!0))}
|
|
25
|
+
</div>`,ze=this.imageDataList.map((y,$)=>`<img src="${y}" class="ew-viewer-thumb-img${c($===this.currentImageIndex?"active":"")}" data-index="${$}"/>`).join(""),u=ye(`<div class="ew-viewer hidden">
|
|
26
|
+
<div class="ew-viewer-mask" data-ew-role="mask">
|
|
27
|
+
<div class="ew-viewer-content" data-ew-role="content">${k}</div>
|
|
28
|
+
<div class="ew-viewer-tooltip-ratio hidden" data-ew-role="tooltip">${d}</div>
|
|
29
|
+
<div class="ew-viewer-footer" data-ew-role="footer">
|
|
30
|
+
<div class="ew-viewer-title" data-ew-role="title">${this.getImageNameFromURL(a)}(${t.naturalWidth} x ${t.naturalHeight})</div>
|
|
31
|
+
${p(l,`<div class="ew-viewer-button" data-ew-role="toolbar">${I}</div>`)}
|
|
32
|
+
${p(h,`<div class="ew-viewer-thumb" data-ew-role="thumb">${ze}</div>`)}
|
|
33
|
+
</div>
|
|
34
|
+
${p(n,`<span class="ew-viewer-close-btn" data-ew-role="close">${r}</span>`)}
|
|
35
|
+
</div>
|
|
36
|
+
</div>`);if(!u)return;x(this.config.zIndex)&&u.style.setProperty("--ew-viewer-z-index",`${this.config.zIndex}`),e.appendChild(u),this.$dom.$el=u,this.$dom.$viewerContentElement=m(".ew-viewer-content",u),this.$dom.$viewerTrackElement=m(".ew-viewer-track",u),this.$dom.$viewerRatioTooltipElement=m(".ew-viewer-tooltip-ratio",u),this.$dom.$viewerToolbarElement=m(".ew-viewer-button",u),this.$dom.$viewerThumbElement=m(".ew-viewer-thumb",u),this.$dom.$viewerTitleElement=m(".ew-viewer-title",u),this.slidePos=this.indexToPos(this.currentImageIndex),this.setTrackPosition(this.slidePos,!1),this.bindEvent();const J=this.pendingOpen;this.pendingOpen=null,J?this.open(J.time):this.config.autoOpen&&this.open()}bindEvent(){const e=this.$dom.$el;if(!e)return;this.ac=new AbortController;const{signal:t}=this.ac;C(e,"click",this.handleRootClick,{signal:t}),this.config.autoSize&&C(window,"resize",this.handleResize,{signal:t}),this.config.zoomOnWheeling&&C(e,"wheel",this.handleWheel,{signal:t});const s=this.$dom.$viewerToolbarElement;s&&C(s,"click",this.handleToolbarClick,{signal:t});const n=this.$dom.$viewerThumbElement;n&&C(n,"click",this.handleThumbClick,{signal:t})}currentMeta(){return this.imageStyle[this.currentImageIndex]??null}get interval(){const e=Number(this.config.interval);return x(e)&&e>0?e:5e3}setTimer(e,t){const s=setTimeout(()=>{this.timers.delete(s),e()},t);return this.timers.add(s),s}clearTimers(){this.timers.forEach(e=>clearTimeout(e)),this.timers.clear()}teardown(){this.ac?.abort(),this.ac=null,this.clearTimers(),this.carouselTimer=null,this.rafId!==null&&(typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(this.rafId),this.rafId=null),this.$dom.$el?.remove(),this.$dom={}}stopCarousel(){this.carouselTimer!==null&&(clearTimeout(this.carouselTimer),this.timers.delete(this.carouselTimer),this.carouselTimer=null)}indexToPos(e){return this.imageDataList.length>1?e+1:0}setTrackPosition(e,t){const s=this.$dom.$viewerTrackElement;if(!s)return;this.slidePos=e;const r=`translate3d(${e===0?"0":`${-e*100}%`}, 0, 0)`;if(t){s.style.removeProperty("transition"),s.style.transform=r;return}s.style.transition="none",s.style.transform=r,s.offsetWidth,s.style.removeProperty("transition")}slideTo(e,t){const s=this.imageDataList.length;if(s<=1)return;this.slidePos===0?this.setTrackPosition(s,!1):this.slidePos===s+1&&this.setTrackPosition(1,!1);let n=e+1;t!==void 0&&t>0&&e===0?n=s+1:t!==void 0&&t<0&&e===s-1&&(n=0),this.setTrackPosition(n,!0),this.setTimer(()=>{this.slidePos===0?this.setTrackPosition(s,!1):this.slidePos===s+1&&this.setTrackPosition(1,!1)},Te+50)}startCarousel(){this.stopCarousel();const e=()=>{this.go(1),this.carouselTimer=this.setTimer(e,this.interval)};this.carouselTimer=this.setTimer(e,this.interval)}go(e){const t=this.imageDataList.length;if(t===0)return;const s=this.currentImageIndex;let n=this.currentImageIndex+e;const r=this.config.loop||this.isPlaying;n<0&&(n=r?t-1:0),n>t-1&&(n=r?0:t-1),this.currentImageIndex=n,this.changeThumbImage(),this.setImageStyle(),n!==s&&this.slideTo(n,e)}manualGo(e){this.go(e),this.isPlaying&&this.startCarousel()}togglePlay(){this.isPlaying=!this.isPlaying;const e=this.$dom.$viewerToolbarElement,t=e?m(".ew-viewer-play",e):null;t&&(t.innerHTML=this.isPlaying?this.config.pauseIcon:this.config.playIcon),this.isPlaying?this.startCarousel():this.stopCarousel()}imageSize(e,t){const{offsetWidth:s,offsetHeight:n}=t,r=e.naturalWidth/e.naturalHeight;let l=s,a=n;return n*r>s?a=s/r:l=n*r,{width:Math.min(l*this.computedImageRatio,e.naturalWidth),height:Math.min(a*this.computedImageRatio,e.naturalHeight)}}scaleImageCallback(){const e=this.$dom.$viewerContentElement,t=this.currentMeta();if(!e||!t)return;const{width:s,height:n}=this.imageSize(t,e);t.scaleWidth=s,t.scaleHeight=n;const r=this.$dom.$viewerRatioTooltipElement;r&&(r.textContent=`${Math.floor(this.computedImageRatio*100)}%`)}async setImageStyle(e=!0){const t=this.$dom.$viewerContentElement,s=this.currentMeta();if(!t||!s)return;e&&this.scaleImageCallback();const n=this.$dom.$viewerTrackElement;(n?[...n.children]:[]).forEach(a=>{const d=Number(a.getAttribute("data-index")),h=this.imageStyle[d],I=a.firstElementChild;if(!h||!I)return;d===this.currentImageIndex?L(a,"show"):R(a,"show");const{width:b,height:z}=this.imageSize(h,t);I.style.width=`${b}px`,I.style.height=`${z}px`,this.config.previewMode==="bg"&&(I.style.backgroundSize=`${b}px ${z}px`),I.style.removeProperty("transform");const k=`${h.rotate!==0?`rotate(${h.rotate}deg)`:""} ${h.scaleX!==0?`scaleX(${h.scaleX})`:""} ${h.scaleY!==0?`scaleY(${h.scaleY})`:""}`.trim();k&&(I.style.transform=k)});const l=this.$dom.$viewerTitleElement;if(l){const a=this.imageDataList[this.currentImageIndex]??"";l.innerHTML=`${this.getImageNameFromURL(a)}(${s.naturalWidth} x ${s.naturalHeight})`}}getImageNameFromURL(e){return T(e)?decodeURIComponent(e.replace(/^.*\//,"").replace(/[?&#].*$/,"")):""}computedImageRatioHandler(e){const{minImageRatio:t,maxImageRatio:s}=this.config,n=e?1:-1,r=this.computedImageRatio+n*(Math.floor(Math.random()*100)/1e3);this.computedImageRatio=Math.max(t,Math.min(r,s))}viewedImageHandler(e){V(e)?this.computedImageRatioHandler(e):this.computedImageRatio=e,this.toggleTooltip(!0),this.setTimer(()=>this.toggleTooltip(!1),1e3),this.setImageStyle()}changeThumbImage(){const e=this.$dom.$viewerThumbElement;if(!e)return;[...e.children].forEach(s=>{Number(s.getAttribute("data-index"))===this.currentImageIndex?L(s,"active"):R(s,"active")})}getFullscreenTarget(){const e=this.$dom.$viewerContentElement;return e?m(".ew-viewer-img-box.show",e):null}requestFullscreen(){const t=this.getFullscreenTarget()?.ownerDocument??document;if(X(t))return;const s=t.documentElement;typeof s.requestFullscreen=="function"?s.requestFullscreen():typeof s.webkitRequestFullscreen=="function"?s.webkitRequestFullscreen():typeof s.mozRequestFullScreen=="function"?s.mozRequestFullScreen():typeof s.msRequestFullscreen=="function"&&s.msRequestFullscreen()}exitFullscreen(){const t=this.getFullscreenTarget()?.ownerDocument??document;X(t)&&(typeof t.exitFullscreen=="function"?t.exitFullscreen():typeof t.webkitExitFullscreen=="function"?t.webkitExitFullscreen():typeof t.mozCancelFullScreen=="function"?t.mozCancelFullScreen():typeof t.msExitFullscreen=="function"&&t.msExitFullscreen())}resetImage(){this.computedImageRatio=O(this.config.imageRatio);const e=this.currentMeta();e&&(e.rotate=0,e.scaleX=0,e.scaleY=0,this.setImageStyle())}toggleTooltip(e){const t=this.$dom.$viewerRatioTooltipElement;t&&this.setTimer(()=>{L(t,e?"show":"hidden"),R(t,e?"hidden":"show")},100)}baseToggle(e,t){const{closeTime:s}=this.config,n=this.$dom.$el;n&&this.setTimer(()=>{L(n,e?"show":"hidden"),R(n,e?"hidden":"show")},t||s)}async close(e){this.resetImage(),this.stopCarousel(),this.isPlaying=!1,this.baseToggle(!1,e)}viewImage(e){E(e)&&e>=0&&e<=this.imageDataList.length-1&&(this.currentImageIndex=e),this.open()}open(e){if(!this.$dom.$el){this.pendingOpen={time:e};return}this.changeThumbImage(),this.setTrackPosition(this.indexToPos(this.currentImageIndex),!1),this.setImageStyle(),this.baseToggle(!0,e)}update(){this.options&&this.reload(this.options)}destroy(){this.teardown(),this.isPlaying=!1,this.fullScreenStatus=!1,this.pendingOpen=null}}return Re}();
|