English | ไธญๆๆๆกฃ
A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3, with Web Components support.
- ๐ฏ Comprehensive โ 57 commonly used directives + 57 composable functions
- ๐ Vue 2/3 Compatible โ Single codebase supporting Vue 2.6+ and Vue 3.0+
- ๐งฉ Web Components โ Shadow DOM, SSR safety, and lifecycle hooks support
- ๐ฆ Tree-shakable โ Import only what you need
- ๐ TypeScript โ Full type support with type definitions
- ๐ SSR Friendly โ Multiple directives support SSR out of the box
- โก Zero Dependencies โ Lightweight with minimal bundle size (full bundle โค 20KB)
- ๐ i18n Support โ Built-in 8 languages (EN/ZH/JA/KO/FR/DE/ES/RU)
- ๐ Plugin System โ Extensible plugin architecture for community contributions
# pnpm
pnpm add directix
# npm
npm install directix
# yarn
yarn add directixVue 2.0โ2.6 requires
@vue/composition-api; Vue 2.7+ has built-in support with no extra dependencies.
<!-- Vue 3 -->
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://unpkg.com/directix/dist/index.iife.min.js"></script>
<!-- Vue 2.7+ -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/directix/dist/index.iife.min.js"></script>// Vue 3
import { createApp } from 'vue'
import Directix from 'directix'
const app = createApp(App)
app.use(Directix)
// Register specific directives only
app.use(Directix, { directives: ['click-outside', 'copy', 'debounce'] })// Vue 2
import Vue from 'vue'
import Directix from 'directix'
Vue.use(Directix)import { vClickOutside, vCopy, vDebounce } from 'directix'
// Vue 3
app.directive('click-outside', vClickOutside)
// Vue 2
Vue.directive('click-outside', vClickOutside)Every directive has a corresponding composable for use with the Composition API:
import { useCopy, useHover, useDebounce } from 'directix'
const { copy, copied } = useCopy({ source: textRef })
const { isHovering } = useHover({ onEnter: handleEnter })
const { run: debouncedSearch } = useDebounce({ handler: search, wait: 500 })Directix provides a Nuxt module with automatic directive registration and composable auto-import:
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['directix/nuxt'],
directix: {
include: ['v-click-outside', 'v-copy', 'v-debounce'], // optional: include specific directives
exclude: ['v-ripple'], // optional: exclude specific directives
autoImportComposables: true // auto-import composables
}
})SSR-incompatible directives are automatically skipped on the server โ no manual handling needed.
| Directive | Description |
|---|---|
v-click-outside |
Detect clicks outside an element |
v-click-delay |
Delay click execution to prevent double clicks |
v-debounce |
Debounce event handlers |
v-throttle |
Throttle event handlers |
v-long-press |
Detect long press events |
v-hover |
Hover state detection |
v-hotkey |
Keyboard shortcut binding |
v-touch |
Touch gesture detection (swipe/pinch/rotate) |
v-swipe |
Swipe gesture detection with mouse support |
| Directive | Description |
|---|---|
v-copy |
Copy text to clipboard |
v-focus |
Auto focus an element |
v-mask |
Input masking |
v-trim |
Trim input whitespace |
v-money |
Currency format input |
v-number |
Number format input |
v-ellipsis |
Text ellipsis overflow |
| Directive | Description |
|---|---|
v-uppercase |
Convert text to uppercase |
v-lowercase |
Convert text to lowercase |
v-capitalcase |
Capitalize first letter |
v-truncate |
Truncate text with ellipsis |
| Directive | Description |
|---|---|
v-lazy |
Lazy load images |
v-intersect |
Detect element intersection |
v-visible |
Control element visibility |
v-loading |
Show loading overlay |
v-scroll |
Scroll event handling |
v-infinite-scroll |
Infinite scrolling |
v-sticky |
Sticky positioning |
v-pull-refresh |
Pull to refresh |
v-virtual-list |
Virtual list for large datasets |
| Directive | Description |
|---|---|
v-permission |
Permission-based element control |
v-sanitize |
Sanitize HTML content (XSS prevention) |
v-tooltip |
Tooltip component |
v-image-preview |
Image preview with zoom/gesture support |
v-countdown |
Countdown timer display |
v-print |
Print element content |
v-watermark |
Watermark overlay |
v-skeleton |
Skeleton loading placeholder |
v-progress |
Progress bar animation |
v-counter |
Animated number counter |
| Directive | Description |
|---|---|
v-ripple |
Material Design ripple effect |
v-draggable |
Make elements draggable |
v-pan |
Pan/drag gesture |
v-pinch |
Pinch/zoom gesture |
v-rotate-gesture |
Rotation gesture |
v-blur |
Background blur overlay |
v-fade |
Fade in/out transition |
v-parallax |
Parallax scrolling effect |
v-lottie |
Lottie animation player |
v-typewriter |
Typewriter animation |
v-click-wave |
Click wave effect |
| Directive | Description |
|---|---|
v-resize |
Element resize observer |
v-mutation |
DOM mutation observer |
v-export |
Export data (CSV/JSON/HTML) |
v-highlight |
Keyword highlighting |
v-emoji |
Emoji input filter |
v-context-menu |
Right-click context menu |
v-fullscreen |
Fullscreen toggle |
๐ For detailed API, options, and SSR compatibility of each directive, see the full documentation.
Every directive has a corresponding use* composable function, such as useClickOutside, useCopy, useDebounce, etc. See the documentation for the complete list.
import { configurePermission } from 'directix'
configurePermission({
getPermissions: () => ['read', 'write'],
getRoles: () => ['editor'],
roleMap: { admin: ['*'], editor: ['read', 'write', 'edit'] }
})<button v-permission="'admin'">Admin Only</button>
<button v-permission="['admin', 'editor']">Admin or Editor</button>
<button v-permission="{ value: 'admin', action: 'disable' }">Disabled for non-admin</button>import { createI18n, setLocale } from 'directix'
createI18n({
locale: 'en-US',
fallbackLocale: 'en-US',
messages: { 'en-US': enUS, 'zh-CN': zhCN, 'ja-JP': jaJP }
})
setLocale('zh-CN') // Switch at runtimeimport { definePlugin, getPluginManager } from 'directix'
const myPlugin = definePlugin({
meta: { name: 'my-plugin', version: '1.0.0' },
install(ctx) { ctx.registerDirective('my-directive', vMyDirective) }
})
getPluginManager().register(myPlugin)import { defineCustomElementDirective, createSSRSafeCustomElement } from 'directix'
defineCustomElementDirective({
name: 'lazy-img',
directive: vLazy,
shadow: true,
styles: ':host { display: block; }',
lifecycle: {
onConnect: (el) => console.log('Connected', el),
onDisconnect: (el) => console.log('Disconnected', el),
},
})
// SSR-safe custom elements
const LazyImage = createSSRSafeCustomElement('lazy-img', vLazy, { shadow: true })
const html = LazyImage.ssrRender({ src: 'image.jpg' })// Event delegation โ reduce DOM listeners
import { registerDelegatedHandler } from 'directix'
const id = registerDelegatedHandler('.btn', 'click', (e, target) => { /* ... */ })
// Batch DOM reads/writes โ avoid layout thrashing
import { domRead, domWrite } from 'directix'
domRead(() => {
const h = el.offsetHeight
domWrite(() => { el.style.transform = `translateY(${h}px)` })
})
// Memory leak detection
import { startLeakDetection, trackResource, cleanupResource } from 'directix'
startLeakDetection()
const id = trackResource('event-listener', 'scroll', cleanupFn)
// Security audit
import { sanitizeHtml, SecurityAudit } from 'directix'
const clean = sanitizeHtml(userInput, { allowedTags: ['b', 'i', 'p'] })
const report = SecurityAudit.generateReport(htmlContent)- ๐ฎ Interactive Playground โ Visual directive configuration and code generation
- ๐ฆ StackBlitz (Vue 3)
- ๐ฆ StackBlitz (Vue 2)
- ๐ Browser Extension DevTools Panel โ Real-time directive monitoring and debugging
Chrome / Firefox / Safari / Edge latest versions
Contributions are welcome! Please read our Contributing Guide for details.
MIT ยฉ 2024-present saqqdy