directix 2.0.0 → 2.1.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/index.d.ts CHANGED
@@ -1225,6 +1225,34 @@ export declare function createSafeDirectiveWrapper<T>(directiveName: string, ope
1225
1225
  validateBinding?: (binding: any) => boolean;
1226
1226
  }): (el: HTMLElement, binding: any, vnode: any) => Promise<T | undefined>;
1227
1227
 
1228
+ /**
1229
+ * Create SSR-safe custom element with declarative shadow DOM support
1230
+ *
1231
+ * @param name - Element name
1232
+ * @param directive - Vue directive
1233
+ * @param options - Element options
1234
+ * @returns SSR-safe custom element definition
1235
+ *
1236
+ * @example
1237
+ * ```ts
1238
+ * import { createSSRSafeCustomElement, vLazy } from 'directix'
1239
+ *
1240
+ * const LazyImage = createSSRSafeCustomElement('lazy-image', vLazy, {
1241
+ * shadow: true,
1242
+ * styles: ':host { display: block; }',
1243
+ * })
1244
+ *
1245
+ * // SSR render
1246
+ * const html = LazyImage.ssrRender({ src: 'image.jpg' })
1247
+ *
1248
+ * // Register in browser
1249
+ * if (typeof window !== 'undefined') {
1250
+ * customElements.define('lazy-image', LazyImage.elementClass)
1251
+ * }
1252
+ * ```
1253
+ */
1254
+ export declare function createSSRSafeCustomElement(name: string, directive: Directive, options?: Omit<CustomElementDirectiveOptions, 'name' | 'directive'>): SSRSafeCustomElement;
1255
+
1228
1256
  /**
1229
1257
  * Create a style-based directive template
1230
1258
  *
@@ -1356,6 +1384,28 @@ export declare interface CustomElementDirectiveOptions {
1356
1384
  shadow?: boolean;
1357
1385
  /** Shadow DOM mode */
1358
1386
  shadowMode?: 'open' | 'closed';
1387
+ /** CSS styles to inject into shadow DOM (v2.1.0) */
1388
+ styles?: string | string[];
1389
+ /** Attributes to observe for changes (v2.1.0) */
1390
+ observedAttributes?: string[];
1391
+ /** Lifecycle hooks (v2.1.0) */
1392
+ lifecycle?: CustomElementLifecycleHooks;
1393
+ /** Enable slot content projection (v2.1.0) */
1394
+ slots?: boolean;
1395
+ }
1396
+
1397
+ /**
1398
+ * Lifecycle hooks for custom element
1399
+ */
1400
+ export declare interface CustomElementLifecycleHooks {
1401
+ /** Called when element is connected to DOM */
1402
+ onConnect?: (el: HTMLElement) => void;
1403
+ /** Called when element is disconnected from DOM */
1404
+ onDisconnect?: (el: HTMLElement) => void;
1405
+ /** Called when element is adopted to a new document */
1406
+ onAdopt?: (el: HTMLElement) => void;
1407
+ /** Called when an attribute changes */
1408
+ onAttributeChange?: (el: HTMLElement, name: string, oldValue: string | null, newValue: string | null) => void;
1359
1409
  }
1360
1410
 
1361
1411
  declare interface CustomIntegration {
@@ -2694,6 +2744,21 @@ export declare function getPolyfillStatus(): Record<string, {
2694
2744
  required: boolean;
2695
2745
  }>;
2696
2746
 
2747
+ /**
2748
+ * Get all registered custom element names
2749
+ *
2750
+ * @returns Array of custom element names
2751
+ *
2752
+ * @example
2753
+ * ```ts
2754
+ * import { getRegisteredCustomElements } from 'directix'
2755
+ *
2756
+ * const elements = getRegisteredCustomElements()
2757
+ * console.log('Registered:', elements)
2758
+ * ```
2759
+ */
2760
+ export declare function getRegisteredCustomElements(): string[];
2761
+
2697
2762
  /**
2698
2763
  * Get slowest directives
2699
2764
  */
@@ -2794,6 +2859,24 @@ export declare interface HotkeyDefinition {
2794
2859
  disabled?: boolean | Ref<boolean>;
2795
2860
  }
2796
2861
 
2862
+ /**
2863
+ * Hydrate custom elements on the client (SSR support)
2864
+ *
2865
+ * @param root - Root element to hydrate
2866
+ *
2867
+ * @example
2868
+ * ```ts
2869
+ * import { hydrateCustomElements, registerDirectiveElements } from 'directix'
2870
+ *
2871
+ * // Register directives first
2872
+ * registerDirectiveElements({ 'lazy-img': vLazy })
2873
+ *
2874
+ * // Then hydrate
2875
+ * hydrateCustomElements(document.body)
2876
+ * ```
2877
+ */
2878
+ export declare function hydrateCustomElements(root?: Element): void;
2879
+
2797
2880
  /**
2798
2881
  * i18n instance type
2799
2882
  */
@@ -2902,6 +2985,23 @@ export declare function isBrowserSupported(browserName: string, version: number)
2902
2985
  */
2903
2986
  export declare function isCustomElement(el: Element): boolean;
2904
2987
 
2988
+ /**
2989
+ * Check if custom element is defined
2990
+ *
2991
+ * @param name - Element name
2992
+ * @returns True if element is defined
2993
+ *
2994
+ * @example
2995
+ * ```ts
2996
+ * import { isCustomElementDefined } from 'directix'
2997
+ *
2998
+ * if (!isCustomElementDefined('lazy-img')) {
2999
+ * customElements.define('lazy-img', LazyImage)
3000
+ * }
3001
+ * ```
3002
+ */
3003
+ export declare function isCustomElementDefined(name: string): boolean;
3004
+
2905
3005
  /**
2906
3006
  * Check if DevTools is available
2907
3007
  */
@@ -4402,6 +4502,14 @@ export declare function setWarningLevel(level: LogLevel): void;
4402
4502
  */
4403
4503
  export declare type SkeletonAnimation = 'wave' | 'pulse' | 'none';
4404
4504
 
4505
+ /**
4506
+ * SSR-safe custom element result (v2.1.0)
4507
+ */
4508
+ export declare interface SSRSafeCustomElement {
4509
+ elementClass: CustomElementConstructor;
4510
+ ssrRender: (attrs?: Record<string, string>) => string;
4511
+ }
4512
+
4405
4513
  /**
4406
4514
  * Start a performance measurement
4407
4515
  */
@@ -10529,6 +10637,22 @@ export declare class WeakCache<K extends object, V> {
10529
10637
  size(): number;
10530
10638
  }
10531
10639
 
10640
+ /**
10641
+ * Wait for custom element to be defined
10642
+ *
10643
+ * @param name - Element name
10644
+ * @returns Promise that resolves when element is defined
10645
+ *
10646
+ * @example
10647
+ * ```ts
10648
+ * import { whenCustomElementDefined } from 'directix'
10649
+ *
10650
+ * await whenCustomElementDefined('lazy-img')
10651
+ * // Element is now ready to use
10652
+ * ```
10653
+ */
10654
+ export declare function whenCustomElementDefined(name: string): Promise<void>;
10655
+
10532
10656
  /**
10533
10657
  * Measure and log performance
10534
10658
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * directix v2.0.0
2
+ * directix v2.1.0
3
3
  * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3, with Web Components support
4
4
  * (c) 2021-present saqqdy <https://github.com/saqqdy>
5
5
  * Released under the MIT License.
@@ -58,7 +58,7 @@ var __async = (__this, __arguments, generator) => {
58
58
  });
59
59
  };
60
60
  /*!
61
- * directix v2.0.0
61
+ * directix v2.1.0
62
62
  * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3, with Web Components support
63
63
  * (c) 2021-present saqqdy <https://github.com/saqqdy>
64
64
  * Released under the MIT License.
@@ -22066,6 +22066,48 @@ ${(_a2 = new Error("Stack trace").stack) == null ? void 0 : _a2.split("\n").slic
22066
22066
  customElements.define(elementName, elementClass);
22067
22067
  });
22068
22068
  }
22069
+ function isCustomElementDefined(name) {
22070
+ return customElements.get(name) !== void 0;
22071
+ }
22072
+ function whenCustomElementDefined(name) {
22073
+ return __async(this, null, function* () {
22074
+ yield customElements.whenDefined(name);
22075
+ });
22076
+ }
22077
+ function getRegisteredCustomElements() {
22078
+ const registry = customElements.__registry;
22079
+ if (registry && typeof registry.keys === "function") {
22080
+ return Array.from(registry.keys());
22081
+ }
22082
+ return [];
22083
+ }
22084
+ function hydrateCustomElements(root = document.body) {
22085
+ const customElementsList = root.querySelectorAll("*");
22086
+ customElementsList.forEach((el) => {
22087
+ var _a2;
22088
+ if (isCustomElement(el)) {
22089
+ const clone = el.cloneNode(true);
22090
+ (_a2 = el.parentNode) == null ? void 0 : _a2.replaceChild(clone, el);
22091
+ }
22092
+ });
22093
+ }
22094
+ function createSSRSafeCustomElement(name, directive, options) {
22095
+ const { styles, shadow = false } = options || {};
22096
+ const ssrRender = (attrs = {}) => {
22097
+ const attrString = Object.entries(attrs).map(([key, value]) => `${key}="${value}"`).join(" ");
22098
+ if (shadow) {
22099
+ const stylesString = styles ? `<style>${Array.isArray(styles) ? styles.join("") : styles}</style>` : "";
22100
+ return `<${name} ${attrString}><template shadowroot="open">${stylesString}<slot></slot></template></${name}>`;
22101
+ }
22102
+ return `<${name} ${attrString}></${name}>`;
22103
+ };
22104
+ const elementClass = typeof window === "undefined" ? class extends HTMLElement {
22105
+ } : createDirectiveElement(name, directive, options);
22106
+ return {
22107
+ elementClass,
22108
+ ssrRender
22109
+ };
22110
+ }
22069
22111
  const zhCN = {
22070
22112
  directives: {
22071
22113
  debounce: {
@@ -24239,6 +24281,7 @@ ${(_a2 = new Error("Stack trace").stack) == null ? void 0 : _a2.split("\n").slic
24239
24281
  exports.createPerformanceBudget = createPerformanceBudget;
24240
24282
  exports.createPermissionCheck = createPermissionCheck;
24241
24283
  exports.createPermissionChecker = createPermissionChecker;
24284
+ exports.createSSRSafeCustomElement = createSSRSafeCustomElement;
24242
24285
  exports.createSafeContentHandler = createSafeContentHandler;
24243
24286
  exports.createSafeDirectiveWrapper = createSafeDirectiveWrapper;
24244
24287
  exports.createStyleDirective = createStyleDirective;
@@ -24359,6 +24402,7 @@ ${(_a2 = new Error("Stack trace").stack) == null ? void 0 : _a2.split("\n").slic
24359
24402
  exports.getPluginManager = getPluginManager;
24360
24403
  exports.getPluginRegistry = getPluginRegistry;
24361
24404
  exports.getPolyfillStatus = getPolyfillStatus;
24405
+ exports.getRegisteredCustomElements = getRegisteredCustomElements;
24362
24406
  exports.getSlowestDirectives = getSlowestDirectives;
24363
24407
  exports.getSupportedRegions = getSupportedRegions;
24364
24408
  exports.getTimezoneInfo = getTimezoneInfo;
@@ -24369,6 +24413,7 @@ ${(_a2 = new Error("Stack trace").stack) == null ? void 0 : _a2.split("\n").slic
24369
24413
  exports.handleTouchConflict = handleTouchConflict;
24370
24414
  exports.hasPermission = hasPermission$2;
24371
24415
  exports.hasPermissionSync = hasPermissionSync;
24416
+ exports.hydrateCustomElements = hydrateCustomElements;
24372
24417
  exports.importConfig = importConfig;
24373
24418
  exports.incrementCounter = incrementCounter;
24374
24419
  exports.info = info;
@@ -24383,6 +24428,7 @@ ${(_a2 = new Error("Stack trace").stack) == null ? void 0 : _a2.split("\n").slic
24383
24428
  exports.isBrowser = isBrowser;
24384
24429
  exports.isBrowserSupported = isBrowserSupported;
24385
24430
  exports.isCustomElement = isCustomElement;
24431
+ exports.isCustomElementDefined = isCustomElementDefined;
24386
24432
  exports.isDOMReady = isDOMReady;
24387
24433
  exports.isDevtoolsAvailable = isDevtoolsAvailable;
24388
24434
  exports.isEmpty = isEmpty;
@@ -24620,6 +24666,7 @@ ${(_a2 = new Error("Stack trace").stack) == null ? void 0 : _a2.split("\n").slic
24620
24666
  exports.warnUnsupportedFeatures = warnUnsupportedFeatures;
24621
24667
  exports.watchConfig = watchConfig;
24622
24668
  exports.watchEffectBinding = watchEffectBinding;
24669
+ exports.whenCustomElementDefined = whenCustomElementDefined;
24623
24670
  exports.withAuditLog = withAuditLog;
24624
24671
  exports.withErrorRecovery = withErrorRecovery;
24625
24672
  exports.withPerformanceMonitoring = withPerformanceMonitoring;