@lytjs/core 3.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.cjs +52 -0
- package/dist/index.mjs +52 -0
- package/dist/types/create-app.d.ts +161 -0
- package/dist/types/create-app.d.ts.map +1 -0
- package/dist/types/dev-error.d.ts +32 -0
- package/dist/types/dev-error.d.ts.map +1 -0
- package/dist/types/error-codes.d.ts +88 -0
- package/dist/types/error-codes.d.ts.map +1 -0
- package/dist/types/error-handling.d.ts +181 -0
- package/dist/types/error-handling.d.ts.map +1 -0
- package/dist/types/h.d.ts +96 -0
- package/dist/types/h.d.ts.map +1 -0
- package/dist/types/index.d.ts +24 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lyt-error.d.ts +57 -0
- package/dist/types/lyt-error.d.ts.map +1 -0
- package/dist/types/plugin.d.ts +119 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/warn.d.ts +32 -0
- package/dist/types/warn.d.ts.map +1 -0
- package/dist/types/web-component.d.ts +127 -0
- package/dist/types/web-component.d.ts.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lyt.js 错误处理系统
|
|
3
|
+
*
|
|
4
|
+
* 纯原生零依赖 TypeScript 实现。
|
|
5
|
+
* 提供统一的错误码、错误类、错误边界、警告系统和友好提示。
|
|
6
|
+
*/
|
|
7
|
+
export declare enum LytErrorCodes {
|
|
8
|
+
INVALID_ARGUMENT = 1001,
|
|
9
|
+
NOT_FOUND = 1002,
|
|
10
|
+
ALREADY_EXISTS = 1003,
|
|
11
|
+
OPERATION_FAILED = 1004,
|
|
12
|
+
REACTIVE_READONLY = 2001,
|
|
13
|
+
REACTIVE_EFFECT_DISPOSED = 2002,
|
|
14
|
+
COMPUTED_CYCLE = 2003,
|
|
15
|
+
PARSE_ERROR = 3001,
|
|
16
|
+
INVALID_EXPRESSION = 3002,
|
|
17
|
+
INVALID_DIRECTIVE = 3003,
|
|
18
|
+
INVALID_TEMPLATE = 3004,
|
|
19
|
+
RENDER_ERROR = 4001,
|
|
20
|
+
HYDRATION_MISMATCH = 4002,
|
|
21
|
+
INVALID_VNODE = 4003,
|
|
22
|
+
COMPONENT_INVALID_PROPS = 5001,
|
|
23
|
+
COMPONENT_MISSING_TEMPLATE = 5002,
|
|
24
|
+
COMPONENT_LIFECYCLE_ERROR = 5003,
|
|
25
|
+
ROUTE_NOT_FOUND = 6001,
|
|
26
|
+
ROUTE_DUPLICATE = 6002,
|
|
27
|
+
NAVIGATION_ABORTED = 6003,
|
|
28
|
+
NAVIGATION_FAILED = 6004,
|
|
29
|
+
STORE_NOT_FOUND = 7001,
|
|
30
|
+
STORE_DUPLICATE = 7002
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 扩展错误码常量,使用简短命名覆盖所有模块。
|
|
34
|
+
* 与 LytErrorCodes 枚举互补,提供更细粒度的错误分类。
|
|
35
|
+
*/
|
|
36
|
+
export declare const ErrorCodes: {
|
|
37
|
+
readonly APP_MOUNT_FAILED: 100;
|
|
38
|
+
readonly APP_UNMOUNT_FAILED: 101;
|
|
39
|
+
readonly APP_PLUGIN_INVALID: 102;
|
|
40
|
+
readonly APP_PROVIDE_INVALID: 103;
|
|
41
|
+
readonly COMPONENT_INVALID: 200;
|
|
42
|
+
readonly COMPONENT_PROPS_INVALID: 201;
|
|
43
|
+
readonly COMPONENT_EMIT_INVALID: 202;
|
|
44
|
+
readonly COMPONENT_LIFECYCLE_ERROR: 203;
|
|
45
|
+
readonly COMPONENT_RENDER_ERROR: 204;
|
|
46
|
+
readonly REACTIVE_SET_READONLY: 300;
|
|
47
|
+
readonly REACTIVE_EFFECT_ERROR: 301;
|
|
48
|
+
readonly COMPUTED_GETTER_ERROR: 302;
|
|
49
|
+
readonly WATCH_CALLBACK_ERROR: 303;
|
|
50
|
+
readonly COMPILER_PARSE_ERROR: 400;
|
|
51
|
+
readonly COMPILER_TRANSFORM_ERROR: 401;
|
|
52
|
+
readonly COMPILER_CODEGEN_ERROR: 402;
|
|
53
|
+
readonly SFC_PARSE_ERROR: 403;
|
|
54
|
+
readonly RENDERER_HYDRATE_ERROR: 500;
|
|
55
|
+
readonly RENDERER_HYDRATE_MISMATCH: 501;
|
|
56
|
+
readonly ROUTER_DUPLICATE_ROUTE: 600;
|
|
57
|
+
readonly ROUTER_NAVIGATION_ABORTED: 601;
|
|
58
|
+
readonly ROUTE_NOT_FOUND: 602;
|
|
59
|
+
readonly STORE_DUPLICATE_ID: 700;
|
|
60
|
+
readonly STORE_DISPOSED: 701;
|
|
61
|
+
readonly STORE_PATCH_ERROR: 702;
|
|
62
|
+
};
|
|
63
|
+
/** ErrorCodes 的值类型 */
|
|
64
|
+
export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
65
|
+
export declare class LytError extends Error {
|
|
66
|
+
code: LytErrorCodes;
|
|
67
|
+
details?: any;
|
|
68
|
+
constructor(code: LytErrorCodes, message: string, details?: any);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 快速创建 LytError 实例的工厂函数
|
|
72
|
+
*
|
|
73
|
+
* @param code LytErrorCodes 枚举值
|
|
74
|
+
* @param message 错误消息
|
|
75
|
+
* @param details 附加详情(可选)
|
|
76
|
+
* @returns LytError 实例
|
|
77
|
+
*/
|
|
78
|
+
export declare function createLytError(code: LytErrorCodes, message: string, details?: any): LytError;
|
|
79
|
+
export interface ErrorBoundaryOptions {
|
|
80
|
+
onError?: (error: LytError, vm: any) => void;
|
|
81
|
+
onErrorCaptured?: (error: LytError, vm: any, info: string) => boolean | void;
|
|
82
|
+
/** 最大错误记录数,超过后自动丢弃最早的错误,默认 100 */
|
|
83
|
+
maxErrors?: number;
|
|
84
|
+
/** 降级 UI 回调,当捕获到错误时调用,返回降级内容 */
|
|
85
|
+
fallback?: (error: Error, vm: any, info: string) => any;
|
|
86
|
+
}
|
|
87
|
+
export declare class ErrorBoundary {
|
|
88
|
+
private errors;
|
|
89
|
+
private options;
|
|
90
|
+
/** 是否处于错误状态 */
|
|
91
|
+
private _hasError;
|
|
92
|
+
/** 全局错误处理器 */
|
|
93
|
+
static globalHandler: ((error: Error, vm: any, info: string) => void) | null;
|
|
94
|
+
constructor(options?: ErrorBoundaryOptions);
|
|
95
|
+
/** 是否处于错误状态 */
|
|
96
|
+
get hasError(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* 设置全局错误处理器
|
|
99
|
+
*/
|
|
100
|
+
static setGlobalHandler(handler: (error: Error, vm: any, info: string) => void): void;
|
|
101
|
+
/**
|
|
102
|
+
* 捕获错误
|
|
103
|
+
*/
|
|
104
|
+
capture(error: Error, vm: any, info?: string): void;
|
|
105
|
+
/**
|
|
106
|
+
* 获取降级 UI 内容
|
|
107
|
+
* 当配置了 fallback 回调时,使用最后捕获的错误生成降级内容
|
|
108
|
+
*/
|
|
109
|
+
getFallback(vm?: any): any;
|
|
110
|
+
/**
|
|
111
|
+
* 获取所有错误
|
|
112
|
+
*/
|
|
113
|
+
getErrors(): Array<{
|
|
114
|
+
error: Error;
|
|
115
|
+
vm: any;
|
|
116
|
+
info: string;
|
|
117
|
+
timestamp: number;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* 获取错误数量
|
|
121
|
+
*/
|
|
122
|
+
getErrorCount(): number;
|
|
123
|
+
/**
|
|
124
|
+
* 获取最后一次错误
|
|
125
|
+
*/
|
|
126
|
+
getLastErrors(): {
|
|
127
|
+
error: Error;
|
|
128
|
+
vm: any;
|
|
129
|
+
info: string;
|
|
130
|
+
timestamp: number;
|
|
131
|
+
} | null;
|
|
132
|
+
/**
|
|
133
|
+
* 清除错误并重置错误状态
|
|
134
|
+
*/
|
|
135
|
+
clear(): void;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 设置开发/生产模式
|
|
139
|
+
*/
|
|
140
|
+
export declare function setDevMode(mode: boolean): void;
|
|
141
|
+
/**
|
|
142
|
+
* 获取当前是否为开发模式
|
|
143
|
+
*/
|
|
144
|
+
export declare function getDevMode(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* 仅开发模式输出警告
|
|
147
|
+
*/
|
|
148
|
+
export declare function warn(msg: string): void;
|
|
149
|
+
/**
|
|
150
|
+
* 每条消息只警告一次
|
|
151
|
+
*/
|
|
152
|
+
export declare function warnOnce(msg: string): void;
|
|
153
|
+
/**
|
|
154
|
+
* 重置已警告消息集合(仅用于测试)
|
|
155
|
+
*/
|
|
156
|
+
export declare function resetWarnedMessages(): void;
|
|
157
|
+
/**
|
|
158
|
+
* 根据错误码生成友好的中文提示信息
|
|
159
|
+
*
|
|
160
|
+
* @param code 错误码
|
|
161
|
+
* @param args 提示模板的参数
|
|
162
|
+
* @returns 格式化的提示字符串
|
|
163
|
+
*/
|
|
164
|
+
export declare function createMessage(code: LytErrorCodes, ...args: any[]): string;
|
|
165
|
+
/**
|
|
166
|
+
* 统一错误处理入口
|
|
167
|
+
*
|
|
168
|
+
* 1. 如果有 ErrorBoundary.globalHandler,调用它
|
|
169
|
+
* 2. 如果是开发模式,console.error 详细信息
|
|
170
|
+
* 3. 如果是生产模式,可以上报错误(预留)
|
|
171
|
+
*/
|
|
172
|
+
export declare function handleError(err: Error, vm?: any, info?: string): void;
|
|
173
|
+
/**
|
|
174
|
+
* 安全执行函数,捕获错误并交给 handleError 处理
|
|
175
|
+
*
|
|
176
|
+
* @param fn 要执行的函数
|
|
177
|
+
* @param instance 组件实例(可选)
|
|
178
|
+
* @returns 函数返回值,出错时返回 undefined
|
|
179
|
+
*/
|
|
180
|
+
export declare function callWithErrorHandling<T>(fn: () => T, instance?: any): T | undefined;
|
|
181
|
+
//# sourceMappingURL=error-handling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling.d.ts","sourceRoot":"","sources":["../../src/error-handling.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,oBAAY,aAAa;I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AA;KAAE,GAAG,IAAI;IAKlF;;OAEG;IACH,KAAK,IAAI,IAAI;CAId;AAWD;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE9C;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAEpC;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAGtC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAK1C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAqED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,CAOzE;AAMD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CA0BrE;AAMD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,SAAS,CAOnF"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lyt.js 核心入口 — 渲染函数(h)
|
|
3
|
+
*
|
|
4
|
+
* 提供创建虚拟节点(VNode)的渲染函数 h()。
|
|
5
|
+
* 这是框架中最基础的 API,用于在渲染函数中描述 UI 结构。
|
|
6
|
+
*
|
|
7
|
+
* 设计说明:
|
|
8
|
+
* - 直接定义最小 VNode 结构,不依赖 @lytjs/vdom 包
|
|
9
|
+
* - 这样 core 包可以独立运行,不依赖其他包的实现
|
|
10
|
+
* - 当与 @lytjs/vdom 一起使用时,可以桥接转换
|
|
11
|
+
*
|
|
12
|
+
* 纯原生零依赖实现。
|
|
13
|
+
*/
|
|
14
|
+
/** VNode 形状标记(位标记) */
|
|
15
|
+
export declare const enum ShapeFlags {
|
|
16
|
+
/** 普通 HTML/SVG 元素 */
|
|
17
|
+
ELEMENT = 1,
|
|
18
|
+
/** 函数式组件 */
|
|
19
|
+
FUNCTIONAL_COMPONENT = 2,
|
|
20
|
+
/** 有状态组件 */
|
|
21
|
+
STATEFUL_COMPONENT = 4,
|
|
22
|
+
/** 子节点是纯文本 */
|
|
23
|
+
TEXT_CHILDREN = 8,
|
|
24
|
+
/** 子节点是数组 */
|
|
25
|
+
ARRAY_CHILDREN = 16,
|
|
26
|
+
/** 子节点是插槽 */
|
|
27
|
+
SLOTS_CHILDREN = 32
|
|
28
|
+
}
|
|
29
|
+
/** VNode 接口(最小化定义) */
|
|
30
|
+
export interface VNode {
|
|
31
|
+
/** 节点类型:HTML 标签字符串 | 组件对象 | 函数 */
|
|
32
|
+
type: string | object | symbol;
|
|
33
|
+
/** 节点属性 */
|
|
34
|
+
props: Record<string, any> | null;
|
|
35
|
+
/** 子节点 */
|
|
36
|
+
children: string | VNode[] | Record<string, any> | null;
|
|
37
|
+
/** 节点唯一标识 */
|
|
38
|
+
key: string | number | null;
|
|
39
|
+
/** ref 回调或 ref 对象 */
|
|
40
|
+
ref: ((el: any) => void) | {
|
|
41
|
+
current: any;
|
|
42
|
+
} | null;
|
|
43
|
+
/** 形状标记 */
|
|
44
|
+
shapeFlag: number;
|
|
45
|
+
/** 对应的真实 DOM 元素引用 */
|
|
46
|
+
el: any;
|
|
47
|
+
/** 关联的组件实例 */
|
|
48
|
+
component: any;
|
|
49
|
+
}
|
|
50
|
+
/** h 函数的 children 参数类型 */
|
|
51
|
+
export type Children = string | number | VNode | Children[];
|
|
52
|
+
/** h 函数的 props 参数类型 */
|
|
53
|
+
export type Props = Record<string, any> | null;
|
|
54
|
+
/** Fragment 标记 Symbol */
|
|
55
|
+
export declare const Fragment: unique symbol;
|
|
56
|
+
/**
|
|
57
|
+
* 渲染函数 h()
|
|
58
|
+
*
|
|
59
|
+
* 用于在渲染函数中创建虚拟节点(VNode)。
|
|
60
|
+
* 这是框架中最核心的 API 之一。
|
|
61
|
+
*
|
|
62
|
+
* 支持的用法:
|
|
63
|
+
* 1. h('div') — 创建空 div 元素
|
|
64
|
+
* 2. h('div', { class: 'app' }) — 创建带属性的 div
|
|
65
|
+
* 3. h('div', null, 'Hello') — 创建带文本内容的 div
|
|
66
|
+
* 4. h('div', null, [h('span', null, 'A'), h('span', null, 'B')]) — 嵌套子节点
|
|
67
|
+
* 5. h(Component, { prop: 'value' }) — 创建组件 VNode
|
|
68
|
+
* 6. h('div', { key: 'unique' }) — 带 key 的 VNode(用于列表渲染)
|
|
69
|
+
*
|
|
70
|
+
* @param type - 节点类型(HTML 标签字符串、组件对象或函数)
|
|
71
|
+
* @param props - 节点属性(可选)
|
|
72
|
+
* @param children - 子节点(可选,支持字符串、数组、VNode)
|
|
73
|
+
* @returns VNode
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { h } from '@lytjs/core'
|
|
78
|
+
*
|
|
79
|
+
* // 创建元素
|
|
80
|
+
* h('div', { class: 'container', id: 'app' }, [
|
|
81
|
+
* h('h1', null, 'Hello Lyt.js'),
|
|
82
|
+
* h('p', { style: { color: 'red' } }, 'This is a paragraph'),
|
|
83
|
+
* h('button', { onClick: () => console.log('clicked') }, 'Click me'),
|
|
84
|
+
* ])
|
|
85
|
+
*
|
|
86
|
+
* // 创建组件
|
|
87
|
+
* h(MyComponent, { title: 'Props', onCustom: handleEvent }, [
|
|
88
|
+
* h('span', null, 'Slot content'),
|
|
89
|
+
* ])
|
|
90
|
+
*
|
|
91
|
+
* // 使用 Fragment
|
|
92
|
+
* h(Fragment, null, [h('li', null, 'Item 1'), h('li', null, 'Item 2')])
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function h(type: string | object | symbol, props?: Props, children?: Children): VNode;
|
|
96
|
+
//# sourceMappingURL=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AM,QAAQ,eAAqB,CAAC;AA2J3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,CAAC,CACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAC9B,KAAK,CAAC,EAAE,KAAK,EACb,QAAQ,CAAC,EAAE,QAAQ,GAClB,KAAK,CAEP"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lyt.js 核心入口 — 统一导出入口
|
|
3
|
+
*
|
|
4
|
+
* 导出所有公共 API 和类型定义。
|
|
5
|
+
* 纯原生零依赖实现。
|
|
6
|
+
*/
|
|
7
|
+
export { createApp } from './create-app';
|
|
8
|
+
export type { App, ComponentOptions, DirectiveHooks, DirectiveBinding, } from './create-app';
|
|
9
|
+
export { h, Fragment } from './h';
|
|
10
|
+
export type { VNode, Children, Props, } from './h';
|
|
11
|
+
export { ShapeFlags } from './h';
|
|
12
|
+
export { createProvidesContext, installPlugin, uninstallPlugin, isPluginObject, isPluginFunction, getPluginName, } from './plugin';
|
|
13
|
+
export type { Plugin, PluginObject, AppAPI, AppConfig, } from './plugin';
|
|
14
|
+
export { LytError, LytErrorCodes, ErrorBoundary, handleError, callWithErrorHandling, warn, warnOnce, setDevMode, createMessage, } from './error-handling';
|
|
15
|
+
export type { ErrorBoundaryOptions, } from './error-handling';
|
|
16
|
+
export { LytErrorCodes as NewLytErrorCodes, ErrorCategory, getErrorMessage, getCategory, } from './error-codes';
|
|
17
|
+
export type { ErrorCategoryType, } from './error-codes';
|
|
18
|
+
export { LytError as NewLytError, createCompilerError, createRendererError, createComponentError, } from './lyt-error';
|
|
19
|
+
export type { SourceLocation, } from './lyt-error';
|
|
20
|
+
export { warn as warnUtil, warnOnce as warnOnceUtil, error, getDevMode, resetWarnedMessages, } from './warn';
|
|
21
|
+
export { formatError, getComponentStack, createErrorOverlay, } from './dev-error';
|
|
22
|
+
export { defineCustomElement, registerComponents, unregisterElement, isBrowser, defineCustomElementFromSFC, } from './web-component';
|
|
23
|
+
export type { CustomElementOptions, ComponentRegistration, } from './web-component';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,YAAY,EACV,GAAG,EACH,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAMtB,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAElC,YAAY,EACV,KAAK,EACL,QAAQ,EACR,KAAK,GACN,MAAM,KAAK,CAAC;AAEb,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAMjC,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,MAAM,EACN,YAAY,EACZ,MAAM,EACN,SAAS,GACV,MAAM,UAAU,CAAC;AAMlB,OAAO,EACL,QAAQ,EACR,aAAa,EACb,aAAa,EACb,WAAW,EACX,qBAAqB,EACrB,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EACL,aAAa,IAAI,gBAAgB,EACjC,aAAa,EACb,eAAe,EACf,WAAW,GACZ,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAMvB,OAAO,EACL,QAAQ,IAAI,WAAW,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,cAAc,GACf,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,IAAI,IAAI,QAAQ,EAChB,QAAQ,IAAI,YAAY,EACxB,KAAK,EACL,UAAU,EACV,mBAAmB,GACpB,MAAM,QAAQ,CAAC;AAMhB,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,EACT,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lyt.js LytError 错误类
|
|
3
|
+
*
|
|
4
|
+
* 统一的错误类,包含错误码、分类、详情信息。
|
|
5
|
+
* 提供工厂函数用于创建特定模块的错误。
|
|
6
|
+
* 纯原生零依赖 TypeScript 实现。
|
|
7
|
+
*/
|
|
8
|
+
import { LytErrorCodes } from './error-codes';
|
|
9
|
+
/** 源代码位置 */
|
|
10
|
+
export interface SourceLocation {
|
|
11
|
+
/** 文件名 */
|
|
12
|
+
file?: string;
|
|
13
|
+
/** 行号(从 1 开始) */
|
|
14
|
+
line?: number;
|
|
15
|
+
/** 列号(从 1 开始) */
|
|
16
|
+
column?: number;
|
|
17
|
+
/** 源代码片段 */
|
|
18
|
+
source?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class LytError extends Error {
|
|
21
|
+
/** 错误码 */
|
|
22
|
+
code: LytErrorCodes;
|
|
23
|
+
/** 错误分类 */
|
|
24
|
+
category: string;
|
|
25
|
+
/** 附加详情 */
|
|
26
|
+
details?: any;
|
|
27
|
+
/** 源代码位置 */
|
|
28
|
+
loc?: SourceLocation;
|
|
29
|
+
constructor(code: LytErrorCodes, message?: string, details?: any);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 创建编译器错误(带源位置信息)
|
|
33
|
+
*
|
|
34
|
+
* @param code 错误码
|
|
35
|
+
* @param loc 源代码位置
|
|
36
|
+
* @param message 自定义消息(可选)
|
|
37
|
+
*/
|
|
38
|
+
export declare function createCompilerError(code: LytErrorCodes, loc?: SourceLocation, message?: string): LytError;
|
|
39
|
+
/**
|
|
40
|
+
* 创建渲染器错误(带 VNode 上下文)
|
|
41
|
+
*
|
|
42
|
+
* @param code 错误码
|
|
43
|
+
* @param vnode 相关的 VNode(可选)
|
|
44
|
+
* @param message 自定义消息(可选)
|
|
45
|
+
*/
|
|
46
|
+
export declare function createRendererError(code: LytErrorCodes, vnode?: any, message?: string): LytError;
|
|
47
|
+
/**
|
|
48
|
+
* 创建组件错误(带组件名称)
|
|
49
|
+
*
|
|
50
|
+
* @param code 错误码
|
|
51
|
+
* @param component 组件名称或组件实例(可选)
|
|
52
|
+
* @param message 自定义消息(可选)
|
|
53
|
+
*/
|
|
54
|
+
export declare function createComponentError(code: LytErrorCodes, component?: string | {
|
|
55
|
+
name?: string;
|
|
56
|
+
}, message?: string): LytError;
|
|
57
|
+
//# sourceMappingURL=lyt-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lyt-error.d.ts","sourceRoot":"","sources":["../../src/lyt-error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,aAAa,EAGd,MAAM,eAAe,CAAA;AAMtB,YAAY;AACZ,MAAM,WAAW,cAAc;IAC7B,UAAU;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iBAAiB;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAMD,qBAAa,QAAS,SAAQ,KAAK;IACjC,UAAU;IACV,IAAI,EAAE,aAAa,CAAA;IACnB,WAAW;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW;IACX,OAAO,CAAC,EAAE,GAAG,CAAA;IACb,YAAY;IACZ,GAAG,CAAC,EAAE,cAAc,CAAA;gBAER,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAOjE;AAMD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,aAAa,EACnB,GAAG,CAAC,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,MAAM,GACf,QAAQ,CAIV;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,aAAa,EACnB,KAAK,CAAC,EAAE,GAAG,EACX,OAAO,CAAC,EAAE,MAAM,GACf,QAAQ,CAIV;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,aAAa,EACnB,SAAS,CAAC,EAAE,MAAM,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EACtC,OAAO,CAAC,EAAE,MAAM,GACf,QAAQ,CAOV"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lyt.js 核心入口 — 插件系统(Plugin)
|
|
3
|
+
*
|
|
4
|
+
* 提供插件安装机制和依赖注入(provide/inject)功能。
|
|
5
|
+
*
|
|
6
|
+
* 插件系统:
|
|
7
|
+
* - app.use(plugin, options?) 安装插件
|
|
8
|
+
* - app.unuse(plugin) 卸载插件
|
|
9
|
+
* - app.isInstalled(plugin) 查询插件状态
|
|
10
|
+
* - 插件签名:{ install: (app, options) => void } 或函数
|
|
11
|
+
* - 支持异步插件(install 返回 Promise)
|
|
12
|
+
* - 支持生命周期钩子 onBeforeInstall / onInstalled
|
|
13
|
+
* - 支持插件元数据 name 属性
|
|
14
|
+
*
|
|
15
|
+
* 依赖注入:
|
|
16
|
+
* - app.provide(key, value) 在祖先组件提供值
|
|
17
|
+
* - app.inject(key, defaultValue?) 在后代组件注入值
|
|
18
|
+
*
|
|
19
|
+
* 纯原生零依赖实现。
|
|
20
|
+
*/
|
|
21
|
+
/** 插件对象(带 install 方法) */
|
|
22
|
+
export interface PluginObject {
|
|
23
|
+
/** 安装方法(支持同步和异步) */
|
|
24
|
+
install: (app: AppAPI, ...options: any[]) => void | Promise<void>;
|
|
25
|
+
/** 卸载方法(可选) */
|
|
26
|
+
uninstall?: (app: AppAPI) => void | Promise<void>;
|
|
27
|
+
/** 安装前回调(可选) */
|
|
28
|
+
onBeforeInstall?: (app: AppAPI, ...options: any[]) => void | Promise<void>;
|
|
29
|
+
/** 安装后回调(可选) */
|
|
30
|
+
onInstalled?: (app: AppAPI, ...options: any[]) => void | Promise<void>;
|
|
31
|
+
/** 插件名称(用于调试) */
|
|
32
|
+
name?: string;
|
|
33
|
+
}
|
|
34
|
+
/** 插件类型:可以是对象或函数 */
|
|
35
|
+
export type Plugin = PluginObject | ((app: AppAPI, ...options: any[]) => void | Promise<void>);
|
|
36
|
+
/** 应用上下文接口(插件系统使用) */
|
|
37
|
+
export interface AppAPI {
|
|
38
|
+
/** 安装插件(同步时返回 AppAPI,异步时返回 Promise<AppAPI>) */
|
|
39
|
+
use(plugin: Plugin, ...options: any[]): AppAPI | Promise<AppAPI>;
|
|
40
|
+
/** 卸载插件 */
|
|
41
|
+
unuse(plugin: Plugin): AppAPI | Promise<AppAPI>;
|
|
42
|
+
/** 查询插件是否已安装 */
|
|
43
|
+
isInstalled(plugin: Plugin): boolean;
|
|
44
|
+
/** 提供依赖 */
|
|
45
|
+
provide<T = any>(key: string | symbol, value: T): void;
|
|
46
|
+
/** 注入依赖 */
|
|
47
|
+
inject<T = any>(key: string | symbol, defaultValue?: T): T | undefined;
|
|
48
|
+
/** 获取全局配置 */
|
|
49
|
+
config: AppConfig;
|
|
50
|
+
/** 全局属性(用于挂载全局方法/属性) */
|
|
51
|
+
globalProperties: Record<string, any>;
|
|
52
|
+
}
|
|
53
|
+
/** 应用配置 */
|
|
54
|
+
export interface AppConfig {
|
|
55
|
+
/** 自定义配置项 */
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
/** 错误处理器 */
|
|
58
|
+
errorHandler?: (err: any, instance: any, info: string) => void;
|
|
59
|
+
/** 警告处理器 */
|
|
60
|
+
warnHandler?: (msg: string, instance: any, trace: string) => void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 创建依赖注入容器
|
|
64
|
+
*
|
|
65
|
+
* 依赖注入使用分层结构:
|
|
66
|
+
* - 每个应用实例有自己的 provides
|
|
67
|
+
* - 子组件可以访问父组件提供的值
|
|
68
|
+
* - 通过原型链实现层级查找
|
|
69
|
+
*
|
|
70
|
+
* @param parent - 父级 provides(可选)
|
|
71
|
+
* @returns 注入容器
|
|
72
|
+
*/
|
|
73
|
+
export declare function createProvidesContext(parent?: Record<string | symbol, any>): Record<string | symbol, any>;
|
|
74
|
+
/**
|
|
75
|
+
* 判断插件是否为对象形式(带 install 方法)
|
|
76
|
+
*/
|
|
77
|
+
export declare function isPluginObject(plugin: Plugin): plugin is PluginObject;
|
|
78
|
+
/**
|
|
79
|
+
* 判断插件是否为函数形式
|
|
80
|
+
*/
|
|
81
|
+
export declare function isPluginFunction(plugin: Plugin): plugin is (app: AppAPI, ...options: any[]) => void | Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* 获取插件名称(用于调试和日志)
|
|
84
|
+
*
|
|
85
|
+
* @param plugin - 插件对象或函数
|
|
86
|
+
* @returns 插件名称或默认标识
|
|
87
|
+
*/
|
|
88
|
+
export declare function getPluginName(plugin: Plugin): string;
|
|
89
|
+
/**
|
|
90
|
+
* 安装插件到应用
|
|
91
|
+
*
|
|
92
|
+
* 支持两种插件形式:
|
|
93
|
+
* 1. 对象形式:{ install: (app, options) => void }
|
|
94
|
+
* 2. 函数形式:(app, options) => void
|
|
95
|
+
*
|
|
96
|
+
* 支持生命周期钩子:
|
|
97
|
+
* - onBeforeInstall: 安装前调用
|
|
98
|
+
* - onInstalled: 安装后调用
|
|
99
|
+
*
|
|
100
|
+
* 支持异步插件:install 返回 Promise 时,本函数也返回 Promise。
|
|
101
|
+
*
|
|
102
|
+
* @param app - 应用 API
|
|
103
|
+
* @param plugin - 插件
|
|
104
|
+
* @param options - 插件选项
|
|
105
|
+
* @returns 同步插件返回 void,异步插件返回 Promise<void>
|
|
106
|
+
*/
|
|
107
|
+
export declare function installPlugin(app: AppAPI, plugin: Plugin, ...options: any[]): void | Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* 卸载插件
|
|
110
|
+
*
|
|
111
|
+
* 如果插件是对象形式且定义了 uninstall 方法,则调用它。
|
|
112
|
+
* 函数形式插件无法卸载(给出警告)。
|
|
113
|
+
*
|
|
114
|
+
* @param app - 应用 API
|
|
115
|
+
* @param plugin - 插件
|
|
116
|
+
* @returns 同步卸载返回 void,异步卸载返回 Promise<void>
|
|
117
|
+
*/
|
|
118
|
+
export declare function uninstallPlugin(app: AppAPI, plugin: Plugin): void | Promise<void>;
|
|
119
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH,yBAAyB;AACzB,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,eAAe;IACf,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,gBAAgB;IAChB,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,gBAAgB;IAChB,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAA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,MAAM,KAAK,IAAI,CAAC;IAC/D,YAAY;IACZ,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnE;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GACpC,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAK9B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,YAAY,CAMrE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnH;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQpD;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,GAAG,OAAO,EAAE,GAAG,EAAE,GAChB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CA6CtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,GACb,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CActB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lyt.js 警告与错误输出工具
|
|
3
|
+
*
|
|
4
|
+
* 提供 warn、warnOnce、error 等工具函数。
|
|
5
|
+
* 开发模式下输出详细信息,生产模式下静默。
|
|
6
|
+
* 纯原生零依赖 TypeScript 实现。
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 设置开发/生产模式
|
|
10
|
+
*/
|
|
11
|
+
export declare function setDevMode(mode: boolean): void;
|
|
12
|
+
/**
|
|
13
|
+
* 获取当前是否为开发模式
|
|
14
|
+
*/
|
|
15
|
+
export declare function getDevMode(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* 仅开发模式输出警告
|
|
18
|
+
*/
|
|
19
|
+
export declare function warn(msg: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* 每条消息只警告一次
|
|
22
|
+
*/
|
|
23
|
+
export declare function warnOnce(msg: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* 始终输出错误信息(不受开发/生产模式限制)
|
|
26
|
+
*/
|
|
27
|
+
export declare function error(msg: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* 重置已警告消息集合(仅用于测试)
|
|
30
|
+
*/
|
|
31
|
+
export declare function resetWarnedMessages(): void;
|
|
32
|
+
//# sourceMappingURL=warn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warn.d.ts","sourceRoot":"","sources":["../../src/warn.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE9C;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAEpC;AASD;;GAEG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAGtC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAK1C;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEvC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lyt.js Web Component 适配器
|
|
3
|
+
*
|
|
4
|
+
* 将 Lyt.js 组件转换为标准 Web Component(Custom Element),
|
|
5
|
+
* 使其可以在 React、Vue、Angular 或任何其他框架中使用。
|
|
6
|
+
*
|
|
7
|
+
* 核心功能:
|
|
8
|
+
* - defineCustomElement: 将 Lyt.js 组件注册为 Custom Element
|
|
9
|
+
* - registerComponents: 批量注册多个组件
|
|
10
|
+
* - unregisterElement: 注销 Custom Element
|
|
11
|
+
* - isBrowser: 检测浏览器环境
|
|
12
|
+
* - defineCustomElementFromSFC: 从 SFC 源码创建 Web Component
|
|
13
|
+
*
|
|
14
|
+
* 纯原生零依赖实现。
|
|
15
|
+
*/
|
|
16
|
+
import { type ComponentOptions } from './index';
|
|
17
|
+
/**
|
|
18
|
+
* Custom Element 配置选项
|
|
19
|
+
*/
|
|
20
|
+
export interface CustomElementOptions {
|
|
21
|
+
/** 需要观察的属性列表(这些属性变化时触发 attributeChangedCallback) */
|
|
22
|
+
observedAttributes?: string[];
|
|
23
|
+
/** Shadow DOM 模式,默认 'open' */
|
|
24
|
+
shadowMode?: 'open' | 'closed';
|
|
25
|
+
/** 注入到 Shadow Root 的 CSS 样式 */
|
|
26
|
+
styles?: string;
|
|
27
|
+
/** 属性名映射(HTML 属性名 → 组件 prop 名) */
|
|
28
|
+
propMappings?: Record<string, string>;
|
|
29
|
+
/** 事件名映射(Lyt 事件名 → CustomEvent 事件名) */
|
|
30
|
+
eventMappings?: Record<string, string>;
|
|
31
|
+
/** 属性值转换器(属性名 → 转换函数) */
|
|
32
|
+
attributeConverters?: Record<string, (value: string) => any>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 批量注册的组件描述
|
|
36
|
+
*/
|
|
37
|
+
export interface ComponentRegistration {
|
|
38
|
+
/** Custom Element 标签名(必须包含 '-') */
|
|
39
|
+
tagName: string;
|
|
40
|
+
/** Lyt.js 组件选项 */
|
|
41
|
+
component: ComponentOptions;
|
|
42
|
+
/** Custom Element 配置 */
|
|
43
|
+
options?: CustomElementOptions;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 检测是否在浏览器环境运行
|
|
47
|
+
*/
|
|
48
|
+
export declare function isBrowser(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 将 Lyt.js 组件定义为 Web Component(Custom Element)
|
|
51
|
+
*
|
|
52
|
+
* @param tagName - Custom Element 标签名(必须包含 '-')
|
|
53
|
+
* @param componentOptions - Lyt.js 组件选项
|
|
54
|
+
* @param options - Custom Element 配置选项
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { defineCustomElement } from 'lyt'
|
|
59
|
+
* import { MyCounter } from './MyCounter'
|
|
60
|
+
*
|
|
61
|
+
* defineCustomElement('lyt-counter', MyCounter, {
|
|
62
|
+
* observedAttributes: ['initial-count', 'theme'],
|
|
63
|
+
* shadowMode: 'open',
|
|
64
|
+
* styles: ':host { display: block; padding: 16px; }'
|
|
65
|
+
* })
|
|
66
|
+
*
|
|
67
|
+
* // 在任何框架中使用
|
|
68
|
+
* // <lyt-counter initial-count="10" theme="dark"></lyt-counter>
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function defineCustomElement(tagName: string, componentOptions: ComponentOptions, options?: CustomElementOptions): void;
|
|
72
|
+
/**
|
|
73
|
+
* 批量注册多个 Lyt.js 组件为 Web Component
|
|
74
|
+
*
|
|
75
|
+
* @param components - 组件注册描述数组
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* registerComponents([
|
|
80
|
+
* { tagName: 'lyt-counter', component: CounterComponent },
|
|
81
|
+
* { tagName: 'lyt-button', component: ButtonComponent },
|
|
82
|
+
* { tagName: 'lyt-input', component: InputComponent },
|
|
83
|
+
* ])
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function registerComponents(components: ComponentRegistration[]): void;
|
|
87
|
+
/**
|
|
88
|
+
* 注销 Custom Element
|
|
89
|
+
*
|
|
90
|
+
* 注意:Custom Elements 规范不支持直接注销已注册的元素。
|
|
91
|
+
* 此函数将标签名加入黑名单,并尝试清理。
|
|
92
|
+
* 实际效果取决于浏览器实现。
|
|
93
|
+
*
|
|
94
|
+
* @param tagName - 要注销的标签名
|
|
95
|
+
*/
|
|
96
|
+
export declare function unregisterElement(tagName: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* 从 SFC 源码创建 Web Component
|
|
99
|
+
*
|
|
100
|
+
* 解析 SFC 源码,提取 template、script、style 部分,
|
|
101
|
+
* 然后创建并注册为 Custom Element。
|
|
102
|
+
*
|
|
103
|
+
* @param tagName - Custom Element 标签名
|
|
104
|
+
* @param sfcSource - SFC 源码字符串
|
|
105
|
+
* @param options - Custom Element 配置选项
|
|
106
|
+
* @returns Promise<void>
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* await defineCustomElementFromSFC('my-counter', `
|
|
111
|
+
* <template>
|
|
112
|
+
* <div>{{ count }}</div>
|
|
113
|
+
* <button @click="count++">+</button>
|
|
114
|
+
* </template>
|
|
115
|
+
* <script>
|
|
116
|
+
* export default {
|
|
117
|
+
* state: () => ({ count: 0 })
|
|
118
|
+
* }
|
|
119
|
+
* </script>
|
|
120
|
+
* <style>
|
|
121
|
+
* :host { display: block; }
|
|
122
|
+
* </style>
|
|
123
|
+
* `)
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function defineCustomElementFromSFC(tagName: string, sfcSource: string, options?: CustomElementOptions): Promise<void>;
|
|
127
|
+
//# sourceMappingURL=web-component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-component.d.ts","sourceRoot":"","sources":["../../src/web-component.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAM9D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,oDAAoD;IACpD,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