1 line
8.4 KiB
JSON
1 line
8.4 KiB
JSON
|
{"ast":null,"code":"import { compute as t } from \"compute-scroll-into-view\";\nconst o = t => !1 === t ? {\n block: \"end\",\n inline: \"nearest\"\n} : (t => t === Object(t) && 0 !== Object.keys(t).length)(t) ? t : {\n block: \"start\",\n inline: \"nearest\"\n};\nfunction e(e, r) {\n if (!e.isConnected || !(t => {\n let o = t;\n for (; o && o.parentNode;) {\n if (o.parentNode === document) return !0;\n o = o.parentNode instanceof ShadowRoot ? o.parentNode.host : o.parentNode;\n }\n return !1;\n })(e)) return;\n const n = (t => {\n const o = window.getComputedStyle(t);\n return {\n top: parseFloat(o.scrollMarginTop) || 0,\n right: parseFloat(o.scrollMarginRight) || 0,\n bottom: parseFloat(o.scrollMarginBottom) || 0,\n left: parseFloat(o.scrollMarginLeft) || 0\n };\n })(e);\n if ((t => \"object\" == typeof t && \"function\" == typeof t.behavior)(r)) return r.behavior(t(e, r));\n const l = \"boolean\" == typeof r || null == r ? void 0 : r.behavior;\n for (const {\n el: a,\n top: i,\n left: s\n } of t(e, o(r))) {\n const t = i - n.top + n.bottom,\n o = s - n.left + n.right;\n a.scroll({\n top: t,\n left: o,\n behavior: l\n });\n }\n}\nexport { e as default };","map":{"version":3,"names":["o","t","block","inline","Object","keys","length","e","r","isConnected","parentNode","document","ShadowRoot","host","n","window","getComputedStyle","top","parseFloat","scrollMarginTop","right","scrollMarginRight","bottom","scrollMarginBottom","left","scrollMarginLeft","behavior","l","el","a","i","s","scroll","default"],"sources":["C:\\Users\\Аришина)\\source\\repos\\PromoCursed\\node_modules\\scroll-into-view-if-needed\\src\\index.ts"],"sourcesContent":["import { compute } from 'compute-scroll-into-view'\nimport type {\n Options as BaseOptions,\n ScrollAction,\n} from 'compute-scroll-into-view'\n\n/** @public */\nexport type Options<T = unknown> =\n | StandardBehaviorOptions\n | CustomBehaviorOptions<T>\n\n/**\n * Only scrolls if the `node` is partially out of view:\n * ```ts\n * scrollIntoView(node, { scrollMode: 'if-needed' })\n * ```\n * Skips scrolling `overflow: hidden` elements:\n * ```ts\n * scrollIntoView(node, { skipOverflowHiddenElements: true })\n * ```\n * When scrolling is needed do the least and smoothest scrolling possible:\n * ```ts\n * scrollIntoView(node, {\n * behavior: 'smooth',\n * scrollMode: 'if-needed',\n * block: 'nearest',\n * inline: 'nearest',\n * })\n * ```\n * @public\n */\nexport interface StandardBehaviorOptions extends BaseOptions {\n /**\n * @defaultValue 'auto\n */\n behavior?: ScrollBehavior\n}\n\n/** @public */\nexport interface CustomBehaviorOptions<T = unknown> extends BaseOptions {\n behavior: CustomScrollBehaviorCallback<T>\n}\n\n/** @public */\nexport type CustomScrollBehaviorCallback<T = unknown> = (\n actions: ScrollAction[]\n) => T\n\nconst isStandardScrollBehavior = (\n options: any\n): options is StandardBehaviorOptions =>\n options === Object(options) && Object.keys(options).length !== 0\n\nconst isCustomScrollBehavior = <T = unknown>(\n options: any\n): options is CustomBehaviorOptions<T> =>\n typeof options === 'object' ? typeof options.behavior === 'function' : false\n\nconst getOptions = (options: any): StandardBehaviorOptions => {\n // Handle alignToTop for legacy reasons, to be compatible with the spec\n if (options === false) {\n return { block: 'end', inline: 'nearest' }\n }\n\n if (isStandardScrollBehavior(options)) {\n // compute.ts ensures the defaults are block: 'center' and inline: 'nearest', to conform to the spec\n return options\n }\n\n // if options = {}, options = true or options = null, based on w3c web platform test\n return { block: 'start', inline: 'nearest' }\n}\n\nconst getScrollMargins = (target: Element) => {\n const computedStyle = window.getComputedStyle(target)\n return {\n top: parseFloat(computedStyle.scrollMarginTop) || 0,\n right: parseFloat(computedStyle.scrollMarginRight) || 0,\n bottom: parseFloat(co
|