{ "version": 3, "sources": [ "plugin.ts" ], "names": [ "Scope", "domObjects", "parentNode", "extend", "is", "win", "CheckName", "touchAction", "boxSizing", "noListeners", "defaultExport", "id", "install" ], "mappings": "gBAESA,MAAqB,+BAEvBC,MAAgB,mDACdC,MAAkB,mCACpBC,MAAY,iCACZC,MAAQ,gCACHC,MAAS,8BA6ChBC,GAAAA,IAAAA,4BAAAA,wBAAAA,8BAAAA,IAAAA,OAwCKA,EAAUC,YAcVD,EAAUE,UAkBVF,EAAUG,YAoCpB,MACMC,EACF,CAAEC,GAFK,YAEDC,4BAwBKF", "sourcesContent": [ "/* eslint-disable no-console */\nimport Interaction from '@interactjs/core/Interaction'\nimport { Scope, Plugin } from '@interactjs/core/scope'\nimport { Element, OptionMethod } from '@interactjs/types/index'\nimport domObjects from '@interactjs/utils/domObjects'\nimport { parentNode } from '@interactjs/utils/domUtils'\nimport extend from '@interactjs/utils/extend'\nimport is from '@interactjs/utils/is'\nimport * as win from '@interactjs/utils/window'\n\nimport visualizer from './visualizer/plugin'\n\ndeclare module '@interactjs/core/scope' {\n interface Scope {\n logger: Logger\n }\n}\n\ndeclare module '@interactjs/core/interactStatic' {\n export interface InteractStatic {\n visializer: typeof visualizer\n }\n}\n\ndeclare module '@interactjs/core/defaultOptions' {\n interface BaseDefaults {\n devTools?: DevToolsOptions\n }\n}\n\ndeclare module '@interactjs/core/Interactable' {\n interface Interactable {\n devTools: OptionMethod\n }\n}\n\nexport interface DevToolsOptions {\n ignore: { [P in keyof typeof CheckName]?: boolean }\n}\n\nexport interface Logger {\n warn: (...args: any[]) => void\n error: (...args: any[]) => void\n log: (...args: any[]) => void\n}\n\nexport interface Check {\n name: CheckName\n text: string\n perform: (interaction: Interaction) => boolean\n getInfo: (interaction: Interaction) => any[]\n}\n\nenum CheckName {\n touchAction = 'touchAction',\n boxSizing = 'boxSizing',\n noListeners = 'noListeners',\n}\n\nconst prefix = '[interact.js] '\nconst links = {\n touchAction: 'https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action',\n boxSizing: 'https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing',\n}\n\n// eslint-disable-next-line no-undef\nconst isProduction = process.env.NODE_ENV === 'production'\n\n// eslint-disable-next-line no-restricted-syntax\nfunction install (scope: Scope, { logger }: { logger?: Logger } = {}) {\n const {\n Interactable,\n defaults,\n } = scope\n\n scope.logger = logger || console\n\n defaults.base.devTools = {\n ignore: {},\n }\n\n Interactable.prototype.devTools = function (options?: object) {\n if (options) {\n extend(this.options.devTools, options)\n return this\n }\n\n return this.options.devTools\n }\n}\n\nconst checks: Check[] = [\n {\n name: CheckName.touchAction,\n perform ({ element }) {\n return !parentHasStyle(element, 'touchAction', /pan-|pinch|none/)\n },\n getInfo ({ element }) {\n return [\n element,\n links.touchAction,\n ]\n },\n text: 'Consider adding CSS \"touch-action: none\" to this element\\n',\n },\n\n {\n name: CheckName.boxSizing,\n perform (interaction) {\n const { element } = interaction\n\n return interaction.prepared.name === 'resize' &&\n element instanceof domObjects.HTMLElement &&\n !hasStyle(element, 'boxSizing', /border-box/)\n },\n text: 'Consider adding CSS \"box-sizing: border-box\" to this resizable element',\n getInfo ({ element }) {\n return [\n element,\n links.boxSizing,\n ]\n },\n },\n\n {\n name: CheckName.noListeners,\n perform (interaction) {\n const actionName = interaction.prepared.name\n const moveListeners = interaction.interactable.events.types[`${actionName}move`] || []\n\n return !moveListeners.length\n },\n getInfo (interaction) {\n return [\n interaction.prepared.name,\n interaction.interactable,\n ]\n },\n text: 'There are no listeners set for this action',\n },\n]\n\nfunction hasStyle (element: HTMLElement, prop: keyof CSSStyleDeclaration, styleRe: RegExp) {\n const value = element.style[prop] || win.window.getComputedStyle(element)[prop]\n return styleRe.test((value || '').toString())\n}\n\nfunction parentHasStyle (element: Element, prop: keyof CSSStyleDeclaration, styleRe: RegExp) {\n let parent = element as HTMLElement\n\n while (is.element(parent)) {\n if (hasStyle(parent, prop, styleRe)) {\n return true\n }\n\n parent = parentNode(parent) as HTMLElement\n }\n\n return false\n}\n\nconst id = 'dev-tools'\nconst defaultExport: Plugin = isProduction\n ? { id, install: () => {} }\n : {\n id,\n install,\n listeners: {\n 'interactions:action-start': ({ interaction }, scope) => {\n for (const check of checks) {\n const options = interaction.interactable && interaction.interactable.options\n\n if (\n !(options && options.devTools && options.devTools.ignore[check.name]) &&\n check.perform(interaction)\n ) {\n scope.logger.warn(prefix + check.text, ...check.getInfo(interaction))\n }\n }\n },\n },\n checks,\n CheckName,\n links,\n prefix,\n }\n\nexport default defaultExport\n" ] }