viewer.esm.js 109 KB

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