{ "version": 3, "sources": [ "base.ts" ], "names": [ "InteractEvent", "Interaction", "Modification", "makeModifier", "module", "name", "defaults", "methods", "start", "set", "beforeEnd", "stop", "modifier", "_options", "options", "enabled", "prop", "m", "enable", "disable", "_defaults", "_methods", "addEventModifiers", "iEvent", "interaction", "modification", "result", "modifiers", "eventProps", "modifiersBase", "id", "before", "install", "scope", "perAction", "listeners", "arg", "coords", "page", "edges", "applyToInteraction", "setAndApply", "restoreInteractionCoords" ], "mappings": "AAAA,SAAqBA,aAArB,QAA0C,0BAA1C;AAEA,OAAOC,WAAP,MAAwB,wBAAxB;AAIA,OAAOC,YAAP,MAAyB,mBAAzB;AAwFA,OAAO,SAASC,YAAT,CAKLC,MALK,EAMLC,IANK,EAOL;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAeF,MAArB;AACA,QAAMG,OAAO,GAAG;AACdC,IAAAA,KAAK,EAAEJ,MAAM,CAACI,KADA;AAEdC,IAAAA,GAAG,EAAEL,MAAM,CAACK,GAFE;AAGdC,IAAAA,SAAS,EAAEN,MAAM,CAACM,SAHJ;AAIdC,IAAAA,IAAI,EAAEP,MAAM,CAACO;AAJC,GAAhB;;AAOA,QAAMC,QAAQ,GAAIC,QAAD,IAAkC;AACjD,UAAMC,OAAiB,GAAID,QAAQ,IAAI,EAAvC;AAEAC,IAAAA,OAAO,CAACC,OAAR,GAAkBD,OAAO,CAACC,OAAR,KAAoB,KAAtC,CAHiD,CAKjD;;AACA,SAAK,MAAMC,IAAX,IAAmBV,QAAnB,EAA6B;AAC3B,UAAI,EAAEU,IAAI,IAAIF,OAAV,CAAJ,EAAwB;AACtBA,QAAAA,OAAO,CAACE,IAAD,CAAP,GAAgBV,QAAQ,CAACU,IAAD,CAAxB;AACD;AACF;;AAED,UAAMC,CAAkC,GAAG;AACzCH,MAAAA,OADyC;AAEzCP,MAAAA,OAFyC;AAGzCF,MAAAA,IAHyC;AAIzCa,MAAAA,MAAM,EAAE,MAAM;AACZJ,QAAAA,OAAO,CA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,MAAhB,CAAuB7B,KAAvB,CAA6B8B,IAArD;AACAF,MAAAA,GAAG,CAACZ,WAAJ,CAAgBe,KAAhB,GAAwBd,YAAY,CAACc,KAArC;AACAd,MAAAA,YAAY,CAACe,kBAAb,CAAgCJ,GAAhC;AACD,KAXQ;AAaT,uCAAmCA,GAAG,IAAIA,GAAG,CAACZ,WAAJ,CAAgBC,YAAhB,CAA6BgB,WAA7B,CAAyCL,GAAzC,CAbjC;AAeT,sCAAkCA,GAAG,IAAIA,GAAG,CAACZ,WAAJ,CAAgBC,YAAhB,CAA6Bf,SAA7B,CAAuC0B,GAAvC,CAfhC;AAiBT,iCAA6Bd,iBAjBpB;AAkBT,gCAA4BA,iBAlBnB;AAmBT,+BAA2BA,iBAnBlB;AAqBT,uCAAmCc,GAAG,IAAIA,GAAG,CAACZ,WAAJ,CAAgBC,YAAhB,CAA6BiB,wBAA7B,CAAsDN,GAAtD,CArBjC;AAsBT,sCAAkCA,GAAG,IAAIA,GAAG,CAACZ,WAAJ,CAAgBC,YAAhB,CAA6BiB,wBAA7B,CAAsDN,GAAtD,CAtBhC;AAwBT,yBAAqBA,GAAG,IAAIA,GAAG,CAACZ,WAAJ,CAAgBC,YAAhB,CAA6Bd,IAA7B,CAAkCyB,GAAlC;AAxBnB;AANiB,CAA9B;AAkCA,eAAeP,aAAf", "sourcesContent": [ "import { EventPhase, InteractEvent } from '@interactjs/core/InteractEvent'\nimport { Interactable } from '@interactjs/core/Interactable'\nimport Interaction from '@interactjs/core/Interaction'\nimport { Plugin } from '@interactjs/core/scope'\nimport { EdgeOptions, FullRect, Point, Rect } from '@interactjs/types/index'\n\nimport Modification from './Modification'\n\ndeclare module '@interactjs/core/Interaction' {\n interface Interaction {\n modification?: Modification\n }\n}\n\ndeclare module '@interactjs/core/InteractEvent' {\n interface InteractEvent {\n modifiers?: Array<{\n name: string\n [key: string]: any\n }>\n }\n}\n\ndeclare module '@interactjs/core/defaultOptions' {\n interface PerActionDefaults {\n modifiers?: Modifier[]\n }\n}\n\nexport interface Modifier<\n Defaults = any,\n State extends ModifierState = any,\n Name extends string = any\n> {\n options?: Defaults\n methods: {\n start?: (arg: ModifierArg) => void\n set: (arg: ModifierArg) => void\n beforeEnd?: (arg: ModifierArg) => Point | void\n stop?: (arg: ModifierArg) => void\n }\n name?: Name\n enable: () => Modifier\n disable: () => Modifier\n}\n\nexport type ModifierState<\n Defaults = {},\n StateProps extends { [prop: string]: any } = {},\n Name extends string = any\n> = {\n options: Defaults\n methods?: Modifier['methods']\n index?: number\n name?: Name\n} & StateProps\n\nexport interface ModifierArg {\n interaction: Interaction\n interactable: Interactable\n phase: EventPhase\n rect: FullRect\n edges: EdgeOptions\n state?: State\n element: Element\n pageCoords?: Point\n prevCoords?: Point\n prevRect?: FullRect\n coords?: Point\n startOffset?: Rect\n preEnd?: boolean\n}\n\nexport interface ModifierModule<\n Defaults extends { enabled?: boolean },\n State extends ModifierState,\n> {\n defaults?: Defaults\n start? (arg: ModifierArg): void\n set? (arg: ModifierArg): any\n beforeEnd? (arg: ModifierArg): Point | void\n stop? (arg: ModifierArg): void\n}\n\nexport interface ModifierFunction <\n Defaults extends { enabled?: boolean },\n State extends ModifierState,\n Name extends string,\n> {\n (_options?: Partial): Modifier\n _defaults: Defaults\n _methods: ModifierModule\n}\n\nexport function makeModifier<\n Defaults extends { enabled?: boolean },\n State extends ModifierState,\n Name extends string\n> (\n module: ModifierModule,\n name?: Name,\n) {\n const { defaults } = module\n const methods = {\n start: module.start,\n set: module.set,\n beforeEnd: module.beforeEnd,\n stop: module.stop,\n }\n\n const modifier = (_options?: Partial) => {\n const options: Defaults = (_options || {}) as Defaults\n\n options.enabled = options.enabled !== false\n\n // add missing defaults to options\n for (const prop in defaults) {\n if (!(prop in options)) {\n options[prop] = defaults[prop]\n }\n }\n\n const m: Modifier = {\n options,\n methods,\n name,\n enable: () => {\n options.enabled = true\n return m\n },\n disable: () => {\n options.enabled = false\n return m\n },\n }\n\n return m\n }\n\n if (name && typeof name === 'string') {\n // for backwrads compatibility\n modifier._defaults = defaults\n modifier._methods = methods\n }\n\n return modifier\n}\n\nexport function addEventModifiers ({ iEvent, interaction: { modification: { result } } }: {\n iEvent: InteractEvent\n interaction: Interaction\n}) {\n if (result) {\n iEvent.modifiers = result.eventProps\n }\n}\n\nconst modifiersBase: Plugin = {\n id: 'modifiers/base',\n before: ['actions'],\n install: scope => {\n scope.defaults.perAction.modifiers = []\n },\n listeners: {\n 'interactions:new': ({ interaction }) => {\n interaction.modification = new Modification(interaction)\n },\n\n 'interactions:before-action-start': arg => {\n const { modification } = arg.interaction\n\n modification.start(arg, arg.interaction.coords.start.page)\n arg.interaction.edges = modification.edges\n modification.applyToInteraction(arg)\n },\n\n 'interactions:before-action-move': arg => arg.interaction.modification.setAndApply(arg),\n\n 'interactions:before-action-end': arg => arg.interaction.modification.beforeEnd(arg),\n\n 'interactions:action-start': addEventModifiers,\n 'interactions:action-move': addEventModifiers,\n 'interactions:action-end': addEventModifiers,\n\n 'interactions:after-action-start': arg => arg.interaction.modification.restoreInteractionCoords(arg),\n 'interactions:after-action-move': arg => arg.interaction.modification.restoreInteractionCoords(arg),\n\n 'interactions:stop': arg => arg.interaction.modification.stop(arg),\n },\n}\n\nexport default modifiersBase\n" ] }