From 1c7e77b8546ac32b8176ab54dd06ede6ba7deb55 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Wed, 2 Oct 2024 10:12:46 +0800 Subject: style: switch to standardjs --- src/dumbyUtils.mjs | 130 ++++++++++++++++++++++++++--------------------------- 1 file changed, 65 insertions(+), 65 deletions(-) (limited to 'src/dumbyUtils.mjs') diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index 2a9b787..7bf26c8 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs @@ -1,62 +1,62 @@ -import LeaderLine from 'leader-line'; +import LeaderLine from 'leader-line' -export function focusNextMap(reverse = false) { - const renderedList = this.utils.renderedMaps(); - const index = renderedList.findIndex(e => e.classList.contains('focus')); +export function focusNextMap (reverse = false) { + const renderedList = this.utils.renderedMaps() + const index = renderedList.findIndex(e => e.classList.contains('focus')) const nextIndex = - index === -1 ? 0 : (index + (reverse ? -1 : 1)) % renderedList.length; + index === -1 ? 0 : (index + (reverse ? -1 : 1)) % renderedList.length - const nextMap = renderedList.at(nextIndex); - nextMap.classList.add('focus'); + const nextMap = renderedList.at(nextIndex) + nextMap.classList.add('focus') } -export function focusNextBlock(reverse = false) { +export function focusNextBlock (reverse = false) { const blocks = this.blocks.filter(b => b.checkVisibility({ contentVisibilityAuto: true, opacityProperty: true, - visibilityProperty: true, - }), - ); - const index = blocks.findIndex(e => e.classList.contains('focus')); + visibilityProperty: true + }) + ) + const index = blocks.findIndex(e => e.classList.contains('focus')) const nextIndex = - index === -1 ? 0 : (index + (reverse ? -1 : 1)) % blocks.length; + index === -1 ? 0 : (index + (reverse ? -1 : 1)) % blocks.length - blocks.forEach(b => b.classList.remove('focus')); - const nextBlock = blocks.at(nextIndex); - nextBlock?.classList?.add('focus'); - scrollToBlock(nextBlock); + blocks.forEach(b => b.classList.remove('focus')) + const nextBlock = blocks.at(nextIndex) + nextBlock?.classList?.add('focus') + scrollToBlock(nextBlock) } // Consider block is bigger then viewport height export const scrollToBlock = block => { - const parentRect = block.parentElement.getBoundingClientRect(); + const parentRect = block.parentElement.getBoundingClientRect() const scrollBlock = block.getBoundingClientRect().height > parentRect.height * 0.8 ? 'nearest' - : 'center'; - block.scrollIntoView({ behavior: 'smooth', block: scrollBlock }); -}; + : 'center' + block.scrollIntoView({ behavior: 'smooth', block: scrollBlock }) +} -export function focusDelay() { - return window.getComputedStyle(this.showcase).display === 'none' ? 50 : 300; +export function focusDelay () { + return window.window.getComputedStyle(this.showcase).display === 'none' ? 50 : 300 } -export function switchToNextLayout(reverse = false) { - const layouts = this.layouts; - const currentLayoutName = this.container.getAttribute('data-layout'); - const currentIndex = layouts.map(l => l.name).indexOf(currentLayoutName); - const padding = reverse ? -1 : 1; +export function switchToNextLayout (reverse = false) { + const layouts = this.layouts + const currentLayoutName = this.container.getAttribute('data-layout') + const currentIndex = layouts.map(l => l.name).indexOf(currentLayoutName) + const padding = reverse ? -1 : 1 const nextIndex = currentIndex === -1 ? 0 - : (currentIndex + padding + layouts.length) % layouts.length; - const nextLayout = layouts[nextIndex]; - this.container.setAttribute('data-layout', nextLayout.name); + : (currentIndex + padding + layouts.length) % layouts.length + const nextLayout = layouts[nextIndex] + this.container.setAttribute('data-layout', nextLayout.name) } -export function removeBlockFocus() { - this.blocks.forEach(b => b.classList.remove('focus')); +export function removeBlockFocus () { + this.blocks.forEach(b => b.classList.remove('focus')) } /** @@ -66,31 +66,31 @@ export function removeBlockFocus() { * @returns {Boolean} ture is link is created, false if coordinates are invalid */ export const createGeoLink = (link, callback = null) => { - const url = new URL(link.href); - const xyInParams = url.searchParams.get('xy'); + const url = new URL(link.href) + const xyInParams = url.searchParams.get('xy') const xy = xyInParams ? xyInParams.split(',')?.map(Number) : url?.href - ?.match(/^geo:([0-9.,]+)/) - ?.at(1) - ?.split(',') - ?.reverse() - ?.map(Number); + ?.match(/^geo:([0-9.,]+)/) + ?.at(1) + ?.split(',') + ?.reverse() + ?.map(Number) - if (!xy || isNaN(xy[0]) || isNaN(xy[1])) return false; + if (!xy || isNaN(xy[0]) || isNaN(xy[1])) return false // Geo information in link - link.url = url; - link.xy = xy; - link.classList.add('with-leader-line', 'geolink'); - link.targets = link.url.searchParams.get('id')?.split(',') ?? null; + link.url = url + link.xy = xy + link.classList.add('with-leader-line', 'geolink') + link.targets = link.url.searchParams.get('id')?.split(',') ?? null // LeaderLine - link.lines = []; - callback?.call(this, link); + link.lines = [] + callback?.call(this, link) - return true; -}; + return true +} /** * CreateDocLink. @@ -98,30 +98,30 @@ export const createGeoLink = (link, callback = null) => { * @param {HTMLElement} Elements contains anchor elements for doclinks */ export const createDocLink = link => { - link.classList.add('with-leader-line', 'doclink'); - link.lines = []; + link.classList.add('with-leader-line', 'doclink') + link.lines = [] link.onmouseover = () => { - const label = decodeURIComponent(link.href.split('#')[1]); - const selector = link.title.split('=>')[1] ?? '#' + label; - const target = document.querySelector(selector); - if (!target?.checkVisibility()) return; + const label = decodeURIComponent(link.href.split('#')[1]) + const selector = link.title.split('=>')[1] ?? '#' + label + const target = document.querySelector(selector) + if (!target?.checkVisibility()) return const line = new LeaderLine({ start: link, end: target, middleLabel: LeaderLine.pathLabel({ text: label, - fontWeight: 'bold', + fontWeight: 'bold' }), hide: true, - path: 'magnet', - }); - link.lines.push(line); - line.show('draw', { duration: 300 }); - }; + path: 'magnet' + }) + link.lines.push(line) + line.show('draw', { duration: 300 }) + } link.onmouseout = () => { - link.lines.forEach(line => line.remove()); - link.lines.length = 0; - }; -}; + link.lines.forEach(line => line.remove()) + link.lines.length = 0 + } +} -- cgit v1.2.3-70-g09d2