aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/dumbymap.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r--src/dumbymap.mjs52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs
index 0b42144..cfaf429 100644
--- a/src/dumbymap.mjs
+++ b/src/dumbymap.mjs
@@ -24,6 +24,35 @@ const onRemove = (element, callback) => {
24 }); 24 });
25 obs.observe(parent, { childList: true, }); 25 obs.observe(parent, { childList: true, });
26} 26}
27const animateRectTransition = (child, rect, resume = false) => {
28 const { width: w1, height: h1, left: x1, top: y1 } = rect
29 const { width: w2, height: h2, left: x2, top: y2 } = child.getBoundingClientRect()
30
31 const rw = w1 / w2
32 const rh = h1 / h2
33 const dx = x1 - x2;
34 const dy = y1 - y2;
35
36 if (dx === 0 && dy === 0) {
37 return;
38 }
39
40 const transform1 = `translate(0, 0) scale(1, 1)`;
41 const transform2 = `translate(${dx}px, ${dy}px) scale(${rw}, ${rh})`;
42 const keyframes = [
43 { transform: transform1, opacity: 1 },
44 { transform: transform2, opacity: 0.3 },
45 ]
46
47 return child.animate(
48 resume
49 ? keyframes.reverse()
50 : keyframes,
51 {
52 duration: 300,
53 easing: 'ease-in-out',
54 });
55}
27// }}} 56// }}}
28// FUNCTION: Get DocLinks from special anchor element {{{ 57// FUNCTION: Get DocLinks from special anchor element {{{
29 58
@@ -253,16 +282,29 @@ export const generateMaps = async (container, callback) => {
253 if (shouldBeInShowcase) { 282 if (shouldBeInShowcase) {
254 if (showcase.contains(target)) return 283 if (showcase.contains(target)) return
255 284
256 const placeholder = document.createElement('div') 285 // Placeholder for map in Showcase, it should has the same rect
286 const placeholder = target.cloneNode(true)
287 placeholder.classList.remove('map-container')
257 placeholder.setAttribute('data-placeholder', target.id) 288 placeholder.setAttribute('data-placeholder', target.id)
258 placeholder.style.width = target.style.width
259 target.parentElement.replaceChild(placeholder, target) 289 target.parentElement.replaceChild(placeholder, target)
290
291 // To fit showcase, remove all inline style
292 target.style = ""
260 showcase.appendChild(target) 293 showcase.appendChild(target)
294
295 // Resume rect from Semantic HTML to Showcase, with animation
296 animateRectTransition(target, placeholder.getBoundingClientRect(), true)
261 } else if (showcase.contains(target)) { 297 } else if (showcase.contains(target)) {
262 const placeholder = htmlHolder.querySelector(`[data-placeholder="${target.id}"]`) 298 const placeholder = htmlHolder.querySelector(`[data-placeholder="${target.id}"]`)
263 if (!placeholder) throw Error(`Cannot fine placeholder for map "${target.id}"`) 299 if (!placeholder) throw Error(`Cannot fine placeholder for map "${target.id}"`)
264 placeholder.parentElement.replaceChild(target, placeholder) 300
265 placeholder.remove() 301 animateRectTransition(target, placeholder.getBoundingClientRect())
302 .finished
303 .finally(() => {
304 placeholder.parentElement.replaceChild(target, placeholder)
305 target.style = placeholder.style.cssText
306 placeholder.remove()
307 })
266 } 308 }
267 }) 309 })
268 // }}} 310 // }}}
@@ -343,7 +385,7 @@ export const generateMaps = async (container, callback) => {
343 top: y, 385 top: y,
344 }) 386 })
345 387
346 // Set initial postion side by side 388 // Set initial position side by side
347 x += parseInt(window.getComputedStyle(block).width) + 50 389 x += parseInt(window.getComputedStyle(block).width) + 50
348 if (x > window.innerWidth) { 390 if (x > window.innerWidth) {
349 y += 200 391 y += 200