swup 3.0.0-rc.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Swup.cjs +1 -1
- package/dist/Swup.cjs.map +1 -1
- package/dist/Swup.modern.js +1 -1
- package/dist/Swup.modern.js.map +1 -1
- package/dist/Swup.module.js +1 -1
- package/dist/Swup.module.js.map +1 -1
- package/dist/Swup.umd.js +1 -1
- package/dist/Swup.umd.js.map +1 -1
- package/dist/types/Swup.d.ts +13 -13
- package/dist/types/__test__/index.test.d.ts +1 -0
- package/dist/types/helpers/fetch.d.ts +2 -2
- package/dist/types/helpers.d.ts +10 -10
- package/dist/types/index.d.ts +3 -3
- package/dist/types/modules/Cache.d.ts +2 -2
- package/dist/types/modules/enterPage.d.ts +1 -1
- package/dist/types/modules/fetchPage.d.ts +3 -3
- package/dist/types/modules/getAnimationPromises.d.ts +1 -1
- package/dist/types/modules/getPageData.d.ts +2 -2
- package/dist/types/modules/leavePage.d.ts +2 -2
- package/dist/types/modules/loadPage.d.ts +1 -1
- package/dist/types/modules/off.d.ts +2 -2
- package/dist/types/modules/on.d.ts +1 -1
- package/dist/types/modules/plugins.d.ts +1 -1
- package/dist/types/modules/renderPage.d.ts +2 -2
- package/dist/types/modules/triggerEvent.d.ts +2 -2
- package/dist/types/modules/updateTransition.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +16 -8
- package/readme.md +2 -2
- package/src/Swup.ts +21 -21
- package/src/__test__/index.test.ts +36 -0
- package/src/helpers/createHistoryRecord.ts +1 -1
- package/src/helpers/fetch.ts +2 -2
- package/src/helpers/getDataFromHtml.ts +1 -1
- package/src/helpers/markSwupElements.ts +1 -1
- package/src/helpers/updateHistoryRecord.ts +1 -1
- package/src/helpers.ts +10 -10
- package/src/index.ts +3 -3
- package/src/modules/Cache.ts +3 -3
- package/src/modules/enterPage.ts +2 -2
- package/src/modules/fetchPage.ts +4 -4
- package/src/modules/getAnchorElement.ts +1 -1
- package/src/modules/getAnimationPromises.ts +2 -2
- package/src/modules/getPageData.ts +3 -3
- package/src/modules/leavePage.ts +2 -2
- package/src/modules/loadPage.ts +3 -3
- package/src/modules/off.ts +2 -2
- package/src/modules/on.ts +1 -1
- package/src/modules/plugins.ts +1 -1
- package/src/modules/renderPage.ts +3 -3
- package/src/modules/triggerEvent.ts +2 -2
- package/src/modules/updateTransition.ts +1 -1
- package/src/utils.ts +1 -1
- package/dist/helpers.cjs +0 -2
- package/dist/helpers.cjs.map +0 -1
- package/dist/helpers.modern.js +0 -2
- package/dist/helpers.modern.js.map +0 -1
- package/dist/helpers.module.js +0 -2
- package/dist/helpers.module.js.map +0 -1
- package/dist/types/helpers/index.d.ts +0 -11
- package/dist/types/helpers/versionSatisfies.d.ts +0 -11
- package/dist/utils.cjs +0 -2
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.modern.js +0 -2
- package/dist/utils.modern.js.map +0 -1
- package/dist/utils.module.js +0 -2
- package/dist/utils.module.js.map +0 -1
package/dist/Swup.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Swup.modern.js","sources":["../src/helpers/classify.ts","../src/helpers/getCurrentUrl.ts","../src/helpers/createHistoryRecord.ts","../src/helpers/updateHistoryRecord.ts","../src/helpers/delegateEvent.ts","../src/utils/index.ts","../src/helpers/getDataFromHtml.ts","../src/helpers/fetch.ts","../src/helpers/Location.ts","../src/helpers/markSwupElements.ts","../src/helpers/cleanupAnimationClasses.ts","../src/modules/Cache.ts","../src/modules/enterPage.ts","../src/modules/getAnchorElement.ts","../src/modules/getAnimationPromises.ts","../src/modules/getPageData.ts","../src/modules/fetchPage.ts","../src/modules/leavePage.ts","../src/modules/loadPage.ts","../src/modules/replaceContent.ts","../src/modules/off.ts","../src/modules/on.ts","../src/modules/plugins.ts","../src/modules/renderPage.ts","../src/modules/triggerEvent.ts","../src/modules/updateTransition.ts","../src/Swup.ts"],"sourcesContent":["export const classify = (text: string, fallback?: string): string => {\n\tconst output = String(text)\n\t\t.toLowerCase()\n\t\t// .normalize('NFD') // split an accented letter in the base letter and the acent\n\t\t// .replace(/[\\u0300-\\u036f]/g, '') // remove all previously split accents\n\t\t.replace(/[\\s/_.]+/g, '-') // replace spaces and _./ with '-'\n\t\t.replace(/[^\\w-]+/g, '') // remove all non-word chars\n\t\t.replace(/--+/g, '-') // replace repeating '-' with single '-'\n\t\t.replace(/^-+|-+$/g, ''); // trim '-' from edges\n\treturn output || fallback || '';\n};\n","export const getCurrentUrl = ({ hash }: { hash?: boolean } = {}): string => {\n\treturn location.pathname + location.search + (hash ? location.hash : '');\n};\n","import { getCurrentUrl } from './getCurrentUrl.js';\n\nexport const createHistoryRecord = (\n\turl: string,\n\tcustomData: Record<string, unknown> = {}\n): void => {\n\turl = url || getCurrentUrl({ hash: true });\n\tconst data = {\n\t\turl,\n\t\trandom: Math.random(),\n\t\tsource: 'swup',\n\t\t...customData\n\t};\n\thistory.pushState(data, '', url);\n};\n","import { getCurrentUrl } from './getCurrentUrl.js';\n\nexport const updateHistoryRecord = (\n\turl: string | null = null,\n\tcustomData: Record<string, unknown> = {}\n): void => {\n\turl = url || getCurrentUrl({ hash: true });\n\tconst data = {\n\t\t...history.state,\n\t\turl,\n\t\trandom: Math.random(),\n\t\tsource: 'swup',\n\t\t...customData\n\t};\n\thistory.replaceState(data, '', url);\n};\n","import delegate, { EventType } from 'delegate-it';\nimport { ParseSelector } from 'typed-query-selector/parser';\n\nexport type Unsubscribe = {\n\tdestroy: () => void;\n};\nexport const delegateEvent = <Selector extends string, TEvent extends EventType>(\n\tselector: Selector,\n\ttype: TEvent,\n\tcallback: delegate.EventHandler<GlobalEventHandlersEventMap[TEvent]>,\n\t{ base = document, ...eventOptions } = {}\n): Unsubscribe => {\n\tconst delegation = delegate<string, ParseSelector<Selector, HTMLElement>, TEvent>(\n\t\tbase,\n\t\tselector,\n\t\ttype,\n\t\tcallback,\n\t\teventOptions\n\t);\n\treturn { destroy: () => delegation.destroy() };\n};\n","export const query = (selector: string, context: Document | Element = document) => {\n\treturn context.querySelector<HTMLElement>(selector);\n};\n\nexport const queryAll = (\n\tselector: string,\n\tcontext: Document | Element = document\n): HTMLElement[] => {\n\treturn Array.from(context.querySelectorAll(selector));\n};\n\nexport const nextTick = (callback: () => void) => {\n\trequestAnimationFrame(() => {\n\t\trequestAnimationFrame(() => {\n\t\t\tcallback();\n\t\t});\n\t});\n};\n\nexport const escapeCssIdentifier = (ident: string) => {\n\t// @ts-ignore this is for support check, so it's correct that TS complains\n\tif (window.CSS && window.CSS.escape) {\n\t\treturn CSS.escape(ident);\n\t} else {\n\t\treturn ident;\n\t}\n};\n\n// Fix for Chrome below v61 formatting CSS floats with comma in some locales\nexport const toMs = (s: string) => {\n\treturn Number(s.slice(0, -1).replace(',', '.')) * 1000;\n};\n","import { query, queryAll } from '../utils.js';\n\nexport type PageHtmlData = {\n\ttitle: string;\n\toriginalContent: string;\n\tblocks: string[];\n\tpageClass?: string;\n};\n\nexport const getDataFromHtml = (html: string, containers: string[]): PageHtmlData => {\n\tlet fakeDom = document.createElement('html');\n\tfakeDom.innerHTML = html;\n\tlet blocks: string[] = [];\n\n\tcontainers.forEach((selector) => {\n\t\tif (query(selector, fakeDom) == null) {\n\t\t\tconsole.warn(`[swup] Container ${selector} not found on page.`);\n\t\t\treturn null;\n\t\t} else {\n\t\t\tif (queryAll(selector).length !== queryAll(selector, fakeDom).length) {\n\t\t\t\tconsole.warn(`[swup] Mismatched number of containers found on new page.`);\n\t\t\t}\n\t\t\tqueryAll(selector).forEach((item, index) => {\n\t\t\t\tqueryAll(selector, fakeDom)[index].setAttribute('data-swup', String(blocks.length));\n\t\t\t\tblocks.push(queryAll(selector, fakeDom)[index].outerHTML);\n\t\t\t});\n\t\t}\n\t});\n\n\tconst title = query('title', fakeDom)?.innerText || '';\n\tconst pageClass = query('body', fakeDom)?.className;\n\n\t// to prevent memory leaks\n\tfakeDom.innerHTML = '';\n\t// @ts-ignore don't want to type it as possible null, since it's created at the top of the function always\n\tfakeDom = null;\n\n\treturn { title, pageClass, blocks, originalContent: html };\n};\n","import { TransitionOptions } from '../modules/loadPage.js';\nimport { Options } from '../Swup.js';\n\nexport const fetch = (\n\toptions: TransitionOptions & { headers: Options['requestHeaders'] },\n\tcallback: (request: XMLHttpRequest) => void\n): XMLHttpRequest => {\n\tconst defaults = {\n\t\turl: window.location.pathname + window.location.search,\n\t\tmethod: 'GET',\n\t\tdata: null,\n\t\theaders: {}\n\t};\n\n\tconst { url, method, headers, data } = { ...defaults, ...options };\n\n\tconst request = new XMLHttpRequest();\n\n\trequest.onreadystatechange = function () {\n\t\tif (request.readyState === 4) {\n\t\t\t// if (request.status === 500) {} else {}\n\t\t\tcallback(request);\n\t\t}\n\t};\n\n\trequest.open(method, url, true);\n\tObject.entries(headers).forEach(([key, header]) => {\n\t\trequest.setRequestHeader(key, header);\n\t});\n\trequest.send(data);\n\n\treturn request;\n};\n","/**\n * A helper for creating a Location from either an element\n * or a URL object/string\n *\n */\n\nexport class Location extends URL {\n\tconstructor(url: string, base: string = document.baseURI) {\n\t\tsuper(url.toString(), base);\n\t}\n\n\tget url() {\n\t\treturn this.pathname + this.search;\n\t}\n\n\t/**\n\t * Instantiate a Location from an element's href attribute\n\t * @param {Element} el\n\t * @return new Location instance\n\t */\n\tstatic fromElement(el: HTMLAnchorElement): Location {\n\t\tconst href = el.getAttribute('href') || el.getAttribute('xlink:href');\n\t\treturn new Location(href!);\n\t}\n\n\t/**\n\t * Instantiate a Location from a URL object or string\n\t * @param {URL|string} url\n\t * @return new Location instance\n\t */\n\tstatic fromUrl(url: string): Location {\n\t\treturn new Location(url);\n\t}\n}\n","import { query, queryAll } from '../utils.js';\n\nexport const markSwupElements = (element: Element, containers: string[]): void => {\n\tlet blocks = 0;\n\n\tcontainers.forEach((selector) => {\n\t\tif (query(selector, element) == null) {\n\t\t\tconsole.warn(`[swup] Container ${selector} not found on page.`);\n\t\t} else {\n\t\t\tqueryAll(selector).forEach((item: Element, index: number) => {\n\t\t\t\tqueryAll(selector, element)[index].setAttribute('data-swup', String(blocks));\n\t\t\t\tblocks++;\n\t\t\t});\n\t\t}\n\t});\n};\n","export const isSwupClass = (className: string): boolean =>\n\t/^to-/.test(className) || ['is-changing', 'is-rendering', 'is-popstate'].includes(className);\n\nexport const cleanupAnimationClasses = (): void => {\n\tconst htmlClasses = document.documentElement.className.split(' ');\n\tconst removeClasses = htmlClasses.filter(isSwupClass);\n\tdocument.documentElement.classList.remove(...removeClasses);\n};\n","import { getCurrentUrl, Location } from '../helpers.js';\nimport Swup from '../Swup.js';\nimport { PageData } from './getPageData.js';\n\nexport interface PageRecord extends PageData {\n\turl: string;\n\tresponseURL: string;\n}\nexport class Cache {\n\tpages: Record<string, PageRecord> = {};\n\tlast: PageRecord | null = null;\n\tswup: Swup;\n\n\tconstructor(swup: Swup) {\n\t\tthis.swup = swup;\n\t}\n\n\tgetCacheUrl(url: string): string {\n\t\treturn this.swup.resolveUrl(Location.fromUrl(url).url);\n\t}\n\n\tcacheUrl(page: PageRecord) {\n\t\tpage.url = this.getCacheUrl(page.url);\n\t\tif (page.url in this.pages === false) {\n\t\t\tthis.pages[page.url] = page;\n\t\t}\n\t\tpage.responseURL = this.getCacheUrl(page.responseURL);\n\t\tthis.last = this.pages[page.url];\n\t\tthis.swup.log(`Cache (${Object.keys(this.pages).length})`, this.pages);\n\t}\n\n\tgetPage(url: string): PageRecord {\n\t\turl = this.getCacheUrl(url);\n\t\treturn this.pages[url];\n\t}\n\n\tgetCurrentPage(): PageRecord {\n\t\treturn this.getPage(getCurrentUrl());\n\t}\n\n\texists(url: string): boolean {\n\t\turl = this.getCacheUrl(url);\n\t\treturn url in this.pages;\n\t}\n\n\tempty(): void {\n\t\tthis.pages = {};\n\t\tthis.last = null;\n\t\tthis.swup.log('Cache cleared');\n\t}\n\n\tremove(url: string): void {\n\t\tdelete this.pages[this.getCacheUrl(url)];\n\t}\n}\n","import { nextTick } from '../utils.js';\nimport Swup from '../Swup.js';\n\nexport const enterPage = function (\n\tthis: Swup,\n\t{ popstate, skipTransition }: { popstate?: PopStateEvent; skipTransition?: boolean }\n) {\n\tif (skipTransition) {\n\t\tthis.triggerEvent('transitionEnd', popstate);\n\t\tthis.cleanupAnimationClasses();\n\t\treturn [Promise.resolve()];\n\t}\n\n\tnextTick(() => {\n\t\tthis.triggerEvent('animationInStart');\n\t\tdocument.documentElement.classList.remove('is-animating');\n\t});\n\n\tconst animationPromises = this.getAnimationPromises('in');\n\tPromise.all(animationPromises).then(() => {\n\t\tthis.triggerEvent('animationInDone');\n\t\tthis.triggerEvent('transitionEnd', popstate);\n\t\tthis.cleanupAnimationClasses();\n\t});\n\treturn animationPromises;\n};\n","import { escapeCssIdentifier, query } from '../utils.js';\n\nexport const getAnchorElement = (hash: string): Element | null => {\n\tif (!hash) {\n\t\treturn null;\n\t}\n\n\tif (hash.charAt(0) === '#') {\n\t\thash = hash.substring(1);\n\t}\n\n\thash = decodeURIComponent(hash);\n\thash = escapeCssIdentifier(hash);\n\n\t// https://html.spec.whatwg.org/#find-a-potential-indicated-element\n\treturn query(`#${hash}`) || query(`a[name='${hash}']`);\n};\n","import { queryAll, toMs } from '../utils.js';\nimport Swup from '../Swup.js';\n\n// Transition property/event sniffing\nlet transitionProp = 'transition';\nlet transitionEndEvent = 'transitionend';\nlet animationProp = 'animation';\nlet animationEndEvent = 'animationend';\n\nif (window.ontransitionend === undefined && window.onwebkittransitionend !== undefined) {\n\ttransitionProp = 'WebkitTransition';\n\ttransitionEndEvent = 'webkitTransitionEnd';\n}\n\nif (window.onanimationend === undefined && window.onwebkitanimationend !== undefined) {\n\tanimationProp = 'WebkitAnimation';\n\tanimationEndEvent = 'webkitAnimationEnd';\n}\n\nexport function getAnimationPromises(\n\tthis: Swup,\n\t// we don't use this argument, but JS plugin depends on it with\n\t// its own version of getAnimationPromises, so it must be specified when\n\t// getAnimationPromises is being used\n\tanimationType: 'in' | 'out'\n): Promise<void>[] {\n\tconst selector = this.options.animationSelector;\n\n\t// Allow usage of swup without animations\n\tif (selector === false) {\n\t\t// Use array of a single resolved promise instead of an empty array to allow\n\t\t// possible future use with Promise.race() which requires an actual value\n\t\treturn [Promise.resolve()];\n\t}\n\n\tconst animatedElements = queryAll(selector, document.body);\n\n\t// Warn if no animated containers found on page, but keep things going\n\tif (!animatedElements.length) {\n\t\tconsole.warn(`[swup] No animated elements found by selector ${selector}`);\n\t\treturn [Promise.resolve()];\n\t}\n\n\treturn animatedElements.map((element) => getAnimationPromiseForElement(element, selector));\n}\n\nconst isTransitionOrAnimationEvent = (event: any): event is TransitionEvent | AnimationEvent =>\n\t!!event.elapsedTime;\n\nfunction getAnimationPromiseForElement(\n\telement: Element,\n\tselector: string,\n\texpectedType: 'animation' | 'transition' | null = null\n): Promise<void> {\n\tconst { type, timeout, propCount } = getTransitionInfo(element, expectedType);\n\n\t// Resolve immediately if no transition defined\n\tif (!type || !timeout) {\n\t\tconsole.warn(\n\t\t\t`[swup] No CSS transition duration defined for element of selector ${selector}`\n\t\t);\n\t\treturn Promise.resolve();\n\t}\n\n\treturn new Promise((resolve) => {\n\t\tconst endEvent = type === 'transition' ? transitionEndEvent : animationEndEvent;\n\t\tconst startTime = performance.now();\n\t\tlet propsTransitioned = 0;\n\n\t\tconst end = () => {\n\t\t\telement.removeEventListener(endEvent, onEnd);\n\t\t\tresolve();\n\t\t};\n\n\t\tconst onEnd: EventListener = (event) => {\n\t\t\t// Skip transitions on child elements\n\t\t\tif (event.target !== element) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isTransitionOrAnimationEvent(event)) {\n\t\t\t\tthrow new Error('Not a transition or animation event.');\n\t\t\t}\n\n\t\t\t// Skip transitions that happened before we started listening\n\t\t\tconst elapsedTime = (performance.now() - startTime) / 1000;\n\t\t\tif (elapsedTime < event.elapsedTime) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// End if all properties have transitioned\n\t\t\tif (++propsTransitioned >= propCount) {\n\t\t\t\tend();\n\t\t\t}\n\t\t};\n\n\t\tsetTimeout(() => {\n\t\t\tif (propsTransitioned < propCount) {\n\t\t\t\tend();\n\t\t\t}\n\t\t}, timeout + 1);\n\n\t\telement.addEventListener(endEvent, onEnd);\n\t});\n}\n\nexport function getTransitionInfo(\n\telement: Element,\n\texpectedType: 'animation' | 'transition' | null = null\n) {\n\tconst styles = window.getComputedStyle(element);\n\n\t// not sure what to do about the below mess other than casting, but it's a mess\n\tconst transitionDelay = `${transitionProp}Delay` as keyof CSSStyleDeclaration;\n\tconst transitionDuration = `${transitionProp}Duration` as keyof CSSStyleDeclaration;\n\tconst animationDelay = `${animationProp}Delay` as keyof CSSStyleDeclaration;\n\tconst animationDuration = `${animationProp}Duration` as keyof CSSStyleDeclaration;\n\n\tconst transitionDelays = (\n\t\tstyles[transitionDelay] as CSSStyleDeclaration['transitionDelay']\n\t).split(', ');\n\tconst transitionDurations = (\n\t\t(styles[transitionDuration] || '') as CSSStyleDeclaration['transitionDuration']\n\t).split(', ');\n\tconst transitionTimeout = calculateTimeout(transitionDelays, transitionDurations);\n\n\tconst animationDelays = (\n\t\t(styles[animationDelay] || '') as CSSStyleDeclaration['animationDelay']\n\t).split(', ');\n\tconst animationDurations = (\n\t\t(styles[animationDuration] || '') as CSSStyleDeclaration['animationDuration']\n\t).split(', ');\n\tconst animationTimeout = calculateTimeout(animationDelays, animationDurations);\n\n\tlet type: string | null = '';\n\tlet timeout = 0;\n\tlet propCount = 0;\n\n\tif (expectedType === 'transition') {\n\t\tif (transitionTimeout > 0) {\n\t\t\ttype = 'transition';\n\t\t\ttimeout = transitionTimeout;\n\t\t\tpropCount = transitionDurations.length;\n\t\t}\n\t} else if (expectedType === 'animation') {\n\t\tif (animationTimeout > 0) {\n\t\t\ttype = 'animation';\n\t\t\ttimeout = animationTimeout;\n\t\t\tpropCount = animationDurations.length;\n\t\t}\n\t} else {\n\t\ttimeout = Math.max(transitionTimeout, animationTimeout);\n\t\ttype =\n\t\t\ttimeout > 0\n\t\t\t\t? transitionTimeout > animationTimeout\n\t\t\t\t\t? 'transition'\n\t\t\t\t\t: 'animation'\n\t\t\t\t: null;\n\t\tpropCount = type\n\t\t\t? type === 'transition'\n\t\t\t\t? transitionDurations.length\n\t\t\t\t: animationDurations.length\n\t\t\t: 0;\n\t}\n\n\treturn {\n\t\ttype,\n\t\ttimeout,\n\t\tpropCount\n\t};\n}\n\nfunction calculateTimeout(delays: string[], durations: string[]) {\n\twhile (delays.length < durations.length) {\n\t\tdelays = delays.concat(delays);\n\t}\n\n\treturn Math.max(...durations.map((duration, i) => toMs(duration) + toMs(delays[i])));\n}\n","import { getDataFromHtml } from '../helpers.js';\nimport Swup from '../Swup.js';\nimport { PageHtmlData } from '../helpers/getDataFromHtml.js';\n\nexport type PageData = PageHtmlData & {\n\tresponseURL: string;\n};\nexport const getPageData = function (this: Swup, request: XMLHttpRequest): PageData | null {\n\t// this method can be replaced in case other content than html is expected to be received from server\n\t// this function should always return { title, pageClass, originalContent, blocks, responseURL }\n\t// in case page has invalid structure - return null\n\tconst html = request.responseText;\n\tconst pageHtmlData = getDataFromHtml(html, this.options.containers);\n\n\tif (!pageHtmlData) {\n\t\tconsole.warn('[swup] Received page is invalid.');\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t...pageHtmlData,\n\t\tresponseURL: request.responseURL || window.location.href\n\t};\n};\n","import Swup from '../Swup.js';\nimport { fetch } from '../helpers.js';\nimport { TransitionOptions } from './loadPage.js';\nimport { PageRecord } from './Cache.js';\n\nexport function fetchPage(this: Swup, data: TransitionOptions): Promise<PageRecord> {\n\tconst headers = this.options.requestHeaders;\n\tconst { url } = data;\n\n\tif (this.cache.exists(url)) {\n\t\tthis.triggerEvent('pageRetrievedFromCache');\n\t\treturn Promise.resolve(this.cache.getPage(url));\n\t}\n\n\treturn new Promise((resolve, reject) => {\n\t\tfetch({ ...data, headers }, (response) => {\n\t\t\tif (response.status === 500) {\n\t\t\t\tthis.triggerEvent('serverError');\n\t\t\t\treject(url);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// get json data\n\t\t\tconst page = this.getPageData(response);\n\t\t\tif (!page || !page.blocks.length) {\n\t\t\t\treject(url);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// render page\n\t\t\tconst cacheablePageData = { ...page, url };\n\t\t\tthis.cache.cacheUrl(cacheablePageData);\n\t\t\tthis.triggerEvent('pageLoaded');\n\t\t\tresolve(cacheablePageData);\n\t\t});\n\t});\n}\n","import Swup from '../Swup.js';\nimport { TransitionOptions } from './loadPage.js';\n\nexport const leavePage = function (\n\tthis: Swup,\n\tdata: TransitionOptions,\n\t{ popstate, skipTransition }: { popstate: PopStateEvent | null; skipTransition?: boolean } = {\n\t\tpopstate: null\n\t}\n) {\n\tif (skipTransition) {\n\t\tthis.triggerEvent('animationSkipped');\n\t\treturn [Promise.resolve()];\n\t}\n\n\tthis.triggerEvent('animationOutStart');\n\n\t// handle classes\n\tdocument.documentElement.classList.add('is-changing', 'is-leaving', 'is-animating');\n\tif (popstate) {\n\t\tdocument.documentElement.classList.add('is-popstate');\n\t}\n\n\t// animation promise stuff\n\tconst animationPromises: Promise<void>[] = this.getAnimationPromises('out');\n\tPromise.all(animationPromises).then(() => {\n\t\tthis.triggerEvent('animationOutDone');\n\t});\n\n\treturn animationPromises;\n};\n","import { classify, createHistoryRecord, getCurrentUrl } from '../helpers.js';\nimport Swup from '../Swup.js';\nimport { PageRecord } from './Cache.js';\n\nexport type TransitionOptions = {\n\turl: string;\n\tcustomTransition?: string;\n};\n\nexport const loadPage = function (\n\tthis: Swup,\n\tdata: TransitionOptions,\n\tpopstate: PopStateEvent | null\n) {\n\tconst { url, customTransition } = data;\n\tconst skipTransition = !!(popstate && !this.options.animateHistoryBrowsing);\n\n\tthis.triggerEvent('transitionStart', popstate || undefined);\n\n\t// set transition object\n\tthis.updateTransition(getCurrentUrl(), url, customTransition);\n\tif (customTransition != null) {\n\t\tdocument.documentElement.classList.add(`to-${classify(customTransition)}`);\n\t}\n\n\t// start/skip animation\n\tconst animationPromises = this.leavePage(data, { popstate, skipTransition });\n\n\t// create history record if this is not a popstate call (with or without anchor)\n\tif (!popstate) {\n\t\tcreateHistoryRecord(url + (this.scrollToElement || ''));\n\t}\n\n\tthis.currentPageUrl = getCurrentUrl();\n\n\t// Load page data\n\tconst fetchPromise = this.fetchPage(data);\n\n\t// when everything is ready, render the page\n\tPromise.all<PageRecord | void>([fetchPromise, ...animationPromises])\n\t\t.then(([pageData]) => {\n\t\t\tthis.renderPage(pageData as PageRecord, { popstate, skipTransition });\n\t\t})\n\t\t.catch((errorUrl) => {\n\t\t\t// Return early if errorUrl is not defined (probably aborted preload request)\n\t\t\tif (errorUrl === undefined) return;\n\n\t\t\t// Rewrite `skipPopStateHandling` to redirect manually when `history.go` is processed\n\t\t\tthis.options.skipPopStateHandling = () => {\n\t\t\t\twindow.location = errorUrl;\n\t\t\t\treturn true;\n\t\t\t};\n\n\t\t\t// Go back to the actual page we're still at\n\t\t\thistory.go(-1);\n\t\t});\n};\n","/**\n * Perform the replacement of content after loading a page.\n *\n * This method can be replaced or augmented by plugins to allow pausing.\n *\n * It takes an object with the page data as return from `getPageData` and has to\n * return a Promise that resolves once all content has been replaced and the\n * site is ready to start animating in the new page.\n *\n * @param {object} page The page object\n * @returns Promise\n */\nexport const replaceContent = function ({ blocks, title }: { blocks: string[]; title: string }) {\n\t// Replace content blocks\n\tblocks.forEach((html, i) => {\n\t\t// we know the block exists at this point\n\t\tconst block = document.body.querySelector(`[data-swup=\"${i}\"]`)!;\n\t\tblock.outerHTML = html;\n\t});\n\n\t// Update browser title\n\tdocument.title = title;\n\n\t// Return a Promise to allow plugins to defer\n\treturn Promise.resolve();\n};\n","import Swup from '../Swup.js';\nimport { EventType, Handler } from './on.js';\n\nexport const off = function off(this: Swup, event?: EventType, handler?: Handler) {\n\tif (event && handler) {\n\t\t// Remove specific handler\n\t\tif (this._handlers[event].includes(handler)) {\n\t\t\tthis._handlers[event] = this._handlers[event].filter((h) => h !== handler);\n\t\t} else {\n\t\t\tconsole.warn(`Handler for event '${event}' not found.`);\n\t\t}\n\t} else if (event) {\n\t\t// Remove all handlers for specific event\n\t\tthis._handlers[event] = [];\n\t} else {\n\t\t// Remove all handlers for all events\n\t\tObject.keys(this._handlers).forEach((event) => {\n\t\t\tthis._handlers[event as EventType] = [];\n\t\t});\n\t}\n};\n","import Swup from '../Swup.js';\n\nexport type EventType =\n\t| 'animationInDone'\n\t| 'animationInStart'\n\t| 'animationOutDone'\n\t| 'animationOutStart'\n\t| 'animationSkipped'\n\t| 'clickLink'\n\t| 'contentReplaced'\n\t| 'disabled'\n\t| 'enabled'\n\t| 'openPageInNewTab'\n\t| 'pageLoaded'\n\t| 'pageRetrievedFromCache'\n\t| 'pageView'\n\t| 'popState'\n\t| 'samePage'\n\t| 'samePageWithHash'\n\t| 'serverError'\n\t| 'transitionStart'\n\t| 'transitionEnd'\n\t| 'willReplaceContent';\nexport type Handler = (event?: Event) => void;\nexport type Handlers = Record<EventType, Handler[]>;\n\nexport const on = function on(this: Swup, event: EventType, handler: Handler) {\n\tif (this._handlers[event]) {\n\t\tthis._handlers[event].push(handler);\n\t} else {\n\t\tconsole.warn(`Unsupported event ${event}.`);\n\t}\n};\n","import Swup from '../Swup.js';\n\nexport type Plugin = {\n\tname: string;\n\tisSwupPlugin: true;\n\tmount: () => void;\n\tunmount: () => void;\n\n\t// the instance is assigned later on after passing to swup\n\tswup?: Swup;\n\n\t// these are possibly undefined for backward compatibility\n\tversion?: string;\n\trequires?: Record<string, string>;\n\t_beforeMount?: () => void;\n\t_afterUnmount?: () => void;\n\t_checkRequirements?: () => boolean;\n};\n\nconst isSwupPlugin = (maybeInvalidPlugin: unknown): maybeInvalidPlugin is Plugin => {\n\t// @ts-ignore\n\treturn maybeInvalidPlugin?.isSwupPlugin;\n};\n\nexport const use = function (this: Swup, plugin: unknown) {\n\tif (!isSwupPlugin(plugin)) {\n\t\tconsole.error('Not a swup plugin instance', plugin);\n\t\treturn;\n\t}\n\n\tplugin.swup = this;\n\tif (plugin._checkRequirements) {\n\t\tif (!plugin._checkRequirements()) {\n\t\t\treturn;\n\t\t}\n\t}\n\tif (plugin._beforeMount) {\n\t\tplugin._beforeMount();\n\t}\n\tplugin.mount();\n\n\tthis.plugins.push(plugin);\n\n\treturn this.plugins;\n};\n\nexport function unuse(this: Swup, pluginOrName: Plugin | string) {\n\tconst plugin = this.findPlugin(pluginOrName);\n\tif (!plugin) {\n\t\tconsole.error('No such plugin', plugin);\n\t\treturn;\n\t}\n\n\tplugin.unmount();\n\tif (plugin._afterUnmount) {\n\t\tplugin._afterUnmount();\n\t}\n\n\tthis.plugins = this.plugins.filter((p) => p !== plugin);\n\n\treturn this.plugins;\n}\n\nexport function findPlugin(this: Swup, pluginOrName: Plugin | string) {\n\treturn this.plugins.find((plugin) => plugin === pluginOrName || plugin.name === pluginOrName);\n}\n","import { Location, updateHistoryRecord, getCurrentUrl } from '../helpers.js';\nimport Swup from '../Swup.js';\nimport { PageRecord } from './Cache.js';\n\nexport const renderPage = function (\n\tthis: Swup,\n\tpage: PageRecord,\n\t{ popstate, skipTransition }: { popstate: PopStateEvent | null; skipTransition?: boolean } = {\n\t\tpopstate: null\n\t}\n) {\n\tdocument.documentElement.classList.remove('is-leaving');\n\n\t// do nothing if another page was requested in the meantime\n\tif (!this.isSameResolvedUrl(getCurrentUrl(), page.url)) {\n\t\treturn;\n\t}\n\n\tconst { url } = Location.fromUrl(page.responseURL);\n\n\t// update cache and state if the url was redirected\n\tif (!this.isSameResolvedUrl(getCurrentUrl(), url)) {\n\t\tthis.cache.cacheUrl({ ...page, url });\n\t\tthis.currentPageUrl = getCurrentUrl();\n\t\tupdateHistoryRecord(url);\n\t}\n\n\t// only add for page loads with transitions\n\tif (!skipTransition) {\n\t\tdocument.documentElement.classList.add('is-rendering');\n\t}\n\n\tthis.triggerEvent('willReplaceContent', popstate || undefined);\n\n\tthis.replaceContent(page).then(() => {\n\t\tthis.triggerEvent('contentReplaced', popstate || undefined);\n\t\tthis.triggerEvent('pageView', popstate || undefined);\n\n\t\t// empty cache if it's disabled (in case preload plugin filled it)\n\t\tif (!this.options.cache) {\n\t\t\tthis.cache.empty();\n\t\t}\n\n\t\t// Perform in transition\n\t\tthis.enterPage({ popstate: popstate || undefined, skipTransition });\n\n\t\t// reset scroll-to element\n\t\tthis.scrollToElement = null;\n\t});\n};\n","import { EventType } from './on.js';\nimport Swup from '../Swup.js';\n\nexport const triggerEvent = function (\n\tthis: Swup,\n\teventName: EventType,\n\toriginalEvent?: PopStateEvent | MouseEvent\n): void {\n\t// call saved handlers with \"on\" method and pass originalEvent object if available\n\tthis._handlers[eventName].forEach((handler) => {\n\t\ttry {\n\t\t\thandler(originalEvent);\n\t\t} catch (error) {\n\t\t\tconsole.error(error);\n\t\t}\n\t});\n\n\t// trigger event on document with prefix \"swup:\"\n\tconst event = new CustomEvent(`swup:${eventName}`, { detail: eventName });\n\tdocument.dispatchEvent(event);\n};\n","import Swup from '../Swup.js';\n\nexport const updateTransition = function (\n\tthis: Swup,\n\tfrom: string,\n\tto: string,\n\tcustom?: string\n): void {\n\tthis.transition = { from, to, custom };\n};\n","import delegate from 'delegate-it';\n\nimport version from './config/version.js';\n\nimport {\n\tcleanupAnimationClasses,\n\tdelegateEvent,\n\tgetCurrentUrl,\n\tLocation,\n\tmarkSwupElements,\n\tupdateHistoryRecord\n} from './helpers.js';\nimport { Unsubscribe } from './helpers/delegateEvent.js';\n\nimport { Cache } from './modules/Cache.js';\nimport { enterPage } from './modules/enterPage.js';\nimport { getAnchorElement } from './modules/getAnchorElement.js';\nimport { getAnimationPromises } from './modules/getAnimationPromises.js';\nimport { getPageData } from './modules/getPageData.js';\nimport { fetchPage } from './modules/fetchPage.js';\nimport { leavePage } from './modules/leavePage.js';\nimport { loadPage } from './modules/loadPage.js';\nimport { replaceContent } from './modules/replaceContent.js';\nimport { off } from './modules/off.js';\nimport { on, Handlers } from './modules/on.js';\nimport { use, unuse, findPlugin, Plugin } from './modules/plugins.js';\nimport { renderPage } from './modules/renderPage.js';\nimport { triggerEvent } from './modules/triggerEvent.js';\nimport { updateTransition } from './modules/updateTransition.js';\n\nimport { queryAll } from './utils.js';\n\nexport type Transition = {\n\tfrom?: string;\n\tto?: string;\n\tcustom?: string;\n};\n\ntype DelegatedListeners = {\n\tclick?: Unsubscribe;\n};\n\nexport type Options = {\n\tanimateHistoryBrowsing: boolean;\n\tanimationSelector: string | false;\n\tlinkSelector: string;\n\tcache: boolean;\n\tcontainers: string[];\n\trequestHeaders: Record<string, string>;\n\tplugins: Plugin[];\n\tskipPopStateHandling: (event: any) => boolean;\n\tignoreVisit: (href: string, { el }: { el?: Element }) => boolean;\n\tresolveUrl: (url: string) => string;\n};\n\nexport default class Swup {\n\tversion = version;\n\n\t_handlers: Handlers = {\n\t\tanimationInDone: [],\n\t\tanimationInStart: [],\n\t\tanimationOutDone: [],\n\t\tanimationOutStart: [],\n\t\tanimationSkipped: [],\n\t\tclickLink: [],\n\t\tcontentReplaced: [],\n\t\tdisabled: [],\n\t\tenabled: [],\n\t\topenPageInNewTab: [],\n\t\tpageLoaded: [],\n\t\tpageRetrievedFromCache: [],\n\t\tpageView: [],\n\t\tpopState: [],\n\t\tsamePage: [],\n\t\tsamePageWithHash: [],\n\t\tserverError: [],\n\t\ttransitionStart: [],\n\t\ttransitionEnd: [],\n\t\twillReplaceContent: []\n\t};\n\n\t// variable for anchor to scroll to after render\n\tscrollToElement: string | null = null;\n\t// variable for save options\n\toptions: Options;\n\t// running plugin instances\n\tplugins: Plugin[] = [];\n\t// variable for current transition info object\n\ttransition: Transition = {};\n\t// cache instance\n\tcache: Cache;\n\t// allows us to compare the current and new path inside popStateHandler\n\tcurrentPageUrl = getCurrentUrl();\n\t// variable for keeping event listeners from \"delegate\"\n\tdelegatedListeners: DelegatedListeners = {};\n\t// so we are able to remove the listener\n\tboundPopStateHandler: (event: PopStateEvent) => void;\n\n\tloadPage = loadPage;\n\tleavePage = leavePage;\n\trenderPage = renderPage;\n\treplaceContent = replaceContent;\n\tenterPage = enterPage;\n\ttriggerEvent = triggerEvent;\n\tdelegateEvent = delegateEvent;\n\ton = on;\n\toff = off;\n\tupdateTransition = updateTransition;\n\tgetAnimationPromises = getAnimationPromises;\n\tgetPageData = getPageData;\n\tfetchPage = fetchPage;\n\tgetAnchorElement = getAnchorElement;\n\tlog: (message: string, context?: any) => void = () => {}; // here so it can be used by plugins\n\tuse = use;\n\tunuse = unuse;\n\tfindPlugin = findPlugin;\n\tgetCurrentUrl = getCurrentUrl;\n\tcleanupAnimationClasses = cleanupAnimationClasses;\n\n\tdefaults: Options = {\n\t\tanimateHistoryBrowsing: false,\n\t\tanimationSelector: '[class*=\"transition-\"]',\n\t\tcache: true,\n\t\tcontainers: ['#swup'],\n\t\tignoreVisit: (href, { el } = {}) => !!el?.closest('[data-no-swup]'),\n\t\tlinkSelector: 'a[href]',\n\t\tplugins: [],\n\t\tresolveUrl: (url) => url,\n\t\trequestHeaders: {\n\t\t\t'X-Requested-With': 'swup',\n\t\t\tAccept: 'text/html, application/xhtml+xml'\n\t\t},\n\t\tskipPopStateHandling: (event) => event.state?.source !== 'swup'\n\t};\n\n\tconstructor(options: Partial<Options> = {}) {\n\t\t// Merge defaults and options\n\t\tthis.options = { ...this.defaults, ...options };\n\n\t\tthis.boundPopStateHandler = this.popStateHandler.bind(this);\n\n\t\tthis.cache = new Cache(this);\n\n\t\tthis.enable();\n\t}\n\n\tenable() {\n\t\t// Check for Promise support\n\t\tif (typeof Promise === 'undefined') {\n\t\t\tconsole.warn('Promise is not supported');\n\t\t\treturn;\n\t\t}\n\n\t\t// Add event listeners\n\t\tthis.delegatedListeners.click = delegateEvent(\n\t\t\tthis.options.linkSelector,\n\t\t\t'click',\n\t\t\tthis.linkClickHandler.bind(this)\n\t\t);\n\n\t\twindow.addEventListener('popstate', this.boundPopStateHandler);\n\n\t\t// Initial save to cache\n\t\tif (this.options.cache) {\n\t\t\t// Disabled to avoid caching modified dom state: logic moved to preload plugin\n\t\t\t// https://github.com/swup/swup/issues/475\n\t\t}\n\n\t\t// Mark swup blocks in html\n\t\tmarkSwupElements(document.documentElement, this.options.containers);\n\n\t\t// Mount plugins\n\t\tthis.options.plugins.forEach((plugin) => this.use(plugin));\n\n\t\t// Modify initial history record\n\t\tupdateHistoryRecord();\n\n\t\t// Trigger enabled event\n\t\tthis.triggerEvent('enabled');\n\n\t\t// Add swup-enabled class to html tag\n\t\tdocument.documentElement.classList.add('swup-enabled');\n\n\t\t// Trigger page view event\n\t\tthis.triggerEvent('pageView');\n\t}\n\n\tdestroy() {\n\t\t// remove delegated listeners\n\t\tthis.delegatedListeners.click!.destroy();\n\n\t\t// remove popstate listener\n\t\twindow.removeEventListener('popstate', this.boundPopStateHandler);\n\n\t\t// empty cache\n\t\tthis.cache.empty();\n\n\t\t// unmount plugins\n\t\tthis.options.plugins.forEach((plugin) => {\n\t\t\tthis.unuse(plugin);\n\t\t});\n\n\t\t// remove swup data atributes from blocks\n\t\tqueryAll('[data-swup]').forEach((element) => {\n\t\t\telement.removeAttribute('data-swup');\n\t\t});\n\n\t\t// remove handlers\n\t\tthis.off();\n\n\t\t// trigger disable event\n\t\tthis.triggerEvent('disabled');\n\n\t\t// remove swup-enabled class from html tag\n\t\tdocument.documentElement.classList.remove('swup-enabled');\n\t}\n\n\tshouldIgnoreVisit(href: string, { el }: { el?: Element } = {}) {\n\t\tconst { origin } = Location.fromUrl(href);\n\n\t\t// Ignore if the new URL's origin doesn't match the current one\n\t\tif (origin !== window.location.origin) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Ignore if the link/form would open a new window (or none at all)\n\t\tif (el && this.triggerWillOpenNewWindow(el)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Ignore if the visit should be ignored as per user options\n\t\tif (this.options.ignoreVisit(href, { el })) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Finally, allow the visit\n\t\treturn false;\n\t}\n\n\tlinkClickHandler(event: delegate.Event<MouseEvent>) {\n\t\tconst linkEl = event.delegateTarget;\n\t\tconst { href, url, hash } = Location.fromElement(linkEl as HTMLAnchorElement);\n\n\t\t// Exit early if the link should be ignored\n\t\tif (this.shouldIgnoreVisit(href, { el: linkEl })) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit early if control key pressed\n\t\tif (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {\n\t\t\tthis.triggerEvent('openPageInNewTab', event);\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit early if other than left mouse button\n\t\tif (event.button !== 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.triggerEvent('clickLink', event);\n\t\tevent.preventDefault();\n\n\t\t// Handle links to the same page and exit early, where applicable\n\t\tif (!url || url === getCurrentUrl()) {\n\t\t\tthis.handleLinkToSamePage(url, hash, event);\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit early if the resolved path hasn't changed\n\t\tif (this.isSameResolvedUrl(url, getCurrentUrl())) return;\n\n\t\t// Store the element that should be scrolled to after loading the next page\n\t\tthis.scrollToElement = hash || null;\n\n\t\t// Get the custom transition name, if present\n\t\tconst customTransition = linkEl.getAttribute('data-swup-transition') || undefined;\n\n\t\t// Finally, proceed with loading the page\n\t\tthis.loadPage({ url, customTransition }, null);\n\t}\n\n\thandleLinkToSamePage(url: string, hash: string, event: MouseEvent) {\n\t\t// Emit event and exit early if the url points to the same page without hash\n\t\tif (!hash) {\n\t\t\tthis.triggerEvent('samePage', event);\n\t\t\treturn;\n\t\t}\n\n\t\t// link to the same URL with hash\n\t\tthis.triggerEvent('samePageWithHash', event);\n\n\t\tconst element = getAnchorElement(hash);\n\n\t\t// Warn and exit early if no matching element was found for the hash\n\t\tif (!element) {\n\t\t\treturn console.warn(`Element for offset not found (#${hash})`);\n\t\t}\n\n\t\tupdateHistoryRecord(url + hash);\n\t}\n\n\ttriggerWillOpenNewWindow(triggerEl: Element) {\n\t\tif (triggerEl.matches('[download], [target=\"_blank\"]')) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tpopStateHandler(event: PopStateEvent) {\n\t\t// Exit early if this event should be ignored\n\t\tif (this.options.skipPopStateHandling(event)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit early if the resolved path hasn't changed\n\t\tif (this.isSameResolvedUrl(getCurrentUrl(), this.currentPageUrl)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { url, hash } = Location.fromUrl(event.state?.url ?? location.href);\n\n\t\tif (hash) {\n\t\t\tthis.scrollToElement = hash;\n\t\t} else {\n\t\t\tevent.preventDefault();\n\t\t}\n\n\t\tthis.triggerEvent('popState', event);\n\n\t\tif (!this.options.animateHistoryBrowsing) {\n\t\t\tdocument.documentElement.classList.remove('is-animating');\n\t\t\tcleanupAnimationClasses();\n\t\t}\n\n\t\tthis.loadPage({ url }, event);\n\t}\n\n\t/**\n\t * Utility function to validate and run the global option 'resolveUrl'\n\t * @param {string} url\n\t * @returns {string} the resolved url\n\t */\n\tresolveUrl(url: string) {\n\t\tif (typeof this.options.resolveUrl !== 'function') {\n\t\t\tconsole.warn(`[swup] options.resolveUrl expects a callback function.`);\n\t\t\treturn url;\n\t\t}\n\t\tconst result = this.options.resolveUrl(url);\n\t\tif (!result || typeof result !== 'string') {\n\t\t\tconsole.warn(`[swup] options.resolveUrl needs to return a url`);\n\t\t\treturn url;\n\t\t}\n\t\tif (result.startsWith('//') || result.startsWith('http')) {\n\t\t\tconsole.warn(`[swup] options.resolveUrl needs to return a relative url`);\n\t\t\treturn url;\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Compares the resolved version of two paths and returns true if they are the same\n\t * @param {string} url1\n\t * @param {string} url2\n\t * @returns {boolean}\n\t */\n\tisSameResolvedUrl(url1: string, url2: string) {\n\t\treturn this.resolveUrl(url1) === this.resolveUrl(url2);\n\t}\n}\n"],"names":["classify","text","fallback","String","toLowerCase","replace","getCurrentUrl","hash","location","pathname","search","createHistoryRecord","url","customData","data","_extends","random","Math","source","history","pushState","updateHistoryRecord","state","replaceState","delegateEvent","selector","type","callback","_ref","base","document","eventOptions","delegation","delegate","destroy","query","context","querySelector","queryAll","Array","from","querySelectorAll","nextTick","requestAnimationFrame","escapeCssIdentifier","ident","window","CSS","escape","toMs","s","Number","slice","getDataFromHtml","html","containers","_query","_query2","fakeDom","createElement","innerHTML","blocks","forEach","console","warn","length","item","index","setAttribute","push","outerHTML","innerText","className","title","pageClass","originalContent","fetch","options","defaults","method","headers","request","XMLHttpRequest","onreadystatechange","readyState","open","Object","entries","key","header","setRequestHeader","send","Location","URL","constructor","baseURI","super","toString","this","static","el","href","getAttribute","markSwupElements","element","isSwupClass","test","includes","cleanupAnimationClasses","removeClasses","documentElement","split","filter","classList","remove","Cache","swup","pages","last","getCacheUrl","resolveUrl","fromUrl","cacheUrl","page","responseURL","log","keys","getPage","getCurrentPage","exists","empty","enterPage","popstate","skipTransition","triggerEvent","Promise","resolve","animationPromises","getAnimationPromises","all","then","getAnchorElement","charAt","substring","decodeURIComponent","transitionProp","transitionEndEvent","animationProp","animationEndEvent","animationType","animationSelector","animatedElements","body","map","expectedType","timeout","propCount","getComputedStyle","transitionDuration","animationDuration","transitionDelays","styles","transitionDurations","transitionTimeout","calculateTimeout","animationDelays","animationDelay","animationDurations","animationTimeout","max","getTransitionInfo","endEvent","startTime","performance","now","propsTransitioned","end","removeEventListener","onEnd","event","target","elapsedTime","isTransitionOrAnimationEvent","Error","setTimeout","addEventListener","getAnimationPromiseForElement","delays","durations","concat","duration","i","undefined","ontransitionend","onwebkittransitionend","onanimationend","onwebkitanimationend","getPageData","pageHtmlData","responseText","fetchPage","requestHeaders","cache","reject","response","status","cacheablePageData","leavePage","add","loadPage","customTransition","animateHistoryBrowsing","updateTransition","scrollToElement","currentPageUrl","fetchPromise","pageData","renderPage","catch","errorUrl","skipPopStateHandling","go","replaceContent","handler","_handlers","h","on","use","plugin","maybeInvalidPlugin","isSwupPlugin","_checkRequirements","_beforeMount","mount","plugins","error","unuse","pluginOrName","findPlugin","unmount","_afterUnmount","p","find","name","isSameResolvedUrl","eventName","originalEvent","detail","dispatchEvent","to","custom","transition","Swup","version","animationInDone","animationInStart","animationOutDone","animationOutStart","animationSkipped","clickLink","contentReplaced","disabled","enabled","openPageInNewTab","pageLoaded","pageRetrievedFromCache","pageView","popState","samePage","samePageWithHash","serverError","transitionStart","transitionEnd","willReplaceContent","delegatedListeners","boundPopStateHandler","off","ignoreVisit","closest","linkSelector","Accept","_event$state","popStateHandler","bind","enable","click","linkClickHandler","removeAttribute","shouldIgnoreVisit","origin","triggerWillOpenNewWindow","linkEl","delegateTarget","fromElement","metaKey","ctrlKey","shiftKey","altKey","button","preventDefault","handleLinkToSamePage","triggerEl","matches","_event$state$url","_event$state2","result","startsWith","url1","url2"],"mappings":"+PAAaA,MAAQA,EAAG,CAACC,EAAcC,IACvBC,OAAOF,GACpBG,cAGAC,QAAQ,YAAa,KACrBA,QAAQ,WAAY,IACpBA,QAAQ,OAAQ,KAChBA,QAAQ,WAAY,KACLH,GAAY,GCTjBI,EAAgB,EAAGC,QAA6B,CAAE,IACvDC,SAASC,SAAWD,SAASE,QAAUH,EAAOC,SAASD,KAAO,ICCzDI,EAAsB,CAClCC,EACAC,EAAsC,CAAA,KAGtC,MAAUC,EAAAC,EAAA,CACTH,IAFDA,EAAMA,GAAON,EAAc,CAAEC,MAAM,IAGlCS,OAAQC,KAAKD,SACbE,OAAQ,QACLL,GAEJM,QAAQC,UAAUN,EAAM,GAAIF,EAC7B,ECZgCS,EAAG,CAClCT,EAAqB,KACrBC,EAAsC,CAAA,KAEtCD,EAAMA,GAAON,EAAc,CAAEC,MAAM,IACnC,MAAMO,EACFK,EAAAA,CAAAA,EAAAA,QAAQG,MACXV,CAAAA,MACAI,OAAQC,KAAKD,SACbE,OAAQ,QACLL,GAEJM,QAAQI,aAAaT,EAAM,GAAIF,EAChC,aCT0BY,EAAG,CAC5BC,EACAC,EACAC,EACAC,EAAuC,CAAA,KAAvC,IAAAC,KA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AaL,EAAc4K,GAE/C,GAAK5K,EAAL,CAWA,GALA2F,KAAKoC,aAAa,mBAAoB6C,IAEtBtC,EAAiBtI,GAIhC,OAAcwD,QAACC,uCAAuCzD,MAGvDc,EAAoBT,EAAML,EAZzB,MAFA2F,KAAKoC,aAAa,WAAY6C,EAehC,CAEA+G,yBAAyBW,GACxB,QAAIA,EAAUC,QAAQ,gCAIvB,CAEApB,gBAAgBvG,GAEf,IAAA4H,EAAAC,EAAA,GAAI9M,KAAKrB,QAAQ+I,qBAAqBzC,GACrC,OAID,GAAIjF,KAAKkJ,kBAAkB9O,IAAiB4F,KAAKoH,gBAChD,OAGD,MAAM1M,IAAEA,EAAGL,KAAEA,GAASqF,EAAS6B,QAAwB,SAAL,SAAX0D,EAAM7J,YAAK,EAAX0R,EAAapS,KAAGmS,EAAIvS,SAAS6F,MAEhE9F,EACH2F,KAAKmH,gBAAkB9M,EAEvB4K,EAAMwH,iBAGPzM,KAAKoC,aAAa,WAAY6C,GAEzBjF,KAAKrB,QAAQsI,yBACjBrL,SAASgF,gBAAgBG,UAAUC,OAAO,gBAC1CN,KAGDV,KAAK+G,SAAS,CAAErM,OAAOuK,EACxB,CAOA3D,WAAW5G,GACV,GAAuC,wBAAvBiE,QAAQ2C,WAEvB,OADAzD,QAAQC,KAAK,0DAEbpD,EACD,MAAYqS,EAAG/M,KAAKrB,QAAQ2C,WAAW5G,GACvC,OAAKqS,GAA4B,iBAALA,EAIxBA,EAAOC,WAAW,OAASD,EAAOC,WAAW,SAChDnP,QAAQC,KAAK,4DACNpD,GAEDqS,GAPNlP,QAAQC,KAAK,mDACNpD,EAOT,CAQAwO,kBAAkB+D,EAAcC,GAC/B,OAAWlN,KAACsB,WAAW2L,KAAUjN,KAAKsB,WAAW4L,EAClD"}
|
|
1
|
+
{"version":3,"file":"Swup.modern.js","sources":["../src/helpers/classify.ts","../src/helpers/getCurrentUrl.ts","../src/helpers/createHistoryRecord.ts","../src/helpers/updateHistoryRecord.ts","../src/helpers/delegateEvent.ts","../src/utils/index.ts","../src/helpers/getDataFromHtml.ts","../src/helpers/fetch.ts","../src/helpers/Location.ts","../src/helpers/markSwupElements.ts","../src/helpers/cleanupAnimationClasses.ts","../src/modules/Cache.ts","../src/modules/enterPage.ts","../src/modules/getAnchorElement.ts","../src/modules/getAnimationPromises.ts","../src/modules/getPageData.ts","../src/modules/fetchPage.ts","../src/modules/leavePage.ts","../src/modules/loadPage.ts","../src/modules/replaceContent.ts","../src/modules/off.ts","../src/modules/on.ts","../src/modules/plugins.ts","../src/modules/renderPage.ts","../src/modules/triggerEvent.ts","../src/modules/updateTransition.ts","../src/Swup.ts"],"sourcesContent":["export const classify = (text: string, fallback?: string): string => {\n\tconst output = String(text)\n\t\t.toLowerCase()\n\t\t// .normalize('NFD') // split an accented letter in the base letter and the acent\n\t\t// .replace(/[\\u0300-\\u036f]/g, '') // remove all previously split accents\n\t\t.replace(/[\\s/_.]+/g, '-') // replace spaces and _./ with '-'\n\t\t.replace(/[^\\w-]+/g, '') // remove all non-word chars\n\t\t.replace(/--+/g, '-') // replace repeating '-' with single '-'\n\t\t.replace(/^-+|-+$/g, ''); // trim '-' from edges\n\treturn output || fallback || '';\n};\n","export const getCurrentUrl = ({ hash }: { hash?: boolean } = {}): string => {\n\treturn location.pathname + location.search + (hash ? location.hash : '');\n};\n","import { getCurrentUrl } from './getCurrentUrl';\n\nexport const createHistoryRecord = (\n\turl: string,\n\tcustomData: Record<string, unknown> = {}\n): void => {\n\turl = url || getCurrentUrl({ hash: true });\n\tconst data = {\n\t\turl,\n\t\trandom: Math.random(),\n\t\tsource: 'swup',\n\t\t...customData\n\t};\n\thistory.pushState(data, '', url);\n};\n","import { getCurrentUrl } from './getCurrentUrl';\n\nexport const updateHistoryRecord = (\n\turl: string | null = null,\n\tcustomData: Record<string, unknown> = {}\n): void => {\n\turl = url || getCurrentUrl({ hash: true });\n\tconst data = {\n\t\t...history.state,\n\t\turl,\n\t\trandom: Math.random(),\n\t\tsource: 'swup',\n\t\t...customData\n\t};\n\thistory.replaceState(data, '', url);\n};\n","import delegate, { EventType } from 'delegate-it';\nimport { ParseSelector } from 'typed-query-selector/parser';\n\nexport type Unsubscribe = {\n\tdestroy: () => void;\n};\nexport const delegateEvent = <Selector extends string, TEvent extends EventType>(\n\tselector: Selector,\n\ttype: TEvent,\n\tcallback: delegate.EventHandler<GlobalEventHandlersEventMap[TEvent]>,\n\t{ base = document, ...eventOptions } = {}\n): Unsubscribe => {\n\tconst delegation = delegate<string, ParseSelector<Selector, HTMLElement>, TEvent>(\n\t\tbase,\n\t\tselector,\n\t\ttype,\n\t\tcallback,\n\t\teventOptions\n\t);\n\treturn { destroy: () => delegation.destroy() };\n};\n","export const query = (selector: string, context: Document | Element = document) => {\n\treturn context.querySelector<HTMLElement>(selector);\n};\n\nexport const queryAll = (\n\tselector: string,\n\tcontext: Document | Element = document\n): HTMLElement[] => {\n\treturn Array.from(context.querySelectorAll(selector));\n};\n\nexport const nextTick = (callback: () => void) => {\n\trequestAnimationFrame(() => {\n\t\trequestAnimationFrame(() => {\n\t\t\tcallback();\n\t\t});\n\t});\n};\n\nexport const escapeCssIdentifier = (ident: string) => {\n\t// @ts-ignore this is for support check, so it's correct that TS complains\n\tif (window.CSS && window.CSS.escape) {\n\t\treturn CSS.escape(ident);\n\t} else {\n\t\treturn ident;\n\t}\n};\n\n// Fix for Chrome below v61 formatting CSS floats with comma in some locales\nexport const toMs = (s: string) => {\n\treturn Number(s.slice(0, -1).replace(',', '.')) * 1000;\n};\n","import { query, queryAll } from '../utils';\n\nexport type PageHtmlData = {\n\ttitle: string;\n\toriginalContent: string;\n\tblocks: string[];\n\tpageClass?: string;\n};\n\nexport const getDataFromHtml = (html: string, containers: string[]): PageHtmlData => {\n\tlet fakeDom = document.createElement('html');\n\tfakeDom.innerHTML = html;\n\tlet blocks: string[] = [];\n\n\tcontainers.forEach((selector) => {\n\t\tif (query(selector, fakeDom) == null) {\n\t\t\tconsole.warn(`[swup] Container ${selector} not found on page.`);\n\t\t\treturn null;\n\t\t} else {\n\t\t\tif (queryAll(selector).length !== queryAll(selector, fakeDom).length) {\n\t\t\t\tconsole.warn(`[swup] Mismatched number of containers found on new page.`);\n\t\t\t}\n\t\t\tqueryAll(selector).forEach((item, index) => {\n\t\t\t\tqueryAll(selector, fakeDom)[index].setAttribute('data-swup', String(blocks.length));\n\t\t\t\tblocks.push(queryAll(selector, fakeDom)[index].outerHTML);\n\t\t\t});\n\t\t}\n\t});\n\n\tconst title = query('title', fakeDom)?.innerText || '';\n\tconst pageClass = query('body', fakeDom)?.className;\n\n\t// to prevent memory leaks\n\tfakeDom.innerHTML = '';\n\t// @ts-ignore don't want to type it as possible null, since it's created at the top of the function always\n\tfakeDom = null;\n\n\treturn { title, pageClass, blocks, originalContent: html };\n};\n","import { TransitionOptions } from '../modules/loadPage';\nimport { Options } from '../Swup';\n\nexport const fetch = (\n\toptions: TransitionOptions & { headers: Options['requestHeaders'] },\n\tcallback: (request: XMLHttpRequest) => void\n): XMLHttpRequest => {\n\tconst defaults = {\n\t\turl: window.location.pathname + window.location.search,\n\t\tmethod: 'GET',\n\t\tdata: null,\n\t\theaders: {}\n\t};\n\n\tconst { url, method, headers, data } = { ...defaults, ...options };\n\n\tconst request = new XMLHttpRequest();\n\n\trequest.onreadystatechange = function () {\n\t\tif (request.readyState === 4) {\n\t\t\t// if (request.status === 500) {} else {}\n\t\t\tcallback(request);\n\t\t}\n\t};\n\n\trequest.open(method, url, true);\n\tObject.entries(headers).forEach(([key, header]) => {\n\t\trequest.setRequestHeader(key, header);\n\t});\n\trequest.send(data);\n\n\treturn request;\n};\n","/**\n * A helper for creating a Location from either an element\n * or a URL object/string\n *\n */\n\nexport class Location extends URL {\n\tconstructor(url: string, base: string = document.baseURI) {\n\t\tsuper(url.toString(), base);\n\t}\n\n\tget url() {\n\t\treturn this.pathname + this.search;\n\t}\n\n\t/**\n\t * Instantiate a Location from an element's href attribute\n\t * @param {Element} el\n\t * @return new Location instance\n\t */\n\tstatic fromElement(el: HTMLAnchorElement): Location {\n\t\tconst href = el.getAttribute('href') || el.getAttribute('xlink:href');\n\t\treturn new Location(href!);\n\t}\n\n\t/**\n\t * Instantiate a Location from a URL object or string\n\t * @param {URL|string} url\n\t * @return new Location instance\n\t */\n\tstatic fromUrl(url: string): Location {\n\t\treturn new Location(url);\n\t}\n}\n","import { query, queryAll } from '../utils';\n\nexport const markSwupElements = (element: Element, containers: string[]): void => {\n\tlet blocks = 0;\n\n\tcontainers.forEach((selector) => {\n\t\tif (query(selector, element) == null) {\n\t\t\tconsole.warn(`[swup] Container ${selector} not found on page.`);\n\t\t} else {\n\t\t\tqueryAll(selector).forEach((item: Element, index: number) => {\n\t\t\t\tqueryAll(selector, element)[index].setAttribute('data-swup', String(blocks));\n\t\t\t\tblocks++;\n\t\t\t});\n\t\t}\n\t});\n};\n","export const isSwupClass = (className: string): boolean =>\n\t/^to-/.test(className) || ['is-changing', 'is-rendering', 'is-popstate'].includes(className);\n\nexport const cleanupAnimationClasses = (): void => {\n\tconst htmlClasses = document.documentElement.className.split(' ');\n\tconst removeClasses = htmlClasses.filter(isSwupClass);\n\tdocument.documentElement.classList.remove(...removeClasses);\n};\n","import { getCurrentUrl, Location } from '../helpers';\nimport Swup from '../Swup';\nimport { PageData } from './getPageData';\n\nexport interface PageRecord extends PageData {\n\turl: string;\n\tresponseURL: string;\n}\nexport class Cache {\n\tpages: Record<string, PageRecord> = {};\n\tlast: PageRecord | null = null;\n\tswup: Swup;\n\n\tconstructor(swup: Swup) {\n\t\tthis.swup = swup;\n\t}\n\n\tgetCacheUrl(url: string): string {\n\t\treturn this.swup.resolveUrl(Location.fromUrl(url).url);\n\t}\n\n\tcacheUrl(page: PageRecord) {\n\t\tpage.url = this.getCacheUrl(page.url);\n\t\tif (page.url in this.pages === false) {\n\t\t\tthis.pages[page.url] = page;\n\t\t}\n\t\tpage.responseURL = this.getCacheUrl(page.responseURL);\n\t\tthis.last = this.pages[page.url];\n\t\tthis.swup.log(`Cache (${Object.keys(this.pages).length})`, this.pages);\n\t}\n\n\tgetPage(url: string): PageRecord {\n\t\turl = this.getCacheUrl(url);\n\t\treturn this.pages[url];\n\t}\n\n\tgetCurrentPage(): PageRecord {\n\t\treturn this.getPage(getCurrentUrl());\n\t}\n\n\texists(url: string): boolean {\n\t\turl = this.getCacheUrl(url);\n\t\treturn url in this.pages;\n\t}\n\n\tempty(): void {\n\t\tthis.pages = {};\n\t\tthis.last = null;\n\t\tthis.swup.log('Cache cleared');\n\t}\n\n\tremove(url: string): void {\n\t\tdelete this.pages[this.getCacheUrl(url)];\n\t}\n}\n","import { nextTick } from '../utils';\nimport Swup from '../Swup';\n\nexport const enterPage = function (\n\tthis: Swup,\n\t{ popstate, skipTransition }: { popstate?: PopStateEvent; skipTransition?: boolean }\n) {\n\tif (skipTransition) {\n\t\tthis.triggerEvent('transitionEnd', popstate);\n\t\tthis.cleanupAnimationClasses();\n\t\treturn [Promise.resolve()];\n\t}\n\n\tnextTick(() => {\n\t\tthis.triggerEvent('animationInStart');\n\t\tdocument.documentElement.classList.remove('is-animating');\n\t});\n\n\tconst animationPromises = this.getAnimationPromises('in');\n\tPromise.all(animationPromises).then(() => {\n\t\tthis.triggerEvent('animationInDone');\n\t\tthis.triggerEvent('transitionEnd', popstate);\n\t\tthis.cleanupAnimationClasses();\n\t});\n\treturn animationPromises;\n};\n","import { escapeCssIdentifier, query } from '../utils';\n\nexport const getAnchorElement = (hash: string): Element | null => {\n\tif (!hash) {\n\t\treturn null;\n\t}\n\n\tif (hash.charAt(0) === '#') {\n\t\thash = hash.substring(1);\n\t}\n\n\thash = decodeURIComponent(hash);\n\thash = escapeCssIdentifier(hash);\n\n\t// https://html.spec.whatwg.org/#find-a-potential-indicated-element\n\treturn query(`#${hash}`) || query(`a[name='${hash}']`);\n};\n","import { queryAll, toMs } from '../utils';\nimport Swup from '../Swup';\n\n// Transition property/event sniffing\nlet transitionProp = 'transition';\nlet transitionEndEvent = 'transitionend';\nlet animationProp = 'animation';\nlet animationEndEvent = 'animationend';\n\nif (window.ontransitionend === undefined && window.onwebkittransitionend !== undefined) {\n\ttransitionProp = 'WebkitTransition';\n\ttransitionEndEvent = 'webkitTransitionEnd';\n}\n\nif (window.onanimationend === undefined && window.onwebkitanimationend !== undefined) {\n\tanimationProp = 'WebkitAnimation';\n\tanimationEndEvent = 'webkitAnimationEnd';\n}\n\nexport function getAnimationPromises(\n\tthis: Swup,\n\t// we don't use this argument, but JS plugin depends on it with\n\t// its own version of getAnimationPromises, so it must be specified when\n\t// getAnimationPromises is being used\n\tanimationType: 'in' | 'out'\n): Promise<void>[] {\n\tconst selector = this.options.animationSelector;\n\n\t// Allow usage of swup without animations\n\tif (selector === false) {\n\t\t// Use array of a single resolved promise instead of an empty array to allow\n\t\t// possible future use with Promise.race() which requires an actual value\n\t\treturn [Promise.resolve()];\n\t}\n\n\tconst animatedElements = queryAll(selector, document.body);\n\n\t// Warn if no animated containers found on page, but keep things going\n\tif (!animatedElements.length) {\n\t\tconsole.warn(`[swup] No animated elements found by selector ${selector}`);\n\t\treturn [Promise.resolve()];\n\t}\n\n\treturn animatedElements.map((element) => getAnimationPromiseForElement(element, selector));\n}\n\nconst isTransitionOrAnimationEvent = (event: any): event is TransitionEvent | AnimationEvent =>\n\t!!event.elapsedTime;\n\nfunction getAnimationPromiseForElement(\n\telement: Element,\n\tselector: string,\n\texpectedType: 'animation' | 'transition' | null = null\n): Promise<void> {\n\tconst { type, timeout, propCount } = getTransitionInfo(element, expectedType);\n\n\t// Resolve immediately if no transition defined\n\tif (!type || !timeout) {\n\t\tconsole.warn(\n\t\t\t`[swup] No CSS transition duration defined for element of selector ${selector}`\n\t\t);\n\t\treturn Promise.resolve();\n\t}\n\n\treturn new Promise((resolve) => {\n\t\tconst endEvent = type === 'transition' ? transitionEndEvent : animationEndEvent;\n\t\tconst startTime = performance.now();\n\t\tlet propsTransitioned = 0;\n\n\t\tconst end = () => {\n\t\t\telement.removeEventListener(endEvent, onEnd);\n\t\t\tresolve();\n\t\t};\n\n\t\tconst onEnd: EventListener = (event) => {\n\t\t\t// Skip transitions on child elements\n\t\t\tif (event.target !== element) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isTransitionOrAnimationEvent(event)) {\n\t\t\t\tthrow new Error('Not a transition or animation event.');\n\t\t\t}\n\n\t\t\t// Skip transitions that happened before we started listening\n\t\t\tconst elapsedTime = (performance.now() - startTime) / 1000;\n\t\t\tif (elapsedTime < event.elapsedTime) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// End if all properties have transitioned\n\t\t\tif (++propsTransitioned >= propCount) {\n\t\t\t\tend();\n\t\t\t}\n\t\t};\n\n\t\tsetTimeout(() => {\n\t\t\tif (propsTransitioned < propCount) {\n\t\t\t\tend();\n\t\t\t}\n\t\t}, timeout + 1);\n\n\t\telement.addEventListener(endEvent, onEnd);\n\t});\n}\n\nexport function getTransitionInfo(\n\telement: Element,\n\texpectedType: 'animation' | 'transition' | null = null\n) {\n\tconst styles = window.getComputedStyle(element);\n\n\t// not sure what to do about the below mess other than casting, but it's a mess\n\tconst transitionDelay = `${transitionProp}Delay` as keyof CSSStyleDeclaration;\n\tconst transitionDuration = `${transitionProp}Duration` as keyof CSSStyleDeclaration;\n\tconst animationDelay = `${animationProp}Delay` as keyof CSSStyleDeclaration;\n\tconst animationDuration = `${animationProp}Duration` as keyof CSSStyleDeclaration;\n\n\tconst transitionDelays = (\n\t\tstyles[transitionDelay] as CSSStyleDeclaration['transitionDelay']\n\t).split(', ');\n\tconst transitionDurations = (\n\t\t(styles[transitionDuration] || '') as CSSStyleDeclaration['transitionDuration']\n\t).split(', ');\n\tconst transitionTimeout = calculateTimeout(transitionDelays, transitionDurations);\n\n\tconst animationDelays = (\n\t\t(styles[animationDelay] || '') as CSSStyleDeclaration['animationDelay']\n\t).split(', ');\n\tconst animationDurations = (\n\t\t(styles[animationDuration] || '') as CSSStyleDeclaration['animationDuration']\n\t).split(', ');\n\tconst animationTimeout = calculateTimeout(animationDelays, animationDurations);\n\n\tlet type: string | null = '';\n\tlet timeout = 0;\n\tlet propCount = 0;\n\n\tif (expectedType === 'transition') {\n\t\tif (transitionTimeout > 0) {\n\t\t\ttype = 'transition';\n\t\t\ttimeout = transitionTimeout;\n\t\t\tpropCount = transitionDurations.length;\n\t\t}\n\t} else if (expectedType === 'animation') {\n\t\tif (animationTimeout > 0) {\n\t\t\ttype = 'animation';\n\t\t\ttimeout = animationTimeout;\n\t\t\tpropCount = animationDurations.length;\n\t\t}\n\t} else {\n\t\ttimeout = Math.max(transitionTimeout, animationTimeout);\n\t\ttype =\n\t\t\ttimeout > 0\n\t\t\t\t? transitionTimeout > animationTimeout\n\t\t\t\t\t? 'transition'\n\t\t\t\t\t: 'animation'\n\t\t\t\t: null;\n\t\tpropCount = type\n\t\t\t? type === 'transition'\n\t\t\t\t? transitionDurations.length\n\t\t\t\t: animationDurations.length\n\t\t\t: 0;\n\t}\n\n\treturn {\n\t\ttype,\n\t\ttimeout,\n\t\tpropCount\n\t};\n}\n\nfunction calculateTimeout(delays: string[], durations: string[]) {\n\twhile (delays.length < durations.length) {\n\t\tdelays = delays.concat(delays);\n\t}\n\n\treturn Math.max(...durations.map((duration, i) => toMs(duration) + toMs(delays[i])));\n}\n","import { getDataFromHtml } from '../helpers';\nimport Swup from '../Swup';\nimport { PageHtmlData } from '../helpers/getDataFromHtml';\n\nexport type PageData = PageHtmlData & {\n\tresponseURL: string;\n};\nexport const getPageData = function (this: Swup, request: XMLHttpRequest): PageData | null {\n\t// this method can be replaced in case other content than html is expected to be received from server\n\t// this function should always return { title, pageClass, originalContent, blocks, responseURL }\n\t// in case page has invalid structure - return null\n\tconst html = request.responseText;\n\tconst pageHtmlData = getDataFromHtml(html, this.options.containers);\n\n\tif (!pageHtmlData) {\n\t\tconsole.warn('[swup] Received page is invalid.');\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t...pageHtmlData,\n\t\tresponseURL: request.responseURL || window.location.href\n\t};\n};\n","import Swup from '../Swup';\nimport { fetch } from '../helpers';\nimport { TransitionOptions } from './loadPage';\nimport { PageRecord } from './Cache';\n\nexport function fetchPage(this: Swup, data: TransitionOptions): Promise<PageRecord> {\n\tconst headers = this.options.requestHeaders;\n\tconst { url } = data;\n\n\tif (this.cache.exists(url)) {\n\t\tthis.triggerEvent('pageRetrievedFromCache');\n\t\treturn Promise.resolve(this.cache.getPage(url));\n\t}\n\n\treturn new Promise((resolve, reject) => {\n\t\tfetch({ ...data, headers }, (response) => {\n\t\t\tif (response.status === 500) {\n\t\t\t\tthis.triggerEvent('serverError');\n\t\t\t\treject(url);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// get json data\n\t\t\tconst page = this.getPageData(response);\n\t\t\tif (!page || !page.blocks.length) {\n\t\t\t\treject(url);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// render page\n\t\t\tconst cacheablePageData = { ...page, url };\n\t\t\tthis.cache.cacheUrl(cacheablePageData);\n\t\t\tthis.triggerEvent('pageLoaded');\n\t\t\tresolve(cacheablePageData);\n\t\t});\n\t});\n}\n","import Swup from '../Swup';\nimport { TransitionOptions } from './loadPage';\n\nexport const leavePage = function (\n\tthis: Swup,\n\tdata: TransitionOptions,\n\t{ popstate, skipTransition }: { popstate: PopStateEvent | null; skipTransition?: boolean } = {\n\t\tpopstate: null\n\t}\n) {\n\tif (skipTransition) {\n\t\tthis.triggerEvent('animationSkipped');\n\t\treturn [Promise.resolve()];\n\t}\n\n\tthis.triggerEvent('animationOutStart');\n\n\t// handle classes\n\tdocument.documentElement.classList.add('is-changing', 'is-leaving', 'is-animating');\n\tif (popstate) {\n\t\tdocument.documentElement.classList.add('is-popstate');\n\t}\n\n\t// animation promise stuff\n\tconst animationPromises: Promise<void>[] = this.getAnimationPromises('out');\n\tPromise.all(animationPromises).then(() => {\n\t\tthis.triggerEvent('animationOutDone');\n\t});\n\n\treturn animationPromises;\n};\n","import { classify, createHistoryRecord, getCurrentUrl } from '../helpers';\nimport Swup from '../Swup';\nimport { PageRecord } from './Cache';\n\nexport type TransitionOptions = {\n\turl: string;\n\tcustomTransition?: string;\n};\n\nexport const loadPage = function (\n\tthis: Swup,\n\tdata: TransitionOptions,\n\tpopstate: PopStateEvent | null\n) {\n\tconst { url, customTransition } = data;\n\tconst skipTransition = !!(popstate && !this.options.animateHistoryBrowsing);\n\n\tthis.triggerEvent('transitionStart', popstate || undefined);\n\n\t// set transition object\n\tthis.updateTransition(getCurrentUrl(), url, customTransition);\n\tif (customTransition != null) {\n\t\tdocument.documentElement.classList.add(`to-${classify(customTransition)}`);\n\t}\n\n\t// start/skip animation\n\tconst animationPromises = this.leavePage(data, { popstate, skipTransition });\n\n\t// create history record if this is not a popstate call (with or without anchor)\n\tif (!popstate) {\n\t\tcreateHistoryRecord(url + (this.scrollToElement || ''));\n\t}\n\n\tthis.currentPageUrl = getCurrentUrl();\n\n\t// Load page data\n\tconst fetchPromise = this.fetchPage(data);\n\n\t// when everything is ready, render the page\n\tPromise.all<PageRecord | void>([fetchPromise, ...animationPromises])\n\t\t.then(([pageData]) => {\n\t\t\tthis.renderPage(pageData as PageRecord, { popstate, skipTransition });\n\t\t})\n\t\t.catch((errorUrl) => {\n\t\t\t// Return early if errorUrl is not defined (probably aborted preload request)\n\t\t\tif (errorUrl === undefined) return;\n\n\t\t\t// Rewrite `skipPopStateHandling` to redirect manually when `history.go` is processed\n\t\t\tthis.options.skipPopStateHandling = () => {\n\t\t\t\twindow.location = errorUrl;\n\t\t\t\treturn true;\n\t\t\t};\n\n\t\t\t// Go back to the actual page we're still at\n\t\t\thistory.go(-1);\n\t\t});\n};\n","/**\n * Perform the replacement of content after loading a page.\n *\n * This method can be replaced or augmented by plugins to allow pausing.\n *\n * It takes an object with the page data as return from `getPageData` and has to\n * return a Promise that resolves once all content has been replaced and the\n * site is ready to start animating in the new page.\n *\n * @param {object} page The page object\n * @returns Promise\n */\nexport const replaceContent = function ({ blocks, title }: { blocks: string[]; title: string }) {\n\t// Replace content blocks\n\tblocks.forEach((html, i) => {\n\t\t// we know the block exists at this point\n\t\tconst block = document.body.querySelector(`[data-swup=\"${i}\"]`)!;\n\t\tblock.outerHTML = html;\n\t});\n\n\t// Update browser title\n\tdocument.title = title;\n\n\t// Return a Promise to allow plugins to defer\n\treturn Promise.resolve();\n};\n","import Swup from '../Swup';\nimport { EventType, Handler } from './on';\n\nexport const off = function off(this: Swup, event?: EventType, handler?: Handler) {\n\tif (event && handler) {\n\t\t// Remove specific handler\n\t\tif (this._handlers[event].includes(handler)) {\n\t\t\tthis._handlers[event] = this._handlers[event].filter((h) => h !== handler);\n\t\t} else {\n\t\t\tconsole.warn(`Handler for event '${event}' not found.`);\n\t\t}\n\t} else if (event) {\n\t\t// Remove all handlers for specific event\n\t\tthis._handlers[event] = [];\n\t} else {\n\t\t// Remove all handlers for all events\n\t\tObject.keys(this._handlers).forEach((event) => {\n\t\t\tthis._handlers[event as EventType] = [];\n\t\t});\n\t}\n};\n","import Swup from '../Swup';\n\nexport type EventType =\n\t| 'animationInDone'\n\t| 'animationInStart'\n\t| 'animationOutDone'\n\t| 'animationOutStart'\n\t| 'animationSkipped'\n\t| 'clickLink'\n\t| 'contentReplaced'\n\t| 'disabled'\n\t| 'enabled'\n\t| 'openPageInNewTab'\n\t| 'pageLoaded'\n\t| 'pageRetrievedFromCache'\n\t| 'pageView'\n\t| 'popState'\n\t| 'samePage'\n\t| 'samePageWithHash'\n\t| 'serverError'\n\t| 'transitionStart'\n\t| 'transitionEnd'\n\t| 'willReplaceContent';\nexport type Handler = (event?: Event) => void;\nexport type Handlers = Record<EventType, Handler[]>;\n\nexport const on = function on(this: Swup, event: EventType, handler: Handler) {\n\tif (this._handlers[event]) {\n\t\tthis._handlers[event].push(handler);\n\t} else {\n\t\tconsole.warn(`Unsupported event ${event}.`);\n\t}\n};\n","import Swup from '../Swup';\n\nexport type Plugin = {\n\tname: string;\n\tisSwupPlugin: true;\n\tmount: () => void;\n\tunmount: () => void;\n\n\t// the instance is assigned later on after passing to swup\n\tswup?: Swup;\n\n\t// these are possibly undefined for backward compatibility\n\tversion?: string;\n\trequires?: Record<string, string>;\n\t_beforeMount?: () => void;\n\t_afterUnmount?: () => void;\n\t_checkRequirements?: () => boolean;\n};\n\nconst isSwupPlugin = (maybeInvalidPlugin: unknown): maybeInvalidPlugin is Plugin => {\n\t// @ts-ignore\n\treturn maybeInvalidPlugin?.isSwupPlugin;\n};\n\nexport const use = function (this: Swup, plugin: unknown) {\n\tif (!isSwupPlugin(plugin)) {\n\t\tconsole.error('Not a swup plugin instance', plugin);\n\t\treturn;\n\t}\n\n\tplugin.swup = this;\n\tif (plugin._checkRequirements) {\n\t\tif (!plugin._checkRequirements()) {\n\t\t\treturn;\n\t\t}\n\t}\n\tif (plugin._beforeMount) {\n\t\tplugin._beforeMount();\n\t}\n\tplugin.mount();\n\n\tthis.plugins.push(plugin);\n\n\treturn this.plugins;\n};\n\nexport function unuse(this: Swup, pluginOrName: Plugin | string) {\n\tconst plugin = this.findPlugin(pluginOrName);\n\tif (!plugin) {\n\t\tconsole.error('No such plugin', plugin);\n\t\treturn;\n\t}\n\n\tplugin.unmount();\n\tif (plugin._afterUnmount) {\n\t\tplugin._afterUnmount();\n\t}\n\n\tthis.plugins = this.plugins.filter((p) => p !== plugin);\n\n\treturn this.plugins;\n}\n\nexport function findPlugin(this: Swup, pluginOrName: Plugin | string) {\n\treturn this.plugins.find((plugin) => plugin === pluginOrName || plugin.name === pluginOrName);\n}\n","import { Location, updateHistoryRecord, getCurrentUrl } from '../helpers';\nimport Swup from '../Swup';\nimport { PageRecord } from './Cache';\n\nexport const renderPage = function (\n\tthis: Swup,\n\tpage: PageRecord,\n\t{ popstate, skipTransition }: { popstate: PopStateEvent | null; skipTransition?: boolean } = {\n\t\tpopstate: null\n\t}\n) {\n\tdocument.documentElement.classList.remove('is-leaving');\n\n\t// do nothing if another page was requested in the meantime\n\tif (!this.isSameResolvedUrl(getCurrentUrl(), page.url)) {\n\t\treturn;\n\t}\n\n\tconst { url } = Location.fromUrl(page.responseURL);\n\n\t// update cache and state if the url was redirected\n\tif (!this.isSameResolvedUrl(getCurrentUrl(), url)) {\n\t\tthis.cache.cacheUrl({ ...page, url });\n\t\tthis.currentPageUrl = getCurrentUrl();\n\t\tupdateHistoryRecord(url);\n\t}\n\n\t// only add for page loads with transitions\n\tif (!skipTransition) {\n\t\tdocument.documentElement.classList.add('is-rendering');\n\t}\n\n\tthis.triggerEvent('willReplaceContent', popstate || undefined);\n\n\tthis.replaceContent(page).then(() => {\n\t\tthis.triggerEvent('contentReplaced', popstate || undefined);\n\t\tthis.triggerEvent('pageView', popstate || undefined);\n\n\t\t// empty cache if it's disabled (in case preload plugin filled it)\n\t\tif (!this.options.cache) {\n\t\t\tthis.cache.empty();\n\t\t}\n\n\t\t// Perform in transition\n\t\tthis.enterPage({ popstate: popstate || undefined, skipTransition });\n\n\t\t// reset scroll-to element\n\t\tthis.scrollToElement = null;\n\t});\n};\n","import { EventType } from './on';\nimport Swup from '../Swup';\n\nexport const triggerEvent = function (\n\tthis: Swup,\n\teventName: EventType,\n\toriginalEvent?: PopStateEvent | MouseEvent\n): void {\n\t// call saved handlers with \"on\" method and pass originalEvent object if available\n\tthis._handlers[eventName].forEach((handler) => {\n\t\ttry {\n\t\t\thandler(originalEvent);\n\t\t} catch (error) {\n\t\t\tconsole.error(error);\n\t\t}\n\t});\n\n\t// trigger event on document with prefix \"swup:\"\n\tconst event = new CustomEvent(`swup:${eventName}`, { detail: eventName });\n\tdocument.dispatchEvent(event);\n};\n","import Swup from '../Swup';\n\nexport const updateTransition = function (\n\tthis: Swup,\n\tfrom: string,\n\tto: string,\n\tcustom?: string\n): void {\n\tthis.transition = { from, to, custom };\n};\n","import delegate from 'delegate-it';\n\nimport version from './config/version';\n\nimport {\n\tcleanupAnimationClasses,\n\tdelegateEvent,\n\tgetCurrentUrl,\n\tLocation,\n\tmarkSwupElements,\n\tupdateHistoryRecord\n} from './helpers';\nimport { Unsubscribe } from './helpers/delegateEvent';\n\nimport { Cache } from './modules/Cache';\nimport { enterPage } from './modules/enterPage';\nimport { getAnchorElement } from './modules/getAnchorElement';\nimport { getAnimationPromises } from './modules/getAnimationPromises';\nimport { getPageData } from './modules/getPageData';\nimport { fetchPage } from './modules/fetchPage';\nimport { leavePage } from './modules/leavePage';\nimport { loadPage } from './modules/loadPage';\nimport { replaceContent } from './modules/replaceContent';\nimport { off } from './modules/off';\nimport { on, Handlers } from './modules/on';\nimport { use, unuse, findPlugin, Plugin } from './modules/plugins';\nimport { renderPage } from './modules/renderPage';\nimport { triggerEvent } from './modules/triggerEvent';\nimport { updateTransition } from './modules/updateTransition';\n\nimport { queryAll } from './utils';\n\nexport type Transition = {\n\tfrom?: string;\n\tto?: string;\n\tcustom?: string;\n};\n\ntype DelegatedListeners = {\n\tclick?: Unsubscribe;\n};\n\nexport type Options = {\n\tanimateHistoryBrowsing: boolean;\n\tanimationSelector: string | false;\n\tlinkSelector: string;\n\tcache: boolean;\n\tcontainers: string[];\n\trequestHeaders: Record<string, string>;\n\tplugins: Plugin[];\n\tskipPopStateHandling: (event: any) => boolean;\n\tignoreVisit: (href: string, { el }: { el?: Element }) => boolean;\n\tresolveUrl: (url: string) => string;\n};\n\nexport default class Swup {\n\tversion = version;\n\n\t_handlers: Handlers = {\n\t\tanimationInDone: [],\n\t\tanimationInStart: [],\n\t\tanimationOutDone: [],\n\t\tanimationOutStart: [],\n\t\tanimationSkipped: [],\n\t\tclickLink: [],\n\t\tcontentReplaced: [],\n\t\tdisabled: [],\n\t\tenabled: [],\n\t\topenPageInNewTab: [],\n\t\tpageLoaded: [],\n\t\tpageRetrievedFromCache: [],\n\t\tpageView: [],\n\t\tpopState: [],\n\t\tsamePage: [],\n\t\tsamePageWithHash: [],\n\t\tserverError: [],\n\t\ttransitionStart: [],\n\t\ttransitionEnd: [],\n\t\twillReplaceContent: []\n\t};\n\n\t// variable for anchor to scroll to after render\n\tscrollToElement: string | null = null;\n\t// variable for save options\n\toptions: Options;\n\t// running plugin instances\n\tplugins: Plugin[] = [];\n\t// variable for current transition info object\n\ttransition: Transition = {};\n\t// cache instance\n\tcache: Cache;\n\t// allows us to compare the current and new path inside popStateHandler\n\tcurrentPageUrl = getCurrentUrl();\n\t// variable for keeping event listeners from \"delegate\"\n\tdelegatedListeners: DelegatedListeners = {};\n\t// so we are able to remove the listener\n\tboundPopStateHandler: (event: PopStateEvent) => void;\n\n\tloadPage = loadPage;\n\tleavePage = leavePage;\n\trenderPage = renderPage;\n\treplaceContent = replaceContent;\n\tenterPage = enterPage;\n\ttriggerEvent = triggerEvent;\n\tdelegateEvent = delegateEvent;\n\ton = on;\n\toff = off;\n\tupdateTransition = updateTransition;\n\tgetAnimationPromises = getAnimationPromises;\n\tgetPageData = getPageData;\n\tfetchPage = fetchPage;\n\tgetAnchorElement = getAnchorElement;\n\tlog: (message: string, context?: any) => void = () => {}; // here so it can be used by plugins\n\tuse = use;\n\tunuse = unuse;\n\tfindPlugin = findPlugin;\n\tgetCurrentUrl = getCurrentUrl;\n\tcleanupAnimationClasses = cleanupAnimationClasses;\n\n\tdefaults: Options = {\n\t\tanimateHistoryBrowsing: false,\n\t\tanimationSelector: '[class*=\"transition-\"]',\n\t\tcache: true,\n\t\tcontainers: ['#swup'],\n\t\tignoreVisit: (href, { el } = {}) => !!el?.closest('[data-no-swup]'),\n\t\tlinkSelector: 'a[href]',\n\t\tplugins: [],\n\t\tresolveUrl: (url) => url,\n\t\trequestHeaders: {\n\t\t\t'X-Requested-With': 'swup',\n\t\t\tAccept: 'text/html, application/xhtml+xml'\n\t\t},\n\t\tskipPopStateHandling: (event) => event.state?.source !== 'swup'\n\t};\n\n\tconstructor(options: Partial<Options> = {}) {\n\t\t// Merge defaults and options\n\t\tthis.options = { ...this.defaults, ...options };\n\n\t\tthis.boundPopStateHandler = this.popStateHandler.bind(this);\n\n\t\tthis.cache = new Cache(this);\n\n\t\tthis.enable();\n\t}\n\n\tenable() {\n\t\t// Check for Promise support\n\t\tif (typeof Promise === 'undefined') {\n\t\t\tconsole.warn('Promise is not supported');\n\t\t\treturn;\n\t\t}\n\n\t\t// Add event listeners\n\t\tthis.delegatedListeners.click = delegateEvent(\n\t\t\tthis.options.linkSelector,\n\t\t\t'click',\n\t\t\tthis.linkClickHandler.bind(this)\n\t\t);\n\n\t\twindow.addEventListener('popstate', this.boundPopStateHandler);\n\n\t\t// Initial save to cache\n\t\tif (this.options.cache) {\n\t\t\t// Disabled to avoid caching modified dom state: logic moved to preload plugin\n\t\t\t// https://github.com/swup/swup/issues/475\n\t\t}\n\n\t\t// Mark swup blocks in html\n\t\tmarkSwupElements(document.documentElement, this.options.containers);\n\n\t\t// Mount plugins\n\t\tthis.options.plugins.forEach((plugin) => this.use(plugin));\n\n\t\t// Modify initial history record\n\t\tupdateHistoryRecord();\n\n\t\t// Trigger enabled event\n\t\tthis.triggerEvent('enabled');\n\n\t\t// Add swup-enabled class to html tag\n\t\tdocument.documentElement.classList.add('swup-enabled');\n\n\t\t// Trigger page view event\n\t\tthis.triggerEvent('pageView');\n\t}\n\n\tdestroy() {\n\t\t// remove delegated listeners\n\t\tthis.delegatedListeners.click!.destroy();\n\n\t\t// remove popstate listener\n\t\twindow.removeEventListener('popstate', this.boundPopStateHandler);\n\n\t\t// empty cache\n\t\tthis.cache.empty();\n\n\t\t// unmount plugins\n\t\tthis.options.plugins.forEach((plugin) => {\n\t\t\tthis.unuse(plugin);\n\t\t});\n\n\t\t// remove swup data atributes from blocks\n\t\tqueryAll('[data-swup]').forEach((element) => {\n\t\t\telement.removeAttribute('data-swup');\n\t\t});\n\n\t\t// remove handlers\n\t\tthis.off();\n\n\t\t// trigger disable event\n\t\tthis.triggerEvent('disabled');\n\n\t\t// remove swup-enabled class from html tag\n\t\tdocument.documentElement.classList.remove('swup-enabled');\n\t}\n\n\tshouldIgnoreVisit(href: string, { el }: { el?: Element } = {}) {\n\t\tconst { origin } = Location.fromUrl(href);\n\n\t\t// Ignore if the new URL's origin doesn't match the current one\n\t\tif (origin !== window.location.origin) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Ignore if the link/form would open a new window (or none at all)\n\t\tif (el && this.triggerWillOpenNewWindow(el)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Ignore if the visit should be ignored as per user options\n\t\tif (this.options.ignoreVisit(href, { el })) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Finally, allow the visit\n\t\treturn false;\n\t}\n\n\tlinkClickHandler(event: delegate.Event<MouseEvent>) {\n\t\tconst linkEl = event.delegateTarget;\n\t\tconst { href, url, hash } = Location.fromElement(linkEl as HTMLAnchorElement);\n\n\t\t// Exit early if the link should be ignored\n\t\tif (this.shouldIgnoreVisit(href, { el: linkEl })) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit early if control key pressed\n\t\tif (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {\n\t\t\tthis.triggerEvent('openPageInNewTab', event);\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit early if other than left mouse button\n\t\tif (event.button !== 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.triggerEvent('clickLink', event);\n\t\tevent.preventDefault();\n\n\t\t// Handle links to the same page and exit early, where applicable\n\t\tif (!url || url === getCurrentUrl()) {\n\t\t\tthis.handleLinkToSamePage(url, hash, event);\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit early if the resolved path hasn't changed\n\t\tif (this.isSameResolvedUrl(url, getCurrentUrl())) return;\n\n\t\t// Store the element that should be scrolled to after loading the next page\n\t\tthis.scrollToElement = hash || null;\n\n\t\t// Get the custom transition name, if present\n\t\tconst customTransition = linkEl.getAttribute('data-swup-transition') || undefined;\n\n\t\t// Finally, proceed with loading the page\n\t\tthis.loadPage({ url, customTransition }, null);\n\t}\n\n\thandleLinkToSamePage(url: string, hash: string, event: MouseEvent) {\n\t\t// Emit event and exit early if the url points to the same page without hash\n\t\tif (!hash) {\n\t\t\tthis.triggerEvent('samePage', event);\n\t\t\treturn;\n\t\t}\n\n\t\t// link to the same URL with hash\n\t\tthis.triggerEvent('samePageWithHash', event);\n\n\t\tconst element = getAnchorElement(hash);\n\n\t\t// Warn and exit early if no matching element was found for the hash\n\t\tif (!element) {\n\t\t\treturn console.warn(`Element for offset not found (#${hash})`);\n\t\t}\n\n\t\tupdateHistoryRecord(url + hash);\n\t}\n\n\ttriggerWillOpenNewWindow(triggerEl: Element) {\n\t\tif (triggerEl.matches('[download], [target=\"_blank\"]')) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tpopStateHandler(event: PopStateEvent) {\n\t\t// Exit early if this event should be ignored\n\t\tif (this.options.skipPopStateHandling(event)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit early if the resolved path hasn't changed\n\t\tif (this.isSameResolvedUrl(getCurrentUrl(), this.currentPageUrl)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { url, hash } = Location.fromUrl(event.state?.url ?? location.href);\n\n\t\tif (hash) {\n\t\t\tthis.scrollToElement = hash;\n\t\t} else {\n\t\t\tevent.preventDefault();\n\t\t}\n\n\t\tthis.triggerEvent('popState', event);\n\n\t\tif (!this.options.animateHistoryBrowsing) {\n\t\t\tdocument.documentElement.classList.remove('is-animating');\n\t\t\tcleanupAnimationClasses();\n\t\t}\n\n\t\tthis.loadPage({ url }, event);\n\t}\n\n\t/**\n\t * Utility function to validate and run the global option 'resolveUrl'\n\t * @param {string} url\n\t * @returns {string} the resolved url\n\t */\n\tresolveUrl(url: string) {\n\t\tif (typeof this.options.resolveUrl !== 'function') {\n\t\t\tconsole.warn(`[swup] options.resolveUrl expects a callback function.`);\n\t\t\treturn url;\n\t\t}\n\t\tconst result = this.options.resolveUrl(url);\n\t\tif (!result || typeof result !== 'string') {\n\t\t\tconsole.warn(`[swup] options.resolveUrl needs to return a url`);\n\t\t\treturn url;\n\t\t}\n\t\tif (result.startsWith('//') || result.startsWith('http')) {\n\t\t\tconsole.warn(`[swup] options.resolveUrl needs to return a relative url`);\n\t\t\treturn url;\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Compares the resolved version of two paths and returns true if they are the same\n\t * @param {string} url1\n\t * @param {string} url2\n\t * @returns {boolean}\n\t */\n\tisSameResolvedUrl(url1: string, url2: string) {\n\t\treturn this.resolveUrl(url1) === this.resolveUrl(url2);\n\t}\n}\n"],"names":["classify","text","fallback","String","toLowerCase","replace","getCurrentUrl","hash","location","pathname","search","createHistoryRecord","url","customData","data","_extends","random","Math","source","history","pushState","updateHistoryRecord","state","replaceState","delegateEvent","selector","type","callback","_ref","base","document","eventOptions","delegation","delegate","destroy","query","context","querySelector","queryAll","Array","from","querySelectorAll","nextTick","requestAnimationFrame","escapeCssIdentifier","ident","window","CSS","escape","toMs","s","Number","slice","getDataFromHtml","html","containers","_query","_query2","fakeDom","createElement","innerHTML","blocks","forEach","console","warn","length","item","index","setAttribute","push","outerHTML","innerText","className","title","pageClass","originalContent","fetch","options","defaults","method","headers","request","XMLHttpRequest","onreadystatechange","readyState","open","Object","entries","key","header","setRequestHeader","send","Location","URL","constructor","baseURI","super","toString","this","static","el","href","getAttribute","markSwupElements","element","isSwupClass","test","includes","cleanupAnimationClasses","removeClasses","documentElement","split","filter","classList","remove","Cache","swup","pages","last","getCacheUrl","resolveUrl","fromUrl","cacheUrl","page","responseURL","log","keys","getPage","getCurrentPage","exists","empty","enterPage","popstate","skipTransition","triggerEvent","Promise","resolve","animationPromises","getAnimationPromises","all","then","getAnchorElement","charAt","substring","decodeURIComponent","transitionProp","transitionEndEvent","animationProp","animationEndEvent","animationType","animationSelector","animatedElements","body","map","expectedType","timeout","propCount","getComputedStyle","transitionDuration","animationDuration","transitionDelays","styles","transitionDurations","transitionTimeout","calculateTimeout","animationDelays","animationDelay","animationDurations","animationTimeout","max","getTransitionInfo","endEvent","startTime","performance","now","propsTransitioned","end","removeEventListener","onEnd","event","target","elapsedTime","isTransitionOrAnimationEvent","Error","setTimeout","addEventListener","getAnimationPromiseForElement","delays","durations","concat","duration","i","undefined","ontransitionend","onwebkittransitionend","onanimationend","onwebkitanimationend","getPageData","pageHtmlData","responseText","fetchPage","requestHeaders","cache","reject","response","status","cacheablePageData","leavePage","add","loadPage","customTransition","animateHistoryBrowsing","updateTransition","scrollToElement","currentPageUrl","fetchPromise","pageData","renderPage","catch","errorUrl","skipPopStateHandling","go","replaceContent","handler","_handlers","h","on","use","plugin","maybeInvalidPlugin","isSwupPlugin","_checkRequirements","_beforeMount","mount","plugins","error","unuse","pluginOrName","findPlugin","unmount","_afterUnmount","p","find","name","isSameResolvedUrl","eventName","originalEvent","detail","dispatchEvent","to","custom","transition","Swup","version","animationInDone","animationInStart","animationOutDone","animationOutStart","animationSkipped","clickLink","contentReplaced","disabled","enabled","openPageInNewTab","pageLoaded","pageRetrievedFromCache","pageView","popState","samePage","samePageWithHash","serverError","transitionStart","transitionEnd","willReplaceContent","delegatedListeners","boundPopStateHandler","off","ignoreVisit","closest","linkSelector","Accept","_event$state","popStateHandler","bind","enable","click","linkClickHandler","removeAttribute","shouldIgnoreVisit","origin","triggerWillOpenNewWindow","linkEl","delegateTarget","fromElement","metaKey","ctrlKey","shiftKey","altKey","button","preventDefault","handleLinkToSamePage","triggerEl","matches","_event$state$url","_event$state2","result","startsWith","url1","url2"],"mappings":"+PAAaA,MAAQA,EAAG,CAACC,EAAcC,IACvBC,OAAOF,GACpBG,cAGAC,QAAQ,YAAa,KACrBA,QAAQ,WAAY,IACpBA,QAAQ,OAAQ,KAChBA,QAAQ,WAAY,KACLH,GAAY,GCTjBI,EAAgB,EAAGC,QAA6B,CAAE,IACvDC,SAASC,SAAWD,SAASE,QAAUH,EAAOC,SAASD,KAAO,ICCzDI,EAAsB,CAClCC,EACAC,EAAsC,CAAA,KAGtC,MAAUC,EAAAC,EAAA,CACTH,IAFDA,EAAMA,GAAON,EAAc,CAAEC,MAAM,IAGlCS,OAAQC,KAAKD,SACbE,OAAQ,QACLL,GAEJM,QAAQC,UAAUN,EAAM,GAAIF,EAC7B,ECZgCS,EAAG,CAClC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,KAAK,4DACNpD,GAEDqS,GAPNlP,QAAQC,KAAK,mDACNpD,EAOT,CAQAwO,kBAAkB+D,EAAcC,GAC/B,OAAWlN,KAACsB,WAAW2L,KAAUjN,KAAKsB,WAAW4L,EAClD"}
|
package/dist/Swup.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"delegate-it";const e=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},i=function(t,e){void 0===e&&(e={});const i={url:t=t||n({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(i,"",t)},s=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||n({hash:!0});const i={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(i,"",t)},o=function(e,n,i,s){let{base:o=document,...r}=void 0===s?{}:s;const a=t(o,e,n,i,r);return{destroy:()=>a.destroy()}},r=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},a=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},l=t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})},u=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,c=t=>1e3*Number(t.slice(0,-1).replace(",",".")),h=(t,e)=>{var n,i;let s=document.createElement("html");s.innerHTML=t;let o=[];e.forEach(t=>{if(null==r(t,s))return console.warn("[swup] Container "+t+" not found on page."),null;a(t).length!==a(t,s).length&&console.warn("[swup] Mismatched number of containers found on new page."),a(t).forEach((e,n)=>{a(t,s)[n].setAttribute("data-swup",String(o.length)),o.push(a(t,s)[n].outerHTML)})});const l=(null==(n=r("title",s))?void 0:n.innerText)||"",u=null==(i=r("body",s))?void 0:i.className;return s.innerHTML="",s=null,{title:l,pageClass:u,blocks:o,originalContent:t}},d=(t,e)=>{const n={url:window.location.pathname+window.location.search,method:"GET",data:null,headers:{}},{url:i,method:s,headers:o,data:r}={...n,...t},a=new XMLHttpRequest;return a.onreadystatechange=function(){4===a.readyState&&e(a)},a.open(s,i,!0),Object.entries(o).forEach(t=>{let[e,n]=t;a.setRequestHeader(e,n)}),a.send(r),a};class p extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href");return new p(e)}static fromUrl(t){return new p(t)}}const g=(t,e)=>{let n=0;e.forEach(e=>{null==r(e,t)?console.warn("[swup] Container "+e+" not found on page."):a(e).forEach((i,s)=>{a(e,t)[s].setAttribute("data-swup",String(n)),n++})})},m=t=>/^to-/.test(t)||["is-changing","is-rendering","is-popstate"].includes(t),v=()=>{const t=document.documentElement.className.split(" ").filter(m);document.documentElement.classList.remove(...t)};class f{constructor(t){this.pages={},this.last=null,this.swup=void 0,this.swup=t}getCacheUrl(t){return this.swup.resolveUrl(p.fromUrl(t).url)}cacheUrl(t){t.url=this.getCacheUrl(t.url),t.url in this.pages==0&&(this.pages[t.url]=t),t.responseURL=this.getCacheUrl(t.responseURL),this.last=this.pages[t.url],this.swup.log("Cache ("+Object.keys(this.pages).length+")",this.pages)}getPage(t){return t=this.getCacheUrl(t),this.pages[t]}getCurrentPage(){return this.getPage(n())}exists(t){return(t=this.getCacheUrl(t))in this.pages}empty(){this.pages={},this.last=null,this.swup.log("Cache cleared")}remove(t){delete this.pages[this.getCacheUrl(t)]}}const w=function(t){let{popstate:e,skipTransition:n}=t;if(n)return this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses(),[Promise.resolve()];l(()=>{this.triggerEvent("animationInStart"),document.documentElement.classList.remove("is-animating")});const i=this.getAnimationPromises("in");return Promise.all(i).then(()=>{this.triggerEvent("animationInDone"),this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses()}),i},E=t=>t?("#"===t.charAt(0)&&(t=t.substring(1)),t=decodeURIComponent(t),t=u(t),r("#"+t)||r("a[name='"+t+"']")):null;let P="transition",S="transitionend",b="animation",U="animationend";function k(t){const e=this.options.animationSelector;if(!1===e)return[Promise.resolve()];const n=a(e,document.body);return n.length?n.map(t=>function(t,e,n){void 0===n&&(n=null);const{type:i,timeout:s,propCount:o}=function(t,e){void 0===e&&(e=null);const n=window.getComputedStyle(t),i=P+"Duration",s=b+"Delay",o=b+"Duration",r=n[P+"Delay"].split(", "),a=(n[i]||"").split(", "),l=y(r,a),u=(n[s]||"").split(", "),c=(n[o]||"").split(", "),h=y(u,c);let d="",p=0,g=0;return"transition"===e?l>0&&(d="transition",p=l,g=a.length):"animation"===e?h>0&&(d="animation",p=h,g=c.length):(p=Math.max(l,h),d=p>0?l>h?"transition":"animation":null,g=d?"transition"===d?a.length:c.length:0),{type:d,timeout:p,propCount:g}}(t,n);return i&&s?new Promise(e=>{const n="transition"===i?S:U,r=performance.now();let a=0;const l=()=>{t.removeEventListener(n,u),e()},u=e=>{if(e.target===t){if(!(t=>!!t.elapsedTime)(e))throw new Error("Not a transition or animation event.");(performance.now()-r)/1e3<e.elapsedTime||++a>=o&&l()}};setTimeout(()=>{a<o&&l()},s+1),t.addEventListener(n,u)}):(console.warn("[swup] No CSS transition duration defined for element of selector "+e),Promise.resolve())}(t,e)):(console.warn("[swup] No animated elements found by selector "+e),[Promise.resolve()])}function y(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>c(e)+c(t[n])))}void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(P="WebkitTransition",S="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(b="WebkitAnimation",U="webkitAnimationEnd");const C=function(t){const e=h(t.responseText,this.options.containers);return e?{...e,responseURL:t.responseURL||window.location.href}:(console.warn("[swup] Received page is invalid."),null)};function L(t){const e=this.options.requestHeaders,{url:n}=t;return this.cache.exists(n)?(this.triggerEvent("pageRetrievedFromCache"),Promise.resolve(this.cache.getPage(n))):new Promise((i,s)=>{d({...t,headers:e},t=>{if(500===t.status)return this.triggerEvent("serverError"),void s(n);const e=this.getPageData(t);if(!e||!e.blocks.length)return void s(n);const o={...e,url:n};this.cache.cacheUrl(o),this.triggerEvent("pageLoaded"),i(o)})})}const T=function(t,e){let{popstate:n,skipTransition:i}=void 0===e?{popstate:null}:e;if(i)return this.triggerEvent("animationSkipped"),[Promise.resolve()];this.triggerEvent("animationOutStart"),document.documentElement.classList.add("is-changing","is-leaving","is-animating"),n&&document.documentElement.classList.add("is-popstate");const s=this.getAnimationPromises("out");return Promise.all(s).then(()=>{this.triggerEvent("animationOutDone")}),s},H=function(t,s){const{url:o,customTransition:r}=t,a=!(!s||this.options.animateHistoryBrowsing);this.triggerEvent("transitionStart",s||void 0),this.updateTransition(n(),o,r),null!=r&&document.documentElement.classList.add("to-"+e(r));const l=this.leavePage(t,{popstate:s,skipTransition:a});s||i(o+(this.scrollToElement||"")),this.currentPageUrl=n();const u=this.fetchPage(t);Promise.all([u,...l]).then(t=>{let[e]=t;this.renderPage(e,{popstate:s,skipTransition:a})}).catch(t=>{void 0!==t&&(this.options.skipPopStateHandling=()=>(window.location=t,!0),history.go(-1))})},R=function(t){let{blocks:e,title:n}=t;return e.forEach((t,e)=>{document.body.querySelector('[data-swup="'+e+'"]').outerHTML=t}),document.title=n,Promise.resolve()},A=function(t,e){t&&e?this._handlers[t].includes(e)?this._handlers[t]=this._handlers[t].filter(t=>t!==e):console.warn("Handler for event '"+t+"' not found."):t?this._handlers[t]=[]:Object.keys(this._handlers).forEach(t=>{this._handlers[t]=[]})},_=function(t,e){this._handlers[t]?this._handlers[t].push(e):console.warn("Unsupported event "+t+".")},x=function(t){var e;if(null==(e=t)?void 0:e.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function q(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function D(t){return this.plugins.find(e=>e===t||e.name===t)}const M=function(t,e){let{popstate:i,skipTransition:o}=void 0===e?{popstate:null}:e;if(document.documentElement.classList.remove("is-leaving"),!this.isSameResolvedUrl(n(),t.url))return;const{url:r}=p.fromUrl(t.responseURL);this.isSameResolvedUrl(n(),r)||(this.cache.cacheUrl({...t,url:r}),this.currentPageUrl=n(),s(r)),o||document.documentElement.classList.add("is-rendering"),this.triggerEvent("willReplaceContent",i||void 0),this.replaceContent(t).then(()=>{this.triggerEvent("contentReplaced",i||void 0),this.triggerEvent("pageView",i||void 0),this.options.cache||this.cache.empty(),this.enterPage({popstate:i||void 0,skipTransition:o}),this.scrollToElement=null})},N=function(t,e){this._handlers[t].forEach(t=>{try{t(e)}catch(t){console.error(t)}});const n=new CustomEvent("swup:"+t,{detail:t});document.dispatchEvent(n)},W=function(t,e,n){this.transition={from:t,to:e,custom:n}};class I{constructor(t){void 0===t&&(t={}),this.version="3.0.0-rc.4",this._handlers={animationInDone:[],animationInStart:[],animationOutDone:[],animationOutStart:[],animationSkipped:[],clickLink:[],contentReplaced:[],disabled:[],enabled:[],openPageInNewTab:[],pageLoaded:[],pageRetrievedFromCache:[],pageView:[],popState:[],samePage:[],samePageWithHash:[],serverError:[],transitionStart:[],transitionEnd:[],willReplaceContent:[]},this.scrollToElement=null,this.options=void 0,this.plugins=[],this.transition={},this.cache=void 0,this.currentPageUrl=n(),this.delegatedListeners={},this.boundPopStateHandler=void 0,this.loadPage=H,this.leavePage=T,this.renderPage=M,this.replaceContent=R,this.enterPage=w,this.triggerEvent=N,this.delegateEvent=o,this.on=_,this.off=A,this.updateTransition=W,this.getAnimationPromises=k,this.getPageData=C,this.fetchPage=L,this.getAnchorElement=E,this.log=()=>{},this.use=x,this.unuse=q,this.findPlugin=D,this.getCurrentUrl=n,this.cleanupAnimationClasses=v,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!(null==n||!n.closest("[data-no-swup]"))},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>{var e;return"swup"!==(null==(e=t.state)?void 0:e.source)}},this.options={...this.defaults,...t},this.boundPopStateHandler=this.popStateHandler.bind(this),this.cache=new f(this),this.enable()}enable(){"undefined"!=typeof Promise?(this.delegatedListeners.click=o(this.options.linkSelector,"click",this.linkClickHandler.bind(this)),window.addEventListener("popstate",this.boundPopStateHandler),g(document.documentElement,this.options.containers),this.options.plugins.forEach(t=>this.use(t)),s(),this.triggerEvent("enabled"),document.documentElement.classList.add("swup-enabled"),this.triggerEvent("pageView")):console.warn("Promise is not supported")}destroy(){this.delegatedListeners.click.destroy(),window.removeEventListener("popstate",this.boundPopStateHandler),this.cache.empty(),this.options.plugins.forEach(t=>{this.unuse(t)}),a("[data-swup]").forEach(t=>{t.removeAttribute("data-swup")}),this.off(),this.triggerEvent("disabled"),document.documentElement.classList.remove("swup-enabled")}shouldIgnoreVisit(t,e){let{el:n}=void 0===e?{}:e;const{origin:i}=p.fromUrl(t);return i!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(t,{el:n})}linkClickHandler(t){const e=t.delegateTarget,{href:i,url:s,hash:o}=p.fromElement(e);if(this.shouldIgnoreVisit(i,{el:e}))return;if(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return void this.triggerEvent("openPageInNewTab",t);if(0!==t.button)return;if(this.triggerEvent("clickLink",t),t.preventDefault(),!s||s===n())return void this.handleLinkToSamePage(s,o,t);if(this.isSameResolvedUrl(s,n()))return;this.scrollToElement=o||null;const r=e.getAttribute("data-swup-transition")||void 0;this.loadPage({url:s,customTransition:r},null)}handleLinkToSamePage(t,e,n){if(e){if(this.triggerEvent("samePageWithHash",n),!E(e))return console.warn("Element for offset not found (#"+e+")");s(t+e)}else this.triggerEvent("samePage",n)}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(t){var e,i;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.currentPageUrl))return;const{url:s,hash:o}=p.fromUrl(null!=(e=null==(i=t.state)?void 0:i.url)?e:location.href);o?this.scrollToElement=o:t.preventDefault(),this.triggerEvent("popState",t),this.options.animateHistoryBrowsing||(document.documentElement.classList.remove("is-animating"),v()),this.loadPage({url:s},t)}resolveUrl(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}isSameResolvedUrl(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}}export{p as Location,e as classify,v as cleanupAnimationClasses,i as createHistoryRecord,I as default,o as delegateEvent,u as escapeCssIdentifier,d as fetch,n as getCurrentUrl,h as getDataFromHtml,g as markSwupElements,l as nextTick,r as query,a as queryAll,c as toMs,s as updateHistoryRecord};
|
|
1
|
+
import t from"delegate-it";const e=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},i=function(t,e){void 0===e&&(e={});const i={url:t=t||n({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(i,"",t)},s=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||n({hash:!0});const i={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(i,"",t)},o=function(e,n,i,s){let{base:o=document,...r}=void 0===s?{}:s;const a=t(o,e,n,i,r);return{destroy:()=>a.destroy()}},r=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},a=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},l=t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})},u=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,c=t=>1e3*Number(t.slice(0,-1).replace(",",".")),h=(t,e)=>{var n,i;let s=document.createElement("html");s.innerHTML=t;let o=[];e.forEach(t=>{if(null==r(t,s))return console.warn("[swup] Container "+t+" not found on page."),null;a(t).length!==a(t,s).length&&console.warn("[swup] Mismatched number of containers found on new page."),a(t).forEach((e,n)=>{a(t,s)[n].setAttribute("data-swup",String(o.length)),o.push(a(t,s)[n].outerHTML)})});const l=(null==(n=r("title",s))?void 0:n.innerText)||"",u=null==(i=r("body",s))?void 0:i.className;return s.innerHTML="",s=null,{title:l,pageClass:u,blocks:o,originalContent:t}},d=(t,e)=>{const n={url:window.location.pathname+window.location.search,method:"GET",data:null,headers:{}},{url:i,method:s,headers:o,data:r}={...n,...t},a=new XMLHttpRequest;return a.onreadystatechange=function(){4===a.readyState&&e(a)},a.open(s,i,!0),Object.entries(o).forEach(t=>{let[e,n]=t;a.setRequestHeader(e,n)}),a.send(r),a};class p extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href");return new p(e)}static fromUrl(t){return new p(t)}}const g=(t,e)=>{let n=0;e.forEach(e=>{null==r(e,t)?console.warn("[swup] Container "+e+" not found on page."):a(e).forEach((i,s)=>{a(e,t)[s].setAttribute("data-swup",String(n)),n++})})},m=t=>/^to-/.test(t)||["is-changing","is-rendering","is-popstate"].includes(t),v=()=>{const t=document.documentElement.className.split(" ").filter(m);document.documentElement.classList.remove(...t)};class f{constructor(t){this.pages={},this.last=null,this.swup=void 0,this.swup=t}getCacheUrl(t){return this.swup.resolveUrl(p.fromUrl(t).url)}cacheUrl(t){t.url=this.getCacheUrl(t.url),t.url in this.pages==0&&(this.pages[t.url]=t),t.responseURL=this.getCacheUrl(t.responseURL),this.last=this.pages[t.url],this.swup.log("Cache ("+Object.keys(this.pages).length+")",this.pages)}getPage(t){return t=this.getCacheUrl(t),this.pages[t]}getCurrentPage(){return this.getPage(n())}exists(t){return(t=this.getCacheUrl(t))in this.pages}empty(){this.pages={},this.last=null,this.swup.log("Cache cleared")}remove(t){delete this.pages[this.getCacheUrl(t)]}}const w=function(t){let{popstate:e,skipTransition:n}=t;if(n)return this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses(),[Promise.resolve()];l(()=>{this.triggerEvent("animationInStart"),document.documentElement.classList.remove("is-animating")});const i=this.getAnimationPromises("in");return Promise.all(i).then(()=>{this.triggerEvent("animationInDone"),this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses()}),i},E=t=>t?("#"===t.charAt(0)&&(t=t.substring(1)),t=decodeURIComponent(t),t=u(t),r("#"+t)||r("a[name='"+t+"']")):null;let P="transition",S="transitionend",b="animation",U="animationend";function k(t){const e=this.options.animationSelector;if(!1===e)return[Promise.resolve()];const n=a(e,document.body);return n.length?n.map(t=>function(t,e,n){void 0===n&&(n=null);const{type:i,timeout:s,propCount:o}=function(t,e){void 0===e&&(e=null);const n=window.getComputedStyle(t),i=P+"Duration",s=b+"Delay",o=b+"Duration",r=n[P+"Delay"].split(", "),a=(n[i]||"").split(", "),l=y(r,a),u=(n[s]||"").split(", "),c=(n[o]||"").split(", "),h=y(u,c);let d="",p=0,g=0;return"transition"===e?l>0&&(d="transition",p=l,g=a.length):"animation"===e?h>0&&(d="animation",p=h,g=c.length):(p=Math.max(l,h),d=p>0?l>h?"transition":"animation":null,g=d?"transition"===d?a.length:c.length:0),{type:d,timeout:p,propCount:g}}(t,n);return i&&s?new Promise(e=>{const n="transition"===i?S:U,r=performance.now();let a=0;const l=()=>{t.removeEventListener(n,u),e()},u=e=>{if(e.target===t){if(!(t=>!!t.elapsedTime)(e))throw new Error("Not a transition or animation event.");(performance.now()-r)/1e3<e.elapsedTime||++a>=o&&l()}};setTimeout(()=>{a<o&&l()},s+1),t.addEventListener(n,u)}):(console.warn("[swup] No CSS transition duration defined for element of selector "+e),Promise.resolve())}(t,e)):(console.warn("[swup] No animated elements found by selector "+e),[Promise.resolve()])}function y(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>c(e)+c(t[n])))}void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(P="WebkitTransition",S="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(b="WebkitAnimation",U="webkitAnimationEnd");const C=function(t){const e=h(t.responseText,this.options.containers);return e?{...e,responseURL:t.responseURL||window.location.href}:(console.warn("[swup] Received page is invalid."),null)};function L(t){const e=this.options.requestHeaders,{url:n}=t;return this.cache.exists(n)?(this.triggerEvent("pageRetrievedFromCache"),Promise.resolve(this.cache.getPage(n))):new Promise((i,s)=>{d({...t,headers:e},t=>{if(500===t.status)return this.triggerEvent("serverError"),void s(n);const e=this.getPageData(t);if(!e||!e.blocks.length)return void s(n);const o={...e,url:n};this.cache.cacheUrl(o),this.triggerEvent("pageLoaded"),i(o)})})}const T=function(t,e){let{popstate:n,skipTransition:i}=void 0===e?{popstate:null}:e;if(i)return this.triggerEvent("animationSkipped"),[Promise.resolve()];this.triggerEvent("animationOutStart"),document.documentElement.classList.add("is-changing","is-leaving","is-animating"),n&&document.documentElement.classList.add("is-popstate");const s=this.getAnimationPromises("out");return Promise.all(s).then(()=>{this.triggerEvent("animationOutDone")}),s},H=function(t,s){const{url:o,customTransition:r}=t,a=!(!s||this.options.animateHistoryBrowsing);this.triggerEvent("transitionStart",s||void 0),this.updateTransition(n(),o,r),null!=r&&document.documentElement.classList.add("to-"+e(r));const l=this.leavePage(t,{popstate:s,skipTransition:a});s||i(o+(this.scrollToElement||"")),this.currentPageUrl=n();const u=this.fetchPage(t);Promise.all([u,...l]).then(t=>{let[e]=t;this.renderPage(e,{popstate:s,skipTransition:a})}).catch(t=>{void 0!==t&&(this.options.skipPopStateHandling=()=>(window.location=t,!0),history.go(-1))})},R=function(t){let{blocks:e,title:n}=t;return e.forEach((t,e)=>{document.body.querySelector('[data-swup="'+e+'"]').outerHTML=t}),document.title=n,Promise.resolve()},A=function(t,e){t&&e?this._handlers[t].includes(e)?this._handlers[t]=this._handlers[t].filter(t=>t!==e):console.warn("Handler for event '"+t+"' not found."):t?this._handlers[t]=[]:Object.keys(this._handlers).forEach(t=>{this._handlers[t]=[]})},_=function(t,e){this._handlers[t]?this._handlers[t].push(e):console.warn("Unsupported event "+t+".")},x=function(t){var e;if(null==(e=t)?void 0:e.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function q(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function D(t){return this.plugins.find(e=>e===t||e.name===t)}const M=function(t,e){let{popstate:i,skipTransition:o}=void 0===e?{popstate:null}:e;if(document.documentElement.classList.remove("is-leaving"),!this.isSameResolvedUrl(n(),t.url))return;const{url:r}=p.fromUrl(t.responseURL);this.isSameResolvedUrl(n(),r)||(this.cache.cacheUrl({...t,url:r}),this.currentPageUrl=n(),s(r)),o||document.documentElement.classList.add("is-rendering"),this.triggerEvent("willReplaceContent",i||void 0),this.replaceContent(t).then(()=>{this.triggerEvent("contentReplaced",i||void 0),this.triggerEvent("pageView",i||void 0),this.options.cache||this.cache.empty(),this.enterPage({popstate:i||void 0,skipTransition:o}),this.scrollToElement=null})},N=function(t,e){this._handlers[t].forEach(t=>{try{t(e)}catch(t){console.error(t)}});const n=new CustomEvent("swup:"+t,{detail:t});document.dispatchEvent(n)},W=function(t,e,n){this.transition={from:t,to:e,custom:n}};class I{constructor(t){void 0===t&&(t={}),this.version="3.0.0",this._handlers={animationInDone:[],animationInStart:[],animationOutDone:[],animationOutStart:[],animationSkipped:[],clickLink:[],contentReplaced:[],disabled:[],enabled:[],openPageInNewTab:[],pageLoaded:[],pageRetrievedFromCache:[],pageView:[],popState:[],samePage:[],samePageWithHash:[],serverError:[],transitionStart:[],transitionEnd:[],willReplaceContent:[]},this.scrollToElement=null,this.options=void 0,this.plugins=[],this.transition={},this.cache=void 0,this.currentPageUrl=n(),this.delegatedListeners={},this.boundPopStateHandler=void 0,this.loadPage=H,this.leavePage=T,this.renderPage=M,this.replaceContent=R,this.enterPage=w,this.triggerEvent=N,this.delegateEvent=o,this.on=_,this.off=A,this.updateTransition=W,this.getAnimationPromises=k,this.getPageData=C,this.fetchPage=L,this.getAnchorElement=E,this.log=()=>{},this.use=x,this.unuse=q,this.findPlugin=D,this.getCurrentUrl=n,this.cleanupAnimationClasses=v,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!(null==n||!n.closest("[data-no-swup]"))},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>{var e;return"swup"!==(null==(e=t.state)?void 0:e.source)}},this.options={...this.defaults,...t},this.boundPopStateHandler=this.popStateHandler.bind(this),this.cache=new f(this),this.enable()}enable(){"undefined"!=typeof Promise?(this.delegatedListeners.click=o(this.options.linkSelector,"click",this.linkClickHandler.bind(this)),window.addEventListener("popstate",this.boundPopStateHandler),g(document.documentElement,this.options.containers),this.options.plugins.forEach(t=>this.use(t)),s(),this.triggerEvent("enabled"),document.documentElement.classList.add("swup-enabled"),this.triggerEvent("pageView")):console.warn("Promise is not supported")}destroy(){this.delegatedListeners.click.destroy(),window.removeEventListener("popstate",this.boundPopStateHandler),this.cache.empty(),this.options.plugins.forEach(t=>{this.unuse(t)}),a("[data-swup]").forEach(t=>{t.removeAttribute("data-swup")}),this.off(),this.triggerEvent("disabled"),document.documentElement.classList.remove("swup-enabled")}shouldIgnoreVisit(t,e){let{el:n}=void 0===e?{}:e;const{origin:i}=p.fromUrl(t);return i!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(t,{el:n})}linkClickHandler(t){const e=t.delegateTarget,{href:i,url:s,hash:o}=p.fromElement(e);if(this.shouldIgnoreVisit(i,{el:e}))return;if(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return void this.triggerEvent("openPageInNewTab",t);if(0!==t.button)return;if(this.triggerEvent("clickLink",t),t.preventDefault(),!s||s===n())return void this.handleLinkToSamePage(s,o,t);if(this.isSameResolvedUrl(s,n()))return;this.scrollToElement=o||null;const r=e.getAttribute("data-swup-transition")||void 0;this.loadPage({url:s,customTransition:r},null)}handleLinkToSamePage(t,e,n){if(e){if(this.triggerEvent("samePageWithHash",n),!E(e))return console.warn("Element for offset not found (#"+e+")");s(t+e)}else this.triggerEvent("samePage",n)}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(t){var e,i;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.currentPageUrl))return;const{url:s,hash:o}=p.fromUrl(null!=(e=null==(i=t.state)?void 0:i.url)?e:location.href);o?this.scrollToElement=o:t.preventDefault(),this.triggerEvent("popState",t),this.options.animateHistoryBrowsing||(document.documentElement.classList.remove("is-animating"),v()),this.loadPage({url:s},t)}resolveUrl(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}isSameResolvedUrl(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}}export{p as Location,e as classify,v as cleanupAnimationClasses,i as createHistoryRecord,I as default,o as delegateEvent,u as escapeCssIdentifier,d as fetch,n as getCurrentUrl,h as getDataFromHtml,g as markSwupElements,l as nextTick,r as query,a as queryAll,c as toMs,s as updateHistoryRecord};
|
|
2
2
|
//# sourceMappingURL=Swup.module.js.map
|