@lytjs/core-vnode 6.7.0 → 6.8.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.
@@ -0,0 +1,146 @@
1
+ import { VNode, Fragment, Text, Comment, VNodeChildren } from '@lytjs/vdom';
2
+ export { Comment, Fragment, Text, VNode, VNodeChildren, cloneVNode, createVNode, mergeProps } from '@lytjs/vdom';
3
+ import { BaseAppConfig, Directive, DebuggerEvent, DirectiveArguments } from '@lytjs/shared-types';
4
+ export { DebuggerEvent, Directive, DirectiveArguments, DirectiveBinding, Renderer } from '@lytjs/shared-types';
5
+ import { ComponentPublicInstance, ComponentOptions, InternalSlots } from '@lytjs/component';
6
+ export { ComponentOptions, ComponentPublicInstance, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated } from '@lytjs/component';
7
+ export { nextTick } from '@lytjs/common-scheduler';
8
+ import { WritableComputedRef } from '@lytjs/reactivity';
9
+ export { computed, effect, reactive, ref, watch, watchEffect } from '@lytjs/reactivity';
10
+ export { compile } from '@lytjs/compiler';
11
+
12
+ /** 插件安装函数签名 */
13
+ type PluginInstallFunction<T = unknown> = (app: App, ...options: T[]) => void;
14
+ interface App<HostElement = Element> {
15
+ config: AppConfig;
16
+ use(plugin: Plugin | PluginInstallFunction, ...options: unknown[]): App;
17
+ mount(rootContainer: HostElement | string): ComponentPublicInstance | null;
18
+ unmount(): void;
19
+ provide<T = unknown>(key: string | symbol, value: T): App;
20
+ inject<T = unknown>(key: string | symbol): T | undefined;
21
+ component(name: string, component: Component): App;
22
+ directive(name: string, directive: Directive): App;
23
+ mixin(mixin: ComponentOptions): App;
24
+ errorHandler?: (err: unknown, instance: ComponentPublicInstance | null, info: string) => void;
25
+ warnHandler?: (msg: string, instance: ComponentPublicInstance | null, trace: string) => void;
26
+ }
27
+ interface AppConfig extends BaseAppConfig {
28
+ performance: boolean;
29
+ globalProperties: Record<string, unknown>;
30
+ isCustomElement?: (tag: string) => boolean;
31
+ compilerOptions?: Record<string, unknown>;
32
+ }
33
+ /** createApp 的配置选项(VNode 模式固定使用 vnode 渲染,忽略 rendererMode) */
34
+ interface AppOptions {
35
+ /** VNode 模式下此选项被忽略,始终使用 VNode 渲染 */
36
+ rendererMode?: 'vnode';
37
+ }
38
+ interface Plugin {
39
+ install: PluginInstallFunction;
40
+ }
41
+ type Component = ComponentOptions | (() => VNode);
42
+
43
+ type AsyncComponentLoader = () => Promise<Component>;
44
+ interface AsyncComponentOptions {
45
+ loader: AsyncComponentLoader;
46
+ loadingComponent?: Component;
47
+ errorComponent?: Component;
48
+ delay?: number;
49
+ timeout?: number;
50
+ suspensible?: boolean;
51
+ onError?: (error: Error, retry: () => void, fail: () => void, attempts: number) => void;
52
+ }
53
+
54
+ type ErrorCapturedHook = (err: Error, instance: ComponentPublicInstance | null, info: string) => boolean | void;
55
+ type DebuggerHook = (event: DebuggerEvent) => void;
56
+
57
+ declare function createApp(rootComponent: Component, rootProps?: Record<string, unknown> | null, _options?: AppOptions): App;
58
+
59
+ /**
60
+ * 创建 VNode
61
+ */
62
+ declare function h(type: string | Component | typeof Fragment | typeof Text | typeof Comment, props?: Record<string, unknown> | null, ...children: VNodeChildren[]): VNode;
63
+
64
+ /**
65
+ * 定义组件(re-export from @lytjs/component)
66
+ *
67
+ * 权威实现在 @lytjs/component 中,此处统一返回类型为 ComponentOptions。
68
+ * 由于 Component = ComponentOptions | (() => any),
69
+ * 返回 ComponentOptions 是 Component 的子集,完全兼容。
70
+ */
71
+ declare const defineComponent: (options: ComponentOptions) => ComponentOptions;
72
+ /**
73
+ * 定义异步组件
74
+ */
75
+ declare function defineAsyncComponent(source: AsyncComponentLoader | AsyncComponentOptions): Component;
76
+
77
+ /**
78
+ * 解析组件:从当前组件实例的 components 选项和全局注册中查找
79
+ */
80
+ declare function resolveComponent(name: string): Component | undefined;
81
+ /**
82
+ * 解析指令:从当前组件实例的 directives 选项和全局注册中查找
83
+ */
84
+ declare function resolveDirective(name: string): Directive | undefined;
85
+
86
+ /**
87
+ * 将指令应用到 VNode 上
88
+ */
89
+ declare function withDirectives(vnode: VNode, directives: DirectiveArguments): VNode;
90
+ /** Memo 缓存条目 */
91
+ interface MemoEntry {
92
+ memo: unknown[];
93
+ result: VNode;
94
+ }
95
+ /**
96
+ * 带缓存的渲染辅助
97
+ */
98
+ declare function withMemo(memo: unknown[], render: () => VNode, cache: MemoEntry[], index: number): VNode;
99
+
100
+ /**
101
+ * 获取当前组件的 slots
102
+ */
103
+ declare function useSlots(): InternalSlots;
104
+ /**
105
+ * 获取当前组件的 attrs
106
+ */
107
+ declare function useAttrs(): Record<string, unknown>;
108
+ /**
109
+ * 双向绑定辅助(v-model 的 composition API 版本)
110
+ */
111
+ declare function useModel<T>(props: Record<string, T | undefined>, key: string): WritableComputedRef<T>;
112
+
113
+ /**
114
+ * defineCustomElement 的配置选项
115
+ */
116
+ interface DefineCustomElementOptions {
117
+ /** 是否使用 Shadow DOM(默认 true) */
118
+ shadowRoot?: boolean;
119
+ /** Custom Element 标签名(默认使用组件 name) */
120
+ name?: string;
121
+ /** CSS 样式(注入到 Shadow DOM) */
122
+ css?: string;
123
+ }
124
+ /**
125
+ * 将 LytJS 组件包装为 Custom Element
126
+ */
127
+ declare function defineCustomElement(componentOptions: ComponentOptions, options?: DefineCustomElementOptions): CustomElementConstructor;
128
+ /**
129
+ * 在 setup 中获取当前 Custom Element 的 Shadow Root
130
+ */
131
+ declare function useShadowRoot(): ShadowRoot | null;
132
+ /**
133
+ * 在 setup 中获取当前 Custom Element 的宿主元素
134
+ */
135
+ declare function useHost(): HTMLElement | null;
136
+ /**
137
+ * 在 setup 中获取 slot 变化通知(MutationObserver)
138
+ * 返回一个注册回调的函数
139
+ */
140
+ declare function useWebComponentSlots(onChange: () => void): void;
141
+ /**
142
+ * 向 Shadow DOM 注入样式
143
+ */
144
+ declare function injectChildStyles(styles: string): void;
145
+
146
+ export { type App, type AppConfig, type AppOptions, type AsyncComponentLoader, type AsyncComponentOptions, type Component, type DebuggerHook, type DefineCustomElementOptions, type ErrorCapturedHook, type Plugin, createApp, h as createElement, defineAsyncComponent, defineComponent, defineCustomElement, h, injectChildStyles, resolveComponent, resolveDirective, useAttrs, useHost, useModel, useShadowRoot, useSlots, useWebComponentSlots, withDirectives, withMemo };
@@ -0,0 +1,146 @@
1
+ import { VNode, Fragment, Text, Comment, VNodeChildren } from '@lytjs/vdom';
2
+ export { Comment, Fragment, Text, VNode, VNodeChildren, cloneVNode, createVNode, mergeProps } from '@lytjs/vdom';
3
+ import { BaseAppConfig, Directive, DebuggerEvent, DirectiveArguments } from '@lytjs/shared-types';
4
+ export { DebuggerEvent, Directive, DirectiveArguments, DirectiveBinding, Renderer } from '@lytjs/shared-types';
5
+ import { ComponentPublicInstance, ComponentOptions, InternalSlots } from '@lytjs/component';
6
+ export { ComponentOptions, ComponentPublicInstance, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated } from '@lytjs/component';
7
+ export { nextTick } from '@lytjs/common-scheduler';
8
+ import { WritableComputedRef } from '@lytjs/reactivity';
9
+ export { computed, effect, reactive, ref, watch, watchEffect } from '@lytjs/reactivity';
10
+ export { compile } from '@lytjs/compiler';
11
+
12
+ /** 插件安装函数签名 */
13
+ type PluginInstallFunction<T = unknown> = (app: App, ...options: T[]) => void;
14
+ interface App<HostElement = Element> {
15
+ config: AppConfig;
16
+ use(plugin: Plugin | PluginInstallFunction, ...options: unknown[]): App;
17
+ mount(rootContainer: HostElement | string): ComponentPublicInstance | null;
18
+ unmount(): void;
19
+ provide<T = unknown>(key: string | symbol, value: T): App;
20
+ inject<T = unknown>(key: string | symbol): T | undefined;
21
+ component(name: string, component: Component): App;
22
+ directive(name: string, directive: Directive): App;
23
+ mixin(mixin: ComponentOptions): App;
24
+ errorHandler?: (err: unknown, instance: ComponentPublicInstance | null, info: string) => void;
25
+ warnHandler?: (msg: string, instance: ComponentPublicInstance | null, trace: string) => void;
26
+ }
27
+ interface AppConfig extends BaseAppConfig {
28
+ performance: boolean;
29
+ globalProperties: Record<string, unknown>;
30
+ isCustomElement?: (tag: string) => boolean;
31
+ compilerOptions?: Record<string, unknown>;
32
+ }
33
+ /** createApp 的配置选项(VNode 模式固定使用 vnode 渲染,忽略 rendererMode) */
34
+ interface AppOptions {
35
+ /** VNode 模式下此选项被忽略,始终使用 VNode 渲染 */
36
+ rendererMode?: 'vnode';
37
+ }
38
+ interface Plugin {
39
+ install: PluginInstallFunction;
40
+ }
41
+ type Component = ComponentOptions | (() => VNode);
42
+
43
+ type AsyncComponentLoader = () => Promise<Component>;
44
+ interface AsyncComponentOptions {
45
+ loader: AsyncComponentLoader;
46
+ loadingComponent?: Component;
47
+ errorComponent?: Component;
48
+ delay?: number;
49
+ timeout?: number;
50
+ suspensible?: boolean;
51
+ onError?: (error: Error, retry: () => void, fail: () => void, attempts: number) => void;
52
+ }
53
+
54
+ type ErrorCapturedHook = (err: Error, instance: ComponentPublicInstance | null, info: string) => boolean | void;
55
+ type DebuggerHook = (event: DebuggerEvent) => void;
56
+
57
+ declare function createApp(rootComponent: Component, rootProps?: Record<string, unknown> | null, _options?: AppOptions): App;
58
+
59
+ /**
60
+ * 创建 VNode
61
+ */
62
+ declare function h(type: string | Component | typeof Fragment | typeof Text | typeof Comment, props?: Record<string, unknown> | null, ...children: VNodeChildren[]): VNode;
63
+
64
+ /**
65
+ * 定义组件(re-export from @lytjs/component)
66
+ *
67
+ * 权威实现在 @lytjs/component 中,此处统一返回类型为 ComponentOptions。
68
+ * 由于 Component = ComponentOptions | (() => any),
69
+ * 返回 ComponentOptions 是 Component 的子集,完全兼容。
70
+ */
71
+ declare const defineComponent: (options: ComponentOptions) => ComponentOptions;
72
+ /**
73
+ * 定义异步组件
74
+ */
75
+ declare function defineAsyncComponent(source: AsyncComponentLoader | AsyncComponentOptions): Component;
76
+
77
+ /**
78
+ * 解析组件:从当前组件实例的 components 选项和全局注册中查找
79
+ */
80
+ declare function resolveComponent(name: string): Component | undefined;
81
+ /**
82
+ * 解析指令:从当前组件实例的 directives 选项和全局注册中查找
83
+ */
84
+ declare function resolveDirective(name: string): Directive | undefined;
85
+
86
+ /**
87
+ * 将指令应用到 VNode 上
88
+ */
89
+ declare function withDirectives(vnode: VNode, directives: DirectiveArguments): VNode;
90
+ /** Memo 缓存条目 */
91
+ interface MemoEntry {
92
+ memo: unknown[];
93
+ result: VNode;
94
+ }
95
+ /**
96
+ * 带缓存的渲染辅助
97
+ */
98
+ declare function withMemo(memo: unknown[], render: () => VNode, cache: MemoEntry[], index: number): VNode;
99
+
100
+ /**
101
+ * 获取当前组件的 slots
102
+ */
103
+ declare function useSlots(): InternalSlots;
104
+ /**
105
+ * 获取当前组件的 attrs
106
+ */
107
+ declare function useAttrs(): Record<string, unknown>;
108
+ /**
109
+ * 双向绑定辅助(v-model 的 composition API 版本)
110
+ */
111
+ declare function useModel<T>(props: Record<string, T | undefined>, key: string): WritableComputedRef<T>;
112
+
113
+ /**
114
+ * defineCustomElement 的配置选项
115
+ */
116
+ interface DefineCustomElementOptions {
117
+ /** 是否使用 Shadow DOM(默认 true) */
118
+ shadowRoot?: boolean;
119
+ /** Custom Element 标签名(默认使用组件 name) */
120
+ name?: string;
121
+ /** CSS 样式(注入到 Shadow DOM) */
122
+ css?: string;
123
+ }
124
+ /**
125
+ * 将 LytJS 组件包装为 Custom Element
126
+ */
127
+ declare function defineCustomElement(componentOptions: ComponentOptions, options?: DefineCustomElementOptions): CustomElementConstructor;
128
+ /**
129
+ * 在 setup 中获取当前 Custom Element 的 Shadow Root
130
+ */
131
+ declare function useShadowRoot(): ShadowRoot | null;
132
+ /**
133
+ * 在 setup 中获取当前 Custom Element 的宿主元素
134
+ */
135
+ declare function useHost(): HTMLElement | null;
136
+ /**
137
+ * 在 setup 中获取 slot 变化通知(MutationObserver)
138
+ * 返回一个注册回调的函数
139
+ */
140
+ declare function useWebComponentSlots(onChange: () => void): void;
141
+ /**
142
+ * 向 Shadow DOM 注入样式
143
+ */
144
+ declare function injectChildStyles(styles: string): void;
145
+
146
+ export { type App, type AppConfig, type AppOptions, type AsyncComponentLoader, type AsyncComponentOptions, type Component, type DebuggerHook, type DefineCustomElementOptions, type ErrorCapturedHook, type Plugin, createApp, h as createElement, defineAsyncComponent, defineComponent, defineCustomElement, h, injectChildStyles, resolveComponent, resolveDirective, useAttrs, useHost, useModel, useShadowRoot, useSlots, useWebComponentSlots, withDirectives, withMemo };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lytjs/core-vnode",
3
- "version": "6.7.0",
3
+ "version": "6.8.0",
4
4
  "description": "Lyt.js Core - VNode rendering mode only",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -22,14 +22,14 @@
22
22
  "dev": "tsup --watch"
23
23
  },
24
24
  "dependencies": {
25
- "@lytjs/component": "^6.7.0",
26
- "@lytjs/reactivity": "^6.7.0",
27
- "@lytjs/vdom": "^6.7.0",
28
- "@lytjs/compiler": "^6.7.0",
29
- "@lytjs/renderer": "^6.7.0",
30
- "@lytjs/common-scheduler": "^6.7.0",
31
- "@lytjs/common-error": "^6.7.0",
32
- "@lytjs/shared-types": "^6.7.0"
25
+ "@lytjs/component": "workspace:*",
26
+ "@lytjs/reactivity": "workspace:*",
27
+ "@lytjs/vdom": "workspace:*",
28
+ "@lytjs/compiler": "workspace:*",
29
+ "@lytjs/renderer": "workspace:*",
30
+ "@lytjs/common-scheduler": "workspace:*",
31
+ "@lytjs/common-error": "workspace:*",
32
+ "@lytjs/shared-types": "workspace:*"
33
33
  },
34
34
  "devDependencies": {
35
35
  "tsup": "^8.0.0",