diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:10:59 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:41:44 +0800 |
| commit | fc87c009806dcc98867f6b58efe29b042aa01dee (patch) | |
| tree | 8f59b3f4a5b66e9dfef2d40c8d318e258a521228 /node_modules/swup/src/helpers | |
| parent | 3336b2356ee6152d9c6ae59bd9b87ccbc0958407 (diff) | |
node: updatemain
Diffstat (limited to 'node_modules/swup/src/helpers')
| -rwxr-xr-x | node_modules/swup/src/helpers/Location.ts | 38 | ||||
| -rwxr-xr-x | node_modules/swup/src/helpers/classify.ts | 12 | ||||
| -rwxr-xr-x | node_modules/swup/src/helpers/delegateEvent.ts | 27 | ||||
| -rwxr-xr-x | node_modules/swup/src/helpers/getCurrentUrl.ts | 4 | ||||
| -rwxr-xr-x | node_modules/swup/src/helpers/history.ts | 37 | ||||
| -rw-r--r-- | node_modules/swup/src/helpers/matchPath.ts | 23 |
6 files changed, 0 insertions, 141 deletions
diff --git a/node_modules/swup/src/helpers/Location.ts b/node_modules/swup/src/helpers/Location.ts deleted file mode 100755 index aca9d6b6..00000000 --- a/node_modules/swup/src/helpers/Location.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * A helper for creating a Location from either an element - * or a URL object/string - * - */ -export class Location extends URL { - constructor(url: URL | string, base: string = document.baseURI) { - super(url.toString(), base); - // Fix Safari bug with extending native classes - Object.setPrototypeOf(this, Location.prototype); - } - - /** - * The full local path including query params. - */ - get url(): string { - return this.pathname + this.search; - } - - /** - * Instantiate a Location from an element's href attribute - * @param el - * @returns new Location instance - */ - static fromElement(el: Element): Location { - const href = el.getAttribute('href') || el.getAttribute('xlink:href') || ''; - return new Location(href); - } - - /** - * Instantiate a Location from a URL object or string - * @param url - * @returns new Location instance - */ - static fromUrl(url: URL | string): Location { - return new Location(url); - } -} diff --git a/node_modules/swup/src/helpers/classify.ts b/node_modules/swup/src/helpers/classify.ts deleted file mode 100755 index 3d9ecec6..00000000 --- a/node_modules/swup/src/helpers/classify.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** Turn a string into a slug by lowercasing and replacing whitespace. */ -export const classify = (text: string, fallback?: string): string => { - const output = String(text) - .toLowerCase() - // .normalize('NFD') // split an accented letter in the base letter and the acent - // .replace(/[\u0300-\u036f]/g, '') // remove all previously split accents - .replace(/[\s/_.]+/g, '-') // replace spaces and _./ with '-' - .replace(/[^\w-]+/g, '') // remove all non-word chars - .replace(/--+/g, '-') // replace repeating '-' with single '-' - .replace(/^-+|-+$/g, ''); // trim '-' from edges - return output || fallback || ''; -}; diff --git a/node_modules/swup/src/helpers/delegateEvent.ts b/node_modules/swup/src/helpers/delegateEvent.ts deleted file mode 100755 index eec44f50..00000000 --- a/node_modules/swup/src/helpers/delegateEvent.ts +++ /dev/null @@ -1,27 +0,0 @@ -import delegate, { - type DelegateEventHandler, - type DelegateOptions, - type EventType -} from 'delegate-it'; -import type { ParseSelector } from 'typed-query-selector/parser.js'; - -export type DelegateEventUnsubscribe = { - destroy: () => void; -}; - -/** Register a delegated event listener. */ -export const delegateEvent = < - Selector extends string, - TElement extends Element = ParseSelector<Selector, HTMLElement>, - TEvent extends EventType = EventType ->( - selector: Selector, - type: TEvent, - callback: DelegateEventHandler<GlobalEventHandlersEventMap[TEvent], TElement>, - options?: DelegateOptions -): DelegateEventUnsubscribe => { - const controller = new AbortController(); - options = { ...options, signal: controller.signal }; - delegate<Selector, TElement, TEvent>(selector, type, callback, options); - return { destroy: () => controller.abort() }; -}; diff --git a/node_modules/swup/src/helpers/getCurrentUrl.ts b/node_modules/swup/src/helpers/getCurrentUrl.ts deleted file mode 100755 index ab0f0d57..00000000 --- a/node_modules/swup/src/helpers/getCurrentUrl.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** Get the current page URL: path name + query params. Optionally including hash. */ -export const getCurrentUrl = ({ hash }: { hash?: boolean } = {}): string => { - return window.location.pathname + window.location.search + (hash ? window.location.hash : ''); -}; diff --git a/node_modules/swup/src/helpers/history.ts b/node_modules/swup/src/helpers/history.ts deleted file mode 100755 index e7ea2f6c..00000000 --- a/node_modules/swup/src/helpers/history.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCurrentUrl } from './getCurrentUrl.js'; - -export interface HistoryState { - url: string; - source: 'swup'; - random: number; - index?: number; - [key: string]: unknown; -} - -type HistoryData = Record<string, unknown>; - -/** Create a new history record with a custom swup identifier. */ -export const createHistoryRecord = (url: string, data: HistoryData = {}): void => { - url = url || getCurrentUrl({ hash: true }); - const state: HistoryState = { - url, - random: Math.random(), - source: 'swup', - ...data - }; - window.history.pushState(state, '', url); -}; - -/** Update the current history record with a custom swup identifier. */ -export const updateHistoryRecord = (url: string | null = null, data: HistoryData = {}): void => { - url = url || getCurrentUrl({ hash: true }); - const currentState = (window.history.state as HistoryState) || {}; - const state: HistoryState = { - ...currentState, - url, - random: Math.random(), - source: 'swup', - ...data - }; - window.history.replaceState(state, '', url); -}; diff --git a/node_modules/swup/src/helpers/matchPath.ts b/node_modules/swup/src/helpers/matchPath.ts deleted file mode 100644 index e1332911..00000000 --- a/node_modules/swup/src/helpers/matchPath.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { match } from 'path-to-regexp'; - -import type { - Path, - ParseOptions, - TokensToRegexpOptions, - RegexpToFunctionOptions, - MatchFunction -} from 'path-to-regexp'; - -export { type Path }; - -/** Create a match function from a path pattern that checks if a URLs matches it. */ -export const matchPath = <P extends object = object>( - path: Path, - options?: ParseOptions & TokensToRegexpOptions & RegexpToFunctionOptions -): MatchFunction<P> => { - try { - return match<P>(path, options); - } catch (error) { - throw new Error(`[swup] Error parsing path "${String(path)}":\n${String(error)}`); - } -}; |
