{ "version": 3, "sources": [ "plugin.ts" ], "names": [ "Interaction", "domUtils", "is", "raf", "getStringOptionResult", "getWindow", "autoScroll", "defaults", "enabled", "margin", "container", "speed", "now", "Date", "interaction", "i", "x", "y", "isScrolling", "prevTime", "start", "cancel", "request", "scroll", "stop", "interactable", "element", "actionName", "prepared", "name", "options", "getContainer", "dt", "s", "scrollBy", "prevScroll", "getScroll", "window", "scrollLeft", "scrollTop", "curScroll", "delta", "fire", "type", "target", "check", "_options$actionName$a", "onInteractionMove", "pointer", "interacting", "simulation", "top", "right", "bottom", "left", "clientX", "clientY", "innerWidth", "innerHeight", "rect", "getElementClientRect", "value", "string", "document", "body", "getScrollSize", "scrollWidth", "scrollHeight", "getScrollSizeDelta", "func", "scrollOptions", "scrollContainer", "prevSize", "curSize", "autoScrollPlugin", "id", "install", "scope", "actions", "phaselessTypes", "autoscroll", "perAction", "listeners", "[object Object]", "interactions:stop", "interactions:action-move", "arg" ], "mappings": "OACOA,MAAiB,wCAGZC,MAAc,mCACnBC,MAAQ,6BACRC,MAAS,uDACPC,MAA6B,4CAC7BC,MAAiB,0BA4C1B,MAAMC,EAAa,CACjBC,SAAU,CACRC,SAAW,EACXC,OAAW,GAGXC,UAAW,KAGXC,MAAW,KAGbC,IAAKC,KAAKD,IAEVE,YAAa,KACbC,EAAG,EAGHC,EAAG,EACHC,EAAG,EAEHC,aAAa,EACbC,SAAU,EACVV,OAAQ,EACRE,MAAO,EAEPS,MAAON,GACLR,EAAWY,aAAc,EACzBf,EAAIkB,OAAOf,EAAWS,GAEtBD,EAAYR,WAAaA,EACzBA,EAAWQ,YAAcA,EACzBR,EAAWa,SAAWb,EAAWM,MACjCN,EAAWS,EAAIZ,EAAImB,QAAQhB,EAAWiB,SAGxCC,OACElB,EAAWY,aAAc,EACrBZ,EAAWQ,cACbR,EAAWQ,YAAYR,WAAa,MAEtCH,EAAIkB,OAAOf,EAAWS,IAIxBQ,SACE,MAAMT,YAAEA,GAAgBR,GAClBmB,aAAEA,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SAASC,MAEjD,CAAEhD,EAAGN,EAAUwD,YAAajD,EAAGP,EAAUyD,qBAG3C,SAASC,oBAA0CtD,YAAEA,EAAFY,QAAeA,GAGtE2C,GACD,MAAMC,EAAgBxD,GAAeA,EAAYW,aAAaK,QAAQhB,EAAYc,SAASC,MAAMvB,WAEjG,IAAKgE,IAAkBA,EAAc9D,QAEnC,OADA6D,IACO,CAAErD,EAAG,EAAGC,EAAG,GAGpB,MAAMsD,EAAkBxC,aACtBuC,EAAc5D,UACdI,EAAYW,aACZC,GAGI8C,EAAWpC,UAAUmC,GAC3BF,IACA,MAAMI,EAAUrC,UAAUmC,GAE1B,MAAO,CACLvD,EAAGyD,EAAQzD,EAAIwD,EAASxD,EACxBC,EAAGwD,EAAQxD,EAAIuD,EAASvD,GAI5B,MAAMyD,EAA2B,CAC/BC,GAAI,cACJC,QApNgBC,GAChB,MAAMtE,SACJA,EADIuE,QAEJA,GACED,EAEJA,EAAMvE,WAAaA,EACnBA,EAAWM,IAAM,IAAMiE,EAAMjE,MAE7BkE,EAAQC,eAAeC,YAAa,EACpCzE,EAAS0E,UAAU3E,WAAaA,EAAWC,UA2M3C2E,UAAW,CACTC,oBAAuBrE,YAAAA,IACrBA,EAAYR,WAAa,MAG3B6E,wBAA2BrE,YAAAA,IACzBA,EAAYR,WAAa,KACzBA,EAAWkB,OACPlB,EAAWQ,cACbR,EAAWQ,YAAc,OAI7BsE,oBAAqB9E,EAAWkB,KAEhC6D,2BAA6BC,GAAahF,EAAWyC,kBAAkBuC,oBAI5DZ", "sourcesContent": [ "import { Interactable } from '@interactjs/core/Interactable'\nimport Interaction from '@interactjs/core/Interaction'\nimport { ActionName, Plugin } from '@interactjs/core/scope'\nimport { PointerType } from '@interactjs/types/index'\nimport * as domUtils from '@interactjs/utils/domUtils'\nimport is from '@interactjs/utils/is'\nimport raf from '@interactjs/utils/raf'\nimport { getStringOptionResult } from '@interactjs/utils/rect'\nimport { getWindow } from '@interactjs/utils/window'\n\ntype Scope = import ('@interactjs/core/scope').Scope\n\ndeclare module '@interactjs/core/scope' {\n interface Scope {\n autoScroll: typeof autoScroll\n }\n}\n\ndeclare module '@interactjs/core/Interaction' {\n interface Interaction {\n autoScroll?: typeof autoScroll\n }\n}\n\ndeclare module '@interactjs/core/defaultOptions' {\n interface PerActionDefaults {\n autoScroll?: AutoScrollOptions\n }\n}\n\nexport interface AutoScrollOptions {\n container?: Window | HTMLElement\n margin?: number\n distance?: number\n interval?: number\n speed?: number\n enabled?: boolean\n}\n\nfunction install (scope: Scope) {\n const {\n defaults,\n actions,\n } = scope\n\n scope.autoScroll = autoScroll\n autoScroll.now = () => scope.now()\n\n actions.phaselessTypes.autoscroll = true\n defaults.perAction.autoScroll = autoScroll.defaults\n}\n\nconst autoScroll = {\n defaults: {\n enabled : false,\n margin : 60,\n\n // the item that is scrolled (Window or HTMLElement)\n container: null as AutoScrollOptions['container'],\n\n // the scroll speed in pixels per second\n speed : 300,\n } as AutoScrollOptions,\n\n now: Date.now,\n\n interaction: null as Interaction,\n i: 0, // the handle returned by window.setInterval\n\n // Direction each pulse is to scroll in\n x: 0,\n y: 0,\n\n isScrolling: false,\n prevTime: 0,\n margin: 0,\n speed: 0,\n\n start (interaction: Interaction) {\n autoScroll.isScrolling = true\n raf.cancel(autoScroll.i)\n\n interaction.autoScroll = autoScroll\n autoScroll.interaction = interaction\n autoScroll.prevTime = autoScroll.now()\n autoScroll.i = raf.request(autoScroll.scroll)\n },\n\n stop () {\n autoScroll.isScrolling = false\n if (autoScroll.interaction) {\n autoScroll.interaction.autoScroll = null\n }\n raf.cancel(autoScroll.i)\n },\n\n // scroll the window by the values in scroll.x/y\n scroll () {\n const { interaction } = autoScroll\n const { interactable, element } = interaction\n const actionName = interaction.prepared.name\n const options = interactable.options[actionName].autoScroll\n const container = getContainer(options.container, interactable, element)\n const now = autoScroll.now()\n // change in time in seconds\n const dt = (now - autoScroll.prevTime) / 1000\n // displacement\n const s = options.speed * dt\n\n if (s >= 1) {\n const scrollBy = {\n x: autoScroll.x * s,\n y: autoScroll.y * s,\n }\n\n if (scrollBy.x || scrollBy.y) {\n const prevScroll = getScroll(container)\n\n if (is.window(container)) {\n container.scrollBy(scrollBy.x, scrollBy.y)\n }\n else if (container) {\n container.scrollLeft += scrollBy.x\n container.scrollTop += scrollBy.y\n }\n\n const curScroll = getScroll(container)\n const delta = {\n x: curScroll.x - prevScroll.x,\n y: curScroll.y - prevScroll.y,\n }\n\n if (delta.x || delta.y) {\n interactable.fire({\n type: 'autoscroll',\n target: element,\n interactable,\n delta,\n interaction,\n container,\n })\n }\n }\n\n autoScroll.prevTime = now\n }\n\n if (autoScroll.isScrolling) {\n raf.cancel(autoScroll.i)\n autoScroll.i = raf.request(autoScroll.scroll)\n }\n },\n check (interactable: Interactable, actionName: ActionName) {\n const options = interactable.options\n\n return options[actionName].autoScroll?.enabled\n },\n onInteractionMove ({ interaction, pointer }: { interaction: Interaction, pointer: PointerType }) {\n if (!(interaction.interacting() &&\n autoScroll.check(interaction.interactable, interaction.prepared.name))) {\n return\n }\n\n if (interaction.simulation) {\n autoScroll.x = autoScroll.y = 0\n return\n }\n\n let top: boolean\n let right: boolean\n let bottom: boolean\n let left: boolean\n\n const { interactable, element } = interaction\n const actionName = interaction.prepared.name\n const options = interactable.options[actionName].autoScroll\n const container = getContainer(options.container, interactable, element)\n\n if (is.window(container)) {\n left = pointer.clientX < autoScroll.margin\n top = pointer.clientY < autoScroll.margin\n right = pointer.clientX > container.innerWidth - autoScroll.margin\n bottom = pointer.clientY > container.innerHeight - autoScroll.margin\n }\n else {\n const rect = domUtils.getElementClientRect(container)\n\n left = pointer.clientX < rect.left + autoScroll.margin\n top = pointer.clientY < rect.top + autoScroll.margin\n right = pointer.clientX > rect.right - autoScroll.margin\n bottom = pointer.clientY > rect.bottom - autoScroll.margin\n }\n\n autoScroll.x = (right ? 1 : left ? -1 : 0)\n autoScroll.y = (bottom ? 1 : top ? -1 : 0)\n\n if (!autoScroll.isScrolling) {\n // set the autoScroll properties to those of the target\n autoScroll.margin = options.margin\n autoScroll.speed = options.speed\n\n autoScroll.start(interaction)\n }\n },\n}\n\nexport function getContainer (value: any, interactable: Interactable, element: Element) {\n return (is.string(value) ? getStringOptionResult(value, interactable, element) : value) || getWindow(element)\n}\n\nexport function getScroll (container: any) {\n if (is.window(container)) { container = window.document.body }\n\n return { x: container.scrollLeft, y: container.scrollTop }\n}\n\nexport function getScrollSize (container: any) {\n if (is.window(container)) { container = window.document.body }\n\n return { x: container.scrollWidth, y: container.scrollHeight }\n}\n\nexport function getScrollSizeDelta ({ interaction, element }: {\n interaction: Partial>\n element: Element\n}, func: any) {\n const scrollOptions = interaction && interaction.interactable.options[interaction.prepared.name].autoScroll\n\n if (!scrollOptions || !scrollOptions.enabled) {\n func()\n return { x: 0, y: 0 }\n }\n\n const scrollContainer = getContainer(\n scrollOptions.container,\n interaction.interactable,\n element,\n )\n\n const prevSize = getScroll(scrollContainer)\n func()\n const curSize = getScroll(scrollContainer)\n\n return {\n x: curSize.x - prevSize.x,\n y: curSize.y - prevSize.y,\n }\n}\n\nconst autoScrollPlugin: Plugin = {\n id: 'auto-scroll',\n install,\n listeners: {\n 'interactions:new': ({ interaction }) => {\n interaction.autoScroll = null\n },\n\n 'interactions:destroy': ({ interaction }) => {\n interaction.autoScroll = null\n autoScroll.stop()\n if (autoScroll.interaction) {\n autoScroll.interaction = null\n }\n },\n\n 'interactions:stop': autoScroll.stop,\n\n 'interactions:action-move': (arg: any) => autoScroll.onInteractionMove(arg),\n },\n}\n\nexport default autoScrollPlugin\n" ] }