interact.js 248 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609
  1. /**
  2. * interact.js 1.10.27
  3. *
  4. * Copyright (c) 2012-present Taye Adeyemi <dev@taye.me>
  5. * Released under the MIT License.
  6. * https://raw.github.com/taye/interact.js/main/LICENSE
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  10. typeof define === 'function' && define.amd ? define(factory) :
  11. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.interact = factory());
  12. })(this, (function () { 'use strict';
  13. function ownKeys(e, r) {
  14. var t = Object.keys(e);
  15. if (Object.getOwnPropertySymbols) {
  16. var o = Object.getOwnPropertySymbols(e);
  17. r && (o = o.filter(function (r) {
  18. return Object.getOwnPropertyDescriptor(e, r).enumerable;
  19. })), t.push.apply(t, o);
  20. }
  21. return t;
  22. }
  23. function _objectSpread2(e) {
  24. for (var r = 1; r < arguments.length; r++) {
  25. var t = null != arguments[r] ? arguments[r] : {};
  26. r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
  27. _defineProperty(e, r, t[r]);
  28. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
  29. Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
  30. });
  31. }
  32. return e;
  33. }
  34. function _typeof(o) {
  35. "@babel/helpers - typeof";
  36. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  37. return typeof o;
  38. } : function (o) {
  39. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  40. }, _typeof(o);
  41. }
  42. function _classCallCheck(instance, Constructor) {
  43. if (!(instance instanceof Constructor)) {
  44. throw new TypeError("Cannot call a class as a function");
  45. }
  46. }
  47. function _defineProperties(target, props) {
  48. for (var i = 0; i < props.length; i++) {
  49. var descriptor = props[i];
  50. descriptor.enumerable = descriptor.enumerable || false;
  51. descriptor.configurable = true;
  52. if ("value" in descriptor) descriptor.writable = true;
  53. Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
  54. }
  55. }
  56. function _createClass(Constructor, protoProps, staticProps) {
  57. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  58. if (staticProps) _defineProperties(Constructor, staticProps);
  59. Object.defineProperty(Constructor, "prototype", {
  60. writable: false
  61. });
  62. return Constructor;
  63. }
  64. function _defineProperty(obj, key, value) {
  65. key = _toPropertyKey(key);
  66. if (key in obj) {
  67. Object.defineProperty(obj, key, {
  68. value: value,
  69. enumerable: true,
  70. configurable: true,
  71. writable: true
  72. });
  73. } else {
  74. obj[key] = value;
  75. }
  76. return obj;
  77. }
  78. function _inherits(subClass, superClass) {
  79. if (typeof superClass !== "function" && superClass !== null) {
  80. throw new TypeError("Super expression must either be null or a function");
  81. }
  82. subClass.prototype = Object.create(superClass && superClass.prototype, {
  83. constructor: {
  84. value: subClass,
  85. writable: true,
  86. configurable: true
  87. }
  88. });
  89. Object.defineProperty(subClass, "prototype", {
  90. writable: false
  91. });
  92. if (superClass) _setPrototypeOf(subClass, superClass);
  93. }
  94. function _getPrototypeOf(o) {
  95. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
  96. return o.__proto__ || Object.getPrototypeOf(o);
  97. };
  98. return _getPrototypeOf(o);
  99. }
  100. function _setPrototypeOf(o, p) {
  101. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  102. o.__proto__ = p;
  103. return o;
  104. };
  105. return _setPrototypeOf(o, p);
  106. }
  107. function _isNativeReflectConstruct() {
  108. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  109. if (Reflect.construct.sham) return false;
  110. if (typeof Proxy === "function") return true;
  111. try {
  112. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  113. return true;
  114. } catch (e) {
  115. return false;
  116. }
  117. }
  118. function _assertThisInitialized(self) {
  119. if (self === void 0) {
  120. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  121. }
  122. return self;
  123. }
  124. function _possibleConstructorReturn(self, call) {
  125. if (call && (typeof call === "object" || typeof call === "function")) {
  126. return call;
  127. } else if (call !== void 0) {
  128. throw new TypeError("Derived constructors may only return object or undefined");
  129. }
  130. return _assertThisInitialized(self);
  131. }
  132. function _createSuper(Derived) {
  133. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  134. return function _createSuperInternal() {
  135. var Super = _getPrototypeOf(Derived),
  136. result;
  137. if (hasNativeReflectConstruct) {
  138. var NewTarget = _getPrototypeOf(this).constructor;
  139. result = Reflect.construct(Super, arguments, NewTarget);
  140. } else {
  141. result = Super.apply(this, arguments);
  142. }
  143. return _possibleConstructorReturn(this, result);
  144. };
  145. }
  146. function _superPropBase(object, property) {
  147. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  148. object = _getPrototypeOf(object);
  149. if (object === null) break;
  150. }
  151. return object;
  152. }
  153. function _get() {
  154. if (typeof Reflect !== "undefined" && Reflect.get) {
  155. _get = Reflect.get.bind();
  156. } else {
  157. _get = function _get(target, property, receiver) {
  158. var base = _superPropBase(target, property);
  159. if (!base) return;
  160. var desc = Object.getOwnPropertyDescriptor(base, property);
  161. if (desc.get) {
  162. return desc.get.call(arguments.length < 3 ? target : receiver);
  163. }
  164. return desc.value;
  165. };
  166. }
  167. return _get.apply(this, arguments);
  168. }
  169. function _toPrimitive(input, hint) {
  170. if (typeof input !== "object" || input === null) return input;
  171. var prim = input[Symbol.toPrimitive];
  172. if (prim !== undefined) {
  173. var res = prim.call(input, hint || "default");
  174. if (typeof res !== "object") return res;
  175. throw new TypeError("@@toPrimitive must return a primitive value.");
  176. }
  177. return (hint === "string" ? String : Number)(input);
  178. }
  179. function _toPropertyKey(arg) {
  180. var key = _toPrimitive(arg, "string");
  181. return typeof key === "symbol" ? key : String(key);
  182. }
  183. var isWindow = (function (thing) {
  184. return !!(thing && thing.Window) && thing instanceof thing.Window;
  185. });
  186. var realWindow = undefined;
  187. var win = undefined;
  188. function init$3(window) {
  189. // get wrapped window if using Shadow DOM polyfill
  190. realWindow = window;
  191. // create a TextNode
  192. var el = window.document.createTextNode('');
  193. // check if it's wrapped by a polyfill
  194. if (el.ownerDocument !== window.document && typeof window.wrap === 'function' && window.wrap(el) === el) {
  195. // use wrapped window
  196. window = window.wrap(window);
  197. }
  198. win = window;
  199. }
  200. if (typeof window !== 'undefined' && !!window) {
  201. init$3(window);
  202. }
  203. function getWindow(node) {
  204. if (isWindow(node)) {
  205. return node;
  206. }
  207. var rootNode = node.ownerDocument || node;
  208. return rootNode.defaultView || win.window;
  209. }
  210. var window$1 = function window(thing) {
  211. return thing === win || isWindow(thing);
  212. };
  213. var docFrag = function docFrag(thing) {
  214. return object(thing) && thing.nodeType === 11;
  215. };
  216. var object = function object(thing) {
  217. return !!thing && _typeof(thing) === 'object';
  218. };
  219. var func = function func(thing) {
  220. return typeof thing === 'function';
  221. };
  222. var number = function number(thing) {
  223. return typeof thing === 'number';
  224. };
  225. var bool = function bool(thing) {
  226. return typeof thing === 'boolean';
  227. };
  228. var string = function string(thing) {
  229. return typeof thing === 'string';
  230. };
  231. var element = function element(thing) {
  232. if (!thing || _typeof(thing) !== 'object') {
  233. return false;
  234. }
  235. var _window = getWindow(thing) || win;
  236. return /object|function/.test(typeof Element === "undefined" ? "undefined" : _typeof(Element)) ? thing instanceof Element || thing instanceof _window.Element : thing.nodeType === 1 && typeof thing.nodeName === 'string';
  237. };
  238. var plainObject = function plainObject(thing) {
  239. return object(thing) && !!thing.constructor && /function Object\b/.test(thing.constructor.toString());
  240. };
  241. var array = function array(thing) {
  242. return object(thing) && typeof thing.length !== 'undefined' && func(thing.splice);
  243. };
  244. var is = {
  245. window: window$1,
  246. docFrag: docFrag,
  247. object: object,
  248. func: func,
  249. number: number,
  250. bool: bool,
  251. string: string,
  252. element: element,
  253. plainObject: plainObject,
  254. array: array
  255. };
  256. function install$g(scope) {
  257. var actions = scope.actions,
  258. Interactable = scope.Interactable,
  259. defaults = scope.defaults;
  260. Interactable.prototype.draggable = drag.draggable;
  261. actions.map.drag = drag;
  262. actions.methodDict.drag = 'draggable';
  263. defaults.actions.drag = drag.defaults;
  264. }
  265. function beforeMove(_ref) {
  266. var interaction = _ref.interaction;
  267. if (interaction.prepared.name !== 'drag') return;
  268. var axis = interaction.prepared.axis;
  269. if (axis === 'x') {
  270. interaction.coords.cur.page.y = interaction.coords.start.page.y;
  271. interaction.coords.cur.client.y = interaction.coords.start.client.y;
  272. interaction.coords.velocity.client.y = 0;
  273. interaction.coords.velocity.page.y = 0;
  274. } else if (axis === 'y') {
  275. interaction.coords.cur.page.x = interaction.coords.start.page.x;
  276. interaction.coords.cur.client.x = interaction.coords.start.client.x;
  277. interaction.coords.velocity.client.x = 0;
  278. interaction.coords.velocity.page.x = 0;
  279. }
  280. }
  281. function move$1(_ref2) {
  282. var iEvent = _ref2.iEvent,
  283. interaction = _ref2.interaction;
  284. if (interaction.prepared.name !== 'drag') return;
  285. var axis = interaction.prepared.axis;
  286. if (axis === 'x' || axis === 'y') {
  287. var opposite = axis === 'x' ? 'y' : 'x';
  288. iEvent.page[opposite] = interaction.coords.start.page[opposite];
  289. iEvent.client[opposite] = interaction.coords.start.client[opposite];
  290. iEvent.delta[opposite] = 0;
  291. }
  292. }
  293. var draggable = function draggable(options) {
  294. if (is.object(options)) {
  295. this.options.drag.enabled = options.enabled !== false;
  296. this.setPerAction('drag', options);
  297. this.setOnEvents('drag', options);
  298. if (/^(xy|x|y|start)$/.test(options.lockAxis)) {
  299. this.options.drag.lockAxis = options.lockAxis;
  300. }
  301. if (/^(xy|x|y)$/.test(options.startAxis)) {
  302. this.options.drag.startAxis = options.startAxis;
  303. }
  304. return this;
  305. }
  306. if (is.bool(options)) {
  307. this.options.drag.enabled = options;
  308. return this;
  309. }
  310. return this.options.drag;
  311. };
  312. var drag = {
  313. id: 'actions/drag',
  314. install: install$g,
  315. listeners: {
  316. 'interactions:before-action-move': beforeMove,
  317. 'interactions:action-resume': beforeMove,
  318. // dragmove
  319. 'interactions:action-move': move$1,
  320. 'auto-start:check': function autoStartCheck(arg) {
  321. var interaction = arg.interaction,
  322. interactable = arg.interactable,
  323. buttons = arg.buttons;
  324. var dragOptions = interactable.options.drag;
  325. if (!(dragOptions && dragOptions.enabled) ||
  326. // check mouseButton setting if the pointer is down
  327. interaction.pointerIsDown && /mouse|pointer/.test(interaction.pointerType) && (buttons & interactable.options.drag.mouseButtons) === 0) {
  328. return undefined;
  329. }
  330. arg.action = {
  331. name: 'drag',
  332. axis: dragOptions.lockAxis === 'start' ? dragOptions.startAxis : dragOptions.lockAxis
  333. };
  334. return false;
  335. }
  336. },
  337. draggable: draggable,
  338. beforeMove: beforeMove,
  339. move: move$1,
  340. defaults: {
  341. startAxis: 'xy',
  342. lockAxis: 'xy'
  343. },
  344. getCursor: function getCursor() {
  345. return 'move';
  346. },
  347. filterEventType: function filterEventType(type) {
  348. return type.search('drag') === 0;
  349. }
  350. };
  351. var drag$1 = drag;
  352. var domObjects = {
  353. init: init$2,
  354. document: null,
  355. DocumentFragment: null,
  356. SVGElement: null,
  357. SVGSVGElement: null,
  358. SVGElementInstance: null,
  359. Element: null,
  360. HTMLElement: null,
  361. Event: null,
  362. Touch: null,
  363. PointerEvent: null
  364. };
  365. function blank() {}
  366. var domObjects$1 = domObjects;
  367. function init$2(window) {
  368. var win = window;
  369. domObjects.document = win.document;
  370. domObjects.DocumentFragment = win.DocumentFragment || blank;
  371. domObjects.SVGElement = win.SVGElement || blank;
  372. domObjects.SVGSVGElement = win.SVGSVGElement || blank;
  373. domObjects.SVGElementInstance = win.SVGElementInstance || blank;
  374. domObjects.Element = win.Element || blank;
  375. domObjects.HTMLElement = win.HTMLElement || domObjects.Element;
  376. domObjects.Event = win.Event;
  377. domObjects.Touch = win.Touch || blank;
  378. domObjects.PointerEvent = win.PointerEvent || win.MSPointerEvent;
  379. }
  380. var browser = {
  381. init: init$1,
  382. supportsTouch: null,
  383. supportsPointerEvent: null,
  384. isIOS7: null,
  385. isIOS: null,
  386. isIe9: null,
  387. isOperaMobile: null,
  388. prefixedMatchesSelector: null,
  389. pEventTypes: null,
  390. wheelEvent: null
  391. };
  392. function init$1(window) {
  393. var Element = domObjects$1.Element;
  394. var navigator = window.navigator || {};
  395. // Does the browser support touch input?
  396. browser.supportsTouch = 'ontouchstart' in window || is.func(window.DocumentTouch) && domObjects$1.document instanceof window.DocumentTouch;
  397. // Does the browser support PointerEvents
  398. // https://github.com/taye/interact.js/issues/703#issuecomment-471570492
  399. browser.supportsPointerEvent = navigator.pointerEnabled !== false && !!domObjects$1.PointerEvent;
  400. browser.isIOS = /iP(hone|od|ad)/.test(navigator.platform);
  401. // scrolling doesn't change the result of getClientRects on iOS 7
  402. browser.isIOS7 = /iP(hone|od|ad)/.test(navigator.platform) && /OS 7[^\d]/.test(navigator.appVersion);
  403. browser.isIe9 = /MSIE 9/.test(navigator.userAgent);
  404. // Opera Mobile must be handled differently
  405. browser.isOperaMobile = navigator.appName === 'Opera' && browser.supportsTouch && /Presto/.test(navigator.userAgent);
  406. // prefix matchesSelector
  407. browser.prefixedMatchesSelector = 'matches' in Element.prototype ? 'matches' : 'webkitMatchesSelector' in Element.prototype ? 'webkitMatchesSelector' : 'mozMatchesSelector' in Element.prototype ? 'mozMatchesSelector' : 'oMatchesSelector' in Element.prototype ? 'oMatchesSelector' : 'msMatchesSelector';
  408. browser.pEventTypes = browser.supportsPointerEvent ? domObjects$1.PointerEvent === window.MSPointerEvent ? {
  409. up: 'MSPointerUp',
  410. down: 'MSPointerDown',
  411. over: 'mouseover',
  412. out: 'mouseout',
  413. move: 'MSPointerMove',
  414. cancel: 'MSPointerCancel'
  415. } : {
  416. up: 'pointerup',
  417. down: 'pointerdown',
  418. over: 'pointerover',
  419. out: 'pointerout',
  420. move: 'pointermove',
  421. cancel: 'pointercancel'
  422. } : null;
  423. // because Webkit and Opera still use 'mousewheel' event type
  424. browser.wheelEvent = domObjects$1.document && 'onmousewheel' in domObjects$1.document ? 'mousewheel' : 'wheel';
  425. }
  426. var browser$1 = browser;
  427. function nodeContains(parent, child) {
  428. if (parent.contains) {
  429. return parent.contains(child);
  430. }
  431. while (child) {
  432. if (child === parent) {
  433. return true;
  434. }
  435. child = child.parentNode;
  436. }
  437. return false;
  438. }
  439. function closest(element, selector) {
  440. while (is.element(element)) {
  441. if (matchesSelector(element, selector)) {
  442. return element;
  443. }
  444. element = parentNode(element);
  445. }
  446. return null;
  447. }
  448. function parentNode(node) {
  449. var parent = node.parentNode;
  450. if (is.docFrag(parent)) {
  451. // skip past #shado-root fragments
  452. // tslint:disable-next-line
  453. while ((parent = parent.host) && is.docFrag(parent)) {
  454. continue;
  455. }
  456. return parent;
  457. }
  458. return parent;
  459. }
  460. function matchesSelector(element, selector) {
  461. // remove /deep/ from selectors if shadowDOM polyfill is used
  462. if (win !== realWindow) {
  463. selector = selector.replace(/\/deep\//g, ' ');
  464. }
  465. return element[browser$1.prefixedMatchesSelector](selector);
  466. }
  467. var getParent = function getParent(el) {
  468. return el.parentNode || el.host;
  469. };
  470. // Test for the element that's "above" all other qualifiers
  471. function indexOfDeepestElement(elements) {
  472. var deepestNodeParents = [];
  473. var deepestNodeIndex;
  474. for (var i = 0; i < elements.length; i++) {
  475. var currentNode = elements[i];
  476. var deepestNode = elements[deepestNodeIndex];
  477. // node may appear in elements array multiple times
  478. if (!currentNode || i === deepestNodeIndex) {
  479. continue;
  480. }
  481. if (!deepestNode) {
  482. deepestNodeIndex = i;
  483. continue;
  484. }
  485. var currentNodeParent = getParent(currentNode);
  486. var deepestNodeParent = getParent(deepestNode);
  487. // check if the deepest or current are document.documentElement/rootElement
  488. // - if the current node is, do nothing and continue
  489. if (currentNodeParent === currentNode.ownerDocument) {
  490. continue;
  491. }
  492. // - if deepest is, update with the current node and continue to next
  493. else if (deepestNodeParent === currentNode.ownerDocument) {
  494. deepestNodeIndex = i;
  495. continue;
  496. }
  497. // compare zIndex of siblings
  498. if (currentNodeParent === deepestNodeParent) {
  499. if (zIndexIsHigherThan(currentNode, deepestNode)) {
  500. deepestNodeIndex = i;
  501. }
  502. continue;
  503. }
  504. // populate the ancestry array for the latest deepest node
  505. deepestNodeParents = deepestNodeParents.length ? deepestNodeParents : getNodeParents(deepestNode);
  506. var ancestryStart = void 0;
  507. // if the deepest node is an HTMLElement and the current node is a non root svg element
  508. if (deepestNode instanceof domObjects$1.HTMLElement && currentNode instanceof domObjects$1.SVGElement && !(currentNode instanceof domObjects$1.SVGSVGElement)) {
  509. // TODO: is this check necessary? Was this for HTML elements embedded in SVG?
  510. if (currentNode === deepestNodeParent) {
  511. continue;
  512. }
  513. ancestryStart = currentNode.ownerSVGElement;
  514. } else {
  515. ancestryStart = currentNode;
  516. }
  517. var currentNodeParents = getNodeParents(ancestryStart, deepestNode.ownerDocument);
  518. var commonIndex = 0;
  519. // get (position of closest common ancestor) + 1
  520. while (currentNodeParents[commonIndex] && currentNodeParents[commonIndex] === deepestNodeParents[commonIndex]) {
  521. commonIndex++;
  522. }
  523. var parents = [currentNodeParents[commonIndex - 1], currentNodeParents[commonIndex], deepestNodeParents[commonIndex]];
  524. if (parents[0]) {
  525. var child = parents[0].lastChild;
  526. while (child) {
  527. if (child === parents[1]) {
  528. deepestNodeIndex = i;
  529. deepestNodeParents = currentNodeParents;
  530. break;
  531. } else if (child === parents[2]) {
  532. break;
  533. }
  534. child = child.previousSibling;
  535. }
  536. }
  537. }
  538. return deepestNodeIndex;
  539. }
  540. function getNodeParents(node, limit) {
  541. var parents = [];
  542. var parent = node;
  543. var parentParent;
  544. while ((parentParent = getParent(parent)) && parent !== limit && parentParent !== parent.ownerDocument) {
  545. parents.unshift(parent);
  546. parent = parentParent;
  547. }
  548. return parents;
  549. }
  550. function zIndexIsHigherThan(higherNode, lowerNode) {
  551. var higherIndex = parseInt(getWindow(higherNode).getComputedStyle(higherNode).zIndex, 10) || 0;
  552. var lowerIndex = parseInt(getWindow(lowerNode).getComputedStyle(lowerNode).zIndex, 10) || 0;
  553. return higherIndex >= lowerIndex;
  554. }
  555. function matchesUpTo(element, selector, limit) {
  556. while (is.element(element)) {
  557. if (matchesSelector(element, selector)) {
  558. return true;
  559. }
  560. element = parentNode(element);
  561. if (element === limit) {
  562. return matchesSelector(element, selector);
  563. }
  564. }
  565. return false;
  566. }
  567. function getActualElement(element) {
  568. return element.correspondingUseElement || element;
  569. }
  570. function getScrollXY(relevantWindow) {
  571. relevantWindow = relevantWindow || win;
  572. return {
  573. x: relevantWindow.scrollX || relevantWindow.document.documentElement.scrollLeft,
  574. y: relevantWindow.scrollY || relevantWindow.document.documentElement.scrollTop
  575. };
  576. }
  577. function getElementClientRect(element) {
  578. var clientRect = element instanceof domObjects$1.SVGElement ? element.getBoundingClientRect() : element.getClientRects()[0];
  579. return clientRect && {
  580. left: clientRect.left,
  581. right: clientRect.right,
  582. top: clientRect.top,
  583. bottom: clientRect.bottom,
  584. width: clientRect.width || clientRect.right - clientRect.left,
  585. height: clientRect.height || clientRect.bottom - clientRect.top
  586. };
  587. }
  588. function getElementRect(element) {
  589. var clientRect = getElementClientRect(element);
  590. if (!browser$1.isIOS7 && clientRect) {
  591. var scroll = getScrollXY(getWindow(element));
  592. clientRect.left += scroll.x;
  593. clientRect.right += scroll.x;
  594. clientRect.top += scroll.y;
  595. clientRect.bottom += scroll.y;
  596. }
  597. return clientRect;
  598. }
  599. function getPath(node) {
  600. var path = [];
  601. while (node) {
  602. path.push(node);
  603. node = parentNode(node);
  604. }
  605. return path;
  606. }
  607. function trySelector(value) {
  608. if (!is.string(value)) {
  609. return false;
  610. }
  611. // an exception will be raised if it is invalid
  612. domObjects$1.document.querySelector(value);
  613. return true;
  614. }
  615. function extend(dest, source) {
  616. for (var prop in source) {
  617. dest[prop] = source[prop];
  618. }
  619. var ret = dest;
  620. return ret;
  621. }
  622. function getStringOptionResult(value, target, element) {
  623. if (value === 'parent') {
  624. return parentNode(element);
  625. }
  626. if (value === 'self') {
  627. return target.getRect(element);
  628. }
  629. return closest(element, value);
  630. }
  631. function resolveRectLike(value, target, element, functionArgs) {
  632. var returnValue = value;
  633. if (is.string(returnValue)) {
  634. returnValue = getStringOptionResult(returnValue, target, element);
  635. } else if (is.func(returnValue)) {
  636. returnValue = returnValue.apply(void 0, functionArgs);
  637. }
  638. if (is.element(returnValue)) {
  639. returnValue = getElementRect(returnValue);
  640. }
  641. return returnValue;
  642. }
  643. function rectToXY(rect) {
  644. return rect && {
  645. x: 'x' in rect ? rect.x : rect.left,
  646. y: 'y' in rect ? rect.y : rect.top
  647. };
  648. }
  649. function xywhToTlbr(rect) {
  650. if (rect && !('left' in rect && 'top' in rect)) {
  651. rect = extend({}, rect);
  652. rect.left = rect.x || 0;
  653. rect.top = rect.y || 0;
  654. rect.right = rect.right || rect.left + rect.width;
  655. rect.bottom = rect.bottom || rect.top + rect.height;
  656. }
  657. return rect;
  658. }
  659. function tlbrToXywh(rect) {
  660. if (rect && !('x' in rect && 'y' in rect)) {
  661. rect = extend({}, rect);
  662. rect.x = rect.left || 0;
  663. rect.y = rect.top || 0;
  664. rect.width = rect.width || (rect.right || 0) - rect.x;
  665. rect.height = rect.height || (rect.bottom || 0) - rect.y;
  666. }
  667. return rect;
  668. }
  669. function addEdges(edges, rect, delta) {
  670. if (edges.left) {
  671. rect.left += delta.x;
  672. }
  673. if (edges.right) {
  674. rect.right += delta.x;
  675. }
  676. if (edges.top) {
  677. rect.top += delta.y;
  678. }
  679. if (edges.bottom) {
  680. rect.bottom += delta.y;
  681. }
  682. rect.width = rect.right - rect.left;
  683. rect.height = rect.bottom - rect.top;
  684. }
  685. function getOriginXY(target, element, actionName) {
  686. var actionOptions = actionName && target.options[actionName];
  687. var actionOrigin = actionOptions && actionOptions.origin;
  688. var origin = actionOrigin || target.options.origin;
  689. var originRect = resolveRectLike(origin, target, element, [target && element]);
  690. return rectToXY(originRect) || {
  691. x: 0,
  692. y: 0
  693. };
  694. }
  695. function normalize(type, listeners) {
  696. var filter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (_typeOrPrefix) {
  697. return true;
  698. };
  699. var result = arguments.length > 3 ? arguments[3] : undefined;
  700. result = result || {};
  701. if (is.string(type) && type.search(' ') !== -1) {
  702. type = split(type);
  703. }
  704. if (is.array(type)) {
  705. type.forEach(function (t) {
  706. return normalize(t, listeners, filter, result);
  707. });
  708. return result;
  709. }
  710. // before: type = [{ drag: () => {} }], listeners = undefined
  711. // after: type = '' , listeners = [{ drag: () => {} }]
  712. if (is.object(type)) {
  713. listeners = type;
  714. type = '';
  715. }
  716. if (is.func(listeners) && filter(type)) {
  717. result[type] = result[type] || [];
  718. result[type].push(listeners);
  719. } else if (is.array(listeners)) {
  720. for (var _i2 = 0, _listeners2 = listeners; _i2 < _listeners2.length; _i2++) {
  721. var l = _listeners2[_i2];
  722. normalize(type, l, filter, result);
  723. }
  724. } else if (is.object(listeners)) {
  725. for (var prefix in listeners) {
  726. var combinedTypes = split(prefix).map(function (p) {
  727. return "".concat(type).concat(p);
  728. });
  729. normalize(combinedTypes, listeners[prefix], filter, result);
  730. }
  731. }
  732. return result;
  733. }
  734. function split(type) {
  735. return type.trim().split(/ +/);
  736. }
  737. var hypot = (function (x, y) {
  738. return Math.sqrt(x * x + y * y);
  739. });
  740. var VENDOR_PREFIXES = ['webkit', 'moz'];
  741. function pointerExtend(dest, source) {
  742. dest.__set || (dest.__set = {});
  743. var _loop = function _loop(prop) {
  744. // skip deprecated prefixed properties
  745. if (VENDOR_PREFIXES.some(function (prefix) {
  746. return prop.indexOf(prefix) === 0;
  747. })) return 1; // continue
  748. if (typeof dest[prop] !== 'function' && prop !== '__set') {
  749. Object.defineProperty(dest, prop, {
  750. get: function get() {
  751. if (prop in dest.__set) return dest.__set[prop];
  752. return dest.__set[prop] = source[prop];
  753. },
  754. set: function set(value) {
  755. dest.__set[prop] = value;
  756. },
  757. configurable: true
  758. });
  759. }
  760. };
  761. for (var prop in source) {
  762. if (_loop(prop)) continue;
  763. }
  764. return dest;
  765. }
  766. function copyCoords(dest, src) {
  767. dest.page = dest.page || {};
  768. dest.page.x = src.page.x;
  769. dest.page.y = src.page.y;
  770. dest.client = dest.client || {};
  771. dest.client.x = src.client.x;
  772. dest.client.y = src.client.y;
  773. dest.timeStamp = src.timeStamp;
  774. }
  775. function setCoordDeltas(targetObj, prev, cur) {
  776. targetObj.page.x = cur.page.x - prev.page.x;
  777. targetObj.page.y = cur.page.y - prev.page.y;
  778. targetObj.client.x = cur.client.x - prev.client.x;
  779. targetObj.client.y = cur.client.y - prev.client.y;
  780. targetObj.timeStamp = cur.timeStamp - prev.timeStamp;
  781. }
  782. function setCoordVelocity(targetObj, delta) {
  783. var dt = Math.max(delta.timeStamp / 1000, 0.001);
  784. targetObj.page.x = delta.page.x / dt;
  785. targetObj.page.y = delta.page.y / dt;
  786. targetObj.client.x = delta.client.x / dt;
  787. targetObj.client.y = delta.client.y / dt;
  788. targetObj.timeStamp = dt;
  789. }
  790. function setZeroCoords(targetObj) {
  791. targetObj.page.x = 0;
  792. targetObj.page.y = 0;
  793. targetObj.client.x = 0;
  794. targetObj.client.y = 0;
  795. }
  796. function isNativePointer(pointer) {
  797. return pointer instanceof domObjects$1.Event || pointer instanceof domObjects$1.Touch;
  798. }
  799. // Get specified X/Y coords for mouse or event.touches[0]
  800. function getXY(type, pointer, xy) {
  801. xy = xy || {};
  802. type = type || 'page';
  803. xy.x = pointer[type + 'X'];
  804. xy.y = pointer[type + 'Y'];
  805. return xy;
  806. }
  807. function getPageXY(pointer, page) {
  808. page = page || {
  809. x: 0,
  810. y: 0
  811. };
  812. // Opera Mobile handles the viewport and scrolling oddly
  813. if (browser$1.isOperaMobile && isNativePointer(pointer)) {
  814. getXY('screen', pointer, page);
  815. page.x += window.scrollX;
  816. page.y += window.scrollY;
  817. } else {
  818. getXY('page', pointer, page);
  819. }
  820. return page;
  821. }
  822. function getClientXY(pointer, client) {
  823. client = client || {};
  824. if (browser$1.isOperaMobile && isNativePointer(pointer)) {
  825. // Opera Mobile handles the viewport and scrolling oddly
  826. getXY('screen', pointer, client);
  827. } else {
  828. getXY('client', pointer, client);
  829. }
  830. return client;
  831. }
  832. function getPointerId(pointer) {
  833. return is.number(pointer.pointerId) ? pointer.pointerId : pointer.identifier;
  834. }
  835. function setCoords(dest, pointers, timeStamp) {
  836. var pointer = pointers.length > 1 ? pointerAverage(pointers) : pointers[0];
  837. getPageXY(pointer, dest.page);
  838. getClientXY(pointer, dest.client);
  839. dest.timeStamp = timeStamp;
  840. }
  841. function getTouchPair(event) {
  842. var touches = [];
  843. // array of touches is supplied
  844. if (is.array(event)) {
  845. touches[0] = event[0];
  846. touches[1] = event[1];
  847. }
  848. // an event
  849. else {
  850. if (event.type === 'touchend') {
  851. if (event.touches.length === 1) {
  852. touches[0] = event.touches[0];
  853. touches[1] = event.changedTouches[0];
  854. } else if (event.touches.length === 0) {
  855. touches[0] = event.changedTouches[0];
  856. touches[1] = event.changedTouches[1];
  857. }
  858. } else {
  859. touches[0] = event.touches[0];
  860. touches[1] = event.touches[1];
  861. }
  862. }
  863. return touches;
  864. }
  865. function pointerAverage(pointers) {
  866. var average = {
  867. pageX: 0,
  868. pageY: 0,
  869. clientX: 0,
  870. clientY: 0,
  871. screenX: 0,
  872. screenY: 0
  873. };
  874. for (var _i2 = 0; _i2 < pointers.length; _i2++) {
  875. var pointer = pointers[_i2];
  876. for (var prop in average) {
  877. average[prop] += pointer[prop];
  878. }
  879. }
  880. for (var _prop in average) {
  881. average[_prop] /= pointers.length;
  882. }
  883. return average;
  884. }
  885. function touchBBox(event) {
  886. if (!event.length) {
  887. return null;
  888. }
  889. var touches = getTouchPair(event);
  890. var minX = Math.min(touches[0].pageX, touches[1].pageX);
  891. var minY = Math.min(touches[0].pageY, touches[1].pageY);
  892. var maxX = Math.max(touches[0].pageX, touches[1].pageX);
  893. var maxY = Math.max(touches[0].pageY, touches[1].pageY);
  894. return {
  895. x: minX,
  896. y: minY,
  897. left: minX,
  898. top: minY,
  899. right: maxX,
  900. bottom: maxY,
  901. width: maxX - minX,
  902. height: maxY - minY
  903. };
  904. }
  905. function touchDistance(event, deltaSource) {
  906. var sourceX = deltaSource + 'X';
  907. var sourceY = deltaSource + 'Y';
  908. var touches = getTouchPair(event);
  909. var dx = touches[0][sourceX] - touches[1][sourceX];
  910. var dy = touches[0][sourceY] - touches[1][sourceY];
  911. return hypot(dx, dy);
  912. }
  913. function touchAngle(event, deltaSource) {
  914. var sourceX = deltaSource + 'X';
  915. var sourceY = deltaSource + 'Y';
  916. var touches = getTouchPair(event);
  917. var dx = touches[1][sourceX] - touches[0][sourceX];
  918. var dy = touches[1][sourceY] - touches[0][sourceY];
  919. var angle = 180 * Math.atan2(dy, dx) / Math.PI;
  920. return angle;
  921. }
  922. function getPointerType(pointer) {
  923. return is.string(pointer.pointerType) ? pointer.pointerType : is.number(pointer.pointerType) ? [undefined, undefined, 'touch', 'pen', 'mouse'][pointer.pointerType] :
  924. // if the PointerEvent API isn't available, then the "pointer" must
  925. // be either a MouseEvent, TouchEvent, or Touch object
  926. /touch/.test(pointer.type || '') || pointer instanceof domObjects$1.Touch ? 'touch' : 'mouse';
  927. }
  928. // [ event.target, event.currentTarget ]
  929. function getEventTargets(event) {
  930. var path = is.func(event.composedPath) ? event.composedPath() : event.path;
  931. return [getActualElement(path ? path[0] : event.target), getActualElement(event.currentTarget)];
  932. }
  933. function newCoords() {
  934. return {
  935. page: {
  936. x: 0,
  937. y: 0
  938. },
  939. client: {
  940. x: 0,
  941. y: 0
  942. },
  943. timeStamp: 0
  944. };
  945. }
  946. function coordsToEvent(coords) {
  947. var event = {
  948. coords: coords,
  949. get page() {
  950. return this.coords.page;
  951. },
  952. get client() {
  953. return this.coords.client;
  954. },
  955. get timeStamp() {
  956. return this.coords.timeStamp;
  957. },
  958. get pageX() {
  959. return this.coords.page.x;
  960. },
  961. get pageY() {
  962. return this.coords.page.y;
  963. },
  964. get clientX() {
  965. return this.coords.client.x;
  966. },
  967. get clientY() {
  968. return this.coords.client.y;
  969. },
  970. get pointerId() {
  971. return this.coords.pointerId;
  972. },
  973. get target() {
  974. return this.coords.target;
  975. },
  976. get type() {
  977. return this.coords.type;
  978. },
  979. get pointerType() {
  980. return this.coords.pointerType;
  981. },
  982. get buttons() {
  983. return this.coords.buttons;
  984. },
  985. preventDefault: function preventDefault() {}
  986. };
  987. return event;
  988. }
  989. var BaseEvent = /*#__PURE__*/function () {
  990. function BaseEvent(interaction) {
  991. _classCallCheck(this, BaseEvent);
  992. /** @internal */
  993. this.immediatePropagationStopped = false;
  994. this.propagationStopped = false;
  995. this._interaction = interaction;
  996. }
  997. _createClass(BaseEvent, [{
  998. key: "preventDefault",
  999. value: function preventDefault() {}
  1000. /**
  1001. * Don't call any other listeners (even on the current target)
  1002. */
  1003. }, {
  1004. key: "stopPropagation",
  1005. value: function stopPropagation() {
  1006. this.propagationStopped = true;
  1007. }
  1008. /**
  1009. * Don't call listeners on the remaining targets
  1010. */
  1011. }, {
  1012. key: "stopImmediatePropagation",
  1013. value: function stopImmediatePropagation() {
  1014. this.immediatePropagationStopped = this.propagationStopped = true;
  1015. }
  1016. }]);
  1017. return BaseEvent;
  1018. }();
  1019. // defined outside of class definition to avoid assignment of undefined during
  1020. // construction
  1021. // getters and setters defined here to support typescript 3.6 and below which
  1022. // don't support getter and setters in .d.ts files
  1023. Object.defineProperty(BaseEvent.prototype, 'interaction', {
  1024. get: function get() {
  1025. return this._interaction._proxy;
  1026. },
  1027. set: function set() {}
  1028. });
  1029. var remove = function remove(array, target) {
  1030. return array.splice(array.indexOf(target), 1);
  1031. };
  1032. var merge = function merge(target, source) {
  1033. for (var _i2 = 0; _i2 < source.length; _i2++) {
  1034. var item = source[_i2];
  1035. target.push(item);
  1036. }
  1037. return target;
  1038. };
  1039. var from = function from(source) {
  1040. return merge([], source);
  1041. };
  1042. var findIndex = function findIndex(array, func) {
  1043. for (var i = 0; i < array.length; i++) {
  1044. if (func(array[i], i, array)) {
  1045. return i;
  1046. }
  1047. }
  1048. return -1;
  1049. };
  1050. var find = function find(array, func) {
  1051. return array[findIndex(array, func)];
  1052. };
  1053. var DropEvent = /*#__PURE__*/function (_BaseEvent) {
  1054. _inherits(DropEvent, _BaseEvent);
  1055. var _super = _createSuper(DropEvent);
  1056. /**
  1057. * Class of events fired on dropzones during drags with acceptable targets.
  1058. */
  1059. function DropEvent(dropState, dragEvent, type) {
  1060. var _this;
  1061. _classCallCheck(this, DropEvent);
  1062. _this = _super.call(this, dragEvent._interaction);
  1063. _this.dropzone = void 0;
  1064. _this.dragEvent = void 0;
  1065. _this.relatedTarget = void 0;
  1066. _this.draggable = void 0;
  1067. _this.propagationStopped = false;
  1068. _this.immediatePropagationStopped = false;
  1069. var _ref = type === 'dragleave' ? dropState.prev : dropState.cur,
  1070. element = _ref.element,
  1071. dropzone = _ref.dropzone;
  1072. _this.type = type;
  1073. _this.target = element;
  1074. _this.currentTarget = element;
  1075. _this.dropzone = dropzone;
  1076. _this.dragEvent = dragEvent;
  1077. _this.relatedTarget = dragEvent.target;
  1078. _this.draggable = dragEvent.interactable;
  1079. _this.timeStamp = dragEvent.timeStamp;
  1080. return _this;
  1081. }
  1082. /**
  1083. * If this is a `dropactivate` event, the dropzone element will be
  1084. * deactivated.
  1085. *
  1086. * If this is a `dragmove` or `dragenter`, a `dragleave` will be fired on the
  1087. * dropzone element and more.
  1088. */
  1089. _createClass(DropEvent, [{
  1090. key: "reject",
  1091. value: function reject() {
  1092. var _this2 = this;
  1093. var dropState = this._interaction.dropState;
  1094. if (this.type !== 'dropactivate' && (!this.dropzone || dropState.cur.dropzone !== this.dropzone || dropState.cur.element !== this.target)) {
  1095. return;
  1096. }
  1097. dropState.prev.dropzone = this.dropzone;
  1098. dropState.prev.element = this.target;
  1099. dropState.rejected = true;
  1100. dropState.events.enter = null;
  1101. this.stopImmediatePropagation();
  1102. if (this.type === 'dropactivate') {
  1103. var activeDrops = dropState.activeDrops;
  1104. var index = findIndex(activeDrops, function (_ref2) {
  1105. var dropzone = _ref2.dropzone,
  1106. element = _ref2.element;
  1107. return dropzone === _this2.dropzone && element === _this2.target;
  1108. });
  1109. dropState.activeDrops.splice(index, 1);
  1110. var deactivateEvent = new DropEvent(dropState, this.dragEvent, 'dropdeactivate');
  1111. deactivateEvent.dropzone = this.dropzone;
  1112. deactivateEvent.target = this.target;
  1113. this.dropzone.fire(deactivateEvent);
  1114. } else {
  1115. this.dropzone.fire(new DropEvent(dropState, this.dragEvent, 'dragleave'));
  1116. }
  1117. }
  1118. }, {
  1119. key: "preventDefault",
  1120. value: function preventDefault() {}
  1121. }, {
  1122. key: "stopPropagation",
  1123. value: function stopPropagation() {
  1124. this.propagationStopped = true;
  1125. }
  1126. }, {
  1127. key: "stopImmediatePropagation",
  1128. value: function stopImmediatePropagation() {
  1129. this.immediatePropagationStopped = this.propagationStopped = true;
  1130. }
  1131. }]);
  1132. return DropEvent;
  1133. }(BaseEvent);
  1134. function install$f(scope) {
  1135. var actions = scope.actions,
  1136. interact = scope.interactStatic,
  1137. Interactable = scope.Interactable,
  1138. defaults = scope.defaults;
  1139. scope.usePlugin(drag$1);
  1140. Interactable.prototype.dropzone = function (options) {
  1141. return dropzoneMethod(this, options);
  1142. };
  1143. Interactable.prototype.dropCheck = function (dragEvent, event, draggable, draggableElement, dropElement, rect) {
  1144. return dropCheckMethod(this, dragEvent, event, draggable, draggableElement, dropElement, rect);
  1145. };
  1146. interact.dynamicDrop = function (newValue) {
  1147. if (is.bool(newValue)) {
  1148. // if (dragging && scope.dynamicDrop !== newValue && !newValue) {
  1149. // calcRects(dropzones)
  1150. // }
  1151. scope.dynamicDrop = newValue;
  1152. return interact;
  1153. }
  1154. return scope.dynamicDrop;
  1155. };
  1156. extend(actions.phaselessTypes, {
  1157. dragenter: true,
  1158. dragleave: true,
  1159. dropactivate: true,
  1160. dropdeactivate: true,
  1161. dropmove: true,
  1162. drop: true
  1163. });
  1164. actions.methodDict.drop = 'dropzone';
  1165. scope.dynamicDrop = false;
  1166. defaults.actions.drop = drop.defaults;
  1167. }
  1168. function collectDropzones(_ref, draggableElement) {
  1169. var interactables = _ref.interactables;
  1170. var drops = [];
  1171. // collect all dropzones and their elements which qualify for a drop
  1172. for (var _i2 = 0, _interactables$list2 = interactables.list; _i2 < _interactables$list2.length; _i2++) {
  1173. var _dropzone = _interactables$list2[_i2];
  1174. if (!_dropzone.options.drop.enabled) {
  1175. continue;
  1176. }
  1177. var accept = _dropzone.options.drop.accept;
  1178. // test the draggable draggableElement against the dropzone's accept setting
  1179. if (is.element(accept) && accept !== draggableElement || is.string(accept) && !matchesSelector(draggableElement, accept) || is.func(accept) && !accept({
  1180. dropzone: _dropzone,
  1181. draggableElement: draggableElement
  1182. })) {
  1183. continue;
  1184. }
  1185. for (var _i4 = 0, _dropzone$getAllEleme2 = _dropzone.getAllElements(); _i4 < _dropzone$getAllEleme2.length; _i4++) {
  1186. var dropzoneElement = _dropzone$getAllEleme2[_i4];
  1187. if (dropzoneElement !== draggableElement) {
  1188. drops.push({
  1189. dropzone: _dropzone,
  1190. element: dropzoneElement,
  1191. rect: _dropzone.getRect(dropzoneElement)
  1192. });
  1193. }
  1194. }
  1195. }
  1196. return drops;
  1197. }
  1198. function fireActivationEvents(activeDrops, event) {
  1199. // loop through all active dropzones and trigger event
  1200. for (var _i6 = 0, _activeDrops$slice2 = activeDrops.slice(); _i6 < _activeDrops$slice2.length; _i6++) {
  1201. var _activeDrops$slice2$_ = _activeDrops$slice2[_i6],
  1202. _dropzone2 = _activeDrops$slice2$_.dropzone,
  1203. element = _activeDrops$slice2$_.element;
  1204. event.dropzone = _dropzone2;
  1205. // set current element as event target
  1206. event.target = element;
  1207. _dropzone2.fire(event);
  1208. event.propagationStopped = event.immediatePropagationStopped = false;
  1209. }
  1210. }
  1211. // return a new array of possible drops. getActiveDrops should always be
  1212. // called when a drag has just started or a drag event happens while
  1213. // dynamicDrop is true
  1214. function getActiveDrops(scope, dragElement) {
  1215. // get dropzones and their elements that could receive the draggable
  1216. var activeDrops = collectDropzones(scope, dragElement);
  1217. for (var _i8 = 0; _i8 < activeDrops.length; _i8++) {
  1218. var activeDrop = activeDrops[_i8];
  1219. activeDrop.rect = activeDrop.dropzone.getRect(activeDrop.element);
  1220. }
  1221. return activeDrops;
  1222. }
  1223. function getDrop(_ref2, dragEvent, pointerEvent) {
  1224. var dropState = _ref2.dropState,
  1225. draggable = _ref2.interactable,
  1226. dragElement = _ref2.element;
  1227. var validDrops = [];
  1228. // collect all dropzones and their elements which qualify for a drop
  1229. for (var _i10 = 0, _dropState$activeDrop2 = dropState.activeDrops; _i10 < _dropState$activeDrop2.length; _i10++) {
  1230. var _dropState$activeDrop3 = _dropState$activeDrop2[_i10],
  1231. _dropzone3 = _dropState$activeDrop3.dropzone,
  1232. dropzoneElement = _dropState$activeDrop3.element,
  1233. _rect = _dropState$activeDrop3.rect;
  1234. var isValid = _dropzone3.dropCheck(dragEvent, pointerEvent, draggable, dragElement, dropzoneElement, _rect);
  1235. validDrops.push(isValid ? dropzoneElement : null);
  1236. } // get the most appropriate dropzone based on DOM depth and order
  1237. var dropIndex = indexOfDeepestElement(validDrops);
  1238. return dropState.activeDrops[dropIndex] || null;
  1239. }
  1240. function getDropEvents(interaction, _pointerEvent, dragEvent) {
  1241. var dropState = interaction.dropState;
  1242. var dropEvents = {
  1243. enter: null,
  1244. leave: null,
  1245. activate: null,
  1246. deactivate: null,
  1247. move: null,
  1248. drop: null
  1249. };
  1250. if (dragEvent.type === 'dragstart') {
  1251. dropEvents.activate = new DropEvent(dropState, dragEvent, 'dropactivate');
  1252. dropEvents.activate.target = null;
  1253. dropEvents.activate.dropzone = null;
  1254. }
  1255. if (dragEvent.type === 'dragend') {
  1256. dropEvents.deactivate = new DropEvent(dropState, dragEvent, 'dropdeactivate');
  1257. dropEvents.deactivate.target = null;
  1258. dropEvents.deactivate.dropzone = null;
  1259. }
  1260. if (dropState.rejected) {
  1261. return dropEvents;
  1262. }
  1263. if (dropState.cur.element !== dropState.prev.element) {
  1264. // if there was a previous dropzone, create a dragleave event
  1265. if (dropState.prev.dropzone) {
  1266. dropEvents.leave = new DropEvent(dropState, dragEvent, 'dragleave');
  1267. dragEvent.dragLeave = dropEvents.leave.target = dropState.prev.element;
  1268. dragEvent.prevDropzone = dropEvents.leave.dropzone = dropState.prev.dropzone;
  1269. }
  1270. // if dropzone is not null, create a dragenter event
  1271. if (dropState.cur.dropzone) {
  1272. dropEvents.enter = new DropEvent(dropState, dragEvent, 'dragenter');
  1273. dragEvent.dragEnter = dropState.cur.element;
  1274. dragEvent.dropzone = dropState.cur.dropzone;
  1275. }
  1276. }
  1277. if (dragEvent.type === 'dragend' && dropState.cur.dropzone) {
  1278. dropEvents.drop = new DropEvent(dropState, dragEvent, 'drop');
  1279. dragEvent.dropzone = dropState.cur.dropzone;
  1280. dragEvent.relatedTarget = dropState.cur.element;
  1281. }
  1282. if (dragEvent.type === 'dragmove' && dropState.cur.dropzone) {
  1283. dropEvents.move = new DropEvent(dropState, dragEvent, 'dropmove');
  1284. dragEvent.dropzone = dropState.cur.dropzone;
  1285. }
  1286. return dropEvents;
  1287. }
  1288. function fireDropEvents(interaction, events) {
  1289. var dropState = interaction.dropState;
  1290. var activeDrops = dropState.activeDrops,
  1291. cur = dropState.cur,
  1292. prev = dropState.prev;
  1293. if (events.leave) {
  1294. prev.dropzone.fire(events.leave);
  1295. }
  1296. if (events.enter) {
  1297. cur.dropzone.fire(events.enter);
  1298. }
  1299. if (events.move) {
  1300. cur.dropzone.fire(events.move);
  1301. }
  1302. if (events.drop) {
  1303. cur.dropzone.fire(events.drop);
  1304. }
  1305. if (events.deactivate) {
  1306. fireActivationEvents(activeDrops, events.deactivate);
  1307. }
  1308. dropState.prev.dropzone = cur.dropzone;
  1309. dropState.prev.element = cur.element;
  1310. }
  1311. function onEventCreated(_ref3, scope) {
  1312. var interaction = _ref3.interaction,
  1313. iEvent = _ref3.iEvent,
  1314. event = _ref3.event;
  1315. if (iEvent.type !== 'dragmove' && iEvent.type !== 'dragend') {
  1316. return;
  1317. }
  1318. var dropState = interaction.dropState;
  1319. if (scope.dynamicDrop) {
  1320. dropState.activeDrops = getActiveDrops(scope, interaction.element);
  1321. }
  1322. var dragEvent = iEvent;
  1323. var dropResult = getDrop(interaction, dragEvent, event);
  1324. // update rejected status
  1325. dropState.rejected = dropState.rejected && !!dropResult && dropResult.dropzone === dropState.cur.dropzone && dropResult.element === dropState.cur.element;
  1326. dropState.cur.dropzone = dropResult && dropResult.dropzone;
  1327. dropState.cur.element = dropResult && dropResult.element;
  1328. dropState.events = getDropEvents(interaction, event, dragEvent);
  1329. }
  1330. function dropzoneMethod(interactable, options) {
  1331. if (is.object(options)) {
  1332. interactable.options.drop.enabled = options.enabled !== false;
  1333. if (options.listeners) {
  1334. var normalized = normalize(options.listeners);
  1335. // rename 'drop' to '' as it will be prefixed with 'drop'
  1336. var corrected = Object.keys(normalized).reduce(function (acc, type) {
  1337. var correctedType = /^(enter|leave)/.test(type) ? "drag".concat(type) : /^(activate|deactivate|move)/.test(type) ? "drop".concat(type) : type;
  1338. acc[correctedType] = normalized[type];
  1339. return acc;
  1340. }, {});
  1341. var prevListeners = interactable.options.drop.listeners;
  1342. prevListeners && interactable.off(prevListeners);
  1343. interactable.on(corrected);
  1344. interactable.options.drop.listeners = corrected;
  1345. }
  1346. if (is.func(options.ondrop)) {
  1347. interactable.on('drop', options.ondrop);
  1348. }
  1349. if (is.func(options.ondropactivate)) {
  1350. interactable.on('dropactivate', options.ondropactivate);
  1351. }
  1352. if (is.func(options.ondropdeactivate)) {
  1353. interactable.on('dropdeactivate', options.ondropdeactivate);
  1354. }
  1355. if (is.func(options.ondragenter)) {
  1356. interactable.on('dragenter', options.ondragenter);
  1357. }
  1358. if (is.func(options.ondragleave)) {
  1359. interactable.on('dragleave', options.ondragleave);
  1360. }
  1361. if (is.func(options.ondropmove)) {
  1362. interactable.on('dropmove', options.ondropmove);
  1363. }
  1364. if (/^(pointer|center)$/.test(options.overlap)) {
  1365. interactable.options.drop.overlap = options.overlap;
  1366. } else if (is.number(options.overlap)) {
  1367. interactable.options.drop.overlap = Math.max(Math.min(1, options.overlap), 0);
  1368. }
  1369. if ('accept' in options) {
  1370. interactable.options.drop.accept = options.accept;
  1371. }
  1372. if ('checker' in options) {
  1373. interactable.options.drop.checker = options.checker;
  1374. }
  1375. return interactable;
  1376. }
  1377. if (is.bool(options)) {
  1378. interactable.options.drop.enabled = options;
  1379. return interactable;
  1380. }
  1381. return interactable.options.drop;
  1382. }
  1383. function dropCheckMethod(interactable, dragEvent, event, draggable, draggableElement, dropElement, rect) {
  1384. var dropped = false;
  1385. // if the dropzone has no rect (eg. display: none)
  1386. // call the custom dropChecker or just return false
  1387. if (!(rect = rect || interactable.getRect(dropElement))) {
  1388. return interactable.options.drop.checker ? interactable.options.drop.checker(dragEvent, event, dropped, interactable, dropElement, draggable, draggableElement) : false;
  1389. }
  1390. var dropOverlap = interactable.options.drop.overlap;
  1391. if (dropOverlap === 'pointer') {
  1392. var origin = getOriginXY(draggable, draggableElement, 'drag');
  1393. var page = getPageXY(dragEvent);
  1394. page.x += origin.x;
  1395. page.y += origin.y;
  1396. var horizontal = page.x > rect.left && page.x < rect.right;
  1397. var vertical = page.y > rect.top && page.y < rect.bottom;
  1398. dropped = horizontal && vertical;
  1399. }
  1400. var dragRect = draggable.getRect(draggableElement);
  1401. if (dragRect && dropOverlap === 'center') {
  1402. var cx = dragRect.left + dragRect.width / 2;
  1403. var cy = dragRect.top + dragRect.height / 2;
  1404. dropped = cx >= rect.left && cx <= rect.right && cy >= rect.top && cy <= rect.bottom;
  1405. }
  1406. if (dragRect && is.number(dropOverlap)) {
  1407. var overlapArea = Math.max(0, Math.min(rect.right, dragRect.right) - Math.max(rect.left, dragRect.left)) * Math.max(0, Math.min(rect.bottom, dragRect.bottom) - Math.max(rect.top, dragRect.top));
  1408. var overlapRatio = overlapArea / (dragRect.width * dragRect.height);
  1409. dropped = overlapRatio >= dropOverlap;
  1410. }
  1411. if (interactable.options.drop.checker) {
  1412. dropped = interactable.options.drop.checker(dragEvent, event, dropped, interactable, dropElement, draggable, draggableElement);
  1413. }
  1414. return dropped;
  1415. }
  1416. var drop = {
  1417. id: 'actions/drop',
  1418. install: install$f,
  1419. listeners: {
  1420. 'interactions:before-action-start': function interactionsBeforeActionStart(_ref4) {
  1421. var interaction = _ref4.interaction;
  1422. if (interaction.prepared.name !== 'drag') {
  1423. return;
  1424. }
  1425. interaction.dropState = {
  1426. cur: {
  1427. dropzone: null,
  1428. element: null
  1429. },
  1430. prev: {
  1431. dropzone: null,
  1432. element: null
  1433. },
  1434. rejected: null,
  1435. events: null,
  1436. activeDrops: []
  1437. };
  1438. },
  1439. 'interactions:after-action-start': function interactionsAfterActionStart(_ref5, scope) {
  1440. var interaction = _ref5.interaction,
  1441. event = _ref5.event,
  1442. dragEvent = _ref5.iEvent;
  1443. if (interaction.prepared.name !== 'drag') {
  1444. return;
  1445. }
  1446. var dropState = interaction.dropState;
  1447. // reset active dropzones
  1448. dropState.activeDrops = [];
  1449. dropState.events = {};
  1450. dropState.activeDrops = getActiveDrops(scope, interaction.element);
  1451. dropState.events = getDropEvents(interaction, event, dragEvent);
  1452. if (dropState.events.activate) {
  1453. fireActivationEvents(dropState.activeDrops, dropState.events.activate);
  1454. scope.fire('actions/drop:start', {
  1455. interaction: interaction,
  1456. dragEvent: dragEvent
  1457. });
  1458. }
  1459. },
  1460. 'interactions:action-move': onEventCreated,
  1461. 'interactions:after-action-move': function interactionsAfterActionMove(_ref6, scope) {
  1462. var interaction = _ref6.interaction,
  1463. dragEvent = _ref6.iEvent;
  1464. if (interaction.prepared.name !== 'drag') {
  1465. return;
  1466. }
  1467. var dropState = interaction.dropState;
  1468. fireDropEvents(interaction, dropState.events);
  1469. scope.fire('actions/drop:move', {
  1470. interaction: interaction,
  1471. dragEvent: dragEvent
  1472. });
  1473. dropState.events = {};
  1474. },
  1475. 'interactions:action-end': function interactionsActionEnd(arg, scope) {
  1476. if (arg.interaction.prepared.name !== 'drag') {
  1477. return;
  1478. }
  1479. var interaction = arg.interaction,
  1480. dragEvent = arg.iEvent;
  1481. onEventCreated(arg, scope);
  1482. fireDropEvents(interaction, interaction.dropState.events);
  1483. scope.fire('actions/drop:end', {
  1484. interaction: interaction,
  1485. dragEvent: dragEvent
  1486. });
  1487. },
  1488. 'interactions:stop': function interactionsStop(_ref7) {
  1489. var interaction = _ref7.interaction;
  1490. if (interaction.prepared.name !== 'drag') {
  1491. return;
  1492. }
  1493. var dropState = interaction.dropState;
  1494. if (dropState) {
  1495. dropState.activeDrops = null;
  1496. dropState.events = null;
  1497. dropState.cur.dropzone = null;
  1498. dropState.cur.element = null;
  1499. dropState.prev.dropzone = null;
  1500. dropState.prev.element = null;
  1501. dropState.rejected = false;
  1502. }
  1503. }
  1504. },
  1505. getActiveDrops: getActiveDrops,
  1506. getDrop: getDrop,
  1507. getDropEvents: getDropEvents,
  1508. fireDropEvents: fireDropEvents,
  1509. filterEventType: function filterEventType(type) {
  1510. return type.search('drag') === 0 || type.search('drop') === 0;
  1511. },
  1512. defaults: {
  1513. enabled: false,
  1514. accept: null,
  1515. overlap: 'pointer'
  1516. }
  1517. };
  1518. var drop$1 = drop;
  1519. function install$e(scope) {
  1520. var actions = scope.actions,
  1521. Interactable = scope.Interactable,
  1522. defaults = scope.defaults;
  1523. Interactable.prototype.gesturable = function (options) {
  1524. if (is.object(options)) {
  1525. this.options.gesture.enabled = options.enabled !== false;
  1526. this.setPerAction('gesture', options);
  1527. this.setOnEvents('gesture', options);
  1528. return this;
  1529. }
  1530. if (is.bool(options)) {
  1531. this.options.gesture.enabled = options;
  1532. return this;
  1533. }
  1534. return this.options.gesture;
  1535. };
  1536. actions.map.gesture = gesture;
  1537. actions.methodDict.gesture = 'gesturable';
  1538. defaults.actions.gesture = gesture.defaults;
  1539. }
  1540. function updateGestureProps(_ref) {
  1541. var interaction = _ref.interaction,
  1542. iEvent = _ref.iEvent,
  1543. phase = _ref.phase;
  1544. if (interaction.prepared.name !== 'gesture') return;
  1545. var pointers = interaction.pointers.map(function (p) {
  1546. return p.pointer;
  1547. });
  1548. var starting = phase === 'start';
  1549. var ending = phase === 'end';
  1550. var deltaSource = interaction.interactable.options.deltaSource;
  1551. iEvent.touches = [pointers[0], pointers[1]];
  1552. if (starting) {
  1553. iEvent.distance = touchDistance(pointers, deltaSource);
  1554. iEvent.box = touchBBox(pointers);
  1555. iEvent.scale = 1;
  1556. iEvent.ds = 0;
  1557. iEvent.angle = touchAngle(pointers, deltaSource);
  1558. iEvent.da = 0;
  1559. interaction.gesture.startDistance = iEvent.distance;
  1560. interaction.gesture.startAngle = iEvent.angle;
  1561. } else if (ending || interaction.pointers.length < 2) {
  1562. var prevEvent = interaction.prevEvent;
  1563. iEvent.distance = prevEvent.distance;
  1564. iEvent.box = prevEvent.box;
  1565. iEvent.scale = prevEvent.scale;
  1566. iEvent.ds = 0;
  1567. iEvent.angle = prevEvent.angle;
  1568. iEvent.da = 0;
  1569. } else {
  1570. iEvent.distance = touchDistance(pointers, deltaSource);
  1571. iEvent.box = touchBBox(pointers);
  1572. iEvent.scale = iEvent.distance / interaction.gesture.startDistance;
  1573. iEvent.angle = touchAngle(pointers, deltaSource);
  1574. iEvent.ds = iEvent.scale - interaction.gesture.scale;
  1575. iEvent.da = iEvent.angle - interaction.gesture.angle;
  1576. }
  1577. interaction.gesture.distance = iEvent.distance;
  1578. interaction.gesture.angle = iEvent.angle;
  1579. if (is.number(iEvent.scale) && iEvent.scale !== Infinity && !isNaN(iEvent.scale)) {
  1580. interaction.gesture.scale = iEvent.scale;
  1581. }
  1582. }
  1583. var gesture = {
  1584. id: 'actions/gesture',
  1585. before: ['actions/drag', 'actions/resize'],
  1586. install: install$e,
  1587. listeners: {
  1588. 'interactions:action-start': updateGestureProps,
  1589. 'interactions:action-move': updateGestureProps,
  1590. 'interactions:action-end': updateGestureProps,
  1591. 'interactions:new': function interactionsNew(_ref2) {
  1592. var interaction = _ref2.interaction;
  1593. interaction.gesture = {
  1594. angle: 0,
  1595. distance: 0,
  1596. scale: 1,
  1597. startAngle: 0,
  1598. startDistance: 0
  1599. };
  1600. },
  1601. 'auto-start:check': function autoStartCheck(arg) {
  1602. if (arg.interaction.pointers.length < 2) {
  1603. return undefined;
  1604. }
  1605. var gestureOptions = arg.interactable.options.gesture;
  1606. if (!(gestureOptions && gestureOptions.enabled)) {
  1607. return undefined;
  1608. }
  1609. arg.action = {
  1610. name: 'gesture'
  1611. };
  1612. return false;
  1613. }
  1614. },
  1615. defaults: {},
  1616. getCursor: function getCursor() {
  1617. return '';
  1618. },
  1619. filterEventType: function filterEventType(type) {
  1620. return type.search('gesture') === 0;
  1621. }
  1622. };
  1623. var gesture$1 = gesture;
  1624. function install$d(scope) {
  1625. var actions = scope.actions,
  1626. browser = scope.browser,
  1627. Interactable = scope.Interactable,
  1628. defaults = scope.defaults;
  1629. // Less Precision with touch input
  1630. resize.cursors = initCursors(browser);
  1631. resize.defaultMargin = browser.supportsTouch || browser.supportsPointerEvent ? 20 : 10;
  1632. Interactable.prototype.resizable = function (options) {
  1633. return resizable(this, options, scope);
  1634. };
  1635. actions.map.resize = resize;
  1636. actions.methodDict.resize = 'resizable';
  1637. defaults.actions.resize = resize.defaults;
  1638. }
  1639. function resizeChecker(arg) {
  1640. var interaction = arg.interaction,
  1641. interactable = arg.interactable,
  1642. element = arg.element,
  1643. rect = arg.rect,
  1644. buttons = arg.buttons;
  1645. if (!rect) {
  1646. return undefined;
  1647. }
  1648. var page = extend({}, interaction.coords.cur.page);
  1649. var resizeOptions = interactable.options.resize;
  1650. if (!(resizeOptions && resizeOptions.enabled) ||
  1651. // check mouseButton setting if the pointer is down
  1652. interaction.pointerIsDown && /mouse|pointer/.test(interaction.pointerType) && (buttons & resizeOptions.mouseButtons) === 0) {
  1653. return undefined;
  1654. }
  1655. // if using resize.edges
  1656. if (is.object(resizeOptions.edges)) {
  1657. var resizeEdges = {
  1658. left: false,
  1659. right: false,
  1660. top: false,
  1661. bottom: false
  1662. };
  1663. for (var edge in resizeEdges) {
  1664. resizeEdges[edge] = checkResizeEdge(edge, resizeOptions.edges[edge], page, interaction._latestPointer.eventTarget, element, rect, resizeOptions.margin || resize.defaultMargin);
  1665. }
  1666. resizeEdges.left = resizeEdges.left && !resizeEdges.right;
  1667. resizeEdges.top = resizeEdges.top && !resizeEdges.bottom;
  1668. if (resizeEdges.left || resizeEdges.right || resizeEdges.top || resizeEdges.bottom) {
  1669. arg.action = {
  1670. name: 'resize',
  1671. edges: resizeEdges
  1672. };
  1673. }
  1674. } else {
  1675. var right = resizeOptions.axis !== 'y' && page.x > rect.right - resize.defaultMargin;
  1676. var bottom = resizeOptions.axis !== 'x' && page.y > rect.bottom - resize.defaultMargin;
  1677. if (right || bottom) {
  1678. arg.action = {
  1679. name: 'resize',
  1680. axes: (right ? 'x' : '') + (bottom ? 'y' : '')
  1681. };
  1682. }
  1683. }
  1684. return arg.action ? false : undefined;
  1685. }
  1686. function resizable(interactable, options, scope) {
  1687. if (is.object(options)) {
  1688. interactable.options.resize.enabled = options.enabled !== false;
  1689. interactable.setPerAction('resize', options);
  1690. interactable.setOnEvents('resize', options);
  1691. if (is.string(options.axis) && /^x$|^y$|^xy$/.test(options.axis)) {
  1692. interactable.options.resize.axis = options.axis;
  1693. } else if (options.axis === null) {
  1694. interactable.options.resize.axis = scope.defaults.actions.resize.axis;
  1695. }
  1696. if (is.bool(options.preserveAspectRatio)) {
  1697. interactable.options.resize.preserveAspectRatio = options.preserveAspectRatio;
  1698. } else if (is.bool(options.square)) {
  1699. interactable.options.resize.square = options.square;
  1700. }
  1701. return interactable;
  1702. }
  1703. if (is.bool(options)) {
  1704. interactable.options.resize.enabled = options;
  1705. return interactable;
  1706. }
  1707. return interactable.options.resize;
  1708. }
  1709. function checkResizeEdge(name, value, page, element, interactableElement, rect, margin) {
  1710. // false, '', undefined, null
  1711. if (!value) {
  1712. return false;
  1713. }
  1714. // true value, use pointer coords and element rect
  1715. if (value === true) {
  1716. // if dimensions are negative, "switch" edges
  1717. var width = is.number(rect.width) ? rect.width : rect.right - rect.left;
  1718. var height = is.number(rect.height) ? rect.height : rect.bottom - rect.top;
  1719. // don't use margin greater than half the relevent dimension
  1720. margin = Math.min(margin, Math.abs((name === 'left' || name === 'right' ? width : height) / 2));
  1721. if (width < 0) {
  1722. if (name === 'left') {
  1723. name = 'right';
  1724. } else if (name === 'right') {
  1725. name = 'left';
  1726. }
  1727. }
  1728. if (height < 0) {
  1729. if (name === 'top') {
  1730. name = 'bottom';
  1731. } else if (name === 'bottom') {
  1732. name = 'top';
  1733. }
  1734. }
  1735. if (name === 'left') {
  1736. var edge = width >= 0 ? rect.left : rect.right;
  1737. return page.x < edge + margin;
  1738. }
  1739. if (name === 'top') {
  1740. var _edge = height >= 0 ? rect.top : rect.bottom;
  1741. return page.y < _edge + margin;
  1742. }
  1743. if (name === 'right') {
  1744. return page.x > (width >= 0 ? rect.right : rect.left) - margin;
  1745. }
  1746. if (name === 'bottom') {
  1747. return page.y > (height >= 0 ? rect.bottom : rect.top) - margin;
  1748. }
  1749. }
  1750. // the remaining checks require an element
  1751. if (!is.element(element)) {
  1752. return false;
  1753. }
  1754. return is.element(value) ?
  1755. // the value is an element to use as a resize handle
  1756. value === element :
  1757. // otherwise check if element matches value as selector
  1758. matchesUpTo(element, value, interactableElement);
  1759. }
  1760. /* eslint-disable multiline-ternary */
  1761. // eslint-disable-next-line @typescript-eslint/consistent-type-imports
  1762. function initCursors(browser) {
  1763. return browser.isIe9 ? {
  1764. x: 'e-resize',
  1765. y: 's-resize',
  1766. xy: 'se-resize',
  1767. top: 'n-resize',
  1768. left: 'w-resize',
  1769. bottom: 's-resize',
  1770. right: 'e-resize',
  1771. topleft: 'se-resize',
  1772. bottomright: 'se-resize',
  1773. topright: 'ne-resize',
  1774. bottomleft: 'ne-resize'
  1775. } : {
  1776. x: 'ew-resize',
  1777. y: 'ns-resize',
  1778. xy: 'nwse-resize',
  1779. top: 'ns-resize',
  1780. left: 'ew-resize',
  1781. bottom: 'ns-resize',
  1782. right: 'ew-resize',
  1783. topleft: 'nwse-resize',
  1784. bottomright: 'nwse-resize',
  1785. topright: 'nesw-resize',
  1786. bottomleft: 'nesw-resize'
  1787. };
  1788. }
  1789. /* eslint-enable multiline-ternary */
  1790. function start$7(_ref) {
  1791. var iEvent = _ref.iEvent,
  1792. interaction = _ref.interaction;
  1793. if (interaction.prepared.name !== 'resize' || !interaction.prepared.edges) {
  1794. return;
  1795. }
  1796. var resizeEvent = iEvent;
  1797. var rect = interaction.rect;
  1798. interaction._rects = {
  1799. start: extend({}, rect),
  1800. corrected: extend({}, rect),
  1801. previous: extend({}, rect),
  1802. delta: {
  1803. left: 0,
  1804. right: 0,
  1805. width: 0,
  1806. top: 0,
  1807. bottom: 0,
  1808. height: 0
  1809. }
  1810. };
  1811. resizeEvent.edges = interaction.prepared.edges;
  1812. resizeEvent.rect = interaction._rects.corrected;
  1813. resizeEvent.deltaRect = interaction._rects.delta;
  1814. }
  1815. function move(_ref2) {
  1816. var iEvent = _ref2.iEvent,
  1817. interaction = _ref2.interaction;
  1818. if (interaction.prepared.name !== 'resize' || !interaction.prepared.edges) return;
  1819. var resizeEvent = iEvent;
  1820. var resizeOptions = interaction.interactable.options.resize;
  1821. var invert = resizeOptions.invert;
  1822. var invertible = invert === 'reposition' || invert === 'negate';
  1823. var current = interaction.rect;
  1824. var _interaction$_rects = interaction._rects,
  1825. startRect = _interaction$_rects.start,
  1826. corrected = _interaction$_rects.corrected,
  1827. deltaRect = _interaction$_rects.delta,
  1828. previous = _interaction$_rects.previous;
  1829. extend(previous, corrected);
  1830. if (invertible) {
  1831. // if invertible, copy the current rect
  1832. extend(corrected, current);
  1833. if (invert === 'reposition') {
  1834. // swap edge values if necessary to keep width/height positive
  1835. if (corrected.top > corrected.bottom) {
  1836. var swap = corrected.top;
  1837. corrected.top = corrected.bottom;
  1838. corrected.bottom = swap;
  1839. }
  1840. if (corrected.left > corrected.right) {
  1841. var _swap = corrected.left;
  1842. corrected.left = corrected.right;
  1843. corrected.right = _swap;
  1844. }
  1845. }
  1846. } else {
  1847. // if not invertible, restrict to minimum of 0x0 rect
  1848. corrected.top = Math.min(current.top, startRect.bottom);
  1849. corrected.bottom = Math.max(current.bottom, startRect.top);
  1850. corrected.left = Math.min(current.left, startRect.right);
  1851. corrected.right = Math.max(current.right, startRect.left);
  1852. }
  1853. corrected.width = corrected.right - corrected.left;
  1854. corrected.height = corrected.bottom - corrected.top;
  1855. for (var edge in corrected) {
  1856. deltaRect[edge] = corrected[edge] - previous[edge];
  1857. }
  1858. resizeEvent.edges = interaction.prepared.edges;
  1859. resizeEvent.rect = corrected;
  1860. resizeEvent.deltaRect = deltaRect;
  1861. }
  1862. function end$1(_ref3) {
  1863. var iEvent = _ref3.iEvent,
  1864. interaction = _ref3.interaction;
  1865. if (interaction.prepared.name !== 'resize' || !interaction.prepared.edges) return;
  1866. var resizeEvent = iEvent;
  1867. resizeEvent.edges = interaction.prepared.edges;
  1868. resizeEvent.rect = interaction._rects.corrected;
  1869. resizeEvent.deltaRect = interaction._rects.delta;
  1870. }
  1871. function updateEventAxes(_ref4) {
  1872. var iEvent = _ref4.iEvent,
  1873. interaction = _ref4.interaction;
  1874. if (interaction.prepared.name !== 'resize' || !interaction.resizeAxes) return;
  1875. var options = interaction.interactable.options;
  1876. var resizeEvent = iEvent;
  1877. if (options.resize.square) {
  1878. if (interaction.resizeAxes === 'y') {
  1879. resizeEvent.delta.x = resizeEvent.delta.y;
  1880. } else {
  1881. resizeEvent.delta.y = resizeEvent.delta.x;
  1882. }
  1883. resizeEvent.axes = 'xy';
  1884. } else {
  1885. resizeEvent.axes = interaction.resizeAxes;
  1886. if (interaction.resizeAxes === 'x') {
  1887. resizeEvent.delta.y = 0;
  1888. } else if (interaction.resizeAxes === 'y') {
  1889. resizeEvent.delta.x = 0;
  1890. }
  1891. }
  1892. }
  1893. var resize = {
  1894. id: 'actions/resize',
  1895. before: ['actions/drag'],
  1896. install: install$d,
  1897. listeners: {
  1898. 'interactions:new': function interactionsNew(_ref5) {
  1899. var interaction = _ref5.interaction;
  1900. interaction.resizeAxes = 'xy';
  1901. },
  1902. 'interactions:action-start': function interactionsActionStart(arg) {
  1903. start$7(arg);
  1904. updateEventAxes(arg);
  1905. },
  1906. 'interactions:action-move': function interactionsActionMove(arg) {
  1907. move(arg);
  1908. updateEventAxes(arg);
  1909. },
  1910. 'interactions:action-end': end$1,
  1911. 'auto-start:check': resizeChecker
  1912. },
  1913. defaults: {
  1914. square: false,
  1915. preserveAspectRatio: false,
  1916. axis: 'xy',
  1917. // use default margin
  1918. margin: NaN,
  1919. // object with props left, right, top, bottom which are
  1920. // true/false values to resize when the pointer is over that edge,
  1921. // CSS selectors to match the handles for each direction
  1922. // or the Elements for each handle
  1923. edges: null,
  1924. // a value of 'none' will limit the resize rect to a minimum of 0x0
  1925. // 'negate' will alow the rect to have negative width/height
  1926. // 'reposition' will keep the width/height positive by swapping
  1927. // the top and bottom edges and/or swapping the left and right edges
  1928. invert: 'none'
  1929. },
  1930. cursors: null,
  1931. getCursor: function getCursor(_ref6) {
  1932. var edges = _ref6.edges,
  1933. axis = _ref6.axis,
  1934. name = _ref6.name;
  1935. var cursors = resize.cursors;
  1936. var result = null;
  1937. if (axis) {
  1938. result = cursors[name + axis];
  1939. } else if (edges) {
  1940. var cursorKey = '';
  1941. for (var _i2 = 0, _ref8 = ['top', 'bottom', 'left', 'right']; _i2 < _ref8.length; _i2++) {
  1942. var edge = _ref8[_i2];
  1943. if (edges[edge]) {
  1944. cursorKey += edge;
  1945. }
  1946. }
  1947. result = cursors[cursorKey];
  1948. }
  1949. return result;
  1950. },
  1951. filterEventType: function filterEventType(type) {
  1952. return type.search('resize') === 0;
  1953. },
  1954. defaultMargin: null
  1955. };
  1956. var resize$1 = resize;
  1957. /* eslint-disable import/no-duplicates -- for typescript module augmentations */
  1958. /* eslint-enable import/no-duplicates */
  1959. var actions = {
  1960. id: 'actions',
  1961. install: function install(scope) {
  1962. scope.usePlugin(gesture$1);
  1963. scope.usePlugin(resize$1);
  1964. scope.usePlugin(drag$1);
  1965. scope.usePlugin(drop$1);
  1966. }
  1967. };
  1968. var lastTime = 0;
  1969. var _request;
  1970. var _cancel;
  1971. function init(global) {
  1972. _request = global.requestAnimationFrame;
  1973. _cancel = global.cancelAnimationFrame;
  1974. if (!_request) {
  1975. var vendors = ['ms', 'moz', 'webkit', 'o'];
  1976. for (var _i2 = 0; _i2 < vendors.length; _i2++) {
  1977. var vendor = vendors[_i2];
  1978. _request = global["".concat(vendor, "RequestAnimationFrame")];
  1979. _cancel = global["".concat(vendor, "CancelAnimationFrame")] || global["".concat(vendor, "CancelRequestAnimationFrame")];
  1980. }
  1981. }
  1982. _request = _request && _request.bind(global);
  1983. _cancel = _cancel && _cancel.bind(global);
  1984. if (!_request) {
  1985. _request = function request(callback) {
  1986. var currTime = Date.now();
  1987. var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  1988. var token = global.setTimeout(function () {
  1989. // eslint-disable-next-line n/no-callback-literal
  1990. callback(currTime + timeToCall);
  1991. }, timeToCall);
  1992. lastTime = currTime + timeToCall;
  1993. return token;
  1994. };
  1995. _cancel = function cancel(token) {
  1996. return clearTimeout(token);
  1997. };
  1998. }
  1999. }
  2000. var raf = {
  2001. request: function request(callback) {
  2002. return _request(callback);
  2003. },
  2004. cancel: function cancel(token) {
  2005. return _cancel(token);
  2006. },
  2007. init: init
  2008. };
  2009. function install$c(scope) {
  2010. var defaults = scope.defaults,
  2011. actions = scope.actions;
  2012. scope.autoScroll = autoScroll;
  2013. autoScroll.now = function () {
  2014. return scope.now();
  2015. };
  2016. actions.phaselessTypes.autoscroll = true;
  2017. defaults.perAction.autoScroll = autoScroll.defaults;
  2018. }
  2019. var autoScroll = {
  2020. defaults: {
  2021. enabled: false,
  2022. margin: 60,
  2023. // the item that is scrolled (Window or HTMLElement)
  2024. container: null,
  2025. // the scroll speed in pixels per second
  2026. speed: 300
  2027. },
  2028. now: Date.now,
  2029. interaction: null,
  2030. i: 0,
  2031. // the handle returned by window.setInterval
  2032. // Direction each pulse is to scroll in
  2033. x: 0,
  2034. y: 0,
  2035. isScrolling: false,
  2036. prevTime: 0,
  2037. margin: 0,
  2038. speed: 0,
  2039. start: function start(interaction) {
  2040. autoScroll.isScrolling = true;
  2041. raf.cancel(autoScroll.i);
  2042. interaction.autoScroll = autoScroll;
  2043. autoScroll.interaction = interaction;
  2044. autoScroll.prevTime = autoScroll.now();
  2045. autoScroll.i = raf.request(autoScroll.scroll);
  2046. },
  2047. stop: function stop() {
  2048. autoScroll.isScrolling = false;
  2049. if (autoScroll.interaction) {
  2050. autoScroll.interaction.autoScroll = null;
  2051. }
  2052. raf.cancel(autoScroll.i);
  2053. },
  2054. // scroll the window by the values in scroll.x/y
  2055. scroll: function scroll() {
  2056. var interaction = autoScroll.interaction;
  2057. var interactable = interaction.interactable,
  2058. element = interaction.element;
  2059. var actionName = interaction.prepared.name;
  2060. var options = interactable.options[actionName].autoScroll;
  2061. var container = getContainer(options.container, interactable, element);
  2062. var now = autoScroll.now();
  2063. // change in time in seconds
  2064. var dt = (now - autoScroll.prevTime) / 1000;
  2065. // displacement
  2066. var s = options.speed * dt;
  2067. if (s >= 1) {
  2068. var scrollBy = {
  2069. x: autoScroll.x * s,
  2070. y: autoScroll.y * s
  2071. };
  2072. if (scrollBy.x || scrollBy.y) {
  2073. var prevScroll = getScroll(container);
  2074. if (is.window(container)) {
  2075. container.scrollBy(scrollBy.x, scrollBy.y);
  2076. } else if (container) {
  2077. container.scrollLeft += scrollBy.x;
  2078. container.scrollTop += scrollBy.y;
  2079. }
  2080. var curScroll = getScroll(container);
  2081. var delta = {
  2082. x: curScroll.x - prevScroll.x,
  2083. y: curScroll.y - prevScroll.y
  2084. };
  2085. if (delta.x || delta.y) {
  2086. interactable.fire({
  2087. type: 'autoscroll',
  2088. target: element,
  2089. interactable: interactable,
  2090. delta: delta,
  2091. interaction: interaction,
  2092. container: container
  2093. });
  2094. }
  2095. }
  2096. autoScroll.prevTime = now;
  2097. }
  2098. if (autoScroll.isScrolling) {
  2099. raf.cancel(autoScroll.i);
  2100. autoScroll.i = raf.request(autoScroll.scroll);
  2101. }
  2102. },
  2103. check: function check(interactable, actionName) {
  2104. var _options$actionName$a;
  2105. var options = interactable.options;
  2106. return (_options$actionName$a = options[actionName].autoScroll) == null ? void 0 : _options$actionName$a.enabled;
  2107. },
  2108. onInteractionMove: function onInteractionMove(_ref) {
  2109. var interaction = _ref.interaction,
  2110. pointer = _ref.pointer;
  2111. if (!(interaction.interacting() && autoScroll.check(interaction.interactable, interaction.prepared.name))) {
  2112. return;
  2113. }
  2114. if (interaction.simulation) {
  2115. autoScroll.x = autoScroll.y = 0;
  2116. return;
  2117. }
  2118. var top;
  2119. var right;
  2120. var bottom;
  2121. var left;
  2122. var interactable = interaction.interactable,
  2123. element = interaction.element;
  2124. var actionName = interaction.prepared.name;
  2125. var options = interactable.options[actionName].autoScroll;
  2126. var container = getContainer(options.container, interactable, element);
  2127. if (is.window(container)) {
  2128. left = pointer.clientX < autoScroll.margin;
  2129. top = pointer.clientY < autoScroll.margin;
  2130. right = pointer.clientX > container.innerWidth - autoScroll.margin;
  2131. bottom = pointer.clientY > container.innerHeight - autoScroll.margin;
  2132. } else {
  2133. var rect = getElementClientRect(container);
  2134. left = pointer.clientX < rect.left + autoScroll.margin;
  2135. top = pointer.clientY < rect.top + autoScroll.margin;
  2136. right = pointer.clientX > rect.right - autoScroll.margin;
  2137. bottom = pointer.clientY > rect.bottom - autoScroll.margin;
  2138. }
  2139. autoScroll.x = right ? 1 : left ? -1 : 0;
  2140. autoScroll.y = bottom ? 1 : top ? -1 : 0;
  2141. if (!autoScroll.isScrolling) {
  2142. // set the autoScroll properties to those of the target
  2143. autoScroll.margin = options.margin;
  2144. autoScroll.speed = options.speed;
  2145. autoScroll.start(interaction);
  2146. }
  2147. }
  2148. };
  2149. function getContainer(value, interactable, element) {
  2150. return (is.string(value) ? getStringOptionResult(value, interactable, element) : value) || getWindow(element);
  2151. }
  2152. function getScroll(container) {
  2153. if (is.window(container)) {
  2154. container = window.document.body;
  2155. }
  2156. return {
  2157. x: container.scrollLeft,
  2158. y: container.scrollTop
  2159. };
  2160. }
  2161. var autoScrollPlugin = {
  2162. id: 'auto-scroll',
  2163. install: install$c,
  2164. listeners: {
  2165. 'interactions:new': function interactionsNew(_ref3) {
  2166. var interaction = _ref3.interaction;
  2167. interaction.autoScroll = null;
  2168. },
  2169. 'interactions:destroy': function interactionsDestroy(_ref4) {
  2170. var interaction = _ref4.interaction;
  2171. interaction.autoScroll = null;
  2172. autoScroll.stop();
  2173. if (autoScroll.interaction) {
  2174. autoScroll.interaction = null;
  2175. }
  2176. },
  2177. 'interactions:stop': autoScroll.stop,
  2178. 'interactions:action-move': function interactionsActionMove(arg) {
  2179. return autoScroll.onInteractionMove(arg);
  2180. }
  2181. }
  2182. };
  2183. var autoScroll$1 = autoScrollPlugin;
  2184. function warnOnce(method, message) {
  2185. var warned = false;
  2186. return function () {
  2187. if (!warned) {
  2188. win.console.warn(message);
  2189. warned = true;
  2190. }
  2191. return method.apply(this, arguments);
  2192. };
  2193. }
  2194. function copyAction(dest, src) {
  2195. dest.name = src.name;
  2196. dest.axis = src.axis;
  2197. dest.edges = src.edges;
  2198. return dest;
  2199. }
  2200. function install$b(scope) {
  2201. var Interactable = scope.Interactable;
  2202. Interactable.prototype.getAction = function getAction(pointer, event, interaction, element) {
  2203. var action = defaultActionChecker(this, event, interaction, element, scope);
  2204. if (this.options.actionChecker) {
  2205. return this.options.actionChecker(pointer, event, action, this, element, interaction);
  2206. }
  2207. return action;
  2208. };
  2209. Interactable.prototype.ignoreFrom = warnOnce(function (newValue) {
  2210. return this._backCompatOption('ignoreFrom', newValue);
  2211. }, 'Interactable.ignoreFrom() has been deprecated. Use Interactble.draggable({ignoreFrom: newValue}).');
  2212. Interactable.prototype.allowFrom = warnOnce(function (newValue) {
  2213. return this._backCompatOption('allowFrom', newValue);
  2214. }, 'Interactable.allowFrom() has been deprecated. Use Interactble.draggable({allowFrom: newValue}).');
  2215. Interactable.prototype.actionChecker = actionChecker;
  2216. Interactable.prototype.styleCursor = styleCursor;
  2217. }
  2218. function defaultActionChecker(interactable, event, interaction, element, scope) {
  2219. var rect = interactable.getRect(element);
  2220. var buttons = event.buttons || {
  2221. 0: 1,
  2222. 1: 4,
  2223. 3: 8,
  2224. 4: 16
  2225. }[event.button];
  2226. var arg = {
  2227. action: null,
  2228. interactable: interactable,
  2229. interaction: interaction,
  2230. element: element,
  2231. rect: rect,
  2232. buttons: buttons
  2233. };
  2234. scope.fire('auto-start:check', arg);
  2235. return arg.action;
  2236. }
  2237. function styleCursor(newValue) {
  2238. if (is.bool(newValue)) {
  2239. this.options.styleCursor = newValue;
  2240. return this;
  2241. }
  2242. if (newValue === null) {
  2243. delete this.options.styleCursor;
  2244. return this;
  2245. }
  2246. return this.options.styleCursor;
  2247. }
  2248. function actionChecker(checker) {
  2249. if (is.func(checker)) {
  2250. this.options.actionChecker = checker;
  2251. return this;
  2252. }
  2253. if (checker === null) {
  2254. delete this.options.actionChecker;
  2255. return this;
  2256. }
  2257. return this.options.actionChecker;
  2258. }
  2259. var InteractableMethods = {
  2260. id: 'auto-start/interactableMethods',
  2261. install: install$b
  2262. };
  2263. /* eslint-enable import/no-duplicates */
  2264. function install$a(scope) {
  2265. var interact = scope.interactStatic,
  2266. defaults = scope.defaults;
  2267. scope.usePlugin(InteractableMethods);
  2268. defaults.base.actionChecker = null;
  2269. defaults.base.styleCursor = true;
  2270. extend(defaults.perAction, {
  2271. manualStart: false,
  2272. max: Infinity,
  2273. maxPerElement: 1,
  2274. allowFrom: null,
  2275. ignoreFrom: null,
  2276. // only allow left button by default
  2277. // see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons#Return_value
  2278. mouseButtons: 1
  2279. });
  2280. interact.maxInteractions = function (newValue) {
  2281. return maxInteractions(newValue, scope);
  2282. };
  2283. scope.autoStart = {
  2284. // Allow this many interactions to happen simultaneously
  2285. maxInteractions: Infinity,
  2286. withinInteractionLimit: withinInteractionLimit,
  2287. cursorElement: null
  2288. };
  2289. }
  2290. function prepareOnDown(_ref, scope) {
  2291. var interaction = _ref.interaction,
  2292. pointer = _ref.pointer,
  2293. event = _ref.event,
  2294. eventTarget = _ref.eventTarget;
  2295. if (interaction.interacting()) return;
  2296. var actionInfo = getActionInfo(interaction, pointer, event, eventTarget, scope);
  2297. prepare(interaction, actionInfo, scope);
  2298. }
  2299. function prepareOnMove(_ref2, scope) {
  2300. var interaction = _ref2.interaction,
  2301. pointer = _ref2.pointer,
  2302. event = _ref2.event,
  2303. eventTarget = _ref2.eventTarget;
  2304. if (interaction.pointerType !== 'mouse' || interaction.pointerIsDown || interaction.interacting()) return;
  2305. var actionInfo = getActionInfo(interaction, pointer, event, eventTarget, scope);
  2306. prepare(interaction, actionInfo, scope);
  2307. }
  2308. function startOnMove(arg, scope) {
  2309. var interaction = arg.interaction;
  2310. if (!interaction.pointerIsDown || interaction.interacting() || !interaction.pointerWasMoved || !interaction.prepared.name) {
  2311. return;
  2312. }
  2313. scope.fire('autoStart:before-start', arg);
  2314. var interactable = interaction.interactable;
  2315. var actionName = interaction.prepared.name;
  2316. if (actionName && interactable) {
  2317. // check manualStart and interaction limit
  2318. if (interactable.options[actionName].manualStart || !withinInteractionLimit(interactable, interaction.element, interaction.prepared, scope)) {
  2319. interaction.stop();
  2320. } else {
  2321. interaction.start(interaction.prepared, interactable, interaction.element);
  2322. setInteractionCursor(interaction, scope);
  2323. }
  2324. }
  2325. }
  2326. function clearCursorOnStop(_ref3, scope) {
  2327. var interaction = _ref3.interaction;
  2328. var interactable = interaction.interactable;
  2329. if (interactable && interactable.options.styleCursor) {
  2330. setCursor(interaction.element, '', scope);
  2331. }
  2332. }
  2333. // Check if the current interactable supports the action.
  2334. // If so, return the validated action. Otherwise, return null
  2335. function validateAction(action, interactable, element, eventTarget, scope) {
  2336. if (interactable.testIgnoreAllow(interactable.options[action.name], element, eventTarget) && interactable.options[action.name].enabled && withinInteractionLimit(interactable, element, action, scope)) {
  2337. return action;
  2338. }
  2339. return null;
  2340. }
  2341. function validateMatches(interaction, pointer, event, matches, matchElements, eventTarget, scope) {
  2342. for (var i = 0, len = matches.length; i < len; i++) {
  2343. var match = matches[i];
  2344. var matchElement = matchElements[i];
  2345. var matchAction = match.getAction(pointer, event, interaction, matchElement);
  2346. if (!matchAction) {
  2347. continue;
  2348. }
  2349. var action = validateAction(matchAction, match, matchElement, eventTarget, scope);
  2350. if (action) {
  2351. return {
  2352. action: action,
  2353. interactable: match,
  2354. element: matchElement
  2355. };
  2356. }
  2357. }
  2358. return {
  2359. action: null,
  2360. interactable: null,
  2361. element: null
  2362. };
  2363. }
  2364. function getActionInfo(interaction, pointer, event, eventTarget, scope) {
  2365. var matches = [];
  2366. var matchElements = [];
  2367. var element = eventTarget;
  2368. function pushMatches(interactable) {
  2369. matches.push(interactable);
  2370. matchElements.push(element);
  2371. }
  2372. while (is.element(element)) {
  2373. matches = [];
  2374. matchElements = [];
  2375. scope.interactables.forEachMatch(element, pushMatches);
  2376. var actionInfo = validateMatches(interaction, pointer, event, matches, matchElements, eventTarget, scope);
  2377. if (actionInfo.action && !actionInfo.interactable.options[actionInfo.action.name].manualStart) {
  2378. return actionInfo;
  2379. }
  2380. element = parentNode(element);
  2381. }
  2382. return {
  2383. action: null,
  2384. interactable: null,
  2385. element: null
  2386. };
  2387. }
  2388. function prepare(interaction, _ref4, scope) {
  2389. var action = _ref4.action,
  2390. interactable = _ref4.interactable,
  2391. element = _ref4.element;
  2392. action = action || {
  2393. name: null
  2394. };
  2395. interaction.interactable = interactable;
  2396. interaction.element = element;
  2397. copyAction(interaction.prepared, action);
  2398. interaction.rect = interactable && action.name ? interactable.getRect(element) : null;
  2399. setInteractionCursor(interaction, scope);
  2400. scope.fire('autoStart:prepared', {
  2401. interaction: interaction
  2402. });
  2403. }
  2404. function withinInteractionLimit(interactable, element, action, scope) {
  2405. var options = interactable.options;
  2406. var maxActions = options[action.name].max;
  2407. var maxPerElement = options[action.name].maxPerElement;
  2408. var autoStartMax = scope.autoStart.maxInteractions;
  2409. var activeInteractions = 0;
  2410. var interactableCount = 0;
  2411. var elementCount = 0;
  2412. // no actions if any of these values == 0
  2413. if (!(maxActions && maxPerElement && autoStartMax)) {
  2414. return false;
  2415. }
  2416. for (var _i2 = 0, _scope$interactions$l2 = scope.interactions.list; _i2 < _scope$interactions$l2.length; _i2++) {
  2417. var interaction = _scope$interactions$l2[_i2];
  2418. var otherAction = interaction.prepared.name;
  2419. if (!interaction.interacting()) {
  2420. continue;
  2421. }
  2422. activeInteractions++;
  2423. if (activeInteractions >= autoStartMax) {
  2424. return false;
  2425. }
  2426. if (interaction.interactable !== interactable) {
  2427. continue;
  2428. }
  2429. interactableCount += otherAction === action.name ? 1 : 0;
  2430. if (interactableCount >= maxActions) {
  2431. return false;
  2432. }
  2433. if (interaction.element === element) {
  2434. elementCount++;
  2435. if (otherAction === action.name && elementCount >= maxPerElement) {
  2436. return false;
  2437. }
  2438. }
  2439. }
  2440. return autoStartMax > 0;
  2441. }
  2442. function maxInteractions(newValue, scope) {
  2443. if (is.number(newValue)) {
  2444. scope.autoStart.maxInteractions = newValue;
  2445. return this;
  2446. }
  2447. return scope.autoStart.maxInteractions;
  2448. }
  2449. function setCursor(element, cursor, scope) {
  2450. var prevCursorElement = scope.autoStart.cursorElement;
  2451. if (prevCursorElement && prevCursorElement !== element) {
  2452. prevCursorElement.style.cursor = '';
  2453. }
  2454. element.ownerDocument.documentElement.style.cursor = cursor;
  2455. element.style.cursor = cursor;
  2456. scope.autoStart.cursorElement = cursor ? element : null;
  2457. }
  2458. function setInteractionCursor(interaction, scope) {
  2459. var interactable = interaction.interactable,
  2460. element = interaction.element,
  2461. prepared = interaction.prepared;
  2462. if (!(interaction.pointerType === 'mouse' && interactable && interactable.options.styleCursor)) {
  2463. // clear previous target element cursor
  2464. if (scope.autoStart.cursorElement) {
  2465. setCursor(scope.autoStart.cursorElement, '', scope);
  2466. }
  2467. return;
  2468. }
  2469. var cursor = '';
  2470. if (prepared.name) {
  2471. var cursorChecker = interactable.options[prepared.name].cursorChecker;
  2472. if (is.func(cursorChecker)) {
  2473. cursor = cursorChecker(prepared, interactable, element, interaction._interacting);
  2474. } else {
  2475. cursor = scope.actions.map[prepared.name].getCursor(prepared);
  2476. }
  2477. }
  2478. setCursor(interaction.element, cursor || '', scope);
  2479. }
  2480. var autoStart$1 = {
  2481. id: 'auto-start/base',
  2482. before: ['actions'],
  2483. install: install$a,
  2484. listeners: {
  2485. 'interactions:down': prepareOnDown,
  2486. 'interactions:move': function interactionsMove(arg, scope) {
  2487. prepareOnMove(arg, scope);
  2488. startOnMove(arg, scope);
  2489. },
  2490. 'interactions:stop': clearCursorOnStop
  2491. },
  2492. maxInteractions: maxInteractions,
  2493. withinInteractionLimit: withinInteractionLimit,
  2494. validateAction: validateAction
  2495. };
  2496. var autoStart$2 = autoStart$1;
  2497. function beforeStart(_ref, scope) {
  2498. var interaction = _ref.interaction,
  2499. eventTarget = _ref.eventTarget,
  2500. dx = _ref.dx,
  2501. dy = _ref.dy;
  2502. if (interaction.prepared.name !== 'drag') return;
  2503. // check if a drag is in the correct axis
  2504. var absX = Math.abs(dx);
  2505. var absY = Math.abs(dy);
  2506. var targetOptions = interaction.interactable.options.drag;
  2507. var startAxis = targetOptions.startAxis;
  2508. var currentAxis = absX > absY ? 'x' : absX < absY ? 'y' : 'xy';
  2509. interaction.prepared.axis = targetOptions.lockAxis === 'start' ? currentAxis[0] // always lock to one axis even if currentAxis === 'xy'
  2510. : targetOptions.lockAxis;
  2511. // if the movement isn't in the startAxis of the interactable
  2512. if (currentAxis !== 'xy' && startAxis !== 'xy' && startAxis !== currentAxis) {
  2513. interaction.prepared.name = null;
  2514. // then try to get a drag from another ineractable
  2515. var element = eventTarget;
  2516. var getDraggable = function getDraggable(interactable) {
  2517. if (interactable === interaction.interactable) return;
  2518. var options = interaction.interactable.options.drag;
  2519. if (!options.manualStart && interactable.testIgnoreAllow(options, element, eventTarget)) {
  2520. var action = interactable.getAction(interaction.downPointer, interaction.downEvent, interaction, element);
  2521. if (action && action.name === 'drag' && checkStartAxis(currentAxis, interactable) && autoStart$2.validateAction(action, interactable, element, eventTarget, scope)) {
  2522. return interactable;
  2523. }
  2524. }
  2525. };
  2526. // check all interactables
  2527. while (is.element(element)) {
  2528. var interactable = scope.interactables.forEachMatch(element, getDraggable);
  2529. if (interactable) {
  2530. interaction.prepared.name = 'drag';
  2531. interaction.interactable = interactable;
  2532. interaction.element = element;
  2533. break;
  2534. }
  2535. element = parentNode(element);
  2536. }
  2537. }
  2538. }
  2539. function checkStartAxis(startAxis, interactable) {
  2540. if (!interactable) {
  2541. return false;
  2542. }
  2543. var thisAxis = interactable.options.drag.startAxis;
  2544. return startAxis === 'xy' || thisAxis === 'xy' || thisAxis === startAxis;
  2545. }
  2546. var dragAxis = {
  2547. id: 'auto-start/dragAxis',
  2548. listeners: {
  2549. 'autoStart:before-start': beforeStart
  2550. }
  2551. };
  2552. /* eslint-disable import/no-duplicates -- for typescript module augmentations */
  2553. /* eslint-enable */
  2554. function install$9(scope) {
  2555. var defaults = scope.defaults;
  2556. scope.usePlugin(autoStart$2);
  2557. defaults.perAction.hold = 0;
  2558. defaults.perAction.delay = 0;
  2559. }
  2560. function getHoldDuration(interaction) {
  2561. var actionName = interaction.prepared && interaction.prepared.name;
  2562. if (!actionName) {
  2563. return null;
  2564. }
  2565. var options = interaction.interactable.options;
  2566. return options[actionName].hold || options[actionName].delay;
  2567. }
  2568. var hold = {
  2569. id: 'auto-start/hold',
  2570. install: install$9,
  2571. listeners: {
  2572. 'interactions:new': function interactionsNew(_ref) {
  2573. var interaction = _ref.interaction;
  2574. interaction.autoStartHoldTimer = null;
  2575. },
  2576. 'autoStart:prepared': function autoStartPrepared(_ref2) {
  2577. var interaction = _ref2.interaction;
  2578. var hold = getHoldDuration(interaction);
  2579. if (hold > 0) {
  2580. interaction.autoStartHoldTimer = setTimeout(function () {
  2581. interaction.start(interaction.prepared, interaction.interactable, interaction.element);
  2582. }, hold);
  2583. }
  2584. },
  2585. 'interactions:move': function interactionsMove(_ref3) {
  2586. var interaction = _ref3.interaction,
  2587. duplicate = _ref3.duplicate;
  2588. if (interaction.autoStartHoldTimer && interaction.pointerWasMoved && !duplicate) {
  2589. clearTimeout(interaction.autoStartHoldTimer);
  2590. interaction.autoStartHoldTimer = null;
  2591. }
  2592. },
  2593. // prevent regular down->move autoStart
  2594. 'autoStart:before-start': function autoStartBeforeStart(_ref4) {
  2595. var interaction = _ref4.interaction;
  2596. var holdDuration = getHoldDuration(interaction);
  2597. if (holdDuration > 0) {
  2598. interaction.prepared.name = null;
  2599. }
  2600. }
  2601. },
  2602. getHoldDuration: getHoldDuration
  2603. };
  2604. var hold$1 = hold;
  2605. /* eslint-disable import/no-duplicates -- for typescript module augmentations */
  2606. /* eslint-enable import/no-duplicates */
  2607. var autoStart = {
  2608. id: 'auto-start',
  2609. install: function install(scope) {
  2610. scope.usePlugin(autoStart$2);
  2611. scope.usePlugin(hold$1);
  2612. scope.usePlugin(dragAxis);
  2613. }
  2614. };
  2615. var preventDefault = function preventDefault(newValue) {
  2616. if (/^(always|never|auto)$/.test(newValue)) {
  2617. this.options.preventDefault = newValue;
  2618. return this;
  2619. }
  2620. if (is.bool(newValue)) {
  2621. this.options.preventDefault = newValue ? 'always' : 'never';
  2622. return this;
  2623. }
  2624. return this.options.preventDefault;
  2625. };
  2626. function checkAndPreventDefault(interactable, scope, event) {
  2627. var setting = interactable.options.preventDefault;
  2628. if (setting === 'never') return;
  2629. if (setting === 'always') {
  2630. event.preventDefault();
  2631. return;
  2632. }
  2633. // setting === 'auto'
  2634. // if the browser supports passive event listeners and isn't running on iOS,
  2635. // don't preventDefault of touch{start,move} events. CSS touch-action and
  2636. // user-select should be used instead of calling event.preventDefault().
  2637. if (scope.events.supportsPassive && /^touch(start|move)$/.test(event.type)) {
  2638. var doc = getWindow(event.target).document;
  2639. var docOptions = scope.getDocOptions(doc);
  2640. if (!(docOptions && docOptions.events) || docOptions.events.passive !== false) {
  2641. return;
  2642. }
  2643. }
  2644. // don't preventDefault of pointerdown events
  2645. if (/^(mouse|pointer|touch)*(down|start)/i.test(event.type)) {
  2646. return;
  2647. }
  2648. // don't preventDefault on editable elements
  2649. if (is.element(event.target) && matchesSelector(event.target, 'input,select,textarea,[contenteditable=true],[contenteditable=true] *')) {
  2650. return;
  2651. }
  2652. event.preventDefault();
  2653. }
  2654. function onInteractionEvent(_ref) {
  2655. var interaction = _ref.interaction,
  2656. event = _ref.event;
  2657. if (interaction.interactable) {
  2658. interaction.interactable.checkAndPreventDefault(event);
  2659. }
  2660. }
  2661. function install$8(scope) {
  2662. var Interactable = scope.Interactable;
  2663. Interactable.prototype.preventDefault = preventDefault;
  2664. Interactable.prototype.checkAndPreventDefault = function (event) {
  2665. return checkAndPreventDefault(this, scope, event);
  2666. };
  2667. // prevent native HTML5 drag on interact.js target elements
  2668. scope.interactions.docEvents.push({
  2669. type: 'dragstart',
  2670. listener: function listener(event) {
  2671. for (var _i2 = 0, _scope$interactions$l2 = scope.interactions.list; _i2 < _scope$interactions$l2.length; _i2++) {
  2672. var interaction = _scope$interactions$l2[_i2];
  2673. if (interaction.element && (interaction.element === event.target || nodeContains(interaction.element, event.target))) {
  2674. interaction.interactable.checkAndPreventDefault(event);
  2675. return;
  2676. }
  2677. }
  2678. }
  2679. });
  2680. }
  2681. var interactablePreventDefault = {
  2682. id: 'core/interactablePreventDefault',
  2683. install: install$8,
  2684. listeners: ['down', 'move', 'up', 'cancel'].reduce(function (acc, eventType) {
  2685. acc["interactions:".concat(eventType)] = onInteractionEvent;
  2686. return acc;
  2687. }, {})
  2688. };
  2689. function isNonNativeEvent(type, actions) {
  2690. if (actions.phaselessTypes[type]) {
  2691. return true;
  2692. }
  2693. for (var name in actions.map) {
  2694. if (type.indexOf(name) === 0 && type.substr(name.length) in actions.phases) {
  2695. return true;
  2696. }
  2697. }
  2698. return false;
  2699. }
  2700. var CheckName = /*#__PURE__*/function (CheckName) {
  2701. CheckName["touchAction"] = "touchAction";
  2702. CheckName["boxSizing"] = "boxSizing";
  2703. CheckName["noListeners"] = "noListeners";
  2704. return CheckName;
  2705. }(CheckName || {});
  2706. var prefix = '[interact.js] ';
  2707. var links = {
  2708. touchAction: 'https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action',
  2709. boxSizing: 'https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing'
  2710. };
  2711. // eslint-disable-next-line no-undef
  2712. var isProduction = "development" === 'production';
  2713. function install$7(scope) {
  2714. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  2715. logger = _ref.logger;
  2716. var Interactable = scope.Interactable,
  2717. defaults = scope.defaults;
  2718. scope.logger = logger || console;
  2719. defaults.base.devTools = {
  2720. ignore: {}
  2721. };
  2722. Interactable.prototype.devTools = function (options) {
  2723. if (options) {
  2724. extend(this.options.devTools, options);
  2725. return this;
  2726. }
  2727. return this.options.devTools;
  2728. };
  2729. // can't set native events on non string targets without `addEventListener` prop
  2730. var _onOff = Interactable.prototype._onOff;
  2731. Interactable.prototype._onOff = function (method, typeArg, listenerArg, options, filter) {
  2732. if (is.string(this.target) || this.target.addEventListener) {
  2733. return _onOff.call(this, method, typeArg, listenerArg, options, filter);
  2734. }
  2735. if (is.object(typeArg) && !is.array(typeArg)) {
  2736. options = listenerArg;
  2737. listenerArg = null;
  2738. }
  2739. var normalizedListeners = normalize(typeArg, listenerArg, filter);
  2740. for (var type in normalizedListeners) {
  2741. if (isNonNativeEvent(type, scope.actions)) continue;
  2742. scope.logger.warn(prefix + "Can't add native \"".concat(type, "\" event listener to target without `addEventListener(type, listener, options)` prop."));
  2743. }
  2744. return _onOff.call(this, method, normalizedListeners, options);
  2745. };
  2746. }
  2747. var checks = [{
  2748. name: CheckName.touchAction,
  2749. perform: function perform(_ref2) {
  2750. var element = _ref2.element;
  2751. return !!element && !parentHasStyle(element, 'touchAction', /pan-|pinch|none/);
  2752. },
  2753. getInfo: function getInfo(_ref3) {
  2754. var element = _ref3.element;
  2755. return [element, links.touchAction];
  2756. },
  2757. text: 'Consider adding CSS "touch-action: none" to this element\n'
  2758. }, {
  2759. name: CheckName.boxSizing,
  2760. perform: function perform(interaction) {
  2761. var element = interaction.element;
  2762. return interaction.prepared.name === 'resize' && element instanceof domObjects$1.HTMLElement && !hasStyle(element, 'boxSizing', /border-box/);
  2763. },
  2764. text: 'Consider adding CSS "box-sizing: border-box" to this resizable element',
  2765. getInfo: function getInfo(_ref4) {
  2766. var element = _ref4.element;
  2767. return [element, links.boxSizing];
  2768. }
  2769. }, {
  2770. name: CheckName.noListeners,
  2771. perform: function perform(interaction) {
  2772. var _interaction$interact;
  2773. var actionName = interaction.prepared.name;
  2774. var moveListeners = ((_interaction$interact = interaction.interactable) == null ? void 0 : _interaction$interact.events.types["".concat(actionName, "move")]) || [];
  2775. return !moveListeners.length;
  2776. },
  2777. getInfo: function getInfo(interaction) {
  2778. return [interaction.prepared.name, interaction.interactable];
  2779. },
  2780. text: 'There are no listeners set for this action'
  2781. }];
  2782. function hasStyle(element, prop, styleRe) {
  2783. var value = element.style[prop] || win.getComputedStyle(element)[prop];
  2784. return styleRe.test((value || '').toString());
  2785. }
  2786. function parentHasStyle(element, prop, styleRe) {
  2787. var parent = element;
  2788. while (is.element(parent)) {
  2789. if (hasStyle(parent, prop, styleRe)) {
  2790. return true;
  2791. }
  2792. parent = parentNode(parent);
  2793. }
  2794. return false;
  2795. }
  2796. var id = 'dev-tools';
  2797. var defaultExport = isProduction ? {
  2798. id: id,
  2799. install: function install() {}
  2800. } : {
  2801. id: id,
  2802. install: install$7,
  2803. listeners: {
  2804. 'interactions:action-start': function interactionsActionStart(_ref5, scope) {
  2805. var interaction = _ref5.interaction;
  2806. for (var _i2 = 0; _i2 < checks.length; _i2++) {
  2807. var check = checks[_i2];
  2808. var options = interaction.interactable && interaction.interactable.options;
  2809. if (!(options && options.devTools && options.devTools.ignore[check.name]) && check.perform(interaction)) {
  2810. var _scope$logger;
  2811. (_scope$logger = scope.logger).warn.apply(_scope$logger, [prefix + check.text].concat(check.getInfo(interaction)));
  2812. }
  2813. }
  2814. }
  2815. },
  2816. checks: checks,
  2817. CheckName: CheckName,
  2818. links: links,
  2819. prefix: prefix
  2820. };
  2821. var devTools = defaultExport;
  2822. // tslint:disable-next-line ban-types
  2823. function clone(source) {
  2824. var dest = {};
  2825. for (var prop in source) {
  2826. var value = source[prop];
  2827. if (is.plainObject(value)) {
  2828. dest[prop] = clone(value);
  2829. } else if (is.array(value)) {
  2830. dest[prop] = from(value);
  2831. } else {
  2832. dest[prop] = value;
  2833. }
  2834. }
  2835. return dest;
  2836. }
  2837. var Modification = /*#__PURE__*/function () {
  2838. function Modification(interaction) {
  2839. _classCallCheck(this, Modification);
  2840. this.states = [];
  2841. this.startOffset = {
  2842. left: 0,
  2843. right: 0,
  2844. top: 0,
  2845. bottom: 0
  2846. };
  2847. this.startDelta = void 0;
  2848. this.result = void 0;
  2849. this.endResult = void 0;
  2850. this.startEdges = void 0;
  2851. this.edges = void 0;
  2852. this.interaction = void 0;
  2853. this.interaction = interaction;
  2854. this.result = createResult();
  2855. this.edges = {
  2856. left: false,
  2857. right: false,
  2858. top: false,
  2859. bottom: false
  2860. };
  2861. }
  2862. _createClass(Modification, [{
  2863. key: "start",
  2864. value: function start(_ref, pageCoords) {
  2865. var phase = _ref.phase;
  2866. var interaction = this.interaction;
  2867. var modifierList = getModifierList(interaction);
  2868. this.prepareStates(modifierList);
  2869. this.startEdges = extend({}, interaction.edges);
  2870. this.edges = extend({}, this.startEdges);
  2871. this.startOffset = getRectOffset(interaction.rect, pageCoords);
  2872. this.startDelta = {
  2873. x: 0,
  2874. y: 0
  2875. };
  2876. var arg = this.fillArg({
  2877. phase: phase,
  2878. pageCoords: pageCoords,
  2879. preEnd: false
  2880. });
  2881. this.result = createResult();
  2882. this.startAll(arg);
  2883. var result = this.result = this.setAll(arg);
  2884. return result;
  2885. }
  2886. }, {
  2887. key: "fillArg",
  2888. value: function fillArg(arg) {
  2889. var interaction = this.interaction;
  2890. arg.interaction = interaction;
  2891. arg.interactable = interaction.interactable;
  2892. arg.element = interaction.element;
  2893. arg.rect || (arg.rect = interaction.rect);
  2894. arg.edges || (arg.edges = this.startEdges);
  2895. arg.startOffset = this.startOffset;
  2896. return arg;
  2897. }
  2898. }, {
  2899. key: "startAll",
  2900. value: function startAll(arg) {
  2901. for (var _i2 = 0, _this$states2 = this.states; _i2 < _this$states2.length; _i2++) {
  2902. var state = _this$states2[_i2];
  2903. if (state.methods.start) {
  2904. arg.state = state;
  2905. state.methods.start(arg);
  2906. }
  2907. }
  2908. }
  2909. }, {
  2910. key: "setAll",
  2911. value: function setAll(arg) {
  2912. var phase = arg.phase,
  2913. preEnd = arg.preEnd,
  2914. skipModifiers = arg.skipModifiers,
  2915. unmodifiedRect = arg.rect,
  2916. unmodifiedEdges = arg.edges;
  2917. arg.coords = extend({}, arg.pageCoords);
  2918. arg.rect = extend({}, unmodifiedRect);
  2919. arg.edges = extend({}, unmodifiedEdges);
  2920. var states = skipModifiers ? this.states.slice(skipModifiers) : this.states;
  2921. var newResult = createResult(arg.coords, arg.rect);
  2922. for (var _i4 = 0; _i4 < states.length; _i4++) {
  2923. var _state$methods;
  2924. var state = states[_i4];
  2925. var options = state.options;
  2926. var lastModifierCoords = extend({}, arg.coords);
  2927. var returnValue = null;
  2928. if ((_state$methods = state.methods) != null && _state$methods.set && this.shouldDo(options, preEnd, phase)) {
  2929. arg.state = state;
  2930. returnValue = state.methods.set(arg);
  2931. addEdges(arg.edges, arg.rect, {
  2932. x: arg.coords.x - lastModifierCoords.x,
  2933. y: arg.coords.y - lastModifierCoords.y
  2934. });
  2935. }
  2936. newResult.eventProps.push(returnValue);
  2937. }
  2938. extend(this.edges, arg.edges);
  2939. newResult.delta.x = arg.coords.x - arg.pageCoords.x;
  2940. newResult.delta.y = arg.coords.y - arg.pageCoords.y;
  2941. newResult.rectDelta.left = arg.rect.left - unmodifiedRect.left;
  2942. newResult.rectDelta.right = arg.rect.right - unmodifiedRect.right;
  2943. newResult.rectDelta.top = arg.rect.top - unmodifiedRect.top;
  2944. newResult.rectDelta.bottom = arg.rect.bottom - unmodifiedRect.bottom;
  2945. var prevCoords = this.result.coords;
  2946. var prevRect = this.result.rect;
  2947. if (prevCoords && prevRect) {
  2948. var rectChanged = newResult.rect.left !== prevRect.left || newResult.rect.right !== prevRect.right || newResult.rect.top !== prevRect.top || newResult.rect.bottom !== prevRect.bottom;
  2949. newResult.changed = rectChanged || prevCoords.x !== newResult.coords.x || prevCoords.y !== newResult.coords.y;
  2950. }
  2951. return newResult;
  2952. }
  2953. }, {
  2954. key: "applyToInteraction",
  2955. value: function applyToInteraction(arg) {
  2956. var interaction = this.interaction;
  2957. var phase = arg.phase;
  2958. var curCoords = interaction.coords.cur;
  2959. var startCoords = interaction.coords.start;
  2960. var result = this.result,
  2961. startDelta = this.startDelta;
  2962. var curDelta = result.delta;
  2963. if (phase === 'start') {
  2964. extend(this.startDelta, result.delta);
  2965. }
  2966. for (var _i6 = 0, _ref3 = [[startCoords, startDelta], [curCoords, curDelta]]; _i6 < _ref3.length; _i6++) {
  2967. var _ref3$_i = _ref3[_i6],
  2968. coordsSet = _ref3$_i[0],
  2969. delta = _ref3$_i[1];
  2970. coordsSet.page.x += delta.x;
  2971. coordsSet.page.y += delta.y;
  2972. coordsSet.client.x += delta.x;
  2973. coordsSet.client.y += delta.y;
  2974. }
  2975. var rectDelta = this.result.rectDelta;
  2976. var rect = arg.rect || interaction.rect;
  2977. rect.left += rectDelta.left;
  2978. rect.right += rectDelta.right;
  2979. rect.top += rectDelta.top;
  2980. rect.bottom += rectDelta.bottom;
  2981. rect.width = rect.right - rect.left;
  2982. rect.height = rect.bottom - rect.top;
  2983. }
  2984. }, {
  2985. key: "setAndApply",
  2986. value: function setAndApply(arg) {
  2987. var interaction = this.interaction;
  2988. var phase = arg.phase,
  2989. preEnd = arg.preEnd,
  2990. skipModifiers = arg.skipModifiers;
  2991. var result = this.setAll(this.fillArg({
  2992. preEnd: preEnd,
  2993. phase: phase,
  2994. pageCoords: arg.modifiedCoords || interaction.coords.cur.page
  2995. }));
  2996. this.result = result;
  2997. // don't fire an action move if a modifier would keep the event in the same
  2998. // cordinates as before
  2999. if (!result.changed && (!skipModifiers || skipModifiers < this.states.length) && interaction.interacting()) {
  3000. return false;
  3001. }
  3002. if (arg.modifiedCoords) {
  3003. var page = interaction.coords.cur.page;
  3004. var adjustment = {
  3005. x: arg.modifiedCoords.x - page.x,
  3006. y: arg.modifiedCoords.y - page.y
  3007. };
  3008. result.coords.x += adjustment.x;
  3009. result.coords.y += adjustment.y;
  3010. result.delta.x += adjustment.x;
  3011. result.delta.y += adjustment.y;
  3012. }
  3013. this.applyToInteraction(arg);
  3014. }
  3015. }, {
  3016. key: "beforeEnd",
  3017. value: function beforeEnd(arg) {
  3018. var interaction = arg.interaction,
  3019. event = arg.event;
  3020. var states = this.states;
  3021. if (!states || !states.length) {
  3022. return;
  3023. }
  3024. var doPreend = false;
  3025. for (var _i8 = 0; _i8 < states.length; _i8++) {
  3026. var state = states[_i8];
  3027. arg.state = state;
  3028. var options = state.options,
  3029. methods = state.methods;
  3030. var endPosition = methods.beforeEnd && methods.beforeEnd(arg);
  3031. if (endPosition) {
  3032. this.endResult = endPosition;
  3033. return false;
  3034. }
  3035. doPreend = doPreend || !doPreend && this.shouldDo(options, true, arg.phase, true);
  3036. }
  3037. if (doPreend) {
  3038. // trigger a final modified move before ending
  3039. interaction.move({
  3040. event: event,
  3041. preEnd: true
  3042. });
  3043. }
  3044. }
  3045. }, {
  3046. key: "stop",
  3047. value: function stop(arg) {
  3048. var interaction = arg.interaction;
  3049. if (!this.states || !this.states.length) {
  3050. return;
  3051. }
  3052. var modifierArg = extend({
  3053. states: this.states,
  3054. interactable: interaction.interactable,
  3055. element: interaction.element,
  3056. rect: null
  3057. }, arg);
  3058. this.fillArg(modifierArg);
  3059. for (var _i10 = 0, _this$states4 = this.states; _i10 < _this$states4.length; _i10++) {
  3060. var state = _this$states4[_i10];
  3061. modifierArg.state = state;
  3062. if (state.methods.stop) {
  3063. state.methods.stop(modifierArg);
  3064. }
  3065. }
  3066. this.states = null;
  3067. this.endResult = null;
  3068. }
  3069. }, {
  3070. key: "prepareStates",
  3071. value: function prepareStates(modifierList) {
  3072. this.states = [];
  3073. for (var index = 0; index < modifierList.length; index++) {
  3074. var _modifierList$index = modifierList[index],
  3075. options = _modifierList$index.options,
  3076. methods = _modifierList$index.methods,
  3077. name = _modifierList$index.name;
  3078. this.states.push({
  3079. options: options,
  3080. methods: methods,
  3081. index: index,
  3082. name: name
  3083. });
  3084. }
  3085. return this.states;
  3086. }
  3087. }, {
  3088. key: "restoreInteractionCoords",
  3089. value: function restoreInteractionCoords(_ref4) {
  3090. var _ref4$interaction = _ref4.interaction,
  3091. coords = _ref4$interaction.coords,
  3092. rect = _ref4$interaction.rect,
  3093. modification = _ref4$interaction.modification;
  3094. if (!modification.result) return;
  3095. var startDelta = modification.startDelta;
  3096. var _modification$result = modification.result,
  3097. curDelta = _modification$result.delta,
  3098. rectDelta = _modification$result.rectDelta;
  3099. var coordsAndDeltas = [[coords.start, startDelta], [coords.cur, curDelta]];
  3100. for (var _i12 = 0, _ref6 = coordsAndDeltas; _i12 < _ref6.length; _i12++) {
  3101. var _ref6$_i = _ref6[_i12],
  3102. coordsSet = _ref6$_i[0],
  3103. delta = _ref6$_i[1];
  3104. coordsSet.page.x -= delta.x;
  3105. coordsSet.page.y -= delta.y;
  3106. coordsSet.client.x -= delta.x;
  3107. coordsSet.client.y -= delta.y;
  3108. }
  3109. rect.left -= rectDelta.left;
  3110. rect.right -= rectDelta.right;
  3111. rect.top -= rectDelta.top;
  3112. rect.bottom -= rectDelta.bottom;
  3113. }
  3114. }, {
  3115. key: "shouldDo",
  3116. value: function shouldDo(options, preEnd, phase, requireEndOnly) {
  3117. if (
  3118. // ignore disabled modifiers
  3119. !options || options.enabled === false ||
  3120. // check if we require endOnly option to fire move before end
  3121. requireEndOnly && !options.endOnly ||
  3122. // don't apply endOnly modifiers when not ending
  3123. options.endOnly && !preEnd ||
  3124. // check if modifier should run be applied on start
  3125. phase === 'start' && !options.setStart) {
  3126. return false;
  3127. }
  3128. return true;
  3129. }
  3130. }, {
  3131. key: "copyFrom",
  3132. value: function copyFrom(other) {
  3133. this.startOffset = other.startOffset;
  3134. this.startDelta = other.startDelta;
  3135. this.startEdges = other.startEdges;
  3136. this.edges = other.edges;
  3137. this.states = other.states.map(function (s) {
  3138. return clone(s);
  3139. });
  3140. this.result = createResult(extend({}, other.result.coords), extend({}, other.result.rect));
  3141. }
  3142. }, {
  3143. key: "destroy",
  3144. value: function destroy() {
  3145. for (var prop in this) {
  3146. this[prop] = null;
  3147. }
  3148. }
  3149. }]);
  3150. return Modification;
  3151. }();
  3152. function createResult(coords, rect) {
  3153. return {
  3154. rect: rect,
  3155. coords: coords,
  3156. delta: {
  3157. x: 0,
  3158. y: 0
  3159. },
  3160. rectDelta: {
  3161. left: 0,
  3162. right: 0,
  3163. top: 0,
  3164. bottom: 0
  3165. },
  3166. eventProps: [],
  3167. changed: true
  3168. };
  3169. }
  3170. function getModifierList(interaction) {
  3171. var actionOptions = interaction.interactable.options[interaction.prepared.name];
  3172. var actionModifiers = actionOptions.modifiers;
  3173. if (actionModifiers && actionModifiers.length) {
  3174. return actionModifiers;
  3175. }
  3176. return ['snap', 'snapSize', 'snapEdges', 'restrict', 'restrictEdges', 'restrictSize'].map(function (type) {
  3177. var options = actionOptions[type];
  3178. return options && options.enabled && {
  3179. options: options,
  3180. methods: options._methods
  3181. };
  3182. }).filter(function (m) {
  3183. return !!m;
  3184. });
  3185. }
  3186. function getRectOffset(rect, coords) {
  3187. return rect ? {
  3188. left: coords.x - rect.left,
  3189. top: coords.y - rect.top,
  3190. right: rect.right - coords.x,
  3191. bottom: rect.bottom - coords.y
  3192. } : {
  3193. left: 0,
  3194. top: 0,
  3195. right: 0,
  3196. bottom: 0
  3197. };
  3198. }
  3199. function makeModifier(module, name) {
  3200. var defaults = module.defaults;
  3201. var methods = {
  3202. start: module.start,
  3203. set: module.set,
  3204. beforeEnd: module.beforeEnd,
  3205. stop: module.stop
  3206. };
  3207. var modifier = function modifier(_options) {
  3208. var options = _options || {};
  3209. options.enabled = options.enabled !== false;
  3210. // add missing defaults to options
  3211. for (var prop in defaults) {
  3212. if (!(prop in options)) {
  3213. options[prop] = defaults[prop];
  3214. }
  3215. }
  3216. var m = {
  3217. options: options,
  3218. methods: methods,
  3219. name: name,
  3220. enable: function enable() {
  3221. options.enabled = true;
  3222. return m;
  3223. },
  3224. disable: function disable() {
  3225. options.enabled = false;
  3226. return m;
  3227. }
  3228. };
  3229. return m;
  3230. };
  3231. if (name && typeof name === 'string') {
  3232. // for backwrads compatibility
  3233. modifier._defaults = defaults;
  3234. modifier._methods = methods;
  3235. }
  3236. return modifier;
  3237. }
  3238. function addEventModifiers(_ref) {
  3239. var iEvent = _ref.iEvent,
  3240. interaction = _ref.interaction;
  3241. var result = interaction.modification.result;
  3242. if (result) {
  3243. iEvent.modifiers = result.eventProps;
  3244. }
  3245. }
  3246. var modifiersBase = {
  3247. id: 'modifiers/base',
  3248. before: ['actions'],
  3249. install: function install(scope) {
  3250. scope.defaults.perAction.modifiers = [];
  3251. },
  3252. listeners: {
  3253. 'interactions:new': function interactionsNew(_ref2) {
  3254. var interaction = _ref2.interaction;
  3255. interaction.modification = new Modification(interaction);
  3256. },
  3257. 'interactions:before-action-start': function interactionsBeforeActionStart(arg) {
  3258. var interaction = arg.interaction;
  3259. var modification = arg.interaction.modification;
  3260. modification.start(arg, interaction.coords.start.page);
  3261. interaction.edges = modification.edges;
  3262. modification.applyToInteraction(arg);
  3263. },
  3264. 'interactions:before-action-move': function interactionsBeforeActionMove(arg) {
  3265. var interaction = arg.interaction;
  3266. var modification = interaction.modification;
  3267. var ret = modification.setAndApply(arg);
  3268. interaction.edges = modification.edges;
  3269. return ret;
  3270. },
  3271. 'interactions:before-action-end': function interactionsBeforeActionEnd(arg) {
  3272. var interaction = arg.interaction;
  3273. var modification = interaction.modification;
  3274. var ret = modification.beforeEnd(arg);
  3275. interaction.edges = modification.startEdges;
  3276. return ret;
  3277. },
  3278. 'interactions:action-start': addEventModifiers,
  3279. 'interactions:action-move': addEventModifiers,
  3280. 'interactions:action-end': addEventModifiers,
  3281. 'interactions:after-action-start': function interactionsAfterActionStart(arg) {
  3282. return arg.interaction.modification.restoreInteractionCoords(arg);
  3283. },
  3284. 'interactions:after-action-move': function interactionsAfterActionMove(arg) {
  3285. return arg.interaction.modification.restoreInteractionCoords(arg);
  3286. },
  3287. 'interactions:stop': function interactionsStop(arg) {
  3288. return arg.interaction.modification.stop(arg);
  3289. }
  3290. }
  3291. };
  3292. var base = modifiersBase;
  3293. // eslint-disable-next-line @typescript-eslint/no-empty-interface
  3294. var defaults$7 = {
  3295. base: {
  3296. preventDefault: 'auto',
  3297. deltaSource: 'page'
  3298. },
  3299. perAction: {
  3300. enabled: false,
  3301. origin: {
  3302. x: 0,
  3303. y: 0
  3304. }
  3305. },
  3306. actions: {}
  3307. };
  3308. // defined outside of class definition to avoid assignment of undefined during
  3309. // construction
  3310. var InteractEvent = /*#__PURE__*/function (_BaseEvent) {
  3311. _inherits(InteractEvent, _BaseEvent);
  3312. var _super = _createSuper(InteractEvent);
  3313. function InteractEvent(interaction, event, actionName, phase, element, preEnd, type) {
  3314. var _this;
  3315. _classCallCheck(this, InteractEvent);
  3316. _this = _super.call(this, interaction);
  3317. _this.relatedTarget = null;
  3318. _this.screenX = void 0;
  3319. _this.screenY = void 0;
  3320. _this.button = void 0;
  3321. _this.buttons = void 0;
  3322. _this.ctrlKey = void 0;
  3323. _this.shiftKey = void 0;
  3324. _this.altKey = void 0;
  3325. _this.metaKey = void 0;
  3326. _this.page = void 0;
  3327. _this.client = void 0;
  3328. _this.delta = void 0;
  3329. _this.rect = void 0;
  3330. _this.x0 = void 0;
  3331. _this.y0 = void 0;
  3332. _this.t0 = void 0;
  3333. _this.dt = void 0;
  3334. _this.duration = void 0;
  3335. _this.clientX0 = void 0;
  3336. _this.clientY0 = void 0;
  3337. _this.velocity = void 0;
  3338. _this.speed = void 0;
  3339. _this.swipe = void 0;
  3340. // resize
  3341. _this.axes = void 0;
  3342. /** @internal */
  3343. _this.preEnd = void 0;
  3344. element = element || interaction.element;
  3345. var target = interaction.interactable;
  3346. var deltaSource = (target && target.options || defaults$7).deltaSource;
  3347. var origin = getOriginXY(target, element, actionName);
  3348. var starting = phase === 'start';
  3349. var ending = phase === 'end';
  3350. var prevEvent = starting ? _assertThisInitialized(_this) : interaction.prevEvent;
  3351. var coords = starting ? interaction.coords.start : ending ? {
  3352. page: prevEvent.page,
  3353. client: prevEvent.client,
  3354. timeStamp: interaction.coords.cur.timeStamp
  3355. } : interaction.coords.cur;
  3356. _this.page = extend({}, coords.page);
  3357. _this.client = extend({}, coords.client);
  3358. _this.rect = extend({}, interaction.rect);
  3359. _this.timeStamp = coords.timeStamp;
  3360. if (!ending) {
  3361. _this.page.x -= origin.x;
  3362. _this.page.y -= origin.y;
  3363. _this.client.x -= origin.x;
  3364. _this.client.y -= origin.y;
  3365. }
  3366. _this.ctrlKey = event.ctrlKey;
  3367. _this.altKey = event.altKey;
  3368. _this.shiftKey = event.shiftKey;
  3369. _this.metaKey = event.metaKey;
  3370. _this.button = event.button;
  3371. _this.buttons = event.buttons;
  3372. _this.target = element;
  3373. _this.currentTarget = element;
  3374. _this.preEnd = preEnd;
  3375. _this.type = type || actionName + (phase || '');
  3376. _this.interactable = target;
  3377. _this.t0 = starting ? interaction.pointers[interaction.pointers.length - 1].downTime : prevEvent.t0;
  3378. _this.x0 = interaction.coords.start.page.x - origin.x;
  3379. _this.y0 = interaction.coords.start.page.y - origin.y;
  3380. _this.clientX0 = interaction.coords.start.client.x - origin.x;
  3381. _this.clientY0 = interaction.coords.start.client.y - origin.y;
  3382. if (starting || ending) {
  3383. _this.delta = {
  3384. x: 0,
  3385. y: 0
  3386. };
  3387. } else {
  3388. _this.delta = {
  3389. x: _this[deltaSource].x - prevEvent[deltaSource].x,
  3390. y: _this[deltaSource].y - prevEvent[deltaSource].y
  3391. };
  3392. }
  3393. _this.dt = interaction.coords.delta.timeStamp;
  3394. _this.duration = _this.timeStamp - _this.t0;
  3395. // velocity and speed in pixels per second
  3396. _this.velocity = extend({}, interaction.coords.velocity[deltaSource]);
  3397. _this.speed = hypot(_this.velocity.x, _this.velocity.y);
  3398. _this.swipe = ending || phase === 'inertiastart' ? _this.getSwipe() : null;
  3399. return _this;
  3400. }
  3401. _createClass(InteractEvent, [{
  3402. key: "getSwipe",
  3403. value: function getSwipe() {
  3404. var interaction = this._interaction;
  3405. if (interaction.prevEvent.speed < 600 || this.timeStamp - interaction.prevEvent.timeStamp > 150) {
  3406. return null;
  3407. }
  3408. var angle = 180 * Math.atan2(interaction.prevEvent.velocityY, interaction.prevEvent.velocityX) / Math.PI;
  3409. var overlap = 22.5;
  3410. if (angle < 0) {
  3411. angle += 360;
  3412. }
  3413. var left = 135 - overlap <= angle && angle < 225 + overlap;
  3414. var up = 225 - overlap <= angle && angle < 315 + overlap;
  3415. var right = !left && (315 - overlap <= angle || angle < 45 + overlap);
  3416. var down = !up && 45 - overlap <= angle && angle < 135 + overlap;
  3417. return {
  3418. up: up,
  3419. down: down,
  3420. left: left,
  3421. right: right,
  3422. angle: angle,
  3423. speed: interaction.prevEvent.speed,
  3424. velocity: {
  3425. x: interaction.prevEvent.velocityX,
  3426. y: interaction.prevEvent.velocityY
  3427. }
  3428. };
  3429. }
  3430. }, {
  3431. key: "preventDefault",
  3432. value: function preventDefault() {}
  3433. /**
  3434. * Don't call listeners on the remaining targets
  3435. */
  3436. }, {
  3437. key: "stopImmediatePropagation",
  3438. value: function stopImmediatePropagation() {
  3439. this.immediatePropagationStopped = this.propagationStopped = true;
  3440. }
  3441. /**
  3442. * Don't call any other listeners (even on the current target)
  3443. */
  3444. }, {
  3445. key: "stopPropagation",
  3446. value: function stopPropagation() {
  3447. this.propagationStopped = true;
  3448. }
  3449. }]);
  3450. return InteractEvent;
  3451. }(BaseEvent);
  3452. // getters and setters defined here to support typescript 3.6 and below which
  3453. // don't support getter and setters in .d.ts files
  3454. Object.defineProperties(InteractEvent.prototype, {
  3455. pageX: {
  3456. get: function get() {
  3457. return this.page.x;
  3458. },
  3459. set: function set(value) {
  3460. this.page.x = value;
  3461. }
  3462. },
  3463. pageY: {
  3464. get: function get() {
  3465. return this.page.y;
  3466. },
  3467. set: function set(value) {
  3468. this.page.y = value;
  3469. }
  3470. },
  3471. clientX: {
  3472. get: function get() {
  3473. return this.client.x;
  3474. },
  3475. set: function set(value) {
  3476. this.client.x = value;
  3477. }
  3478. },
  3479. clientY: {
  3480. get: function get() {
  3481. return this.client.y;
  3482. },
  3483. set: function set(value) {
  3484. this.client.y = value;
  3485. }
  3486. },
  3487. dx: {
  3488. get: function get() {
  3489. return this.delta.x;
  3490. },
  3491. set: function set(value) {
  3492. this.delta.x = value;
  3493. }
  3494. },
  3495. dy: {
  3496. get: function get() {
  3497. return this.delta.y;
  3498. },
  3499. set: function set(value) {
  3500. this.delta.y = value;
  3501. }
  3502. },
  3503. velocityX: {
  3504. get: function get() {
  3505. return this.velocity.x;
  3506. },
  3507. set: function set(value) {
  3508. this.velocity.x = value;
  3509. }
  3510. },
  3511. velocityY: {
  3512. get: function get() {
  3513. return this.velocity.y;
  3514. },
  3515. set: function set(value) {
  3516. this.velocity.y = value;
  3517. }
  3518. }
  3519. });
  3520. var PointerInfo = /*#__PURE__*/_createClass(function PointerInfo(id, pointer, event, downTime, downTarget) {
  3521. _classCallCheck(this, PointerInfo);
  3522. this.id = void 0;
  3523. this.pointer = void 0;
  3524. this.event = void 0;
  3525. this.downTime = void 0;
  3526. this.downTarget = void 0;
  3527. this.id = id;
  3528. this.pointer = pointer;
  3529. this.event = event;
  3530. this.downTime = downTime;
  3531. this.downTarget = downTarget;
  3532. });
  3533. var _ProxyValues = /*#__PURE__*/function (_ProxyValues) {
  3534. _ProxyValues["interactable"] = "";
  3535. _ProxyValues["element"] = "";
  3536. _ProxyValues["prepared"] = "";
  3537. _ProxyValues["pointerIsDown"] = "";
  3538. _ProxyValues["pointerWasMoved"] = "";
  3539. _ProxyValues["_proxy"] = "";
  3540. return _ProxyValues;
  3541. }({});
  3542. var _ProxyMethods = /*#__PURE__*/function (_ProxyMethods) {
  3543. _ProxyMethods["start"] = "";
  3544. _ProxyMethods["move"] = "";
  3545. _ProxyMethods["end"] = "";
  3546. _ProxyMethods["stop"] = "";
  3547. _ProxyMethods["interacting"] = "";
  3548. return _ProxyMethods;
  3549. }({});
  3550. var idCounter = 0;
  3551. var Interaction = /*#__PURE__*/function () {
  3552. function Interaction(_ref) {
  3553. var _this = this;
  3554. var pointerType = _ref.pointerType,
  3555. scopeFire = _ref.scopeFire;
  3556. _classCallCheck(this, Interaction);
  3557. /** current interactable being interacted with */
  3558. this.interactable = null;
  3559. /** the target element of the interactable */
  3560. this.element = null;
  3561. this.rect = null;
  3562. /** @internal */
  3563. this._rects = void 0;
  3564. /** @internal */
  3565. this.edges = null;
  3566. /** @internal */
  3567. this._scopeFire = void 0;
  3568. // action that's ready to be fired on next move event
  3569. this.prepared = {
  3570. name: null,
  3571. axis: null,
  3572. edges: null
  3573. };
  3574. this.pointerType = void 0;
  3575. /** @internal keep track of added pointers */
  3576. this.pointers = [];
  3577. /** @internal pointerdown/mousedown/touchstart event */
  3578. this.downEvent = null;
  3579. /** @internal */
  3580. this.downPointer = {};
  3581. /** @internal */
  3582. this._latestPointer = {
  3583. pointer: null,
  3584. event: null,
  3585. eventTarget: null
  3586. };
  3587. /** @internal */
  3588. this.prevEvent = null;
  3589. this.pointerIsDown = false;
  3590. this.pointerWasMoved = false;
  3591. /** @internal */
  3592. this._interacting = false;
  3593. /** @internal */
  3594. this._ending = false;
  3595. /** @internal */
  3596. this._stopped = true;
  3597. /** @internal */
  3598. this._proxy = void 0;
  3599. /** @internal */
  3600. this.simulation = null;
  3601. this.doMove = warnOnce(function (signalArg) {
  3602. this.move(signalArg);
  3603. }, 'The interaction.doMove() method has been renamed to interaction.move()');
  3604. this.coords = {
  3605. // Starting InteractEvent pointer coordinates
  3606. start: newCoords(),
  3607. // Previous native pointer move event coordinates
  3608. prev: newCoords(),
  3609. // current native pointer move event coordinates
  3610. cur: newCoords(),
  3611. // Change in coordinates and time of the pointer
  3612. delta: newCoords(),
  3613. // pointer velocity
  3614. velocity: newCoords()
  3615. };
  3616. /** @internal */
  3617. this._id = idCounter++;
  3618. this._scopeFire = scopeFire;
  3619. this.pointerType = pointerType;
  3620. var that = this;
  3621. this._proxy = {};
  3622. var _loop = function _loop(key) {
  3623. Object.defineProperty(_this._proxy, key, {
  3624. get: function get() {
  3625. return that[key];
  3626. }
  3627. });
  3628. };
  3629. for (var key in _ProxyValues) {
  3630. _loop(key);
  3631. }
  3632. var _loop2 = function _loop2(_key) {
  3633. Object.defineProperty(_this._proxy, _key, {
  3634. value: function value() {
  3635. return that[_key].apply(that, arguments);
  3636. }
  3637. });
  3638. };
  3639. for (var _key in _ProxyMethods) {
  3640. _loop2(_key);
  3641. }
  3642. this._scopeFire('interactions:new', {
  3643. interaction: this
  3644. });
  3645. }
  3646. _createClass(Interaction, [{
  3647. key: "pointerMoveTolerance",
  3648. get: /** @internal */function get() {
  3649. return 1;
  3650. }
  3651. }, {
  3652. key: "pointerDown",
  3653. value: function pointerDown(pointer, event, eventTarget) {
  3654. var pointerIndex = this.updatePointer(pointer, event, eventTarget, true);
  3655. var pointerInfo = this.pointers[pointerIndex];
  3656. this._scopeFire('interactions:down', {
  3657. pointer: pointer,
  3658. event: event,
  3659. eventTarget: eventTarget,
  3660. pointerIndex: pointerIndex,
  3661. pointerInfo: pointerInfo,
  3662. type: 'down',
  3663. interaction: this
  3664. });
  3665. }
  3666. /**
  3667. * ```js
  3668. * interact(target)
  3669. * .draggable({
  3670. * // disable the default drag start by down->move
  3671. * manualStart: true
  3672. * })
  3673. * // start dragging after the user holds the pointer down
  3674. * .on('hold', function (event) {
  3675. * var interaction = event.interaction
  3676. *
  3677. * if (!interaction.interacting()) {
  3678. * interaction.start({ name: 'drag' },
  3679. * event.interactable,
  3680. * event.currentTarget)
  3681. * }
  3682. * })
  3683. * ```
  3684. *
  3685. * Start an action with the given Interactable and Element as tartgets. The
  3686. * action must be enabled for the target Interactable and an appropriate
  3687. * number of pointers must be held down - 1 for drag/resize, 2 for gesture.
  3688. *
  3689. * Use it with `interactable.<action>able({ manualStart: false })` to always
  3690. * [start actions manually](https://github.com/taye/interact.js/issues/114)
  3691. *
  3692. * @param action - The action to be performed - drag, resize, etc.
  3693. * @param target - The Interactable to target
  3694. * @param element - The DOM Element to target
  3695. * @returns Whether the interaction was successfully started
  3696. */
  3697. }, {
  3698. key: "start",
  3699. value: function start(action, interactable, element) {
  3700. if (this.interacting() || !this.pointerIsDown || this.pointers.length < (action.name === 'gesture' ? 2 : 1) || !interactable.options[action.name].enabled) {
  3701. return false;
  3702. }
  3703. copyAction(this.prepared, action);
  3704. this.interactable = interactable;
  3705. this.element = element;
  3706. this.rect = interactable.getRect(element);
  3707. this.edges = this.prepared.edges ? extend({}, this.prepared.edges) : {
  3708. left: true,
  3709. right: true,
  3710. top: true,
  3711. bottom: true
  3712. };
  3713. this._stopped = false;
  3714. this._interacting = this._doPhase({
  3715. interaction: this,
  3716. event: this.downEvent,
  3717. phase: 'start'
  3718. }) && !this._stopped;
  3719. return this._interacting;
  3720. }
  3721. }, {
  3722. key: "pointerMove",
  3723. value: function pointerMove(pointer, event, eventTarget) {
  3724. if (!this.simulation && !(this.modification && this.modification.endResult)) {
  3725. this.updatePointer(pointer, event, eventTarget, false);
  3726. }
  3727. var duplicateMove = this.coords.cur.page.x === this.coords.prev.page.x && this.coords.cur.page.y === this.coords.prev.page.y && this.coords.cur.client.x === this.coords.prev.client.x && this.coords.cur.client.y === this.coords.prev.client.y;
  3728. var dx;
  3729. var dy;
  3730. // register movement greater than pointerMoveTolerance
  3731. if (this.pointerIsDown && !this.pointerWasMoved) {
  3732. dx = this.coords.cur.client.x - this.coords.start.client.x;
  3733. dy = this.coords.cur.client.y - this.coords.start.client.y;
  3734. this.pointerWasMoved = hypot(dx, dy) > this.pointerMoveTolerance;
  3735. }
  3736. var pointerIndex = this.getPointerIndex(pointer);
  3737. var signalArg = {
  3738. pointer: pointer,
  3739. pointerIndex: pointerIndex,
  3740. pointerInfo: this.pointers[pointerIndex],
  3741. event: event,
  3742. type: 'move',
  3743. eventTarget: eventTarget,
  3744. dx: dx,
  3745. dy: dy,
  3746. duplicate: duplicateMove,
  3747. interaction: this
  3748. };
  3749. if (!duplicateMove) {
  3750. // set pointer coordinate, time changes and velocity
  3751. setCoordVelocity(this.coords.velocity, this.coords.delta);
  3752. }
  3753. this._scopeFire('interactions:move', signalArg);
  3754. if (!duplicateMove && !this.simulation) {
  3755. // if interacting, fire an 'action-move' signal etc
  3756. if (this.interacting()) {
  3757. signalArg.type = null;
  3758. this.move(signalArg);
  3759. }
  3760. if (this.pointerWasMoved) {
  3761. copyCoords(this.coords.prev, this.coords.cur);
  3762. }
  3763. }
  3764. }
  3765. /**
  3766. * ```js
  3767. * interact(target)
  3768. * .draggable(true)
  3769. * .on('dragmove', function (event) {
  3770. * if (someCondition) {
  3771. * // change the snap settings
  3772. * event.interactable.draggable({ snap: { targets: [] }})
  3773. * // fire another move event with re-calculated snap
  3774. * event.interaction.move()
  3775. * }
  3776. * })
  3777. * ```
  3778. *
  3779. * Force a move of the current action at the same coordinates. Useful if
  3780. * snap/restrict has been changed and you want a movement with the new
  3781. * settings.
  3782. */
  3783. }, {
  3784. key: "move",
  3785. value: function move(signalArg) {
  3786. if (!signalArg || !signalArg.event) {
  3787. setZeroCoords(this.coords.delta);
  3788. }
  3789. signalArg = extend({
  3790. pointer: this._latestPointer.pointer,
  3791. event: this._latestPointer.event,
  3792. eventTarget: this._latestPointer.eventTarget,
  3793. interaction: this
  3794. }, signalArg || {});
  3795. signalArg.phase = 'move';
  3796. this._doPhase(signalArg);
  3797. }
  3798. /**
  3799. * @internal
  3800. * End interact move events and stop auto-scroll unless simulation is running
  3801. */
  3802. }, {
  3803. key: "pointerUp",
  3804. value: function pointerUp(pointer, event, eventTarget, curEventTarget) {
  3805. var pointerIndex = this.getPointerIndex(pointer);
  3806. if (pointerIndex === -1) {
  3807. pointerIndex = this.updatePointer(pointer, event, eventTarget, false);
  3808. }
  3809. var type = /cancel$/i.test(event.type) ? 'cancel' : 'up';
  3810. this._scopeFire("interactions:".concat(type), {
  3811. pointer: pointer,
  3812. pointerIndex: pointerIndex,
  3813. pointerInfo: this.pointers[pointerIndex],
  3814. event: event,
  3815. eventTarget: eventTarget,
  3816. type: type,
  3817. curEventTarget: curEventTarget,
  3818. interaction: this
  3819. });
  3820. if (!this.simulation) {
  3821. this.end(event);
  3822. }
  3823. this.removePointer(pointer, event);
  3824. }
  3825. /** @internal */
  3826. }, {
  3827. key: "documentBlur",
  3828. value: function documentBlur(event) {
  3829. this.end(event);
  3830. this._scopeFire('interactions:blur', {
  3831. event: event,
  3832. type: 'blur',
  3833. interaction: this
  3834. });
  3835. }
  3836. /**
  3837. * ```js
  3838. * interact(target)
  3839. * .draggable(true)
  3840. * .on('move', function (event) {
  3841. * if (event.pageX > 1000) {
  3842. * // end the current action
  3843. * event.interaction.end()
  3844. * // stop all further listeners from being called
  3845. * event.stopImmediatePropagation()
  3846. * }
  3847. * })
  3848. * ```
  3849. */
  3850. }, {
  3851. key: "end",
  3852. value: function end(event) {
  3853. this._ending = true;
  3854. event = event || this._latestPointer.event;
  3855. var endPhaseResult;
  3856. if (this.interacting()) {
  3857. endPhaseResult = this._doPhase({
  3858. event: event,
  3859. interaction: this,
  3860. phase: 'end'
  3861. });
  3862. }
  3863. this._ending = false;
  3864. if (endPhaseResult === true) {
  3865. this.stop();
  3866. }
  3867. }
  3868. }, {
  3869. key: "currentAction",
  3870. value: function currentAction() {
  3871. return this._interacting ? this.prepared.name : null;
  3872. }
  3873. }, {
  3874. key: "interacting",
  3875. value: function interacting() {
  3876. return this._interacting;
  3877. }
  3878. }, {
  3879. key: "stop",
  3880. value: function stop() {
  3881. this._scopeFire('interactions:stop', {
  3882. interaction: this
  3883. });
  3884. this.interactable = this.element = null;
  3885. this._interacting = false;
  3886. this._stopped = true;
  3887. this.prepared.name = this.prevEvent = null;
  3888. }
  3889. /** @internal */
  3890. }, {
  3891. key: "getPointerIndex",
  3892. value: function getPointerIndex(pointer) {
  3893. var pointerId = getPointerId(pointer);
  3894. // mouse and pen interactions may have only one pointer
  3895. return this.pointerType === 'mouse' || this.pointerType === 'pen' ? this.pointers.length - 1 : findIndex(this.pointers, function (curPointer) {
  3896. return curPointer.id === pointerId;
  3897. });
  3898. }
  3899. /** @internal */
  3900. }, {
  3901. key: "getPointerInfo",
  3902. value: function getPointerInfo(pointer) {
  3903. return this.pointers[this.getPointerIndex(pointer)];
  3904. }
  3905. /** @internal */
  3906. }, {
  3907. key: "updatePointer",
  3908. value: function updatePointer(pointer, event, eventTarget, down) {
  3909. var id = getPointerId(pointer);
  3910. var pointerIndex = this.getPointerIndex(pointer);
  3911. var pointerInfo = this.pointers[pointerIndex];
  3912. down = down === false ? false : down || /(down|start)$/i.test(event.type);
  3913. if (!pointerInfo) {
  3914. pointerInfo = new PointerInfo(id, pointer, event, null, null);
  3915. pointerIndex = this.pointers.length;
  3916. this.pointers.push(pointerInfo);
  3917. } else {
  3918. pointerInfo.pointer = pointer;
  3919. }
  3920. setCoords(this.coords.cur, this.pointers.map(function (p) {
  3921. return p.pointer;
  3922. }), this._now());
  3923. setCoordDeltas(this.coords.delta, this.coords.prev, this.coords.cur);
  3924. if (down) {
  3925. this.pointerIsDown = true;
  3926. pointerInfo.downTime = this.coords.cur.timeStamp;
  3927. pointerInfo.downTarget = eventTarget;
  3928. pointerExtend(this.downPointer, pointer);
  3929. if (!this.interacting()) {
  3930. copyCoords(this.coords.start, this.coords.cur);
  3931. copyCoords(this.coords.prev, this.coords.cur);
  3932. this.downEvent = event;
  3933. this.pointerWasMoved = false;
  3934. }
  3935. }
  3936. this._updateLatestPointer(pointer, event, eventTarget);
  3937. this._scopeFire('interactions:update-pointer', {
  3938. pointer: pointer,
  3939. event: event,
  3940. eventTarget: eventTarget,
  3941. down: down,
  3942. pointerInfo: pointerInfo,
  3943. pointerIndex: pointerIndex,
  3944. interaction: this
  3945. });
  3946. return pointerIndex;
  3947. }
  3948. /** @internal */
  3949. }, {
  3950. key: "removePointer",
  3951. value: function removePointer(pointer, event) {
  3952. var pointerIndex = this.getPointerIndex(pointer);
  3953. if (pointerIndex === -1) return;
  3954. var pointerInfo = this.pointers[pointerIndex];
  3955. this._scopeFire('interactions:remove-pointer', {
  3956. pointer: pointer,
  3957. event: event,
  3958. eventTarget: null,
  3959. pointerIndex: pointerIndex,
  3960. pointerInfo: pointerInfo,
  3961. interaction: this
  3962. });
  3963. this.pointers.splice(pointerIndex, 1);
  3964. this.pointerIsDown = false;
  3965. }
  3966. /** @internal */
  3967. }, {
  3968. key: "_updateLatestPointer",
  3969. value: function _updateLatestPointer(pointer, event, eventTarget) {
  3970. this._latestPointer.pointer = pointer;
  3971. this._latestPointer.event = event;
  3972. this._latestPointer.eventTarget = eventTarget;
  3973. }
  3974. }, {
  3975. key: "destroy",
  3976. value: function destroy() {
  3977. this._latestPointer.pointer = null;
  3978. this._latestPointer.event = null;
  3979. this._latestPointer.eventTarget = null;
  3980. }
  3981. /** @internal */
  3982. }, {
  3983. key: "_createPreparedEvent",
  3984. value: function _createPreparedEvent(event, phase, preEnd, type) {
  3985. return new InteractEvent(this, event, this.prepared.name, phase, this.element, preEnd, type);
  3986. }
  3987. /** @internal */
  3988. }, {
  3989. key: "_fireEvent",
  3990. value: function _fireEvent(iEvent) {
  3991. var _this$interactable;
  3992. (_this$interactable = this.interactable) == null ? void 0 : _this$interactable.fire(iEvent);
  3993. if (!this.prevEvent || iEvent.timeStamp >= this.prevEvent.timeStamp) {
  3994. this.prevEvent = iEvent;
  3995. }
  3996. }
  3997. /** @internal */
  3998. }, {
  3999. key: "_doPhase",
  4000. value: function _doPhase(signalArg) {
  4001. var event = signalArg.event,
  4002. phase = signalArg.phase,
  4003. preEnd = signalArg.preEnd,
  4004. type = signalArg.type;
  4005. var rect = this.rect;
  4006. if (rect && phase === 'move') {
  4007. // update the rect changes due to pointer move
  4008. addEdges(this.edges, rect, this.coords.delta[this.interactable.options.deltaSource]);
  4009. rect.width = rect.right - rect.left;
  4010. rect.height = rect.bottom - rect.top;
  4011. }
  4012. var beforeResult = this._scopeFire("interactions:before-action-".concat(phase), signalArg);
  4013. if (beforeResult === false) {
  4014. return false;
  4015. }
  4016. var iEvent = signalArg.iEvent = this._createPreparedEvent(event, phase, preEnd, type);
  4017. this._scopeFire("interactions:action-".concat(phase), signalArg);
  4018. if (phase === 'start') {
  4019. this.prevEvent = iEvent;
  4020. }
  4021. this._fireEvent(iEvent);
  4022. this._scopeFire("interactions:after-action-".concat(phase), signalArg);
  4023. return true;
  4024. }
  4025. /** @internal */
  4026. }, {
  4027. key: "_now",
  4028. value: function _now() {
  4029. return Date.now();
  4030. }
  4031. }]);
  4032. return Interaction;
  4033. }();
  4034. _ProxyMethods.offsetBy = '';
  4035. function addTotal(interaction) {
  4036. if (!interaction.pointerIsDown) {
  4037. return;
  4038. }
  4039. addToCoords(interaction.coords.cur, interaction.offset.total);
  4040. interaction.offset.pending.x = 0;
  4041. interaction.offset.pending.y = 0;
  4042. }
  4043. function beforeAction(_ref) {
  4044. var interaction = _ref.interaction;
  4045. applyPending(interaction);
  4046. }
  4047. function beforeEnd(_ref2) {
  4048. var interaction = _ref2.interaction;
  4049. var hadPending = applyPending(interaction);
  4050. if (!hadPending) return;
  4051. interaction.move({
  4052. offset: true
  4053. });
  4054. interaction.end();
  4055. return false;
  4056. }
  4057. function end(_ref3) {
  4058. var interaction = _ref3.interaction;
  4059. interaction.offset.total.x = 0;
  4060. interaction.offset.total.y = 0;
  4061. interaction.offset.pending.x = 0;
  4062. interaction.offset.pending.y = 0;
  4063. }
  4064. function applyPending(interaction) {
  4065. if (!hasPending(interaction)) {
  4066. return false;
  4067. }
  4068. var pending = interaction.offset.pending;
  4069. addToCoords(interaction.coords.cur, pending);
  4070. addToCoords(interaction.coords.delta, pending);
  4071. addEdges(interaction.edges, interaction.rect, pending);
  4072. pending.x = 0;
  4073. pending.y = 0;
  4074. return true;
  4075. }
  4076. function offsetBy(_ref4) {
  4077. var x = _ref4.x,
  4078. y = _ref4.y;
  4079. this.offset.pending.x += x;
  4080. this.offset.pending.y += y;
  4081. this.offset.total.x += x;
  4082. this.offset.total.y += y;
  4083. }
  4084. function addToCoords(_ref5, _ref6) {
  4085. var page = _ref5.page,
  4086. client = _ref5.client;
  4087. var x = _ref6.x,
  4088. y = _ref6.y;
  4089. page.x += x;
  4090. page.y += y;
  4091. client.x += x;
  4092. client.y += y;
  4093. }
  4094. function hasPending(interaction) {
  4095. return !!(interaction.offset.pending.x || interaction.offset.pending.y);
  4096. }
  4097. var offset = {
  4098. id: 'offset',
  4099. before: ['modifiers', 'pointer-events', 'actions', 'inertia'],
  4100. install: function install(scope) {
  4101. scope.Interaction.prototype.offsetBy = offsetBy;
  4102. },
  4103. listeners: {
  4104. 'interactions:new': function interactionsNew(_ref7) {
  4105. var interaction = _ref7.interaction;
  4106. interaction.offset = {
  4107. total: {
  4108. x: 0,
  4109. y: 0
  4110. },
  4111. pending: {
  4112. x: 0,
  4113. y: 0
  4114. }
  4115. };
  4116. },
  4117. 'interactions:update-pointer': function interactionsUpdatePointer(_ref8) {
  4118. var interaction = _ref8.interaction;
  4119. return addTotal(interaction);
  4120. },
  4121. 'interactions:before-action-start': beforeAction,
  4122. 'interactions:before-action-move': beforeAction,
  4123. 'interactions:before-action-end': beforeEnd,
  4124. 'interactions:stop': end
  4125. }
  4126. };
  4127. var offset$1 = offset;
  4128. function install$6(scope) {
  4129. var defaults = scope.defaults;
  4130. scope.usePlugin(offset$1);
  4131. scope.usePlugin(base);
  4132. scope.actions.phases.inertiastart = true;
  4133. scope.actions.phases.resume = true;
  4134. defaults.perAction.inertia = {
  4135. enabled: false,
  4136. resistance: 10,
  4137. // the lambda in exponential decay
  4138. minSpeed: 100,
  4139. // target speed must be above this for inertia to start
  4140. endSpeed: 10,
  4141. // the speed at which inertia is slow enough to stop
  4142. allowResume: true,
  4143. // allow resuming an action in inertia phase
  4144. smoothEndDuration: 300 // animate to snap/restrict endOnly if there's no inertia
  4145. };
  4146. }
  4147. var InertiaState = /*#__PURE__*/function () {
  4148. function InertiaState(interaction) {
  4149. _classCallCheck(this, InertiaState);
  4150. this.active = false;
  4151. this.isModified = false;
  4152. this.smoothEnd = false;
  4153. this.allowResume = false;
  4154. this.modification = void 0;
  4155. this.modifierCount = 0;
  4156. this.modifierArg = void 0;
  4157. this.startCoords = void 0;
  4158. this.t0 = 0;
  4159. this.v0 = 0;
  4160. this.te = 0;
  4161. this.targetOffset = void 0;
  4162. this.modifiedOffset = void 0;
  4163. this.currentOffset = void 0;
  4164. this.lambda_v0 = 0;
  4165. // eslint-disable-line camelcase
  4166. this.one_ve_v0 = 0;
  4167. // eslint-disable-line camelcase
  4168. this.timeout = void 0;
  4169. this.interaction = void 0;
  4170. this.interaction = interaction;
  4171. }
  4172. _createClass(InertiaState, [{
  4173. key: "start",
  4174. value: function start(event) {
  4175. var interaction = this.interaction;
  4176. var options = getOptions$1(interaction);
  4177. if (!options || !options.enabled) {
  4178. return false;
  4179. }
  4180. var velocityClient = interaction.coords.velocity.client;
  4181. var pointerSpeed = hypot(velocityClient.x, velocityClient.y);
  4182. var modification = this.modification || (this.modification = new Modification(interaction));
  4183. modification.copyFrom(interaction.modification);
  4184. this.t0 = interaction._now();
  4185. this.allowResume = options.allowResume;
  4186. this.v0 = pointerSpeed;
  4187. this.currentOffset = {
  4188. x: 0,
  4189. y: 0
  4190. };
  4191. this.startCoords = interaction.coords.cur.page;
  4192. this.modifierArg = modification.fillArg({
  4193. pageCoords: this.startCoords,
  4194. preEnd: true,
  4195. phase: 'inertiastart'
  4196. });
  4197. var thrown = this.t0 - interaction.coords.cur.timeStamp < 50 && pointerSpeed > options.minSpeed && pointerSpeed > options.endSpeed;
  4198. if (thrown) {
  4199. this.startInertia();
  4200. } else {
  4201. modification.result = modification.setAll(this.modifierArg);
  4202. if (!modification.result.changed) {
  4203. return false;
  4204. }
  4205. this.startSmoothEnd();
  4206. }
  4207. // force modification change
  4208. interaction.modification.result.rect = null;
  4209. // bring inertiastart event to the target coords
  4210. interaction.offsetBy(this.targetOffset);
  4211. interaction._doPhase({
  4212. interaction: interaction,
  4213. event: event,
  4214. phase: 'inertiastart'
  4215. });
  4216. interaction.offsetBy({
  4217. x: -this.targetOffset.x,
  4218. y: -this.targetOffset.y
  4219. });
  4220. // force modification change
  4221. interaction.modification.result.rect = null;
  4222. this.active = true;
  4223. interaction.simulation = this;
  4224. return true;
  4225. }
  4226. }, {
  4227. key: "startInertia",
  4228. value: function startInertia() {
  4229. var _this = this;
  4230. var startVelocity = this.interaction.coords.velocity.client;
  4231. var options = getOptions$1(this.interaction);
  4232. var lambda = options.resistance;
  4233. var inertiaDur = -Math.log(options.endSpeed / this.v0) / lambda;
  4234. this.targetOffset = {
  4235. x: (startVelocity.x - inertiaDur) / lambda,
  4236. y: (startVelocity.y - inertiaDur) / lambda
  4237. };
  4238. this.te = inertiaDur;
  4239. this.lambda_v0 = lambda / this.v0;
  4240. this.one_ve_v0 = 1 - options.endSpeed / this.v0;
  4241. var modification = this.modification,
  4242. modifierArg = this.modifierArg;
  4243. modifierArg.pageCoords = {
  4244. x: this.startCoords.x + this.targetOffset.x,
  4245. y: this.startCoords.y + this.targetOffset.y
  4246. };
  4247. modification.result = modification.setAll(modifierArg);
  4248. if (modification.result.changed) {
  4249. this.isModified = true;
  4250. this.modifiedOffset = {
  4251. x: this.targetOffset.x + modification.result.delta.x,
  4252. y: this.targetOffset.y + modification.result.delta.y
  4253. };
  4254. }
  4255. this.onNextFrame(function () {
  4256. return _this.inertiaTick();
  4257. });
  4258. }
  4259. }, {
  4260. key: "startSmoothEnd",
  4261. value: function startSmoothEnd() {
  4262. var _this2 = this;
  4263. this.smoothEnd = true;
  4264. this.isModified = true;
  4265. this.targetOffset = {
  4266. x: this.modification.result.delta.x,
  4267. y: this.modification.result.delta.y
  4268. };
  4269. this.onNextFrame(function () {
  4270. return _this2.smoothEndTick();
  4271. });
  4272. }
  4273. }, {
  4274. key: "onNextFrame",
  4275. value: function onNextFrame(tickFn) {
  4276. var _this3 = this;
  4277. this.timeout = raf.request(function () {
  4278. if (_this3.active) {
  4279. tickFn();
  4280. }
  4281. });
  4282. }
  4283. }, {
  4284. key: "inertiaTick",
  4285. value: function inertiaTick() {
  4286. var _this4 = this;
  4287. var interaction = this.interaction;
  4288. var options = getOptions$1(interaction);
  4289. var lambda = options.resistance;
  4290. var t = (interaction._now() - this.t0) / 1000;
  4291. if (t < this.te) {
  4292. var progress = 1 - (Math.exp(-lambda * t) - this.lambda_v0) / this.one_ve_v0;
  4293. var newOffset;
  4294. if (this.isModified) {
  4295. newOffset = getQuadraticCurvePoint(0, 0, this.targetOffset.x, this.targetOffset.y, this.modifiedOffset.x, this.modifiedOffset.y, progress);
  4296. } else {
  4297. newOffset = {
  4298. x: this.targetOffset.x * progress,
  4299. y: this.targetOffset.y * progress
  4300. };
  4301. }
  4302. var delta = {
  4303. x: newOffset.x - this.currentOffset.x,
  4304. y: newOffset.y - this.currentOffset.y
  4305. };
  4306. this.currentOffset.x += delta.x;
  4307. this.currentOffset.y += delta.y;
  4308. interaction.offsetBy(delta);
  4309. interaction.move();
  4310. this.onNextFrame(function () {
  4311. return _this4.inertiaTick();
  4312. });
  4313. } else {
  4314. interaction.offsetBy({
  4315. x: this.modifiedOffset.x - this.currentOffset.x,
  4316. y: this.modifiedOffset.y - this.currentOffset.y
  4317. });
  4318. this.end();
  4319. }
  4320. }
  4321. }, {
  4322. key: "smoothEndTick",
  4323. value: function smoothEndTick() {
  4324. var _this5 = this;
  4325. var interaction = this.interaction;
  4326. var t = interaction._now() - this.t0;
  4327. var _getOptions = getOptions$1(interaction),
  4328. duration = _getOptions.smoothEndDuration;
  4329. if (t < duration) {
  4330. var newOffset = {
  4331. x: easeOutQuad(t, 0, this.targetOffset.x, duration),
  4332. y: easeOutQuad(t, 0, this.targetOffset.y, duration)
  4333. };
  4334. var delta = {
  4335. x: newOffset.x - this.currentOffset.x,
  4336. y: newOffset.y - this.currentOffset.y
  4337. };
  4338. this.currentOffset.x += delta.x;
  4339. this.currentOffset.y += delta.y;
  4340. interaction.offsetBy(delta);
  4341. interaction.move({
  4342. skipModifiers: this.modifierCount
  4343. });
  4344. this.onNextFrame(function () {
  4345. return _this5.smoothEndTick();
  4346. });
  4347. } else {
  4348. interaction.offsetBy({
  4349. x: this.targetOffset.x - this.currentOffset.x,
  4350. y: this.targetOffset.y - this.currentOffset.y
  4351. });
  4352. this.end();
  4353. }
  4354. }
  4355. }, {
  4356. key: "resume",
  4357. value: function resume(_ref) {
  4358. var pointer = _ref.pointer,
  4359. event = _ref.event,
  4360. eventTarget = _ref.eventTarget;
  4361. var interaction = this.interaction;
  4362. // undo inertia changes to interaction coords
  4363. interaction.offsetBy({
  4364. x: -this.currentOffset.x,
  4365. y: -this.currentOffset.y
  4366. });
  4367. // update pointer at pointer down position
  4368. interaction.updatePointer(pointer, event, eventTarget, true);
  4369. // fire resume signals and event
  4370. interaction._doPhase({
  4371. interaction: interaction,
  4372. event: event,
  4373. phase: 'resume'
  4374. });
  4375. copyCoords(interaction.coords.prev, interaction.coords.cur);
  4376. this.stop();
  4377. }
  4378. }, {
  4379. key: "end",
  4380. value: function end() {
  4381. this.interaction.move();
  4382. this.interaction.end();
  4383. this.stop();
  4384. }
  4385. }, {
  4386. key: "stop",
  4387. value: function stop() {
  4388. this.active = this.smoothEnd = false;
  4389. this.interaction.simulation = null;
  4390. raf.cancel(this.timeout);
  4391. }
  4392. }]);
  4393. return InertiaState;
  4394. }();
  4395. function start$6(_ref2) {
  4396. var interaction = _ref2.interaction,
  4397. event = _ref2.event;
  4398. if (!interaction._interacting || interaction.simulation) {
  4399. return null;
  4400. }
  4401. var started = interaction.inertia.start(event);
  4402. // prevent action end if inertia or smoothEnd
  4403. return started ? false : null;
  4404. }
  4405. // Check if the down event hits the current inertia target
  4406. // control should be return to the user
  4407. function resume(arg) {
  4408. var interaction = arg.interaction,
  4409. eventTarget = arg.eventTarget;
  4410. var state = interaction.inertia;
  4411. if (!state.active) return;
  4412. var element = eventTarget;
  4413. // climb up the DOM tree from the event target
  4414. while (is.element(element)) {
  4415. // if interaction element is the current inertia target element
  4416. if (element === interaction.element) {
  4417. state.resume(arg);
  4418. break;
  4419. }
  4420. element = parentNode(element);
  4421. }
  4422. }
  4423. function stop(_ref3) {
  4424. var interaction = _ref3.interaction;
  4425. var state = interaction.inertia;
  4426. if (state.active) {
  4427. state.stop();
  4428. }
  4429. }
  4430. function getOptions$1(_ref4) {
  4431. var interactable = _ref4.interactable,
  4432. prepared = _ref4.prepared;
  4433. return interactable && interactable.options && prepared.name && interactable.options[prepared.name].inertia;
  4434. }
  4435. var inertia = {
  4436. id: 'inertia',
  4437. before: ['modifiers', 'actions'],
  4438. install: install$6,
  4439. listeners: {
  4440. 'interactions:new': function interactionsNew(_ref5) {
  4441. var interaction = _ref5.interaction;
  4442. interaction.inertia = new InertiaState(interaction);
  4443. },
  4444. 'interactions:before-action-end': start$6,
  4445. 'interactions:down': resume,
  4446. 'interactions:stop': stop,
  4447. 'interactions:before-action-resume': function interactionsBeforeActionResume(arg) {
  4448. var modification = arg.interaction.modification;
  4449. modification.stop(arg);
  4450. modification.start(arg, arg.interaction.coords.cur.page);
  4451. modification.applyToInteraction(arg);
  4452. },
  4453. 'interactions:before-action-inertiastart': function interactionsBeforeActionInertiastart(arg) {
  4454. return arg.interaction.modification.setAndApply(arg);
  4455. },
  4456. 'interactions:action-resume': addEventModifiers,
  4457. 'interactions:action-inertiastart': addEventModifiers,
  4458. 'interactions:after-action-inertiastart': function interactionsAfterActionInertiastart(arg) {
  4459. return arg.interaction.modification.restoreInteractionCoords(arg);
  4460. },
  4461. 'interactions:after-action-resume': function interactionsAfterActionResume(arg) {
  4462. return arg.interaction.modification.restoreInteractionCoords(arg);
  4463. }
  4464. }
  4465. };
  4466. // http://stackoverflow.com/a/5634528/2280888
  4467. function _getQBezierValue(t, p1, p2, p3) {
  4468. var iT = 1 - t;
  4469. return iT * iT * p1 + 2 * iT * t * p2 + t * t * p3;
  4470. }
  4471. function getQuadraticCurvePoint(startX, startY, cpX, cpY, endX, endY, position) {
  4472. return {
  4473. x: _getQBezierValue(position, startX, cpX, endX),
  4474. y: _getQBezierValue(position, startY, cpY, endY)
  4475. };
  4476. }
  4477. // http://gizma.com/easing/
  4478. function easeOutQuad(t, b, c, d) {
  4479. t /= d;
  4480. return -c * t * (t - 2) + b;
  4481. }
  4482. var inertia$1 = inertia;
  4483. function fireUntilImmediateStopped(event, listeners) {
  4484. for (var _i2 = 0; _i2 < listeners.length; _i2++) {
  4485. var listener = listeners[_i2];
  4486. if (event.immediatePropagationStopped) {
  4487. break;
  4488. }
  4489. listener(event);
  4490. }
  4491. }
  4492. var Eventable = /*#__PURE__*/function () {
  4493. function Eventable(options) {
  4494. _classCallCheck(this, Eventable);
  4495. this.options = void 0;
  4496. this.types = {};
  4497. this.propagationStopped = false;
  4498. this.immediatePropagationStopped = false;
  4499. this.global = void 0;
  4500. this.options = extend({}, options || {});
  4501. }
  4502. _createClass(Eventable, [{
  4503. key: "fire",
  4504. value: function fire(event) {
  4505. var listeners;
  4506. var global = this.global;
  4507. // Interactable#on() listeners
  4508. // tslint:disable no-conditional-assignment
  4509. if (listeners = this.types[event.type]) {
  4510. fireUntilImmediateStopped(event, listeners);
  4511. }
  4512. // interact.on() listeners
  4513. if (!event.propagationStopped && global && (listeners = global[event.type])) {
  4514. fireUntilImmediateStopped(event, listeners);
  4515. }
  4516. }
  4517. }, {
  4518. key: "on",
  4519. value: function on(type, listener) {
  4520. var listeners = normalize(type, listener);
  4521. for (type in listeners) {
  4522. this.types[type] = merge(this.types[type] || [], listeners[type]);
  4523. }
  4524. }
  4525. }, {
  4526. key: "off",
  4527. value: function off(type, listener) {
  4528. var listeners = normalize(type, listener);
  4529. for (type in listeners) {
  4530. var eventList = this.types[type];
  4531. if (!eventList || !eventList.length) {
  4532. continue;
  4533. }
  4534. for (var _i4 = 0, _listeners$type2 = listeners[type]; _i4 < _listeners$type2.length; _i4++) {
  4535. var subListener = _listeners$type2[_i4];
  4536. var _index = eventList.indexOf(subListener);
  4537. if (_index !== -1) {
  4538. eventList.splice(_index, 1);
  4539. }
  4540. }
  4541. }
  4542. }
  4543. }, {
  4544. key: "getRect",
  4545. value: function getRect(_element) {
  4546. return null;
  4547. }
  4548. }]);
  4549. return Eventable;
  4550. }();
  4551. function install$5(scope) {
  4552. var _scope$document;
  4553. var targets = [];
  4554. var delegatedEvents = {};
  4555. var documents = [];
  4556. var eventsMethods = {
  4557. add: add,
  4558. remove: remove,
  4559. addDelegate: addDelegate,
  4560. removeDelegate: removeDelegate,
  4561. delegateListener: delegateListener,
  4562. delegateUseCapture: delegateUseCapture,
  4563. delegatedEvents: delegatedEvents,
  4564. documents: documents,
  4565. targets: targets,
  4566. supportsOptions: false,
  4567. supportsPassive: false
  4568. };
  4569. // check if browser supports passive events and options arg
  4570. (_scope$document = scope.document) == null ? void 0 : _scope$document.createElement('div').addEventListener('test', null, {
  4571. get capture() {
  4572. return eventsMethods.supportsOptions = true;
  4573. },
  4574. get passive() {
  4575. return eventsMethods.supportsPassive = true;
  4576. }
  4577. });
  4578. scope.events = eventsMethods;
  4579. function add(eventTarget, type, listener, optionalArg) {
  4580. if (!eventTarget.addEventListener) return;
  4581. var options = getOptions(optionalArg);
  4582. var target = find(targets, function (t) {
  4583. return t.eventTarget === eventTarget;
  4584. });
  4585. if (!target) {
  4586. target = {
  4587. eventTarget: eventTarget,
  4588. events: {}
  4589. };
  4590. targets.push(target);
  4591. }
  4592. if (!target.events[type]) {
  4593. target.events[type] = [];
  4594. }
  4595. if (!find(target.events[type], function (l) {
  4596. return l.func === listener && optionsMatch(l.options, options);
  4597. })) {
  4598. eventTarget.addEventListener(type, listener, eventsMethods.supportsOptions ? options : options.capture);
  4599. target.events[type].push({
  4600. func: listener,
  4601. options: options
  4602. });
  4603. }
  4604. }
  4605. function remove(eventTarget, type, listener, optionalArg) {
  4606. if (!eventTarget.addEventListener || !eventTarget.removeEventListener) return;
  4607. var targetIndex = findIndex(targets, function (t) {
  4608. return t.eventTarget === eventTarget;
  4609. });
  4610. var target = targets[targetIndex];
  4611. if (!target || !target.events) {
  4612. return;
  4613. }
  4614. if (type === 'all') {
  4615. for (type in target.events) {
  4616. if (target.events.hasOwnProperty(type)) {
  4617. remove(eventTarget, type, 'all');
  4618. }
  4619. }
  4620. return;
  4621. }
  4622. var typeIsEmpty = false;
  4623. var typeListeners = target.events[type];
  4624. if (typeListeners) {
  4625. if (listener === 'all') {
  4626. for (var i = typeListeners.length - 1; i >= 0; i--) {
  4627. var entry = typeListeners[i];
  4628. remove(eventTarget, type, entry.func, entry.options);
  4629. }
  4630. return;
  4631. } else {
  4632. var options = getOptions(optionalArg);
  4633. for (var _i = 0; _i < typeListeners.length; _i++) {
  4634. var _entry = typeListeners[_i];
  4635. if (_entry.func === listener && optionsMatch(_entry.options, options)) {
  4636. eventTarget.removeEventListener(type, listener, eventsMethods.supportsOptions ? options : options.capture);
  4637. typeListeners.splice(_i, 1);
  4638. if (typeListeners.length === 0) {
  4639. delete target.events[type];
  4640. typeIsEmpty = true;
  4641. }
  4642. break;
  4643. }
  4644. }
  4645. }
  4646. }
  4647. if (typeIsEmpty && !Object.keys(target.events).length) {
  4648. targets.splice(targetIndex, 1);
  4649. }
  4650. }
  4651. function addDelegate(selector, context, type, listener, optionalArg) {
  4652. var options = getOptions(optionalArg);
  4653. if (!delegatedEvents[type]) {
  4654. delegatedEvents[type] = [];
  4655. // add delegate listener functions
  4656. for (var _i3 = 0; _i3 < documents.length; _i3++) {
  4657. var doc = documents[_i3];
  4658. add(doc, type, delegateListener);
  4659. add(doc, type, delegateUseCapture, true);
  4660. }
  4661. }
  4662. var delegates = delegatedEvents[type];
  4663. var delegate = find(delegates, function (d) {
  4664. return d.selector === selector && d.context === context;
  4665. });
  4666. if (!delegate) {
  4667. delegate = {
  4668. selector: selector,
  4669. context: context,
  4670. listeners: []
  4671. };
  4672. delegates.push(delegate);
  4673. }
  4674. delegate.listeners.push({
  4675. func: listener,
  4676. options: options
  4677. });
  4678. }
  4679. function removeDelegate(selector, context, type, listener, optionalArg) {
  4680. var options = getOptions(optionalArg);
  4681. var delegates = delegatedEvents[type];
  4682. var matchFound = false;
  4683. var index;
  4684. if (!delegates) return;
  4685. // count from last index of delegated to 0
  4686. for (index = delegates.length - 1; index >= 0; index--) {
  4687. var cur = delegates[index];
  4688. // look for matching selector and context Node
  4689. if (cur.selector === selector && cur.context === context) {
  4690. var listeners = cur.listeners;
  4691. // each item of the listeners array is an array: [function, capture, passive]
  4692. for (var i = listeners.length - 1; i >= 0; i--) {
  4693. var entry = listeners[i];
  4694. // check if the listener functions and capture and passive flags match
  4695. if (entry.func === listener && optionsMatch(entry.options, options)) {
  4696. // remove the listener from the array of listeners
  4697. listeners.splice(i, 1);
  4698. // if all listeners for this target have been removed
  4699. // remove the target from the delegates array
  4700. if (!listeners.length) {
  4701. delegates.splice(index, 1);
  4702. // remove delegate function from context
  4703. remove(context, type, delegateListener);
  4704. remove(context, type, delegateUseCapture, true);
  4705. }
  4706. // only remove one listener
  4707. matchFound = true;
  4708. break;
  4709. }
  4710. }
  4711. if (matchFound) {
  4712. break;
  4713. }
  4714. }
  4715. }
  4716. }
  4717. // bound to the interactable context when a DOM event
  4718. // listener is added to a selector interactable
  4719. function delegateListener(event, optionalArg) {
  4720. var options = getOptions(optionalArg);
  4721. var fakeEvent = new FakeEvent(event);
  4722. var delegates = delegatedEvents[event.type];
  4723. var _pointerUtils$getEven = getEventTargets(event),
  4724. eventTarget = _pointerUtils$getEven[0];
  4725. var element = eventTarget;
  4726. // climb up document tree looking for selector matches
  4727. while (is.element(element)) {
  4728. for (var i = 0; i < delegates.length; i++) {
  4729. var cur = delegates[i];
  4730. var selector = cur.selector,
  4731. context = cur.context;
  4732. if (matchesSelector(element, selector) && nodeContains(context, eventTarget) && nodeContains(context, element)) {
  4733. var listeners = cur.listeners;
  4734. fakeEvent.currentTarget = element;
  4735. for (var _i5 = 0; _i5 < listeners.length; _i5++) {
  4736. var entry = listeners[_i5];
  4737. if (optionsMatch(entry.options, options)) {
  4738. entry.func(fakeEvent);
  4739. }
  4740. }
  4741. }
  4742. }
  4743. element = parentNode(element);
  4744. }
  4745. }
  4746. function delegateUseCapture(event) {
  4747. return delegateListener.call(this, event, true);
  4748. }
  4749. // for type inferrence
  4750. return eventsMethods;
  4751. }
  4752. var FakeEvent = /*#__PURE__*/function () {
  4753. function FakeEvent(originalEvent) {
  4754. _classCallCheck(this, FakeEvent);
  4755. this.currentTarget = void 0;
  4756. this.originalEvent = void 0;
  4757. this.type = void 0;
  4758. this.originalEvent = originalEvent;
  4759. // duplicate the event so that currentTarget can be changed
  4760. pointerExtend(this, originalEvent);
  4761. }
  4762. _createClass(FakeEvent, [{
  4763. key: "preventOriginalDefault",
  4764. value: function preventOriginalDefault() {
  4765. this.originalEvent.preventDefault();
  4766. }
  4767. }, {
  4768. key: "stopPropagation",
  4769. value: function stopPropagation() {
  4770. this.originalEvent.stopPropagation();
  4771. }
  4772. }, {
  4773. key: "stopImmediatePropagation",
  4774. value: function stopImmediatePropagation() {
  4775. this.originalEvent.stopImmediatePropagation();
  4776. }
  4777. }]);
  4778. return FakeEvent;
  4779. }();
  4780. function getOptions(param) {
  4781. if (!is.object(param)) {
  4782. return {
  4783. capture: !!param,
  4784. passive: false
  4785. };
  4786. }
  4787. return {
  4788. capture: !!param.capture,
  4789. passive: !!param.passive
  4790. };
  4791. }
  4792. function optionsMatch(a, b) {
  4793. if (a === b) return true;
  4794. if (typeof a === 'boolean') return !!b.capture === a && !!b.passive === false;
  4795. return !!a.capture === !!b.capture && !!a.passive === !!b.passive;
  4796. }
  4797. var events = {
  4798. id: 'events',
  4799. install: install$5
  4800. };
  4801. var finder = {
  4802. methodOrder: ['simulationResume', 'mouseOrPen', 'hasPointer', 'idle'],
  4803. search: function search(details) {
  4804. for (var _i2 = 0, _finder$methodOrder2 = finder.methodOrder; _i2 < _finder$methodOrder2.length; _i2++) {
  4805. var method = _finder$methodOrder2[_i2];
  4806. var interaction = finder[method](details);
  4807. if (interaction) {
  4808. return interaction;
  4809. }
  4810. }
  4811. return null;
  4812. },
  4813. // try to resume simulation with a new pointer
  4814. simulationResume: function simulationResume(_ref) {
  4815. var pointerType = _ref.pointerType,
  4816. eventType = _ref.eventType,
  4817. eventTarget = _ref.eventTarget,
  4818. scope = _ref.scope;
  4819. if (!/down|start/i.test(eventType)) {
  4820. return null;
  4821. }
  4822. for (var _i4 = 0, _scope$interactions$l2 = scope.interactions.list; _i4 < _scope$interactions$l2.length; _i4++) {
  4823. var interaction = _scope$interactions$l2[_i4];
  4824. var element = eventTarget;
  4825. if (interaction.simulation && interaction.simulation.allowResume && interaction.pointerType === pointerType) {
  4826. while (element) {
  4827. // if the element is the interaction element
  4828. if (element === interaction.element) {
  4829. return interaction;
  4830. }
  4831. element = parentNode(element);
  4832. }
  4833. }
  4834. }
  4835. return null;
  4836. },
  4837. // if it's a mouse or pen interaction
  4838. mouseOrPen: function mouseOrPen(_ref2) {
  4839. var pointerId = _ref2.pointerId,
  4840. pointerType = _ref2.pointerType,
  4841. eventType = _ref2.eventType,
  4842. scope = _ref2.scope;
  4843. if (pointerType !== 'mouse' && pointerType !== 'pen') {
  4844. return null;
  4845. }
  4846. var firstNonActive;
  4847. for (var _i6 = 0, _scope$interactions$l4 = scope.interactions.list; _i6 < _scope$interactions$l4.length; _i6++) {
  4848. var interaction = _scope$interactions$l4[_i6];
  4849. if (interaction.pointerType === pointerType) {
  4850. // if it's a down event, skip interactions with running simulations
  4851. if (interaction.simulation && !hasPointerId(interaction, pointerId)) {
  4852. continue;
  4853. }
  4854. // if the interaction is active, return it immediately
  4855. if (interaction.interacting()) {
  4856. return interaction;
  4857. }
  4858. // otherwise save it and look for another active interaction
  4859. else if (!firstNonActive) {
  4860. firstNonActive = interaction;
  4861. }
  4862. }
  4863. } // if no active mouse interaction was found use the first inactive mouse
  4864. // interaction
  4865. if (firstNonActive) {
  4866. return firstNonActive;
  4867. }
  4868. // find any mouse or pen interaction.
  4869. // ignore the interaction if the eventType is a *down, and a simulation
  4870. // is active
  4871. for (var _i8 = 0, _scope$interactions$l6 = scope.interactions.list; _i8 < _scope$interactions$l6.length; _i8++) {
  4872. var _interaction = _scope$interactions$l6[_i8];
  4873. if (_interaction.pointerType === pointerType && !(/down/i.test(eventType) && _interaction.simulation)) {
  4874. return _interaction;
  4875. }
  4876. }
  4877. return null;
  4878. },
  4879. // get interaction that has this pointer
  4880. hasPointer: function hasPointer(_ref3) {
  4881. var pointerId = _ref3.pointerId,
  4882. scope = _ref3.scope;
  4883. for (var _i10 = 0, _scope$interactions$l8 = scope.interactions.list; _i10 < _scope$interactions$l8.length; _i10++) {
  4884. var interaction = _scope$interactions$l8[_i10];
  4885. if (hasPointerId(interaction, pointerId)) {
  4886. return interaction;
  4887. }
  4888. }
  4889. return null;
  4890. },
  4891. // get first idle interaction with a matching pointerType
  4892. idle: function idle(_ref4) {
  4893. var pointerType = _ref4.pointerType,
  4894. scope = _ref4.scope;
  4895. for (var _i12 = 0, _scope$interactions$l10 = scope.interactions.list; _i12 < _scope$interactions$l10.length; _i12++) {
  4896. var interaction = _scope$interactions$l10[_i12];
  4897. // if there's already a pointer held down
  4898. if (interaction.pointers.length === 1) {
  4899. var target = interaction.interactable;
  4900. // don't add this pointer if there is a target interactable and it
  4901. // isn't gesturable
  4902. if (target && !(target.options.gesture && target.options.gesture.enabled)) {
  4903. continue;
  4904. }
  4905. }
  4906. // maximum of 2 pointers per interaction
  4907. else if (interaction.pointers.length >= 2) {
  4908. continue;
  4909. }
  4910. if (!interaction.interacting() && pointerType === interaction.pointerType) {
  4911. return interaction;
  4912. }
  4913. }
  4914. return null;
  4915. }
  4916. };
  4917. function hasPointerId(interaction, pointerId) {
  4918. return interaction.pointers.some(function (_ref5) {
  4919. var id = _ref5.id;
  4920. return id === pointerId;
  4921. });
  4922. }
  4923. var finder$1 = finder;
  4924. var methodNames = ['pointerDown', 'pointerMove', 'pointerUp', 'updatePointer', 'removePointer', 'windowBlur'];
  4925. function install$4(scope) {
  4926. var listeners = {};
  4927. for (var _i2 = 0; _i2 < methodNames.length; _i2++) {
  4928. var method = methodNames[_i2];
  4929. listeners[method] = doOnInteractions(method, scope);
  4930. }
  4931. var pEventTypes = browser$1.pEventTypes;
  4932. var docEvents;
  4933. if (domObjects$1.PointerEvent) {
  4934. docEvents = [{
  4935. type: pEventTypes.down,
  4936. listener: releasePointersOnRemovedEls
  4937. }, {
  4938. type: pEventTypes.down,
  4939. listener: listeners.pointerDown
  4940. }, {
  4941. type: pEventTypes.move,
  4942. listener: listeners.pointerMove
  4943. }, {
  4944. type: pEventTypes.up,
  4945. listener: listeners.pointerUp
  4946. }, {
  4947. type: pEventTypes.cancel,
  4948. listener: listeners.pointerUp
  4949. }];
  4950. } else {
  4951. docEvents = [{
  4952. type: 'mousedown',
  4953. listener: listeners.pointerDown
  4954. }, {
  4955. type: 'mousemove',
  4956. listener: listeners.pointerMove
  4957. }, {
  4958. type: 'mouseup',
  4959. listener: listeners.pointerUp
  4960. }, {
  4961. type: 'touchstart',
  4962. listener: releasePointersOnRemovedEls
  4963. }, {
  4964. type: 'touchstart',
  4965. listener: listeners.pointerDown
  4966. }, {
  4967. type: 'touchmove',
  4968. listener: listeners.pointerMove
  4969. }, {
  4970. type: 'touchend',
  4971. listener: listeners.pointerUp
  4972. }, {
  4973. type: 'touchcancel',
  4974. listener: listeners.pointerUp
  4975. }];
  4976. }
  4977. docEvents.push({
  4978. type: 'blur',
  4979. listener: function listener(event) {
  4980. for (var _i4 = 0, _scope$interactions$l2 = scope.interactions.list; _i4 < _scope$interactions$l2.length; _i4++) {
  4981. var interaction = _scope$interactions$l2[_i4];
  4982. interaction.documentBlur(event);
  4983. }
  4984. }
  4985. });
  4986. // for ignoring browser's simulated mouse events
  4987. scope.prevTouchTime = 0;
  4988. scope.Interaction = /*#__PURE__*/function (_InteractionBase) {
  4989. _inherits(_class, _InteractionBase);
  4990. var _super = _createSuper(_class);
  4991. function _class() {
  4992. _classCallCheck(this, _class);
  4993. return _super.apply(this, arguments);
  4994. }
  4995. _createClass(_class, [{
  4996. key: "pointerMoveTolerance",
  4997. get: function get() {
  4998. return scope.interactions.pointerMoveTolerance;
  4999. },
  5000. set: function set(value) {
  5001. scope.interactions.pointerMoveTolerance = value;
  5002. }
  5003. }, {
  5004. key: "_now",
  5005. value: function _now() {
  5006. return scope.now();
  5007. }
  5008. }]);
  5009. return _class;
  5010. }(Interaction);
  5011. scope.interactions = {
  5012. // all active and idle interactions
  5013. list: [],
  5014. new: function _new(options) {
  5015. options.scopeFire = function (name, arg) {
  5016. return scope.fire(name, arg);
  5017. };
  5018. var interaction = new scope.Interaction(options);
  5019. scope.interactions.list.push(interaction);
  5020. return interaction;
  5021. },
  5022. listeners: listeners,
  5023. docEvents: docEvents,
  5024. pointerMoveTolerance: 1
  5025. };
  5026. function releasePointersOnRemovedEls() {
  5027. // for all inactive touch interactions with pointers down
  5028. for (var _i6 = 0, _scope$interactions$l4 = scope.interactions.list; _i6 < _scope$interactions$l4.length; _i6++) {
  5029. var interaction = _scope$interactions$l4[_i6];
  5030. if (!interaction.pointerIsDown || interaction.pointerType !== 'touch' || interaction._interacting) {
  5031. continue;
  5032. }
  5033. // if a pointer is down on an element that is no longer in the DOM tree
  5034. var _loop = function _loop() {
  5035. var pointer = _interaction$pointers2[_i8];
  5036. if (!scope.documents.some(function (_ref) {
  5037. var doc = _ref.doc;
  5038. return nodeContains(doc, pointer.downTarget);
  5039. })) {
  5040. // remove the pointer from the interaction
  5041. interaction.removePointer(pointer.pointer, pointer.event);
  5042. }
  5043. };
  5044. for (var _i8 = 0, _interaction$pointers2 = interaction.pointers; _i8 < _interaction$pointers2.length; _i8++) {
  5045. _loop();
  5046. }
  5047. }
  5048. }
  5049. scope.usePlugin(interactablePreventDefault);
  5050. }
  5051. function doOnInteractions(method, scope) {
  5052. return function (event) {
  5053. var interactions = scope.interactions.list;
  5054. var pointerType = getPointerType(event);
  5055. var _pointerUtils$getEven = getEventTargets(event),
  5056. eventTarget = _pointerUtils$getEven[0],
  5057. curEventTarget = _pointerUtils$getEven[1];
  5058. var matches = []; // [ [pointer, interaction], ...]
  5059. if (/^touch/.test(event.type)) {
  5060. scope.prevTouchTime = scope.now();
  5061. // @ts-expect-error
  5062. for (var _i10 = 0, _event$changedTouches2 = event.changedTouches; _i10 < _event$changedTouches2.length; _i10++) {
  5063. var changedTouch = _event$changedTouches2[_i10];
  5064. var pointer = changedTouch;
  5065. var pointerId = getPointerId(pointer);
  5066. var searchDetails = {
  5067. pointer: pointer,
  5068. pointerId: pointerId,
  5069. pointerType: pointerType,
  5070. eventType: event.type,
  5071. eventTarget: eventTarget,
  5072. curEventTarget: curEventTarget,
  5073. scope: scope
  5074. };
  5075. var interaction = getInteraction(searchDetails);
  5076. matches.push([searchDetails.pointer, searchDetails.eventTarget, searchDetails.curEventTarget, interaction]);
  5077. }
  5078. } else {
  5079. var invalidPointer = false;
  5080. if (!browser$1.supportsPointerEvent && /mouse/.test(event.type)) {
  5081. // ignore mouse events while touch interactions are active
  5082. for (var i = 0; i < interactions.length && !invalidPointer; i++) {
  5083. invalidPointer = interactions[i].pointerType !== 'mouse' && interactions[i].pointerIsDown;
  5084. }
  5085. // try to ignore mouse events that are simulated by the browser
  5086. // after a touch event
  5087. invalidPointer = invalidPointer || scope.now() - scope.prevTouchTime < 500 ||
  5088. // on iOS and Firefox Mobile, MouseEvent.timeStamp is zero if simulated
  5089. event.timeStamp === 0;
  5090. }
  5091. if (!invalidPointer) {
  5092. var _searchDetails = {
  5093. pointer: event,
  5094. pointerId: getPointerId(event),
  5095. pointerType: pointerType,
  5096. eventType: event.type,
  5097. curEventTarget: curEventTarget,
  5098. eventTarget: eventTarget,
  5099. scope: scope
  5100. };
  5101. var _interaction = getInteraction(_searchDetails);
  5102. matches.push([_searchDetails.pointer, _searchDetails.eventTarget, _searchDetails.curEventTarget, _interaction]);
  5103. }
  5104. }
  5105. // eslint-disable-next-line no-shadow
  5106. for (var _i12 = 0; _i12 < matches.length; _i12++) {
  5107. var _matches$_i = matches[_i12],
  5108. _pointer = _matches$_i[0],
  5109. _eventTarget = _matches$_i[1],
  5110. _curEventTarget = _matches$_i[2],
  5111. _interaction2 = _matches$_i[3];
  5112. _interaction2[method](_pointer, event, _eventTarget, _curEventTarget);
  5113. }
  5114. };
  5115. }
  5116. function getInteraction(searchDetails) {
  5117. var pointerType = searchDetails.pointerType,
  5118. scope = searchDetails.scope;
  5119. var foundInteraction = finder$1.search(searchDetails);
  5120. var signalArg = {
  5121. interaction: foundInteraction,
  5122. searchDetails: searchDetails
  5123. };
  5124. scope.fire('interactions:find', signalArg);
  5125. return signalArg.interaction || scope.interactions.new({
  5126. pointerType: pointerType
  5127. });
  5128. }
  5129. function onDocSignal(_ref2, eventMethodName) {
  5130. var doc = _ref2.doc,
  5131. scope = _ref2.scope,
  5132. options = _ref2.options;
  5133. var docEvents = scope.interactions.docEvents,
  5134. events = scope.events;
  5135. var eventMethod = events[eventMethodName];
  5136. if (scope.browser.isIOS && !options.events) {
  5137. options.events = {
  5138. passive: false
  5139. };
  5140. }
  5141. // delegate event listener
  5142. for (var eventType in events.delegatedEvents) {
  5143. eventMethod(doc, eventType, events.delegateListener);
  5144. eventMethod(doc, eventType, events.delegateUseCapture, true);
  5145. }
  5146. var eventOptions = options && options.events;
  5147. for (var _i14 = 0; _i14 < docEvents.length; _i14++) {
  5148. var _docEvents$_i = docEvents[_i14],
  5149. _type = _docEvents$_i.type,
  5150. listener = _docEvents$_i.listener;
  5151. eventMethod(doc, _type, listener, eventOptions);
  5152. }
  5153. }
  5154. var interactions = {
  5155. id: 'core/interactions',
  5156. install: install$4,
  5157. listeners: {
  5158. 'scope:add-document': function scopeAddDocument(arg) {
  5159. return onDocSignal(arg, 'add');
  5160. },
  5161. 'scope:remove-document': function scopeRemoveDocument(arg) {
  5162. return onDocSignal(arg, 'remove');
  5163. },
  5164. 'interactable:unset': function interactableUnset(_ref3, scope) {
  5165. var interactable = _ref3.interactable;
  5166. // Stop and destroy related interactions when an Interactable is unset
  5167. for (var i = scope.interactions.list.length - 1; i >= 0; i--) {
  5168. var interaction = scope.interactions.list[i];
  5169. if (interaction.interactable !== interactable) {
  5170. continue;
  5171. }
  5172. interaction.stop();
  5173. scope.fire('interactions:destroy', {
  5174. interaction: interaction
  5175. });
  5176. interaction.destroy();
  5177. if (scope.interactions.list.length > 2) {
  5178. scope.interactions.list.splice(i, 1);
  5179. }
  5180. }
  5181. }
  5182. },
  5183. onDocSignal: onDocSignal,
  5184. doOnInteractions: doOnInteractions,
  5185. methodNames: methodNames
  5186. };
  5187. var interactions$1 = interactions;
  5188. var OnOffMethod = /*#__PURE__*/function (OnOffMethod) {
  5189. OnOffMethod[OnOffMethod["On"] = 0] = "On";
  5190. OnOffMethod[OnOffMethod["Off"] = 1] = "Off";
  5191. return OnOffMethod;
  5192. }(OnOffMethod || {});
  5193. /**
  5194. * ```ts
  5195. * const interactable = interact('.cards')
  5196. * .draggable({
  5197. * listeners: { move: event => console.log(event.type, event.pageX, event.pageY) }
  5198. * })
  5199. * .resizable({
  5200. * listeners: { move: event => console.log(event.rect) },
  5201. * modifiers: [interact.modifiers.restrictEdges({ outer: 'parent' })]
  5202. * })
  5203. * ```
  5204. */
  5205. var Interactable = /*#__PURE__*/function () {
  5206. function Interactable(target, options, defaultContext, scopeEvents) {
  5207. _classCallCheck(this, Interactable);
  5208. this.target = void 0;
  5209. /** @internal */
  5210. this.options = void 0;
  5211. /** @internal */
  5212. this._actions = void 0;
  5213. /** @internal */
  5214. this.events = new Eventable();
  5215. /** @internal */
  5216. this._context = void 0;
  5217. /** @internal */
  5218. this._win = void 0;
  5219. /** @internal */
  5220. this._doc = void 0;
  5221. /** @internal */
  5222. this._scopeEvents = void 0;
  5223. this._actions = options.actions;
  5224. this.target = target;
  5225. this._context = options.context || defaultContext;
  5226. this._win = getWindow(trySelector(target) ? this._context : target);
  5227. this._doc = this._win.document;
  5228. this._scopeEvents = scopeEvents;
  5229. this.set(options);
  5230. }
  5231. _createClass(Interactable, [{
  5232. key: "_defaults",
  5233. get: /** @internal */function get() {
  5234. return {
  5235. base: {},
  5236. perAction: {},
  5237. actions: {}
  5238. };
  5239. }
  5240. }, {
  5241. key: "setOnEvents",
  5242. value: function setOnEvents(actionName, phases) {
  5243. if (is.func(phases.onstart)) {
  5244. this.on("".concat(actionName, "start"), phases.onstart);
  5245. }
  5246. if (is.func(phases.onmove)) {
  5247. this.on("".concat(actionName, "move"), phases.onmove);
  5248. }
  5249. if (is.func(phases.onend)) {
  5250. this.on("".concat(actionName, "end"), phases.onend);
  5251. }
  5252. if (is.func(phases.oninertiastart)) {
  5253. this.on("".concat(actionName, "inertiastart"), phases.oninertiastart);
  5254. }
  5255. return this;
  5256. }
  5257. }, {
  5258. key: "updatePerActionListeners",
  5259. value: function updatePerActionListeners(actionName, prev, cur) {
  5260. var _this$_actions$map$ac,
  5261. _this = this;
  5262. var actionFilter = (_this$_actions$map$ac = this._actions.map[actionName]) == null ? void 0 : _this$_actions$map$ac.filterEventType;
  5263. var filter = function filter(type) {
  5264. return (actionFilter == null || actionFilter(type)) && isNonNativeEvent(type, _this._actions);
  5265. };
  5266. if (is.array(prev) || is.object(prev)) {
  5267. this._onOff(OnOffMethod.Off, actionName, prev, undefined, filter);
  5268. }
  5269. if (is.array(cur) || is.object(cur)) {
  5270. this._onOff(OnOffMethod.On, actionName, cur, undefined, filter);
  5271. }
  5272. }
  5273. }, {
  5274. key: "setPerAction",
  5275. value: function setPerAction(actionName, options) {
  5276. var defaults = this._defaults;
  5277. // for all the default per-action options
  5278. for (var optionName_ in options) {
  5279. var optionName = optionName_;
  5280. var actionOptions = this.options[actionName];
  5281. var optionValue = options[optionName];
  5282. // remove old event listeners and add new ones
  5283. if (optionName === 'listeners') {
  5284. this.updatePerActionListeners(actionName, actionOptions.listeners, optionValue);
  5285. }
  5286. // if the option value is an array
  5287. if (is.array(optionValue)) {
  5288. actionOptions[optionName] = from(optionValue);
  5289. }
  5290. // if the option value is an object
  5291. else if (is.plainObject(optionValue)) {
  5292. actionOptions[optionName] = extend(actionOptions[optionName] || {}, clone(optionValue));
  5293. // set anabled field to true if it exists in the defaults
  5294. if (is.object(defaults.perAction[optionName]) && 'enabled' in defaults.perAction[optionName]) {
  5295. actionOptions[optionName].enabled = optionValue.enabled !== false;
  5296. }
  5297. }
  5298. // if the option value is a boolean and the default is an object
  5299. else if (is.bool(optionValue) && is.object(defaults.perAction[optionName])) {
  5300. actionOptions[optionName].enabled = optionValue;
  5301. }
  5302. // if it's anything else, do a plain assignment
  5303. else {
  5304. actionOptions[optionName] = optionValue;
  5305. }
  5306. }
  5307. }
  5308. /**
  5309. * The default function to get an Interactables bounding rect. Can be
  5310. * overridden using {@link Interactable.rectChecker}.
  5311. *
  5312. * @param {Element} [element] The element to measure.
  5313. * @return {Rect} The object's bounding rectangle.
  5314. */
  5315. }, {
  5316. key: "getRect",
  5317. value: function getRect(element) {
  5318. element = element || (is.element(this.target) ? this.target : null);
  5319. if (is.string(this.target)) {
  5320. element = element || this._context.querySelector(this.target);
  5321. }
  5322. return getElementRect(element);
  5323. }
  5324. /**
  5325. * Returns or sets the function used to calculate the interactable's
  5326. * element's rectangle
  5327. *
  5328. * @param {function} [checker] A function which returns this Interactable's
  5329. * bounding rectangle. See {@link Interactable.getRect}
  5330. * @return {function | object} The checker function or this Interactable
  5331. */
  5332. }, {
  5333. key: "rectChecker",
  5334. value: function rectChecker(checker) {
  5335. var _this2 = this;
  5336. if (is.func(checker)) {
  5337. this.getRect = function (element) {
  5338. var rect = extend({}, checker.apply(_this2, element));
  5339. if (!('width' in rect)) {
  5340. rect.width = rect.right - rect.left;
  5341. rect.height = rect.bottom - rect.top;
  5342. }
  5343. return rect;
  5344. };
  5345. return this;
  5346. }
  5347. if (checker === null) {
  5348. delete this.getRect;
  5349. return this;
  5350. }
  5351. return this.getRect;
  5352. }
  5353. /** @internal */
  5354. }, {
  5355. key: "_backCompatOption",
  5356. value: function _backCompatOption(optionName, newValue) {
  5357. if (trySelector(newValue) || is.object(newValue)) {
  5358. this.options[optionName] = newValue;
  5359. for (var action in this._actions.map) {
  5360. this.options[action][optionName] = newValue;
  5361. }
  5362. return this;
  5363. }
  5364. return this.options[optionName];
  5365. }
  5366. /**
  5367. * Gets or sets the origin of the Interactable's element. The x and y
  5368. * of the origin will be subtracted from action event coordinates.
  5369. *
  5370. * @param {Element | object | string} [origin] An HTML or SVG Element whose
  5371. * rect will be used, an object eg. { x: 0, y: 0 } or string 'parent', 'self'
  5372. * or any CSS selector
  5373. *
  5374. * @return {object} The current origin or this Interactable
  5375. */
  5376. }, {
  5377. key: "origin",
  5378. value: function origin(newValue) {
  5379. return this._backCompatOption('origin', newValue);
  5380. }
  5381. /**
  5382. * Returns or sets the mouse coordinate types used to calculate the
  5383. * movement of the pointer.
  5384. *
  5385. * @param {string} [newValue] Use 'client' if you will be scrolling while
  5386. * interacting; Use 'page' if you want autoScroll to work
  5387. * @return {string | object} The current deltaSource or this Interactable
  5388. */
  5389. }, {
  5390. key: "deltaSource",
  5391. value: function deltaSource(newValue) {
  5392. if (newValue === 'page' || newValue === 'client') {
  5393. this.options.deltaSource = newValue;
  5394. return this;
  5395. }
  5396. return this.options.deltaSource;
  5397. }
  5398. /** @internal */
  5399. }, {
  5400. key: "getAllElements",
  5401. value: function getAllElements() {
  5402. var target = this.target;
  5403. if (is.string(target)) {
  5404. return Array.from(this._context.querySelectorAll(target));
  5405. }
  5406. if (is.func(target) && target.getAllElements) {
  5407. return target.getAllElements();
  5408. }
  5409. return is.element(target) ? [target] : [];
  5410. }
  5411. /**
  5412. * Gets the selector context Node of the Interactable. The default is
  5413. * `window.document`.
  5414. *
  5415. * @return {Node} The context Node of this Interactable
  5416. */
  5417. }, {
  5418. key: "context",
  5419. value: function context() {
  5420. return this._context;
  5421. }
  5422. }, {
  5423. key: "inContext",
  5424. value: function inContext(element) {
  5425. return this._context === element.ownerDocument || nodeContains(this._context, element);
  5426. }
  5427. /** @internal */
  5428. }, {
  5429. key: "testIgnoreAllow",
  5430. value: function testIgnoreAllow(options, targetNode, eventTarget) {
  5431. return !this.testIgnore(options.ignoreFrom, targetNode, eventTarget) && this.testAllow(options.allowFrom, targetNode, eventTarget);
  5432. }
  5433. /** @internal */
  5434. }, {
  5435. key: "testAllow",
  5436. value: function testAllow(allowFrom, targetNode, element) {
  5437. if (!allowFrom) {
  5438. return true;
  5439. }
  5440. if (!is.element(element)) {
  5441. return false;
  5442. }
  5443. if (is.string(allowFrom)) {
  5444. return matchesUpTo(element, allowFrom, targetNode);
  5445. } else if (is.element(allowFrom)) {
  5446. return nodeContains(allowFrom, element);
  5447. }
  5448. return false;
  5449. }
  5450. /** @internal */
  5451. }, {
  5452. key: "testIgnore",
  5453. value: function testIgnore(ignoreFrom, targetNode, element) {
  5454. if (!ignoreFrom || !is.element(element)) {
  5455. return false;
  5456. }
  5457. if (is.string(ignoreFrom)) {
  5458. return matchesUpTo(element, ignoreFrom, targetNode);
  5459. } else if (is.element(ignoreFrom)) {
  5460. return nodeContains(ignoreFrom, element);
  5461. }
  5462. return false;
  5463. }
  5464. /**
  5465. * Calls listeners for the given InteractEvent type bound globally
  5466. * and directly to this Interactable
  5467. *
  5468. * @param {InteractEvent} iEvent The InteractEvent object to be fired on this
  5469. * Interactable
  5470. * @return {Interactable} this Interactable
  5471. */
  5472. }, {
  5473. key: "fire",
  5474. value: function fire(iEvent) {
  5475. this.events.fire(iEvent);
  5476. return this;
  5477. }
  5478. /** @internal */
  5479. }, {
  5480. key: "_onOff",
  5481. value: function _onOff(method, typeArg, listenerArg, options, filter) {
  5482. if (is.object(typeArg) && !is.array(typeArg)) {
  5483. options = listenerArg;
  5484. listenerArg = null;
  5485. }
  5486. var listeners = normalize(typeArg, listenerArg, filter);
  5487. for (var _type in listeners) {
  5488. if (_type === 'wheel') {
  5489. _type = browser$1.wheelEvent;
  5490. }
  5491. for (var _i2 = 0, _listeners$_type2 = listeners[_type]; _i2 < _listeners$_type2.length; _i2++) {
  5492. var listener = _listeners$_type2[_i2];
  5493. // if it is an action event type
  5494. if (isNonNativeEvent(_type, this._actions)) {
  5495. this.events[method === OnOffMethod.On ? 'on' : 'off'](_type, listener);
  5496. }
  5497. // delegated event
  5498. else if (is.string(this.target)) {
  5499. this._scopeEvents[method === OnOffMethod.On ? 'addDelegate' : 'removeDelegate'](this.target, this._context, _type, listener, options);
  5500. }
  5501. // remove listener from this Interactable's element
  5502. else {
  5503. this._scopeEvents[method === OnOffMethod.On ? 'add' : 'remove'](this.target, _type, listener, options);
  5504. }
  5505. }
  5506. }
  5507. return this;
  5508. }
  5509. /**
  5510. * Binds a listener for an InteractEvent, pointerEvent or DOM event.
  5511. *
  5512. * @param {string | array | object} types The types of events to listen
  5513. * for
  5514. * @param {function | array | object} [listener] The event listener function(s)
  5515. * @param {object | boolean} [options] options object or useCapture flag for
  5516. * addEventListener
  5517. * @return {Interactable} This Interactable
  5518. */
  5519. }, {
  5520. key: "on",
  5521. value: function on(types, listener, options) {
  5522. return this._onOff(OnOffMethod.On, types, listener, options);
  5523. }
  5524. /**
  5525. * Removes an InteractEvent, pointerEvent or DOM event listener.
  5526. *
  5527. * @param {string | array | object} types The types of events that were
  5528. * listened for
  5529. * @param {function | array | object} [listener] The event listener function(s)
  5530. * @param {object | boolean} [options] options object or useCapture flag for
  5531. * removeEventListener
  5532. * @return {Interactable} This Interactable
  5533. */
  5534. }, {
  5535. key: "off",
  5536. value: function off(types, listener, options) {
  5537. return this._onOff(OnOffMethod.Off, types, listener, options);
  5538. }
  5539. /**
  5540. * Reset the options of this Interactable
  5541. *
  5542. * @param {object} options The new settings to apply
  5543. * @return {object} This Interactable
  5544. */
  5545. }, {
  5546. key: "set",
  5547. value: function set(options) {
  5548. var defaults = this._defaults;
  5549. if (!is.object(options)) {
  5550. options = {};
  5551. }
  5552. this.options = clone(defaults.base);
  5553. for (var actionName_ in this._actions.methodDict) {
  5554. var actionName = actionName_;
  5555. var methodName = this._actions.methodDict[actionName];
  5556. this.options[actionName] = {};
  5557. this.setPerAction(actionName, extend(extend({}, defaults.perAction), defaults.actions[actionName]));
  5558. this[methodName](options[actionName]);
  5559. }
  5560. for (var setting in options) {
  5561. if (setting === 'getRect') {
  5562. this.rectChecker(options.getRect);
  5563. continue;
  5564. }
  5565. if (is.func(this[setting])) {
  5566. this[setting](options[setting]);
  5567. }
  5568. }
  5569. return this;
  5570. }
  5571. /**
  5572. * Remove this interactable from the list of interactables and remove it's
  5573. * action capabilities and event listeners
  5574. */
  5575. }, {
  5576. key: "unset",
  5577. value: function unset() {
  5578. if (is.string(this.target)) {
  5579. // remove delegated events
  5580. for (var _type2 in this._scopeEvents.delegatedEvents) {
  5581. var delegated = this._scopeEvents.delegatedEvents[_type2];
  5582. for (var i = delegated.length - 1; i >= 0; i--) {
  5583. var _delegated$i = delegated[i],
  5584. selector = _delegated$i.selector,
  5585. context = _delegated$i.context,
  5586. listeners = _delegated$i.listeners;
  5587. if (selector === this.target && context === this._context) {
  5588. delegated.splice(i, 1);
  5589. }
  5590. for (var l = listeners.length - 1; l >= 0; l--) {
  5591. this._scopeEvents.removeDelegate(this.target, this._context, _type2, listeners[l][0], listeners[l][1]);
  5592. }
  5593. }
  5594. }
  5595. } else {
  5596. this._scopeEvents.remove(this.target, 'all');
  5597. }
  5598. }
  5599. }]);
  5600. return Interactable;
  5601. }();
  5602. var InteractableSet = /*#__PURE__*/function () {
  5603. function InteractableSet(scope) {
  5604. var _this = this;
  5605. _classCallCheck(this, InteractableSet);
  5606. // all set interactables
  5607. this.list = [];
  5608. this.selectorMap = {};
  5609. this.scope = void 0;
  5610. this.scope = scope;
  5611. scope.addListeners({
  5612. 'interactable:unset': function interactableUnset(_ref) {
  5613. var interactable = _ref.interactable;
  5614. var target = interactable.target;
  5615. var interactablesOnTarget = is.string(target) ? _this.selectorMap[target] : target[_this.scope.id];
  5616. var targetIndex = findIndex(interactablesOnTarget, function (i) {
  5617. return i === interactable;
  5618. });
  5619. interactablesOnTarget.splice(targetIndex, 1);
  5620. }
  5621. });
  5622. }
  5623. _createClass(InteractableSet, [{
  5624. key: "new",
  5625. value: function _new(target, options) {
  5626. options = extend(options || {}, {
  5627. actions: this.scope.actions
  5628. });
  5629. var interactable = new this.scope.Interactable(target, options, this.scope.document, this.scope.events);
  5630. this.scope.addDocument(interactable._doc);
  5631. this.list.push(interactable);
  5632. if (is.string(target)) {
  5633. if (!this.selectorMap[target]) {
  5634. this.selectorMap[target] = [];
  5635. }
  5636. this.selectorMap[target].push(interactable);
  5637. } else {
  5638. if (!interactable.target[this.scope.id]) {
  5639. Object.defineProperty(target, this.scope.id, {
  5640. value: [],
  5641. configurable: true
  5642. });
  5643. }
  5644. target[this.scope.id].push(interactable);
  5645. }
  5646. this.scope.fire('interactable:new', {
  5647. target: target,
  5648. options: options,
  5649. interactable: interactable,
  5650. win: this.scope._win
  5651. });
  5652. return interactable;
  5653. }
  5654. }, {
  5655. key: "getExisting",
  5656. value: function getExisting(target, options) {
  5657. var context = options && options.context || this.scope.document;
  5658. var isSelector = is.string(target);
  5659. var interactablesOnTarget = isSelector ? this.selectorMap[target] : target[this.scope.id];
  5660. if (!interactablesOnTarget) return undefined;
  5661. return find(interactablesOnTarget, function (interactable) {
  5662. return interactable._context === context && (isSelector || interactable.inContext(target));
  5663. });
  5664. }
  5665. }, {
  5666. key: "forEachMatch",
  5667. value: function forEachMatch(node, callback) {
  5668. for (var _i2 = 0, _this$list2 = this.list; _i2 < _this$list2.length; _i2++) {
  5669. var _interactable = _this$list2[_i2];
  5670. var ret = void 0;
  5671. if ((is.string(_interactable.target) ?
  5672. // target is a selector and the element matches
  5673. is.element(node) && matchesSelector(node, _interactable.target) :
  5674. // target is the element
  5675. node === _interactable.target) &&
  5676. // the element is in context
  5677. _interactable.inContext(node)) {
  5678. ret = callback(_interactable);
  5679. }
  5680. if (ret !== undefined) {
  5681. return ret;
  5682. }
  5683. }
  5684. }
  5685. }]);
  5686. return InteractableSet;
  5687. }();
  5688. /**
  5689. * ```js
  5690. * interact('#draggable').draggable(true)
  5691. *
  5692. * var rectables = interact('rect')
  5693. * rectables
  5694. * .gesturable(true)
  5695. * .on('gesturemove', function (event) {
  5696. * // ...
  5697. * })
  5698. * ```
  5699. *
  5700. * The methods of this variable can be used to set elements as interactables
  5701. * and also to change various default settings.
  5702. *
  5703. * Calling it as a function and passing an element or a valid CSS selector
  5704. * string returns an Interactable object which has various methods to configure
  5705. * it.
  5706. *
  5707. * @param {Element | string} target The HTML or SVG Element to interact with
  5708. * or CSS selector
  5709. * @return {Interactable}
  5710. */
  5711. function createInteractStatic(scope) {
  5712. var interact = function interact(target, options) {
  5713. var interactable = scope.interactables.getExisting(target, options);
  5714. if (!interactable) {
  5715. interactable = scope.interactables.new(target, options);
  5716. interactable.events.global = interact.globalEvents;
  5717. }
  5718. return interactable;
  5719. };
  5720. // expose the functions used to calculate multi-touch properties
  5721. interact.getPointerAverage = pointerAverage;
  5722. interact.getTouchBBox = touchBBox;
  5723. interact.getTouchDistance = touchDistance;
  5724. interact.getTouchAngle = touchAngle;
  5725. interact.getElementRect = getElementRect;
  5726. interact.getElementClientRect = getElementClientRect;
  5727. interact.matchesSelector = matchesSelector;
  5728. interact.closest = closest;
  5729. interact.globalEvents = {};
  5730. // eslint-disable-next-line no-undef
  5731. interact.version = "1.10.27";
  5732. interact.scope = scope;
  5733. interact.use = function (plugin, options) {
  5734. this.scope.usePlugin(plugin, options);
  5735. return this;
  5736. };
  5737. interact.isSet = function (target, options) {
  5738. return !!this.scope.interactables.get(target, options && options.context);
  5739. };
  5740. interact.on = warnOnce(function on(type, listener, options) {
  5741. if (is.string(type) && type.search(' ') !== -1) {
  5742. type = type.trim().split(/ +/);
  5743. }
  5744. if (is.array(type)) {
  5745. for (var _i2 = 0, _ref2 = type; _i2 < _ref2.length; _i2++) {
  5746. var eventType = _ref2[_i2];
  5747. this.on(eventType, listener, options);
  5748. }
  5749. return this;
  5750. }
  5751. if (is.object(type)) {
  5752. for (var prop in type) {
  5753. this.on(prop, type[prop], listener);
  5754. }
  5755. return this;
  5756. }
  5757. // if it is an InteractEvent type, add listener to globalEvents
  5758. if (isNonNativeEvent(type, this.scope.actions)) {
  5759. // if this type of event was never bound
  5760. if (!this.globalEvents[type]) {
  5761. this.globalEvents[type] = [listener];
  5762. } else {
  5763. this.globalEvents[type].push(listener);
  5764. }
  5765. }
  5766. // If non InteractEvent type, addEventListener to document
  5767. else {
  5768. this.scope.events.add(this.scope.document, type, listener, {
  5769. options: options
  5770. });
  5771. }
  5772. return this;
  5773. }, 'The interact.on() method is being deprecated');
  5774. interact.off = warnOnce(function off(type, listener, options) {
  5775. if (is.string(type) && type.search(' ') !== -1) {
  5776. type = type.trim().split(/ +/);
  5777. }
  5778. if (is.array(type)) {
  5779. for (var _i4 = 0, _type2 = type; _i4 < _type2.length; _i4++) {
  5780. var eventType = _type2[_i4];
  5781. this.off(eventType, listener, options);
  5782. }
  5783. return this;
  5784. }
  5785. if (is.object(type)) {
  5786. for (var prop in type) {
  5787. this.off(prop, type[prop], listener);
  5788. }
  5789. return this;
  5790. }
  5791. if (isNonNativeEvent(type, this.scope.actions)) {
  5792. var index;
  5793. if (type in this.globalEvents && (index = this.globalEvents[type].indexOf(listener)) !== -1) {
  5794. this.globalEvents[type].splice(index, 1);
  5795. }
  5796. } else {
  5797. this.scope.events.remove(this.scope.document, type, listener, options);
  5798. }
  5799. return this;
  5800. }, 'The interact.off() method is being deprecated');
  5801. interact.debug = function () {
  5802. return this.scope;
  5803. };
  5804. interact.supportsTouch = function () {
  5805. return browser$1.supportsTouch;
  5806. };
  5807. interact.supportsPointerEvent = function () {
  5808. return browser$1.supportsPointerEvent;
  5809. };
  5810. interact.stop = function () {
  5811. for (var _i6 = 0, _this$scope$interacti2 = this.scope.interactions.list; _i6 < _this$scope$interacti2.length; _i6++) {
  5812. var interaction = _this$scope$interacti2[_i6];
  5813. interaction.stop();
  5814. }
  5815. return this;
  5816. };
  5817. interact.pointerMoveTolerance = function (newValue) {
  5818. if (is.number(newValue)) {
  5819. this.scope.interactions.pointerMoveTolerance = newValue;
  5820. return this;
  5821. }
  5822. return this.scope.interactions.pointerMoveTolerance;
  5823. };
  5824. interact.addDocument = function (doc, options) {
  5825. this.scope.addDocument(doc, options);
  5826. };
  5827. interact.removeDocument = function (doc) {
  5828. this.scope.removeDocument(doc);
  5829. };
  5830. return interact;
  5831. }
  5832. /** @internal */
  5833. var Scope = /*#__PURE__*/function () {
  5834. function Scope() {
  5835. var _this = this;
  5836. _classCallCheck(this, Scope);
  5837. this.id = "__interact_scope_".concat(Math.floor(Math.random() * 100));
  5838. this.isInitialized = false;
  5839. this.listenerMaps = [];
  5840. this.browser = browser$1;
  5841. this.defaults = clone(defaults$7);
  5842. this.Eventable = Eventable;
  5843. this.actions = {
  5844. map: {},
  5845. phases: {
  5846. start: true,
  5847. move: true,
  5848. end: true
  5849. },
  5850. methodDict: {},
  5851. phaselessTypes: {}
  5852. };
  5853. this.interactStatic = createInteractStatic(this);
  5854. this.InteractEvent = InteractEvent;
  5855. this.Interactable = void 0;
  5856. this.interactables = new InteractableSet(this);
  5857. // main window
  5858. this._win = void 0;
  5859. // main document
  5860. this.document = void 0;
  5861. // main window
  5862. this.window = void 0;
  5863. // all documents being listened to
  5864. this.documents = [];
  5865. this._plugins = {
  5866. list: [],
  5867. map: {}
  5868. };
  5869. this.onWindowUnload = function (event) {
  5870. return _this.removeDocument(event.target);
  5871. };
  5872. var scope = this;
  5873. this.Interactable = /*#__PURE__*/function (_InteractableBase) {
  5874. _inherits(_class2, _InteractableBase);
  5875. var _super = _createSuper(_class2);
  5876. function _class2() {
  5877. _classCallCheck(this, _class2);
  5878. return _super.apply(this, arguments);
  5879. }
  5880. _createClass(_class2, [{
  5881. key: "_defaults",
  5882. get: function get() {
  5883. return scope.defaults;
  5884. }
  5885. }, {
  5886. key: "set",
  5887. value: function set(options) {
  5888. _get(_getPrototypeOf(_class2.prototype), "set", this).call(this, options);
  5889. scope.fire('interactable:set', {
  5890. options: options,
  5891. interactable: this
  5892. });
  5893. return this;
  5894. }
  5895. }, {
  5896. key: "unset",
  5897. value: function unset() {
  5898. _get(_getPrototypeOf(_class2.prototype), "unset", this).call(this);
  5899. var index = scope.interactables.list.indexOf(this);
  5900. if (index < 0) return;
  5901. scope.interactables.list.splice(index, 1);
  5902. scope.fire('interactable:unset', {
  5903. interactable: this
  5904. });
  5905. }
  5906. }]);
  5907. return _class2;
  5908. }(Interactable);
  5909. }
  5910. _createClass(Scope, [{
  5911. key: "addListeners",
  5912. value: function addListeners(map, id) {
  5913. this.listenerMaps.push({
  5914. id: id,
  5915. map: map
  5916. });
  5917. }
  5918. }, {
  5919. key: "fire",
  5920. value: function fire(name, arg) {
  5921. for (var _i2 = 0, _this$listenerMaps2 = this.listenerMaps; _i2 < _this$listenerMaps2.length; _i2++) {
  5922. var listener = _this$listenerMaps2[_i2].map[name];
  5923. if (!!listener && listener(arg, this, name) === false) {
  5924. return false;
  5925. }
  5926. }
  5927. }
  5928. }, {
  5929. key: "init",
  5930. value: function init(window) {
  5931. return this.isInitialized ? this : initScope(this, window);
  5932. }
  5933. }, {
  5934. key: "pluginIsInstalled",
  5935. value: function pluginIsInstalled(plugin) {
  5936. var id = plugin.id;
  5937. return id ? !!this._plugins.map[id] : this._plugins.list.indexOf(plugin) !== -1;
  5938. }
  5939. }, {
  5940. key: "usePlugin",
  5941. value: function usePlugin(plugin, options) {
  5942. if (!this.isInitialized) {
  5943. return this;
  5944. }
  5945. if (this.pluginIsInstalled(plugin)) {
  5946. return this;
  5947. }
  5948. if (plugin.id) {
  5949. this._plugins.map[plugin.id] = plugin;
  5950. }
  5951. this._plugins.list.push(plugin);
  5952. if (plugin.install) {
  5953. plugin.install(this, options);
  5954. }
  5955. if (plugin.listeners && plugin.before) {
  5956. var index = 0;
  5957. var len = this.listenerMaps.length;
  5958. var before = plugin.before.reduce(function (acc, id) {
  5959. acc[id] = true;
  5960. acc[pluginIdRoot(id)] = true;
  5961. return acc;
  5962. }, {});
  5963. for (; index < len; index++) {
  5964. var otherId = this.listenerMaps[index].id;
  5965. if (otherId && (before[otherId] || before[pluginIdRoot(otherId)])) {
  5966. break;
  5967. }
  5968. }
  5969. this.listenerMaps.splice(index, 0, {
  5970. id: plugin.id,
  5971. map: plugin.listeners
  5972. });
  5973. } else if (plugin.listeners) {
  5974. this.listenerMaps.push({
  5975. id: plugin.id,
  5976. map: plugin.listeners
  5977. });
  5978. }
  5979. return this;
  5980. }
  5981. }, {
  5982. key: "addDocument",
  5983. value: function addDocument(doc, options) {
  5984. // do nothing if document is already known
  5985. if (this.getDocIndex(doc) !== -1) {
  5986. return false;
  5987. }
  5988. var window = getWindow(doc);
  5989. options = options ? extend({}, options) : {};
  5990. this.documents.push({
  5991. doc: doc,
  5992. options: options
  5993. });
  5994. this.events.documents.push(doc);
  5995. // don't add an unload event for the main document
  5996. // so that the page may be cached in browser history
  5997. if (doc !== this.document) {
  5998. this.events.add(window, 'unload', this.onWindowUnload);
  5999. }
  6000. this.fire('scope:add-document', {
  6001. doc: doc,
  6002. window: window,
  6003. scope: this,
  6004. options: options
  6005. });
  6006. }
  6007. }, {
  6008. key: "removeDocument",
  6009. value: function removeDocument(doc) {
  6010. var index = this.getDocIndex(doc);
  6011. var window = getWindow(doc);
  6012. var options = this.documents[index].options;
  6013. this.events.remove(window, 'unload', this.onWindowUnload);
  6014. this.documents.splice(index, 1);
  6015. this.events.documents.splice(index, 1);
  6016. this.fire('scope:remove-document', {
  6017. doc: doc,
  6018. window: window,
  6019. scope: this,
  6020. options: options
  6021. });
  6022. }
  6023. }, {
  6024. key: "getDocIndex",
  6025. value: function getDocIndex(doc) {
  6026. for (var i = 0; i < this.documents.length; i++) {
  6027. if (this.documents[i].doc === doc) {
  6028. return i;
  6029. }
  6030. }
  6031. return -1;
  6032. }
  6033. }, {
  6034. key: "getDocOptions",
  6035. value: function getDocOptions(doc) {
  6036. var docIndex = this.getDocIndex(doc);
  6037. return docIndex === -1 ? null : this.documents[docIndex].options;
  6038. }
  6039. }, {
  6040. key: "now",
  6041. value: function now() {
  6042. return (this.window.Date || Date).now();
  6043. }
  6044. }]);
  6045. return Scope;
  6046. }();
  6047. // Keep Scope class internal, but expose minimal interface to avoid broken types when Scope is stripped out
  6048. /** @internal */
  6049. function initScope(scope, window) {
  6050. scope.isInitialized = true;
  6051. if (is.window(window)) {
  6052. init$3(window);
  6053. }
  6054. domObjects$1.init(window);
  6055. browser$1.init(window);
  6056. raf.init(window);
  6057. // @ts-expect-error
  6058. scope.window = window;
  6059. scope.document = window.document;
  6060. scope.usePlugin(interactions$1);
  6061. scope.usePlugin(events);
  6062. return scope;
  6063. }
  6064. function pluginIdRoot(id) {
  6065. return id && id.replace(/\/.*$/, '');
  6066. }
  6067. var scope = new Scope();
  6068. var interact = scope.interactStatic;
  6069. var interact$1 = interact;
  6070. var _global = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : window;
  6071. scope.init(_global);
  6072. var edgeTarget = (function () {});
  6073. var elements = (function () {});
  6074. var grid = (function (grid) {
  6075. var coordFields = [['x', 'y'], ['left', 'top'], ['right', 'bottom'], ['width', 'height']].filter(function (_ref) {
  6076. var xField = _ref[0],
  6077. yField = _ref[1];
  6078. return xField in grid || yField in grid;
  6079. });
  6080. var gridFunc = function gridFunc(x, y) {
  6081. var range = grid.range,
  6082. _grid$limits = grid.limits,
  6083. limits = _grid$limits === void 0 ? {
  6084. left: -Infinity,
  6085. right: Infinity,
  6086. top: -Infinity,
  6087. bottom: Infinity
  6088. } : _grid$limits,
  6089. _grid$offset = grid.offset,
  6090. offset = _grid$offset === void 0 ? {
  6091. x: 0,
  6092. y: 0
  6093. } : _grid$offset;
  6094. var result = {
  6095. range: range,
  6096. grid: grid,
  6097. x: null,
  6098. y: null
  6099. };
  6100. for (var _i2 = 0; _i2 < coordFields.length; _i2++) {
  6101. var _coordFields$_i = coordFields[_i2],
  6102. xField = _coordFields$_i[0],
  6103. yField = _coordFields$_i[1];
  6104. var gridx = Math.round((x - offset.x) / grid[xField]);
  6105. var gridy = Math.round((y - offset.y) / grid[yField]);
  6106. result[xField] = Math.max(limits.left, Math.min(limits.right, gridx * grid[xField] + offset.x));
  6107. result[yField] = Math.max(limits.top, Math.min(limits.bottom, gridy * grid[yField] + offset.y));
  6108. }
  6109. return result;
  6110. };
  6111. gridFunc.grid = grid;
  6112. gridFunc.coordFields = coordFields;
  6113. return gridFunc;
  6114. });
  6115. /* eslint-disable import/no-named-as-default, import/no-unresolved */
  6116. var allSnappers = /*#__PURE__*/Object.freeze({
  6117. __proto__: null,
  6118. edgeTarget: edgeTarget,
  6119. elements: elements,
  6120. grid: grid
  6121. });
  6122. var snappersPlugin = {
  6123. id: 'snappers',
  6124. install: function install(scope) {
  6125. var interact = scope.interactStatic;
  6126. interact.snappers = extend(interact.snappers || {}, allSnappers);
  6127. interact.createSnapGrid = interact.snappers.grid;
  6128. }
  6129. };
  6130. var snappers = snappersPlugin;
  6131. var aspectRatio = {
  6132. start: function start(arg) {
  6133. var state = arg.state,
  6134. rect = arg.rect,
  6135. edges = arg.edges,
  6136. coords = arg.pageCoords;
  6137. var _state$options = state.options,
  6138. ratio = _state$options.ratio,
  6139. enabled = _state$options.enabled;
  6140. var _state$options2 = state.options,
  6141. equalDelta = _state$options2.equalDelta,
  6142. modifiers = _state$options2.modifiers;
  6143. if (ratio === 'preserve') {
  6144. ratio = rect.width / rect.height;
  6145. }
  6146. state.startCoords = extend({}, coords);
  6147. state.startRect = extend({}, rect);
  6148. state.ratio = ratio;
  6149. state.equalDelta = equalDelta;
  6150. var linkedEdges = state.linkedEdges = {
  6151. top: edges.top || edges.left && !edges.bottom,
  6152. left: edges.left || edges.top && !edges.right,
  6153. bottom: edges.bottom || edges.right && !edges.top,
  6154. right: edges.right || edges.bottom && !edges.left
  6155. };
  6156. state.xIsPrimaryAxis = !!(edges.left || edges.right);
  6157. if (state.equalDelta) {
  6158. var sign = (linkedEdges.left ? 1 : -1) * (linkedEdges.top ? 1 : -1);
  6159. state.edgeSign = {
  6160. x: sign,
  6161. y: sign
  6162. };
  6163. } else {
  6164. state.edgeSign = {
  6165. x: linkedEdges.left ? -1 : 1,
  6166. y: linkedEdges.top ? -1 : 1
  6167. };
  6168. }
  6169. if (enabled !== false) {
  6170. extend(edges, linkedEdges);
  6171. }
  6172. if (!(modifiers != null && modifiers.length)) return;
  6173. var subModification = new Modification(arg.interaction);
  6174. subModification.copyFrom(arg.interaction.modification);
  6175. subModification.prepareStates(modifiers);
  6176. state.subModification = subModification;
  6177. subModification.startAll(_objectSpread2({}, arg));
  6178. },
  6179. set: function set(arg) {
  6180. var state = arg.state,
  6181. rect = arg.rect,
  6182. coords = arg.coords;
  6183. var linkedEdges = state.linkedEdges;
  6184. var initialCoords = extend({}, coords);
  6185. var aspectMethod = state.equalDelta ? setEqualDelta : setRatio;
  6186. extend(arg.edges, linkedEdges);
  6187. aspectMethod(state, state.xIsPrimaryAxis, coords, rect);
  6188. if (!state.subModification) {
  6189. return null;
  6190. }
  6191. var correctedRect = extend({}, rect);
  6192. addEdges(linkedEdges, correctedRect, {
  6193. x: coords.x - initialCoords.x,
  6194. y: coords.y - initialCoords.y
  6195. });
  6196. var result = state.subModification.setAll(_objectSpread2(_objectSpread2({}, arg), {}, {
  6197. rect: correctedRect,
  6198. edges: linkedEdges,
  6199. pageCoords: coords,
  6200. prevCoords: coords,
  6201. prevRect: correctedRect
  6202. }));
  6203. var delta = result.delta;
  6204. if (result.changed) {
  6205. var xIsCriticalAxis = Math.abs(delta.x) > Math.abs(delta.y);
  6206. // do aspect modification again with critical edge axis as primary
  6207. aspectMethod(state, xIsCriticalAxis, result.coords, result.rect);
  6208. extend(coords, result.coords);
  6209. }
  6210. return result.eventProps;
  6211. },
  6212. defaults: {
  6213. ratio: 'preserve',
  6214. equalDelta: false,
  6215. modifiers: [],
  6216. enabled: false
  6217. }
  6218. };
  6219. function setEqualDelta(_ref, xIsPrimaryAxis, coords) {
  6220. var startCoords = _ref.startCoords,
  6221. edgeSign = _ref.edgeSign;
  6222. if (xIsPrimaryAxis) {
  6223. coords.y = startCoords.y + (coords.x - startCoords.x) * edgeSign.y;
  6224. } else {
  6225. coords.x = startCoords.x + (coords.y - startCoords.y) * edgeSign.x;
  6226. }
  6227. }
  6228. function setRatio(_ref2, xIsPrimaryAxis, coords, rect) {
  6229. var startRect = _ref2.startRect,
  6230. startCoords = _ref2.startCoords,
  6231. ratio = _ref2.ratio,
  6232. edgeSign = _ref2.edgeSign;
  6233. if (xIsPrimaryAxis) {
  6234. var newHeight = rect.width / ratio;
  6235. coords.y = startCoords.y + (newHeight - startRect.height) * edgeSign.y;
  6236. } else {
  6237. var newWidth = rect.height * ratio;
  6238. coords.x = startCoords.x + (newWidth - startRect.width) * edgeSign.x;
  6239. }
  6240. }
  6241. var aspectRatio$1 = makeModifier(aspectRatio, 'aspectRatio');
  6242. var noop = function noop() {};
  6243. noop._defaults = {};
  6244. var rubberband = noop;
  6245. function start$5(_ref) {
  6246. var rect = _ref.rect,
  6247. startOffset = _ref.startOffset,
  6248. state = _ref.state,
  6249. interaction = _ref.interaction,
  6250. pageCoords = _ref.pageCoords;
  6251. var options = state.options;
  6252. var elementRect = options.elementRect;
  6253. var offset = extend({
  6254. left: 0,
  6255. top: 0,
  6256. right: 0,
  6257. bottom: 0
  6258. }, options.offset || {});
  6259. if (rect && elementRect) {
  6260. var restriction = getRestrictionRect(options.restriction, interaction, pageCoords);
  6261. if (restriction) {
  6262. var widthDiff = restriction.right - restriction.left - rect.width;
  6263. var heightDiff = restriction.bottom - restriction.top - rect.height;
  6264. if (widthDiff < 0) {
  6265. offset.left += widthDiff;
  6266. offset.right += widthDiff;
  6267. }
  6268. if (heightDiff < 0) {
  6269. offset.top += heightDiff;
  6270. offset.bottom += heightDiff;
  6271. }
  6272. }
  6273. offset.left += startOffset.left - rect.width * elementRect.left;
  6274. offset.top += startOffset.top - rect.height * elementRect.top;
  6275. offset.right += startOffset.right - rect.width * (1 - elementRect.right);
  6276. offset.bottom += startOffset.bottom - rect.height * (1 - elementRect.bottom);
  6277. }
  6278. state.offset = offset;
  6279. }
  6280. function set$4(_ref2) {
  6281. var coords = _ref2.coords,
  6282. interaction = _ref2.interaction,
  6283. state = _ref2.state;
  6284. var options = state.options,
  6285. offset = state.offset;
  6286. var restriction = getRestrictionRect(options.restriction, interaction, coords);
  6287. if (!restriction) return;
  6288. var rect = xywhToTlbr(restriction);
  6289. coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left);
  6290. coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top);
  6291. }
  6292. function getRestrictionRect(value, interaction, coords) {
  6293. if (is.func(value)) {
  6294. return resolveRectLike(value, interaction.interactable, interaction.element, [coords.x, coords.y, interaction]);
  6295. } else {
  6296. return resolveRectLike(value, interaction.interactable, interaction.element);
  6297. }
  6298. }
  6299. var defaults$6 = {
  6300. restriction: null,
  6301. elementRect: null,
  6302. offset: null,
  6303. endOnly: false,
  6304. enabled: false
  6305. };
  6306. var restrict = {
  6307. start: start$5,
  6308. set: set$4,
  6309. defaults: defaults$6
  6310. };
  6311. var restrict$1 = makeModifier(restrict, 'restrict');
  6312. // This modifier adds the options.resize.restrictEdges setting which sets min and
  6313. // max for the top, left, bottom and right edges of the target being resized.
  6314. //
  6315. // interact(target).resize({
  6316. // edges: { top: true, left: true },
  6317. // restrictEdges: {
  6318. // inner: { top: 200, left: 200, right: 400, bottom: 400 },
  6319. // outer: { top: 0, left: 0, right: 600, bottom: 600 },
  6320. // },
  6321. // })
  6322. var noInner = {
  6323. top: +Infinity,
  6324. left: +Infinity,
  6325. bottom: -Infinity,
  6326. right: -Infinity
  6327. };
  6328. var noOuter = {
  6329. top: -Infinity,
  6330. left: -Infinity,
  6331. bottom: +Infinity,
  6332. right: +Infinity
  6333. };
  6334. function start$4(_ref) {
  6335. var interaction = _ref.interaction,
  6336. startOffset = _ref.startOffset,
  6337. state = _ref.state;
  6338. var options = state.options;
  6339. var offset;
  6340. if (options) {
  6341. var offsetRect = getRestrictionRect(options.offset, interaction, interaction.coords.start.page);
  6342. offset = rectToXY(offsetRect);
  6343. }
  6344. offset = offset || {
  6345. x: 0,
  6346. y: 0
  6347. };
  6348. state.offset = {
  6349. top: offset.y + startOffset.top,
  6350. left: offset.x + startOffset.left,
  6351. bottom: offset.y - startOffset.bottom,
  6352. right: offset.x - startOffset.right
  6353. };
  6354. }
  6355. function set$3(_ref2) {
  6356. var coords = _ref2.coords,
  6357. edges = _ref2.edges,
  6358. interaction = _ref2.interaction,
  6359. state = _ref2.state;
  6360. var offset = state.offset,
  6361. options = state.options;
  6362. if (!edges) {
  6363. return;
  6364. }
  6365. var page = extend({}, coords);
  6366. var inner = getRestrictionRect(options.inner, interaction, page) || {};
  6367. var outer = getRestrictionRect(options.outer, interaction, page) || {};
  6368. fixRect(inner, noInner);
  6369. fixRect(outer, noOuter);
  6370. if (edges.top) {
  6371. coords.y = Math.min(Math.max(outer.top + offset.top, page.y), inner.top + offset.top);
  6372. } else if (edges.bottom) {
  6373. coords.y = Math.max(Math.min(outer.bottom + offset.bottom, page.y), inner.bottom + offset.bottom);
  6374. }
  6375. if (edges.left) {
  6376. coords.x = Math.min(Math.max(outer.left + offset.left, page.x), inner.left + offset.left);
  6377. } else if (edges.right) {
  6378. coords.x = Math.max(Math.min(outer.right + offset.right, page.x), inner.right + offset.right);
  6379. }
  6380. }
  6381. function fixRect(rect, defaults) {
  6382. for (var _i2 = 0, _ref4 = ['top', 'left', 'bottom', 'right']; _i2 < _ref4.length; _i2++) {
  6383. var edge = _ref4[_i2];
  6384. if (!(edge in rect)) {
  6385. rect[edge] = defaults[edge];
  6386. }
  6387. }
  6388. return rect;
  6389. }
  6390. var defaults$5 = {
  6391. inner: null,
  6392. outer: null,
  6393. offset: null,
  6394. endOnly: false,
  6395. enabled: false
  6396. };
  6397. var restrictEdges = {
  6398. noInner: noInner,
  6399. noOuter: noOuter,
  6400. start: start$4,
  6401. set: set$3,
  6402. defaults: defaults$5
  6403. };
  6404. var restrictEdges$1 = makeModifier(restrictEdges, 'restrictEdges');
  6405. var defaults$4 = extend({
  6406. get elementRect() {
  6407. return {
  6408. top: 0,
  6409. left: 0,
  6410. bottom: 1,
  6411. right: 1
  6412. };
  6413. },
  6414. set elementRect(_) {}
  6415. }, restrict.defaults);
  6416. var restrictRect = {
  6417. start: restrict.start,
  6418. set: restrict.set,
  6419. defaults: defaults$4
  6420. };
  6421. var restrictRect$1 = makeModifier(restrictRect, 'restrictRect');
  6422. var noMin = {
  6423. width: -Infinity,
  6424. height: -Infinity
  6425. };
  6426. var noMax = {
  6427. width: +Infinity,
  6428. height: +Infinity
  6429. };
  6430. function start$3(arg) {
  6431. return restrictEdges.start(arg);
  6432. }
  6433. function set$2(arg) {
  6434. var interaction = arg.interaction,
  6435. state = arg.state,
  6436. rect = arg.rect,
  6437. edges = arg.edges;
  6438. var options = state.options;
  6439. if (!edges) {
  6440. return;
  6441. }
  6442. var minSize = tlbrToXywh(getRestrictionRect(options.min, interaction, arg.coords)) || noMin;
  6443. var maxSize = tlbrToXywh(getRestrictionRect(options.max, interaction, arg.coords)) || noMax;
  6444. state.options = {
  6445. endOnly: options.endOnly,
  6446. inner: extend({}, restrictEdges.noInner),
  6447. outer: extend({}, restrictEdges.noOuter)
  6448. };
  6449. if (edges.top) {
  6450. state.options.inner.top = rect.bottom - minSize.height;
  6451. state.options.outer.top = rect.bottom - maxSize.height;
  6452. } else if (edges.bottom) {
  6453. state.options.inner.bottom = rect.top + minSize.height;
  6454. state.options.outer.bottom = rect.top + maxSize.height;
  6455. }
  6456. if (edges.left) {
  6457. state.options.inner.left = rect.right - minSize.width;
  6458. state.options.outer.left = rect.right - maxSize.width;
  6459. } else if (edges.right) {
  6460. state.options.inner.right = rect.left + minSize.width;
  6461. state.options.outer.right = rect.left + maxSize.width;
  6462. }
  6463. restrictEdges.set(arg);
  6464. state.options = options;
  6465. }
  6466. var defaults$3 = {
  6467. min: null,
  6468. max: null,
  6469. endOnly: false,
  6470. enabled: false
  6471. };
  6472. var restrictSize = {
  6473. start: start$3,
  6474. set: set$2,
  6475. defaults: defaults$3
  6476. };
  6477. var restrictSize$1 = makeModifier(restrictSize, 'restrictSize');
  6478. function start$2(arg) {
  6479. var interaction = arg.interaction,
  6480. interactable = arg.interactable,
  6481. element = arg.element,
  6482. rect = arg.rect,
  6483. state = arg.state,
  6484. startOffset = arg.startOffset;
  6485. var options = state.options;
  6486. var origin = options.offsetWithOrigin ? getOrigin(arg) : {
  6487. x: 0,
  6488. y: 0
  6489. };
  6490. var snapOffset;
  6491. if (options.offset === 'startCoords') {
  6492. snapOffset = {
  6493. x: interaction.coords.start.page.x,
  6494. y: interaction.coords.start.page.y
  6495. };
  6496. } else {
  6497. var offsetRect = resolveRectLike(options.offset, interactable, element, [interaction]);
  6498. snapOffset = rectToXY(offsetRect) || {
  6499. x: 0,
  6500. y: 0
  6501. };
  6502. snapOffset.x += origin.x;
  6503. snapOffset.y += origin.y;
  6504. }
  6505. var relativePoints = options.relativePoints;
  6506. state.offsets = rect && relativePoints && relativePoints.length ? relativePoints.map(function (relativePoint, index) {
  6507. return {
  6508. index: index,
  6509. relativePoint: relativePoint,
  6510. x: startOffset.left - rect.width * relativePoint.x + snapOffset.x,
  6511. y: startOffset.top - rect.height * relativePoint.y + snapOffset.y
  6512. };
  6513. }) : [{
  6514. index: 0,
  6515. relativePoint: null,
  6516. x: snapOffset.x,
  6517. y: snapOffset.y
  6518. }];
  6519. }
  6520. function set$1(arg) {
  6521. var interaction = arg.interaction,
  6522. coords = arg.coords,
  6523. state = arg.state;
  6524. var options = state.options,
  6525. offsets = state.offsets;
  6526. var origin = getOriginXY(interaction.interactable, interaction.element, interaction.prepared.name);
  6527. var page = extend({}, coords);
  6528. var targets = [];
  6529. if (!options.offsetWithOrigin) {
  6530. page.x -= origin.x;
  6531. page.y -= origin.y;
  6532. }
  6533. for (var _i2 = 0, _ref2 = offsets; _i2 < _ref2.length; _i2++) {
  6534. var _offset = _ref2[_i2];
  6535. var relativeX = page.x - _offset.x;
  6536. var relativeY = page.y - _offset.y;
  6537. for (var _index = 0, len = options.targets.length; _index < len; _index++) {
  6538. var snapTarget = options.targets[_index];
  6539. var target = void 0;
  6540. if (is.func(snapTarget)) {
  6541. target = snapTarget(relativeX, relativeY, interaction._proxy, _offset, _index);
  6542. } else {
  6543. target = snapTarget;
  6544. }
  6545. if (!target) {
  6546. continue;
  6547. }
  6548. targets.push({
  6549. x: (is.number(target.x) ? target.x : relativeX) + _offset.x,
  6550. y: (is.number(target.y) ? target.y : relativeY) + _offset.y,
  6551. range: is.number(target.range) ? target.range : options.range,
  6552. source: snapTarget,
  6553. index: _index,
  6554. offset: _offset
  6555. });
  6556. }
  6557. }
  6558. var closest = {
  6559. target: null,
  6560. inRange: false,
  6561. distance: 0,
  6562. range: 0,
  6563. delta: {
  6564. x: 0,
  6565. y: 0
  6566. }
  6567. };
  6568. for (var _i4 = 0; _i4 < targets.length; _i4++) {
  6569. var _target = targets[_i4];
  6570. var range = _target.range;
  6571. var dx = _target.x - page.x;
  6572. var dy = _target.y - page.y;
  6573. var distance = hypot(dx, dy);
  6574. var inRange = distance <= range;
  6575. // Infinite targets count as being out of range
  6576. // compared to non infinite ones that are in range
  6577. if (range === Infinity && closest.inRange && closest.range !== Infinity) {
  6578. inRange = false;
  6579. }
  6580. if (!closest.target || (inRange ?
  6581. // is the closest target in range?
  6582. closest.inRange && range !== Infinity ?
  6583. // the pointer is relatively deeper in this target
  6584. distance / range < closest.distance / closest.range :
  6585. // this target has Infinite range and the closest doesn't
  6586. range === Infinity && closest.range !== Infinity ||
  6587. // OR this target is closer that the previous closest
  6588. distance < closest.distance :
  6589. // The other is not in range and the pointer is closer to this target
  6590. !closest.inRange && distance < closest.distance)) {
  6591. closest.target = _target;
  6592. closest.distance = distance;
  6593. closest.range = range;
  6594. closest.inRange = inRange;
  6595. closest.delta.x = dx;
  6596. closest.delta.y = dy;
  6597. }
  6598. }
  6599. if (closest.inRange) {
  6600. coords.x = closest.target.x;
  6601. coords.y = closest.target.y;
  6602. }
  6603. state.closest = closest;
  6604. return closest;
  6605. }
  6606. function getOrigin(arg) {
  6607. var element = arg.interaction.element;
  6608. var optionsOrigin = rectToXY(resolveRectLike(arg.state.options.origin, null, null, [element]));
  6609. var origin = optionsOrigin || getOriginXY(arg.interactable, element, arg.interaction.prepared.name);
  6610. return origin;
  6611. }
  6612. var defaults$2 = {
  6613. range: Infinity,
  6614. targets: null,
  6615. offset: null,
  6616. offsetWithOrigin: true,
  6617. origin: null,
  6618. relativePoints: null,
  6619. endOnly: false,
  6620. enabled: false
  6621. };
  6622. var snap = {
  6623. start: start$2,
  6624. set: set$1,
  6625. defaults: defaults$2
  6626. };
  6627. var snap$1 = makeModifier(snap, 'snap');
  6628. // This modifier allows snapping of the size of targets during resize
  6629. // interactions.
  6630. function start$1(arg) {
  6631. var state = arg.state,
  6632. edges = arg.edges;
  6633. var options = state.options;
  6634. if (!edges) {
  6635. return null;
  6636. }
  6637. arg.state = {
  6638. options: {
  6639. targets: null,
  6640. relativePoints: [{
  6641. x: edges.left ? 0 : 1,
  6642. y: edges.top ? 0 : 1
  6643. }],
  6644. offset: options.offset || 'self',
  6645. origin: {
  6646. x: 0,
  6647. y: 0
  6648. },
  6649. range: options.range
  6650. }
  6651. };
  6652. state.targetFields = state.targetFields || [['width', 'height'], ['x', 'y']];
  6653. snap.start(arg);
  6654. state.offsets = arg.state.offsets;
  6655. arg.state = state;
  6656. }
  6657. function set(arg) {
  6658. var interaction = arg.interaction,
  6659. state = arg.state,
  6660. coords = arg.coords;
  6661. var options = state.options,
  6662. offsets = state.offsets;
  6663. var relative = {
  6664. x: coords.x - offsets[0].x,
  6665. y: coords.y - offsets[0].y
  6666. };
  6667. state.options = extend({}, options);
  6668. state.options.targets = [];
  6669. for (var _i2 = 0, _ref2 = options.targets || []; _i2 < _ref2.length; _i2++) {
  6670. var snapTarget = _ref2[_i2];
  6671. var target = void 0;
  6672. if (is.func(snapTarget)) {
  6673. target = snapTarget(relative.x, relative.y, interaction);
  6674. } else {
  6675. target = snapTarget;
  6676. }
  6677. if (!target) {
  6678. continue;
  6679. }
  6680. for (var _i4 = 0, _state$targetFields2 = state.targetFields; _i4 < _state$targetFields2.length; _i4++) {
  6681. var _state$targetFields2$ = _state$targetFields2[_i4],
  6682. xField = _state$targetFields2$[0],
  6683. yField = _state$targetFields2$[1];
  6684. if (xField in target || yField in target) {
  6685. target.x = target[xField];
  6686. target.y = target[yField];
  6687. break;
  6688. }
  6689. }
  6690. state.options.targets.push(target);
  6691. }
  6692. var returnValue = snap.set(arg);
  6693. state.options = options;
  6694. return returnValue;
  6695. }
  6696. var defaults$1 = {
  6697. range: Infinity,
  6698. targets: null,
  6699. offset: null,
  6700. endOnly: false,
  6701. enabled: false
  6702. };
  6703. var snapSize = {
  6704. start: start$1,
  6705. set: set,
  6706. defaults: defaults$1
  6707. };
  6708. var snapSize$1 = makeModifier(snapSize, 'snapSize');
  6709. /**
  6710. * @module modifiers/snapEdges
  6711. *
  6712. * @description
  6713. * This modifier allows snapping of the edges of targets during resize
  6714. * interactions.
  6715. *
  6716. * ```js
  6717. * interact(target).resizable({
  6718. * snapEdges: {
  6719. * targets: [interact.snappers.grid({ x: 100, y: 50 })],
  6720. * },
  6721. * })
  6722. *
  6723. * interact(target).resizable({
  6724. * snapEdges: {
  6725. * targets: [
  6726. * interact.snappers.grid({
  6727. * top: 50,
  6728. * left: 50,
  6729. * bottom: 100,
  6730. * right: 100,
  6731. * }),
  6732. * ],
  6733. * },
  6734. * })
  6735. * ```
  6736. */
  6737. function start(arg) {
  6738. var edges = arg.edges;
  6739. if (!edges) {
  6740. return null;
  6741. }
  6742. arg.state.targetFields = arg.state.targetFields || [[edges.left ? 'left' : 'right', edges.top ? 'top' : 'bottom']];
  6743. return snapSize.start(arg);
  6744. }
  6745. var snapEdges = {
  6746. start: start,
  6747. set: snapSize.set,
  6748. defaults: extend(clone(snapSize.defaults), {
  6749. targets: undefined,
  6750. range: undefined,
  6751. offset: {
  6752. x: 0,
  6753. y: 0
  6754. }
  6755. })
  6756. };
  6757. var snapEdges$1 = makeModifier(snapEdges, 'snapEdges');
  6758. /* eslint-disable n/no-extraneous-import, import/no-unresolved */
  6759. var all = {
  6760. aspectRatio: aspectRatio$1,
  6761. restrictEdges: restrictEdges$1,
  6762. restrict: restrict$1,
  6763. restrictRect: restrictRect$1,
  6764. restrictSize: restrictSize$1,
  6765. snapEdges: snapEdges$1,
  6766. snap: snap$1,
  6767. snapSize: snapSize$1,
  6768. spring: rubberband,
  6769. avoid: rubberband,
  6770. transform: rubberband,
  6771. rubberband: rubberband
  6772. };
  6773. /* eslint-enable import/no-duplicates */
  6774. var modifiers = {
  6775. id: 'modifiers',
  6776. install: function install(scope) {
  6777. var interact = scope.interactStatic;
  6778. scope.usePlugin(base);
  6779. scope.usePlugin(snappers);
  6780. interact.modifiers = all;
  6781. // for backwrads compatibility
  6782. for (var type in all) {
  6783. var _all = all[type],
  6784. _defaults = _all._defaults,
  6785. _methods = _all._methods;
  6786. _defaults._methods = _methods;
  6787. scope.defaults.perAction[type] = _defaults;
  6788. }
  6789. }
  6790. };
  6791. var modifiers$1 = modifiers;
  6792. var PointerEvent = /*#__PURE__*/function (_BaseEvent) {
  6793. _inherits(PointerEvent, _BaseEvent);
  6794. var _super = _createSuper(PointerEvent);
  6795. function PointerEvent(type, pointer, event, eventTarget, interaction, timeStamp) {
  6796. var _this;
  6797. _classCallCheck(this, PointerEvent);
  6798. _this = _super.call(this, interaction);
  6799. pointerExtend(_assertThisInitialized(_this), event);
  6800. if (event !== pointer) {
  6801. pointerExtend(_assertThisInitialized(_this), pointer);
  6802. }
  6803. _this.timeStamp = timeStamp;
  6804. _this.originalEvent = event;
  6805. _this.type = type;
  6806. _this.pointerId = getPointerId(pointer);
  6807. _this.pointerType = getPointerType(pointer);
  6808. _this.target = eventTarget;
  6809. _this.currentTarget = null;
  6810. if (type === 'tap') {
  6811. var pointerIndex = interaction.getPointerIndex(pointer);
  6812. _this.dt = _this.timeStamp - interaction.pointers[pointerIndex].downTime;
  6813. var interval = _this.timeStamp - interaction.tapTime;
  6814. _this.double = !!interaction.prevTap && interaction.prevTap.type !== 'doubletap' && interaction.prevTap.target === _this.target && interval < 500;
  6815. } else if (type === 'doubletap') {
  6816. _this.dt = pointer.timeStamp - interaction.tapTime;
  6817. _this.double = true;
  6818. }
  6819. return _this;
  6820. }
  6821. _createClass(PointerEvent, [{
  6822. key: "_subtractOrigin",
  6823. value: function _subtractOrigin(_ref) {
  6824. var originX = _ref.x,
  6825. originY = _ref.y;
  6826. this.pageX -= originX;
  6827. this.pageY -= originY;
  6828. this.clientX -= originX;
  6829. this.clientY -= originY;
  6830. return this;
  6831. }
  6832. }, {
  6833. key: "_addOrigin",
  6834. value: function _addOrigin(_ref2) {
  6835. var originX = _ref2.x,
  6836. originY = _ref2.y;
  6837. this.pageX += originX;
  6838. this.pageY += originY;
  6839. this.clientX += originX;
  6840. this.clientY += originY;
  6841. return this;
  6842. }
  6843. /**
  6844. * Prevent the default behaviour of the original Event
  6845. */
  6846. }, {
  6847. key: "preventDefault",
  6848. value: function preventDefault() {
  6849. this.originalEvent.preventDefault();
  6850. }
  6851. }]);
  6852. return PointerEvent;
  6853. }(BaseEvent);
  6854. var defaults = {
  6855. holdDuration: 600,
  6856. ignoreFrom: null,
  6857. allowFrom: null,
  6858. origin: {
  6859. x: 0,
  6860. y: 0
  6861. }
  6862. };
  6863. var pointerEvents$1 = {
  6864. id: 'pointer-events/base',
  6865. before: ['inertia', 'modifiers', 'auto-start', 'actions'],
  6866. install: install$3,
  6867. listeners: {
  6868. 'interactions:new': addInteractionProps,
  6869. 'interactions:update-pointer': addHoldInfo,
  6870. 'interactions:move': moveAndClearHold,
  6871. 'interactions:down': function interactionsDown(arg, scope) {
  6872. downAndStartHold(arg, scope);
  6873. fire(arg, scope);
  6874. },
  6875. 'interactions:up': function interactionsUp(arg, scope) {
  6876. clearHold(arg);
  6877. fire(arg, scope);
  6878. tapAfterUp(arg, scope);
  6879. },
  6880. 'interactions:cancel': function interactionsCancel(arg, scope) {
  6881. clearHold(arg);
  6882. fire(arg, scope);
  6883. }
  6884. },
  6885. PointerEvent: PointerEvent,
  6886. fire: fire,
  6887. collectEventTargets: collectEventTargets,
  6888. defaults: defaults,
  6889. types: {
  6890. down: true,
  6891. move: true,
  6892. up: true,
  6893. cancel: true,
  6894. tap: true,
  6895. doubletap: true,
  6896. hold: true
  6897. }
  6898. };
  6899. function fire(arg, scope) {
  6900. var interaction = arg.interaction,
  6901. pointer = arg.pointer,
  6902. event = arg.event,
  6903. eventTarget = arg.eventTarget,
  6904. type = arg.type,
  6905. _arg$targets = arg.targets,
  6906. targets = _arg$targets === void 0 ? collectEventTargets(arg, scope) : _arg$targets;
  6907. var pointerEvent = new PointerEvent(type, pointer, event, eventTarget, interaction, scope.now());
  6908. scope.fire('pointerEvents:new', {
  6909. pointerEvent: pointerEvent
  6910. });
  6911. var signalArg = {
  6912. interaction: interaction,
  6913. pointer: pointer,
  6914. event: event,
  6915. eventTarget: eventTarget,
  6916. targets: targets,
  6917. type: type,
  6918. pointerEvent: pointerEvent
  6919. };
  6920. for (var i = 0; i < targets.length; i++) {
  6921. var target = targets[i];
  6922. for (var prop in target.props || {}) {
  6923. pointerEvent[prop] = target.props[prop];
  6924. }
  6925. var origin = getOriginXY(target.eventable, target.node);
  6926. pointerEvent._subtractOrigin(origin);
  6927. pointerEvent.eventable = target.eventable;
  6928. pointerEvent.currentTarget = target.node;
  6929. target.eventable.fire(pointerEvent);
  6930. pointerEvent._addOrigin(origin);
  6931. if (pointerEvent.immediatePropagationStopped || pointerEvent.propagationStopped && i + 1 < targets.length && targets[i + 1].node !== pointerEvent.currentTarget) {
  6932. break;
  6933. }
  6934. }
  6935. scope.fire('pointerEvents:fired', signalArg);
  6936. if (type === 'tap') {
  6937. // if pointerEvent should make a double tap, create and fire a doubletap
  6938. // PointerEvent and use that as the prevTap
  6939. var prevTap = pointerEvent.double ? fire({
  6940. interaction: interaction,
  6941. pointer: pointer,
  6942. event: event,
  6943. eventTarget: eventTarget,
  6944. type: 'doubletap'
  6945. }, scope) : pointerEvent;
  6946. interaction.prevTap = prevTap;
  6947. interaction.tapTime = prevTap.timeStamp;
  6948. }
  6949. return pointerEvent;
  6950. }
  6951. function collectEventTargets(_ref, scope) {
  6952. var interaction = _ref.interaction,
  6953. pointer = _ref.pointer,
  6954. event = _ref.event,
  6955. eventTarget = _ref.eventTarget,
  6956. type = _ref.type;
  6957. var pointerIndex = interaction.getPointerIndex(pointer);
  6958. var pointerInfo = interaction.pointers[pointerIndex];
  6959. // do not fire a tap event if the pointer was moved before being lifted
  6960. if (type === 'tap' && (interaction.pointerWasMoved ||
  6961. // or if the pointerup target is different to the pointerdown target
  6962. !(pointerInfo && pointerInfo.downTarget === eventTarget))) {
  6963. return [];
  6964. }
  6965. var path = getPath(eventTarget);
  6966. var signalArg = {
  6967. interaction: interaction,
  6968. pointer: pointer,
  6969. event: event,
  6970. eventTarget: eventTarget,
  6971. type: type,
  6972. path: path,
  6973. targets: [],
  6974. node: null
  6975. };
  6976. for (var _i2 = 0; _i2 < path.length; _i2++) {
  6977. var node = path[_i2];
  6978. signalArg.node = node;
  6979. scope.fire('pointerEvents:collect-targets', signalArg);
  6980. }
  6981. if (type === 'hold') {
  6982. signalArg.targets = signalArg.targets.filter(function (target) {
  6983. var _interaction$pointers, _interaction$pointers2;
  6984. return target.eventable.options.holdDuration === ((_interaction$pointers = interaction.pointers[pointerIndex]) == null ? void 0 : (_interaction$pointers2 = _interaction$pointers.hold) == null ? void 0 : _interaction$pointers2.duration);
  6985. });
  6986. }
  6987. return signalArg.targets;
  6988. }
  6989. function addInteractionProps(_ref2) {
  6990. var interaction = _ref2.interaction;
  6991. interaction.prevTap = null; // the most recent tap event on this interaction
  6992. interaction.tapTime = 0; // time of the most recent tap event
  6993. }
  6994. function addHoldInfo(_ref3) {
  6995. var down = _ref3.down,
  6996. pointerInfo = _ref3.pointerInfo;
  6997. if (!down && pointerInfo.hold) {
  6998. return;
  6999. }
  7000. pointerInfo.hold = {
  7001. duration: Infinity,
  7002. timeout: null
  7003. };
  7004. }
  7005. function clearHold(_ref4) {
  7006. var interaction = _ref4.interaction,
  7007. pointerIndex = _ref4.pointerIndex;
  7008. var hold = interaction.pointers[pointerIndex].hold;
  7009. if (hold && hold.timeout) {
  7010. clearTimeout(hold.timeout);
  7011. hold.timeout = null;
  7012. }
  7013. }
  7014. function moveAndClearHold(arg, scope) {
  7015. var interaction = arg.interaction,
  7016. pointer = arg.pointer,
  7017. event = arg.event,
  7018. eventTarget = arg.eventTarget,
  7019. duplicate = arg.duplicate;
  7020. if (!duplicate && (!interaction.pointerIsDown || interaction.pointerWasMoved)) {
  7021. if (interaction.pointerIsDown) {
  7022. clearHold(arg);
  7023. }
  7024. fire({
  7025. interaction: interaction,
  7026. pointer: pointer,
  7027. event: event,
  7028. eventTarget: eventTarget,
  7029. type: 'move'
  7030. }, scope);
  7031. }
  7032. }
  7033. function downAndStartHold(_ref5, scope) {
  7034. var interaction = _ref5.interaction,
  7035. pointer = _ref5.pointer,
  7036. event = _ref5.event,
  7037. eventTarget = _ref5.eventTarget,
  7038. pointerIndex = _ref5.pointerIndex;
  7039. var timer = interaction.pointers[pointerIndex].hold;
  7040. var path = getPath(eventTarget);
  7041. var signalArg = {
  7042. interaction: interaction,
  7043. pointer: pointer,
  7044. event: event,
  7045. eventTarget: eventTarget,
  7046. type: 'hold',
  7047. targets: [],
  7048. path: path,
  7049. node: null
  7050. };
  7051. for (var _i4 = 0; _i4 < path.length; _i4++) {
  7052. var node = path[_i4];
  7053. signalArg.node = node;
  7054. scope.fire('pointerEvents:collect-targets', signalArg);
  7055. }
  7056. if (!signalArg.targets.length) return;
  7057. var minDuration = Infinity;
  7058. for (var _i6 = 0, _signalArg$targets2 = signalArg.targets; _i6 < _signalArg$targets2.length; _i6++) {
  7059. var target = _signalArg$targets2[_i6];
  7060. var holdDuration = target.eventable.options.holdDuration;
  7061. if (holdDuration < minDuration) {
  7062. minDuration = holdDuration;
  7063. }
  7064. }
  7065. timer.duration = minDuration;
  7066. timer.timeout = setTimeout(function () {
  7067. fire({
  7068. interaction: interaction,
  7069. eventTarget: eventTarget,
  7070. pointer: pointer,
  7071. event: event,
  7072. type: 'hold'
  7073. }, scope);
  7074. }, minDuration);
  7075. }
  7076. function tapAfterUp(_ref6, scope) {
  7077. var interaction = _ref6.interaction,
  7078. pointer = _ref6.pointer,
  7079. event = _ref6.event,
  7080. eventTarget = _ref6.eventTarget;
  7081. if (!interaction.pointerWasMoved) {
  7082. fire({
  7083. interaction: interaction,
  7084. eventTarget: eventTarget,
  7085. pointer: pointer,
  7086. event: event,
  7087. type: 'tap'
  7088. }, scope);
  7089. }
  7090. }
  7091. function install$3(scope) {
  7092. scope.pointerEvents = pointerEvents$1;
  7093. scope.defaults.actions.pointerEvents = pointerEvents$1.defaults;
  7094. extend(scope.actions.phaselessTypes, pointerEvents$1.types);
  7095. }
  7096. var pointerEvents$2 = /*#__PURE__*/Object.freeze({
  7097. __proto__: null,
  7098. default: pointerEvents$1
  7099. });
  7100. /* eslint-disable import/no-duplicates -- for typescript module augmentations */
  7101. function install$2(scope) {
  7102. scope.usePlugin(pointerEvents$1);
  7103. var pointerEvents = scope.pointerEvents;
  7104. // don't repeat by default
  7105. pointerEvents.defaults.holdRepeatInterval = 0;
  7106. pointerEvents.types.holdrepeat = scope.actions.phaselessTypes.holdrepeat = true;
  7107. }
  7108. function onNew(_ref) {
  7109. var pointerEvent = _ref.pointerEvent;
  7110. if (pointerEvent.type !== 'hold') return;
  7111. pointerEvent.count = (pointerEvent.count || 0) + 1;
  7112. }
  7113. function onFired(_ref2, scope) {
  7114. var interaction = _ref2.interaction,
  7115. pointerEvent = _ref2.pointerEvent,
  7116. eventTarget = _ref2.eventTarget,
  7117. targets = _ref2.targets;
  7118. if (pointerEvent.type !== 'hold' || !targets.length) return;
  7119. // get the repeat interval from the first eventable
  7120. var interval = targets[0].eventable.options.holdRepeatInterval;
  7121. // don't repeat if the interval is 0 or less
  7122. if (interval <= 0) return;
  7123. // set a timeout to fire the holdrepeat event
  7124. interaction.holdIntervalHandle = setTimeout(function () {
  7125. scope.pointerEvents.fire({
  7126. interaction: interaction,
  7127. eventTarget: eventTarget,
  7128. type: 'hold',
  7129. pointer: pointerEvent,
  7130. event: pointerEvent
  7131. }, scope);
  7132. }, interval);
  7133. }
  7134. function endHoldRepeat(_ref3) {
  7135. var interaction = _ref3.interaction;
  7136. // set the interaction's holdStopTime property
  7137. // to stop further holdRepeat events
  7138. if (interaction.holdIntervalHandle) {
  7139. clearInterval(interaction.holdIntervalHandle);
  7140. interaction.holdIntervalHandle = null;
  7141. }
  7142. }
  7143. var holdRepeat = {
  7144. id: 'pointer-events/holdRepeat',
  7145. install: install$2,
  7146. listeners: ['move', 'up', 'cancel', 'endall'].reduce(function (acc, enderTypes) {
  7147. acc["pointerEvents:".concat(enderTypes)] = endHoldRepeat;
  7148. return acc;
  7149. }, {
  7150. 'pointerEvents:new': onNew,
  7151. 'pointerEvents:fired': onFired
  7152. })
  7153. };
  7154. var holdRepeat$1 = holdRepeat;
  7155. function install$1(scope) {
  7156. var Interactable = scope.Interactable;
  7157. Interactable.prototype.pointerEvents = function (options) {
  7158. extend(this.events.options, options);
  7159. return this;
  7160. };
  7161. var __backCompatOption = Interactable.prototype._backCompatOption;
  7162. Interactable.prototype._backCompatOption = function (optionName, newValue) {
  7163. var ret = __backCompatOption.call(this, optionName, newValue);
  7164. if (ret === this) {
  7165. this.events.options[optionName] = newValue;
  7166. }
  7167. return ret;
  7168. };
  7169. }
  7170. var plugin$1 = {
  7171. id: 'pointer-events/interactableTargets',
  7172. install: install$1,
  7173. listeners: {
  7174. 'pointerEvents:collect-targets': function pointerEventsCollectTargets(_ref, scope) {
  7175. var targets = _ref.targets,
  7176. node = _ref.node,
  7177. type = _ref.type,
  7178. eventTarget = _ref.eventTarget;
  7179. scope.interactables.forEachMatch(node, function (interactable) {
  7180. var eventable = interactable.events;
  7181. var options = eventable.options;
  7182. if (eventable.types[type] && eventable.types[type].length && interactable.testIgnoreAllow(options, node, eventTarget)) {
  7183. targets.push({
  7184. node: node,
  7185. eventable: eventable,
  7186. props: {
  7187. interactable: interactable
  7188. }
  7189. });
  7190. }
  7191. });
  7192. },
  7193. 'interactable:new': function interactableNew(_ref2) {
  7194. var interactable = _ref2.interactable;
  7195. interactable.events.getRect = function (element) {
  7196. return interactable.getRect(element);
  7197. };
  7198. },
  7199. 'interactable:set': function interactableSet(_ref3, scope) {
  7200. var interactable = _ref3.interactable,
  7201. options = _ref3.options;
  7202. extend(interactable.events.options, scope.pointerEvents.defaults);
  7203. extend(interactable.events.options, options.pointerEvents || {});
  7204. }
  7205. }
  7206. };
  7207. var interactableTargets = plugin$1;
  7208. /* eslint-disable import/no-duplicates -- for typescript module augmentations */
  7209. /* eslint-enable import/no-duplicates */
  7210. var plugin = {
  7211. id: 'pointer-events',
  7212. install: function install(scope) {
  7213. scope.usePlugin(pointerEvents$2);
  7214. scope.usePlugin(holdRepeat$1);
  7215. scope.usePlugin(interactableTargets);
  7216. }
  7217. };
  7218. var pointerEvents = plugin;
  7219. function install(scope) {
  7220. var Interactable = scope.Interactable;
  7221. scope.actions.phases.reflow = true;
  7222. Interactable.prototype.reflow = function (action) {
  7223. return doReflow(this, action, scope);
  7224. };
  7225. }
  7226. function doReflow(interactable, action, scope) {
  7227. var elements = interactable.getAllElements();
  7228. // tslint:disable-next-line variable-name
  7229. var Promise = scope.window.Promise;
  7230. var promises = Promise ? [] : null;
  7231. var _loop = function _loop() {
  7232. var element = elements[_i2];
  7233. var rect = interactable.getRect(element);
  7234. if (!rect) {
  7235. return 1; // break
  7236. }
  7237. var runningInteraction = find(scope.interactions.list, function (interaction) {
  7238. return interaction.interacting() && interaction.interactable === interactable && interaction.element === element && interaction.prepared.name === action.name;
  7239. });
  7240. var reflowPromise;
  7241. if (runningInteraction) {
  7242. runningInteraction.move();
  7243. if (promises) {
  7244. reflowPromise = runningInteraction._reflowPromise || new Promise(function (resolve) {
  7245. runningInteraction._reflowResolve = resolve;
  7246. });
  7247. }
  7248. } else {
  7249. var xywh = tlbrToXywh(rect);
  7250. var coords = {
  7251. page: {
  7252. x: xywh.x,
  7253. y: xywh.y
  7254. },
  7255. client: {
  7256. x: xywh.x,
  7257. y: xywh.y
  7258. },
  7259. timeStamp: scope.now()
  7260. };
  7261. var event = coordsToEvent(coords);
  7262. reflowPromise = startReflow(scope, interactable, element, action, event);
  7263. }
  7264. if (promises) {
  7265. promises.push(reflowPromise);
  7266. }
  7267. };
  7268. for (var _i2 = 0; _i2 < elements.length; _i2++) {
  7269. if (_loop()) break;
  7270. }
  7271. return promises && Promise.all(promises).then(function () {
  7272. return interactable;
  7273. });
  7274. }
  7275. function startReflow(scope, interactable, element, action, event) {
  7276. var interaction = scope.interactions.new({
  7277. pointerType: 'reflow'
  7278. });
  7279. var signalArg = {
  7280. interaction: interaction,
  7281. event: event,
  7282. pointer: event,
  7283. eventTarget: element,
  7284. phase: 'reflow'
  7285. };
  7286. interaction.interactable = interactable;
  7287. interaction.element = element;
  7288. interaction.prevEvent = event;
  7289. interaction.updatePointer(event, event, element, true);
  7290. setZeroCoords(interaction.coords.delta);
  7291. copyAction(interaction.prepared, action);
  7292. interaction._doPhase(signalArg);
  7293. var _ref = scope.window,
  7294. Promise = _ref.Promise;
  7295. var reflowPromise = Promise ? new Promise(function (resolve) {
  7296. interaction._reflowResolve = resolve;
  7297. }) : undefined;
  7298. interaction._reflowPromise = reflowPromise;
  7299. interaction.start(action, interactable, element);
  7300. if (interaction._interacting) {
  7301. interaction.move(signalArg);
  7302. interaction.end(event);
  7303. } else {
  7304. interaction.stop();
  7305. interaction._reflowResolve();
  7306. }
  7307. interaction.removePointer(event, event);
  7308. return reflowPromise;
  7309. }
  7310. var reflow = {
  7311. id: 'reflow',
  7312. install: install,
  7313. listeners: {
  7314. // remove completed reflow interactions
  7315. 'interactions:stop': function interactionsStop(_ref2, scope) {
  7316. var interaction = _ref2.interaction;
  7317. if (interaction.pointerType === 'reflow') {
  7318. if (interaction._reflowResolve) {
  7319. interaction._reflowResolve();
  7320. }
  7321. remove(scope.interactions.list, interaction);
  7322. }
  7323. }
  7324. }
  7325. };
  7326. var reflow$1 = reflow;
  7327. /* eslint-disable import/no-duplicates -- for typescript module augmentations */
  7328. /* eslint-enable import/no-duplicates */
  7329. interact$1.use(interactablePreventDefault);
  7330. interact$1.use(offset$1);
  7331. // pointerEvents
  7332. interact$1.use(pointerEvents);
  7333. // inertia
  7334. interact$1.use(inertia$1);
  7335. // snap, resize, etc.
  7336. interact$1.use(modifiers$1);
  7337. // autoStart, hold
  7338. interact$1.use(autoStart);
  7339. // drag and drop, resize, gesture
  7340. interact$1.use(actions);
  7341. // autoScroll
  7342. interact$1.use(autoScroll$1);
  7343. // reflow
  7344. interact$1.use(reflow$1);
  7345. // eslint-disable-next-line no-undef
  7346. {
  7347. interact$1.use(devTools);
  7348. }
  7349. interact$1.default = interact$1;
  7350. if ((typeof module === "undefined" ? "undefined" : _typeof(module)) === 'object' && !!module) {
  7351. try {
  7352. module.exports = interact$1;
  7353. } catch (_unused) {}
  7354. }
  7355. interact$1.default = interact$1;
  7356. return interact$1;
  7357. }));
  7358. //# sourceMappingURL=interact.js.map