viewer.common.js 109 KB

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