diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-08 17:33:26 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-09 14:52:19 +0800 |
commit | 9e62f0371f66cc4f2aa275f958f16a9443b108b7 (patch) | |
tree | 41580b2b047eff59dc37b2fe935789d36a0c4654 /src/dumbyUtils.mjs | |
parent | 551c5c3fbe7163bc78e5159ddbc57967a0299e4e (diff) |
chore: apply standardjs with trailing comma
Diffstat (limited to 'src/dumbyUtils.mjs')
-rw-r--r-- | src/dumbyUtils.mjs | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index 852e4c7..2efc3b1 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs | |||
@@ -6,7 +6,7 @@ import { insideWindow, insideParent } from './utils' | |||
6 | * | 6 | * |
7 | * @param {Boolean} reverse -- focus previous map | 7 | * @param {Boolean} reverse -- focus previous map |
8 | */ | 8 | */ |
9 | export function focusNextMap(reverse = false) { | 9 | export function focusNextMap (reverse = false) { |
10 | const renderedList = this.utils.renderedMaps() | 10 | const renderedList = this.utils.renderedMaps() |
11 | const index = renderedList.findIndex(e => e.classList.contains('focus')) | 11 | const index = renderedList.findIndex(e => e.classList.contains('focus')) |
12 | const nextIndex = (index + (reverse ? -1 : 1)) % renderedList.length | 12 | const nextIndex = (index + (reverse ? -1 : 1)) % renderedList.length |
@@ -21,13 +21,13 @@ export function focusNextMap(reverse = false) { | |||
21 | * | 21 | * |
22 | * @param {Boolean} reverse -- focus previous block | 22 | * @param {Boolean} reverse -- focus previous block |
23 | */ | 23 | */ |
24 | export function focusNextBlock(reverse = false) { | 24 | export function focusNextBlock (reverse = false) { |
25 | const blocks = this.blocks.filter(b => | 25 | const blocks = this.blocks.filter(b => |
26 | b.checkVisibility({ | 26 | b.checkVisibility({ |
27 | contentVisibilityAuto: true, | 27 | contentVisibilityAuto: true, |
28 | opacityProperty: true, | 28 | opacityProperty: true, |
29 | visibilityProperty: true | 29 | visibilityProperty: true, |
30 | }) | 30 | }), |
31 | ) | 31 | ) |
32 | const index = blocks.findIndex(e => e.classList.contains('focus')) | 32 | const index = blocks.findIndex(e => e.classList.contains('focus')) |
33 | const nextIndex = (index + (reverse ? -1 : 1)) % blocks.length | 33 | const nextIndex = (index + (reverse ? -1 : 1)) % blocks.length |
@@ -56,7 +56,7 @@ export const scrollToBlock = block => { | |||
56 | /** | 56 | /** |
57 | * focusDelay. Delay of throttle, value changes by cases | 57 | * focusDelay. Delay of throttle, value changes by cases |
58 | */ | 58 | */ |
59 | export function focusDelay() { | 59 | export function focusDelay () { |
60 | return window.window.getComputedStyle(this.showcase).display === 'none' ? 50 : 300 | 60 | return window.window.getComputedStyle(this.showcase).display === 'none' ? 50 : 300 |
61 | } | 61 | } |
62 | 62 | ||
@@ -65,7 +65,7 @@ export function focusDelay() { | |||
65 | * | 65 | * |
66 | * @param {Boolean} reverse -- Switch to previous one | 66 | * @param {Boolean} reverse -- Switch to previous one |
67 | */ | 67 | */ |
68 | export function switchToNextLayout(reverse = false) { | 68 | export function switchToNextLayout (reverse = false) { |
69 | const layouts = this.layouts | 69 | const layouts = this.layouts |
70 | const currentLayoutName = this.container.getAttribute('data-layout') | 70 | const currentLayoutName = this.container.getAttribute('data-layout') |
71 | const currentIndex = layouts.map(l => l.name).indexOf(currentLayoutName) | 71 | const currentIndex = layouts.map(l => l.name).indexOf(currentLayoutName) |
@@ -81,7 +81,7 @@ export function switchToNextLayout(reverse = false) { | |||
81 | /** | 81 | /** |
82 | * removeBlockFocus. | 82 | * removeBlockFocus. |
83 | */ | 83 | */ |
84 | export function removeBlockFocus() { | 84 | export function removeBlockFocus () { |
85 | this.blocks.forEach(b => b.classList.remove('focus')) | 85 | this.blocks.forEach(b => b.classList.remove('focus')) |
86 | } | 86 | } |
87 | 87 | ||
@@ -94,7 +94,7 @@ export function removeBlockFocus() { | |||
94 | const getMarkersFromMaps = link => { | 94 | const getMarkersFromMaps = link => { |
95 | const maps = Array.from( | 95 | const maps = Array.from( |
96 | link.closest('.Dumby') | 96 | link.closest('.Dumby') |
97 | .querySelectorAll('.mapclay[data-render="fulfilled"]') | 97 | .querySelectorAll('.mapclay[data-render="fulfilled"]'), |
98 | ) | 98 | ) |
99 | return maps | 99 | return maps |
100 | .filter(map => link.targets ? link.targets.includes(map.id) : true) | 100 | .filter(map => link.targets ? link.targets.includes(map.id) : true) |
@@ -105,7 +105,7 @@ const getMarkersFromMaps = link => { | |||
105 | return map.querySelector(`.marker[title="${markerTitle}"]`) ?? | 105 | return map.querySelector(`.marker[title="${markerTitle}"]`) ?? |
106 | renderer.addMarker({ | 106 | renderer.addMarker({ |
107 | xy: link.xy, | 107 | xy: link.xy, |
108 | title: markerTitle | 108 | title: markerTitle, |
109 | }) | 109 | }) |
110 | }) | 110 | }) |
111 | } | 111 | } |
@@ -122,7 +122,7 @@ const addLeaderLine = (link, target) => { | |||
122 | end: target, | 122 | end: target, |
123 | hide: true, | 123 | hide: true, |
124 | middleLabel: link.url.searchParams.get('text'), | 124 | middleLabel: link.url.searchParams.get('text'), |
125 | path: 'magnet' | 125 | path: 'magnet', |
126 | }) | 126 | }) |
127 | line.show('draw', { duration: 300 }) | 127 | line.show('draw', { duration: 300 }) |
128 | 128 | ||
@@ -196,10 +196,10 @@ export const createDocLink = link => { | |||
196 | end: target, | 196 | end: target, |
197 | middleLabel: LeaderLine.pathLabel({ | 197 | middleLabel: LeaderLine.pathLabel({ |
198 | text: label, | 198 | text: label, |
199 | fontWeight: 'bold' | 199 | fontWeight: 'bold', |
200 | }), | 200 | }), |
201 | hide: true, | 201 | hide: true, |
202 | path: 'magnet' | 202 | path: 'magnet', |
203 | }) | 203 | }) |
204 | link.lines.push(line) | 204 | link.lines.push(line) |
205 | line.show('draw', { duration: 300 }) | 205 | line.show('draw', { duration: 300 }) |
@@ -229,7 +229,6 @@ const removeLeaderLines = link => { | |||
229 | * @return {Function} function | 229 | * @return {Function} function |
230 | */ | 230 | */ |
231 | const updateMapCameraByMarker = xy => marker => { | 231 | const updateMapCameraByMarker = xy => marker => { |
232 | console.log('update') | ||
233 | const renderer = marker.closest('.mapclay')?.renderer | 232 | const renderer = marker.closest('.mapclay')?.renderer |
234 | renderer.updateCamera({ center: xy }, true) | 233 | renderer.updateCamera({ center: xy }, true) |
235 | } | 234 | } |
@@ -244,10 +243,17 @@ const isAnchorVisible = anchor => { | |||
244 | return insideWindow(anchor) && insideParent(anchor, mapContainer) | 243 | return insideWindow(anchor) && insideParent(anchor, mapContainer) |
245 | } | 244 | } |
246 | 245 | ||
246 | /** | ||
247 | * addAnchorByPoint. | ||
248 | * | ||
249 | * @param {point} options.point -- object has {x, y} for window coordinates | ||
250 | * @param {HTMLElement} options.map | ||
251 | * @param {Function} options.validateAnchorName -- validate anchor name is OK to use | ||
252 | */ | ||
247 | export const addAnchorByPoint = ({ | 253 | export const addAnchorByPoint = ({ |
248 | point, | 254 | point, |
249 | map, | 255 | map, |
250 | validateAnchorName = () => true | 256 | validateAnchorName = () => true, |
251 | }) => { | 257 | }) => { |
252 | const rect = map.getBoundingClientRect() | 258 | const rect = map.getBoundingClientRect() |
253 | const [x, y] = map.renderer | 259 | const [x, y] = map.renderer |
@@ -268,7 +274,7 @@ export const addAnchorByPoint = ({ | |||
268 | map.renderer.addMarker({ | 274 | map.renderer.addMarker({ |
269 | xy: [x, y], | 275 | xy: [x, y], |
270 | title: `${map.id}@${x},${y}`, | 276 | title: `${map.id}@${x},${y}`, |
271 | type: 'circle' | 277 | type: 'circle', |
272 | }) | 278 | }) |
273 | 279 | ||
274 | return { ref: anchorName, link } | 280 | return { ref: anchorName, link } |