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/README.md CHANGED
@@ -25,31 +25,57 @@ A comprehensive, easy-to-use, and high-performance Vue custom directives library
25
25
  - 🌐 **i18n Support** - Built-in internationalization with Chinese, English, and Japanese translations
26
26
  - 🔌 **Plugin System** - Extensible plugin architecture for community contributions
27
27
 
28
- ## What's Coming in v2.0.0 (Planned)
28
+ ## What's New in v2.1.0
29
29
 
30
- > **Note**: v2.0.0 is currently in development. The features below are planned and will be released soon.
30
+ ### Enhanced Web Components Support
31
31
 
32
- ### Web Components Support
33
-
34
- Use Directix directives with Custom Elements / Web Components:
32
+ v2.1.0 significantly enhances Web Components support with Shadow DOM, SSR safety, lifecycle hooks, and more:
35
33
 
36
34
  ```typescript
37
- import { vLazy, defineCustomElementDirective, registerDirectiveElements } from 'directix'
35
+ import {
36
+ vLazy,
37
+ defineCustomElementDirective,
38
+ createSSRSafeCustomElement,
39
+ hydrateCustomElements
40
+ } from 'directix'
38
41
 
39
- // Define a single custom element from directive
42
+ // Define with lifecycle hooks and styles
40
43
  defineCustomElementDirective({
41
44
  name: 'lazy-img',
42
45
  directive: vLazy,
43
- shadow: true
46
+ shadow: true,
47
+ styles: ':host { display: block; }',
48
+ lifecycle: {
49
+ onConnect: (el) => console.log('Connected', el),
50
+ onDisconnect: (el) => console.log('Disconnected', el),
51
+ },
44
52
  })
45
53
 
46
- // Register multiple directives as custom elements
47
- registerDirectiveElements({
48
- 'lazy-img': vLazy,
49
- 'click-outside': vClickOutside
54
+ // SSR-safe custom elements
55
+ const LazyImage = createSSRSafeCustomElement('lazy-img', vLazy, {
56
+ shadow: true,
57
+ styles: ':host { display: block; }',
50
58
  })
59
+
60
+ // SSR render
61
+ const html = LazyImage.ssrRender({ src: 'image.jpg' })
62
+
63
+ // Client hydration
64
+ hydrateCustomElements(document.body)
51
65
  ```
52
66
 
67
+ ### New Web Components APIs
68
+
69
+ | API | Description |
70
+ |-----|-------------|
71
+ | `CustomElementLifecycleHooks` | Lifecycle hooks interface (onConnect, onDisconnect, onAdopt, onAttributeChange) |
72
+ | `SSRSafeCustomElement` | SSR-safe custom element type |
73
+ | `isCustomElementDefined(name)` | Check if a custom element is already defined |
74
+ | `whenCustomElementDefined(name)` | Async wait for custom element definition |
75
+ | `getRegisteredCustomElements()` | Get all registered custom element names |
76
+ | `hydrateCustomElements(root)` | Hydrate custom elements on client (SSR support) |
77
+ | `createSSRSafeCustomElement()` | Create SSR-safe custom elements with declarative Shadow DOM |
78
+
53
79
  ### Vue 3 Conditional Optimizations
54
80
 
55
81
  When using Vue 3, Directix automatically applies performance optimizations:
package/dist/index.cjs CHANGED
@@ -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.
@@ -79,7 +79,7 @@ var __async = (__this, __arguments, generator) => {
79
79
  });
80
80
  };
81
81
  /*!
82
- * directix v2.0.0
82
+ * directix v2.1.0
83
83
  * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3, with Web Components support
84
84
  * (c) 2021-present saqqdy <https://github.com/saqqdy>
85
85
  * Released under the MIT License.
@@ -22087,6 +22087,48 @@ function registerDirectiveElements(elements) {
22087
22087
  customElements.define(elementName, elementClass);
22088
22088
  });
22089
22089
  }
22090
+ function isCustomElementDefined(name) {
22091
+ return customElements.get(name) !== void 0;
22092
+ }
22093
+ function whenCustomElementDefined(name) {
22094
+ return __async(this, null, function* () {
22095
+ yield customElements.whenDefined(name);
22096
+ });
22097
+ }
22098
+ function getRegisteredCustomElements() {
22099
+ const registry = customElements.__registry;
22100
+ if (registry && typeof registry.keys === "function") {
22101
+ return Array.from(registry.keys());
22102
+ }
22103
+ return [];
22104
+ }
22105
+ function hydrateCustomElements(root = document.body) {
22106
+ const customElementsList = root.querySelectorAll("*");
22107
+ customElementsList.forEach((el) => {
22108
+ var _a2;
22109
+ if (isCustomElement(el)) {
22110
+ const clone = el.cloneNode(true);
22111
+ (_a2 = el.parentNode) == null ? void 0 : _a2.replaceChild(clone, el);
22112
+ }
22113
+ });
22114
+ }
22115
+ function createSSRSafeCustomElement(name, directive, options) {
22116
+ const { styles, shadow = false } = options || {};
22117
+ const ssrRender = (attrs = {}) => {
22118
+ const attrString = Object.entries(attrs).map(([key, value]) => `${key}="${value}"`).join(" ");
22119
+ if (shadow) {
22120
+ const stylesString = styles ? `<style>${Array.isArray(styles) ? styles.join("") : styles}</style>` : "";
22121
+ return `<${name} ${attrString}><template shadowroot="open">${stylesString}<slot></slot></template></${name}>`;
22122
+ }
22123
+ return `<${name} ${attrString}></${name}>`;
22124
+ };
22125
+ const elementClass = typeof window === "undefined" ? class extends HTMLElement {
22126
+ } : createDirectiveElement(name, directive, options);
22127
+ return {
22128
+ elementClass,
22129
+ ssrRender
22130
+ };
22131
+ }
22090
22132
  const zhCN = {
22091
22133
  directives: {
22092
22134
  debounce: {
@@ -24260,6 +24302,7 @@ exports.createNumberFormatter = createNumberFormatter;
24260
24302
  exports.createPerformanceBudget = createPerformanceBudget;
24261
24303
  exports.createPermissionCheck = createPermissionCheck;
24262
24304
  exports.createPermissionChecker = createPermissionChecker;
24305
+ exports.createSSRSafeCustomElement = createSSRSafeCustomElement;
24263
24306
  exports.createSafeContentHandler = createSafeContentHandler;
24264
24307
  exports.createSafeDirectiveWrapper = createSafeDirectiveWrapper;
24265
24308
  exports.createStyleDirective = createStyleDirective;
@@ -24380,6 +24423,7 @@ exports.getPermissionManager = getPermissionManager;
24380
24423
  exports.getPluginManager = getPluginManager;
24381
24424
  exports.getPluginRegistry = getPluginRegistry;
24382
24425
  exports.getPolyfillStatus = getPolyfillStatus;
24426
+ exports.getRegisteredCustomElements = getRegisteredCustomElements;
24383
24427
  exports.getSlowestDirectives = getSlowestDirectives;
24384
24428
  exports.getSupportedRegions = getSupportedRegions;
24385
24429
  exports.getTimezoneInfo = getTimezoneInfo;
@@ -24390,6 +24434,7 @@ exports.handleSSRUnsupported = handleSSRUnsupported;
24390
24434
  exports.handleTouchConflict = handleTouchConflict;
24391
24435
  exports.hasPermission = hasPermission$2;
24392
24436
  exports.hasPermissionSync = hasPermissionSync;
24437
+ exports.hydrateCustomElements = hydrateCustomElements;
24393
24438
  exports.importConfig = importConfig;
24394
24439
  exports.incrementCounter = incrementCounter;
24395
24440
  exports.info = info;
@@ -24404,6 +24449,7 @@ exports.isBoolean = isBoolean;
24404
24449
  exports.isBrowser = isBrowser;
24405
24450
  exports.isBrowserSupported = isBrowserSupported;
24406
24451
  exports.isCustomElement = isCustomElement;
24452
+ exports.isCustomElementDefined = isCustomElementDefined;
24407
24453
  exports.isDOMReady = isDOMReady;
24408
24454
  exports.isDevtoolsAvailable = isDevtoolsAvailable;
24409
24455
  exports.isEmpty = isEmpty;
@@ -24641,6 +24687,7 @@ exports.warnUnsupportedFeatureOnce = warnUnsupportedFeatureOnce;
24641
24687
  exports.warnUnsupportedFeatures = warnUnsupportedFeatures;
24642
24688
  exports.watchConfig = watchConfig;
24643
24689
  exports.watchEffectBinding = watchEffectBinding;
24690
+ exports.whenCustomElementDefined = whenCustomElementDefined;
24644
24691
  exports.withAuditLog = withAuditLog;
24645
24692
  exports.withErrorRecovery = withErrorRecovery;
24646
24693
  exports.withPerformanceMonitoring = withPerformanceMonitoring;