astro-vtbot
Advanced tools
Comparing version 1.7.13 to 1.7.14
@@ -0,1 +1,3 @@ | ||
const PERSIST_ATTR = 'data-astro-transition-persist'; | ||
type SavedFocus = { | ||
@@ -39,4 +41,7 @@ activeElement: HTMLElement | null; | ||
[...document.head.children].forEach((e) => { | ||
if (e instanceof HTMLElement) { | ||
let other = [...doc.head.children].find((o) => o.isEqualNode(e)); | ||
const id = e.getAttribute(PERSIST_ATTR); | ||
let other: Element | "" | null | undefined = id && doc.head.querySelector(`[${PERSIST_ATTR}="${id}"]`); | ||
other ||= [...doc.head.children].find((o) => o.isEqualNode(e)); | ||
(other ?? e).remove(); | ||
@@ -77,2 +82,25 @@ } | ||
export function astroBodySwap(oldEl: Element, newEl: Element) { | ||
const PERSIST_ATTR = 'data-astro-transition-persist'; | ||
const shouldCopyProps = (el: HTMLElement) => { | ||
const persistProps = el.dataset.astroTransitionPersistProps; | ||
return persistProps == null || persistProps === 'false'; | ||
}; | ||
oldEl.replaceWith(newEl); | ||
for (const el of oldEl.querySelectorAll(`[${PERSIST_ATTR}]`)) { | ||
const id = el.getAttribute(PERSIST_ATTR); | ||
const newEl = document.querySelector(`[${PERSIST_ATTR}="${id}"]`); | ||
if (newEl) { | ||
newEl.replaceWith(el); | ||
if (el.localName === 'astro-island' && shouldCopyProps(el as HTMLElement)) { | ||
el.setAttribute('ssr', ''); | ||
el.setAttribute('props', newEl.getAttribute('props')!); | ||
} | ||
} | ||
} | ||
} | ||
/* | ||
@@ -79,0 +107,0 @@ * Execute all steps of the original swap function except the swap of the body element. |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.7.13", | ||
"version": "1.7.14", | ||
"description": "The 👜 Bag of Tricks ✨ for Astro's View Transitions", | ||
@@ -9,0 +9,0 @@ "homepage": "https://github.com/martrapp/astro-vtbot#readme", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89656
1134