diff --git a/.changeset/sad-teams-end.md b/.changeset/sad-teams-end.md new file mode 100644 index 000000000000..56e4d7e07d69 --- /dev/null +++ b/.changeset/sad-teams-end.md @@ -0,0 +1,5 @@ +--- +'astro': major +--- + +Deprecates exposed `astro:transitions` internals - ([v6 upgrade guidance](https://deploy-preview-12322--astro-docs-2.netlify.app/en/guides/upgrade-to/v6/#deprecated-exposed-astrotransitions-internals)) diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts index 43c263f9f1fa..ed13c5ac3fa4 100644 --- a/packages/astro/client.d.ts +++ b/packages/astro/client.d.ts @@ -1,8 +1,10 @@ /// -/// + /// +/// /// /// +/// interface ImportMetaEnv { // TODO: remove in Astro 7 @@ -119,46 +121,6 @@ declare module '*.svg' { export default Component; } -declare module 'astro:transitions' { - type TransitionModule = typeof import('./dist/virtual-modules/transitions.js'); - export const slide: TransitionModule['slide']; - export const fade: TransitionModule['fade']; - export const createAnimationScope: TransitionModule['createAnimationScope']; - - type ClientRouterModule = typeof import('./components/ClientRouter.astro'); - export const ClientRouter: ClientRouterModule['default']; -} - -declare module 'astro:transitions/client' { - type TransitionRouterModule = typeof import('./dist/virtual-modules/transitions-router.js'); - export const navigate: TransitionRouterModule['navigate']; - export const supportsViewTransitions: TransitionRouterModule['supportsViewTransitions']; - export const getFallback: TransitionRouterModule['getFallback']; - export const transitionEnabledOnThisPage: TransitionRouterModule['transitionEnabledOnThisPage']; - - export type Fallback = import('./dist/virtual-modules/transitions-types.js').Fallback; - export type Direction = import('./dist/virtual-modules/transitions-types.ts').Direction; - // biome-ignore format: bug - export type NavigationTypeString = import('./dist/virtual-modules/transitions-types.js').NavigationTypeString; - export type Options = import('./dist/virtual-modules/transitions-types.js').Options; - - type EventModule = typeof import('./dist/virtual-modules/transitions-events.js'); - export const TRANSITION_BEFORE_PREPARATION: EventModule['TRANSITION_BEFORE_PREPARATION']; - export const TRANSITION_AFTER_PREPARATION: EventModule['TRANSITION_AFTER_PREPARATION']; - export const TRANSITION_BEFORE_SWAP: EventModule['TRANSITION_BEFORE_SWAP']; - export const TRANSITION_AFTER_SWAP: EventModule['TRANSITION_AFTER_SWAP']; - export const TRANSITION_PAGE_LOAD: EventModule['TRANSITION_PAGE_LOAD']; - // biome-ignore format: bug - export type TransitionBeforePreparationEvent = import('./dist/virtual-modules/transitions-events.js').TransitionBeforePreparationEvent; - // biome-ignore format: bug - export type TransitionBeforeSwapEvent = import('./dist/virtual-modules/transitions-events.js').TransitionBeforeSwapEvent; - export const isTransitionBeforePreparationEvent: EventModule['isTransitionBeforePreparationEvent']; - export const isTransitionBeforeSwapEvent: EventModule['isTransitionBeforeSwapEvent']; - // biome-ignore format: bug - type TransitionSwapFunctionModule = typeof import('./dist/virtual-modules/transitions-swap-functions.js'); - export const swapFunctions: TransitionSwapFunctionModule['swapFunctions']; -} - declare module 'astro:prefetch' { export { prefetch, PrefetchOptions } from 'astro/virtual-modules/prefetch.js'; } diff --git a/packages/astro/src/runtime/server/transition.ts b/packages/astro/src/runtime/server/transition.ts index d20e5816b038..21cf31faa9fd 100644 --- a/packages/astro/src/runtime/server/transition.ts +++ b/packages/astro/src/runtime/server/transition.ts @@ -115,6 +115,7 @@ export function renderTransition( return scope; } +/** @deprecated This will be removed in Astro 7 */ export function createAnimationScope( transitionName: string, animations: Record, diff --git a/packages/astro/src/transitions/events.ts b/packages/astro/src/transitions/events.ts index 2d2b131cffeb..b4ef0c6d0a23 100644 --- a/packages/astro/src/transitions/events.ts +++ b/packages/astro/src/transitions/events.ts @@ -2,10 +2,15 @@ import { updateScrollPosition } from './router.js'; import { swap } from './swap-functions.js'; import type { Direction, NavigationTypeString } from './types.js'; +/** @deprecated This will be removed in Astro 7 */ export const TRANSITION_BEFORE_PREPARATION = 'astro:before-preparation'; +/** @deprecated This will be removed in Astro 7 */ export const TRANSITION_AFTER_PREPARATION = 'astro:after-preparation'; +/** @deprecated This will be removed in Astro 7 */ export const TRANSITION_BEFORE_SWAP = 'astro:before-swap'; +/** @deprecated This will be removed in Astro 7 */ export const TRANSITION_AFTER_SWAP = 'astro:after-swap'; +/** @deprecated This will be removed in Astro 7 */ export const TRANSITION_PAGE_LOAD = 'astro:page-load'; type Events = @@ -67,6 +72,7 @@ class BeforeEvent extends Event { * TransitionBeforePreparationEvent */ +/** @deprecated This will be removed in Astro 7 */ export const isTransitionBeforePreparationEvent = ( value: any, ): value is TransitionBeforePreparationEvent => value.type === TRANSITION_BEFORE_PREPARATION; @@ -109,7 +115,7 @@ export class TransitionBeforePreparationEvent extends BeforeEvent { /* * TransitionBeforeSwapEvent */ - +/** @deprecated This will be removed in Astro 7 */ export const isTransitionBeforeSwapEvent = (value: any): value is TransitionBeforeSwapEvent => value.type === TRANSITION_BEFORE_SWAP; export class TransitionBeforeSwapEvent extends BeforeEvent { diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index faeb4b4fb8bd..028fed6affbd 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -1,6 +1,12 @@ import { internalFetchHeaders } from 'virtual:astro:adapter-config/client'; import type { TransitionBeforePreparationEvent } from './events.js'; -import { doPreparation, doSwap, TRANSITION_AFTER_SWAP } from './events.js'; +import { + doPreparation, + doSwap, + TRANSITION_AFTER_SWAP, + onPageLoad, + triggerEvent, +} from './events.js'; import { detectScriptExecuted } from './swap-functions.js'; import type { Direction, Fallback, Options } from './types.js'; @@ -9,7 +15,6 @@ type State = { scrollX: number; scrollY: number; }; -type Events = 'astro:page-load' | 'astro:after-swap'; type Navigation = { controller: AbortController }; type Transition = { // The view transitions object (API and simulation) @@ -47,8 +52,6 @@ let mostRecentTransition: Transition | undefined; // This variable tells us where we came from let originalLocation: URL; -const triggerEvent = (name: Events) => document.dispatchEvent(new Event(name)); -const onPageLoad = () => triggerEvent('astro:page-load'); const announce = () => { let div = document.createElement('div'); div.setAttribute('aria-live', 'assertive'); diff --git a/packages/astro/types/transitions.d.ts b/packages/astro/types/transitions.d.ts new file mode 100644 index 000000000000..a5b3f20fa62f --- /dev/null +++ b/packages/astro/types/transitions.d.ts @@ -0,0 +1,25 @@ +declare module 'astro:transitions' { + export * from 'astro/virtual-modules/transitions.js'; + export { default as ClientRouter } from 'astro/components/ClientRouter.astro'; +} + +declare module 'astro:transitions/client' { + export { + navigate, + supportsViewTransitions, + transitionEnabledOnThisPage, + } from 'astro/virtual-modules/transitions-router.js'; + export * from 'astro/virtual-modules/transitions-types.js'; + export { + TRANSITION_BEFORE_PREPARATION, + isTransitionBeforePreparationEvent, + TransitionBeforePreparationEvent, + TRANSITION_AFTER_PREPARATION, + TRANSITION_BEFORE_SWAP, + isTransitionBeforeSwapEvent, + TransitionBeforeSwapEvent, + TRANSITION_AFTER_SWAP, + TRANSITION_PAGE_LOAD, + } from 'astro/virtual-modules/transitions-events.js'; + export { swapFunctions } from 'astro/virtual-modules/transitions-swap-functions.js'; +}