12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474 |
- /*!
- * Splide.js
- * Version : 3.0.0
- * License : MIT
- * Copyright: 2021 Naotoshi Fujita
- */
- 'use strict';
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- /**
- * The project code.
- *
- * @since 3.0.0
- */
- var PROJECT_CODE = 'splide';
- /**
- * The data attribute prefix.
- *
- * @since 3.0.0
- */
- var DATA_ATTRIBUTE = "data-" + PROJECT_CODE;
- /**
- * Splide has been just created.
- */
- var CREATED = 1;
- /**
- * Splide has mounted components.
- */
- var MOUNTED = 2;
- /**
- * Splide is ready.
- */
- var IDLE = 3;
- /**
- * Splide is moving.
- */
- var MOVING = 4;
- /**
- * Splide has been destroyed.
- */
- var DESTROYED = 5;
- /**
- * The collection of all states.
- *
- * @since 3.0.0
- */
- var STATES = {
- CREATED: CREATED,
- MOUNTED: MOUNTED,
- IDLE: IDLE,
- MOVING: MOVING,
- DESTROYED: DESTROYED
- };
- /**
- * Empties the array.
- *
- * @param array - A array to empty.
- */
- function empty(array) {
- array.length = 0;
- }
- /**
- * Checks if the given subject is an object or not.
- *
- * @param subject - A subject to check.
- *
- * @return `true` if the subject is an object, or otherwise `false`.
- */
- function isObject(subject) {
- return !isNull(subject) && typeof subject === 'object';
- }
- /**
- * Checks if the given subject is an array or not.
- *
- * @param subject - A subject to check.
- *
- * @return `true` if the subject is an array, or otherwise `false`.
- */
- function isArray(subject) {
- return Array.isArray(subject);
- }
- /**
- * Checks if the given subject is a function or not.
- *
- * @param subject - A subject to check.
- *
- * @return `true` if the subject is a function, or otherwise `false`.
- */
- function isFunction(subject) {
- return typeof subject === 'function';
- }
- /**
- * Checks if the given subject is a string or not.
- *
- * @param subject - A subject to check.
- *
- * @return `true` if the subject is a string, or otherwise `false`.
- */
- function isString(subject) {
- return typeof subject === 'string';
- }
- /**
- * Checks if the given subject is `undefined` or not.
- *
- * @param subject - A subject to check.
- *
- * @return `true` if the subject is `undefined`, or otherwise `false`.
- */
- function isUndefined(subject) {
- return typeof subject === 'undefined';
- }
- /**
- * Checks if the given subject is `null` or not.
- *
- * @param subject - A subject to check.
- *
- * @return `true` if the subject is `null`, or otherwise `false`.
- */
- function isNull(subject) {
- return subject === null;
- }
- /**
- * Checks if the given subject is an HTMLElement or not.
- *
- * @param subject - A subject to check.
- *
- * @return `true` if the subject is an HTMLElement instance, or otherwise `false`.
- */
- function isHTMLElement(subject) {
- return subject instanceof HTMLElement;
- }
- /**
- * Checks if the given subject is an HTMLButtonElement or not.
- *
- * @param subject - A subject to check.
- *
- * @return `true` if the subject is an HTMLButtonElement, or otherwise `false`.
- */
- function isHTMLButtonElement(subject) {
- return subject instanceof HTMLButtonElement;
- }
- /**
- * Push the provided value to an array if the value is not an array.
- *
- * @param value - A value to push.
- *
- * @return An array containing the value, or the value itself if it is already an array.
- */
- function toArray(value) {
- return isArray(value) ? value : [value];
- }
- /**
- * The extended `Array#forEach` method that accepts a single value as an argument.
- *
- * @param values - A value or values to iterate over.
- * @param iteratee - An iteratee function.
- */
- function forEach(values, iteratee) {
- toArray(values).forEach(iteratee);
- }
- /**
- * Checks if the array includes the value or not.
- * `Array#includes` is not supported by IE.
- *
- * @param array - An array.
- * @param value - A value to search for.
- *
- * @return `true` if the array includes the value, or otherwise `false`.
- */
- function includes(array, value) {
- return array.indexOf(value) > -1;
- }
- /**
- * Extended `Array#push()` that accepts an item or an array with items.
- *
- * @param array - An array to push items.
- * @param items - An item or items to push.
- *
- * @return A provided array itself.
- */
- function push(array, items) {
- array.push.apply(array, toArray(items));
- return array;
- }
- var arrayProto = Array.prototype;
- /**
- * The slice method for an array-like object.
- *
- * @param arrayLike - An array-like object.
- * @param start - Optional. A start index.
- * @param end - Optional. A end index.
- *
- * @return An array with sliced elements.
- */
- function slice(arrayLike, start, end) {
- return arrayProto.slice.call(arrayLike, start, end);
- }
- /**
- * The find method for an array or array-like object, works in IE.
- * This method is not performant for a huge array.
- *
- * @param arrayLike - An array-like object.
- * @param predicate - The predicate function to test each element in the object.
- *
- * @return A found value if available, or otherwise `undefined`.
- */
- function find(arrayLike, predicate) {
- return slice(arrayLike).filter(predicate)[0];
- }
- /**
- * Toggles the provided class or classes by following the `add` boolean.
- *
- * @param elm - An element whose classes are toggled.
- * @param classes - A class or class names.
- * @param add - Whether to add or remove a class.
- */
- function toggleClass(elm, classes, add) {
- if (elm) {
- forEach(classes, function (name) {
- if (name) {
- elm.classList[add ? 'add' : 'remove'](name);
- }
- });
- }
- }
- /**
- * Adds classes to the element.
- *
- * @param elm - An element to add classes to.
- * @param classes - Classes to add.
- */
- function addClass(elm, classes) {
- toggleClass(elm, classes, true);
- }
- /**
- * Appends children to the parent element.
- *
- * @param parent - A parent element.
- * @param children - A child or children to append to the parent.
- */
- function append(parent, children) {
- forEach(children, parent.appendChild.bind(parent));
- }
- /**
- * Inserts a node or nodes before the specified reference node.
- *
- * @param nodes - A node or nodes to insert.
- * @param ref - A reference node.
- */
- function before(nodes, ref) {
- forEach(nodes, function (node) {
- var parent = ref.parentNode;
- if (parent) {
- parent.insertBefore(node, ref);
- }
- });
- }
- /**
- * Checks if the element can be selected by the provided selector or not.
- *
- * @param elm - An element to check.
- * @param selector - A selector to test.
- *
- * @return `true` if the selector matches the element, or otherwise `false`.
- */
- function matches(elm, selector) {
- return (elm['msMatchesSelector'] || elm.matches).call(elm, selector);
- }
- /**
- * Finds children that has the specified tag or class name.
- *
- * @param parent - A parent element.
- * @param selector - A selector to filter children.
- *
- * @return An array with filtered children.
- */
- function children(parent, selector) {
- return parent ? slice(parent.children).filter(function (child) {
- return matches(child, selector);
- }) : [];
- }
- /**
- * Returns a child element that matches the specified tag or class name.
- *
- * @param parent - A parent element.
- * @param selector - A selector to filter children.
- *
- * @return A matched child element if available, or otherwise `undefined`.
- */
- function child(parent, selector) {
- return selector ? children(parent, selector)[0] : parent.firstElementChild;
- }
- /**
- * Iterates over the provided object by own enumerable keys with calling the iteratee function.
- *
- * @param object - An object to iterate over.
- * @param iteratee - An iteratee function that takes the value and key as arguments.
- *
- * @return A provided object itself.
- */
- function forOwn(object, iteratee) {
- if (object) {
- var keys = Object.keys(object);
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i];
- if (key !== '__proto__') {
- if (iteratee(object[key], key) === false) {
- break;
- }
- }
- }
- }
- return object;
- }
- /**
- * Assigns all own enumerable properties of all source objects to the provided object.
- * `undefined` in source objects will be skipped.
- *
- * @param object - An object to assign properties to.
- * @param sources - Objects to assign properties from.
- *
- * @return An object assigned properties of the sources to.
- */
- function assign(object) {
- for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- sources[_key - 1] = arguments[_key];
- }
- sources.forEach(function (source) {
- forOwn(source, function (value, key) {
- object[key] = source[key];
- });
- });
- return object;
- }
- /**
- * Recursively merges source properties to the object.
- *
- * @param object - An object to merge properties to.
- * @param source - A source object to merge properties from.
- *
- * @return A new object with merged properties.
- */
- function merge(object, source) {
- forOwn(source, function (value, key) {
- object[key] = isObject(value) ? merge(isObject(object[key]) ? object[key] : {}, value) : value;
- });
- return object;
- }
- /**
- * Removes attributes from the element.
- *
- * @param elm - An element.
- * @param attrs - An attribute or attributes to remove.
- */
- function removeAttribute(elm, attrs) {
- if (elm) {
- forEach(attrs, function (attr) {
- elm.removeAttribute(attr);
- });
- }
- }
- function setAttribute(elm, attrs, value) {
- if (isObject(attrs)) {
- forOwn(attrs, function (value, name) {
- setAttribute(elm, name, value);
- });
- } else {
- isNull(value) ? removeAttribute(elm, attrs) : elm.setAttribute(attrs, String(value));
- }
- }
- /**
- * Creates a HTML element.
- *
- * @param tag - A tag name.
- * @param attrs - Optional. An object with attributes to apply the created element to, or a string with classes.
- * @param parent - Optional. A parent element where the created element is appended.
- */
- function create(tag, attrs, parent) {
- var elm = document.createElement(tag);
- if (attrs) {
- if (isString(attrs) || isArray(attrs)) {
- addClass(elm, attrs);
- } else {
- setAttribute(elm, attrs);
- }
- }
- if (parent) {
- append(parent, elm);
- }
- return elm;
- }
- /**
- * Applies inline styles to the provided element by an object literal.
- *
- * @param elms - An element or elements to apply styles to.
- * @param styles - An object literal with styles.
- */
- function style(elms, styles) {
- if (isString(styles)) {
- return isArray(elms) ? null : getComputedStyle(elms)[styles];
- }
- forOwn(styles, function (value, key) {
- if (!isNull(value)) {
- forEach(elms, function (elm) {
- if (elm) {
- elm.style[key] = "" + value;
- }
- });
- }
- });
- }
- /**
- * Sets the `display` CSS value to the element.
- *
- * @param elm - An element to set a new value to.
- * @param display - A new `display` value.
- */
- function display(elm, display) {
- style(elm, {
- display: display
- });
- }
- /**
- * Returns the specified attribute value.
- *
- * @param elm - An element.
- * @param attr - An attribute to get.
- */
- function getAttribute(elm, attr) {
- return elm.getAttribute(attr);
- }
- /**
- * Checks if the element contains the specified class or not.
- *
- * @param elm - An element to check.
- * @param className - A class name that may be contained by the element.
- *
- * @return `true` if the element contains the class, or otherwise `false`.
- */
- function hasClass(elm, className) {
- return elm && elm.classList.contains(className);
- }
- /**
- * Parses the provided HTML string and returns the first element.
- *
- * @param html - An HTML string to parse.
- *
- * @return An Element on success, or otherwise `undefined`.
- */
- function parseHtml(html) {
- return child(new DOMParser().parseFromString(html, 'text/html').body);
- }
- /**
- * Call the `preventDefault()` of the provided event.
- *
- * @param e - An Event object.
- * @param stopPropagation - Optional. Whether to stop the event propagation or not.
- */
- function prevent(e, stopPropagation) {
- e.preventDefault();
- if (stopPropagation) {
- e.stopPropagation();
- e.stopImmediatePropagation();
- }
- }
- /**
- * Returns an element that matches the provided selector.
- *
- * @param parent - A parent element to start searching from.
- * @param selector - A selector to query.
- *
- * @return A found element or `null`.
- */
- function query(parent, selector) {
- return parent && parent.querySelector(selector);
- }
- /**
- * Returns elements that match the provided selector.
- *
- * @param parent - A parent element to start searching from.
- * @param selector - A selector to query.
- *
- * @return An array with matched elements.
- */
- function queryAll(parent, selector) {
- return slice(parent.querySelectorAll(selector));
- }
- /**
- * Returns a DOMRect object of the provided element.
- *
- * @param target - An element.
- */
- function rect(target) {
- return target.getBoundingClientRect();
- }
- /**
- * Removes the provided node from its parent.
- *
- * @param nodes - A node or nodes to remove.
- */
- function remove(nodes) {
- forEach(nodes, function (node) {
- if (node && node.parentNode) {
- node.parentNode.removeChild(node);
- }
- });
- }
- /**
- * Removes classes from the element.
- *
- * @param elm - An element to remove classes from.
- * @param classes - Classes to remove.
- */
- function removeClass(elm, classes) {
- toggleClass(elm, classes, false);
- }
- /**
- * Appends `px` to the provided number.
- * If the value is already string, just returns it.
- *
- * @param value - A value to append `px` to.
- *
- * @return A string with the CSS unit.
- */
- function unit(value) {
- return isString(value) ? value : value ? value + "px" : '';
- }
- /**
- * Throws an error if the provided condition is falsy.
- *
- * @param condition - If falsy, an error is thrown.
- * @param message - Optional. A message to display.
- */
- function assert(condition, message) {
- if (message === void 0) {
- message = '';
- }
- if (!condition) {
- throw new Error("[" + PROJECT_CODE + "] " + message);
- }
- }
- /**
- * Invokes the callback on the next tick.
- *
- * @param callback - A callback function.
- */
- function nextTick(callback) {
- setTimeout(callback);
- }
- /**
- * No operation.
- */
- var noop = function noop() {}; // eslint-disable-line no-empty-function, @typescript-eslint/no-empty-function
- /**
- * The arias of `window.requestAnimationFrame()`.
- */
- function raf(func) {
- return requestAnimationFrame(func);
- }
- /**
- * Checks if the subject number is between `minOrMax` and `maxOrMin`.
- *
- * @param number - A subject number to check.
- * @param minOrMax - A min or max number.
- * @param maxOrMin - A max or min number.
- * @param exclusive - Optional. Whether to exclude `x` or `y`.
- */
- function between(number, minOrMax, maxOrMin, exclusive) {
- var min = Math.min(minOrMax, maxOrMin);
- var max = Math.max(minOrMax, maxOrMin);
- return exclusive ? min < number && number < max : min <= number && number <= max;
- }
- var max$1 = Math.max,
- min$1 = Math.min;
- /**
- * Clamps a number.
- *
- * @param number - A subject number to check.
- * @param x - A min or max number.
- * @param y - A min or max number.
- */
- function clamp(number, x, y) {
- var minimum = min$1(x, y);
- var maximum = max$1(x, y);
- return min$1(max$1(minimum, number), maximum);
- }
- /**
- * Returns the sign of the provided number.
- *
- * @param x - A number.
- *
- * @return `1` for positive numbers, `-1` for negative numbers, or `0` for `0`.
- */
- function sign(x) {
- return +(x > 0) - +(x < 0);
- }
- var min = Math.min,
- max = Math.max,
- floor = Math.floor,
- ceil = Math.ceil,
- abs = Math.abs,
- round = Math.round;
- /**
- * The component for managing options.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return An Options component object.
- */
- function Options(Splide, Components, options) {
- /**
- * Keeps the initial options to apply when no matched query exists.
- */
- var initialOptions;
- /**
- * Stores breakpoints with the MediaQueryList object.
- */
- var points;
- /**
- * Holds the current breakpoint.
- */
- var currPoint;
- /**
- * Called when the component is constructed.
- */
- function setup() {
- try {
- merge(options, JSON.parse(getAttribute(Splide.root, DATA_ATTRIBUTE)));
- } catch (e) {
- assert(false, e.message);
- }
- initialOptions = merge({}, options);
- }
- /**
- * Called when the component is mounted.
- */
- function mount() {
- var breakpoints = options.breakpoints;
- if (breakpoints) {
- points = Object.keys(breakpoints).sort(function (n, m) {
- return +n - +m;
- }).map(function (point) {
- return [point, matchMedia("(" + (options.mediaQuery || 'max') + "-width:" + point + "px)")];
- });
- addEventListener('resize', observe);
- observe();
- }
- }
- /**
- * Destroys the component.
- *
- * @param completely - Will be `true` for complete destruction.
- */
- function destroy(completely) {
- if (completely) {
- removeEventListener('resize', observe);
- }
- }
- /**
- * Observes breakpoints.
- * The `currPoint` may be `undefined`.
- */
- function observe() {
- var item = find(points, function (item) {
- return item[1].matches;
- }) || [];
- if (item[0] !== currPoint) {
- onMatch(currPoint = item[0]);
- }
- }
- /**
- * Called when the media query matches breakpoints.
- *
- * @param point - A matched point, or `undefined` that means no breakpoint matches a media query.
- */
- function onMatch(point) {
- var newOptions = options.breakpoints[point] || initialOptions;
- if (newOptions.destroy) {
- Splide.options = initialOptions;
- Splide.destroy(newOptions.destroy === 'completely');
- } else {
- if (Splide.state.is(DESTROYED)) {
- destroy(true);
- Splide.mount();
- }
- Splide.options = newOptions;
- }
- }
- return {
- setup: setup,
- mount: mount,
- destroy: destroy
- };
- }
- /**
- * Enumerates slides from left to right.
- */
- /**
- * Enumerates slides from right to left.
- */
- var RTL = 'rtl';
- /**
- * Enumerates slides in a col.
- */
- var TTB = 'ttb';
- /**
- * The translation map for directions.
- *
- * @since 3.0.0
- */
- var ORIENTATION_MAP = {
- marginRight: ['marginBottom', 'marginLeft'],
- width: ['height'],
- autoWidth: ['autoHeight'],
- fixedWidth: ['fixedHeight'],
- paddingLeft: ['paddingTop', 'paddingRight'],
- paddingRight: ['paddingBottom', 'paddingLeft'],
- left: ['top', 'right'],
- right: ['bottom', 'left'],
- x: ['y'],
- X: ['Y'],
- pageX: ['pageY'],
- ArrowLeft: ['ArrowUp', 'ArrowRight'],
- ArrowRight: ['ArrowDown', 'ArrowLeft']
- };
- /**
- * The component that absorbs the difference among directions.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Direction component object.
- */
- function Direction(Splide, Components, options) {
- /**
- * Resolves the provided property name.
- *
- * @param prop - A property name to translate.
- * @param axisOnly - Optional. If `ture`, returns the same property for LTR and RTL.
- */
- function resolve(prop, axisOnly) {
- var direction = options.direction;
- var index = direction === RTL && !axisOnly ? 1 : direction === TTB ? 0 : -1;
- return ORIENTATION_MAP[prop][index] || prop;
- }
- /**
- * Orients the value towards the current direction.
- *
- * @param value - A value to orient.
- *
- * @return The oriented value.
- */
- function orient(value) {
- return value * (options.direction === RTL ? 1 : -1);
- }
- return {
- resolve: resolve,
- orient: orient
- };
- }
- var CLASS_ROOT = PROJECT_CODE;
- var CLASS_SLIDER = PROJECT_CODE + "__slider";
- var CLASS_TRACK = PROJECT_CODE + "__track";
- var CLASS_LIST = PROJECT_CODE + "__list";
- var CLASS_SLIDE = PROJECT_CODE + "__slide";
- var CLASS_CLONE = CLASS_SLIDE + "--clone";
- var CLASS_CONTAINER = CLASS_SLIDE + "__container";
- var CLASS_ARROWS = PROJECT_CODE + "__arrows";
- var CLASS_ARROW = PROJECT_CODE + "__arrow";
- var CLASS_ARROW_PREV = CLASS_ARROW + "--prev";
- var CLASS_ARROW_NEXT = CLASS_ARROW + "--next";
- var CLASS_PAGINATION = PROJECT_CODE + "__pagination";
- var CLASS_PAGINATION_PAGE = CLASS_PAGINATION + "__page";
- var CLASS_PROGRESS = PROJECT_CODE + "__progress";
- var CLASS_PROGRESS_BAR = CLASS_PROGRESS + "__bar";
- var CLASS_AUTOPLAY = PROJECT_CODE + "__autoplay";
- var CLASS_PLAY = PROJECT_CODE + "__play";
- var CLASS_PAUSE = PROJECT_CODE + "__pause";
- var CLASS_SPINNER = PROJECT_CODE + "__spinner";
- var CLASS_INITIALIZED = 'is-initialized';
- var CLASS_ACTIVE = 'is-active';
- var CLASS_PREV = 'is-prev';
- var CLASS_NEXT = 'is-next';
- var CLASS_VISIBLE = 'is-visible';
- var CLASS_LOADING = 'is-loading';
- /**
- * The array with all status classes.
- *
- * @since 3.0.0
- */
- var STATUS_CLASSES = [CLASS_ACTIVE, CLASS_VISIBLE, CLASS_PREV, CLASS_NEXT, CLASS_LOADING];
- /**
- * The collection of classes for elements that Splide dynamically creates.
- *
- * @since 3.0.0
- */
- var CLASSES = {
- slide: CLASS_SLIDE,
- clone: CLASS_CLONE,
- arrows: CLASS_ARROWS,
- arrow: CLASS_ARROW,
- prev: CLASS_ARROW_PREV,
- next: CLASS_ARROW_NEXT,
- pagination: CLASS_PAGINATION,
- page: CLASS_PAGINATION_PAGE,
- spinner: CLASS_SPINNER
- };
- var EVENT_MOUNTED = 'mounted';
- var EVENT_READY = 'ready';
- var EVENT_MOVE = 'move';
- var EVENT_MOVED = 'moved';
- var EVENT_CLICK = 'click';
- var EVENT_ACTIVE = 'active';
- var EVENT_INACTIVE = 'inactive';
- var EVENT_VISIBLE = 'visible';
- var EVENT_HIDDEN = 'hidden';
- var EVENT_SLIDE_KEYDOWN = 'slide:keydown';
- var EVENT_REFRESH = 'refresh';
- var EVENT_UPDATED = 'undated';
- var EVENT_RESIZE = 'resize';
- var EVENT_RESIZED = 'resized';
- var EVENT_DRAG = 'drag';
- var EVENT_DRAGGING = 'dragging';
- var EVENT_DRAGGED = 'dragged';
- var EVENT_SCROLL = 'scroll';
- var EVENT_SCROLLED = 'scrolled';
- var EVENT_DESTROY = 'destroy';
- var EVENT_ARROWS_MOUNTED = 'arrows:mounted';
- var EVENT_ARROWS_UPDATED = 'arrows:updated';
- var EVENT_PAGINATION_MOUNTED = 'pagination:mounted';
- var EVENT_PAGINATION_PAGE = 'pagination:page';
- var EVENT_PAGINATION_UPDATED = 'pagination:updated';
- var EVENT_NAVIGATION_MOUNTED = 'navigation:mounted';
- var EVENT_AUTOPLAY_PLAY = 'autoplay:play';
- var EVENT_AUTOPLAY_PLAYING = 'autoplay:playing';
- var EVENT_AUTOPLAY_PAUSE = 'autoplay:pause';
- var EVENT_LAZYLOAD_LOADED = 'lazyload:loaded';
- /**
- * The constructor to provided a simple event system.
- *
- * @since 3.0.0
- *
- * @return An EventBus object.
- */
- function EventBus() {
- /**
- * The collection of registered handlers.
- */
- var handlers = {};
- /**
- * Registers an event handler.
- *
- * @param events - An event name or names separated by spaces. Use a dot(.) to add a namespace.
- * @param callback - A callback function to register.
- * @param key - Optional. An object for an identifier of the handler.
- * @param priority - Optional. A priority number for the order in which the callbacks are invoked.
- * Lower numbers correspond with earlier execution. The default value is 10.
- */
- function on(events, callback, key, priority) {
- if (priority === void 0) {
- priority = 10;
- }
- forEachEvent(events, function (event, namespace) {
- handlers[event] = handlers[event] || [];
- push(handlers[event], {
- event: event,
- callback: callback,
- namespace: namespace,
- priority: priority,
- key: key
- }).sort(function (handler1, handler2) {
- return handler1.priority - handler2.priority;
- });
- });
- }
- /**
- * Removes event handlers registered by `on()`.
- * If only the event name is provided, all handlers that associate with the event are removed.
- * If the event name and namespace are specified, handlers that associate with the event and namespace are removed.
- *
- * @param events - An event name or names separated by spaces. Use a dot(.) to add a namespace.
- * @param key - Optional. An object for an identifier of the handler.
- */
- function off(events, key) {
- forEachEvent(events, function (event, namespace) {
- var eventHandlers = handlers[event];
- handlers[event] = eventHandlers && eventHandlers.filter(function (handler) {
- return handler.key ? handler.key !== key : handler.namespace !== namespace;
- });
- });
- }
- /**
- * Removes all handlers locked by the specified key.
- *
- * @param key - A key.
- */
- function offBy(key) {
- forOwn(handlers, function (eventHandlers, event) {
- off(event, key);
- });
- }
- /**
- * Triggers callback functions.
- * This accepts additional arguments and passes them to callbacks.
- *
- * @param event - An event name.
- */
- function emit(event) {
- var _arguments = arguments;
- (handlers[event] || []).forEach(function (handler) {
- handler.callback.apply(handler, slice(_arguments, 1));
- });
- }
- /**
- * Removes all handlers.
- */
- function destroy() {
- handlers = {};
- }
- /**
- * Parses provided events and iterates over them.
- *
- * @param events - An event or events.
- * @param iteratee - An iteratee function.
- */
- function forEachEvent(events, iteratee) {
- toArray(events).join(' ').split(' ').forEach(function (eventNS) {
- var fragments = eventNS.split('.');
- iteratee(fragments[0], fragments[1]);
- });
- }
- return {
- on: on,
- off: off,
- offBy: offBy,
- emit: emit,
- destroy: destroy
- };
- }
- /**
- * The function that provides interface for internal and native events.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- *
- * @return A collection of interface functions.
- */
- function EventInterface(Splide) {
- /**
- * Holds the event object.
- */
- var event = Splide.event;
- /**
- * The key for events.
- */
- var key = {};
- /**
- * Stores all handlers that listen to native events.
- */
- var listeners = [];
- /**
- * Registers an event handler with an unique key.
- * It can only be removed by `off()` method below.
- *
- * @param events - An event name or names separated by spaces. Use a dot(.) to add a namespace.
- * @param callback - A callback function to register.
- * @param priority - Optional. A priority number for the order in which the callbacks are invoked.
- * Lower numbers correspond with earlier execution. The default value is 10.
- */
- function on(events, callback, priority) {
- event.on(events, callback, key, priority);
- }
- /**
- * Removes event handlers registered by `on()`.
- *
- * @param events - An event name or names separated by spaces. Use a dot(.) to add a namespace.
- */
- function off(events) {
- event.off(events, key);
- }
- /**
- * Listens to native events.
- * Splide#destory() will remove all registered listeners.
- *
- * @param targets - A target element, the window object or the document object.
- * @param events - An event or events to listen to.
- * @param callback - A callback function.
- * @param options - Optional. The options to pass to the `addEventListener` function.
- */
- function bind(targets, events, callback, options) {
- forEachEvent(targets, events, function (target, event) {
- listeners.push([target, event, callback, options]);
- target.addEventListener(event, callback, options);
- });
- }
- /**
- * Removes the event handler.
- *
- * @param targets - A target element, the window object or the document object.
- * @param events - An event name or names to remove.
- */
- function unbind(targets, events) {
- forEachEvent(targets, events, function (target, event) {
- listeners = listeners.filter(function (listener) {
- if (listener[0] === target && listener[1] === event) {
- target.removeEventListener(event, listener[2], listener[3]);
- return false;
- }
- return true;
- });
- });
- }
- /**
- * Iterates over each target and event.
- *
- * @param targets - A target element, the window object or the document object.
- * @param events - An event name or names.
- * @param iteratee - An iteratee function.
- */
- function forEachEvent(targets, events, iteratee) {
- forEach(targets, function (target) {
- if (target) {
- events.split(' ').forEach(iteratee.bind(null, target));
- }
- });
- }
- /**
- * Removes all listeners.
- */
- function destroy() {
- listeners = listeners.filter(function (data) {
- return unbind(data[0], data[1]);
- });
- event.offBy(key);
- }
- /**
- * Invokes destroy when the slider is destroyed.
- */
- event.on(EVENT_DESTROY, destroy, key);
- return {
- on: on,
- off: off,
- emit: event.emit,
- bind: bind,
- unbind: unbind,
- destroy: destroy
- };
- }
- /**
- * Requests interval like the native `setInterval()` with using `requestAnimationFrame`.
- *
- * @since 3.0.0
- *
- * @param interval - The interval duration in milliseconds.
- * @param onInterval - The callback fired on every interval.
- * @param onUpdate - Optional. Called on every animation frame, taking the progress rate.
- * @param limit - Optional. Limits the number of interval.
- */
- function RequestInterval(interval, onInterval, onUpdate, limit) {
- var now = Date.now;
- /**
- * The time when the interval starts.
- */
- var startTime;
- /**
- * The current progress rate.
- */
- var rate = 0;
- /**
- * The animation frame ID.
- */
- var id;
- /**
- * Indicates whether the interval is currently paused or not.
- */
- var paused = true;
- /**
- * The loop count. This only works when the `limit` argument is provided.
- */
- var count = 0;
- /**
- * The update function called on every animation frame.
- */
- function update() {
- if (!paused) {
- var elapsed = now() - startTime;
- if (elapsed >= interval) {
- rate = 1;
- startTime = now();
- } else {
- rate = elapsed / interval;
- }
- if (onUpdate) {
- onUpdate(rate);
- }
- if (rate === 1) {
- onInterval();
- if (limit && ++count >= limit) {
- pause();
- return;
- }
- }
- raf(update);
- }
- }
- /**
- * Starts the interval.
- *
- * @param resume - Optional. Whether to resume the paused progress or not.
- */
- function start(resume) {
- !resume && cancel();
- startTime = now() - (resume ? rate * interval : 0);
- paused = false;
- raf(update);
- }
- /**
- * Pauses the interval.
- */
- function pause() {
- paused = true;
- }
- /**
- * Rewinds the current progress.
- */
- function rewind() {
- startTime = now();
- rate = 0;
- if (onUpdate) {
- onUpdate(rate);
- }
- }
- /**
- * Cancels the interval.
- */
- function cancel() {
- cancelAnimationFrame(id);
- rate = 0;
- id = 0;
- paused = true;
- }
- /**
- * Checks if the interval is paused or not.
- *
- * @return `true` if the interval is paused, or otherwise `false`.
- */
- function isPaused() {
- return paused;
- }
- return {
- start: start,
- rewind: rewind,
- pause: pause,
- cancel: cancel,
- isPaused: isPaused
- };
- }
- /**
- * The function providing a super simple state system.
- *
- * @param initialState - Specifies the initial state.
- */
- function State(initialState) {
- /**
- * The current state.
- */
- var state = initialState;
- /**
- * Sets a new state.
- *
- * @param value - A new state value.
- */
- function set(value) {
- state = value;
- }
- /**
- * Checks if the current state matches the provided one.
- *
- * @param states - A state to check.
- *
- * @return `true` if the current state is the provided one.
- */
- function is(states) {
- return includes(toArray(states), state);
- }
- return {
- set: set,
- is: is
- };
- }
- /**
- * Returns the throttled function.
- *
- * @param func - A function to throttle.
- * @param duration - Optional. Throttle duration in milliseconds.
- *
- * @return A throttled function.
- */
- function Throttle(func, duration) {
- var interval;
- function throttled() {
- var _arguments2 = arguments,
- _this = this;
- if (!interval) {
- interval = RequestInterval(duration || 0, function () {
- func.apply(_this, _arguments2);
- interval = null;
- }, null, 1);
- interval.start();
- }
- }
- return throttled;
- }
- /**
- * Formats a string.
- *
- * @param string - A string to format.
- * @param replacements - A replacement or replacements.
- *
- * @return A formatted string.
- */
- function format(string, replacements) {
- forEach(replacements, function (replacement) {
- string = string.replace('%s', "" + replacement);
- });
- return string;
- }
- /**
- * Pads the number with 0.
- *
- * @param number - A number to pad.
- *
- * @return string - Padded number.
- */
- function pad(number) {
- return number < 10 ? "0" + number : "" + number;
- }
- /**
- * Stores unique IDs.
- *
- * @since 3.0.0
- */
- var ids = {};
- /**
- * Returns a sequential unique ID as "{ prefix }-{ number }".
- *
- * @param prefix - A prefix for the ID.
- */
- function uniqueId(prefix) {
- return "" + prefix + pad(ids[prefix] = (ids[prefix] || 0) + 1);
- }
- /**
- * The component that collects and handles elements which the slider consists of.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return An Elements component object.
- */
- function Elements(Splide, Components, options) {
- var _EventInterface = EventInterface(Splide),
- on = _EventInterface.on;
- var root = Splide.root;
- var elements = {};
- /**
- * Stores all slide elements.
- */
- var slides = [];
- /**
- * Stores all root classes.
- */
- var classes;
- /**
- * The slider element that may be `undefined`.
- */
- var slider;
- /**
- * The track element.
- */
- var track;
- /**
- * The list element.
- */
- var list;
- /**
- * Called when the component is constructed.
- */
- function setup() {
- collect();
- identify();
- addClass(root, classes = getClasses());
- }
- /**
- * Called when the component is mounted.
- */
- function mount() {
- on(EVENT_REFRESH, refresh);
- on(EVENT_UPDATED, update);
- }
- /**
- * Destroys the component.
- */
- function destroy() {
- empty(slides);
- removeClass(root, classes);
- }
- /**
- * Recollects slide elements.
- */
- function refresh() {
- destroy();
- setup();
- }
- /**
- * Updates the status of elements.
- */
- function update() {
- removeClass(root, classes);
- addClass(root, classes = getClasses());
- }
- /**
- * Collects elements which the slider consists of.
- */
- function collect() {
- slider = child(root, "." + CLASS_SLIDER);
- track = query(root, "." + CLASS_TRACK);
- list = child(track, "." + CLASS_LIST);
- assert(track && list, 'Missing a track/list element.');
- push(slides, children(list, "." + CLASS_SLIDE + ":not(." + CLASS_CLONE + ")"));
- var autoplay = find("." + CLASS_AUTOPLAY);
- var arrows = find("." + CLASS_ARROWS);
- assign(elements, {
- root: root,
- slider: slider,
- track: track,
- list: list,
- slides: slides,
- arrows: arrows,
- prev: query(arrows, "." + CLASS_ARROW_PREV),
- next: query(arrows, "." + CLASS_ARROW_NEXT),
- bar: query(find("." + CLASS_PROGRESS), "." + CLASS_PROGRESS_BAR),
- play: query(autoplay, "." + CLASS_PLAY),
- pause: query(autoplay, "." + CLASS_PAUSE)
- });
- }
- /**
- * Assigns unique IDs to essential elements.
- */
- function identify() {
- var id = root.id || uniqueId(PROJECT_CODE);
- root.id = id;
- track.id = track.id || id + "-track";
- list.id = list.id || id + "-list";
- }
- /**
- * Finds an element only in children of the root or slider element.
- *
- * @return {Element} - A found element or undefined.
- */
- function find(selector) {
- return child(root, selector) || child(slider, selector);
- }
- /**
- * Return an array with classes for the root element.
- *
- * @return An array with classes.
- */
- function getClasses() {
- return [CLASS_ROOT + "--" + options.type, CLASS_ROOT + "--" + options.direction, options.drag && CLASS_ROOT + "--draggable", options.isNavigation && CLASS_ROOT + "--nav", CLASS_ACTIVE];
- }
- return assign(elements, {
- setup: setup,
- mount: mount,
- destroy: destroy
- });
- }
- /**
- * The component for managing styles of the slider.
- *
- * @since 3.0.0
- *
- * @return A Style component object.
- */
- function Style() {
- /**
- * The style element for the slider.
- */
- var style;
- /**
- * The CSSStyleSheet object of the created style element.
- */
- var sheet;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- style = create('style', {}, document.head);
- sheet = style.sheet;
- }
- /**
- * Destroys the component.
- */
- function destroy() {
- remove(style);
- sheet = null;
- }
- /**
- * Registers the style for the selector.
- *
- * @param selector - A selector string.
- * @param prop - A CSS property, accepting the camel case.
- * @param value - A CSS value.
- */
- function rule(selector, prop, value) {
- var _sheet = sheet,
- cssRules = _sheet.cssRules;
- var cssRule = find(cssRules, function (cssRule) {
- return isCSSStyleRule(cssRule) && cssRule.selectorText === selector;
- }) || cssRules[sheet.insertRule(selector + "{}", 0)];
- if (isCSSStyleRule(cssRule)) {
- cssRule.style[prop] = "" + value;
- }
- }
- /**
- * Registers the style by the element or the ID.
- *
- * @param target - A target element or ID.
- * @param prop - A CSS property, accepting the camel case.
- * @param value - A CSS value.
- */
- function ruleBy(target, prop, value) {
- rule("#" + (isHTMLElement(target) ? target.id : target), prop, value);
- }
- /**
- * Checks if the provided rule is a CSSStyleRule instance or not.
- *
- * @param cssRule - An instance to check.
- *
- * @return `true` if the cssRule is an instance of CSSStyleRule, or otherwise `false`.
- */
- function isCSSStyleRule(cssRule) {
- return cssRule instanceof CSSStyleRule;
- }
- return {
- mount: mount,
- destroy: destroy,
- rule: rule,
- ruleBy: ruleBy
- };
- }
- var ROLE = 'role';
- var ARIA_CONTROLS = 'aria-controls';
- var ARIA_CURRENT = 'aria-current';
- var ARIA_LABEL = 'aria-label';
- var ARIA_HIDDEN = 'aria-hidden';
- var TAB_INDEX = 'tabindex';
- var DISABLED = 'disabled';
- /**
- * The array with all attributes.
- *
- * @since 3.0.0
- */
- var ALL_ATTRIBUTES = [ROLE, ARIA_CONTROLS, ARIA_CURRENT, ARIA_LABEL, ARIA_HIDDEN, TAB_INDEX, DISABLED];
- /**
- * The type for the regular slider.
- *
- * @since 3.0.0
- */
- var SLIDE = 'slide';
- /**
- * The type for the carousel slider.
- *
- * @since 3.0.0
- */
- var LOOP = 'loop';
- /**
- * The type for the fade slider that can not have multiple slides in a page.
- *
- * @since 3.0.0
- */
- var FADE = 'fade';
- /**
- * The sub component for managing each slide.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param index - A slide index.
- * @param slideIndex - A slide index for clones. This must be `-1` if the slide is not clone.
- * @param slide - A slide element.
- *
- * @return A Slide sub component.
- */
- function Slide$1(Splide, index, slideIndex, slide) {
- var _EventInterface2 = EventInterface(Splide),
- on = _EventInterface2.on,
- emit = _EventInterface2.emit,
- bind = _EventInterface2.bind,
- destroyEvents = _EventInterface2.destroy;
- var Components = Splide.Components,
- root = Splide.root,
- options = Splide.options;
- var isNavigation = options.isNavigation,
- updateOnMove = options.updateOnMove;
- var resolve = Components.Direction.resolve;
- var isClone = slideIndex > -1;
- var container = child(slide, "." + CLASS_CONTAINER);
- /**
- * Called when the component is mounted.
- */
- function mount() {
- var _this2 = this;
- init();
- bind(slide, 'click keydown', function (e) {
- emit(e.type === 'click' ? EVENT_CLICK : EVENT_SLIDE_KEYDOWN, _this2, e);
- });
- on([EVENT_MOUNTED, EVENT_MOVED, EVENT_UPDATED, EVENT_RESIZED, EVENT_SCROLLED], update.bind(this));
- if (updateOnMove) {
- on(EVENT_MOVE, onMove);
- }
- }
- /**
- * If the `updateOnMove` option is `true`, called when the slider starts moving.
- *
- * @param next - A next index.
- * @param prev - A previous index.
- * @param dest - A destination index.
- */
- function onMove(next, prev, dest) {
- if (dest === index) {
- updateActivity.call(this, true);
- }
- update.call(this);
- }
- /**
- * Initializes the component.
- */
- function init() {
- if (!isClone) {
- slide.id = root.id + "-slide" + pad(index + 1);
- }
- if (isNavigation) {
- if (!isHTMLButtonElement(slide)) {
- setAttribute(slide, ROLE, 'button');
- }
- var idx = isClone ? slideIndex : index;
- var label = format(options.i18n.slideX, idx + 1);
- var controls = Splide.splides.map(function (splide) {
- return splide.root.id;
- }).join(' ');
- setAttribute(slide, ARIA_LABEL, label);
- setAttribute(slide, ARIA_CONTROLS, controls);
- }
- }
- /**
- * Destroys the component.
- */
- function destroy() {
- destroyEvents();
- removeClass(slide, STATUS_CLASSES);
- removeAttribute(slide, ALL_ATTRIBUTES);
- }
- /**
- * Updates attribute and classes of the slide.
- */
- function update() {
- if (Components.Controller) {
- var currIndex = Splide.index;
- updateActivity.call(this, isActive());
- updateVisibility.call(this, isVisible());
- toggleClass(slide, CLASS_PREV, index === currIndex - 1);
- toggleClass(slide, CLASS_NEXT, index === currIndex + 1);
- }
- }
- /**
- * Updates the status related with activity.
- *
- * @param active - Set `true` if the slide is active.
- */
- function updateActivity(active) {
- toggleClass(slide, CLASS_ACTIVE, active);
- if (active) {
- if (!hasClass(slide, CLASS_ACTIVE)) {
- isNavigation && setAttribute(slide, ARIA_CURRENT, true);
- emit(EVENT_ACTIVE, this);
- }
- } else {
- if (hasClass(slide, CLASS_ACTIVE)) {
- removeAttribute(slide, ARIA_CURRENT);
- emit(EVENT_INACTIVE, this);
- }
- }
- }
- /**
- * Updates the status related with visibility.
- *
- * @param visible - Set `true` if the slide is visible.
- */
- function updateVisibility(visible) {
- toggleClass(slide, CLASS_VISIBLE, visible);
- setAttribute(slide, ARIA_HIDDEN, !visible || null);
- setAttribute(slide, TAB_INDEX, visible && options.slideFocus ? 0 : null);
- if (visible) {
- if (!hasClass(slide, CLASS_VISIBLE)) {
- emit(EVENT_VISIBLE, this);
- }
- } else {
- if (hasClass(slide, CLASS_VISIBLE)) {
- emit(EVENT_HIDDEN, this);
- }
- }
- }
- /**
- * Adds a CSS rule to the slider or the container.
- *
- * @param prop - A property name.
- * @param value - A CSS value to add.
- * @param useContainer - Optional. Determines whether to apply the rule to the container or not.
- */
- function rule(prop, value, useContainer) {
- var selector = "#" + slide.id + (container && useContainer ? " > ." + CLASS_CONTAINER : '');
- Components.Style.rule(selector, prop, value);
- }
- /**
- * Checks if the slide is active or not.
- *
- * @return `true` if the slide is active.
- */
- function isActive() {
- return Splide.index === index;
- }
- /**
- * Checks if the slide is visible or not.
- */
- function isVisible() {
- if (Splide.is(FADE)) {
- return isActive();
- }
- var trackRect = rect(Components.Elements.track);
- var slideRect = rect(slide);
- var left = resolve('left');
- var right = resolve('right');
- return floor(trackRect[left]) <= slideRect[left] && slideRect[right] <= ceil(trackRect[right]);
- }
- /**
- * Calculates how far this slide is from another slide and
- * returns `true` if the distance is within the given number.
- *
- * @param from - An index of a base slide.
- * @param distance - `true` if the slide is within this number.
- *
- * @return `true` if the slide is within the `distance` from the base slide, or otherwise `false`.
- */
- function isWithin(from, distance) {
- var diff = abs(from - index);
- if (!Splide.is(SLIDE) && !isClone) {
- diff = min(diff, Splide.length - diff);
- }
- return diff <= distance;
- }
- return {
- index: index,
- slideIndex: slideIndex,
- slide: slide,
- container: container,
- isClone: isClone,
- mount: mount,
- destroy: destroy,
- rule: rule,
- isWithin: isWithin
- };
- }
- /**
- * The component for managing all slides include clones.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return An Slides component object.
- */
- function Slides(Splide, Components, options) {
- var _EventInterface3 = EventInterface(Splide),
- on = _EventInterface3.on,
- emit = _EventInterface3.emit,
- bind = _EventInterface3.bind;
- var _Components$Elements = Components.Elements,
- slides = _Components$Elements.slides,
- list = _Components$Elements.list;
- /**
- * Stores all SlideComponent objects.
- */
- var Slides = [];
- /**
- * Called when the component is mounted.
- */
- function mount() {
- init();
- on(EVENT_REFRESH, refresh);
- }
- /**
- * Initializes the component.
- */
- function init() {
- slides.forEach(function (slide, index) {
- register(slide, index, -1);
- });
- }
- /**
- * Destroys the component.
- */
- function destroy() {
- forEach$1(function (Slide) {
- Slide.destroy();
- });
- empty(Slides);
- }
- /**
- * Discards all Slide components and regenerates them.
- */
- function refresh() {
- destroy();
- init();
- }
- /**
- * Registers a slide element and creates a Slide object.
- *
- * @param slide - A slide element to register.
- * @param index - A slide index.
- * @param slideIndex - A slide index for clones. This must be `-1` for regular slides.
- */
- function register(slide, index, slideIndex) {
- var object = Slide$1(Splide, index, slideIndex, slide);
- object.mount();
- Slides.push(object);
- }
- /**
- * Returns all Slide objects.
- *
- * @param excludeClones - Optional. Determines whether to exclude clones or not.
- *
- * @return An array with Slide objects.
- */
- function get(excludeClones) {
- return excludeClones ? filter(function (Slide) {
- return !Slide.isClone;
- }) : Slides;
- }
- /**
- * Returns slides in the specified page.
- *
- * @param page - A page index.
- *
- * @return An array with slides that belong to the page.
- */
- function getIn(page) {
- var Controller = Components.Controller;
- var index = Controller.toIndex(page);
- var max = Controller.hasFocus() ? 1 : options.perPage;
- return filter(function (Slide) {
- return between(Slide.index, index, index + max - 1);
- });
- }
- /**
- * Returns a Slide object at the specified index.
- *
- * @param index - A slide index.
- *
- * @return A Slide object if available, or otherwise `undefined`.
- */
- function getAt(index) {
- return filter(index)[0];
- }
- /**
- * Inserts a slide or slides at a specified index.
- *
- * @param items - A slide element, an HTML string or an array with them.
- * @param index - Optional. An index to insert the slide at. If omitted, appends it to the list.
- */
- function add(items, index) {
- forEach(items, function (slide) {
- if (isString(slide)) {
- slide = parseHtml(slide);
- }
- if (isHTMLElement(slide)) {
- var ref = slides[index];
- ref ? before(slide, ref) : append(list, slide);
- addClass(slide, options.classes.slide);
- observeImages(slide, emit.bind(null, EVENT_RESIZE));
- }
- });
- emit(EVENT_REFRESH);
- }
- /**
- * Removes slides that match the matcher
- * that can be an index, an array with indices, a selector, or an iteratee function.
- *
- * @param matcher - An index, an array with indices, a selector string, or an iteratee function.
- */
- function remove$1(matcher) {
- remove(filter(matcher).map(function (Slide) {
- return Slide.slide;
- }));
- emit(EVENT_REFRESH);
- }
- /**
- * Iterates over Slide objects by the iteratee function.
- *
- * @param iteratee - An iteratee function that takes a Slide object, an index and an array with Slides.
- * @param excludeClones - Optional. Determines whether to exclude clones or not.
- */
- function forEach$1(iteratee, excludeClones) {
- get(excludeClones).forEach(iteratee);
- }
- /**
- * Filters Slides by the matcher
- * that can be an index, an array with indices, a selector, or an predicate function.
- *
- * @param matcher - An index, an array with indices, a selector string, or an predicate function.
- *
- * @return An array with SlideComponent objects.
- */
- function filter(matcher) {
- return Slides.filter(isFunction(matcher) ? matcher : function (Slide) {
- return isString(matcher) ? matches(Slide.slide, matcher) : includes(toArray(matcher), Slide.index);
- });
- }
- /**
- * Adds a CSS rule to all slides or containers.
- *
- * @param prop - A property name.
- * @param value - A CSS value to add.
- * @param useContainer - Optional. Determines whether to apply the rule to the container or not.
- */
- function rule(prop, value, useContainer) {
- forEach$1(function (Slide) {
- Slide.rule(prop, value, useContainer);
- });
- }
- /**
- * Invokes the callback after all images in the element are loaded.
- *
- * @param elm - An element that may contain images.
- * @param callback - A callback function.
- */
- function observeImages(elm, callback) {
- var images = queryAll(elm, 'img');
- var length = images.length;
- if (length) {
- images.forEach(function (img) {
- bind(img, 'load error', function () {
- if (! --length) {
- callback();
- }
- });
- });
- } else {
- callback();
- }
- }
- /**
- * Returns the length of slides.
- *
- * @param excludeClones - Optional. Determines whether to exclude clones or not.
- *
- * @return The length of slides.
- */
- function getLength(excludeClones) {
- return excludeClones ? slides.length : Slides.length;
- }
- /**
- * Checks if the number of slides is over than the `perPage` option, including clones.
- *
- * @return `true` if there are enough slides, or otherwise `false`.
- */
- function isEnough() {
- return Slides.length > options.perPage;
- }
- return {
- mount: mount,
- destroy: destroy,
- register: register,
- get: get,
- getIn: getIn,
- getAt: getAt,
- add: add,
- remove: remove$1,
- forEach: forEach$1,
- filter: filter,
- rule: rule,
- getLength: getLength,
- isEnough: isEnough
- };
- }
- /**
- * The component that generates clones for the loop slider.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Clones component object.
- */
- function Clones(Splide, Components, options) {
- var _EventInterface4 = EventInterface(Splide),
- on = _EventInterface4.on,
- emit = _EventInterface4.emit;
- var Elements = Components.Elements,
- Slides = Components.Slides;
- var resolve = Components.Direction.resolve;
- var clones = [];
- /**
- * Keeps the current number of clones.
- */
- var cloneCount;
- /**
- * The index used for generating IDs.
- */
- var cloneIndex;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- init();
- on(EVENT_REFRESH, refresh);
- on([EVENT_UPDATED, EVENT_RESIZE], observe);
- }
- /**
- * Removes all clones if available, and generates new clones.
- */
- function init() {
- if (cloneCount = computeCloneCount()) {
- generate(cloneCount);
- }
- }
- /**
- * Destroys clones.
- */
- function destroy() {
- remove(clones);
- empty(clones);
- }
- /**
- * Discards all clones and regenerates them.
- * Must do this before the Elements component collects slide elements.
- */
- function refresh() {
- destroy();
- init();
- }
- /**
- * Observes the required clone count and refreshes the slider if necessary.
- */
- function observe() {
- if (cloneCount !== computeCloneCount()) {
- emit(EVENT_REFRESH);
- }
- }
- /**
- * Generates the specified number of clones.
- *
- * @param count - The number of clones to generate for each side.
- */
- function generate(count) {
- var slides = Slides.get().slice();
- var length = slides.length;
- if (length) {
- cloneIndex = 0;
- while (slides.length < count) {
- push(slides, slides);
- }
- slides.slice(-count).concat(slides.slice(0, count)).forEach(function (Slide, index) {
- var isHead = index < count;
- var clone = cloneDeep(Slide.slide);
- isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
- push(clones, clone);
- Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
- });
- }
- }
- /**
- * Deeply clones the provided element with removing the ID attribute.
- *
- * @param elm - An element to clone.
- *
- * @return A cloned element.
- */
- function cloneDeep(elm) {
- var clone = elm.cloneNode(true);
- addClass(clone, options.classes.clone);
- clone.id = Splide.root.id + "-clone" + pad(++cloneIndex);
- return clone;
- }
- /**
- * Returns the number of elements to generate.
- * This always returns 0 if the slider type is not `'loop'`.
- *
- * @return The number of clones.
- */
- function computeCloneCount() {
- var clones = options.clones;
- if (!Splide.is(LOOP)) {
- clones = 0;
- } else if (!clones) {
- var fixedSize = options[resolve('fixedWidth')];
- var fixedCount = fixedSize && ceil(rect(Elements.track)[resolve('width')] / fixedSize);
- var baseCount = fixedCount || options[resolve('autoWidth')] && Splide.length || options.perPage;
- clones = baseCount * (options.drag ? (options.flickMaxPages || 1) + 1 : 2);
- }
- return clones;
- }
- return {
- mount: mount,
- destroy: destroy
- };
- }
- /**
- * The component that layouts slider components and provides methods for dimensions.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return An Layout component object.
- */
- function Layout(Splide, Components, options) {
- var _EventInterface5 = EventInterface(Splide),
- on = _EventInterface5.on,
- bind = _EventInterface5.bind,
- emit = _EventInterface5.emit;
- var Slides = Components.Slides;
- var ruleBy = Components.Style.ruleBy;
- var resolve = Components.Direction.resolve;
- var _Components$Elements2 = Components.Elements,
- root = _Components$Elements2.root,
- track = _Components$Elements2.track,
- list = _Components$Elements2.list;
- var getAt = Slides.getAt;
- var vertical = options.direction === TTB;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- init();
- bind(window, 'resize load', Throttle(emit.bind(this, EVENT_RESIZE)));
- on([EVENT_UPDATED, EVENT_REFRESH], init);
- on(EVENT_RESIZE, resize);
- }
- /**
- * Initializes the component on `mount` or `updated`.
- * Uses `max-width` for the root to prevent the slider from exceeding the parent element.
- */
- function init() {
- ruleBy(root, 'maxWidth', unit(options.width));
- ruleBy(track, resolve('paddingLeft'), cssPadding(false));
- ruleBy(track, resolve('paddingRight'), cssPadding(true));
- Slides.rule(resolve('marginRight'), unit(options.gap));
- Slides.rule('width', cssSlideWidth());
- setSlidesHeight();
- resize();
- }
- /**
- * Updates dimensions of some elements when the slider is resized.
- */
- function resize() {
- ruleBy(track, 'height', cssTrackHeight());
- options.heightRatio && setSlidesHeight();
- emit(EVENT_RESIZED);
- }
- /**
- * Updates the height of slides or their container elements if available.
- */
- function setSlidesHeight() {
- Slides.rule('height', cssSlideHeight(), true);
- }
- /**
- * Parses the padding option and returns the value for each side.
- * This method returns `paddingTop` or `paddingBottom` for the vertical slider.
- *
- * @param right - Determines whether to get `paddingRight/Bottom` or `paddingLeft/Top`.
- *
- * @return The padding value as a CSS string.
- */
- function cssPadding(right) {
- var padding = options.padding;
- var prop = resolve(right ? 'right' : 'left', true);
- return padding ? unit(padding[prop] || (isObject(padding) ? '0' : padding)) : '';
- }
- /**
- * Returns the height of the track element as a CSS string.
- *
- * @return The height of the track.
- */
- function cssTrackHeight() {
- var height = '';
- if (vertical) {
- height = cssHeight();
- assert(height, '"height" or "heightRatio" is missing.');
- var paddingTop = cssPadding(false);
- var paddingBottom = cssPadding(true);
- if (paddingTop || paddingBottom) {
- height = "calc(" + height;
- height += "" + (paddingTop ? " - " + paddingTop : '') + (paddingBottom ? " - " + paddingBottom : '') + ")";
- }
- }
- return height;
- }
- /**
- * Converts options related with height to a CSS string.
- *
- * @return The height as a CSS string if available, or otherwise an empty string.
- */
- function cssHeight() {
- return unit(options.height || rect(list).width * options.heightRatio);
- }
- /**
- * Returns the width of the slide as a CSS string.
- *
- * @return The width of the slide.
- */
- function cssSlideWidth() {
- return options.autoWidth ? '' : unit(options.fixedWidth) || (vertical ? '' : cssSlideSize());
- }
- /**
- * Returns the height of the slide as a CSS string.
- *
- * @return The height of the slide.
- */
- function cssSlideHeight() {
- return unit(options.fixedHeight) || (vertical ? options.autoHeight ? '' : cssSlideSize() : cssHeight());
- }
- /**
- * Returns the CSS string for slide width or height without gap.
- *
- * @return The CSS string for slide width or height.
- */
- function cssSlideSize() {
- var gap = unit(options.gap);
- return "calc((100%" + (gap && " + " + gap) + ")/" + (options.perPage || 1) + (gap && " - " + gap) + ")";
- }
- /**
- * Returns the list width for the horizontal slider, or the height for the vertical slider.
- *
- * @return The size of the track element in pixel.
- */
- function listSize() {
- return rect(list)[resolve('width')];
- }
- /**
- * Returns the slide width for the horizontal slider, or the height for the vertical slider.
- *
- * @param index - Optional. A slide index.
- * @param withoutGap - Optional. Determines whether to exclude the gap amount or not.
- *
- * @return The size of the specified slide element in pixel.
- */
- function slideSize(index, withoutGap) {
- var Slide = getAt(index || 0);
- return Slide ? rect(Slide.slide)[resolve('width')] + (withoutGap ? 0 : getGap()) : 0;
- }
- /**
- * Returns the total width or height of slides from 0 to the specified index.
- *
- * @param index - A slide index. If omitted, uses the last index.
- * @param withoutGap - Optional. Determines whether to exclude the last gap or not.
- *
- * @return The total width of slides in the horizontal slider, or the height in the vertical one.
- */
- function totalSize(index, withoutGap) {
- var Slide = getAt(index);
- if (Slide) {
- var right = rect(Slide.slide)[resolve('right')];
- var left = rect(list)[resolve('left')];
- return abs(right - left) + (withoutGap ? 0 : getGap());
- }
- return 0;
- }
- /**
- * Returns the slider size without clones.
- *
- * @return The slider size.
- */
- function sliderSize() {
- var firstSlide = getAt(0);
- var lastSlide = getAt(Slides.getLength(true) - 1);
- if (firstSlide && lastSlide) {
- return rect(lastSlide.slide)[resolve('right')] - rect(firstSlide.slide)[resolve('left')];
- }
- return 0;
- }
- /**
- * Returns the gap value.
- *
- *
- * @return The gap value in pixel.
- */
- function getGap() {
- var Slide = getAt(0);
- return Slide ? parseFloat(style(Slide.slide, resolve('marginRight'))) || 0 : 0;
- }
- /**
- * Returns the padding value.
- *
- * @param right - Determines whether to get `paddingRight/Bottom` or `paddingLeft/Top`.
- *
- * @return The padding value in pixel.
- */
- function getPadding(right) {
- return parseFloat(style(track, resolve("padding" + (right ? 'Right' : 'Left'), true))) || 0;
- }
- return {
- mount: mount,
- listSize: listSize,
- slideSize: slideSize,
- sliderSize: sliderSize,
- totalSize: totalSize,
- getPadding: getPadding
- };
- }
- /**
- * The component for moving the slider.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Move component object.
- */
- function Move(Splide, Components, options) {
- var _EventInterface6 = EventInterface(Splide),
- on = _EventInterface6.on,
- emit = _EventInterface6.emit;
- var _Components$Layout = Components.Layout,
- slideSize = _Components$Layout.slideSize,
- getPadding = _Components$Layout.getPadding,
- totalSize = _Components$Layout.totalSize,
- listSize = _Components$Layout.listSize,
- sliderSize = _Components$Layout.sliderSize;
- var _Components$Direction = Components.Direction,
- resolve = _Components$Direction.resolve,
- orient = _Components$Direction.orient;
- var _Components$Elements3 = Components.Elements,
- list = _Components$Elements3.list,
- track = _Components$Elements3.track;
- /**
- * Indicates whether the slider is just looping or not.
- */
- var looping;
- /**
- * Indicates whether the component can move the slider or not.
- */
- var waiting;
- /**
- * Keeps the current position.
- */
- var currPosition = 0;
- /**
- * Keeps the rate of position to the slider width.
- */
- var positionRate = 0;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- on([EVENT_RESIZE, EVENT_UPDATED, EVENT_REFRESH], reposition);
- }
- /**
- * Repositions the slider.
- */
- function reposition() {
- if (options.drag !== 'free') {
- jump(Splide.index);
- } else {
- if (!options[resolve('fixedWidth')] && !options[resolve('autoWidth')]) {
- translate(listSize() * positionRate);
- }
- if (isExceededMax(currPosition)) {
- translate(getLimit(true));
- }
- }
- }
- /**
- * Goes to the slide at the specified index with the Transition component.
- *
- * @param dest - A destination index to go to.
- * @param index - A slide index.
- * @param prev - A previous index.
- */
- function move(dest, index, prev) {
- if (!isBusy()) {
- var position = getPosition();
- looping = dest !== index;
- waiting = options.waitForTransition;
- Splide.state.set(MOVING);
- emit(EVENT_MOVE, index, prev, dest);
- Components.Transition.start(dest, function () {
- onMoved(dest, index, prev, position);
- });
- }
- }
- /**
- * Called after the transition ends.
- *
- * @param dest - A destination index to go to.
- * @param index - A slide index.
- * @param prev - A previous index.
- * @param oldPosition - An old position.
- */
- function onMoved(dest, index, prev, oldPosition) {
- if (looping) {
- jump(index);
- looping = false;
- }
- waiting = false;
- Splide.state.set(IDLE);
- emit(EVENT_MOVED, index, prev, dest);
- if (options.trimSpace === 'move' && dest !== prev && oldPosition === getPosition()) {
- Components.Controller.go(dest > prev ? '>' : '<');
- }
- }
- /**
- * Jumps to the slide at the specified index.
- *
- * @param index - An index to jump to.
- */
- function jump(index) {
- translate(toPosition(index, true));
- }
- /**
- * Moves the slider to the specified position.
- *
- * @param position - The destination.
- */
- function translate(position) {
- currPosition = loop(position);
- positionRate = currPosition / listSize();
- Components.Style.ruleBy(list, 'transform', "translate" + resolve('X') + "(" + currPosition + "px)");
- }
- /**
- * Loops the provided position if it exceeds limits.
- *
- * @param position - A position to loop.
- */
- function loop(position) {
- if (!looping && Splide.is(LOOP)) {
- var diff = position - currPosition;
- var exceededMin = isExceededMin(position);
- var exceededMax = isExceededMax(position);
- if (exceededMin && diff > 0 || exceededMax && diff < 0) {
- position += orient(sliderSize() * (exceededMin ? 1 : -1));
- }
- }
- return position;
- }
- /**
- * Cancels transition.
- */
- function cancel() {
- translate(getPosition());
- Components.Transition.cancel();
- }
- /**
- * Returns the closest index to the position.
- *
- * @param position - A position to convert.
- *
- * @return The closest index to the position.
- */
- function toIndex(position) {
- var Slides = Components.Slides.get();
- var index = 0;
- var minDistance = Infinity;
- for (var i = 0; i < Slides.length; i++) {
- var slideIndex = Slides[i].index;
- var distance = abs(toPosition(slideIndex) - position);
- if (distance < minDistance) {
- minDistance = distance;
- index = slideIndex;
- } else {
- break;
- }
- }
- return index;
- }
- /**
- * Converts the slide index to the position.
- *
- * @param index - An index to convert.
- * @param trimming - Optional. Whether to trim edge spaces or not.
- *
- * @return The position corresponding with the index.
- */
- function toPosition(index, trimming) {
- var position = orient(totalSize(index - 1) - offset(index));
- return trimming ? trim(position) : position;
- }
- /**
- * Returns the current position.
- *
- * @return The position of the list element.
- */
- function getPosition() {
- var left = resolve('left');
- return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
- }
- /**
- * Trims spaces on the edge of the slider.
- *
- * @param position - A position to trim.
- *
- * @return A trimmed position.
- */
- function trim(position) {
- if (options.trimSpace && Splide.is(SLIDE)) {
- position = clamp(position, 0, orient(sliderSize() - listSize()));
- }
- return position;
- }
- /**
- * Returns the offset amount.
- *
- * @param index - An index.
- */
- function offset(index) {
- var focus = options.focus;
- if (focus === 'center') {
- return (listSize() - slideSize(index, true)) / 2;
- }
- return (+focus || 0) * slideSize(index);
- }
- /**
- * Returns the limit number that the slider can move to.
- *
- * @param max - Determines whether to return the maximum or minimum limit.
- *
- * @return The border number.
- */
- function getLimit(max) {
- var trimming = !!options.trimSpace;
- return max ? toPosition(Components.Controller.getEnd(), trimming) : toPosition(0, trimming);
- }
- /**
- * Checks if the slider can move now or not.
- *
- * @return `true` if the slider can move, or otherwise `false`.
- */
- function isBusy() {
- return !!(looping || waiting);
- }
- /**
- * Checks if the provided position exceeds the minimum limit or not.
- *
- * @param position - A position to test.
- * @param offset - Optional. Offsets the limit in pixel.
- *
- * @return `true` if the position exceeds the limit, or otherwise `false`.
- */
- function isExceededMin(position, offset) {
- return orient(position) + (offset || 0) < orient(getLimit(false));
- }
- /**
- * Checks if the provided position exceeds the maximum limit or not.
- *
- * @param position - A position to test.
- * @param offset - Optional. Offsets the limit in pixel.
- *
- * @return `true` if the position exceeds the limit, or otherwise `false`.
- */
- function isExceededMax(position, offset) {
- return orient(position) + (offset || 0) > orient(getLimit(true));
- }
- /**
- * Checks if the slider position exceeds borders or not.
- *
- * @return `true` if the position is over borders, or otherwise `false`.
- */
- function isExceeded() {
- return isExceededMin(currPosition) || isExceededMax(currPosition);
- }
- return {
- mount: mount,
- move: move,
- jump: jump,
- translate: translate,
- cancel: cancel,
- toIndex: toIndex,
- toPosition: toPosition,
- getPosition: getPosition,
- getLimit: getLimit,
- isBusy: isBusy,
- isExceededMin: isExceededMin,
- isExceededMax: isExceededMax,
- isExceeded: isExceeded
- };
- }
- /**
- * The component for controlling the slider.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Controller component object.
- */
- function Controller(Splide, Components, options) {
- var _EventInterface7 = EventInterface(Splide),
- on = _EventInterface7.on;
- var Move = Components.Move;
- var _Components$Slides = Components.Slides,
- isEnough = _Components$Slides.isEnough,
- getLength = _Components$Slides.getLength;
- var isLoop = Splide.is(LOOP);
- /**
- * The current index.
- */
- var currIndex = options.start || 0;
- /**
- * The previous index.
- */
- var prevIndex = currIndex;
- /**
- * The latest number of slides.
- */
- var slideCount;
- /**
- * The latest `perMove` value.
- */
- var perMove;
- /**
- * The latest `perMove` value.
- */
- var perPage;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- init();
- Move.jump(currIndex);
- on([EVENT_UPDATED, EVENT_REFRESH], init);
- on(EVENT_SCROLLED, function () {
- setIndex(Move.toIndex(Move.getPosition()));
- }, 0);
- }
- /**
- * Initializes the component.
- */
- function init() {
- slideCount = getLength(true);
- perMove = options.perMove;
- perPage = options.perPage;
- }
- /**
- * Moves the slider by the control pattern.
- *
- * @todo
- *
- * @see `Splide#go()`
- *
- * @param control - A control pattern.
- * @param allowSameIndex - Optional. Determines whether to allow to go to the current index or not.
- */
- function go(control, allowSameIndex) {
- var dest = parse(control);
- var index = loop(dest);
- if (index > -1 && !Move.isBusy() && (allowSameIndex || index !== currIndex)) {
- setIndex(index);
- Move.move(dest, index, prevIndex);
- }
- }
- /**
- * Parses the control and returns a slide index.
- *
- * @param control - A control pattern to parse.
- */
- function parse(control) {
- var index = currIndex;
- if (isString(control)) {
- var _ref = control.match(/([+\-<>])(\d+)?/) || [],
- indicator = _ref[1],
- number = _ref[2];
- if (indicator === '+' || indicator === '-') {
- index = computeDestIndex(currIndex + +("" + indicator + (+number || 1)), currIndex, true);
- } else if (indicator === '>') {
- index = number ? toIndex(+number) : getNext(true);
- } else if (indicator === '<') {
- index = getPrev(true);
- }
- } else {
- if (isLoop) {
- index = clamp(control, -perPage, slideCount + perPage - 1);
- } else {
- index = clamp(control, 0, getEnd());
- }
- }
- return index;
- }
- /**
- * Returns a next destination index.
- *
- * @param destination - Optional. Determines whether to get a destination index or a slide one.
- *
- * @return A next index if available, or otherwise `-1`.
- */
- function getNext(destination) {
- return getAdjacent(false, destination);
- }
- /**
- * Returns a previous destination index.
- *
- * @param destination - Optional. Determines whether to get a destination index or a slide one.
- *
- * @return A previous index if available, or otherwise `-1`.
- */
- function getPrev(destination) {
- return getAdjacent(true, destination);
- }
- /**
- * Returns an adjacent destination index.
- *
- * @param prev - Determines whether to return a previous or next index.
- * @param destination - Optional. Determines whether to get a destination index or a slide one.
- *
- * @return An adjacent index if available, or otherwise `-1`.
- */
- function getAdjacent(prev, destination) {
- var dest = computeDestIndex(currIndex + getPerMove() * (prev ? -1 : 1), currIndex);
- return destination ? dest : loop(dest);
- }
- /**
- * Converts the desired destination index to the valid one.
- * - This may return clone indices if the editor is the loop mode,
- * or `-1` if there is no slide to go.
- * - There are still slides where the slider can go if borders are between `from` and `dest`.
- *
- * @param dest - The desired destination.
- * @param from - A base index.
- * @param incremental - Optional. Whether the control is incremental or not.
- *
- * @return A converted destination index, including clones.
- */
- function computeDestIndex(dest, from, incremental) {
- if (isEnough()) {
- var end = getEnd(); // Will overrun:
- if (dest < 0 || dest > end) {
- if (between(0, dest, from, true) || between(end, from, dest, true)) {
- dest = toIndex(toPage(dest));
- } else {
- if (isLoop) {
- dest = perMove ? dest : dest < 0 ? -(slideCount % perPage || perPage) : slideCount;
- } else if (options.rewind) {
- dest = dest < 0 ? end : 0;
- } else {
- dest = -1;
- }
- }
- } else {
- if (!isLoop && !incremental && dest !== from) {
- dest = toIndex(toPage(from) + (dest < from ? -1 : 1));
- }
- }
- } else {
- dest = -1;
- }
- return dest;
- }
- /**
- * Returns the end index where the slider can go.
- * For example, if the slider has 10 slides and the `perPage` option is 3,
- * the slider can go to the slide 8 (the index is 7).
- *
- * @return An end index.
- */
- function getEnd() {
- var end = slideCount - perPage;
- if (hasFocus() || isLoop && perMove) {
- end = slideCount - 1;
- }
- return max(end, 0);
- }
- /**
- * Loops the provided index only in the loop mode.
- *
- * @param index - An index to loop.
- *
- * @return A looped index.
- */
- function loop(index) {
- if (isLoop) {
- return isEnough() ? index % slideCount + (index < 0 ? slideCount : 0) : -1;
- }
- return index;
- }
- /**
- * Converts the page index to the slide index.
- *
- * @param page - A page index to convert.
- *
- * @return A slide index.
- */
- function toIndex(page) {
- return clamp(hasFocus() ? page : perPage * page, 0, getEnd());
- }
- /**
- * Converts the slide index to the page index.
- *
- * @param index - An index to convert.
- */
- function toPage(index) {
- if (!hasFocus()) {
- index = between(index, slideCount - perPage, slideCount - 1) ? slideCount - 1 : index;
- index = floor(index / perPage);
- }
- return index;
- }
- /**
- * Returns the number of slides to move for '>' and '<'.
- *
- * @return The number of slides to move.
- */
- function getPerMove() {
- return perMove || hasFocus() ? 1 : perPage;
- }
- /**
- * Sets a new index and retains old one.
- *
- * @param index - A new index to set.
- */
- function setIndex(index) {
- if (index !== currIndex) {
- prevIndex = currIndex;
- currIndex = index;
- }
- }
- /**
- * Returns the current/previous index slide index.
- *
- * @param prev - Optional. Whether to return previous index or not.
- */
- function getIndex(prev) {
- return prev ? prevIndex : currIndex;
- }
- /**
- * Verifies if the focus option is available or not.
- *
- * @return `true` if the slider has the focus option.
- */
- function hasFocus() {
- return !isUndefined(options.focus) || options.isNavigation;
- }
- return {
- mount: mount,
- go: go,
- getNext: getNext,
- getPrev: getPrev,
- getEnd: getEnd,
- setIndex: setIndex,
- getIndex: getIndex,
- toIndex: toIndex,
- toPage: toPage,
- hasFocus: hasFocus
- };
- }
- /**
- * The namespace for SVG elements.
- */
- var XML_NAME_SPACE = 'http://www.w3.org/2000/svg';
- /**
- * The arrow path.
- */
- var PATH = 'm15.5 0.932-4.3 4.38 14.5 14.6-14.5 14.5 4.3 4.4 14.6-14.6 4.4-4.3-4.4-4.4-14.6-14.6z';
- /**
- * SVG width and height.
- */
- var SIZE = 40;
- /**
- * The component for handling previous and next arrows.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return An Arrows component object.
- */
- function Arrows(Splide, Components, options) {
- var _EventInterface8 = EventInterface(Splide),
- on = _EventInterface8.on,
- bind = _EventInterface8.bind,
- emit = _EventInterface8.emit;
- var classes = options.classes,
- i18n = options.i18n;
- var Elements = Components.Elements,
- Controller = Components.Controller;
- var slider = Elements.slider,
- track = Elements.track;
- /**
- * The wrapper element.
- */
- var wrapper = Elements.arrows;
- /**
- * The previous arrow element.
- */
- var prev = Elements.prev;
- /**
- * The next arrow element.
- */
- var next = Elements.next;
- /**
- * Indicates whether the component creates arrows or retrieved from the DOM.
- */
- var created;
- /**
- * An object with previous and next arrows.
- */
- var arrows = {};
- /**
- * Called when the component is mounted.
- */
- function mount() {
- init();
- on(EVENT_UPDATED, init);
- }
- /**
- * Initializes the component.
- */
- function init() {
- if (options.arrows) {
- if (!prev || !next) {
- createArrows();
- }
- }
- if (prev && next) {
- if (!arrows.prev) {
- setAttribute(prev, ARIA_CONTROLS, track.id);
- setAttribute(next, ARIA_CONTROLS, track.id);
- arrows.prev = prev;
- arrows.next = next;
- listen();
- emit(EVENT_ARROWS_MOUNTED, prev, next);
- } else {
- display(wrapper, options.arrows === false ? 'none' : '');
- }
- }
- }
- /**
- * Destroys the component.
- */
- function destroy() {
- if (created) {
- remove(wrapper);
- } else {
- removeAttribute(prev, ALL_ATTRIBUTES);
- removeAttribute(next, ALL_ATTRIBUTES);
- }
- }
- /**
- * Listens to some events.
- */
- function listen() {
- var go = Controller.go;
- on([EVENT_MOUNTED, EVENT_MOVE, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
- bind(next, 'click', function () {
- go('>');
- });
- bind(prev, 'click', function () {
- go('<');
- });
- }
- /**
- * Create arrows and append them to the slider.
- */
- function createArrows() {
- var parent = options.arrows === 'slider' && slider ? slider : Splide.root;
- wrapper = create('div', classes.arrows);
- prev = createArrow(true);
- next = createArrow(false);
- created = true;
- append(wrapper, [prev, next]);
- before(wrapper, child(parent));
- }
- /**
- * Creates an arrow button.
- *
- * @param prev - Determines whether to create a previous or next arrow.
- *
- * @return A created button element.
- */
- function createArrow(prev) {
- var arrow = "<button class=\"" + classes.arrow + " " + (prev ? classes.prev : classes.next) + "\" type=\"button\">" + ("<svg xmlns=\"" + XML_NAME_SPACE + "\" viewBox=\"0 0 " + SIZE + " " + SIZE + "\" width=\"" + SIZE + "\" height=\"" + SIZE + "\">") + ("<path d=\"" + (options.arrowPath || PATH) + "\" />");
- return parseHtml(arrow);
- }
- /**
- * Updates status of arrows, such as `disabled` and `aria-label`.
- */
- function update() {
- var index = Splide.index;
- var prevIndex = Controller.getPrev();
- var nextIndex = Controller.getNext();
- var prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
- var nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
- prev.disabled = prevIndex < 0;
- next.disabled = nextIndex < 0;
- setAttribute(prev, ARIA_LABEL, prevLabel);
- setAttribute(next, ARIA_LABEL, nextLabel);
- emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
- }
- return {
- arrows: arrows,
- mount: mount,
- destroy: destroy
- };
- }
- /**
- * The component for auto playing sliders.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return An Autoplay component object.
- */
- function Autoplay(Splide, Components, options) {
- var _EventInterface9 = EventInterface(Splide),
- on = _EventInterface9.on,
- bind = _EventInterface9.bind,
- emit = _EventInterface9.emit;
- var _Components$Elements4 = Components.Elements,
- root = _Components$Elements4.root,
- track = _Components$Elements4.track,
- bar = _Components$Elements4.bar,
- playButton = _Components$Elements4.play,
- pauseButton = _Components$Elements4.pause;
- var interval = RequestInterval(options.interval, Splide.go.bind(Splide, '>'), update);
- var isPaused = interval.isPaused;
- /**
- * Indicates whether the slider is hovered or not.
- */
- var hovered;
- /**
- * Indicates whether one of slider elements has focus or not.
- */
- var focused;
- /**
- * Turns into `true` when autoplay is manually paused.
- */
- var paused;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- var autoplay = options.autoplay;
- if (autoplay) {
- initButton(true);
- initButton(false);
- listen();
- if (autoplay !== 'pause') {
- play();
- }
- }
- }
- /**
- * Initializes a play/pause button.
- *
- * @param forPause - Determines whether to initialize a pause or play button.
- */
- function initButton(forPause) {
- var button = forPause ? pauseButton : playButton;
- if (button) {
- if (!isHTMLButtonElement(button)) {
- setAttribute(button, ROLE, 'button');
- }
- setAttribute(button, ARIA_CONTROLS, track.id);
- setAttribute(button, ARIA_LABEL, options.i18n[forPause ? 'pause' : 'play']);
- bind(button, 'click', forPause ? pause : play);
- }
- }
- /**
- * Listens to some events.
- */
- function listen() {
- if (options.pauseOnHover) {
- bind(root, 'mouseenter mouseleave', function (e) {
- hovered = e.type === 'mouseenter';
- autoToggle();
- });
- }
- if (options.pauseOnFocus) {
- bind(root, 'focusin focusout', function (e) {
- focused = e.type === 'focusin';
- autoToggle();
- });
- }
- on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
- }
- /**
- * Starts autoplay and clears all flags.
- */
- function play() {
- if (isPaused() && Components.Slides.isEnough()) {
- interval.start(!options.resetProgress);
- focused = false;
- hovered = false;
- emit(EVENT_AUTOPLAY_PLAY);
- }
- }
- /**
- * Pauses autoplay.
- *
- * @param manual - If `true`, autoplay keeps paused until `play()` is explicitly called.
- */
- function pause(manual) {
- if (manual === void 0) {
- manual = true;
- }
- if (!isPaused()) {
- interval.pause();
- emit(EVENT_AUTOPLAY_PAUSE);
- }
- paused = manual;
- }
- /**
- * Toggles play/pause according to current flags.
- * If autoplay is manually paused, this will do nothing.
- */
- function autoToggle() {
- if (!paused) {
- if (!hovered && !focused) {
- play();
- } else {
- pause(false);
- }
- }
- }
- /**
- * Called on every animation frame when auto playing.
- *
- * @param rate - The progress rate between 0 to 1.
- */
- function update(rate) {
- emit(EVENT_AUTOPLAY_PLAYING, rate);
- if (bar) {
- style(bar, {
- width: rate * 100 + "%"
- });
- }
- }
- return {
- mount: mount,
- destroy: interval.cancel,
- play: play,
- pause: pause,
- isPaused: isPaused
- };
- }
- /**
- * The component for setting the image as the slide background.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Cover component object.
- */
- function Cover(Splide, Components, options) {
- var _EventInterface10 = EventInterface(Splide),
- on = _EventInterface10.on;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- if (options.cover) {
- on(EVENT_LAZYLOAD_LOADED, function (img, Slide) {
- toggle(true, img, Slide);
- });
- on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], apply.bind(null, true));
- }
- }
- /**
- * Destroys the component.
- */
- function destroy() {
- apply(false);
- }
- /**
- * Sets/removes the background image to/from all slides.
- *
- * @param cover - If `false`, removes the background image.
- */
- function apply(cover) {
- Components.Slides.forEach(function (Slide) {
- var img = child(Slide.container || Slide.slide, 'img');
- if (img && img.src) {
- toggle(cover, img, Slide);
- }
- });
- }
- /**
- * Sets/removes the background image to/from the parent element.
- *
- * @param cover - If `false`, removes the background image.
- * @param img - A target image element.
- * @param Slide - A SlideComponent object where the image belongs.
- */
- function toggle(cover, img, Slide) {
- Slide.rule('background', cover ? "center/cover no-repeat url(\"" + img.src + "\")" : '', true);
- display(img, cover ? 'none' : '');
- }
- return {
- mount: mount,
- destroy: destroy
- };
- }
- /**
- * Triggers the bounce effect when the diff becomes less than this value.
- *
- * @since 3.0.0
- */
- var BOUNCE_DIFF_THRESHOLD = 10;
- /**
- * The duration of the bounce effect.
- *
- * @since 3.0.0
- */
- var BOUNCE_DURATION = 600;
- /**
- * The friction factor.
- *
- * @since 3.0.0
- */
- var FRICTION_FACTOR = 0.6;
- /**
- * The velocity to calculate the scroll duration.
- *
- * @since 3.0.0
- */
- var BASE_VELOCITY = 1.2;
- /**
- * The minimum duration of scroll.
- *
- * @since 3.0.0
- */
- var MIN_DURATION = 800;
- /**
- * The component for scrolling the slider.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Scroll component object.
- */
- function Scroll(Splide, Components, options) {
- var _EventInterface11 = EventInterface(Splide),
- on = _EventInterface11.on,
- emit = _EventInterface11.emit;
- var Move = Components.Move;
- var getPosition = Move.getPosition,
- getLimit = Move.getLimit;
- /**
- * Retains the active RequestInterval object.
- */
- var interval;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- on(EVENT_MOVE, clear);
- on([EVENT_UPDATED, EVENT_REFRESH], cancel);
- }
- /**
- * Scrolls the slider to the provided destination.
- *
- * @param destination - The destination to scroll to.
- * @param duration - Optional. The scroll duration. If omitted, calculates it by the distance.
- * @param suppressConstraint - Optional. Whether to suppress constraint process when the slider exceeds bounds.
- */
- function scroll(destination, duration, suppressConstraint) {
- var start = getPosition();
- var friction = 1;
- duration = duration || computeDuration(abs(destination - start));
- clear();
- interval = RequestInterval(duration, onScrolled, function (rate) {
- var position = getPosition();
- var target = start + (destination - start) * easing(rate);
- var diff = (target - getPosition()) * friction;
- Move.translate(position + diff);
- if (Splide.is(SLIDE) && !suppressConstraint && Move.isExceeded()) {
- friction *= FRICTION_FACTOR;
- if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
- bounce(Move.isExceededMin(getPosition()));
- }
- }
- }, 1);
- emit(EVENT_SCROLL);
- interval.start();
- }
- /**
- * Triggers the bounce effect when the slider reaches bounds.
- *
- * @param backwards - The direction the slider is going towards.
- */
- function bounce(backwards) {
- scroll(getLimit(!backwards), BOUNCE_DURATION, true);
- }
- /**
- * Called when scroll ends or is canceled.
- */
- function onScrolled() {
- emit(EVENT_SCROLLED);
- }
- /**
- * Computes the scroll duration by the distance and the base velocity.
- *
- * @param distance - Distance in pixel.
- *
- * @return The duration for scroll.
- */
- function computeDuration(distance) {
- return max(distance / BASE_VELOCITY, MIN_DURATION);
- }
- /**
- * Clears the active interval.
- */
- function clear() {
- if (interval) {
- interval.cancel();
- }
- }
- /**
- * Cancels the active interval and emits the `scrolled` event.
- */
- function cancel() {
- if (interval && !interval.isPaused()) {
- clear();
- onScrolled();
- }
- }
- /**
- * The easing function.
- *
- * @param t - A value to ease.
- *
- * @return An eased value.
- */
- function easing(t) {
- var easingFunc = options.easingFunc;
- return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
- }
- return {
- mount: mount,
- destroy: clear,
- scroll: scroll,
- cancel: cancel
- };
- }
- /**
- * The power of the friction.
- *
- * @since 3.0.0
- */
- var FRICTION = 5;
- /**
- * If the user stops dragging for this duration with keeping the pointer down, updates the base coord and time.
- *
- * @since 3.0.0
- */
- var SAMPLING_INTERVAL = 50;
- /**
- * Start events for dragging.
- *
- * @since 3.0.0
- */
- var POINTER_DOWN_EVENTS = 'touchstart mousedown';
- /**
- * Update events for dragging.
- *
- * @since 3.0.0
- */
- var POINTER_MOVE_EVENTS = 'touchmove mousemove';
- /**
- * End events for dragging.
- *
- * @since 3.0.0
- */
- var POINTER_UP_EVENTS = 'touchend touchcancel mouseup mouseleave';
- /**
- * The component for dragging the slider.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Drag component object.
- */
- function Drag(Splide, Components, options) {
- var _EventInterface12 = EventInterface(Splide),
- emit = _EventInterface12.emit,
- bind = _EventInterface12.bind,
- unbind = _EventInterface12.unbind;
- var track = Components.Elements.track;
- var _Components$Direction2 = Components.Direction,
- resolve = _Components$Direction2.resolve,
- orient = _Components$Direction2.orient;
- var listSize = Components.Layout.listSize;
- var _Components$Controlle = Components.Controller,
- go = _Components$Controlle.go,
- getEnd = _Components$Controlle.getEnd;
- var Move = Components.Move,
- Scroll = Components.Scroll;
- var translate = Move.translate,
- toIndex = Move.toIndex,
- getPosition = Move.getPosition,
- isExceeded = Move.isExceeded;
- var isSlide = Splide.is(SLIDE);
- var isFade = Splide.is(FADE);
- var isFree = options.drag === 'free';
- /**
- * The coord where a pointer becomes active.
- */
- var startCoord;
- /**
- * Keeps the last time when the component detects dragging.
- */
- var lastTime;
- /**
- * The base slider position where the diff of coords is applied.
- */
- var basePosition;
- /**
- * The base coord to calculate the diff of coords.
- */
- var baseCoord;
- /**
- * The base time when the base position and the base coord are saved.
- */
- var baseTime;
- /**
- * Keeps the last TouchEvent/MouseEvent object.
- */
- var lastEvent;
- /**
- * Indicates whether the user is dragging the slider or not.
- */
- var moving;
- /**
- * Indicates whether the user drags the slider by the mouse or not.
- */
- var isMouse;
- var target;
- /**
- * Indicates whether the slider exceeds borders or not.
- */
- var exceeded;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- if (options.drag) {
- bind(track, POINTER_DOWN_EVENTS, onPointerDown);
- }
- }
- /**
- * Called when the user clicks or touches the slider.
- *
- * @param e - A TouchEvent or MouseEvent object
- */
- function onPointerDown(e) {
- isMouse = e.type === 'mousedown';
- target = isMouse ? window : track;
- if (!(isMouse && e.button)) {
- if (!Move.isBusy()) {
- bind(target, POINTER_MOVE_EVENTS, onPointerMove);
- bind(target, POINTER_UP_EVENTS, onPointerUp);
- Move.cancel();
- Scroll.cancel();
- startCoord = getCoord(e);
- } else {
- prevent(e);
- }
- }
- }
- /**
- * Called while the user moves the pointer on the slider.
- *
- * @param e - A TouchEvent or MouseEvent object
- */
- function onPointerMove(e) {
- if (e.cancelable) {
- var _min = options.dragMinThreshold || 15;
- if (isMouse || abs(getCoord(e) - startCoord) > _min) {
- moving = true;
- onDrag();
- }
- if (moving) {
- onDragging(e);
- prevent(e, true);
- }
- } else {
- onPointerUp(e);
- }
- }
- /**
- * Called when the user releases pointing devices.
- * Be aware that the TouchEvent object provided by the `touchend` does not contain `Touch` objects,
- * which means the last touch position is not available.
- *
- * @param e - A TouchEvent or MouseEvent object
- */
- function onPointerUp(e) {
- unbind(target, POINTER_MOVE_EVENTS + " " + POINTER_UP_EVENTS);
- moving = false;
- if (lastEvent) {
- onDragged(e);
- lastEvent = null;
- }
- }
- /**
- * Called when the user starts dragging the slider.
- */
- function onDrag() {
- bind(track, 'click', function (e) {
- unbind(track, 'click');
- prevent(e, true);
- }, {
- capture: true
- });
- emit(EVENT_DRAG);
- }
- /**
- * Called while the user is dragging the slider.
- *
- * @param e - A TouchEvent or MouseEvent object
- */
- function onDragging(e) {
- var timeStamp = e.timeStamp;
- var expired = !lastTime || timeStamp - lastTime > SAMPLING_INTERVAL;
- if (expired || isExceeded() !== exceeded) {
- basePosition = getPosition();
- baseCoord = getCoord(e);
- baseTime = timeStamp;
- }
- exceeded = isExceeded();
- lastTime = timeStamp;
- lastEvent = e;
- if (!isFade) {
- translate(basePosition + constrain(getCoord(e) - baseCoord));
- }
- emit(EVENT_DRAGGING);
- }
- /**
- * Called when the user finishes dragging.
- *
- * @param e - A TouchEvent or MouseEvent object
- */
- function onDragged(e) {
- var velocity = computeVelocity(e);
- if (isFade) {
- go(Splide.index + orient(sign(velocity)));
- } else {
- var destination = computeDestination(velocity);
- if (isFree) {
- Scroll.scroll(destination);
- } else {
- go(computeIndex(destination), true);
- }
- }
- lastTime = 0;
- emit(EVENT_DRAGGED);
- }
- /**
- * Computes the drag velocity.
- *
- * @param e - A TouchEvent or MouseEvent object
- *
- * @return The drag velocity.
- */
- function computeVelocity(e) {
- if (Splide.is(LOOP) || !isExceeded()) {
- var diffCoord = getCoord(lastEvent) - baseCoord;
- var diffTime = lastEvent.timeStamp - baseTime;
- var isFlick = e.timeStamp - lastTime < SAMPLING_INTERVAL;
- if (diffTime && isFlick) {
- return diffCoord / diffTime;
- }
- }
- return 0;
- }
- /**
- * Computes the destination by the velocity and the `flickPower` option.
- *
- * @param velocity - The drag velocity.
- *
- * @return The destination.
- */
- function computeDestination(velocity) {
- var flickPower = options.flickPower || 600;
- return getPosition() + sign(velocity) * min(abs(velocity) * flickPower, isFree ? Infinity : listSize() * (options.flickMaxPages || 1));
- }
- /**
- * Converts the destination to the slide index.
- *
- * @param destination - The target destination.
- *
- * @return The destination index.
- */
- function computeIndex(destination) {
- var dest = toIndex(destination);
- return isSlide ? clamp(dest, 0, getEnd()) : dest;
- }
- /**
- * Returns the `pageX` and `pageY` coordinates provided by the event.
- * Be aware that IE does not support both TouchEvent and MouseEvent constructors.
- *
- * @param e - A TouchEvent or MouseEvent object.
- *
- * @return A pageX or pageY coordinate.
- */
- function getCoord(e) {
- return (isMouse ? e : e.touches[0])[resolve('pageX')];
- }
- /**
- * Reduces the distance to move by the predefined friction.
- * This does nothing when the slider type is not `slide`, or the position is inside borders.
- *
- * @param diff - Diff to constrain.
- *
- * @return The constrained diff.
- */
- function constrain(diff) {
- return diff / (exceeded && isSlide ? FRICTION : 1);
- }
- return {
- mount: mount
- };
- }
- /**
- * The collection of arrow keys of IE.
- *
- * @since 3.0.0
- */
- var IE_ARROW_KEYS = ['Left', 'Right', 'Up', 'Down'];
- /**
- * The component for controlling the slider by keyboards.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Keyboard component object.
- */
- function Keyboard(Splide, Components, options) {
- var _EventInterface13 = EventInterface(Splide),
- on = _EventInterface13.on,
- bind = _EventInterface13.bind,
- unbind = _EventInterface13.unbind;
- var root = Components.Elements.root;
- var resolve = Components.Direction.resolve;
- /**
- * The target element of the keyboard event.
- */
- var target;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- init();
- on(EVENT_UPDATED, function () {
- destroy();
- init();
- });
- }
- /**
- * Initializes the component.
- */
- function init() {
- var _options$keyboard = options.keyboard,
- keyboard = _options$keyboard === void 0 ? 'global' : _options$keyboard;
- if (keyboard) {
- if (keyboard === 'focused') {
- target = root;
- setAttribute(root, TAB_INDEX, 0);
- } else {
- target = window;
- }
- bind(target, 'keydown', function (e) {
- var key = normalize(e.key);
- if (key === resolve('ArrowLeft')) {
- Splide.go('<');
- } else if (key === resolve('ArrowRight')) {
- Splide.go('>');
- }
- });
- }
- }
- /**
- * Destroys the component.
- */
- function destroy() {
- if (target) {
- unbind(target, 'keydown');
- if (isHTMLElement(target)) {
- removeAttribute(target, TAB_INDEX);
- }
- }
- }
- /**
- * Absorbs the difference of key names among browsers.
- *
- * @param key - A key to normalize.
- *
- * @return A normalized key.
- */
- function normalize(key) {
- return includes(IE_ARROW_KEYS, key) ? "Arrow" + key : key;
- }
- return {
- mount: mount,
- destroy: destroy
- };
- }
- /**
- * The data attribute for the src value.
- *
- * @since 3.0.0
- */
- var SRC_DATA_ATTRIBUTE = DATA_ATTRIBUTE + "-lazy";
- /**
- * The data attribute for the srcset value.
- *
- * @since 3.0.0
- */
- var SRCSET_DATA_ATTRIBUTE = SRC_DATA_ATTRIBUTE + "-srcset";
- /**
- * The selector string for images to load.
- *
- * @since 3.0.0
- */
- var IMAGE_SELECTOR = "[" + SRC_DATA_ATTRIBUTE + "], [" + SRCSET_DATA_ATTRIBUTE + "]";
- /**
- * The component for lazily loading images.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return An LazyLoad component object.
- */
- function LazyLoad(Splide, Components, options) {
- var _EventInterface14 = EventInterface(Splide),
- on = _EventInterface14.on,
- off = _EventInterface14.off,
- bind = _EventInterface14.bind,
- emit = _EventInterface14.emit;
- var isSequential = options.lazyLoad === 'sequential';
- /**
- * Stores data of images.
- */
- var images = [];
- /**
- * The current index of images.
- */
- var index = 0;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- if (options.lazyLoad) {
- on([EVENT_MOUNTED, EVENT_REFRESH], function () {
- destroy();
- init();
- });
- if (!isSequential) {
- on([EVENT_MOUNTED, EVENT_REFRESH, EVENT_MOVED], observe);
- }
- }
- }
- /**
- * Finds images that contain specific data attributes.
- */
- function init() {
- Components.Slides.forEach(function (Slide) {
- queryAll(Slide.slide, IMAGE_SELECTOR).forEach(function (img) {
- var src = getAttribute(img, SRC_DATA_ATTRIBUTE);
- var srcset = getAttribute(img, SRCSET_DATA_ATTRIBUTE);
- if (src !== img.src || srcset !== img.srcset) {
- var spinner = create('span', options.classes.spinner, img.parentElement);
- setAttribute(spinner, ROLE, 'presentation');
- images.push({
- img: img,
- Slide: Slide,
- src: src,
- srcset: srcset,
- spinner: spinner
- });
- display(img, 'none');
- }
- });
- });
- if (isSequential) {
- loadNext();
- }
- }
- /**
- * Destroys the component.
- */
- function destroy() {
- index = 0;
- images = [];
- }
- /**
- * Checks how close each image is from the active slide, and determines whether to start loading or not.
- * The last `+1` is for the current page.
- */
- function observe() {
- images = images.filter(function (data) {
- if (data.Slide.isWithin(Splide.index, options.perPage * ((options.preloadPages || 1) + 1))) {
- return load(data);
- }
- return true;
- });
- if (!images.length) {
- off(EVENT_MOVED);
- }
- }
- /**
- * Starts loading the image in the data.
- *
- * @param data - A LazyLoadImagesData object.
- */
- function load(data) {
- var img = data.img;
- addClass(data.Slide.slide, CLASS_LOADING);
- bind(img, 'load error', function (e) {
- onLoad(data, e.type === 'error');
- });
- ['src', 'srcset'].forEach(function (name) {
- if (data[name]) {
- setAttribute(img, name, data[name]);
- removeAttribute(img, name === 'src' ? SRC_DATA_ATTRIBUTE : SRCSET_DATA_ATTRIBUTE);
- }
- });
- }
- /**
- * Called when the image is loaded or any error occurs.
- *
- * @param data - A LazyLoadImagesData object.
- * @param error - `true` if this method is called on error.
- */
- function onLoad(data, error) {
- var Slide = data.Slide;
- removeClass(Slide.slide, CLASS_LOADING);
- if (!error) {
- remove(data.spinner);
- display(data.img, '');
- emit(EVENT_LAZYLOAD_LOADED, data.img, Slide);
- emit(EVENT_RESIZE);
- }
- if (isSequential) {
- loadNext();
- }
- }
- /**
- * Starts loading a next image.
- */
- function loadNext() {
- if (index < images.length) {
- load(images[index++]);
- }
- }
- return {
- mount: mount,
- destroy: destroy
- };
- }
- /**
- * The component for handling previous and next arrows.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Arrows component object.
- */
- function Pagination(Splide, Components, options) {
- var _EventInterface15 = EventInterface(Splide),
- on = _EventInterface15.on,
- emit = _EventInterface15.emit,
- bind = _EventInterface15.bind,
- unbind = _EventInterface15.unbind;
- var Slides = Components.Slides;
- var _Components$Controlle2 = Components.Controller,
- go = _Components$Controlle2.go,
- toPage = _Components$Controlle2.toPage,
- hasFocus = _Components$Controlle2.hasFocus,
- getIndex = _Components$Controlle2.getIndex;
- /**
- * Stores all pagination items.
- */
- var items = [];
- /**
- * The pagination element.
- */
- var list;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- init();
- on([EVENT_UPDATED, EVENT_REFRESH], init);
- on([EVENT_MOVE, EVENT_SCROLLED], update);
- }
- /**
- * Initializes the pagination.
- */
- function init() {
- destroy();
- if (options.pagination && Slides.isEnough()) {
- createPagination();
- emit(EVENT_PAGINATION_MOUNTED, {
- list: list,
- items: items
- }, getAt(Splide.index));
- update();
- }
- }
- /**
- * Destroys the component.
- */
- function destroy() {
- if (list) {
- remove(list);
- items.forEach(function (item) {
- unbind(item.button, 'click');
- });
- empty(items);
- list = null;
- }
- }
- /**
- * Creates the pagination element and appends it to the slider.
- */
- function createPagination() {
- var length = Splide.length;
- var classes = options.classes,
- i18n = options.i18n,
- perPage = options.perPage;
- var _Components$Elements5 = Components.Elements,
- slider = _Components$Elements5.slider,
- root = _Components$Elements5.root;
- var parent = options.pagination === 'slider' && slider ? slider : root;
- var max = hasFocus() ? length : ceil(length / perPage);
- list = create('ul', classes.pagination, parent);
- var _loop = function _loop(i) {
- var li = create('li', null, list);
- var button = create('button', {
- class: classes.page,
- type: 'button'
- }, li);
- var controls = Slides.getIn(i).map(function (Slide) {
- return Slide.slide.id;
- });
- var text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
- bind(button, 'click', function () {
- go(">" + i);
- });
- setAttribute(button, ARIA_CONTROLS, controls.join(' '));
- setAttribute(button, ARIA_LABEL, format(text, i + 1));
- emit(EVENT_PAGINATION_PAGE, list, li, button, i);
- items.push({
- li: li,
- button: button,
- page: i
- });
- };
- for (var i = 0; i < max; i++) {
- _loop(i);
- }
- }
- /**
- * Returns the pagination item at the specified index.
- *
- * @param index - An index.
- *
- * @return A pagination item object if available, or otherwise `undefined`.
- */
- function getAt(index) {
- return items[toPage(index)];
- }
- /**
- * Updates the pagination status.
- */
- function update() {
- var prev = getAt(getIndex(true));
- var curr = getAt(getIndex());
- if (prev) {
- removeClass(prev.button, CLASS_ACTIVE);
- removeAttribute(prev.button, ARIA_CURRENT);
- }
- if (curr) {
- addClass(curr.button, CLASS_ACTIVE);
- setAttribute(curr.button, ARIA_CURRENT, true);
- }
- emit(EVENT_PAGINATION_UPDATED, {
- list: list,
- items: items
- }, prev, curr);
- }
- return {
- items: items,
- mount: mount,
- destroy: destroy,
- getAt: getAt
- };
- }
- /**
- * The keys for triggering the navigation slide.
- *
- * @since 3.0.0
- */
- var TRIGGER_KEYS = [' ', 'Enter', 'Spacebar'];
- /**
- * The component for syncing multiple sliders.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Sync component object.
- */
- function Sync(Splide, Components, options) {
- var splides = Splide.splides;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- if (options.isNavigation) {
- navigate();
- } else {
- sync();
- }
- }
- /**
- * Syncs the current index among all slides.
- * The `processed` array prevents recursive call of handlers.
- */
- function sync() {
- var processed = [];
- splides.concat(Splide).forEach(function (splide, index, instances) {
- EventInterface(splide).on(EVENT_MOVE, function (index, prev, dest) {
- instances.forEach(function (instance) {
- if (instance !== splide && !includes(processed, splide)) {
- processed.push(instance);
- instance.go(instance.is(LOOP) ? dest : index);
- }
- });
- empty(processed);
- });
- });
- }
- /**
- * Makes slides clickable and moves the slider to the index of clicked slide.
- */
- function navigate() {
- var _EventInterface16 = EventInterface(Splide),
- on = _EventInterface16.on,
- emit = _EventInterface16.emit;
- on(EVENT_CLICK, function (Slide) {
- Splide.go(Slide.index);
- });
- on(EVENT_SLIDE_KEYDOWN, function (Slide, e) {
- if (includes(TRIGGER_KEYS, e.key)) {
- Splide.go(Slide.index);
- prevent(e);
- }
- });
- emit(EVENT_NAVIGATION_MOUNTED, Splide.splides);
- }
- return {
- mount: mount
- };
- }
- /**
- * The component for observing the mouse wheel and moving the slider.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Wheel component object.
- */
- function Wheel(Splide, Components, options) {
- var _EventInterface17 = EventInterface(Splide),
- bind = _EventInterface17.bind;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- if (options.wheel) {
- bind(Components.Elements.track, 'wheel', onWheel);
- }
- }
- /**
- * Called when the user rotates the mouse wheel.
- *
- * @param e - A WheelEvent object.
- */
- function onWheel(e) {
- var deltaY = e.deltaY;
- if (deltaY) {
- Splide.go(deltaY < 0 ? '<' : '>');
- prevent(e);
- }
- }
- return {
- mount: mount
- };
- }
- var ComponentConstructors = /*#__PURE__*/Object.freeze({
- __proto__: null,
- Options: Options,
- Direction: Direction,
- Elements: Elements,
- Style: Style,
- Slides: Slides,
- Clones: Clones,
- Layout: Layout,
- Move: Move,
- Controller: Controller,
- Arrows: Arrows,
- Autoplay: Autoplay,
- Cover: Cover,
- Scroll: Scroll,
- Drag: Drag,
- Keyboard: Keyboard,
- LazyLoad: LazyLoad,
- Pagination: Pagination,
- Sync: Sync,
- Wheel: Wheel
- });
- /**
- * The collection of i18n strings.
- *
- * @since 3.0.0
- */
- var I18N = {
- prev: 'Previous slide',
- next: 'Next slide',
- first: 'Go to first slide',
- last: 'Go to last slide',
- slideX: 'Go to slide %s',
- pageX: 'Go to page %s',
- play: 'Start autoplay',
- pause: 'Pause autoplay'
- };
- /**
- * The collection of default options.
- * Note that this collection does not contain all options.
- *
- * @since 3.0.0
- */
- var DEFAULTS = {
- type: 'slide',
- speed: 400,
- waitForTransition: true,
- perPage: 1,
- arrows: true,
- pagination: true,
- interval: 5000,
- pauseOnHover: true,
- pauseOnFocus: true,
- resetProgress: true,
- easing: 'cubic-bezier(.42,.65,.27,.99)',
- drag: true,
- direction: 'ltr',
- slideFocus: true,
- trimSpace: true,
- classes: CLASSES,
- i18n: I18N
- };
- /**
- * The component for the fade transition.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Transition component object.
- */
- function Fade(Splide, Components, options) {
- var _EventInterface18 = EventInterface(Splide),
- on = _EventInterface18.on;
- var ruleBy = Components.Style.ruleBy;
- /**
- * Called when the component is mounted.
- * The nextTick disables the initial fade transition of the first slide.
- */
- function mount() {
- on([EVENT_MOUNTED, EVENT_REFRESH], function () {
- nextTick(function () {
- Components.Slides.forEach(function (Slide) {
- ruleBy(Slide.slide, 'transition', "opacity " + options.speed + "ms " + options.easing);
- });
- });
- });
- }
- /**
- * Starts the transition.
- * Explicitly sets the track height to avoid it will collapse in Safari.
- *
- * @param index - A destination index.
- * @param done - The callback function that must be called after the transition ends.
- */
- function start(index, done) {
- var track = Components.Elements.track;
- ruleBy(track, 'height', unit(rect(track).height));
- nextTick(function () {
- done();
- ruleBy(track, 'height', '');
- });
- }
- return {
- mount: mount,
- start: start,
- cancel: noop
- };
- }
- /**
- * The component for the slide transition.
- *
- * @since 3.0.0
- *
- * @param Splide - A Splide instance.
- * @param Components - A collection of components.
- * @param options - Options.
- *
- * @return A Transition component object.
- */
- function Slide(Splide, Components, options) {
- var _EventInterface19 = EventInterface(Splide),
- bind = _EventInterface19.bind;
- var Move = Components.Move,
- Controller = Components.Controller;
- var list = Components.Elements.list;
- /**
- * Holds the `done` callback function.
- */
- var endCallback;
- /**
- * Called when the component is mounted.
- */
- function mount() {
- bind(list, 'transitionend', function (e) {
- if (e.target === list && endCallback) {
- cancel();
- endCallback();
- }
- });
- }
- /**
- * Starts the transition.
- * The Move component calls this method just before the slider moves.
- *
- * @param index - A destination index.
- * @param done - The callback function that must be called after the transition ends.
- */
- function start(index, done) {
- var destination = Move.toPosition(index, true);
- var position = Move.getPosition();
- var speed = getSpeed(index);
- if (abs(destination - position) >= 1 && speed >= 1) {
- apply("transform " + speed + "ms " + options.easing);
- Move.translate(destination);
- endCallback = done;
- } else {
- Move.jump(index);
- done();
- }
- }
- /**
- * Cancels the transition.
- */
- function cancel() {
- apply('');
- }
- /**
- * Returns the transition speed.
- *
- * @param index - A destination index.
- */
- function getSpeed(index) {
- var rewindSpeed = options.rewindSpeed;
- if (Splide.is(SLIDE) && rewindSpeed) {
- var prev = Controller.getIndex(true);
- var end = Controller.getEnd();
- if (prev === 0 && index >= end || prev >= end && index === 0) {
- return rewindSpeed;
- }
- }
- return options.speed;
- }
- /**
- * Applies the transition CSS property to the list element.
- *
- * @param transition - A transition CSS value.
- */
- function apply(transition) {
- Components.Style.ruleBy(list, 'transition', transition);
- }
- return {
- mount: mount,
- start: start,
- cancel: cancel
- };
- }
- /**
- * The frontend class for the Splide slider.
- *
- * @since 3.0.0
- */
- var Splide = /*#__PURE__*/function () {
- /**
- * The Splide constructor.
- *
- * @param target - The selector for the target element, or the element itself.
- * @param options - Optional. An object with options.
- */
- function Splide(target, options) {
- /**
- * The EventBusObject object.
- */
- this.event = EventBus();
- /**
- * The collection of all component objects.
- */
- this.Components = {};
- /**
- * The StateObject object.
- */
- this.state = State(CREATED);
- /**
- * Splide instances to sync with.
- */
- this.splides = [];
- /**
- * The collection of options.
- */
- this.opts = {};
- /**
- * The collection of extensions.
- */
- this.Extensions = {};
- var root = isString(target) ? query(document, target) : target;
- assert(root, root + " is invalid.");
- this.root = root;
- merge(DEFAULTS, Splide.defaults);
- merge(merge(this.opts, DEFAULTS), options || {});
- }
- /**
- * Initializes the instance.
- *
- * @param Extensions - Optional. An object with extensions.
- * @param Transition - Optional. A Transition component.
- *
- * @return `this`
- */
- var _proto = Splide.prototype;
- _proto.mount = function mount(Extensions, Transition) {
- var _this3 = this;
- this.state.set(CREATED);
- this.Transition = Transition || this.Transition || (this.is(FADE) ? Fade : Slide);
- this.Extensions = Extensions || this.Extensions;
- var Constructors = assign({}, ComponentConstructors, this.Extensions, {
- Transition: this.Transition
- });
- var Components = this.Components;
- forOwn(Constructors, function (Component, key) {
- var component = Component(_this3, _this3.Components, _this3.opts);
- Components[key] = component;
- component.setup && component.setup();
- });
- forOwn(Components, function (component) {
- component.mount && component.mount();
- });
- forOwn(Components, function (component) {
- component.mounted && component.mounted();
- });
- this.emit(EVENT_MOUNTED);
- addClass(this.root, CLASS_INITIALIZED);
- this.state.set(IDLE);
- this.emit(EVENT_READY);
- return this;
- }
- /**
- * Syncs the slider with the provided one.
- * This method must be called before the `mount()`.
- *
- * @example
- * ```ts
- * var primary = new Splide();
- * var secondary = new Splide();
- *
- * primary.sync( secondary );
- * primary.mount();
- * secondary.mount();
- * ```
- *
- * @param splide - A Splide instance to sync with.
- *
- * @return `this`
- */
- ;
- _proto.sync = function sync(splide) {
- this.splides.push(splide);
- splide.splides.push(this);
- return this;
- }
- /**
- * Moves the slider with the following control pattern.
- *
- * | Pattern | Description |
- * |---|---|
- * | `i` | Goes to the slide `i` |
- * | `'+${i}'` | Increments the slide index by `i` |
- * | `'-${i}'` | Decrements the slide index by `i` |
- * | `'>'` | Goes to the next page |
- * | `'<'` | Goes to the previous page |
- * | `>${i}` | Goes to the page `i` |
- *
- * In most cases, `'>'` and `'<'` notations are enough to control the slider
- * because they respect `perPage` and `perMove` options.
- *
- * @example
- * ```ts
- * var splide = new Splide();
- *
- * // Goes to the slide 1:
- * splide.go( 1 );
- *
- * // Increments the index:
- * splide.go( '+2' );
- *
- * // Goes to the next page:
- * splide.go( '>' );
- *
- * // Goes to the page 2:
- * splide.go( '>2' );
- * ```
- *
- * @param control
- */
- ;
- _proto.go = function go(control) {
- this.Components.Controller.go(control);
- }
- /**
- * Registers an event handler.
- *
- * @example
- * ```ts
- * var splide = new Splide();
- *
- * // Listens to a single event:
- * splide.on( 'move', function() {} );
- *
- * // Listens to multiple events:
- * splide.on( 'move resize', function() {} );
- *
- * // Appends a namespace:
- * splide.on( 'move.myNamespace resize.myNamespace', function() {} );
- * ```
- *
- * @param events - An event name or names separated by spaces. Use a dot(.) to append a namespace.
- * @param callback - A callback function.
- *
- * @return `this`
- */
- ;
- _proto.on = function on(events, callback) {
- this.event.on(events, callback);
- return this;
- }
- /**
- * Removes the registered all handlers for the specified event or events.
- * If you want to only remove a particular handler, use namespace to identify it.
- *
- * @example
- * ```ts
- * var splide = new Splide();
- *
- * // Removes all handlers assigned to "move":
- * splide.off( 'move' );
- *
- * // Only removes handlers that belong to the specified namespace:
- * splide.off( 'move.myNamespace' );
- * ```
- *
- * @param events - An event name or names separated by spaces. Use a dot(.) to append a namespace.
- *
- * @return `this`
- */
- ;
- _proto.off = function off(events) {
- this.event.off(events);
- return this;
- }
- /**
- * Emits an event and triggers registered handlers.
- *
- * @param event - An event name to emit.
- * @param args - Optional. Any number of arguments to pass to handlers.
- *
- * @return `this`
- */
- ;
- _proto.emit = function emit(event) {
- var _this$event;
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
- args[_key2 - 1] = arguments[_key2];
- }
- (_this$event = this.event).emit.apply(_this$event, [event].concat(args));
- return this;
- }
- /**
- * Inserts a slide at the specified position.
- *
- * @example
- * ```ts
- * var splide = new Splide();
- * splide.mount();
- *
- * // Adds the slide by the HTML:
- * splide.add( '<li></li> );
- *
- * // or adds the element:
- * splide.add( document.createElement( 'li' ) );
- * ```
- *
- * @param slides - A slide element, an HTML string that represents a slide, or an array with them.
- * @param index - Optional. An index to insert a slide at.
- *
- * @return `this`
- */
- ;
- _proto.add = function add(slides, index) {
- this.Components.Slides.add(slides, index);
- return this;
- }
- /**
- * Removes slides that match the matcher
- * that can be an index, an array with indices, a selector, or an iteratee function.
- *
- * @param matcher - An index, an array with indices, a selector string, or an iteratee function.
- */
- ;
- _proto.remove = function remove(matcher) {
- this.Components.Slides.remove(matcher);
- return this;
- }
- /**
- * Checks the slider type.
- *
- * @param type - A type to test.
- *
- * @return `true` if the type matches the current one, or otherwise `false`.
- */
- ;
- _proto.is = function is(type) {
- return this.opts.type === type;
- }
- /**
- * Refreshes the slider.
- *
- * @return `this`
- */
- ;
- _proto.refresh = function refresh() {
- this.emit(EVENT_REFRESH);
- return this;
- }
- /**
- * Destroys the slider.
- *
- * @param completely - Optional. If `true`, Splide will not remount the slider by breakpoints.
- *
- * @return `this`
- */
- ;
- _proto.destroy = function destroy(completely) {
- var event = this.event,
- state = this.state;
- if (state.is(CREATED)) {
- // Postpones destruction requested before the slider becomes ready.
- event.on(EVENT_READY, this.destroy.bind(this, completely), this);
- } else {
- forOwn(this.Components, function (component) {
- component.destroy && component.destroy(completely);
- });
- event.emit(EVENT_DESTROY);
- event.destroy();
- empty(this.splides);
- state.set(DESTROYED);
- }
- return this;
- }
- /**
- * Returns options.
- *
- * @return An object with the latest options.
- */
- ;
- _createClass(Splide, [{
- key: "options",
- get: function get() {
- return this.opts;
- }
- /**
- * Merges options to the current options and emits `updated` event.
- *
- * @param options - An object with new options.
- */
- ,
- set: function set(options) {
- var opts = this.opts;
- merge(opts, options);
- if (!this.state.is(CREATED)) {
- this.emit(EVENT_UPDATED, opts);
- }
- }
- /**
- * Returns the number of slides without clones.
- *
- * @return The number of slides.
- */
- }, {
- key: "length",
- get: function get() {
- return this.Components.Slides.getLength(true);
- }
- /**
- * Returns the active slide index.
- *
- * @return The active slide index.
- */
- }, {
- key: "index",
- get: function get() {
- return this.Components.Controller.getIndex();
- }
- }]);
- return Splide;
- }();
- /**
- * Changes the default options for all Splide instances.
- */
- Splide.defaults = {};
- /**
- * The collection of state numbers.
- */
- Splide.STATES = STATES;
- exports.CLASSES = CLASSES;
- exports.CLASS_ACTIVE = CLASS_ACTIVE;
- exports.CLASS_ARROW = CLASS_ARROW;
- exports.CLASS_ARROWS = CLASS_ARROWS;
- exports.CLASS_ARROW_NEXT = CLASS_ARROW_NEXT;
- exports.CLASS_ARROW_PREV = CLASS_ARROW_PREV;
- exports.CLASS_AUTOPLAY = CLASS_AUTOPLAY;
- exports.CLASS_CLONE = CLASS_CLONE;
- exports.CLASS_CONTAINER = CLASS_CONTAINER;
- exports.CLASS_INITIALIZED = CLASS_INITIALIZED;
- exports.CLASS_LIST = CLASS_LIST;
- exports.CLASS_LOADING = CLASS_LOADING;
- exports.CLASS_NEXT = CLASS_NEXT;
- exports.CLASS_PAGINATION = CLASS_PAGINATION;
- exports.CLASS_PAGINATION_PAGE = CLASS_PAGINATION_PAGE;
- exports.CLASS_PAUSE = CLASS_PAUSE;
- exports.CLASS_PLAY = CLASS_PLAY;
- exports.CLASS_PREV = CLASS_PREV;
- exports.CLASS_PROGRESS = CLASS_PROGRESS;
- exports.CLASS_PROGRESS_BAR = CLASS_PROGRESS_BAR;
- exports.CLASS_ROOT = CLASS_ROOT;
- exports.CLASS_SLIDE = CLASS_SLIDE;
- exports.CLASS_SLIDER = CLASS_SLIDER;
- exports.CLASS_SPINNER = CLASS_SPINNER;
- exports.CLASS_TRACK = CLASS_TRACK;
- exports.CLASS_VISIBLE = CLASS_VISIBLE;
- exports.EVENT_ACTIVE = EVENT_ACTIVE;
- exports.EVENT_ARROWS_MOUNTED = EVENT_ARROWS_MOUNTED;
- exports.EVENT_ARROWS_UPDATED = EVENT_ARROWS_UPDATED;
- exports.EVENT_AUTOPLAY_PAUSE = EVENT_AUTOPLAY_PAUSE;
- exports.EVENT_AUTOPLAY_PLAY = EVENT_AUTOPLAY_PLAY;
- exports.EVENT_AUTOPLAY_PLAYING = EVENT_AUTOPLAY_PLAYING;
- exports.EVENT_CLICK = EVENT_CLICK;
- exports.EVENT_DESTROY = EVENT_DESTROY;
- exports.EVENT_DRAG = EVENT_DRAG;
- exports.EVENT_DRAGGED = EVENT_DRAGGED;
- exports.EVENT_DRAGGING = EVENT_DRAGGING;
- exports.EVENT_HIDDEN = EVENT_HIDDEN;
- exports.EVENT_INACTIVE = EVENT_INACTIVE;
- exports.EVENT_LAZYLOAD_LOADED = EVENT_LAZYLOAD_LOADED;
- exports.EVENT_MOUNTED = EVENT_MOUNTED;
- exports.EVENT_MOVE = EVENT_MOVE;
- exports.EVENT_MOVED = EVENT_MOVED;
- exports.EVENT_NAVIGATION_MOUNTED = EVENT_NAVIGATION_MOUNTED;
- exports.EVENT_PAGINATION_MOUNTED = EVENT_PAGINATION_MOUNTED;
- exports.EVENT_PAGINATION_PAGE = EVENT_PAGINATION_PAGE;
- exports.EVENT_PAGINATION_UPDATED = EVENT_PAGINATION_UPDATED;
- exports.EVENT_READY = EVENT_READY;
- exports.EVENT_REFRESH = EVENT_REFRESH;
- exports.EVENT_RESIZE = EVENT_RESIZE;
- exports.EVENT_RESIZED = EVENT_RESIZED;
- exports.EVENT_SCROLL = EVENT_SCROLL;
- exports.EVENT_SCROLLED = EVENT_SCROLLED;
- exports.EVENT_SLIDE_KEYDOWN = EVENT_SLIDE_KEYDOWN;
- exports.EVENT_UPDATED = EVENT_UPDATED;
- exports.EVENT_VISIBLE = EVENT_VISIBLE;
- exports.EventBus = EventBus;
- exports.EventInterface = EventInterface;
- exports.RequestInterval = RequestInterval;
- exports.STATUS_CLASSES = STATUS_CLASSES;
- exports.Splide = Splide;
- exports.State = State;
- exports.Throttle = Throttle;
- exports['default'] = Splide;
|