### Install and Initialize Taxi Core
Source: https://context7.com/craftedbygc/taxi/llms.txt
Install Taxi.js via npm or yarn and create a new Core instance. Ensure your HTML structure includes data-taxi and data-taxi-view attributes.
```javascript
// Install
// npm i @unseenco/taxi
import { Core } from '@unseenco/taxi'
const taxi = new Core()
```
--------------------------------
### Install Taxi.js with npm
Source: https://github.com/craftedbygc/taxi/blob/main/docs/how-to-use.md
Use npm to add the Taxi.js package to your project dependencies.
```bash
npm i @unseenco/taxi
```
--------------------------------
### Install Taxi.js with pnpm
Source: https://github.com/craftedbygc/taxi/blob/main/docs/how-to-use.md
Use pnpm to add the Taxi.js package to your project dependencies.
```bash
pnpm add @unseenco/taxi
```
--------------------------------
### Install Taxi.js with yarn
Source: https://github.com/craftedbygc/taxi/blob/main/docs/how-to-use.md
Use yarn to add the Taxi.js package to your project dependencies.
```bash
yarn add @unseenco/taxi
```
--------------------------------
### HTML Example for Renderer Selection
Source: https://context7.com/craftedbygc/taxi/llms.txt
Pages can specify which renderer to use via the data-taxi-view attribute. If the attribute is empty, the default renderer is used. If it has a value (e.g., 'blog'), the corresponding registered renderer is used.
```html
...
...
```
--------------------------------
### Configuring Taxi.js Links Option
Source: https://github.com/craftedbygc/taxi/blob/main/docs/how-to-use.md
Customize which links are handled by Taxi.js using a CSS selector. This example shows the default configuration.
```javascript
const taxi = new Core({
links: 'a:not([target]):not([href^=\#]):not([data-taxi-ignore])'
})
```
--------------------------------
### Custom reloadJsFilter with Script Source Matching
Source: https://github.com/craftedbygc/taxi/blob/main/docs/reloading-js.md
Example of a custom `reloadJsFilter` callback that reloads scripts based on the `data-taxi-reload` attribute or if the script's source URL matches a specific pattern.
```javascript
import { Core } from '@unseenco/taxi'
const taxi = new Core({
reloadJsFilter: (element) => element.dataset.taxiReload !== undefined || element.src?.match('myscript.js')
})
```
--------------------------------
### Initial Load Method for First Visit
Source: https://github.com/craftedbygc/taxi/blob/main/docs/renderers.md
Implement the `initialLoad` method within your custom renderer to execute code only on the user's first visit to the site. This is suitable for setting up persistent components or one-time initializations.
```javascript
import { Renderer } from '@unseenco/taxi';
export default class CustomRenderer extends Renderer {
initialLoad() {
// run code that should only happen once for your site
this.onEnter()
this.onEnterCompleted()
}
// rest of your methods
}
```
--------------------------------
### Using Taxi.js via CDN
Source: https://github.com/craftedbygc/taxi/blob/main/docs/how-to-use.md
Include Taxi.js from a CDN and initialize it. Note the lowercase 'taxi' export.
```html
...
```
--------------------------------
### Preload URLs and Assets with preload()
Source: https://context7.com/craftedbygc/taxi/llms.txt
Fetch a URL and cache its content ahead of user interaction. Optionally preload linked assets like images. Handles success and failure with Promises.
```javascript
/**
* preload(url: string, preloadAssets?: boolean = false): Promise
*/
// Preload HTML only
taxi.preload('/heavy-page')
// Preload HTML + all linked assets
taxi.preload('/gallery', true)
// Handle success / failure
taxi.preload('/might-404')
.then(() => console.log('Cached!'))
.catch(err => console.warn('Preload failed:', err))
```
--------------------------------
### Initialize Taxi.js Core
Source: https://github.com/craftedbygc/taxi/blob/main/docs/how-to-use.md
Import and create a new instance of the Taxi.js Core. Supports named or namespace imports.
```javascript
import { Core } from '@unseenco/taxi'
const taxi = new Core()
// or if you prefer
import * as Taxi from '@unseenco/taxi'
const taxi = new Taxi.Core()
```
--------------------------------
### navigateTo
Source: https://context7.com/craftedbygc/taxi/llms.txt
Programmatically navigate to a URL, optionally specifying which transition to use. Returns a Promise that resolves when the full transition lifecycle completes.
```APIDOC
## navigateTo
### Description
Programmatically navigate to a URL, optionally specifying which transition to use. Returns a Promise that resolves when the full transition lifecycle completes.
### Method Signature
`navigateTo(url: string, transition?: string = false): Promise`
### Examples
```js
// Navigate using the router / default transition
taxi.navigateTo('/contact')
// Navigate with an explicit transition
taxi.navigateTo('/contact', 'slide')
.then(() => {
console.log('Navigation complete')
analytics.track('page_view', { url: '/contact' })
})
.catch(err => {
// Rejected when allowInterruption is false and a transition is in progress
console.warn(err.message) // "A transition is currently in progress"
})
```
```
--------------------------------
### preload()
Source: https://github.com/craftedbygc/taxi/blob/main/docs/api-events.md
Prefetch the provided URL and add it to the cache ahead of any user navigation. You can optionally preload assets on the target URL as well.
```APIDOC
## preload()
### Description
Prefetch the provided URL and add it to the cache ahead of any user navigation.
You can pass a second argument to indicate you want to preload the assets on the target URL as well (images, media, etc).
### Method Signature
`preload( url: string, preloadAssets?: boolean = false): Promise`
### Examples
```js
taxi.preload('/path/to/preload')
taxi.preload('/path/to/preload', true)
taxi.preload('/path/to/404')
.then(() => console.log('success!'))
.catch(err => console.warn(err))
```
```
--------------------------------
### Preload URL Content with preload()
Source: https://github.com/craftedbygc/taxi/blob/main/docs/api-events.md
Use `preload` to prefetch and cache the content of a given URL. This can improve performance by having content ready before user navigation. An optional boolean argument can be passed to also preload associated assets.
```javascript
taxi.preload('/path/to/preload')
```
```javascript
taxi.preload('/path/to/preload', true)
```
```javascript
taxi.preload('/path/to/404')
.then(() => console.log('success!'))
.catch(err => console.warn(err))
```
--------------------------------
### navigateTo()
Source: https://github.com/craftedbygc/taxi/blob/main/docs/api-events.md
Perform a manual navigation to the provided URL. If a transition name is not provided, Taxi will try to find a match in the RouteStore, otherwise the default transition will be used.
```APIDOC
## navigateTo()
### Description
Perform a manual navigation to the provided URL.
If a `transition` name is not provided then Taxi will try and find a match in the RouteStore, otherwise the default transition will be used.
### Method Signature
`navigateTo(url: string, transition?: string = false): Promise`
### Examples
```js
taxi.navigateTo('/contact')
taxi.navigateTo('/contact', 'explcitTransition').then(() => { ... })
```
```
--------------------------------
### Define URL Routes with Transitions
Source: https://github.com/craftedbygc/taxi/blob/main/docs/routing.md
Use the addRoute method to define routing rules. Provide regex for the current URL, the new URL, and the transition to use if matched. Regex is automatically wrapped with ^ and $.
```javascript
taxi.addRoute('/blog/.*', '', 'blogToHome')
```
```javascript
taxi.addRoute('', '.*', 'fromHome')
```
```javascript
taxi.addRoute('/about', '/contact', 'aboutToContact')
```
--------------------------------
### addRoute
Source: https://context7.com/craftedbygc/taxi/llms.txt
Register URL-pattern-based rules to automatically choose a transition depending on where the user is navigating from and to. Patterns are treated as RegExp and automatically wrapped in ^ and $. Register specific routes before catch-all routes.
```APIDOC
## addRoute
### Description
Register URL-pattern-based rules to automatically choose a transition depending on where the user is navigating from and to. Patterns are treated as `RegExp` and automatically wrapped in `^` and `$`. Register specific routes before catch-all routes.
### Method Signature
`addRoute(fromPattern: string, toPattern: string, transitionKey: string): void`
### Examples
```js
// Blog post → homepage
taxi.addRoute('/blog/.*', '', 'blogToHome')
// Homepage → any page
taxi.addRoute('', '.*', 'fromHome')
// Specific page pair
taxi.addRoute('/about', '/contact', 'aboutToContact')
// IMPORTANT: specific rules must come before broad catch-alls
// ✅ correct order
taxi.addRoute('/pages/specific', '', 'something')
taxi.addRoute('/pages/.*', '', 'somethingElse')
// ❌ wrong – catch-all fires first, specific rule never reached
taxi.addRoute('/pages/.*', '', 'somethingElse')
taxi.addRoute('/pages/specific', '', 'something')
```
```
--------------------------------
### CDN Usage for Taxi.js
Source: https://context7.com/craftedbygc/taxi/llms.txt
Use Taxi.js via CDN by including the necessary script tags for the library and its dependencies. Initialize the Core instance after the DOM is ready.
```html
...
```
--------------------------------
### Taxi Core Constructor Options
Source: https://context7.com/craftedbygc/taxi/llms.txt
Configure Taxi.js by passing an options object to the Core constructor. Options control link matching, caching, transitions, renderers, and script/CSS reloading.
```javascript
import { Core, Renderer, Transition } from '@unseenco/taxi'
const taxi = new Core({
// CSS selector for links Taxi should handle (default shown)
links: 'a[href]:not([target]):not([href^=\#]):not([data-taxi-ignore])',
// Remove the old page content after onLeave completes (default: true)
removeOldContent: true,
// Allow new navigations to interrupt an in-progress transition (default: false)
allowInterruption: false,
// Disable HTML caching entirely (default: false)
bypassCache: false,
// Prefetch pages on mouseenter/focus (default: true)
enablePrefetch: true,
// Named renderer classes (key "default" is the fallback)
renderers: {
default: Renderer,
},
// Named transition classes (key "default" is the fallback)
transitions: {
default: Transition,
},
// Only reload
```
--------------------------------
### Default reloadJsFilter Callback
Source: https://github.com/craftedbygc/taxi/blob/main/docs/reloading-js.md
This is the default JavaScript callback function used by Taxi to filter which scripts should be reloaded. It checks if the script element has the `data-taxi-reload` attribute.
```javascript
(element) => element.dataset.taxiReload !== undefined
```
--------------------------------
### Disable CSS Reloading Feature
Source: https://github.com/craftedbygc/taxi/blob/main/docs/reloading-css.md
To disable the CSS reloading feature entirely, set the `reloadCssFilter` option to `false` during Taxi.js initialization.
```javascript
import { Core } from '@unseenco/taxi'
const taxi = new Core({
reloadCssFilter: false
})
```
--------------------------------
### Remove Navigation Event Listeners
Source: https://github.com/craftedbygc/taxi/blob/main/docs/api-events.md
Remove event listeners using `taxi.off()`. You can remove all listeners for a specific event by providing only the event name, or remove a single listener by providing both the event name and the callback function.
```javascript
function foo() {
...
}
taxi.on('NAVIGATE_OUT', foo)
// Remove just the foo listener
taxi.off('NAVIGATE_OUT', foo)
// Remove all listeners
taxi.off('NAVIGATE_IN')
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.