viewer.js 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569
  1. /*!
  2. * Viewer.js v1.10.2
  3. * https://fengyuanchen.github.io/viewerjs
  4. *
  5. * Copyright 2015-present Chen Fengyuan
  6. * Released under the MIT license
  7. *
  8. * Date: 2021-10-22T13:59:51.046Z
  9. */
  10. (function (global, factory) {
  11. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  12. typeof define === 'function' && define.amd ? define(factory) :
  13. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Viewer = factory());
  14. })(this, (function () { 'use strict';
  15. function ownKeys(object, enumerableOnly) {
  16. var keys = Object.keys(object);
  17. if (Object.getOwnPropertySymbols) {
  18. var symbols = Object.getOwnPropertySymbols(object);
  19. if (enumerableOnly) {
  20. symbols = symbols.filter(function (sym) {
  21. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  22. });
  23. }
  24. keys.push.apply(keys, symbols);
  25. }
  26. return keys;
  27. }
  28. function _objectSpread2(target) {
  29. for (var i = 1; i < arguments.length; i++) {
  30. var source = arguments[i] != null ? arguments[i] : {};
  31. if (i % 2) {
  32. ownKeys(Object(source), true).forEach(function (key) {
  33. _defineProperty(target, key, source[key]);
  34. });
  35. } else if (Object.getOwnPropertyDescriptors) {
  36. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  37. } else {
  38. ownKeys(Object(source)).forEach(function (key) {
  39. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  40. });
  41. }
  42. }
  43. return target;
  44. }
  45. function _typeof(obj) {
  46. "@babel/helpers - typeof";
  47. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  48. _typeof = function (obj) {
  49. return typeof obj;
  50. };
  51. } else {
  52. _typeof = function (obj) {
  53. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  54. };
  55. }
  56. return _typeof(obj);
  57. }
  58. function _classCallCheck(instance, Constructor) {
  59. if (!(instance instanceof Constructor)) {
  60. throw new TypeError("Cannot call a class as a function");
  61. }
  62. }
  63. function _defineProperties(target, props) {
  64. for (var i = 0; i < props.length; i++) {
  65. var descriptor = props[i];
  66. descriptor.enumerable = descriptor.enumerable || false;
  67. descriptor.configurable = true;
  68. if ("value" in descriptor) descriptor.writable = true;
  69. Object.defineProperty(target, descriptor.key, descriptor);
  70. }
  71. }
  72. function _createClass(Constructor, protoProps, staticProps) {
  73. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  74. if (staticProps) _defineProperties(Constructor, staticProps);
  75. return Constructor;
  76. }
  77. function _defineProperty(obj, key, value) {
  78. if (key in obj) {
  79. Object.defineProperty(obj, key, {
  80. value: value,
  81. enumerable: true,
  82. configurable: true,
  83. writable: true
  84. });
  85. } else {
  86. obj[key] = value;
  87. }
  88. return obj;
  89. }
  90. var DEFAULTS = {
  91. /**
  92. * Enable a modal backdrop, specify `static` for a backdrop
  93. * which doesn't close the modal on click.
  94. * @type {boolean}
  95. */
  96. backdrop: true,
  97. /**
  98. * Show the button on the top-right of the viewer.
  99. * @type {boolean}
  100. */
  101. button: true,
  102. /**
  103. * Show the navbar.
  104. * @type {boolean | number}
  105. */
  106. navbar: true,
  107. /**
  108. * Specify the visibility and the content of the title.
  109. * @type {boolean | number | Function | Array}
  110. */
  111. title: true,
  112. /**
  113. * Show the toolbar.
  114. * @type {boolean | number | Object}
  115. */
  116. toolbar: true,
  117. /**
  118. * Custom class name(s) to add to the viewer's root element.
  119. * @type {string}
  120. */
  121. className: '',
  122. /**
  123. * Define where to put the viewer in modal mode.
  124. * @type {string | Element}
  125. */
  126. container: 'body',
  127. /**
  128. * Filter the images for viewing. Return true if the image is viewable.
  129. * @type {Function}
  130. */
  131. filter: null,
  132. /**
  133. * Enable to request fullscreen when play.
  134. * {@link https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions}
  135. * @type {boolean|FullscreenOptions}
  136. */
  137. fullscreen: true,
  138. /**
  139. * Define the extra attributes to inherit from the original image.
  140. * @type {Array}
  141. */
  142. inheritedAttributes: ['crossOrigin', 'decoding', 'isMap', 'loading', 'referrerPolicy', 'sizes', 'srcset', 'useMap'],
  143. /**
  144. * Define the initial index of image for viewing.
  145. * @type {number}
  146. */
  147. initialViewIndex: 0,
  148. /**
  149. * Enable inline mode.
  150. * @type {boolean}
  151. */
  152. inline: false,
  153. /**
  154. * The amount of time to delay between automatically cycling an image when playing.
  155. * @type {number}
  156. */
  157. interval: 5000,
  158. /**
  159. * Enable keyboard support.
  160. * @type {boolean}
  161. */
  162. keyboard: true,
  163. /**
  164. * Focus the viewer when initialized.
  165. * @type {boolean}
  166. */
  167. focus: true,
  168. /**
  169. * Indicate if show a loading spinner when load image or not.
  170. * @type {boolean}
  171. */
  172. loading: true,
  173. /**
  174. * Indicate if enable loop viewing or not.
  175. * @type {boolean}
  176. */
  177. loop: true,
  178. /**
  179. * Min width of the viewer in inline mode.
  180. * @type {number}
  181. */
  182. minWidth: 200,
  183. /**
  184. * Min height of the viewer in inline mode.
  185. * @type {number}
  186. */
  187. minHeight: 100,
  188. /**
  189. * Enable to move the image.
  190. * @type {boolean}
  191. */
  192. movable: true,
  193. /**
  194. * Enable to rotate the image.
  195. * @type {boolean}
  196. */
  197. rotatable: true,
  198. /**
  199. * Enable to scale the image.
  200. * @type {boolean}
  201. */
  202. scalable: true,
  203. /**
  204. * Enable to zoom the image.
  205. * @type {boolean}
  206. */
  207. zoomable: true,
  208. /**
  209. * Enable to zoom the current image by dragging on the touch screen.
  210. * @type {boolean}
  211. */
  212. zoomOnTouch: true,
  213. /**
  214. * Enable to zoom the image by wheeling mouse.
  215. * @type {boolean}
  216. */
  217. zoomOnWheel: true,
  218. /**
  219. * Enable to slide to the next or previous image by swiping on the touch screen.
  220. * @type {boolean}
  221. */
  222. slideOnTouch: true,
  223. /**
  224. * Indicate if toggle the image size between its natural size
  225. * and initial size when double click on the image or not.
  226. * @type {boolean}
  227. */
  228. toggleOnDblclick: true,
  229. /**
  230. * Show the tooltip with image ratio (percentage) when zoom in or zoom out.
  231. * @type {boolean}
  232. */
  233. tooltip: true,
  234. /**
  235. * Enable CSS3 Transition for some special elements.
  236. * @type {boolean}
  237. */
  238. transition: true,
  239. /**
  240. * Define the CSS `z-index` value of viewer in modal mode.
  241. * @type {number}
  242. */
  243. zIndex: 2015,
  244. /**
  245. * Define the CSS `z-index` value of viewer in inline mode.
  246. * @type {number}
  247. */
  248. zIndexInline: 0,
  249. /**
  250. * Define the ratio when zoom the image by wheeling mouse.
  251. * @type {number}
  252. */
  253. zoomRatio: 0.1,
  254. /**
  255. * Define the min ratio of the image when zoom out.
  256. * @type {number}
  257. */
  258. minZoomRatio: 0.01,
  259. /**
  260. * Define the max ratio of the image when zoom in.
  261. * @type {number}
  262. */
  263. maxZoomRatio: 100,
  264. /**
  265. * Define where to get the original image URL for viewing.
  266. * @type {string | Function}
  267. */
  268. url: 'src',
  269. /**
  270. * Event shortcuts.
  271. * @type {Function}
  272. */
  273. ready: null,
  274. show: null,
  275. shown: null,
  276. hide: null,
  277. hidden: null,
  278. view: null,
  279. viewed: null,
  280. move: null,
  281. moved: null,
  282. rotate: null,
  283. rotated: null,
  284. scale: null,
  285. scaled: null,
  286. zoom: null,
  287. zoomed: null,
  288. play: null,
  289. stop: null
  290. };
  291. var TEMPLATE = '<div class="viewer-container" tabindex="-1" touch-action="none">' + '<div class="viewer-canvas"></div>' + '<div class="viewer-footer">' + '<div class="viewer-title"></div>' + '<div class="viewer-toolbar"></div>' + '<div class="viewer-navbar">' + '<ul class="viewer-list" role="navigation"></ul>' + '</div>' + '</div>' + '<div class="viewer-tooltip" role="alert" aria-hidden="true"></div>' + '<div class="viewer-button" data-viewer-action="mix" role="button"></div>' + '<div class="viewer-player"></div>' + '</div>';
  292. var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
  293. var WINDOW = IS_BROWSER ? window : {};
  294. var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false;
  295. var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false;
  296. var NAMESPACE = 'viewer'; // Actions
  297. var ACTION_MOVE = 'move';
  298. var ACTION_SWITCH = 'switch';
  299. var ACTION_ZOOM = 'zoom'; // Classes
  300. var CLASS_ACTIVE = "".concat(NAMESPACE, "-active");
  301. var CLASS_CLOSE = "".concat(NAMESPACE, "-close");
  302. var CLASS_FADE = "".concat(NAMESPACE, "-fade");
  303. var CLASS_FIXED = "".concat(NAMESPACE, "-fixed");
  304. var CLASS_FULLSCREEN = "".concat(NAMESPACE, "-fullscreen");
  305. var CLASS_FULLSCREEN_EXIT = "".concat(NAMESPACE, "-fullscreen-exit");
  306. var CLASS_HIDE = "".concat(NAMESPACE, "-hide");
  307. var CLASS_HIDE_MD_DOWN = "".concat(NAMESPACE, "-hide-md-down");
  308. var CLASS_HIDE_SM_DOWN = "".concat(NAMESPACE, "-hide-sm-down");
  309. var CLASS_HIDE_XS_DOWN = "".concat(NAMESPACE, "-hide-xs-down");
  310. var CLASS_IN = "".concat(NAMESPACE, "-in");
  311. var CLASS_INVISIBLE = "".concat(NAMESPACE, "-invisible");
  312. var CLASS_LOADING = "".concat(NAMESPACE, "-loading");
  313. var CLASS_MOVE = "".concat(NAMESPACE, "-move");
  314. var CLASS_OPEN = "".concat(NAMESPACE, "-open");
  315. var CLASS_SHOW = "".concat(NAMESPACE, "-show");
  316. var CLASS_TRANSITION = "".concat(NAMESPACE, "-transition"); // Native events
  317. var EVENT_CLICK = 'click';
  318. var EVENT_DBLCLICK = 'dblclick';
  319. var EVENT_DRAG_START = 'dragstart';
  320. var EVENT_FOCUSIN = 'focusin';
  321. var EVENT_KEY_DOWN = 'keydown';
  322. var EVENT_LOAD = 'load';
  323. var EVENT_ERROR = 'error';
  324. var EVENT_TOUCH_END = IS_TOUCH_DEVICE ? 'touchend touchcancel' : 'mouseup';
  325. var EVENT_TOUCH_MOVE = IS_TOUCH_DEVICE ? 'touchmove' : 'mousemove';
  326. var EVENT_TOUCH_START = IS_TOUCH_DEVICE ? 'touchstart' : 'mousedown';
  327. var EVENT_POINTER_DOWN = HAS_POINTER_EVENT ? 'pointerdown' : EVENT_TOUCH_START;
  328. var EVENT_POINTER_MOVE = HAS_POINTER_EVENT ? 'pointermove' : EVENT_TOUCH_MOVE;
  329. var EVENT_POINTER_UP = HAS_POINTER_EVENT ? 'pointerup pointercancel' : EVENT_TOUCH_END;
  330. var EVENT_RESIZE = 'resize';
  331. var EVENT_TRANSITION_END = 'transitionend';
  332. var EVENT_WHEEL = 'wheel'; // Custom events
  333. var EVENT_READY = 'ready';
  334. var EVENT_SHOW = 'show';
  335. var EVENT_SHOWN = 'shown';
  336. var EVENT_HIDE = 'hide';
  337. var EVENT_HIDDEN = 'hidden';
  338. var EVENT_VIEW = 'view';
  339. var EVENT_VIEWED = 'viewed';
  340. var EVENT_MOVE = 'move';
  341. var EVENT_MOVED = 'moved';
  342. var EVENT_ROTATE = 'rotate';
  343. var EVENT_ROTATED = 'rotated';
  344. var EVENT_SCALE = 'scale';
  345. var EVENT_SCALED = 'scaled';
  346. var EVENT_ZOOM = 'zoom';
  347. var EVENT_ZOOMED = 'zoomed';
  348. var EVENT_PLAY = 'play';
  349. var EVENT_STOP = 'stop'; // Data keys
  350. var DATA_ACTION = "".concat(NAMESPACE, "Action"); // RegExps
  351. var REGEXP_SPACES = /\s\s*/; // Misc
  352. var BUTTONS = ['zoom-in', 'zoom-out', 'one-to-one', 'reset', 'prev', 'play', 'next', 'rotate-left', 'rotate-right', 'flip-horizontal', 'flip-vertical'];
  353. /**
  354. * Check if the given value is a string.
  355. * @param {*} value - The value to check.
  356. * @returns {boolean} Returns `true` if the given value is a string, else `false`.
  357. */
  358. function isString(value) {
  359. return typeof value === 'string';
  360. }
  361. /**
  362. * Check if the given value is not a number.
  363. */
  364. var isNaN = Number.isNaN || WINDOW.isNaN;
  365. /**
  366. * Check if the given value is a number.
  367. * @param {*} value - The value to check.
  368. * @returns {boolean} Returns `true` if the given value is a number, else `false`.
  369. */
  370. function isNumber(value) {
  371. return typeof value === 'number' && !isNaN(value);
  372. }
  373. /**
  374. * Check if the given value is undefined.
  375. * @param {*} value - The value to check.
  376. * @returns {boolean} Returns `true` if the given value is undefined, else `false`.
  377. */
  378. function isUndefined(value) {
  379. return typeof value === 'undefined';
  380. }
  381. /**
  382. * Check if the given value is an object.
  383. * @param {*} value - The value to check.
  384. * @returns {boolean} Returns `true` if the given value is an object, else `false`.
  385. */
  386. function isObject(value) {
  387. return _typeof(value) === 'object' && value !== null;
  388. }
  389. var hasOwnProperty = Object.prototype.hasOwnProperty;
  390. /**
  391. * Check if the given value is a plain object.
  392. * @param {*} value - The value to check.
  393. * @returns {boolean} Returns `true` if the given value is a plain object, else `false`.
  394. */
  395. function isPlainObject(value) {
  396. if (!isObject(value)) {
  397. return false;
  398. }
  399. try {
  400. var _constructor = value.constructor;
  401. var prototype = _constructor.prototype;
  402. return _constructor && prototype && hasOwnProperty.call(prototype, 'isPrototypeOf');
  403. } catch (error) {
  404. return false;
  405. }
  406. }
  407. /**
  408. * Check if the given value is a function.
  409. * @param {*} value - The value to check.
  410. * @returns {boolean} Returns `true` if the given value is a function, else `false`.
  411. */
  412. function isFunction(value) {
  413. return typeof value === 'function';
  414. }
  415. /**
  416. * Iterate the given data.
  417. * @param {*} data - The data to iterate.
  418. * @param {Function} callback - The process function for each element.
  419. * @returns {*} The original data.
  420. */
  421. function forEach(data, callback) {
  422. if (data && isFunction(callback)) {
  423. if (Array.isArray(data) || isNumber(data.length)
  424. /* array-like */
  425. ) {
  426. var length = data.length;
  427. var i;
  428. for (i = 0; i < length; i += 1) {
  429. if (callback.call(data, data[i], i, data) === false) {
  430. break;
  431. }
  432. }
  433. } else if (isObject(data)) {
  434. Object.keys(data).forEach(function (key) {
  435. callback.call(data, data[key], key, data);
  436. });
  437. }
  438. }
  439. return data;
  440. }
  441. /**
  442. * Extend the given object.
  443. * @param {*} obj - The object to be extended.
  444. * @param {*} args - The rest objects which will be merged to the first object.
  445. * @returns {Object} The extended object.
  446. */
  447. var assign = Object.assign || function assign(obj) {
  448. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  449. args[_key - 1] = arguments[_key];
  450. }
  451. if (isObject(obj) && args.length > 0) {
  452. args.forEach(function (arg) {
  453. if (isObject(arg)) {
  454. Object.keys(arg).forEach(function (key) {
  455. obj[key] = arg[key];
  456. });
  457. }
  458. });
  459. }
  460. return obj;
  461. };
  462. var REGEXP_SUFFIX = /^(?:width|height|left|top|marginLeft|marginTop)$/;
  463. /**
  464. * Apply styles to the given element.
  465. * @param {Element} element - The target element.
  466. * @param {Object} styles - The styles for applying.
  467. */
  468. function setStyle(element, styles) {
  469. var style = element.style;
  470. forEach(styles, function (value, property) {
  471. if (REGEXP_SUFFIX.test(property) && isNumber(value)) {
  472. value += 'px';
  473. }
  474. style[property] = value;
  475. });
  476. }
  477. /**
  478. * Escape a string for using in HTML.
  479. * @param {String} value - The string to escape.
  480. * @returns {String} Returns the escaped string.
  481. */
  482. function escapeHTMLEntities(value) {
  483. return isString(value) ? value.replace(/&(?!amp;|quot;|#39;|lt;|gt;)/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;') : value;
  484. }
  485. /**
  486. * Check if the given element has a special class.
  487. * @param {Element} element - The element to check.
  488. * @param {string} value - The class to search.
  489. * @returns {boolean} Returns `true` if the special class was found.
  490. */
  491. function hasClass(element, value) {
  492. if (!element || !value) {
  493. return false;
  494. }
  495. return element.classList ? element.classList.contains(value) : element.className.indexOf(value) > -1;
  496. }
  497. /**
  498. * Add classes to the given element.
  499. * @param {Element} element - The target element.
  500. * @param {string} value - The classes to be added.
  501. */
  502. function addClass(element, value) {
  503. if (!element || !value) {
  504. return;
  505. }
  506. if (isNumber(element.length)) {
  507. forEach(element, function (elem) {
  508. addClass(elem, value);
  509. });
  510. return;
  511. }
  512. if (element.classList) {
  513. element.classList.add(value);
  514. return;
  515. }
  516. var className = element.className.trim();
  517. if (!className) {
  518. element.className = value;
  519. } else if (className.indexOf(value) < 0) {
  520. element.className = "".concat(className, " ").concat(value);
  521. }
  522. }
  523. /**
  524. * Remove classes from the given element.
  525. * @param {Element} element - The target element.
  526. * @param {string} value - The classes to be removed.
  527. */
  528. function removeClass(element, value) {
  529. if (!element || !value) {
  530. return;
  531. }
  532. if (isNumber(element.length)) {
  533. forEach(element, function (elem) {
  534. removeClass(elem, value);
  535. });
  536. return;
  537. }
  538. if (element.classList) {
  539. element.classList.remove(value);
  540. return;
  541. }
  542. if (element.className.indexOf(value) >= 0) {
  543. element.className = element.className.replace(value, '');
  544. }
  545. }
  546. /**
  547. * Add or remove classes from the given element.
  548. * @param {Element} element - The target element.
  549. * @param {string} value - The classes to be toggled.
  550. * @param {boolean} added - Add only.
  551. */
  552. function toggleClass(element, value, added) {
  553. if (!value) {
  554. return;
  555. }
  556. if (isNumber(element.length)) {
  557. forEach(element, function (elem) {
  558. toggleClass(elem, value, added);
  559. });
  560. return;
  561. } // IE10-11 doesn't support the second parameter of `classList.toggle`
  562. if (added) {
  563. addClass(element, value);
  564. } else {
  565. removeClass(element, value);
  566. }
  567. }
  568. var REGEXP_HYPHENATE = /([a-z\d])([A-Z])/g;
  569. /**
  570. * Transform the given string from camelCase to kebab-case
  571. * @param {string} value - The value to transform.
  572. * @returns {string} The transformed value.
  573. */
  574. function hyphenate(value) {
  575. return value.replace(REGEXP_HYPHENATE, '$1-$2').toLowerCase();
  576. }
  577. /**
  578. * Get data from the given element.
  579. * @param {Element} element - The target element.
  580. * @param {string} name - The data key to get.
  581. * @returns {string} The data value.
  582. */
  583. function getData(element, name) {
  584. if (isObject(element[name])) {
  585. return element[name];
  586. }
  587. if (element.dataset) {
  588. return element.dataset[name];
  589. }
  590. return element.getAttribute("data-".concat(hyphenate(name)));
  591. }
  592. /**
  593. * Set data to the given element.
  594. * @param {Element} element - The target element.
  595. * @param {string} name - The data key to set.
  596. * @param {string} data - The data value.
  597. */
  598. function setData(element, name, data) {
  599. if (isObject(data)) {
  600. element[name] = data;
  601. } else if (element.dataset) {
  602. element.dataset[name] = data;
  603. } else {
  604. element.setAttribute("data-".concat(hyphenate(name)), data);
  605. }
  606. }
  607. var onceSupported = function () {
  608. var supported = false;
  609. if (IS_BROWSER) {
  610. var once = false;
  611. var listener = function listener() {};
  612. var options = Object.defineProperty({}, 'once', {
  613. get: function get() {
  614. supported = true;
  615. return once;
  616. },
  617. /**
  618. * This setter can fix a `TypeError` in strict mode
  619. * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only}
  620. * @param {boolean} value - The value to set
  621. */
  622. set: function set(value) {
  623. once = value;
  624. }
  625. });
  626. WINDOW.addEventListener('test', listener, options);
  627. WINDOW.removeEventListener('test', listener, options);
  628. }
  629. return supported;
  630. }();
  631. /**
  632. * Remove event listener from the target element.
  633. * @param {Element} element - The event target.
  634. * @param {string} type - The event type(s).
  635. * @param {Function} listener - The event listener.
  636. * @param {Object} options - The event options.
  637. */
  638. function removeListener(element, type, listener) {
  639. var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  640. var handler = listener;
  641. type.trim().split(REGEXP_SPACES).forEach(function (event) {
  642. if (!onceSupported) {
  643. var listeners = element.listeners;
  644. if (listeners && listeners[event] && listeners[event][listener]) {
  645. handler = listeners[event][listener];
  646. delete listeners[event][listener];
  647. if (Object.keys(listeners[event]).length === 0) {
  648. delete listeners[event];
  649. }
  650. if (Object.keys(listeners).length === 0) {
  651. delete element.listeners;
  652. }
  653. }
  654. }
  655. element.removeEventListener(event, handler, options);
  656. });
  657. }
  658. /**
  659. * Add event listener to the target element.
  660. * @param {Element} element - The event target.
  661. * @param {string} type - The event type(s).
  662. * @param {Function} listener - The event listener.
  663. * @param {Object} options - The event options.
  664. */
  665. function addListener(element, type, listener) {
  666. var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  667. var _handler = listener;
  668. type.trim().split(REGEXP_SPACES).forEach(function (event) {
  669. if (options.once && !onceSupported) {
  670. var _element$listeners = element.listeners,
  671. listeners = _element$listeners === void 0 ? {} : _element$listeners;
  672. _handler = function handler() {
  673. delete listeners[event][listener];
  674. element.removeEventListener(event, _handler, options);
  675. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  676. args[_key2] = arguments[_key2];
  677. }
  678. listener.apply(element, args);
  679. };
  680. if (!listeners[event]) {
  681. listeners[event] = {};
  682. }
  683. if (listeners[event][listener]) {
  684. element.removeEventListener(event, listeners[event][listener], options);
  685. }
  686. listeners[event][listener] = _handler;
  687. element.listeners = listeners;
  688. }
  689. element.addEventListener(event, _handler, options);
  690. });
  691. }
  692. /**
  693. * Dispatch event on the target element.
  694. * @param {Element} element - The event target.
  695. * @param {string} type - The event type(s).
  696. * @param {Object} data - The additional event data.
  697. * @param {Object} options - The additional event options.
  698. * @returns {boolean} Indicate if the event is default prevented or not.
  699. */
  700. function dispatchEvent(element, type, data, options) {
  701. var event; // Event and CustomEvent on IE9-11 are global objects, not constructors
  702. if (isFunction(Event) && isFunction(CustomEvent)) {
  703. event = new CustomEvent(type, _objectSpread2({
  704. bubbles: true,
  705. cancelable: true,
  706. detail: data
  707. }, options));
  708. } else {
  709. event = document.createEvent('CustomEvent');
  710. event.initCustomEvent(type, true, true, data);
  711. }
  712. return element.dispatchEvent(event);
  713. }
  714. /**
  715. * Get the offset base on the document.
  716. * @param {Element} element - The target element.
  717. * @returns {Object} The offset data.
  718. */
  719. function getOffset(element) {
  720. var box = element.getBoundingClientRect();
  721. return {
  722. left: box.left + (window.pageXOffset - document.documentElement.clientLeft),
  723. top: box.top + (window.pageYOffset - document.documentElement.clientTop)
  724. };
  725. }
  726. /**
  727. * Get transforms base on the given object.
  728. * @param {Object} obj - The target object.
  729. * @returns {string} A string contains transform values.
  730. */
  731. function getTransforms(_ref) {
  732. var rotate = _ref.rotate,
  733. scaleX = _ref.scaleX,
  734. scaleY = _ref.scaleY,
  735. translateX = _ref.translateX,
  736. translateY = _ref.translateY;
  737. var values = [];
  738. if (isNumber(translateX) && translateX !== 0) {
  739. values.push("translateX(".concat(translateX, "px)"));
  740. }
  741. if (isNumber(translateY) && translateY !== 0) {
  742. values.push("translateY(".concat(translateY, "px)"));
  743. } // Rotate should come first before scale to match orientation transform
  744. if (isNumber(rotate) && rotate !== 0) {
  745. values.push("rotate(".concat(rotate, "deg)"));
  746. }
  747. if (isNumber(scaleX) && scaleX !== 1) {
  748. values.push("scaleX(".concat(scaleX, ")"));
  749. }
  750. if (isNumber(scaleY) && scaleY !== 1) {
  751. values.push("scaleY(".concat(scaleY, ")"));
  752. }
  753. var transform = values.length ? values.join(' ') : 'none';
  754. return {
  755. WebkitTransform: transform,
  756. msTransform: transform,
  757. transform: transform
  758. };
  759. }
  760. /**
  761. * Get an image name from an image url.
  762. * @param {string} url - The target url.
  763. * @example
  764. * // picture.jpg
  765. * getImageNameFromURL('https://domain.com/path/to/picture.jpg?size=1280×960')
  766. * @returns {string} A string contains the image name.
  767. */
  768. function getImageNameFromURL(url) {
  769. return isString(url) ? decodeURIComponent(url.replace(/^.*\//, '').replace(/[?&#].*$/, '')) : '';
  770. }
  771. var IS_SAFARI = WINDOW.navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(WINDOW.navigator.userAgent);
  772. /**
  773. * Get an image's natural sizes.
  774. * @param {string} image - The target image.
  775. * @param {Object} options - The viewer options.
  776. * @param {Function} callback - The callback function.
  777. * @returns {HTMLImageElement} The new image.
  778. */
  779. function getImageNaturalSizes(image, options, callback) {
  780. var newImage = document.createElement('img'); // Modern browsers (except Safari)
  781. if (image.naturalWidth && !IS_SAFARI) {
  782. callback(image.naturalWidth, image.naturalHeight);
  783. return newImage;
  784. }
  785. var body = document.body || document.documentElement;
  786. newImage.onload = function () {
  787. callback(newImage.width, newImage.height);
  788. if (!IS_SAFARI) {
  789. body.removeChild(newImage);
  790. }
  791. };
  792. forEach(options.inheritedAttributes, function (name) {
  793. var value = image.getAttribute(name);
  794. if (value !== null) {
  795. newImage.setAttribute(name, value);
  796. }
  797. });
  798. newImage.src = image.src; // iOS Safari will convert the image automatically
  799. // with its orientation once append it into DOM
  800. if (!IS_SAFARI) {
  801. newImage.style.cssText = 'left:0;' + 'max-height:none!important;' + 'max-width:none!important;' + 'min-height:0!important;' + 'min-width:0!important;' + 'opacity:0;' + 'position:absolute;' + 'top:0;' + 'z-index:-1;';
  802. body.appendChild(newImage);
  803. }
  804. return newImage;
  805. }
  806. /**
  807. * Get the related class name of a responsive type number.
  808. * @param {string} type - The responsive type.
  809. * @returns {string} The related class name.
  810. */
  811. function getResponsiveClass(type) {
  812. switch (type) {
  813. case 2:
  814. return CLASS_HIDE_XS_DOWN;
  815. case 3:
  816. return CLASS_HIDE_SM_DOWN;
  817. case 4:
  818. return CLASS_HIDE_MD_DOWN;
  819. default:
  820. return '';
  821. }
  822. }
  823. /**
  824. * Get the max ratio of a group of pointers.
  825. * @param {string} pointers - The target pointers.
  826. * @returns {number} The result ratio.
  827. */
  828. function getMaxZoomRatio(pointers) {
  829. var pointers2 = _objectSpread2({}, pointers);
  830. var ratios = [];
  831. forEach(pointers, function (pointer, pointerId) {
  832. delete pointers2[pointerId];
  833. forEach(pointers2, function (pointer2) {
  834. var x1 = Math.abs(pointer.startX - pointer2.startX);
  835. var y1 = Math.abs(pointer.startY - pointer2.startY);
  836. var x2 = Math.abs(pointer.endX - pointer2.endX);
  837. var y2 = Math.abs(pointer.endY - pointer2.endY);
  838. var z1 = Math.sqrt(x1 * x1 + y1 * y1);
  839. var z2 = Math.sqrt(x2 * x2 + y2 * y2);
  840. var ratio = (z2 - z1) / z1;
  841. ratios.push(ratio);
  842. });
  843. });
  844. ratios.sort(function (a, b) {
  845. return Math.abs(a) < Math.abs(b);
  846. });
  847. return ratios[0];
  848. }
  849. /**
  850. * Get a pointer from an event object.
  851. * @param {Object} event - The target event object.
  852. * @param {boolean} endOnly - Indicates if only returns the end point coordinate or not.
  853. * @returns {Object} The result pointer contains start and/or end point coordinates.
  854. */
  855. function getPointer(_ref2, endOnly) {
  856. var pageX = _ref2.pageX,
  857. pageY = _ref2.pageY;
  858. var end = {
  859. endX: pageX,
  860. endY: pageY
  861. };
  862. return endOnly ? end : _objectSpread2({
  863. timeStamp: Date.now(),
  864. startX: pageX,
  865. startY: pageY
  866. }, end);
  867. }
  868. /**
  869. * Get the center point coordinate of a group of pointers.
  870. * @param {Object} pointers - The target pointers.
  871. * @returns {Object} The center point coordinate.
  872. */
  873. function getPointersCenter(pointers) {
  874. var pageX = 0;
  875. var pageY = 0;
  876. var count = 0;
  877. forEach(pointers, function (_ref3) {
  878. var startX = _ref3.startX,
  879. startY = _ref3.startY;
  880. pageX += startX;
  881. pageY += startY;
  882. count += 1;
  883. });
  884. pageX /= count;
  885. pageY /= count;
  886. return {
  887. pageX: pageX,
  888. pageY: pageY
  889. };
  890. }
  891. var render = {
  892. render: function render() {
  893. this.initContainer();
  894. this.initViewer();
  895. this.initList();
  896. this.renderViewer();
  897. },
  898. initBody: function initBody() {
  899. var ownerDocument = this.element.ownerDocument;
  900. var body = ownerDocument.body || ownerDocument.documentElement;
  901. this.body = body;
  902. this.scrollbarWidth = window.innerWidth - ownerDocument.documentElement.clientWidth;
  903. this.initialBodyPaddingRight = body.style.paddingRight;
  904. this.initialBodyComputedPaddingRight = window.getComputedStyle(body).paddingRight;
  905. },
  906. initContainer: function initContainer() {
  907. this.containerData = {
  908. width: window.innerWidth,
  909. height: window.innerHeight
  910. };
  911. },
  912. initViewer: function initViewer() {
  913. var options = this.options,
  914. parent = this.parent;
  915. var viewerData;
  916. if (options.inline) {
  917. viewerData = {
  918. width: Math.max(parent.offsetWidth, options.minWidth),
  919. height: Math.max(parent.offsetHeight, options.minHeight)
  920. };
  921. this.parentData = viewerData;
  922. }
  923. if (this.fulled || !viewerData) {
  924. viewerData = this.containerData;
  925. }
  926. this.viewerData = assign({}, viewerData);
  927. },
  928. renderViewer: function renderViewer() {
  929. if (this.options.inline && !this.fulled) {
  930. setStyle(this.viewer, this.viewerData);
  931. }
  932. },
  933. initList: function initList() {
  934. var _this = this;
  935. var element = this.element,
  936. options = this.options,
  937. list = this.list;
  938. var items = []; // initList may be called in this.update, so should keep idempotent
  939. list.innerHTML = '';
  940. forEach(this.images, function (image, index) {
  941. var src = image.src;
  942. var alt = image.alt || getImageNameFromURL(src);
  943. var url = _this.getImageURL(image);
  944. if (src || url) {
  945. var item = document.createElement('li');
  946. var img = document.createElement('img');
  947. forEach(options.inheritedAttributes, function (name) {
  948. var value = image.getAttribute(name);
  949. if (value !== null) {
  950. img.setAttribute(name, value);
  951. }
  952. });
  953. img.src = src || url;
  954. img.alt = alt;
  955. img.setAttribute('data-original-url', url || src);
  956. item.setAttribute('data-index', index);
  957. item.setAttribute('data-viewer-action', 'view');
  958. item.setAttribute('role', 'button');
  959. if (options.keyboard) {
  960. item.setAttribute('tabindex', 0);
  961. }
  962. item.appendChild(img);
  963. list.appendChild(item);
  964. items.push(item);
  965. }
  966. });
  967. this.items = items;
  968. forEach(items, function (item) {
  969. var image = item.firstElementChild;
  970. var onLoad;
  971. var onError;
  972. setData(image, 'filled', true);
  973. if (options.loading) {
  974. addClass(item, CLASS_LOADING);
  975. }
  976. addListener(image, EVENT_LOAD, onLoad = function onLoad(event) {
  977. removeListener(image, EVENT_ERROR, onError);
  978. if (options.loading) {
  979. removeClass(item, CLASS_LOADING);
  980. }
  981. _this.loadImage(event);
  982. }, {
  983. once: true
  984. });
  985. addListener(image, EVENT_ERROR, onError = function onError() {
  986. removeListener(image, EVENT_LOAD, onLoad);
  987. if (options.loading) {
  988. removeClass(item, CLASS_LOADING);
  989. }
  990. }, {
  991. once: true
  992. });
  993. });
  994. if (options.transition) {
  995. addListener(element, EVENT_VIEWED, function () {
  996. addClass(list, CLASS_TRANSITION);
  997. }, {
  998. once: true
  999. });
  1000. }
  1001. },
  1002. renderList: function renderList() {
  1003. var index = this.index;
  1004. var item = this.items[index];
  1005. if (!item) {
  1006. return;
  1007. }
  1008. var next = item.nextElementSibling;
  1009. var gutter = parseInt(window.getComputedStyle(next || item).marginLeft, 10);
  1010. var offsetWidth = item.offsetWidth;
  1011. var outerWidth = offsetWidth + gutter; // Place the active item in the center of the screen
  1012. setStyle(this.list, assign({
  1013. width: outerWidth * this.length - gutter
  1014. }, getTransforms({
  1015. translateX: (this.viewerData.width - offsetWidth) / 2 - outerWidth * index
  1016. })));
  1017. },
  1018. resetList: function resetList() {
  1019. var list = this.list;
  1020. list.innerHTML = '';
  1021. removeClass(list, CLASS_TRANSITION);
  1022. setStyle(list, getTransforms({
  1023. translateX: 0
  1024. }));
  1025. },
  1026. initImage: function initImage(done) {
  1027. var _this2 = this;
  1028. var options = this.options,
  1029. image = this.image,
  1030. viewerData = this.viewerData;
  1031. var footerHeight = this.footer.offsetHeight;
  1032. var viewerWidth = viewerData.width;
  1033. var viewerHeight = Math.max(viewerData.height - footerHeight, footerHeight);
  1034. var oldImageData = this.imageData || {};
  1035. var sizingImage;
  1036. this.imageInitializing = {
  1037. abort: function abort() {
  1038. sizingImage.onload = null;
  1039. }
  1040. };
  1041. sizingImage = getImageNaturalSizes(image, options, function (naturalWidth, naturalHeight) {
  1042. var aspectRatio = naturalWidth / naturalHeight;
  1043. var width = viewerWidth;
  1044. var height = viewerHeight;
  1045. _this2.imageInitializing = false;
  1046. if (viewerHeight * aspectRatio > viewerWidth) {
  1047. height = viewerWidth / aspectRatio;
  1048. } else {
  1049. width = viewerHeight * aspectRatio;
  1050. }
  1051. width = Math.min(width * 0.9, naturalWidth);
  1052. height = Math.min(height * 0.9, naturalHeight);
  1053. var left = (viewerWidth - width) / 2;
  1054. var top = (viewerHeight - height) / 2;
  1055. var imageData = {
  1056. left: left,
  1057. top: top,
  1058. x: left,
  1059. y: top,
  1060. width: width,
  1061. height: height,
  1062. oldRatio: 1,
  1063. ratio: width / naturalWidth,
  1064. aspectRatio: aspectRatio,
  1065. naturalWidth: naturalWidth,
  1066. naturalHeight: naturalHeight
  1067. };
  1068. var initialImageData = assign({}, imageData);
  1069. if (options.rotatable) {
  1070. imageData.rotate = oldImageData.rotate || 0;
  1071. initialImageData.rotate = 0;
  1072. }
  1073. if (options.scalable) {
  1074. imageData.scaleX = oldImageData.scaleX || 1;
  1075. imageData.scaleY = oldImageData.scaleY || 1;
  1076. initialImageData.scaleX = 1;
  1077. initialImageData.scaleY = 1;
  1078. }
  1079. _this2.imageData = imageData;
  1080. _this2.initialImageData = initialImageData;
  1081. if (done) {
  1082. done();
  1083. }
  1084. });
  1085. },
  1086. renderImage: function renderImage(done) {
  1087. var _this3 = this;
  1088. var image = this.image,
  1089. imageData = this.imageData;
  1090. setStyle(image, assign({
  1091. width: imageData.width,
  1092. height: imageData.height,
  1093. // XXX: Not to use translateX/Y to avoid image shaking when zooming
  1094. marginLeft: imageData.x,
  1095. marginTop: imageData.y
  1096. }, getTransforms(imageData)));
  1097. if (done) {
  1098. if ((this.viewing || this.moving || this.rotating || this.scaling || this.zooming) && this.options.transition && hasClass(image, CLASS_TRANSITION)) {
  1099. var onTransitionEnd = function onTransitionEnd() {
  1100. _this3.imageRendering = false;
  1101. done();
  1102. };
  1103. this.imageRendering = {
  1104. abort: function abort() {
  1105. removeListener(image, EVENT_TRANSITION_END, onTransitionEnd);
  1106. }
  1107. };
  1108. addListener(image, EVENT_TRANSITION_END, onTransitionEnd, {
  1109. once: true
  1110. });
  1111. } else {
  1112. done();
  1113. }
  1114. }
  1115. },
  1116. resetImage: function resetImage() {
  1117. // this.image only defined after viewed
  1118. if (this.viewing || this.viewed) {
  1119. var image = this.image;
  1120. if (this.viewing) {
  1121. this.viewing.abort();
  1122. }
  1123. image.parentNode.removeChild(image);
  1124. this.image = null;
  1125. }
  1126. }
  1127. };
  1128. var events = {
  1129. bind: function bind() {
  1130. var options = this.options,
  1131. viewer = this.viewer,
  1132. canvas = this.canvas;
  1133. var document = this.element.ownerDocument;
  1134. addListener(viewer, EVENT_CLICK, this.onClick = this.click.bind(this));
  1135. addListener(viewer, EVENT_DRAG_START, this.onDragStart = this.dragstart.bind(this));
  1136. addListener(canvas, EVENT_POINTER_DOWN, this.onPointerDown = this.pointerdown.bind(this));
  1137. addListener(document, EVENT_POINTER_MOVE, this.onPointerMove = this.pointermove.bind(this));
  1138. addListener(document, EVENT_POINTER_UP, this.onPointerUp = this.pointerup.bind(this));
  1139. addListener(document, EVENT_KEY_DOWN, this.onKeyDown = this.keydown.bind(this));
  1140. addListener(window, EVENT_RESIZE, this.onResize = this.resize.bind(this));
  1141. if (options.zoomable && options.zoomOnWheel) {
  1142. addListener(viewer, EVENT_WHEEL, this.onWheel = this.wheel.bind(this), {
  1143. passive: false,
  1144. capture: true
  1145. });
  1146. }
  1147. if (options.toggleOnDblclick) {
  1148. addListener(canvas, EVENT_DBLCLICK, this.onDblclick = this.dblclick.bind(this));
  1149. }
  1150. },
  1151. unbind: function unbind() {
  1152. var options = this.options,
  1153. viewer = this.viewer,
  1154. canvas = this.canvas;
  1155. var document = this.element.ownerDocument;
  1156. removeListener(viewer, EVENT_CLICK, this.onClick);
  1157. removeListener(viewer, EVENT_DRAG_START, this.onDragStart);
  1158. removeListener(canvas, EVENT_POINTER_DOWN, this.onPointerDown);
  1159. removeListener(document, EVENT_POINTER_MOVE, this.onPointerMove);
  1160. removeListener(document, EVENT_POINTER_UP, this.onPointerUp);
  1161. removeListener(document, EVENT_KEY_DOWN, this.onKeyDown);
  1162. removeListener(window, EVENT_RESIZE, this.onResize);
  1163. if (options.zoomable && options.zoomOnWheel) {
  1164. removeListener(viewer, EVENT_WHEEL, this.onWheel, {
  1165. passive: false,
  1166. capture: true
  1167. });
  1168. }
  1169. if (options.toggleOnDblclick) {
  1170. removeListener(canvas, EVENT_DBLCLICK, this.onDblclick);
  1171. }
  1172. }
  1173. };
  1174. var handlers = {
  1175. click: function click(event) {
  1176. var options = this.options,
  1177. imageData = this.imageData;
  1178. var target = event.target;
  1179. var action = getData(target, DATA_ACTION);
  1180. if (!action && target.localName === 'img' && target.parentElement.localName === 'li') {
  1181. target = target.parentElement;
  1182. action = getData(target, DATA_ACTION);
  1183. } // Cancel the emulated click when the native click event was triggered.
  1184. if (IS_TOUCH_DEVICE && event.isTrusted && target === this.canvas) {
  1185. clearTimeout(this.clickCanvasTimeout);
  1186. }
  1187. switch (action) {
  1188. case 'mix':
  1189. if (this.played) {
  1190. this.stop();
  1191. } else if (options.inline) {
  1192. if (this.fulled) {
  1193. this.exit();
  1194. } else {
  1195. this.full();
  1196. }
  1197. } else {
  1198. this.hide();
  1199. }
  1200. break;
  1201. case 'hide':
  1202. this.hide();
  1203. break;
  1204. case 'view':
  1205. this.view(getData(target, 'index'));
  1206. break;
  1207. case 'zoom-in':
  1208. this.zoom(0.1, true);
  1209. break;
  1210. case 'zoom-out':
  1211. this.zoom(-0.1, true);
  1212. break;
  1213. case 'one-to-one':
  1214. this.toggle();
  1215. break;
  1216. case 'reset':
  1217. this.reset();
  1218. break;
  1219. case 'prev':
  1220. this.prev(options.loop);
  1221. break;
  1222. case 'play':
  1223. this.play(options.fullscreen);
  1224. break;
  1225. case 'next':
  1226. this.next(options.loop);
  1227. break;
  1228. case 'rotate-left':
  1229. this.rotate(-90);
  1230. break;
  1231. case 'rotate-right':
  1232. this.rotate(90);
  1233. break;
  1234. case 'flip-horizontal':
  1235. this.scaleX(-imageData.scaleX || -1);
  1236. break;
  1237. case 'flip-vertical':
  1238. this.scaleY(-imageData.scaleY || -1);
  1239. break;
  1240. default:
  1241. if (this.played) {
  1242. this.stop();
  1243. }
  1244. }
  1245. },
  1246. dblclick: function dblclick(event) {
  1247. event.preventDefault();
  1248. if (this.viewed && event.target === this.image) {
  1249. // Cancel the emulated double click when the native dblclick event was triggered.
  1250. if (IS_TOUCH_DEVICE && event.isTrusted) {
  1251. clearTimeout(this.doubleClickImageTimeout);
  1252. }
  1253. this.toggle(event);
  1254. }
  1255. },
  1256. load: function load() {
  1257. var _this = this;
  1258. if (this.timeout) {
  1259. clearTimeout(this.timeout);
  1260. this.timeout = false;
  1261. }
  1262. var element = this.element,
  1263. options = this.options,
  1264. image = this.image,
  1265. index = this.index,
  1266. viewerData = this.viewerData;
  1267. removeClass(image, CLASS_INVISIBLE);
  1268. if (options.loading) {
  1269. removeClass(this.canvas, CLASS_LOADING);
  1270. }
  1271. image.style.cssText = 'height:0;' + "margin-left:".concat(viewerData.width / 2, "px;") + "margin-top:".concat(viewerData.height / 2, "px;") + 'max-width:none!important;' + 'position:relative;' + 'width:0;';
  1272. this.initImage(function () {
  1273. toggleClass(image, CLASS_MOVE, options.movable);
  1274. toggleClass(image, CLASS_TRANSITION, options.transition);
  1275. _this.renderImage(function () {
  1276. _this.viewed = true;
  1277. _this.viewing = false;
  1278. if (isFunction(options.viewed)) {
  1279. addListener(element, EVENT_VIEWED, options.viewed, {
  1280. once: true
  1281. });
  1282. }
  1283. dispatchEvent(element, EVENT_VIEWED, {
  1284. originalImage: _this.images[index],
  1285. index: index,
  1286. image: image
  1287. }, {
  1288. cancelable: false
  1289. });
  1290. });
  1291. });
  1292. },
  1293. loadImage: function loadImage(event) {
  1294. var image = event.target;
  1295. var parent = image.parentNode;
  1296. var parentWidth = parent.offsetWidth || 30;
  1297. var parentHeight = parent.offsetHeight || 50;
  1298. var filled = !!getData(image, 'filled');
  1299. getImageNaturalSizes(image, this.options, function (naturalWidth, naturalHeight) {
  1300. var aspectRatio = naturalWidth / naturalHeight;
  1301. var width = parentWidth;
  1302. var height = parentHeight;
  1303. if (parentHeight * aspectRatio > parentWidth) {
  1304. if (filled) {
  1305. width = parentHeight * aspectRatio;
  1306. } else {
  1307. height = parentWidth / aspectRatio;
  1308. }
  1309. } else if (filled) {
  1310. height = parentWidth / aspectRatio;
  1311. } else {
  1312. width = parentHeight * aspectRatio;
  1313. }
  1314. setStyle(image, assign({
  1315. width: width,
  1316. height: height
  1317. }, getTransforms({
  1318. translateX: (parentWidth - width) / 2,
  1319. translateY: (parentHeight - height) / 2
  1320. })));
  1321. });
  1322. },
  1323. keydown: function keydown(event) {
  1324. var options = this.options;
  1325. if (!options.keyboard) {
  1326. return;
  1327. }
  1328. var keyCode = event.keyCode || event.which || event.charCode;
  1329. switch (keyCode) {
  1330. // Enter
  1331. case 13:
  1332. if (this.viewer.contains(event.target)) {
  1333. this.click(event);
  1334. }
  1335. break;
  1336. }
  1337. if (!this.fulled) {
  1338. return;
  1339. }
  1340. switch (keyCode) {
  1341. // Escape
  1342. case 27:
  1343. if (this.played) {
  1344. this.stop();
  1345. } else if (options.inline) {
  1346. if (this.fulled) {
  1347. this.exit();
  1348. }
  1349. } else {
  1350. this.hide();
  1351. }
  1352. break;
  1353. // Space
  1354. case 32:
  1355. if (this.played) {
  1356. this.stop();
  1357. }
  1358. break;
  1359. // ArrowLeft
  1360. case 37:
  1361. this.prev(options.loop);
  1362. break;
  1363. // ArrowUp
  1364. case 38:
  1365. // Prevent scroll on Firefox
  1366. event.preventDefault(); // Zoom in
  1367. this.zoom(options.zoomRatio, true);
  1368. break;
  1369. // ArrowRight
  1370. case 39:
  1371. this.next(options.loop);
  1372. break;
  1373. // ArrowDown
  1374. case 40:
  1375. // Prevent scroll on Firefox
  1376. event.preventDefault(); // Zoom out
  1377. this.zoom(-options.zoomRatio, true);
  1378. break;
  1379. // Ctrl + 0
  1380. case 48: // Fall through
  1381. // Ctrl + 1
  1382. // eslint-disable-next-line no-fallthrough
  1383. case 49:
  1384. if (event.ctrlKey) {
  1385. event.preventDefault();
  1386. this.toggle();
  1387. }
  1388. break;
  1389. }
  1390. },
  1391. dragstart: function dragstart(event) {
  1392. if (event.target.localName === 'img') {
  1393. event.preventDefault();
  1394. }
  1395. },
  1396. pointerdown: function pointerdown(event) {
  1397. var options = this.options,
  1398. pointers = this.pointers;
  1399. var buttons = event.buttons,
  1400. button = event.button;
  1401. if (!this.viewed || this.showing || this.viewing || this.hiding // Handle mouse event and pointer event and ignore touch event
  1402. || (event.type === 'mousedown' || event.type === 'pointerdown' && event.pointerType === 'mouse') && ( // No primary button (Usually the left button)
  1403. isNumber(buttons) && buttons !== 1 || isNumber(button) && button !== 0 // Open context menu
  1404. || event.ctrlKey)) {
  1405. return;
  1406. } // Prevent default behaviours as page zooming in touch devices.
  1407. event.preventDefault();
  1408. if (event.changedTouches) {
  1409. forEach(event.changedTouches, function (touch) {
  1410. pointers[touch.identifier] = getPointer(touch);
  1411. });
  1412. } else {
  1413. pointers[event.pointerId || 0] = getPointer(event);
  1414. }
  1415. var action = options.movable ? ACTION_MOVE : false;
  1416. if (options.zoomOnTouch && options.zoomable && Object.keys(pointers).length > 1) {
  1417. action = ACTION_ZOOM;
  1418. } else if (options.slideOnTouch && (event.pointerType === 'touch' || event.type === 'touchstart') && this.isSwitchable()) {
  1419. action = ACTION_SWITCH;
  1420. }
  1421. if (options.transition && (action === ACTION_MOVE || action === ACTION_ZOOM)) {
  1422. removeClass(this.image, CLASS_TRANSITION);
  1423. }
  1424. this.action = action;
  1425. },
  1426. pointermove: function pointermove(event) {
  1427. var pointers = this.pointers,
  1428. action = this.action;
  1429. if (!this.viewed || !action) {
  1430. return;
  1431. }
  1432. event.preventDefault();
  1433. if (event.changedTouches) {
  1434. forEach(event.changedTouches, function (touch) {
  1435. assign(pointers[touch.identifier] || {}, getPointer(touch, true));
  1436. });
  1437. } else {
  1438. assign(pointers[event.pointerId || 0] || {}, getPointer(event, true));
  1439. }
  1440. this.change(event);
  1441. },
  1442. pointerup: function pointerup(event) {
  1443. var _this2 = this;
  1444. var options = this.options,
  1445. action = this.action,
  1446. pointers = this.pointers;
  1447. var pointer;
  1448. if (event.changedTouches) {
  1449. forEach(event.changedTouches, function (touch) {
  1450. pointer = pointers[touch.identifier];
  1451. delete pointers[touch.identifier];
  1452. });
  1453. } else {
  1454. pointer = pointers[event.pointerId || 0];
  1455. delete pointers[event.pointerId || 0];
  1456. }
  1457. if (!action) {
  1458. return;
  1459. }
  1460. event.preventDefault();
  1461. if (options.transition && (action === ACTION_MOVE || action === ACTION_ZOOM)) {
  1462. addClass(this.image, CLASS_TRANSITION);
  1463. }
  1464. this.action = false; // Emulate click and double click in touch devices to support backdrop and image zooming (#210).
  1465. if (IS_TOUCH_DEVICE && action !== ACTION_ZOOM && pointer && Date.now() - pointer.timeStamp < 500) {
  1466. clearTimeout(this.clickCanvasTimeout);
  1467. clearTimeout(this.doubleClickImageTimeout);
  1468. if (options.toggleOnDblclick && this.viewed && event.target === this.image) {
  1469. if (this.imageClicked) {
  1470. this.imageClicked = false; // This timeout will be cleared later when a native dblclick event is triggering
  1471. this.doubleClickImageTimeout = setTimeout(function () {
  1472. dispatchEvent(_this2.image, EVENT_DBLCLICK);
  1473. }, 50);
  1474. } else {
  1475. this.imageClicked = true; // The default timing of a double click in Windows is 500 ms
  1476. this.doubleClickImageTimeout = setTimeout(function () {
  1477. _this2.imageClicked = false;
  1478. }, 500);
  1479. }
  1480. } else {
  1481. this.imageClicked = false;
  1482. if (options.backdrop && options.backdrop !== 'static' && event.target === this.canvas) {
  1483. // This timeout will be cleared later when a native click event is triggering
  1484. this.clickCanvasTimeout = setTimeout(function () {
  1485. dispatchEvent(_this2.canvas, EVENT_CLICK);
  1486. }, 50);
  1487. }
  1488. }
  1489. }
  1490. },
  1491. resize: function resize() {
  1492. var _this3 = this;
  1493. if (!this.isShown || this.hiding) {
  1494. return;
  1495. }
  1496. if (this.fulled) {
  1497. this.close();
  1498. this.initBody();
  1499. this.open();
  1500. }
  1501. this.initContainer();
  1502. this.initViewer();
  1503. this.renderViewer();
  1504. this.renderList();
  1505. if (this.viewed) {
  1506. this.initImage(function () {
  1507. _this3.renderImage();
  1508. });
  1509. }
  1510. if (this.played) {
  1511. if (this.options.fullscreen && this.fulled && !(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
  1512. this.stop();
  1513. return;
  1514. }
  1515. forEach(this.player.getElementsByTagName('img'), function (image) {
  1516. addListener(image, EVENT_LOAD, _this3.loadImage.bind(_this3), {
  1517. once: true
  1518. });
  1519. dispatchEvent(image, EVENT_LOAD);
  1520. });
  1521. }
  1522. },
  1523. wheel: function wheel(event) {
  1524. var _this4 = this;
  1525. if (!this.viewed) {
  1526. return;
  1527. }
  1528. event.preventDefault(); // Limit wheel speed to prevent zoom too fast
  1529. if (this.wheeling) {
  1530. return;
  1531. }
  1532. this.wheeling = true;
  1533. setTimeout(function () {
  1534. _this4.wheeling = false;
  1535. }, 50);
  1536. var ratio = Number(this.options.zoomRatio) || 0.1;
  1537. var delta = 1;
  1538. if (event.deltaY) {
  1539. delta = event.deltaY > 0 ? 1 : -1;
  1540. } else if (event.wheelDelta) {
  1541. delta = -event.wheelDelta / 120;
  1542. } else if (event.detail) {
  1543. delta = event.detail > 0 ? 1 : -1;
  1544. }
  1545. this.zoom(-delta * ratio, true, event);
  1546. }
  1547. };
  1548. var methods = {
  1549. /** Show the viewer (only available in modal mode)
  1550. * @param {boolean} [immediate=false] - Indicates if show the viewer immediately or not.
  1551. * @returns {Viewer} this
  1552. */
  1553. show: function show() {
  1554. var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1555. var element = this.element,
  1556. options = this.options;
  1557. if (options.inline || this.showing || this.isShown || this.showing) {
  1558. return this;
  1559. }
  1560. if (!this.ready) {
  1561. this.build();
  1562. if (this.ready) {
  1563. this.show(immediate);
  1564. }
  1565. return this;
  1566. }
  1567. if (isFunction(options.show)) {
  1568. addListener(element, EVENT_SHOW, options.show, {
  1569. once: true
  1570. });
  1571. }
  1572. if (dispatchEvent(element, EVENT_SHOW) === false || !this.ready) {
  1573. return this;
  1574. }
  1575. if (this.hiding) {
  1576. this.transitioning.abort();
  1577. }
  1578. this.showing = true;
  1579. this.open();
  1580. var viewer = this.viewer;
  1581. removeClass(viewer, CLASS_HIDE);
  1582. viewer.setAttribute('role', 'dialog');
  1583. viewer.setAttribute('aria-labelledby', this.title.id);
  1584. viewer.setAttribute('aria-modal', true);
  1585. viewer.removeAttribute('aria-hidden');
  1586. if (options.transition && !immediate) {
  1587. var shown = this.shown.bind(this);
  1588. this.transitioning = {
  1589. abort: function abort() {
  1590. removeListener(viewer, EVENT_TRANSITION_END, shown);
  1591. removeClass(viewer, CLASS_IN);
  1592. }
  1593. };
  1594. addClass(viewer, CLASS_TRANSITION); // Force reflow to enable CSS3 transition
  1595. viewer.initialOffsetWidth = viewer.offsetWidth;
  1596. addListener(viewer, EVENT_TRANSITION_END, shown, {
  1597. once: true
  1598. });
  1599. addClass(viewer, CLASS_IN);
  1600. } else {
  1601. addClass(viewer, CLASS_IN);
  1602. this.shown();
  1603. }
  1604. return this;
  1605. },
  1606. /**
  1607. * Hide the viewer (only available in modal mode)
  1608. * @param {boolean} [immediate=false] - Indicates if hide the viewer immediately or not.
  1609. * @returns {Viewer} this
  1610. */
  1611. hide: function hide() {
  1612. var _this = this;
  1613. var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1614. var element = this.element,
  1615. options = this.options;
  1616. if (options.inline || this.hiding || !(this.isShown || this.showing)) {
  1617. return this;
  1618. }
  1619. if (isFunction(options.hide)) {
  1620. addListener(element, EVENT_HIDE, options.hide, {
  1621. once: true
  1622. });
  1623. }
  1624. if (dispatchEvent(element, EVENT_HIDE) === false) {
  1625. return this;
  1626. }
  1627. if (this.showing) {
  1628. this.transitioning.abort();
  1629. }
  1630. this.hiding = true;
  1631. if (this.played) {
  1632. this.stop();
  1633. } else if (this.viewing) {
  1634. this.viewing.abort();
  1635. }
  1636. var viewer = this.viewer,
  1637. image = this.image;
  1638. var hideImmediately = function hideImmediately() {
  1639. removeClass(viewer, CLASS_IN);
  1640. _this.hidden();
  1641. };
  1642. if (options.transition && !immediate) {
  1643. var onViewerTransitionEnd = function onViewerTransitionEnd(event) {
  1644. // Ignore all propagating `transitionend` events (#275).
  1645. if (event && event.target === viewer) {
  1646. removeListener(viewer, EVENT_TRANSITION_END, onViewerTransitionEnd);
  1647. _this.hidden();
  1648. }
  1649. };
  1650. var onImageTransitionEnd = function onImageTransitionEnd() {
  1651. // In case of show the viewer by `viewer.show(true)` previously (#407).
  1652. if (hasClass(viewer, CLASS_TRANSITION)) {
  1653. addListener(viewer, EVENT_TRANSITION_END, onViewerTransitionEnd);
  1654. removeClass(viewer, CLASS_IN);
  1655. } else {
  1656. hideImmediately();
  1657. }
  1658. };
  1659. this.transitioning = {
  1660. abort: function abort() {
  1661. if (_this.viewed && hasClass(image, CLASS_TRANSITION)) {
  1662. removeListener(image, EVENT_TRANSITION_END, onImageTransitionEnd);
  1663. } else if (hasClass(viewer, CLASS_TRANSITION)) {
  1664. removeListener(viewer, EVENT_TRANSITION_END, onViewerTransitionEnd);
  1665. }
  1666. }
  1667. }; // In case of hiding the viewer when holding on the image (#255),
  1668. // note that the `CLASS_TRANSITION` class will be removed on pointer down.
  1669. if (this.viewed && hasClass(image, CLASS_TRANSITION)) {
  1670. addListener(image, EVENT_TRANSITION_END, onImageTransitionEnd, {
  1671. once: true
  1672. });
  1673. this.zoomTo(0, false, null, true);
  1674. } else {
  1675. onImageTransitionEnd();
  1676. }
  1677. } else {
  1678. hideImmediately();
  1679. }
  1680. return this;
  1681. },
  1682. /**
  1683. * View one of the images with image's index
  1684. * @param {number} index - The index of the image to view.
  1685. * @returns {Viewer} this
  1686. */
  1687. view: function view() {
  1688. var _this2 = this;
  1689. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.initialViewIndex;
  1690. index = Number(index) || 0;
  1691. if (this.hiding || this.played || index < 0 || index >= this.length || this.viewed && index === this.index) {
  1692. return this;
  1693. }
  1694. if (!this.isShown) {
  1695. this.index = index;
  1696. return this.show();
  1697. }
  1698. if (this.viewing) {
  1699. this.viewing.abort();
  1700. }
  1701. var element = this.element,
  1702. options = this.options,
  1703. title = this.title,
  1704. canvas = this.canvas;
  1705. var item = this.items[index];
  1706. var img = item.querySelector('img');
  1707. var url = getData(img, 'originalUrl');
  1708. var alt = img.getAttribute('alt');
  1709. var image = document.createElement('img');
  1710. forEach(options.inheritedAttributes, function (name) {
  1711. var value = img.getAttribute(name);
  1712. if (value !== null) {
  1713. image.setAttribute(name, value);
  1714. }
  1715. });
  1716. image.src = url;
  1717. image.alt = alt;
  1718. if (isFunction(options.view)) {
  1719. addListener(element, EVENT_VIEW, options.view, {
  1720. once: true
  1721. });
  1722. }
  1723. if (dispatchEvent(element, EVENT_VIEW, {
  1724. originalImage: this.images[index],
  1725. index: index,
  1726. image: image
  1727. }) === false || !this.isShown || this.hiding || this.played) {
  1728. return this;
  1729. }
  1730. var activeItem = this.items[this.index];
  1731. if (activeItem) {
  1732. removeClass(activeItem, CLASS_ACTIVE);
  1733. activeItem.removeAttribute('aria-selected');
  1734. }
  1735. addClass(item, CLASS_ACTIVE);
  1736. item.setAttribute('aria-selected', true);
  1737. if (options.focus) {
  1738. item.focus();
  1739. }
  1740. this.image = image;
  1741. this.viewed = false;
  1742. this.index = index;
  1743. this.imageData = {};
  1744. addClass(image, CLASS_INVISIBLE);
  1745. if (options.loading) {
  1746. addClass(canvas, CLASS_LOADING);
  1747. }
  1748. canvas.innerHTML = '';
  1749. canvas.appendChild(image); // Center current item
  1750. this.renderList(); // Clear title
  1751. title.innerHTML = ''; // Generate title after viewed
  1752. var onViewed = function onViewed() {
  1753. var imageData = _this2.imageData;
  1754. var render = Array.isArray(options.title) ? options.title[1] : options.title;
  1755. title.innerHTML = escapeHTMLEntities(isFunction(render) ? render.call(_this2, image, imageData) : "".concat(alt, " (").concat(imageData.naturalWidth, " \xD7 ").concat(imageData.naturalHeight, ")"));
  1756. };
  1757. var onLoad;
  1758. var onError;
  1759. addListener(element, EVENT_VIEWED, onViewed, {
  1760. once: true
  1761. });
  1762. this.viewing = {
  1763. abort: function abort() {
  1764. removeListener(element, EVENT_VIEWED, onViewed);
  1765. if (image.complete) {
  1766. if (_this2.imageRendering) {
  1767. _this2.imageRendering.abort();
  1768. } else if (_this2.imageInitializing) {
  1769. _this2.imageInitializing.abort();
  1770. }
  1771. } else {
  1772. // Cancel download to save bandwidth.
  1773. image.src = '';
  1774. removeListener(image, EVENT_LOAD, onLoad);
  1775. if (_this2.timeout) {
  1776. clearTimeout(_this2.timeout);
  1777. }
  1778. }
  1779. }
  1780. };
  1781. if (image.complete) {
  1782. this.load();
  1783. } else {
  1784. addListener(image, EVENT_LOAD, onLoad = function onLoad() {
  1785. removeListener(image, EVENT_ERROR, onError);
  1786. _this2.load();
  1787. }, {
  1788. once: true
  1789. });
  1790. addListener(image, EVENT_ERROR, onError = function onError() {
  1791. removeListener(image, EVENT_LOAD, onLoad);
  1792. if (_this2.timeout) {
  1793. clearTimeout(_this2.timeout);
  1794. _this2.timeout = false;
  1795. }
  1796. removeClass(image, CLASS_INVISIBLE);
  1797. if (options.loading) {
  1798. removeClass(_this2.canvas, CLASS_LOADING);
  1799. }
  1800. }, {
  1801. once: true
  1802. });
  1803. if (this.timeout) {
  1804. clearTimeout(this.timeout);
  1805. } // Make the image visible if it fails to load within 1s
  1806. this.timeout = setTimeout(function () {
  1807. removeClass(image, CLASS_INVISIBLE);
  1808. _this2.timeout = false;
  1809. }, 1000);
  1810. }
  1811. return this;
  1812. },
  1813. /**
  1814. * View the previous image
  1815. * @param {boolean} [loop=false] - Indicate if view the last one
  1816. * when it is the first one at present.
  1817. * @returns {Viewer} this
  1818. */
  1819. prev: function prev() {
  1820. var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1821. var index = this.index - 1;
  1822. if (index < 0) {
  1823. index = loop ? this.length - 1 : 0;
  1824. }
  1825. this.view(index);
  1826. return this;
  1827. },
  1828. /**
  1829. * View the next image
  1830. * @param {boolean} [loop=false] - Indicate if view the first one
  1831. * when it is the last one at present.
  1832. * @returns {Viewer} this
  1833. */
  1834. next: function next() {
  1835. var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1836. var maxIndex = this.length - 1;
  1837. var index = this.index + 1;
  1838. if (index > maxIndex) {
  1839. index = loop ? 0 : maxIndex;
  1840. }
  1841. this.view(index);
  1842. return this;
  1843. },
  1844. /**
  1845. * Move the image with relative offsets.
  1846. * @param {number} x - The moving distance in the horizontal direction.
  1847. * @param {number} [y=x] The moving distance in the vertical direction.
  1848. * @returns {Viewer} this
  1849. */
  1850. move: function move(x) {
  1851. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
  1852. var imageData = this.imageData;
  1853. this.moveTo(isUndefined(x) ? x : imageData.x + Number(x), isUndefined(y) ? y : imageData.y + Number(y));
  1854. return this;
  1855. },
  1856. /**
  1857. * Move the image to an absolute point.
  1858. * @param {number} x - The new position in the horizontal direction.
  1859. * @param {number} [y=x] - The new position in the vertical direction.
  1860. * @param {Event} [_originalEvent=null] - The original event if any.
  1861. * @returns {Viewer} this
  1862. */
  1863. moveTo: function moveTo(x) {
  1864. var _this3 = this;
  1865. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
  1866. var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1867. var element = this.element,
  1868. options = this.options,
  1869. imageData = this.imageData;
  1870. x = Number(x);
  1871. y = Number(y);
  1872. if (this.viewed && !this.played && options.movable) {
  1873. var oldX = imageData.x;
  1874. var oldY = imageData.y;
  1875. var changed = false;
  1876. if (isNumber(x)) {
  1877. changed = true;
  1878. } else {
  1879. x = oldX;
  1880. }
  1881. if (isNumber(y)) {
  1882. changed = true;
  1883. } else {
  1884. y = oldY;
  1885. }
  1886. if (changed) {
  1887. if (isFunction(options.move)) {
  1888. addListener(element, EVENT_MOVE, options.move, {
  1889. once: true
  1890. });
  1891. }
  1892. if (dispatchEvent(element, EVENT_MOVE, {
  1893. x: x,
  1894. y: y,
  1895. oldX: oldX,
  1896. oldY: oldY,
  1897. originalEvent: _originalEvent
  1898. }) === false) {
  1899. return this;
  1900. }
  1901. imageData.x = x;
  1902. imageData.y = y;
  1903. imageData.left = x;
  1904. imageData.top = y;
  1905. this.moving = true;
  1906. this.renderImage(function () {
  1907. _this3.moving = false;
  1908. if (isFunction(options.moved)) {
  1909. addListener(element, EVENT_MOVED, options.moved, {
  1910. once: true
  1911. });
  1912. }
  1913. dispatchEvent(element, EVENT_MOVED, {
  1914. x: x,
  1915. y: y,
  1916. oldX: oldX,
  1917. oldY: oldY,
  1918. originalEvent: _originalEvent
  1919. }, {
  1920. cancelable: false
  1921. });
  1922. });
  1923. }
  1924. }
  1925. return this;
  1926. },
  1927. /**
  1928. * Rotate the image with a relative degree.
  1929. * @param {number} degree - The rotate degree.
  1930. * @returns {Viewer} this
  1931. */
  1932. rotate: function rotate(degree) {
  1933. this.rotateTo((this.imageData.rotate || 0) + Number(degree));
  1934. return this;
  1935. },
  1936. /**
  1937. * Rotate the image to an absolute degree.
  1938. * @param {number} degree - The rotate degree.
  1939. * @returns {Viewer} this
  1940. */
  1941. rotateTo: function rotateTo(degree) {
  1942. var _this4 = this;
  1943. var element = this.element,
  1944. options = this.options,
  1945. imageData = this.imageData;
  1946. degree = Number(degree);
  1947. if (isNumber(degree) && this.viewed && !this.played && options.rotatable) {
  1948. var oldDegree = imageData.rotate;
  1949. if (isFunction(options.rotate)) {
  1950. addListener(element, EVENT_ROTATE, options.rotate, {
  1951. once: true
  1952. });
  1953. }
  1954. if (dispatchEvent(element, EVENT_ROTATE, {
  1955. degree: degree,
  1956. oldDegree: oldDegree
  1957. }) === false) {
  1958. return this;
  1959. }
  1960. imageData.rotate = degree;
  1961. this.rotating = true;
  1962. this.renderImage(function () {
  1963. _this4.rotating = false;
  1964. if (isFunction(options.rotated)) {
  1965. addListener(element, EVENT_ROTATED, options.rotated, {
  1966. once: true
  1967. });
  1968. }
  1969. dispatchEvent(element, EVENT_ROTATED, {
  1970. degree: degree,
  1971. oldDegree: oldDegree
  1972. }, {
  1973. cancelable: false
  1974. });
  1975. });
  1976. }
  1977. return this;
  1978. },
  1979. /**
  1980. * Scale the image on the x-axis.
  1981. * @param {number} scaleX - The scale ratio on the x-axis.
  1982. * @returns {Viewer} this
  1983. */
  1984. scaleX: function scaleX(_scaleX) {
  1985. this.scale(_scaleX, this.imageData.scaleY);
  1986. return this;
  1987. },
  1988. /**
  1989. * Scale the image on the y-axis.
  1990. * @param {number} scaleY - The scale ratio on the y-axis.
  1991. * @returns {Viewer} this
  1992. */
  1993. scaleY: function scaleY(_scaleY) {
  1994. this.scale(this.imageData.scaleX, _scaleY);
  1995. return this;
  1996. },
  1997. /**
  1998. * Scale the image.
  1999. * @param {number} scaleX - The scale ratio on the x-axis.
  2000. * @param {number} [scaleY=scaleX] - The scale ratio on the y-axis.
  2001. * @returns {Viewer} this
  2002. */
  2003. scale: function scale(scaleX) {
  2004. var _this5 = this;
  2005. var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX;
  2006. var element = this.element,
  2007. options = this.options,
  2008. imageData = this.imageData;
  2009. scaleX = Number(scaleX);
  2010. scaleY = Number(scaleY);
  2011. if (this.viewed && !this.played && options.scalable) {
  2012. var oldScaleX = imageData.scaleX;
  2013. var oldScaleY = imageData.scaleY;
  2014. var changed = false;
  2015. if (isNumber(scaleX)) {
  2016. changed = true;
  2017. } else {
  2018. scaleX = oldScaleX;
  2019. }
  2020. if (isNumber(scaleY)) {
  2021. changed = true;
  2022. } else {
  2023. scaleY = oldScaleY;
  2024. }
  2025. if (changed) {
  2026. if (isFunction(options.scale)) {
  2027. addListener(element, EVENT_SCALE, options.scale, {
  2028. once: true
  2029. });
  2030. }
  2031. if (dispatchEvent(element, EVENT_SCALE, {
  2032. scaleX: scaleX,
  2033. scaleY: scaleY,
  2034. oldScaleX: oldScaleX,
  2035. oldScaleY: oldScaleY
  2036. }) === false) {
  2037. return this;
  2038. }
  2039. imageData.scaleX = scaleX;
  2040. imageData.scaleY = scaleY;
  2041. this.scaling = true;
  2042. this.renderImage(function () {
  2043. _this5.scaling = false;
  2044. if (isFunction(options.scaled)) {
  2045. addListener(element, EVENT_SCALED, options.scaled, {
  2046. once: true
  2047. });
  2048. }
  2049. dispatchEvent(element, EVENT_SCALED, {
  2050. scaleX: scaleX,
  2051. scaleY: scaleY,
  2052. oldScaleX: oldScaleX,
  2053. oldScaleY: oldScaleY
  2054. }, {
  2055. cancelable: false
  2056. });
  2057. });
  2058. }
  2059. }
  2060. return this;
  2061. },
  2062. /**
  2063. * Zoom the image with a relative ratio.
  2064. * @param {number} ratio - The target ratio.
  2065. * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
  2066. * @param {Event} [_originalEvent=null] - The original event if any.
  2067. * @returns {Viewer} this
  2068. */
  2069. zoom: function zoom(ratio) {
  2070. var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2071. var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  2072. var imageData = this.imageData;
  2073. ratio = Number(ratio);
  2074. if (ratio < 0) {
  2075. ratio = 1 / (1 - ratio);
  2076. } else {
  2077. ratio = 1 + ratio;
  2078. }
  2079. this.zoomTo(imageData.width * ratio / imageData.naturalWidth, hasTooltip, _originalEvent);
  2080. return this;
  2081. },
  2082. /**
  2083. * Zoom the image to an absolute ratio.
  2084. * @param {number} ratio - The target ratio.
  2085. * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
  2086. * @param {Event} [_originalEvent=null] - The original event if any.
  2087. * @param {Event} [_zoomable=false] - Indicates if the current zoom is available or not.
  2088. * @returns {Viewer} this
  2089. */
  2090. zoomTo: function zoomTo(ratio) {
  2091. var _this6 = this;
  2092. var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2093. var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  2094. var _zoomable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  2095. var element = this.element,
  2096. options = this.options,
  2097. pointers = this.pointers,
  2098. imageData = this.imageData;
  2099. var x = imageData.x,
  2100. y = imageData.y,
  2101. width = imageData.width,
  2102. height = imageData.height,
  2103. naturalWidth = imageData.naturalWidth,
  2104. naturalHeight = imageData.naturalHeight;
  2105. ratio = Math.max(0, ratio);
  2106. if (isNumber(ratio) && this.viewed && !this.played && (_zoomable || options.zoomable)) {
  2107. if (!_zoomable) {
  2108. var minZoomRatio = Math.max(0.01, options.minZoomRatio);
  2109. var maxZoomRatio = Math.min(100, options.maxZoomRatio);
  2110. ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio);
  2111. }
  2112. if (_originalEvent && options.zoomRatio >= 0.055 && ratio > 0.95 && ratio < 1.05) {
  2113. ratio = 1;
  2114. }
  2115. var newWidth = naturalWidth * ratio;
  2116. var newHeight = naturalHeight * ratio;
  2117. var offsetWidth = newWidth - width;
  2118. var offsetHeight = newHeight - height;
  2119. var oldRatio = imageData.ratio;
  2120. if (isFunction(options.zoom)) {
  2121. addListener(element, EVENT_ZOOM, options.zoom, {
  2122. once: true
  2123. });
  2124. }
  2125. if (dispatchEvent(element, EVENT_ZOOM, {
  2126. ratio: ratio,
  2127. oldRatio: oldRatio,
  2128. originalEvent: _originalEvent
  2129. }) === false) {
  2130. return this;
  2131. }
  2132. this.zooming = true;
  2133. if (_originalEvent) {
  2134. var offset = getOffset(this.viewer);
  2135. var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : {
  2136. pageX: _originalEvent.pageX,
  2137. pageY: _originalEvent.pageY
  2138. }; // Zoom from the triggering point of the event
  2139. imageData.x -= offsetWidth * ((center.pageX - offset.left - x) / width);
  2140. imageData.y -= offsetHeight * ((center.pageY - offset.top - y) / height);
  2141. } else {
  2142. // Zoom from the center of the image
  2143. imageData.x -= offsetWidth / 2;
  2144. imageData.y -= offsetHeight / 2;
  2145. }
  2146. imageData.left = imageData.x;
  2147. imageData.top = imageData.y;
  2148. imageData.width = newWidth;
  2149. imageData.height = newHeight;
  2150. imageData.oldRatio = oldRatio;
  2151. imageData.ratio = ratio;
  2152. this.renderImage(function () {
  2153. _this6.zooming = false;
  2154. if (isFunction(options.zoomed)) {
  2155. addListener(element, EVENT_ZOOMED, options.zoomed, {
  2156. once: true
  2157. });
  2158. }
  2159. dispatchEvent(element, EVENT_ZOOMED, {
  2160. ratio: ratio,
  2161. oldRatio: oldRatio,
  2162. originalEvent: _originalEvent
  2163. }, {
  2164. cancelable: false
  2165. });
  2166. });
  2167. if (hasTooltip) {
  2168. this.tooltip();
  2169. }
  2170. }
  2171. return this;
  2172. },
  2173. /**
  2174. * Play the images
  2175. * @param {boolean|FullscreenOptions} [fullscreen=false] - Indicate if request fullscreen or not.
  2176. * @returns {Viewer} this
  2177. */
  2178. play: function play() {
  2179. var _this7 = this;
  2180. var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  2181. if (!this.isShown || this.played) {
  2182. return this;
  2183. }
  2184. var element = this.element,
  2185. options = this.options;
  2186. if (isFunction(options.play)) {
  2187. addListener(element, EVENT_PLAY, options.play, {
  2188. once: true
  2189. });
  2190. }
  2191. if (dispatchEvent(element, EVENT_PLAY) === false) {
  2192. return this;
  2193. }
  2194. var player = this.player;
  2195. var onLoad = this.loadImage.bind(this);
  2196. var list = [];
  2197. var total = 0;
  2198. var index = 0;
  2199. this.played = true;
  2200. this.onLoadWhenPlay = onLoad;
  2201. if (fullscreen) {
  2202. this.requestFullscreen(fullscreen);
  2203. }
  2204. addClass(player, CLASS_SHOW);
  2205. forEach(this.items, function (item, i) {
  2206. var img = item.querySelector('img');
  2207. var image = document.createElement('img');
  2208. image.src = getData(img, 'originalUrl');
  2209. image.alt = img.getAttribute('alt');
  2210. image.referrerPolicy = img.referrerPolicy;
  2211. total += 1;
  2212. addClass(image, CLASS_FADE);
  2213. toggleClass(image, CLASS_TRANSITION, options.transition);
  2214. if (hasClass(item, CLASS_ACTIVE)) {
  2215. addClass(image, CLASS_IN);
  2216. index = i;
  2217. }
  2218. list.push(image);
  2219. addListener(image, EVENT_LOAD, onLoad, {
  2220. once: true
  2221. });
  2222. player.appendChild(image);
  2223. });
  2224. if (isNumber(options.interval) && options.interval > 0) {
  2225. var play = function play() {
  2226. _this7.playing = setTimeout(function () {
  2227. removeClass(list[index], CLASS_IN);
  2228. index += 1;
  2229. index = index < total ? index : 0;
  2230. addClass(list[index], CLASS_IN);
  2231. play();
  2232. }, options.interval);
  2233. };
  2234. if (total > 1) {
  2235. play();
  2236. }
  2237. }
  2238. return this;
  2239. },
  2240. // Stop play
  2241. stop: function stop() {
  2242. var _this8 = this;
  2243. if (!this.played) {
  2244. return this;
  2245. }
  2246. var element = this.element,
  2247. options = this.options;
  2248. if (isFunction(options.stop)) {
  2249. addListener(element, EVENT_STOP, options.stop, {
  2250. once: true
  2251. });
  2252. }
  2253. if (dispatchEvent(element, EVENT_STOP) === false) {
  2254. return this;
  2255. }
  2256. var player = this.player;
  2257. this.played = false;
  2258. clearTimeout(this.playing);
  2259. forEach(player.getElementsByTagName('img'), function (image) {
  2260. removeListener(image, EVENT_LOAD, _this8.onLoadWhenPlay);
  2261. });
  2262. removeClass(player, CLASS_SHOW);
  2263. player.innerHTML = '';
  2264. this.exitFullscreen();
  2265. return this;
  2266. },
  2267. // Enter modal mode (only available in inline mode)
  2268. full: function full() {
  2269. var _this9 = this;
  2270. var options = this.options,
  2271. viewer = this.viewer,
  2272. image = this.image,
  2273. list = this.list;
  2274. if (!this.isShown || this.played || this.fulled || !options.inline) {
  2275. return this;
  2276. }
  2277. this.fulled = true;
  2278. this.open();
  2279. addClass(this.button, CLASS_FULLSCREEN_EXIT);
  2280. if (options.transition) {
  2281. removeClass(list, CLASS_TRANSITION);
  2282. if (this.viewed) {
  2283. removeClass(image, CLASS_TRANSITION);
  2284. }
  2285. }
  2286. addClass(viewer, CLASS_FIXED);
  2287. viewer.setAttribute('role', 'dialog');
  2288. viewer.setAttribute('aria-labelledby', this.title.id);
  2289. viewer.setAttribute('aria-modal', true);
  2290. viewer.removeAttribute('style');
  2291. setStyle(viewer, {
  2292. zIndex: options.zIndex
  2293. });
  2294. if (options.focus) {
  2295. this.enforceFocus();
  2296. }
  2297. this.initContainer();
  2298. this.viewerData = assign({}, this.containerData);
  2299. this.renderList();
  2300. if (this.viewed) {
  2301. this.initImage(function () {
  2302. _this9.renderImage(function () {
  2303. if (options.transition) {
  2304. setTimeout(function () {
  2305. addClass(image, CLASS_TRANSITION);
  2306. addClass(list, CLASS_TRANSITION);
  2307. }, 0);
  2308. }
  2309. });
  2310. });
  2311. }
  2312. return this;
  2313. },
  2314. // Exit modal mode (only available in inline mode)
  2315. exit: function exit() {
  2316. var _this10 = this;
  2317. var options = this.options,
  2318. viewer = this.viewer,
  2319. image = this.image,
  2320. list = this.list;
  2321. if (!this.isShown || this.played || !this.fulled || !options.inline) {
  2322. return this;
  2323. }
  2324. this.fulled = false;
  2325. this.close();
  2326. removeClass(this.button, CLASS_FULLSCREEN_EXIT);
  2327. if (options.transition) {
  2328. removeClass(list, CLASS_TRANSITION);
  2329. if (this.viewed) {
  2330. removeClass(image, CLASS_TRANSITION);
  2331. }
  2332. }
  2333. if (options.focus) {
  2334. this.clearEnforceFocus();
  2335. }
  2336. viewer.removeAttribute('role');
  2337. viewer.removeAttribute('aria-labelledby');
  2338. viewer.removeAttribute('aria-modal');
  2339. removeClass(viewer, CLASS_FIXED);
  2340. setStyle(viewer, {
  2341. zIndex: options.zIndexInline
  2342. });
  2343. this.viewerData = assign({}, this.parentData);
  2344. this.renderViewer();
  2345. this.renderList();
  2346. if (this.viewed) {
  2347. this.initImage(function () {
  2348. _this10.renderImage(function () {
  2349. if (options.transition) {
  2350. setTimeout(function () {
  2351. addClass(image, CLASS_TRANSITION);
  2352. addClass(list, CLASS_TRANSITION);
  2353. }, 0);
  2354. }
  2355. });
  2356. });
  2357. }
  2358. return this;
  2359. },
  2360. // Show the current ratio of the image with percentage
  2361. tooltip: function tooltip() {
  2362. var _this11 = this;
  2363. var options = this.options,
  2364. tooltipBox = this.tooltipBox,
  2365. imageData = this.imageData;
  2366. if (!this.viewed || this.played || !options.tooltip) {
  2367. return this;
  2368. }
  2369. tooltipBox.textContent = "".concat(Math.round(imageData.ratio * 100), "%");
  2370. if (!this.tooltipping) {
  2371. if (options.transition) {
  2372. if (this.fading) {
  2373. dispatchEvent(tooltipBox, EVENT_TRANSITION_END);
  2374. }
  2375. addClass(tooltipBox, CLASS_SHOW);
  2376. addClass(tooltipBox, CLASS_FADE);
  2377. addClass(tooltipBox, CLASS_TRANSITION);
  2378. tooltipBox.removeAttribute('aria-hidden'); // Force reflow to enable CSS3 transition
  2379. tooltipBox.initialOffsetWidth = tooltipBox.offsetWidth;
  2380. addClass(tooltipBox, CLASS_IN);
  2381. } else {
  2382. addClass(tooltipBox, CLASS_SHOW);
  2383. tooltipBox.removeAttribute('aria-hidden');
  2384. }
  2385. } else {
  2386. clearTimeout(this.tooltipping);
  2387. }
  2388. this.tooltipping = setTimeout(function () {
  2389. if (options.transition) {
  2390. addListener(tooltipBox, EVENT_TRANSITION_END, function () {
  2391. removeClass(tooltipBox, CLASS_SHOW);
  2392. removeClass(tooltipBox, CLASS_FADE);
  2393. removeClass(tooltipBox, CLASS_TRANSITION);
  2394. tooltipBox.setAttribute('aria-hidden', true);
  2395. _this11.fading = false;
  2396. }, {
  2397. once: true
  2398. });
  2399. removeClass(tooltipBox, CLASS_IN);
  2400. _this11.fading = true;
  2401. } else {
  2402. removeClass(tooltipBox, CLASS_SHOW);
  2403. tooltipBox.setAttribute('aria-hidden', true);
  2404. }
  2405. _this11.tooltipping = false;
  2406. }, 1000);
  2407. return this;
  2408. },
  2409. /**
  2410. * Toggle the image size between its current size and natural size
  2411. * @param {Event} [_originalEvent=null] - The original event if any.
  2412. * @returns {Viewer} this
  2413. */
  2414. toggle: function toggle() {
  2415. var _originalEvent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  2416. if (this.imageData.ratio === 1) {
  2417. this.zoomTo(this.imageData.oldRatio, true, _originalEvent);
  2418. } else {
  2419. this.zoomTo(1, true, _originalEvent);
  2420. }
  2421. return this;
  2422. },
  2423. // Reset the image to its initial state
  2424. reset: function reset() {
  2425. if (this.viewed && !this.played) {
  2426. this.imageData = assign({}, this.initialImageData);
  2427. this.renderImage();
  2428. }
  2429. return this;
  2430. },
  2431. // Update viewer when images changed
  2432. update: function update() {
  2433. var _this12 = this;
  2434. var element = this.element,
  2435. options = this.options,
  2436. isImg = this.isImg; // Destroy viewer if the target image was deleted
  2437. if (isImg && !element.parentNode) {
  2438. return this.destroy();
  2439. }
  2440. var images = [];
  2441. forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
  2442. if (isFunction(options.filter)) {
  2443. if (options.filter.call(_this12, image)) {
  2444. images.push(image);
  2445. }
  2446. } else if (_this12.getImageURL(image)) {
  2447. images.push(image);
  2448. }
  2449. });
  2450. if (!images.length) {
  2451. return this;
  2452. }
  2453. this.images = images;
  2454. this.length = images.length;
  2455. if (this.ready) {
  2456. var changedIndexes = [];
  2457. forEach(this.items, function (item, i) {
  2458. var img = item.querySelector('img');
  2459. var image = images[i];
  2460. if (image && img) {
  2461. if (image.src !== img.src // Title changed (#408)
  2462. || image.alt !== img.alt) {
  2463. changedIndexes.push(i);
  2464. }
  2465. } else {
  2466. changedIndexes.push(i);
  2467. }
  2468. });
  2469. setStyle(this.list, {
  2470. width: 'auto'
  2471. });
  2472. this.initList();
  2473. if (this.isShown) {
  2474. if (this.length) {
  2475. if (this.viewed) {
  2476. var changedIndex = changedIndexes.indexOf(this.index);
  2477. if (changedIndex >= 0) {
  2478. this.viewed = false;
  2479. this.view(Math.max(Math.min(this.index - changedIndex, this.length - 1), 0));
  2480. } else {
  2481. var activeItem = this.items[this.index]; // Reactivate the current viewing item after reset the list.
  2482. addClass(activeItem, CLASS_ACTIVE);
  2483. activeItem.setAttribute('aria-selected', true);
  2484. }
  2485. }
  2486. } else {
  2487. this.image = null;
  2488. this.viewed = false;
  2489. this.index = 0;
  2490. this.imageData = {};
  2491. this.canvas.innerHTML = '';
  2492. this.title.innerHTML = '';
  2493. }
  2494. }
  2495. } else {
  2496. this.build();
  2497. }
  2498. return this;
  2499. },
  2500. // Destroy the viewer
  2501. destroy: function destroy() {
  2502. var element = this.element,
  2503. options = this.options;
  2504. if (!element[NAMESPACE]) {
  2505. return this;
  2506. }
  2507. this.destroyed = true;
  2508. if (this.ready) {
  2509. if (this.played) {
  2510. this.stop();
  2511. }
  2512. if (options.inline) {
  2513. if (this.fulled) {
  2514. this.exit();
  2515. }
  2516. this.unbind();
  2517. } else if (this.isShown) {
  2518. if (this.viewing) {
  2519. if (this.imageRendering) {
  2520. this.imageRendering.abort();
  2521. } else if (this.imageInitializing) {
  2522. this.imageInitializing.abort();
  2523. }
  2524. }
  2525. if (this.hiding) {
  2526. this.transitioning.abort();
  2527. }
  2528. this.hidden();
  2529. } else if (this.showing) {
  2530. this.transitioning.abort();
  2531. this.hidden();
  2532. }
  2533. this.ready = false;
  2534. this.viewer.parentNode.removeChild(this.viewer);
  2535. } else if (options.inline) {
  2536. if (this.delaying) {
  2537. this.delaying.abort();
  2538. } else if (this.initializing) {
  2539. this.initializing.abort();
  2540. }
  2541. }
  2542. if (!options.inline) {
  2543. removeListener(element, EVENT_CLICK, this.onStart);
  2544. }
  2545. element[NAMESPACE] = undefined;
  2546. return this;
  2547. }
  2548. };
  2549. var others = {
  2550. getImageURL: function getImageURL(image) {
  2551. var url = this.options.url;
  2552. if (isString(url)) {
  2553. url = image.getAttribute(url);
  2554. } else if (isFunction(url)) {
  2555. url = url.call(this, image);
  2556. } else {
  2557. url = '';
  2558. }
  2559. return url;
  2560. },
  2561. enforceFocus: function enforceFocus() {
  2562. var _this = this;
  2563. this.clearEnforceFocus();
  2564. addListener(document, EVENT_FOCUSIN, this.onFocusin = function (event) {
  2565. var viewer = _this.viewer;
  2566. var target = event.target;
  2567. if (target !== document && target !== viewer && !viewer.contains(target) // Avoid conflicts with other modals (#474)
  2568. && (target.getAttribute('tabindex') === null || target.getAttribute('aria-modal') !== 'true')) {
  2569. viewer.focus();
  2570. }
  2571. });
  2572. },
  2573. clearEnforceFocus: function clearEnforceFocus() {
  2574. if (this.onFocusin) {
  2575. removeListener(document, EVENT_FOCUSIN, this.onFocusin);
  2576. this.onFocusin = null;
  2577. }
  2578. },
  2579. open: function open() {
  2580. var body = this.body;
  2581. addClass(body, CLASS_OPEN);
  2582. body.style.paddingRight = "".concat(this.scrollbarWidth + (parseFloat(this.initialBodyComputedPaddingRight) || 0), "px");
  2583. },
  2584. close: function close() {
  2585. var body = this.body;
  2586. removeClass(body, CLASS_OPEN);
  2587. body.style.paddingRight = this.initialBodyPaddingRight;
  2588. },
  2589. shown: function shown() {
  2590. var element = this.element,
  2591. options = this.options,
  2592. viewer = this.viewer;
  2593. this.fulled = true;
  2594. this.isShown = true;
  2595. this.render();
  2596. this.bind();
  2597. this.showing = false;
  2598. if (options.focus) {
  2599. viewer.focus();
  2600. this.enforceFocus();
  2601. }
  2602. if (isFunction(options.shown)) {
  2603. addListener(element, EVENT_SHOWN, options.shown, {
  2604. once: true
  2605. });
  2606. }
  2607. if (dispatchEvent(element, EVENT_SHOWN) === false) {
  2608. return;
  2609. }
  2610. if (this.ready && this.isShown && !this.hiding) {
  2611. this.view(this.index);
  2612. }
  2613. },
  2614. hidden: function hidden() {
  2615. var element = this.element,
  2616. options = this.options,
  2617. viewer = this.viewer;
  2618. if (options.fucus) {
  2619. this.clearEnforceFocus();
  2620. }
  2621. this.fulled = false;
  2622. this.viewed = false;
  2623. this.isShown = false;
  2624. this.close();
  2625. this.unbind();
  2626. addClass(viewer, CLASS_HIDE);
  2627. viewer.removeAttribute('role');
  2628. viewer.removeAttribute('aria-labelledby');
  2629. viewer.removeAttribute('aria-modal');
  2630. viewer.setAttribute('aria-hidden', true);
  2631. this.resetList();
  2632. this.resetImage();
  2633. this.hiding = false;
  2634. if (!this.destroyed) {
  2635. if (isFunction(options.hidden)) {
  2636. addListener(element, EVENT_HIDDEN, options.hidden, {
  2637. once: true
  2638. });
  2639. }
  2640. dispatchEvent(element, EVENT_HIDDEN, null, {
  2641. cancelable: false
  2642. });
  2643. }
  2644. },
  2645. requestFullscreen: function requestFullscreen(options) {
  2646. var document = this.element.ownerDocument;
  2647. if (this.fulled && !(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
  2648. var documentElement = document.documentElement; // Element.requestFullscreen()
  2649. if (documentElement.requestFullscreen) {
  2650. // Avoid TypeError when convert `options` to dictionary
  2651. if (isPlainObject(options)) {
  2652. documentElement.requestFullscreen(options);
  2653. } else {
  2654. documentElement.requestFullscreen();
  2655. }
  2656. } else if (documentElement.webkitRequestFullscreen) {
  2657. documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  2658. } else if (documentElement.mozRequestFullScreen) {
  2659. documentElement.mozRequestFullScreen();
  2660. } else if (documentElement.msRequestFullscreen) {
  2661. documentElement.msRequestFullscreen();
  2662. }
  2663. }
  2664. },
  2665. exitFullscreen: function exitFullscreen() {
  2666. var document = this.element.ownerDocument;
  2667. if (this.fulled && (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
  2668. // Document.exitFullscreen()
  2669. if (document.exitFullscreen) {
  2670. document.exitFullscreen();
  2671. } else if (document.webkitExitFullscreen) {
  2672. document.webkitExitFullscreen();
  2673. } else if (document.mozCancelFullScreen) {
  2674. document.mozCancelFullScreen();
  2675. } else if (document.msExitFullscreen) {
  2676. document.msExitFullscreen();
  2677. }
  2678. }
  2679. },
  2680. change: function change(event) {
  2681. var options = this.options,
  2682. pointers = this.pointers;
  2683. var pointer = pointers[Object.keys(pointers)[0]]; // In the case of the `pointers` object is empty (#421)
  2684. if (!pointer) {
  2685. return;
  2686. }
  2687. var offsetX = pointer.endX - pointer.startX;
  2688. var offsetY = pointer.endY - pointer.startY;
  2689. switch (this.action) {
  2690. // Move the current image
  2691. case ACTION_MOVE:
  2692. this.move(offsetX, offsetY, event);
  2693. break;
  2694. // Zoom the current image
  2695. case ACTION_ZOOM:
  2696. this.zoom(getMaxZoomRatio(pointers), false, event);
  2697. break;
  2698. case ACTION_SWITCH:
  2699. {
  2700. this.action = 'switched';
  2701. var absoluteOffsetX = Math.abs(offsetX);
  2702. if (absoluteOffsetX > 1 && absoluteOffsetX > Math.abs(offsetY)) {
  2703. // Empty `pointers` as `touchend` event will not be fired after swiped in iOS browsers.
  2704. this.pointers = {};
  2705. if (offsetX > 1) {
  2706. this.prev(options.loop);
  2707. } else if (offsetX < -1) {
  2708. this.next(options.loop);
  2709. }
  2710. }
  2711. break;
  2712. }
  2713. } // Override
  2714. forEach(pointers, function (p) {
  2715. p.startX = p.endX;
  2716. p.startY = p.endY;
  2717. });
  2718. },
  2719. isSwitchable: function isSwitchable() {
  2720. var imageData = this.imageData,
  2721. viewerData = this.viewerData;
  2722. return this.length > 1 && imageData.x >= 0 && imageData.y >= 0 && imageData.width <= viewerData.width && imageData.height <= viewerData.height;
  2723. }
  2724. };
  2725. var AnotherViewer = WINDOW.Viewer;
  2726. var getUniqueID = function (id) {
  2727. return function () {
  2728. id += 1;
  2729. return id;
  2730. };
  2731. }(-1);
  2732. var Viewer = /*#__PURE__*/function () {
  2733. /**
  2734. * Create a new Viewer.
  2735. * @param {Element} element - The target element for viewing.
  2736. * @param {Object} [options={}] - The configuration options.
  2737. */
  2738. function Viewer(element) {
  2739. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2740. _classCallCheck(this, Viewer);
  2741. if (!element || element.nodeType !== 1) {
  2742. throw new Error('The first argument is required and must be an element.');
  2743. }
  2744. this.element = element;
  2745. this.options = assign({}, DEFAULTS, isPlainObject(options) && options);
  2746. this.action = false;
  2747. this.fading = false;
  2748. this.fulled = false;
  2749. this.hiding = false;
  2750. this.imageClicked = false;
  2751. this.imageData = {};
  2752. this.index = this.options.initialViewIndex;
  2753. this.isImg = false;
  2754. this.isShown = false;
  2755. this.length = 0;
  2756. this.moving = false;
  2757. this.played = false;
  2758. this.playing = false;
  2759. this.pointers = {};
  2760. this.ready = false;
  2761. this.rotating = false;
  2762. this.scaling = false;
  2763. this.showing = false;
  2764. this.timeout = false;
  2765. this.tooltipping = false;
  2766. this.viewed = false;
  2767. this.viewing = false;
  2768. this.wheeling = false;
  2769. this.zooming = false;
  2770. this.id = getUniqueID();
  2771. this.init();
  2772. }
  2773. _createClass(Viewer, [{
  2774. key: "init",
  2775. value: function init() {
  2776. var _this = this;
  2777. var element = this.element,
  2778. options = this.options;
  2779. if (element[NAMESPACE]) {
  2780. return;
  2781. }
  2782. element[NAMESPACE] = this; // The `focus` option requires the `keyboard` option set to `true`.
  2783. if (options.focus && !options.keyboard) {
  2784. options.focus = false;
  2785. }
  2786. var isImg = element.localName === 'img';
  2787. var images = [];
  2788. forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
  2789. if (isFunction(options.filter)) {
  2790. if (options.filter.call(_this, image)) {
  2791. images.push(image);
  2792. }
  2793. } else if (_this.getImageURL(image)) {
  2794. images.push(image);
  2795. }
  2796. });
  2797. this.isImg = isImg;
  2798. this.length = images.length;
  2799. this.images = images;
  2800. this.initBody(); // Override `transition` option if it is not supported
  2801. if (isUndefined(document.createElement(NAMESPACE).style.transition)) {
  2802. options.transition = false;
  2803. }
  2804. if (options.inline) {
  2805. var count = 0;
  2806. var progress = function progress() {
  2807. count += 1;
  2808. if (count === _this.length) {
  2809. var timeout;
  2810. _this.initializing = false;
  2811. _this.delaying = {
  2812. abort: function abort() {
  2813. clearTimeout(timeout);
  2814. }
  2815. }; // build asynchronously to keep `this.viewer` is accessible in `ready` event handler.
  2816. timeout = setTimeout(function () {
  2817. _this.delaying = false;
  2818. _this.build();
  2819. }, 0);
  2820. }
  2821. };
  2822. this.initializing = {
  2823. abort: function abort() {
  2824. forEach(images, function (image) {
  2825. if (!image.complete) {
  2826. removeListener(image, EVENT_LOAD, progress);
  2827. }
  2828. });
  2829. }
  2830. };
  2831. forEach(images, function (image) {
  2832. if (image.complete) {
  2833. progress();
  2834. } else {
  2835. addListener(image, EVENT_LOAD, progress, {
  2836. once: true
  2837. });
  2838. }
  2839. });
  2840. } else {
  2841. addListener(element, EVENT_CLICK, this.onStart = function (_ref) {
  2842. var target = _ref.target;
  2843. if (target.localName === 'img' && (!isFunction(options.filter) || options.filter.call(_this, target))) {
  2844. _this.view(_this.images.indexOf(target));
  2845. }
  2846. });
  2847. }
  2848. }
  2849. }, {
  2850. key: "build",
  2851. value: function build() {
  2852. if (this.ready) {
  2853. return;
  2854. }
  2855. var element = this.element,
  2856. options = this.options;
  2857. var parent = element.parentNode;
  2858. var template = document.createElement('div');
  2859. template.innerHTML = TEMPLATE;
  2860. var viewer = template.querySelector(".".concat(NAMESPACE, "-container"));
  2861. var title = viewer.querySelector(".".concat(NAMESPACE, "-title"));
  2862. var toolbar = viewer.querySelector(".".concat(NAMESPACE, "-toolbar"));
  2863. var navbar = viewer.querySelector(".".concat(NAMESPACE, "-navbar"));
  2864. var button = viewer.querySelector(".".concat(NAMESPACE, "-button"));
  2865. var canvas = viewer.querySelector(".".concat(NAMESPACE, "-canvas"));
  2866. this.parent = parent;
  2867. this.viewer = viewer;
  2868. this.title = title;
  2869. this.toolbar = toolbar;
  2870. this.navbar = navbar;
  2871. this.button = button;
  2872. this.canvas = canvas;
  2873. this.footer = viewer.querySelector(".".concat(NAMESPACE, "-footer"));
  2874. this.tooltipBox = viewer.querySelector(".".concat(NAMESPACE, "-tooltip"));
  2875. this.player = viewer.querySelector(".".concat(NAMESPACE, "-player"));
  2876. this.list = viewer.querySelector(".".concat(NAMESPACE, "-list"));
  2877. viewer.id = "".concat(NAMESPACE).concat(this.id);
  2878. title.id = "".concat(NAMESPACE, "Title").concat(this.id);
  2879. addClass(title, !options.title ? CLASS_HIDE : getResponsiveClass(Array.isArray(options.title) ? options.title[0] : options.title));
  2880. addClass(navbar, !options.navbar ? CLASS_HIDE : getResponsiveClass(options.navbar));
  2881. toggleClass(button, CLASS_HIDE, !options.button);
  2882. if (options.keyboard) {
  2883. button.setAttribute('tabindex', 0);
  2884. }
  2885. if (options.backdrop) {
  2886. addClass(viewer, "".concat(NAMESPACE, "-backdrop"));
  2887. if (!options.inline && options.backdrop !== 'static') {
  2888. setData(canvas, DATA_ACTION, 'hide');
  2889. }
  2890. }
  2891. if (isString(options.className) && options.className) {
  2892. // In case there are multiple class names
  2893. options.className.split(REGEXP_SPACES).forEach(function (className) {
  2894. addClass(viewer, className);
  2895. });
  2896. }
  2897. if (options.toolbar) {
  2898. var list = document.createElement('ul');
  2899. var custom = isPlainObject(options.toolbar);
  2900. var zoomButtons = BUTTONS.slice(0, 3);
  2901. var rotateButtons = BUTTONS.slice(7, 9);
  2902. var scaleButtons = BUTTONS.slice(9);
  2903. if (!custom) {
  2904. addClass(toolbar, getResponsiveClass(options.toolbar));
  2905. }
  2906. forEach(custom ? options.toolbar : BUTTONS, function (value, index) {
  2907. var deep = custom && isPlainObject(value);
  2908. var name = custom ? hyphenate(index) : value;
  2909. var show = deep && !isUndefined(value.show) ? value.show : value;
  2910. if (!show || !options.zoomable && zoomButtons.indexOf(name) !== -1 || !options.rotatable && rotateButtons.indexOf(name) !== -1 || !options.scalable && scaleButtons.indexOf(name) !== -1) {
  2911. return;
  2912. }
  2913. var size = deep && !isUndefined(value.size) ? value.size : value;
  2914. var click = deep && !isUndefined(value.click) ? value.click : value;
  2915. var item = document.createElement('li');
  2916. if (options.keyboard) {
  2917. item.setAttribute('tabindex', 0);
  2918. }
  2919. item.setAttribute('role', 'button');
  2920. addClass(item, "".concat(NAMESPACE, "-").concat(name));
  2921. if (!isFunction(click)) {
  2922. setData(item, DATA_ACTION, name);
  2923. }
  2924. if (isNumber(show)) {
  2925. addClass(item, getResponsiveClass(show));
  2926. }
  2927. if (['small', 'large'].indexOf(size) !== -1) {
  2928. addClass(item, "".concat(NAMESPACE, "-").concat(size));
  2929. } else if (name === 'play') {
  2930. addClass(item, "".concat(NAMESPACE, "-large"));
  2931. }
  2932. if (isFunction(click)) {
  2933. addListener(item, EVENT_CLICK, click);
  2934. }
  2935. list.appendChild(item);
  2936. });
  2937. toolbar.appendChild(list);
  2938. } else {
  2939. addClass(toolbar, CLASS_HIDE);
  2940. }
  2941. if (!options.rotatable) {
  2942. var rotates = toolbar.querySelectorAll('li[class*="rotate"]');
  2943. addClass(rotates, CLASS_INVISIBLE);
  2944. forEach(rotates, function (rotate) {
  2945. toolbar.appendChild(rotate);
  2946. });
  2947. }
  2948. if (options.inline) {
  2949. addClass(button, CLASS_FULLSCREEN);
  2950. setStyle(viewer, {
  2951. zIndex: options.zIndexInline
  2952. });
  2953. if (window.getComputedStyle(parent).position === 'static') {
  2954. setStyle(parent, {
  2955. position: 'relative'
  2956. });
  2957. }
  2958. parent.insertBefore(viewer, element.nextSibling);
  2959. } else {
  2960. addClass(button, CLASS_CLOSE);
  2961. addClass(viewer, CLASS_FIXED);
  2962. addClass(viewer, CLASS_FADE);
  2963. addClass(viewer, CLASS_HIDE);
  2964. setStyle(viewer, {
  2965. zIndex: options.zIndex
  2966. });
  2967. var container = options.container;
  2968. if (isString(container)) {
  2969. container = element.ownerDocument.querySelector(container);
  2970. }
  2971. if (!container) {
  2972. container = this.body;
  2973. }
  2974. container.appendChild(viewer);
  2975. }
  2976. if (options.inline) {
  2977. this.render();
  2978. this.bind();
  2979. this.isShown = true;
  2980. }
  2981. this.ready = true;
  2982. if (isFunction(options.ready)) {
  2983. addListener(element, EVENT_READY, options.ready, {
  2984. once: true
  2985. });
  2986. }
  2987. if (dispatchEvent(element, EVENT_READY) === false) {
  2988. this.ready = false;
  2989. return;
  2990. }
  2991. if (this.ready && options.inline) {
  2992. this.view(this.index);
  2993. }
  2994. }
  2995. /**
  2996. * Get the no conflict viewer class.
  2997. * @returns {Viewer} The viewer class.
  2998. */
  2999. }], [{
  3000. key: "noConflict",
  3001. value: function noConflict() {
  3002. window.Viewer = AnotherViewer;
  3003. return Viewer;
  3004. }
  3005. /**
  3006. * Change the default options.
  3007. * @param {Object} options - The new default options.
  3008. */
  3009. }, {
  3010. key: "setDefaults",
  3011. value: function setDefaults(options) {
  3012. assign(DEFAULTS, isPlainObject(options) && options);
  3013. }
  3014. }]);
  3015. return Viewer;
  3016. }();
  3017. assign(Viewer.prototype, render, events, handlers, methods, others);
  3018. return Viewer;
  3019. }));