@lytjs/renderer 4.2.0 → 5.0.1
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/dom.cjs +1 -1
- package/dist/dom.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/miniapp.cjs +26 -4
- package/dist/miniapp.mjs +26 -4
- package/dist/native.cjs +1 -1
- package/dist/native.mjs +1 -1
- package/dist/ssr.cjs +1 -1
- package/dist/ssr.mjs +1 -1
- package/dist/types/dom/dom-ops.d.ts.map +1 -1
- package/dist/types/dom/dom-renderer.d.ts +3 -3
- package/dist/types/dom/dom-renderer.d.ts.map +1 -1
- package/dist/types/dom/patch-events.d.ts.map +1 -1
- package/dist/types/dom/patch-props.d.ts +2 -32
- package/dist/types/dom/patch-props.d.ts.map +1 -1
- package/dist/types/miniapp/api-adapter.d.ts +514 -0
- package/dist/types/miniapp/api-adapter.d.ts.map +1 -0
- package/dist/types/miniapp/index.d.ts +23 -2
- package/dist/types/miniapp/index.d.ts.map +1 -1
- package/dist/types/miniapp/miniapp-compiler.d.ts +269 -0
- package/dist/types/miniapp/miniapp-compiler.d.ts.map +1 -0
- package/dist/types/miniapp/miniapp-event-bridge.d.ts +255 -0
- package/dist/types/miniapp/miniapp-event-bridge.d.ts.map +1 -0
- package/dist/types/miniapp/miniapp-lifecycle.d.ts +224 -0
- package/dist/types/miniapp/miniapp-lifecycle.d.ts.map +1 -0
- package/dist/types/miniapp/miniapp-renderer.d.ts.map +1 -1
- package/dist/types/miniapp/miniapp-utils.d.ts +168 -0
- package/dist/types/miniapp/miniapp-utils.d.ts.map +1 -0
- package/dist/types/miniapp/shared-constants.d.ts +28 -0
- package/dist/types/miniapp/shared-constants.d.ts.map +1 -0
- package/dist/types/miniapp/style-compiler.d.ts +193 -0
- package/dist/types/miniapp/style-compiler.d.ts.map +1 -0
- package/dist/types/native/native-renderer.d.ts.map +1 -1
- package/dist/types/renderer-interfaces.d.ts +19 -19
- package/dist/types/renderer-interfaces.d.ts.map +1 -1
- package/dist/types/shared/abstract-renderer.d.ts +74 -0
- package/dist/types/shared/abstract-renderer.d.ts.map +1 -0
- package/dist/types/ssr/hydration.d.ts +1 -16
- package/dist/types/ssr/hydration.d.ts.map +1 -1
- package/dist/types/ssr/ssr-renderer.d.ts +9 -24
- package/dist/types/ssr/ssr-renderer.d.ts.map +1 -1
- package/dist/types/vapor/index.d.ts +1 -1
- package/dist/types/vapor/index.d.ts.map +1 -1
- package/dist/types/vapor/vapor-compiler.d.ts +9 -0
- package/dist/types/vapor/vapor-compiler.d.ts.map +1 -1
- package/dist/types/vapor/vapor-component.d.ts +8 -1
- package/dist/types/vapor/vapor-component.d.ts.map +1 -1
- package/dist/types/vapor/vapor-reactive.d.ts +27 -4
- package/dist/types/vapor/vapor-reactive.d.ts.map +1 -1
- package/dist/types/vapor/vapor-renderer.d.ts +4 -2
- package/dist/types/vapor/vapor-renderer.d.ts.map +1 -1
- package/dist/types/vnode.d.ts +76 -7
- package/dist/types/vnode.d.ts.map +1 -1
- package/dist/vapor.cjs +1 -1
- package/dist/vapor.mjs +1 -1
- package/package.json +4 -3
package/dist/types/vnode.d.ts
CHANGED
|
@@ -17,13 +17,15 @@ export interface VNode {
|
|
|
17
17
|
/** 节点类型:HTML 标签字符串 | 组件对象 | Symbol(Fragment/Text/Comment) */
|
|
18
18
|
type: string | object | symbol;
|
|
19
19
|
/** 节点属性 */
|
|
20
|
-
props: Record<string,
|
|
20
|
+
props: Record<string, unknown> | null;
|
|
21
21
|
/** 子节点:文本字符串 | VNode 数组 | 插槽对象 */
|
|
22
|
-
children: string | VNode[] | Record<string,
|
|
22
|
+
children: string | VNode[] | Record<string, unknown> | null;
|
|
23
23
|
/** 节点的唯一标识,用于列表 diff */
|
|
24
24
|
key: string | number | null;
|
|
25
25
|
/** ref 回调或 ref 对象 */
|
|
26
|
-
ref:
|
|
26
|
+
ref: ((el: unknown) => void) | {
|
|
27
|
+
current: unknown;
|
|
28
|
+
} | null;
|
|
27
29
|
/** 形状标记,描述节点类型和子节点形态 */
|
|
28
30
|
shapeFlag: number;
|
|
29
31
|
/** PatchFlag,标记哪些 props 是动态的 */
|
|
@@ -33,13 +35,17 @@ export interface VNode {
|
|
|
33
35
|
/** 动态 props 的键名列表 */
|
|
34
36
|
dynamicProps: string[] | null;
|
|
35
37
|
/** 关联的组件实例 */
|
|
36
|
-
component:
|
|
38
|
+
component: {
|
|
39
|
+
update?: () => void;
|
|
40
|
+
subTree?: VNode;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
} | null;
|
|
37
43
|
/** 应用上下文(用于 provide/inject 等跨层级通信) */
|
|
38
|
-
appContext: Record<string,
|
|
44
|
+
appContext: Record<string, unknown> | null;
|
|
39
45
|
/** 对应的真实 DOM 元素引用 */
|
|
40
|
-
el:
|
|
46
|
+
el: Element | Text | null;
|
|
41
47
|
/** Fragment 锚点 */
|
|
42
|
-
anchor:
|
|
48
|
+
anchor: Element | Text | null;
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
45
51
|
* VNode 形状标记
|
|
@@ -109,26 +115,89 @@ export declare const Text: unique symbol;
|
|
|
109
115
|
export declare const Comment: unique symbol;
|
|
110
116
|
/**
|
|
111
117
|
* 判断 VNode 是否为 Fragment 类型
|
|
118
|
+
*
|
|
119
|
+
* @param vnode - 待检测的虚拟节点
|
|
120
|
+
* @returns 如果节点类型为 Fragment 则返回 true
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { isFragment, Fragment, h } from '@lytjs/renderer'
|
|
125
|
+
*
|
|
126
|
+
* const vnode = h(Fragment, null, [h('div', null, 'A'), h('div', null, 'B')])
|
|
127
|
+
* console.log(isFragment(vnode)) // true
|
|
128
|
+
* ```
|
|
112
129
|
*/
|
|
113
130
|
export declare function isFragment(vnode: VNode): boolean;
|
|
114
131
|
/**
|
|
115
132
|
* 判断 VNode 是否为文本类型
|
|
133
|
+
*
|
|
134
|
+
* @param vnode - 待检测的虚拟节点
|
|
135
|
+
* @returns 如果节点类型为 Text 则返回 true
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { isTextVNode, Text, h } from '@lytjs/renderer'
|
|
140
|
+
*
|
|
141
|
+
* const vnode = h(Text, null, 'hello')
|
|
142
|
+
* console.log(isTextVNode(vnode)) // true
|
|
143
|
+
* ```
|
|
116
144
|
*/
|
|
117
145
|
export declare function isTextVNode(vnode: VNode): boolean;
|
|
118
146
|
/**
|
|
119
147
|
* 判断 VNode 是否为注释类型
|
|
148
|
+
*
|
|
149
|
+
* @param vnode - 待检测的虚拟节点
|
|
150
|
+
* @returns 如果节点类型为 Comment 则返回 true
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { isCommentVNode, Comment, h } from '@lytjs/renderer'
|
|
155
|
+
*
|
|
156
|
+
* const vnode = h(Comment, null, 'conditional comment')
|
|
157
|
+
* console.log(isCommentVNode(vnode)) // true
|
|
158
|
+
* ```
|
|
120
159
|
*/
|
|
121
160
|
export declare function isCommentVNode(vnode: VNode): boolean;
|
|
122
161
|
/**
|
|
123
162
|
* 判断两个 VNode 是否为相同类型
|
|
124
163
|
*
|
|
125
164
|
* 相同类型的定义:type 相同且 key 相同。
|
|
165
|
+
* 在 diff 算法中,只有相同类型的 VNode 才会进行 patch 复用。
|
|
166
|
+
*
|
|
167
|
+
* @param n1 - 第一个虚拟节点
|
|
168
|
+
* @param n2 - 第二个虚拟节点
|
|
169
|
+
* @returns 如果两个节点的 type 和 key 均相同则返回 true
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* import { isSameVNodeType, h } from '@lytjs/renderer'
|
|
174
|
+
*
|
|
175
|
+
* const a = h('div', { key: 'x' }, 'hello')
|
|
176
|
+
* const b = h('div', { key: 'x' }, 'world')
|
|
177
|
+
* const c = h('span', { key: 'x' }, 'hello')
|
|
178
|
+
*
|
|
179
|
+
* console.log(isSameVNodeType(a, b)) // true(type 和 key 相同)
|
|
180
|
+
* console.log(isSameVNodeType(a, c)) // false(type 不同)
|
|
181
|
+
* ```
|
|
126
182
|
*/
|
|
127
183
|
export declare function isSameVNodeType(n1: VNode, n2: VNode): boolean;
|
|
128
184
|
/**
|
|
129
185
|
* 判断 VNode 是否为 Block
|
|
130
186
|
*
|
|
131
187
|
* Block 的 dynamicChildren 是非 null 的数组。
|
|
188
|
+
* Block Tree 优化允许跳过静态子树的 diff,仅更新 dynamicChildren 列表中的节点。
|
|
189
|
+
*
|
|
190
|
+
* @param vnode - 待检测的虚拟节点
|
|
191
|
+
* @returns 如果节点是 Block 则返回 true
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* import { isBlock, h, openBlock } from '@lytjs/renderer'
|
|
196
|
+
*
|
|
197
|
+
* // Block 节点在编译时通过 openBlock() 创建
|
|
198
|
+
* const vnode = openBlock(() => h('div', null, h('span', null, 'dynamic')))
|
|
199
|
+
* console.log(isBlock(vnode)) // true
|
|
200
|
+
* ```
|
|
132
201
|
*/
|
|
133
202
|
export declare function isBlock(vnode: VNode): boolean;
|
|
134
203
|
//# sourceMappingURL=vnode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vnode.d.ts","sourceRoot":"","sources":["../../src/vnode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK;IACpB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;IAE9B,WAAW;IACX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"vnode.d.ts","sourceRoot":"","sources":["../../src/vnode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK;IACpB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;IAE9B,WAAW;IACX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAErC,kCAAkC;IAClC,QAAQ,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAE3D,wBAAwB;IACxB,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAE3B,qBAAqB;IACrB,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAA;IAE1D,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAA;IAEjB,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAA;IAEjB,6BAA6B;IAC7B,eAAe,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IAE/B,qBAAqB;IACrB,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAE7B,cAAc;IACd,SAAS,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,CAAA;IAElF,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAE1C,qBAAqB;IACrB,EAAE,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAAA;IAEzB,kBAAkB;IAClB,MAAM,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAAA;CAC9B;AAMD;;;;;GAKG;AACH,0BAAkB,UAAU;IAC1B,qBAAqB;IACrB,OAAO,IAAI;IAEX,YAAY;IACZ,oBAAoB,IAAI;IAExB,YAAY;IACZ,kBAAkB,IAAI;IAEtB,cAAc;IACd,aAAa,IAAI;IAEjB,aAAa;IACb,cAAc,KAAK;IAEnB,aAAa;IACb,cAAc,KAAK;CACpB;AAMD;;;;GAIG;AACH,0BAAkB,UAAU;IAC1B,WAAW;IACX,IAAI,IAAI;IACR,eAAe;IACf,KAAK,IAAI;IACT,eAAe;IACf,KAAK,IAAI;IACT,eAAe;IACf,KAAK,IAAI;IACT,sBAAsB;IACtB,UAAU,KAAK;IACf,mBAAmB;IACnB,eAAe,KAAK;IACpB,uBAAuB;IACvB,cAAc,KAAK;IACnB,wBAAwB;IACxB,gBAAgB,MAAM;IACtB,eAAe;IACf,UAAU,MAAM;IAChB,WAAW;IACX,aAAa,MAAM;IACnB,WAAW;IACX,OAAO,KAAK;IACZ,WAAW;IACX,IAAI,KAAK;CACV;AAMD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,eAAqB,CAAA;AAE1C;;GAEG;AACH,eAAO,MAAM,IAAI,eAAiB,CAAA;AAElC;;GAEG;AACH,eAAO,MAAM,OAAO,eAAoB,CAAA;AAMxC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEhD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEjD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEpD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAE7D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAE7C"}
|
package/dist/vapor.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var ge=(e,r)=>{for(var o in r)P(e,o,{get:r[o],enumerable:!0})},he=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of me(r))!ye.call(e,n)&&n!==o&&P(e,n,{get:()=>r[n],enumerable:!(t=ue(r,n))||t.enumerable});return e};var Ve=e=>he(P({},"__esModule",{value:!0}),e);var ke={};ge(ke,{Comment:()=>W,Fragment:()=>U,PatchFlags:()=>T,ShapeFlags:()=>V,Text:()=>H,bindAttr:()=>k,bindClass:()=>_,bindEach:()=>G,bindEvent:()=>M,bindIf:()=>Z,bindProp:()=>x,bindText:()=>w,compileToVapor:()=>j,createRenderer:()=>re,createVaporApp:()=>le,createVaporElement:()=>q,defineVaporComponent:()=>ae,getVaporDOMFactory:()=>v,parseTemplate:()=>B,renderVaporComponent:()=>pe,renderVaporNode:()=>m,setVaporDOMFactory:()=>se,vaporMount:()=>I,vaporPatch:()=>J});module.exports=Ve(ke);var oe=require("@lytjs/vdom");var V=(s=>(s[s.ELEMENT=1]="ELEMENT",s[s.FUNCTIONAL_COMPONENT=2]="FUNCTIONAL_COMPONENT",s[s.STATEFUL_COMPONENT=4]="STATEFUL_COMPONENT",s[s.TEXT_CHILDREN=8]="TEXT_CHILDREN",s[s.ARRAY_CHILDREN=16]="ARRAY_CHILDREN",s[s.SLOTS_CHILDREN=32]="SLOTS_CHILDREN",s))(V||{}),T=(d=>(d[d.TEXT=1]="TEXT",d[d.CLASS=2]="CLASS",d[d.STYLE=4]="STYLE",d[d.PROPS=8]="PROPS",d[d.FULL_PROPS=16]="FULL_PROPS",d[d.STABLE_FRAGMENT=32]="STABLE_FRAGMENT",d[d.KEYED_FRAGMENT=64]="KEYED_FRAGMENT",d[d.UNKEYED_FRAGMENT=128]="UNKEYED_FRAGMENT",d[d.NEED_PATCH=256]="NEED_PATCH",d[d.DYNAMIC_SLOTS=512]="DYNAMIC_SLOTS",d[d.HOISTED=-1]="HOISTED",d[d.BAIL=-2]="BAIL",d))(T||{}),U=Symbol("Fragment"),H=Symbol("Text"),W=Symbol("Comment");function N(e){return e.type===U}function R(e){return e.type===H}function b(e){return e.type===W}function Q(e,r){return e.type===r.type&&e.key===r.key}function K(e){return Array.isArray(e.dynamicChildren)}function ee(e,r,o,t){if(o==="class")e.setClass(r,t);else if(o==="style")e.setStyle(r,t);else if(o.startsWith("on")||o.startsWith("@")){let n=o.startsWith("@")?o.slice(1).toLowerCase():o.slice(2).toLowerCase();e.addEventListener(r,n,t)}else o==="key"||o==="ref"||e.setAttribute(r,o,t)}function Y(e,r,o,t,n){if(o==="class")e.setClass(r,t);else if(o==="style")e.setStyle(r,t||{});else if(o.startsWith("on")||o.startsWith("@")){let i=o.startsWith("@")?o.slice(1).toLowerCase():o.slice(2).toLowerCase();n&&e.removeEventListener(r,i,n),t&&e.addEventListener(r,i,t)}else e.setAttribute(r,o,t)}function $(e,r,o,t){for(let n in t){if(n==="key"||n==="ref")continue;let i=o[n],s=t[n];s!==i&&Y(e,r,n,s,i)}for(let n in o)if(!(n==="key"||n==="ref")&&!(n in t))if(n==="class")e.setClass(r,"");else if(n==="style")e.setStyle(r,{});else if(n.startsWith("on")||n.startsWith("@")){let i=n.startsWith("@")?n.slice(1).toLowerCase():n.slice(2).toLowerCase();e.removeEventListener(r,i,o[n])}else e.removeAttribute(r,n)}function z(e,r,o,t,n,i){let{shapeFlag:s}=o;if(N(o)){ve(e,r,o,t,n,i);return}if(R(o)){let a=e.createText(o.children);o.el=a,e.insert(t,a,n);return}if(b(o)){let a=e.createComment(o.children);o.el=a,e.insert(t,a,n);return}if(s&1){Ne(e,r,o,t,n,i);return}if(s&6){xe(r,o,t,n,i);return}}function Ne(e,r,o,t,n,i){let s=o.type,a=e.createElement(s);if(o.el=a,o.props)for(let p in o.props){let f=o.props[p];ee(e,a,p,f)}let{shapeFlag:l,children:c}=o;l&8?a.textContent=c:l&16&&A(r,c,a,null,i),e.insert(t,a,n)}function A(e,r,o,t,n){for(let i=0;i<r.length;i++)e(null,r[i],o,t,n)}function ve(e,r,o,t,n,i){let{children:s}=o,a=e.createComment("");e.insert(t,a,n),Array.isArray(s)&&s.length>0&&A(r,s,t,a,i),o.el=a,o.anchor=a}function xe(e,r,o,t,n){let i=r.component;i&&i.update&&i.update(),i&&i.subTree&&(e(null,i.subTree,o,t,i),r.el=i.subTree.el)}function te(e,r,o,t){let{shapeFlag:n,children:i}=o;if(N(o)){if(Array.isArray(i))for(let s=0;s<i.length;s++)r(i[s],t);o.anchor&&o.anchor.parentNode&&e.remove(o.anchor);return}if(n&6){o.component&&o.component.subTree&&r(o.component.subTree,t);return}o.el&&e.remove(o.el)}function L(e,r){for(let o=0;o<r.length;o++)e(r[o])}var S=require("@lytjs/vdom");function O(e,r,o,t,n,i=null,s=null){if(t==null){o&&r(o,n);return}if(o===null){z(e,X(e,r),t,n,i,s);return}if(K(t)&&K(o)){Re(e,r,o,t,n,s);return}if(!Q(o,t)){r(o,n),z(e,X(e,r),t,n,i,s);return}t.el=o.el,t.anchor=o.anchor;let{shapeFlag:a}=t;if(N(t)){Te(e,r,o,t,n,i,s);return}if(R(t)){t.children!==o.children&&(t.el.nodeValue=t.children);return}if(b(t)){t.children!==o.children&&(t.el.nodeValue=t.children);return}if(a&1){Ce(e,r,o,t,s);return}if(a&6){be(o,t,s);return}}function X(e,r){return(o,t,n,i,s)=>{O(e,r,o,t,n,i,s)}}function Ce(e,r,o,t,n=null){let i=t.el=o.el,s=o.props||{},a=t.props||{},{patchFlag:l,dynamicProps:c}=t;if(l&&l>0){if(l&1&&o.children!==t.children&&(i.textContent=t.children),l&2&&s.class!==a.class&&e.setClass(i,a.class),l&4&&s.style!==a.style&&e.setStyle(i,a.style||{}),l&8&&c)for(let p=0;p<c.length;p++){let f=c[p],d=s[f],u=a[f];u!==d&&Y(e,i,f,u,d)}l&16&&$(e,i,s,a)}else $(e,i,s,a);(!l||!(l&1))&&ne(e,r,o,t,i,null,n)}function ne(e,r,o,t,n,i,s){let a=o.shapeFlag,l=t.shapeFlag,c=o.children,p=t.children;if(l&8){a&16&&L(r,c),c!==p&&(n.textContent=p);return}if(l&16){a&16?Ee(e,r,c,p,n,i,s):(a&8&&(n.textContent=""),A(X(e,r),p,n,i,s));return}p==null&&(a&8?n.textContent="":a&16&&L(r,c))}function Ee(e,r,o,t,n,i,s){t.every(l=>l.key!==null&&l.key!==void 0)&&o.every(l=>l.key!==null&&l.key!==void 0)?(0,S.patchKeyedChildren)(o,t,n,i,s,null,!1):(0,S.patchUnkeyedChildren)(o,t,n,i,s,null,!1)}function Te(e,r,o,t,n,i,s){let a=o.children,l=t.children;Array.isArray(l)&&l.length>0?(ne(e,r,o,t,n,i,s),t.el=l[0].el,t.anchor=l[l.length-1].el?e.nextSibling(l[l.length-1].el):i):Array.isArray(a)&&a.length>0&&l===null?(L(r,a),t.el=o.el,t.anchor=o.anchor):(t.el=o.el,t.anchor=o.anchor)}function Re(e,r,o,t,n,i){let s=o.dynamicChildren,a=t.dynamicChildren;for(let l=0;l<a.length;l++)O(e,r,s[l],a[l],n,null,i)}function be(e,r,o){r.component=e.component,r.el=e.el,r.component&&r.component.update&&r.component.update()}function re(e){function r(n,i){te(e,r,n,i)}(0,oe.registerDOMOperations)({insert(n,i,s){e.insert(i,n,s)},createElement(n){return e.createElement(n)},createText(n){return e.createText(n)},setText(n,i){n.nodeValue=i},setElementText(n,i){n.textContent=i},remove(n){e.remove(n)},createComment(n){return e.createComment(n)},mount(n,i,s,a,l,c,p){t(null,n,i,s,a)},patch(n,i,s,a,l,c,p,f){t(n,i,s,a,l)},unmount(n,i,s,a){r(n)},move(n,i,s){e.insert(i,n.el,s)}});function t(n,i,s,a,l){O(e,r,n,i,s,a,l)}return{mount(n,i){i.nodeType===1&&(i.textContent=""),t(null,n,i,null,null)},patch(n,i,s){var a;t(n,i,s||((a=n.el)==null?void 0:a.parentNode),null,null)},unmount(n,i){r(n,i)}}}var h=require("@lytjs/reactivity/signal");function w(e,r){return(0,h.effect)(()=>{let t=r();e.textContent=t==null?"":String(t)})}function x(e,r,o){return(0,h.effect)(()=>{let n=o();e[r]=n})}function k(e,r,o){return(0,h.effect)(()=>{let n=o();n==null||n===!1?e.removeAttribute(r):e.setAttribute(r,n===!0?"":String(n))})}function _(e,r){return(0,h.effect)(()=>{let t=r();if(typeof t=="string")e.className=t;else if(Array.isArray(t))e.className=t.filter(Boolean).join(" ");else if(typeof t=="object"&&t!==null){let n=[],i=t;for(let s of Object.keys(i))i[s]&&n.push(s);e.className=n.join(" ")}else e.className=""})}function M(e,r,o){return e.addEventListener(r,o),()=>{e.removeEventListener(r,o)}}function Z(e,r){return(0,h.effect)(()=>{let t=r(),n=e;t?(n.style=n.style||{},n.style.display==="none"&&(n.style.display=""),n.hidden=!1):(n.style=n.style||{},n.style.display="none",n.hidden=!0)})}function G(e,r,o,t){let n=[],i=[],s=new Map,a=(0,h.effect)(()=>{let l=r();if(!Array.isArray(l))return;let c=l.map((p,f)=>t?t(p,f):f);if(c.length===i.length){let p=!0;for(let f=0;f<c.length;f++)if(c[f]!==i[f]){p=!1;break}if(p){for(let f=0;f<l.length;f++){let d=o(l[f],f),u=n[f];u&&u.parentNode===e&&e.replaceChild(d,u),n[f]=d}return}}for(let p of n)p.parentNode===e&&e.removeChild(p);s.clear(),n=[],i=[];for(let p=0;p<l.length;p++){let f=o(l[p],p);e.appendChild(f),n.push(f),i.push(c[p]),s.set(c[p],f)}});return()=>{a();for(let l of n)l.parentNode===e&&e.removeChild(l);n=[],i=[],s.clear()}}var D=e=>{if(typeof document!="undefined")return document.createElement(e);throw new Error("[lyt:vapor] \u672A\u8BBE\u7F6E DOM \u5DE5\u5382\u51FD\u6570\u3002\u5728\u975E\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\u8BF7\u8C03\u7528 setVaporDOMFactory()")};function se(e){D=e}function v(){return D}function q(e,r,...o){let t={tag:e,children:[],props:{},events:{},bindings:[]};if(r)for(let[n,i]of Object.entries(r))if(n.startsWith("on")&&typeof i=="function"&&!ie(i)){let s=n.slice(2).toLowerCase();t.events[s]=i}else ie(i)?n==="textContent"||n==="text"?t.bindings.push({type:"text",target:"textContent",signal:i}):n==="className"||n==="class"?t.bindings.push({type:"class",target:"className",signal:i}):n==="style"?t.bindings.push({type:"style",target:"style",signal:i}):t.bindings.push({type:"prop",target:n,signal:i}):t.props[n]=i;for(let n of o)typeof n=="string"?t.children.push({tag:"#text",children:[],props:{},events:{},bindings:[],text:n}):t.children.push(n);return t}function ie(e){if(typeof e!="function")return!1;let r=e;return!!(r._subscribe||r.set)&&!e.toString().startsWith("class")}function m(e){if(e.tag==="#text"){let t=D("#text");return t.textContent=e.text||"",t.nodeType=3,t}let r=D(e.tag);e.el=r;let o=r;for(let[t,n]of Object.entries(e.props))if(t==="style"&&typeof n=="object"&&n!==null)for(let[i,s]of Object.entries(n))o.style[i]=s;else t==="className"||t==="class"?r.className=String(n):o[t]=n;for(let t of e.bindings)t.signal&&(t.type==="text"?w(r,t.signal):t.type==="prop"?x(r,t.target,t.signal):t.type==="attr"?k(r,t.target,t.signal):t.type==="class"?_(r,t.signal):t.type==="style"&&x(r,"style",t.signal));for(let[t,n]of Object.entries(e.events))M(r,t,n);for(let t of e.children){let n=m(t);r.appendChild(n)}return r}function J(e,r,o){if(e.tag!==r.tag){let s=m(r);e.el&&e.el.parentNode===o&&o.removeChild(e.el),o.appendChild(s);return}let t=e.el||m(e);r.el=t;let n=t;for(let[s,a]of Object.entries(r.props))if(s==="style"&&typeof a=="object"&&a!==null)for(let[l,c]of Object.entries(a))n.style[l]=c;else s==="className"||s==="class"?t.className=String(a):n[s]=a;r.text!==void 0&&(t.textContent=r.text);for(let[s,a]of Object.entries(e.events))r.events[s]||t.removeEventListener(s,a);for(let[s,a]of Object.entries(r.events))e.events[s]!==a&&(e.events[s]&&t.removeEventListener(s,e.events[s]),t.addEventListener(s,a));let i=Math.max(e.children.length,r.children.length);for(let s=0;s<i;s++){let a=e.children[s],l=r.children[s];if(!a&&l){let c=m(l);t.appendChild(c)}else a&&!l?a.el&&a.el.parentNode===t&&t.removeChild(a.el):a&&l&&J(a,l,t)}}function I(e,r){let o=r.setup?r.setup():{};r.beforeMount&&r.beforeMount();let t;if(r.render){let i=r.render(o,q);t=Array.isArray(i)?i:[i]}else t=[];let n=[];for(let i of t){let s=m(i);e.appendChild(s),n.push(s)}return r.mounted&&r.mounted(),()=>{r.beforeUnmount&&r.beforeUnmount();for(let i of n)e.removeChild(i);r.unmounted&&r.unmounted()}}function B(e){var t,n,i,s,a;let r={type:"fragment",children:[]},o=e.trim();for(;o.length>0;){let l=o.match(/^<([a-zA-Z][a-zA-Z0-9-]*)([\s\S]*?)(\/?)>/);if(l){let c=l[1],p=l[2],f=l[3]==="/",{props:d,events:u,directives:g}=Le(p),y={type:"element",tag:c,props:d,events:u,directives:g,children:[]};if(o=o.slice(l[0].length),f){((t=r.children)!=null?t:[]).push(y);continue}let ce=`</${c}>`,F=Ae(o,c);if(F===-1)throw new Error(`[lyt:vapor:compiler] \u672A\u627E\u5230\u95ED\u5408\u6807\u7B7E: </${c}>`);let de=o.slice(0,F);o=o.slice(F+ce.length);let fe=B(de);y.children=fe.children||[],((n=r.children)!=null?n:[]).push(y)}else{let c=o.indexOf("<"),p;if(c===-1?(p=o,o=""):(p=o.slice(0,c),o=o.slice(c)),p.trim())if(p.includes("{{")){let f=Se(p);for(let d of f)d.type==="text"?((i=r.children)!=null?i:[]).push({type:"text",text:d.value}):((s=r.children)!=null?s:[]).push({type:"interpolation",expression:d.value})}else((a=r.children)!=null?a:[]).push({type:"text",text:p})}}return r}function Ae(e,r){let o=1,t=0,n=`<${r}`,i=`</${r}>`;for(;t<e.length&&o>0;){let s=e.indexOf(n,t),a=e.indexOf(i,t);if(a===-1)return-1;if(s!==-1&&s<a){let l=e[s+n.length];l===">"||l===" "||l==="/"?(o++,t=s+n.length):(t=a+i.length,o--)}else t=a+i.length,o--}return o===0?t-i.length:-1}function Le(e){let r={},o={},t={},n=/([a-zA-Z@:][a-zA-Z0-9@:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g,i;for(;(i=n.exec(e))!==null;){let s=i[1],a=i[2]||i[3];if(s.startsWith("on:")){let l=s.slice(3);o[l]=a}else if(s.startsWith(":")){let l=s.slice(1);r[l]=a}else if(s==="v-if")t.if=a;else if(s==="v-each"){let l=a.match(/^\s*(\w+)\s+in\s+(.+)\s*$/);l&&(t.each={item:l[1],expression:l[2]})}else r[s]=a}return{props:r,events:o,directives:t}}function Se(e){let r=[],o=/\{\{([\s\S]*?)\}\}/g,t=0,n;for(;(n=o.exec(e))!==null;)n.index>t&&r.push({type:"text",value:e.slice(t,n.index)}),r.push({type:"interpolation",value:n[1].trim()}),t=n.index+n[0].length;return t<e.length&&r.push({type:"text",value:e.slice(t)}),r}function j(e){let r=B(e);return{render:Oe(r),ast:r}}function Oe(e){return function(o){let t=v();return E(e,o,t)}}function E(e,r,o){var t,n;if(e.type==="fragment"){if(e.children&&e.children.length===1)return E(e.children[0],r,o);let i=o("div");if(i.nodeType=11,i.childNodes=i.childNodes||[],e.children)for(let s of e.children){let a=E(s,r,o);i.appendChild?i.appendChild(a):i.childNodes.push(a)}return i}if(e.type==="text"){let i=o("#text");return i.textContent=e.text||"",i.nodeType=3,i}if(e.type==="interpolation"){let i=o("span"),s=e.expression||"",a=C(r,s);return i.textContent=a!=null?String(a):"",i}if(e.type==="element"){if((t=e.directives)!=null&&t.each){let{item:a,expression:l}=e.directives.each,c=C(r,l),p=o("#fragment");if(p.childNodes=[],p.nodeType=11,Array.isArray(c))for(let f=0;f<c.length;f++){let d={...r,[a]:c[f],index:f},u=o(e.tag||"div");if(e.props)for(let[g,y]of Object.entries(e.props))g==="class"||g==="className"?u.className=y:u[g]=y;if(e.children)for(let g of e.children){let y=E(g,d,o);u.appendChild(y)}p.appendChild(u)}return p}let i=o(e.tag||"div"),s=i;if((n=e.directives)!=null&&n.if&&(C(r,e.directives.if)||(s.style=s.style||{},s.style.display="none",s.hidden=!0)),e.props)for(let[a,l]of Object.entries(e.props))if(a.startsWith(":")){let c=a.slice(1),p=C(r,l);s[c]=p}else a==="class"||a==="className"?i.className=l:s[a]=l;if(e.events)for(let[a,l]of Object.entries(e.events)){let c=C(r,l);typeof c=="function"&&i.addEventListener(a,c)}if(e.children)for(let a of e.children){let l=E(a,r,o);if(l.nodeType===11&&l.childNodes)for(let c of l.childNodes)i.appendChild(c);else i.appendChild(l)}return i}return o("div")}function C(e,r){let o=r.trim();if(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(o)){let i=e[o];return typeof i=="function"&&!i.prototype?i():i}let t=o.split("."),n=e;for(let i of t){if(n==null)return;n=n[i],typeof n=="function"&&!n.prototype&&t.indexOf(i)<t.length-1&&(n=n())}return n}function ae(e){return e}function le(e){let r=!1,o=null,t=null;return{mount(n){if(!r){if(typeof n=="string")if(typeof document!="undefined"){let i=document.querySelector(n);if(!i)throw new Error(`[lyt:vapor] \u672A\u627E\u5230\u6302\u8F7D\u76EE\u6807: ${n}`);t=i}else throw new Error("[lyt:vapor] \u5728\u975E\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\uFF0C\u8BF7\u76F4\u63A5\u4F20\u5165\u5BB9\u5668\u5143\u7D20");else t=n;o=I(t,e),r=!0}},unmount(){r&&(o&&(o(),o=null),r=!1,t=null)}}}function pe(e){let r=e.setup?e.setup():{};e.beforeMount&&e.beforeMount();let o;if(e.template){let{render:t}=j(e.template);o=t(r)}else if(e.render){let t=e.render(r,we),n=Array.isArray(t)?t:[t];if(n.length===1)o=m(n[0]);else{o=v()("div");for(let s of n)o.appendChild(m(s))}}else throw new Error("[lyt:vapor] \u7EC4\u4EF6\u5FC5\u987B\u63D0\u4F9B template \u6216 render \u51FD\u6570");return e.mounted&&e.mounted(),o}function we(e,r,...o){let t={tag:e,children:[],props:r||{},events:{},bindings:[]};for(let n of o)typeof n=="string"?t.children.push({tag:"#text",children:[],props:{},events:{},bindings:[],text:n}):t.children.push(n);return t}
|
|
1
|
+
"use strict";var G=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var Re=(e,o)=>{for(var t in o)G(e,t,{get:o[t],enumerable:!0})},be=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of ve(o))!xe.call(e,n)&&n!==t&&G(e,n,{get:()=>o[n],enumerable:!(r=Ne(o,n))||r.enumerable});return e};var Te=e=>be(G({},"__esModule",{value:!0}),e);var He={};Re(He,{Comment:()=>Q,Fragment:()=>q,PatchFlags:()=>B,ShapeFlags:()=>v,Text:()=>J,bindAttr:()=>k,bindClass:()=>A,bindEach:()=>O,bindEvent:()=>U,bindHTML:()=>ie,bindIf:()=>L,bindProp:()=>w,bindStyle:()=>S,bindText:()=>T,compileToVapor:()=>Z,createRenderer:()=>fe,createVaporApp:()=>Ce,createVaporElement:()=>_,defineVaporComponent:()=>Ve,getVaporDOMFactory:()=>R,parseTemplate:()=>X,renderVaporComponent:()=>Ee,renderVaporNode:()=>h,setVaporDOMFactory:()=>ge,vaporMount:()=>Y,vaporPatch:()=>se});module.exports=Te(He);var ue=require("@lytjs/vdom");var v=(l=>(l[l.ELEMENT=1]="ELEMENT",l[l.FUNCTIONAL_COMPONENT=2]="FUNCTIONAL_COMPONENT",l[l.STATEFUL_COMPONENT=4]="STATEFUL_COMPONENT",l[l.TEXT_CHILDREN=8]="TEXT_CHILDREN",l[l.ARRAY_CHILDREN=16]="ARRAY_CHILDREN",l[l.SLOTS_CHILDREN=32]="SLOTS_CHILDREN",l))(v||{}),B=(c=>(c[c.TEXT=1]="TEXT",c[c.CLASS=2]="CLASS",c[c.STYLE=4]="STYLE",c[c.PROPS=8]="PROPS",c[c.FULL_PROPS=16]="FULL_PROPS",c[c.STABLE_FRAGMENT=32]="STABLE_FRAGMENT",c[c.KEYED_FRAGMENT=64]="KEYED_FRAGMENT",c[c.UNKEYED_FRAGMENT=128]="UNKEYED_FRAGMENT",c[c.NEED_PATCH=256]="NEED_PATCH",c[c.DYNAMIC_SLOTS=512]="DYNAMIC_SLOTS",c[c.HOISTED=-1]="HOISTED",c[c.BAIL=-2]="BAIL",c))(B||{}),q=Symbol("Fragment"),J=Symbol("Text"),Q=Symbol("Comment");function x(e){return e.type===q}function I(e){return e.type===J}function D(e){return e.type===Q}function ae(e,o){return e.type===o.type&&e.key===o.key}function ee(e){return Array.isArray(e.dynamicChildren)}function pe(e,o,t,r){if(t==="class")e.setClass(o,r);else if(t==="style")e.setStyle(o,r);else if(t.startsWith("on")||t.startsWith("@")){let n=t.startsWith("@")?t.slice(1).toLowerCase():t.slice(2).toLowerCase();e.addEventListener(o,n,r)}else t==="key"||t==="ref"||e.setAttribute(o,t,r)}function ne(e,o,t,r,n){if(t==="class")e.setClass(o,r);else if(t==="style")e.setStyle(o,r||{});else if(t.startsWith("on")||t.startsWith("@")){let i=t.startsWith("@")?t.slice(1).toLowerCase():t.slice(2).toLowerCase();n&&e.removeEventListener(o,i,n),r&&e.addEventListener(o,i,r)}else e.setAttribute(o,t,r)}function te(e,o,t,r){for(let n in r){if(n==="key"||n==="ref")continue;let i=t[n],l=r[n];l!==i&&ne(e,o,n,l,i)}for(let n in t)if(!(n==="key"||n==="ref")&&!(n in r))if(n==="class")e.setClass(o,"");else if(n==="style")e.setStyle(o,{});else if(n.startsWith("on")||n.startsWith("@")){let i=n.startsWith("@")?n.slice(1).toLowerCase():n.slice(2).toLowerCase();e.removeEventListener(o,i,t[n])}else e.removeAttribute(o,n)}function oe(e,o,t,r,n,i){let{shapeFlag:l}=t;if(x(t)){ke(e,o,t,r,n,i);return}if(I(t)){let s=e.createText(t.children);t.el=s,e.insert(r,s,n);return}if(D(t)){let s=e.createComment(t.children);t.el=s,e.insert(r,s,n);return}if(l&1){we(e,o,t,r,n,i);return}if(l&6){Ae(o,t,r,n,i);return}}function we(e,o,t,r,n,i){let l=t.type,s=e.createElement(l);if(t.el=s,t.props)for(let d in t.props){let g=t.props[d];pe(e,s,d,g)}let{shapeFlag:a,children:p}=t;a&8?s.textContent=p:a&16&&j(o,p,s,null,i),e.insert(r,s,n)}function j(e,o,t,r,n){for(let i=0;i<o.length;i++)e(null,o[i],t,r,n)}function ke(e,o,t,r,n,i){let{children:l}=t,s=e.createComment("");e.insert(r,s,n),Array.isArray(l)&&l.length>0&&j(o,l,r,s,i),t.el=s,t.anchor=s}function Ae(e,o,t,r,n){let i=o.component;i&&i.update&&i.update(),i&&i.subTree&&(e(null,i.subTree,t,r,i),o.el=i.subTree.el)}function ce(e,o,t,r){let{shapeFlag:n,children:i}=t;if(x(t)){if(Array.isArray(i))for(let l=0;l<i.length;l++)o(i[l],r);t.anchor&&t.anchor.parentNode&&e.remove(t.anchor);return}if(n&6){t.component&&t.component.subTree&&o(t.component.subTree,r);return}t.el&&e.remove(t.el)}function H(e,o){for(let t=0;t<o.length;t++)e(o[t])}var P=require("@lytjs/vdom");function F(e,o,t,r,n,i=null,l=null){if(r==null){t&&o(t,n);return}if(t===null){oe(e,re(e,o),r,n,i,l);return}if(ee(r)&&ee(t)){_e(e,o,t,r,n,l);return}if(!ae(t,r)){o(t,n),oe(e,re(e,o),r,n,i,l);return}r.el=t.el,r.anchor=t.anchor;let{shapeFlag:s}=r;if(x(r)){Oe(e,o,t,r,n,i,l);return}if(I(r)){r.children!==t.children&&(r.el.nodeValue=r.children);return}if(D(r)){r.children!==t.children&&(r.el.nodeValue=r.children);return}if(s&1){Se(e,o,t,r,l);return}if(s&6){Me(t,r,l);return}}function re(e,o){return(t,r,n,i,l)=>{F(e,o,t,r,n,i,l)}}function Se(e,o,t,r,n=null){let i=r.el=t.el,l=t.props||{},s=r.props||{},{patchFlag:a,dynamicProps:p}=r;if(a&&a>0){if(a&1&&t.children!==r.children&&(i.textContent=r.children),a&2&&l.class!==s.class&&e.setClass(i,s.class),a&4&&l.style!==s.style&&e.setStyle(i,s.style||{}),a&8&&p)for(let d=0;d<p.length;d++){let g=p[d],c=l[g],f=s[g];f!==c&&ne(e,i,g,f,c)}a&16&&te(e,i,l,s)}else te(e,i,l,s);(!a||!(a&1))&&de(e,o,t,r,i,null,n)}function de(e,o,t,r,n,i,l){let s=t.shapeFlag,a=r.shapeFlag,p=t.children,d=r.children;if(a&8){s&16&&H(o,p),p!==d&&(n.textContent=d);return}if(a&16){s&16?Le(e,o,p,d,n,i,l):(s&8&&(n.textContent=""),j(re(e,o),d,n,i,l));return}d==null&&(s&8?n.textContent="":s&16&&H(o,p))}function Le(e,o,t,r,n,i,l){r.every(a=>a.key!==null&&a.key!==void 0)&&t.every(a=>a.key!==null&&a.key!==void 0)?(0,P.patchKeyedChildren)(t,r,n,i,l,null,!1):(0,P.patchUnkeyedChildren)(t,r,n,i,l,null,!1)}function Oe(e,o,t,r,n,i,l){let s=t.children,a=r.children;Array.isArray(a)&&a.length>0?(de(e,o,t,r,n,i,l),r.el=a[0].el,r.anchor=a[a.length-1].el?e.nextSibling(a[a.length-1].el):i):Array.isArray(s)&&s.length>0&&a===null?(H(o,s),r.el=t.el,r.anchor=t.anchor):(r.el=t.el,r.anchor=t.anchor)}function _e(e,o,t,r,n,i){let l=t.dynamicChildren,s=r.dynamicChildren;for(let a=0;a<s.length;a++)F(e,o,l[a],s[a],n,null,i)}function Me(e,o,t){o.component=e.component,o.el=e.el,o.component&&o.component.update&&o.component.update()}function fe(e){function o(n,i){ce(e,o,n,i)}(0,ue.registerDOMOperations)({insert(n,i,l){e.insert(i,n,l)},createElement(n){return e.createElement(n)},createText(n){return e.createText(n)},setText(n,i){n.nodeValue=i},setElementText(n,i){n.textContent=i},remove(n){e.remove(n)},createComment(n){return e.createComment(n)},mount(n,i,l,s,a,p,d){r(null,n,i,l,s)},patch(n,i,l,s,a,p,d,g){r(n,i,l,s,a)},unmount(n,i,l,s){o(n)},move(n,i,l){e.insert(i,n.el,l)}});function r(n,i,l,s,a){F(e,o,n,i,l,s,a)}return{mount(n,i){i.nodeType===1&&(i.textContent=""),r(null,n,i,null,null)},patch(n,i,l){var s;r(n,i,l||((s=n.el)==null?void 0:s.parentNode),null,null)},unmount(n,i){o(n,i)}}}var V=require("@lytjs/reactivity/signal");function T(e,o){return(0,V.effect)(()=>{let r=o();e.textContent=r==null?"":String(r)})}function w(e,o,t){return(0,V.effect)(()=>{let n=t();e[o]=n})}function k(e,o,t){return(0,V.effect)(()=>{let n=t();n==null||n===!1?e.removeAttribute(o):e.setAttribute(o,n===!0?"":String(n))})}function A(e,o){return(0,V.effect)(()=>{let r=o();if(typeof r=="string")e.className=r;else if(Array.isArray(r))e.className=r.filter(Boolean).join(" ");else if(typeof r=="object"&&r!==null){let n=[],i=r;for(let l of Object.keys(i))i[l]&&n.push(l);e.className=n.join(" ")}else e.className=""})}function U(e,o,t){return e.addEventListener(o,t),()=>{e.removeEventListener(o,t)}}function S(e,o){return(0,V.effect)(()=>{let r=o();if(typeof r=="string")e.style=r;else if(typeof r=="object"&&r!==null){let n=e.style;for(let i of Object.keys(n))n[i]="";for(let[i,l]of Object.entries(r))n[i]=l}else e.style=""})}function ie(e,o){return(0,V.effect)(()=>{let r=o(),n=r==null?"":String(r);e.innerHTML!==n&&(e.innerHTML=n)})}function L(e,o,t){let r=e.parentNode!==null,n=t||null;!n&&e.parentNode&&(n=e.parentNode);let i=(0,V.effect)(()=>{o()?r||(n&&n.parentNode?n.parentNode.insertBefore(e,n.nextSibling):n&&n.appendChild(e),r=!0):r&&e.parentNode&&(e.parentNode.removeChild(e),r=!1)});return()=>{i(),r&&e.parentNode&&e.parentNode.removeChild(e)}}function O(e,o,t,r){let n=[],i=[],l=new Map,s=(0,V.effect)(()=>{let a=o();if(!Array.isArray(a))return;let p=a.map((f,u)=>r?r(f,u):u);if(p.length===i.length){let f=!0;for(let u=0;u<p.length;u++)if(p[u]!==i[u]){f=!1;break}if(f){for(let u=0;u<a.length;u++){let m=t(a[u],u),y=n[u];y&&y.parentNode===e&&e.replaceChild(m,y),n[u]=m,l.set(p[u],m)}return}}let d=new Set(i),g=new Set(p),c=new Map;for(let f=0;f<a.length;f++){let u=p[f];if(d.has(u)&&l.has(u)){let m=l.get(u);c.set(u,m),l.delete(u)}else{let m=t(a[f],f);c.set(u,m)}}for(let[f,u]of l)!g.has(f)&&u.parentNode===e&&e.removeChild(u);for(let f of n)f.parentNode===e&&e.removeChild(f);n=[],i=[];for(let f=0;f<a.length;f++){let u=p[f],m=c.get(u);e.appendChild(m),n.push(m),i.push(u)}l.clear();for(let[f,u]of c)l.set(f,u)});return()=>{s();for(let a of n)a.parentNode===e&&e.removeChild(a);n=[],i=[],l.clear()}}var W=require("@lytjs/common"),K=e=>{if(typeof document!="undefined")return document.createElement(e);throw new W.LytError(W.LytErrorCodes.LYT_RENDERER_VAPOR_ERROR,"\u672A\u8BBE\u7F6E DOM \u5DE5\u5382\u51FD\u6570\u3002\u5728\u975E\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\u8BF7\u8C03\u7528 setVaporDOMFactory()")};function ge(e){K=e}function R(){return K}function _(e,o,...t){let r={tag:e,children:[],props:{},events:{},bindings:[]};if(o)for(let[n,i]of Object.entries(o))if(n.startsWith("on")&&typeof i=="function"&&!me(i)){let l=n.slice(2).toLowerCase();r.events[l]=i}else me(i)?n==="textContent"||n==="text"?r.bindings.push({type:"text",target:"textContent",signal:i}):n==="className"||n==="class"?r.bindings.push({type:"class",target:"className",signal:i}):n==="style"?r.bindings.push({type:"style",target:"style",signal:i}):r.bindings.push({type:"prop",target:n,signal:i}):r.props[n]=i;for(let n of t)typeof n=="string"?r.children.push({tag:"#text",children:[],props:{},events:{},bindings:[],text:n}):r.children.push(n);return r}function me(e){if(typeof e!="function")return!1;let o=e;return!!o._subscribe||!!(o.set&&o._subscribe)}function h(e){if(e.tag==="#text"){let n=K("#text");return n.textContent=e.text||"",n.nodeType=3,n}let o=K(e.tag);e.el=o;let t=o;for(let[n,i]of Object.entries(e.props))if(n==="style"&&typeof i=="object"&&i!==null)for(let[l,s]of Object.entries(i))t.style[l]=s;else n==="className"||n==="class"?o.className=String(i):t[n]=i;let r=[];for(let n of e.bindings){if(!n.signal)continue;let i;if(n.type==="text")i=T(o,n.signal);else if(n.type==="prop")i=w(o,n.target,n.signal);else if(n.type==="attr")i=k(o,n.target,n.signal);else if(n.type==="class")i=A(o,n.signal);else if(n.type==="style")i=S(o,n.signal);else continue;r.push(i)}e._bindingCleanups=r;for(let[n,i]of Object.entries(e.events))U(o,n,i);for(let n of e.children){let i=h(n);o.appendChild(i)}return o}function se(e,o,t){if(e.tag!==o.tag){let s=h(o);e.el&&e.el.parentNode===t&&t.removeChild(e.el),t.appendChild(s);return}let r=e.el||h(e);o.el=r;let n=r;if(e._bindingCleanups)for(let s of e._bindingCleanups)s();let i=[];for(let s of o.bindings){if(!s.signal)continue;let a;if(s.type==="text")a=T(r,s.signal);else if(s.type==="prop")a=w(r,s.target,s.signal);else if(s.type==="attr")a=k(r,s.target,s.signal);else if(s.type==="class")a=A(r,s.signal);else if(s.type==="style")a=S(r,s.signal);else continue;i.push(a)}o._bindingCleanups=i;for(let[s,a]of Object.entries(o.props))if(s==="style"&&typeof a=="object"&&a!==null)for(let[p,d]of Object.entries(a))n.style[p]=d;else s==="className"||s==="class"?r.className=String(a):n[s]=a;o.text!==void 0&&(r.textContent=o.text);for(let[s,a]of Object.entries(e.events))o.events[s]||r.removeEventListener(s,a);for(let[s,a]of Object.entries(o.events))e.events[s]!==a&&(e.events[s]&&r.removeEventListener(s,e.events[s]),r.addEventListener(s,a));let l=Math.max(e.children.length,o.children.length);for(let s=0;s<l;s++){let a=e.children[s],p=o.children[s];if(!a&&p){let d=h(p);r.appendChild(d)}else a&&!p?a.el&&a.el.parentNode===r&&r.removeChild(a.el):a&&p&&se(a,p,r)}}function Y(e,o){let t=o.setup?o.setup():{};o.beforeMount&&o.beforeMount();let r;if(o.render){let l=o.render(t,_);r=Array.isArray(l)?l:[l]}else r=[];let n=[],i=[];for(let l of r){let s=h(l);e.appendChild(s),n.push(s),ye(l,i)}return o.mounted&&o.mounted(),()=>{o.beforeUnmount&&o.beforeUnmount();for(let l of i)l();for(let l of n)(l.parentNode===e||e===l.parentNode)&&e.removeChild(l);o.unmounted&&o.unmounted()}}function ye(e,o){e._bindingCleanups&&o.push(...e._bindingCleanups);for(let t of e.children)ye(t,o)}var le=require("@lytjs/reactivity/signal");var z=require("@lytjs/common");function X(e){var r,n,i,l,s;let o={type:"fragment",children:[]},t=e.trim();for(;t.length>0;){let a=t.match(/^<([a-zA-Z][a-zA-Z0-9-]*)([\s\S]*?)(\/?)>/);if(a){let p=a[1],d=a[2],g=a[3]==="/",{props:c,events:f,directives:u}=Ie(d),m={type:"element",tag:p,props:c,events:f,directives:u,children:[]};if(t=t.slice(a[0].length),g){((r=o.children)!=null?r:[]).push(m);continue}let y=`</${p}>`,C=Be(t,p);if(C===-1)throw new z.LytError(z.LytErrorCodes.LYT_RENDERER_VAPOR_COMPILER_ERROR,`\u672A\u627E\u5230\u95ED\u5408\u6807\u7B7E: </${p}>`);let E=t.slice(0,C);t=t.slice(C+y.length);let N=X(E);m.children=N.children||[],((n=o.children)!=null?n:[]).push(m)}else{let p=t.indexOf("<"),d;if(p===-1?(d=t,t=""):(d=t.slice(0,p),t=t.slice(p)),d.trim())if(d.includes("{{")){let g=De(d);for(let c of g)c.type==="text"?((i=o.children)!=null?i:[]).push({type:"text",text:c.value}):((l=o.children)!=null?l:[]).push({type:"interpolation",expression:c.value})}else((s=o.children)!=null?s:[]).push({type:"text",text:d})}}return o}function Be(e,o){let t=1,r=0,n=`<${o}`,i=`</${o}>`;for(;r<e.length&&t>0;){let l=e.indexOf(n,r),s=e.indexOf(i,r);if(s===-1)return-1;if(l!==-1&&l<s){let a=e[l+n.length];a===">"||a===" "||a==="/"?(t++,r=l+n.length):(r=s+i.length,t--)}else r=s+i.length,t--}return t===0?r-i.length:-1}function Ie(e){let o={},t={},r={},n=/([a-zA-Z@:][a-zA-Z0-9@:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g,i;for(;(i=n.exec(e))!==null;){let l=i[1],s=i[2]||i[3];if(l.startsWith("on:")){let a=l.slice(3);t[a]=s}else if(l.startsWith(":")){let a=l.slice(1);o[a]=s}else if(l==="v-if")r.if=s;else if(l==="v-each"){let a=s.match(/^\s*(\w+)\s+in\s+(.+)\s*$/);a&&(r.each={item:a[1],expression:a[2]})}else o[l]=s}return{props:o,events:t,directives:r}}function De(e){let o=[],t=/\{\{([\s\S]*?)\}\}/g,r=0,n;for(;(n=t.exec(e))!==null;)n.index>r&&o.push({type:"text",value:e.slice(r,n.index)}),o.push({type:"interpolation",value:n[1].trim()}),r=n.index+n[0].length;return r<e.length&&o.push({type:"text",value:e.slice(r)}),o}function Z(e){let o=X(e);return{render:je(o),ast:o}}function je(e){return function(t){let r=R();return b(e,t,r)}}function b(e,o,t){var r,n;if(e.type==="fragment"){if(e.children&&e.children.length===1)return b(e.children[0],o,t);let i=t("div");if(i.nodeType=11,i.childNodes=i.childNodes||[],e.children)for(let l of e.children){let s=b(l,o,t);i.appendChild?i.appendChild(s):i.childNodes.push(s)}return i}if(e.type==="text"){let i=t("#text");return i.textContent=e.text||"",i.nodeType=3,i}if(e.type==="interpolation"){let i=t("span"),l=e.expression||"",s=M(o,l);if($(s)){let a=s,p=t("#text");p.nodeType=3,p.textContent=String(a());let d=(0,le.effect)(()=>{p.textContent=a()===null||a()===void 0?"":String(a())});i.appendChild(p),i._bindingCleanup=d,he(i,d)}else i.textContent=s!=null?String(s):"";return i}if(e.type==="element"){if((r=e.directives)!=null&&r.each){let{item:s,expression:a}=e.directives.each,p=M(o,a);if($(p)){let c=t("#fragment");c.childNodes=[],c.nodeType=11;let f=c;return O(f,p,(u,m)=>{let y={...o,[s]:u,index:m},C=t(e.tag||"div");if(e.props)for(let[E,N]of Object.entries(e.props))E==="class"||E==="className"?C.className=N:C[E]=N;if(e.children)for(let E of e.children){let N=b(E,y,t);C.appendChild(N)}return C}),f}let d=Array.isArray(p)?p:[],g=t("#fragment");if(g.childNodes=[],g.nodeType=11,d.length>0)for(let c=0;c<d.length;c++){let f={...o,[s]:d[c],index:c},u=t(e.tag||"div");if(e.props)for(let[m,y]of Object.entries(e.props))m==="class"||m==="className"?u.className=y:u[m]=y;if(e.children)for(let m of e.children){let y=b(m,f,t);u.appendChild(y)}g.appendChild(u)}return g}let i=t(e.tag||"div"),l=i;if((n=e.directives)!=null&&n.if){let s=M(o,e.directives.if);$(s)?L(i,s):s||(l.style=l.style||{},l.style.display="none",l.hidden=!0)}if(e.props)for(let[s,a]of Object.entries(e.props))if(s.startsWith(":")){let p=s.slice(1),d=M(o,a);if($(d)){let g=d,c=(0,le.effect)(()=>{l[p]=g()});i._propBindingCleanup=c,he(i,c)}else l[p]=d}else s==="class"||s==="className"?i.className=a:l[s]=a;if(e.events)for(let[s,a]of Object.entries(e.events)){let p=M(o,a);typeof p=="function"&&i.addEventListener(s,p)}if(e.children)for(let s of e.children){let a=b(s,o,t);if(a.nodeType===11&&a.childNodes)for(let p of a.childNodes)i.appendChild(p);else i.appendChild(a)}return i}return t("div")}function M(e,o){let t=o.trim();if(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t))return e[t];let r=t.split("."),n=e;for(let i of r){if(n==null)return;n=n[i]}return n}function $(e){return typeof e!="function"?!1:!!e._subscribe}function he(e,o){let t=e;t._cleanupEffects||(t._cleanupEffects=[]),t._cleanupEffects.push(o)}function Ve(e){return e.__vapor__=!0,e}function Ce(e){let o=!1,t=null,r=null;return{mount(n){if(!o){if(typeof n=="string")if(typeof document!="undefined"){let i=document.querySelector(n);if(!i)throw new Error(`[lyt:vapor] \u672A\u627E\u5230\u6302\u8F7D\u76EE\u6807: ${n}`);r=i}else throw new Error("[lyt:vapor] \u5728\u975E\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\uFF0C\u8BF7\u76F4\u63A5\u4F20\u5165\u5BB9\u5668\u5143\u7D20");else r=n;t=Y(r,e),o=!0}},unmount(){o&&(t&&(t(),t=null),o=!1,r=null)}}}function Ee(e,o){let t=e.setup?{...e.setup(),...o}:{...o};e.beforeMount&&e.beforeMount();let r;if(e.template){let{render:n}=Z(e.template);r=n(t)}else if(e.render){let n=e.render(t,_),i=Array.isArray(n)?n:[n];if(i.length===1)r=h(i[0]);else{r=R()("div");for(let s of i)r.appendChild(h(s))}}else throw new Error("[lyt:vapor] \u7EC4\u4EF6\u5FC5\u987B\u63D0\u4F9B template \u6216 render \u51FD\u6570");return e.mounted&&e.mounted(),r}
|
package/dist/vapor.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{registerDOMOperations as ye}from"@lytjs/vdom";var N=(s=>(s[s.ELEMENT=1]="ELEMENT",s[s.FUNCTIONAL_COMPONENT=2]="FUNCTIONAL_COMPONENT",s[s.STATEFUL_COMPONENT=4]="STATEFUL_COMPONENT",s[s.TEXT_CHILDREN=8]="TEXT_CHILDREN",s[s.ARRAY_CHILDREN=16]="ARRAY_CHILDREN",s[s.SLOTS_CHILDREN=32]="SLOTS_CHILDREN",s))(N||{}),w=(d=>(d[d.TEXT=1]="TEXT",d[d.CLASS=2]="CLASS",d[d.STYLE=4]="STYLE",d[d.PROPS=8]="PROPS",d[d.FULL_PROPS=16]="FULL_PROPS",d[d.STABLE_FRAGMENT=32]="STABLE_FRAGMENT",d[d.KEYED_FRAGMENT=64]="KEYED_FRAGMENT",d[d.UNKEYED_FRAGMENT=128]="UNKEYED_FRAGMENT",d[d.NEED_PATCH=256]="NEED_PATCH",d[d.DYNAMIC_SLOTS=512]="DYNAMIC_SLOTS",d[d.HOISTED=-1]="HOISTED",d[d.BAIL=-2]="BAIL",d))(w||{}),K=Symbol("Fragment"),Y=Symbol("Text"),$=Symbol("Comment");function h(e){return e.type===K}function E(e){return e.type===Y}function T(e){return e.type===$}function z(e,r){return e.type===r.type&&e.key===r.key}function k(e){return Array.isArray(e.dynamicChildren)}function X(e,r,o,t){if(o==="class")e.setClass(r,t);else if(o==="style")e.setStyle(r,t);else if(o.startsWith("on")||o.startsWith("@")){let n=o.startsWith("@")?o.slice(1).toLowerCase():o.slice(2).toLowerCase();e.addEventListener(r,n,t)}else o==="key"||o==="ref"||e.setAttribute(r,o,t)}function _(e,r,o,t,n){if(o==="class")e.setClass(r,t);else if(o==="style")e.setStyle(r,t||{});else if(o.startsWith("on")||o.startsWith("@")){let i=o.startsWith("@")?o.slice(1).toLowerCase():o.slice(2).toLowerCase();n&&e.removeEventListener(r,i,n),t&&e.addEventListener(r,i,t)}else e.setAttribute(r,o,t)}function M(e,r,o,t){for(let n in t){if(n==="key"||n==="ref")continue;let i=o[n],s=t[n];s!==i&&_(e,r,n,s,i)}for(let n in o)if(!(n==="key"||n==="ref")&&!(n in t))if(n==="class")e.setClass(r,"");else if(n==="style")e.setStyle(r,{});else if(n.startsWith("on")||n.startsWith("@")){let i=n.startsWith("@")?n.slice(1).toLowerCase():n.slice(2).toLowerCase();e.removeEventListener(r,i,o[n])}else e.removeAttribute(r,n)}function D(e,r,o,t,n,i){let{shapeFlag:s}=o;if(h(o)){se(e,r,o,t,n,i);return}if(E(o)){let a=e.createText(o.children);o.el=a,e.insert(t,a,n);return}if(T(o)){let a=e.createComment(o.children);o.el=a,e.insert(t,a,n);return}if(s&1){ie(e,r,o,t,n,i);return}if(s&6){ae(r,o,t,n,i);return}}function ie(e,r,o,t,n,i){let s=o.type,a=e.createElement(s);if(o.el=a,o.props)for(let p in o.props){let f=o.props[p];X(e,a,p,f)}let{shapeFlag:l,children:c}=o;l&8?a.textContent=c:l&16&&R(r,c,a,null,i),e.insert(t,a,n)}function R(e,r,o,t,n){for(let i=0;i<r.length;i++)e(null,r[i],o,t,n)}function se(e,r,o,t,n,i){let{children:s}=o,a=e.createComment("");e.insert(t,a,n),Array.isArray(s)&&s.length>0&&R(r,s,t,a,i),o.el=a,o.anchor=a}function ae(e,r,o,t,n){let i=r.component;i&&i.update&&i.update(),i&&i.subTree&&(e(null,i.subTree,o,t,i),r.el=i.subTree.el)}function Z(e,r,o,t){let{shapeFlag:n,children:i}=o;if(h(o)){if(Array.isArray(i))for(let s=0;s<i.length;s++)r(i[s],t);o.anchor&&o.anchor.parentNode&&e.remove(o.anchor);return}if(n&6){o.component&&o.component.subTree&&r(o.component.subTree,t);return}o.el&&e.remove(o.el)}function b(e,r){for(let o=0;o<r.length;o++)e(r[o])}import{patchKeyedChildren as le,patchUnkeyedChildren as pe}from"@lytjs/vdom";function A(e,r,o,t,n,i=null,s=null){if(t==null){o&&r(o,n);return}if(o===null){D(e,I(e,r),t,n,i,s);return}if(k(t)&&k(o)){ue(e,r,o,t,n,s);return}if(!z(o,t)){r(o,n),D(e,I(e,r),t,n,i,s);return}t.el=o.el,t.anchor=o.anchor;let{shapeFlag:a}=t;if(h(t)){fe(e,r,o,t,n,i,s);return}if(E(t)){t.children!==o.children&&(t.el.nodeValue=t.children);return}if(T(t)){t.children!==o.children&&(t.el.nodeValue=t.children);return}if(a&1){ce(e,r,o,t,s);return}if(a&6){me(o,t,s);return}}function I(e,r){return(o,t,n,i,s)=>{A(e,r,o,t,n,i,s)}}function ce(e,r,o,t,n=null){let i=t.el=o.el,s=o.props||{},a=t.props||{},{patchFlag:l,dynamicProps:c}=t;if(l&&l>0){if(l&1&&o.children!==t.children&&(i.textContent=t.children),l&2&&s.class!==a.class&&e.setClass(i,a.class),l&4&&s.style!==a.style&&e.setStyle(i,a.style||{}),l&8&&c)for(let p=0;p<c.length;p++){let f=c[p],d=s[f],u=a[f];u!==d&&_(e,i,f,u,d)}l&16&&M(e,i,s,a)}else M(e,i,s,a);(!l||!(l&1))&&G(e,r,o,t,i,null,n)}function G(e,r,o,t,n,i,s){let a=o.shapeFlag,l=t.shapeFlag,c=o.children,p=t.children;if(l&8){a&16&&b(r,c),c!==p&&(n.textContent=p);return}if(l&16){a&16?de(e,r,c,p,n,i,s):(a&8&&(n.textContent=""),R(I(e,r),p,n,i,s));return}p==null&&(a&8?n.textContent="":a&16&&b(r,c))}function de(e,r,o,t,n,i,s){t.every(l=>l.key!==null&&l.key!==void 0)&&o.every(l=>l.key!==null&&l.key!==void 0)?le(o,t,n,i,s,null,!1):pe(o,t,n,i,s,null,!1)}function fe(e,r,o,t,n,i,s){let a=o.children,l=t.children;Array.isArray(l)&&l.length>0?(G(e,r,o,t,n,i,s),t.el=l[0].el,t.anchor=l[l.length-1].el?e.nextSibling(l[l.length-1].el):i):Array.isArray(a)&&a.length>0&&l===null?(b(r,a),t.el=o.el,t.anchor=o.anchor):(t.el=o.el,t.anchor=o.anchor)}function ue(e,r,o,t,n,i){let s=o.dynamicChildren,a=t.dynamicChildren;for(let l=0;l<a.length;l++)A(e,r,s[l],a[l],n,null,i)}function me(e,r,o){r.component=e.component,r.el=e.el,r.component&&r.component.update&&r.component.update()}function ge(e){function r(n,i){Z(e,r,n,i)}ye({insert(n,i,s){e.insert(i,n,s)},createElement(n){return e.createElement(n)},createText(n){return e.createText(n)},setText(n,i){n.nodeValue=i},setElementText(n,i){n.textContent=i},remove(n){e.remove(n)},createComment(n){return e.createComment(n)},mount(n,i,s,a,l,c,p){t(null,n,i,s,a)},patch(n,i,s,a,l,c,p,f){t(n,i,s,a,l)},unmount(n,i,s,a){r(n)},move(n,i,s){e.insert(i,n.el,s)}});function t(n,i,s,a,l){A(e,r,n,i,s,a,l)}return{mount(n,i){i.nodeType===1&&(i.textContent=""),t(null,n,i,null,null)},patch(n,i,s){var a;t(n,i,s||((a=n.el)==null?void 0:a.parentNode),null,null)},unmount(n,i){r(n,i)}}}import{effect as V}from"@lytjs/reactivity/signal";function B(e,r){return V(()=>{let t=r();e.textContent=t==null?"":String(t)})}function L(e,r,o){return V(()=>{let n=o();e[r]=n})}function j(e,r,o){return V(()=>{let n=o();n==null||n===!1?e.removeAttribute(r):e.setAttribute(r,n===!0?"":String(n))})}function F(e,r){return V(()=>{let t=r();if(typeof t=="string")e.className=t;else if(Array.isArray(t))e.className=t.filter(Boolean).join(" ");else if(typeof t=="object"&&t!==null){let n=[],i=t;for(let s of Object.keys(i))i[s]&&n.push(s);e.className=n.join(" ")}else e.className=""})}function P(e,r,o){return e.addEventListener(r,o),()=>{e.removeEventListener(r,o)}}function q(e,r){return V(()=>{let t=r(),n=e;t?(n.style=n.style||{},n.style.display==="none"&&(n.style.display=""),n.hidden=!1):(n.style=n.style||{},n.style.display="none",n.hidden=!0)})}function J(e,r,o,t){let n=[],i=[],s=new Map,a=V(()=>{let l=r();if(!Array.isArray(l))return;let c=l.map((p,f)=>t?t(p,f):f);if(c.length===i.length){let p=!0;for(let f=0;f<c.length;f++)if(c[f]!==i[f]){p=!1;break}if(p){for(let f=0;f<l.length;f++){let d=o(l[f],f),u=n[f];u&&u.parentNode===e&&e.replaceChild(d,u),n[f]=d}return}}for(let p of n)p.parentNode===e&&e.removeChild(p);s.clear(),n=[],i=[];for(let p=0;p<l.length;p++){let f=o(l[p],p);e.appendChild(f),n.push(f),i.push(c[p]),s.set(c[p],f)}});return()=>{a();for(let l of n)l.parentNode===e&&e.removeChild(l);n=[],i=[],s.clear()}}var S=e=>{if(typeof document!="undefined")return document.createElement(e);throw new Error("[lyt:vapor] \u672A\u8BBE\u7F6E DOM \u5DE5\u5382\u51FD\u6570\u3002\u5728\u975E\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\u8BF7\u8C03\u7528 setVaporDOMFactory()")};function he(e){S=e}function v(){return S}function ee(e,r,...o){let t={tag:e,children:[],props:{},events:{},bindings:[]};if(r)for(let[n,i]of Object.entries(r))if(n.startsWith("on")&&typeof i=="function"&&!Q(i)){let s=n.slice(2).toLowerCase();t.events[s]=i}else Q(i)?n==="textContent"||n==="text"?t.bindings.push({type:"text",target:"textContent",signal:i}):n==="className"||n==="class"?t.bindings.push({type:"class",target:"className",signal:i}):n==="style"?t.bindings.push({type:"style",target:"style",signal:i}):t.bindings.push({type:"prop",target:n,signal:i}):t.props[n]=i;for(let n of o)typeof n=="string"?t.children.push({tag:"#text",children:[],props:{},events:{},bindings:[],text:n}):t.children.push(n);return t}function Q(e){if(typeof e!="function")return!1;let r=e;return!!(r._subscribe||r.set)&&!e.toString().startsWith("class")}function m(e){if(e.tag==="#text"){let t=S("#text");return t.textContent=e.text||"",t.nodeType=3,t}let r=S(e.tag);e.el=r;let o=r;for(let[t,n]of Object.entries(e.props))if(t==="style"&&typeof n=="object"&&n!==null)for(let[i,s]of Object.entries(n))o.style[i]=s;else t==="className"||t==="class"?r.className=String(n):o[t]=n;for(let t of e.bindings)t.signal&&(t.type==="text"?B(r,t.signal):t.type==="prop"?L(r,t.target,t.signal):t.type==="attr"?j(r,t.target,t.signal):t.type==="class"?F(r,t.signal):t.type==="style"&&L(r,"style",t.signal));for(let[t,n]of Object.entries(e.events))P(r,t,n);for(let t of e.children){let n=m(t);r.appendChild(n)}return r}function te(e,r,o){if(e.tag!==r.tag){let s=m(r);e.el&&e.el.parentNode===o&&o.removeChild(e.el),o.appendChild(s);return}let t=e.el||m(e);r.el=t;let n=t;for(let[s,a]of Object.entries(r.props))if(s==="style"&&typeof a=="object"&&a!==null)for(let[l,c]of Object.entries(a))n.style[l]=c;else s==="className"||s==="class"?t.className=String(a):n[s]=a;r.text!==void 0&&(t.textContent=r.text);for(let[s,a]of Object.entries(e.events))r.events[s]||t.removeEventListener(s,a);for(let[s,a]of Object.entries(r.events))e.events[s]!==a&&(e.events[s]&&t.removeEventListener(s,e.events[s]),t.addEventListener(s,a));let i=Math.max(e.children.length,r.children.length);for(let s=0;s<i;s++){let a=e.children[s],l=r.children[s];if(!a&&l){let c=m(l);t.appendChild(c)}else a&&!l?a.el&&a.el.parentNode===t&&t.removeChild(a.el):a&&l&&te(a,l,t)}}function U(e,r){let o=r.setup?r.setup():{};r.beforeMount&&r.beforeMount();let t;if(r.render){let i=r.render(o,ee);t=Array.isArray(i)?i:[i]}else t=[];let n=[];for(let i of t){let s=m(i);e.appendChild(s),n.push(s)}return r.mounted&&r.mounted(),()=>{r.beforeUnmount&&r.beforeUnmount();for(let i of n)e.removeChild(i);r.unmounted&&r.unmounted()}}function H(e){var t,n,i,s,a;let r={type:"fragment",children:[]},o=e.trim();for(;o.length>0;){let l=o.match(/^<([a-zA-Z][a-zA-Z0-9-]*)([\s\S]*?)(\/?)>/);if(l){let c=l[1],p=l[2],f=l[3]==="/",{props:d,events:u,directives:g}=Ne(p),y={type:"element",tag:c,props:d,events:u,directives:g,children:[]};if(o=o.slice(l[0].length),f){((t=r.children)!=null?t:[]).push(y);continue}let ne=`</${c}>`,O=Ve(o,c);if(O===-1)throw new Error(`[lyt:vapor:compiler] \u672A\u627E\u5230\u95ED\u5408\u6807\u7B7E: </${c}>`);let oe=o.slice(0,O);o=o.slice(O+ne.length);let re=H(oe);y.children=re.children||[],((n=r.children)!=null?n:[]).push(y)}else{let c=o.indexOf("<"),p;if(c===-1?(p=o,o=""):(p=o.slice(0,c),o=o.slice(c)),p.trim())if(p.includes("{{")){let f=ve(p);for(let d of f)d.type==="text"?((i=r.children)!=null?i:[]).push({type:"text",text:d.value}):((s=r.children)!=null?s:[]).push({type:"interpolation",expression:d.value})}else((a=r.children)!=null?a:[]).push({type:"text",text:p})}}return r}function Ve(e,r){let o=1,t=0,n=`<${r}`,i=`</${r}>`;for(;t<e.length&&o>0;){let s=e.indexOf(n,t),a=e.indexOf(i,t);if(a===-1)return-1;if(s!==-1&&s<a){let l=e[s+n.length];l===">"||l===" "||l==="/"?(o++,t=s+n.length):(t=a+i.length,o--)}else t=a+i.length,o--}return o===0?t-i.length:-1}function Ne(e){let r={},o={},t={},n=/([a-zA-Z@:][a-zA-Z0-9@:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g,i;for(;(i=n.exec(e))!==null;){let s=i[1],a=i[2]||i[3];if(s.startsWith("on:")){let l=s.slice(3);o[l]=a}else if(s.startsWith(":")){let l=s.slice(1);r[l]=a}else if(s==="v-if")t.if=a;else if(s==="v-each"){let l=a.match(/^\s*(\w+)\s+in\s+(.+)\s*$/);l&&(t.each={item:l[1],expression:l[2]})}else r[s]=a}return{props:r,events:o,directives:t}}function ve(e){let r=[],o=/\{\{([\s\S]*?)\}\}/g,t=0,n;for(;(n=o.exec(e))!==null;)n.index>t&&r.push({type:"text",value:e.slice(t,n.index)}),r.push({type:"interpolation",value:n[1].trim()}),t=n.index+n[0].length;return t<e.length&&r.push({type:"text",value:e.slice(t)}),r}function W(e){let r=H(e);return{render:xe(r),ast:r}}function xe(e){return function(o){let t=v();return C(e,o,t)}}function C(e,r,o){var t,n;if(e.type==="fragment"){if(e.children&&e.children.length===1)return C(e.children[0],r,o);let i=o("div");if(i.nodeType=11,i.childNodes=i.childNodes||[],e.children)for(let s of e.children){let a=C(s,r,o);i.appendChild?i.appendChild(a):i.childNodes.push(a)}return i}if(e.type==="text"){let i=o("#text");return i.textContent=e.text||"",i.nodeType=3,i}if(e.type==="interpolation"){let i=o("span"),s=e.expression||"",a=x(r,s);return i.textContent=a!=null?String(a):"",i}if(e.type==="element"){if((t=e.directives)!=null&&t.each){let{item:a,expression:l}=e.directives.each,c=x(r,l),p=o("#fragment");if(p.childNodes=[],p.nodeType=11,Array.isArray(c))for(let f=0;f<c.length;f++){let d={...r,[a]:c[f],index:f},u=o(e.tag||"div");if(e.props)for(let[g,y]of Object.entries(e.props))g==="class"||g==="className"?u.className=y:u[g]=y;if(e.children)for(let g of e.children){let y=C(g,d,o);u.appendChild(y)}p.appendChild(u)}return p}let i=o(e.tag||"div"),s=i;if((n=e.directives)!=null&&n.if&&(x(r,e.directives.if)||(s.style=s.style||{},s.style.display="none",s.hidden=!0)),e.props)for(let[a,l]of Object.entries(e.props))if(a.startsWith(":")){let c=a.slice(1),p=x(r,l);s[c]=p}else a==="class"||a==="className"?i.className=l:s[a]=l;if(e.events)for(let[a,l]of Object.entries(e.events)){let c=x(r,l);typeof c=="function"&&i.addEventListener(a,c)}if(e.children)for(let a of e.children){let l=C(a,r,o);if(l.nodeType===11&&l.childNodes)for(let c of l.childNodes)i.appendChild(c);else i.appendChild(l)}return i}return o("div")}function x(e,r){let o=r.trim();if(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(o)){let i=e[o];return typeof i=="function"&&!i.prototype?i():i}let t=o.split("."),n=e;for(let i of t){if(n==null)return;n=n[i],typeof n=="function"&&!n.prototype&&t.indexOf(i)<t.length-1&&(n=n())}return n}function Ce(e){return e}function Ee(e){let r=!1,o=null,t=null;return{mount(n){if(!r){if(typeof n=="string")if(typeof document!="undefined"){let i=document.querySelector(n);if(!i)throw new Error(`[lyt:vapor] \u672A\u627E\u5230\u6302\u8F7D\u76EE\u6807: ${n}`);t=i}else throw new Error("[lyt:vapor] \u5728\u975E\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\uFF0C\u8BF7\u76F4\u63A5\u4F20\u5165\u5BB9\u5668\u5143\u7D20");else t=n;o=U(t,e),r=!0}},unmount(){r&&(o&&(o(),o=null),r=!1,t=null)}}}function Te(e){let r=e.setup?e.setup():{};e.beforeMount&&e.beforeMount();let o;if(e.template){let{render:t}=W(e.template);o=t(r)}else if(e.render){let t=e.render(r,Re),n=Array.isArray(t)?t:[t];if(n.length===1)o=m(n[0]);else{o=v()("div");for(let s of n)o.appendChild(m(s))}}else throw new Error("[lyt:vapor] \u7EC4\u4EF6\u5FC5\u987B\u63D0\u4F9B template \u6216 render \u51FD\u6570");return e.mounted&&e.mounted(),o}function Re(e,r,...o){let t={tag:e,children:[],props:r||{},events:{},bindings:[]};for(let n of o)typeof n=="string"?t.children.push({tag:"#text",children:[],props:{},events:{},bindings:[],text:n}):t.children.push(n);return t}export{$ as Comment,K as Fragment,w as PatchFlags,N as ShapeFlags,Y as Text,j as bindAttr,F as bindClass,J as bindEach,P as bindEvent,q as bindIf,L as bindProp,B as bindText,W as compileToVapor,ge as createRenderer,Ee as createVaporApp,ee as createVaporElement,Ce as defineVaporComponent,v as getVaporDOMFactory,H as parseTemplate,Te as renderVaporComponent,m as renderVaporNode,he as setVaporDOMFactory,U as vaporMount,te as vaporPatch};
|
|
1
|
+
import{registerDOMOperations as Ne}from"@lytjs/vdom";var R=(l=>(l[l.ELEMENT=1]="ELEMENT",l[l.FUNCTIONAL_COMPONENT=2]="FUNCTIONAL_COMPONENT",l[l.STATEFUL_COMPONENT=4]="STATEFUL_COMPONENT",l[l.TEXT_CHILDREN=8]="TEXT_CHILDREN",l[l.ARRAY_CHILDREN=16]="ARRAY_CHILDREN",l[l.SLOTS_CHILDREN=32]="SLOTS_CHILDREN",l))(R||{}),U=(c=>(c[c.TEXT=1]="TEXT",c[c.CLASS=2]="CLASS",c[c.STYLE=4]="STYLE",c[c.PROPS=8]="PROPS",c[c.FULL_PROPS=16]="FULL_PROPS",c[c.STABLE_FRAGMENT=32]="STABLE_FRAGMENT",c[c.KEYED_FRAGMENT=64]="KEYED_FRAGMENT",c[c.UNKEYED_FRAGMENT=128]="UNKEYED_FRAGMENT",c[c.NEED_PATCH=256]="NEED_PATCH",c[c.DYNAMIC_SLOTS=512]="DYNAMIC_SLOTS",c[c.HOISTED=-1]="HOISTED",c[c.BAIL=-2]="BAIL",c))(U||{}),J=Symbol("Fragment"),Q=Symbol("Text"),ee=Symbol("Comment");function v(e){return e.type===J}function w(e){return e.type===Q}function k(e){return e.type===ee}function ne(e,r){return e.type===r.type&&e.key===r.key}function K(e){return Array.isArray(e.dynamicChildren)}function te(e,r,t,o){if(t==="class")e.setClass(r,o);else if(t==="style")e.setStyle(r,o);else if(t.startsWith("on")||t.startsWith("@")){let n=t.startsWith("@")?t.slice(1).toLowerCase():t.slice(2).toLowerCase();e.addEventListener(r,n,o)}else t==="key"||t==="ref"||e.setAttribute(r,t,o)}function W(e,r,t,o,n){if(t==="class")e.setClass(r,o);else if(t==="style")e.setStyle(r,o||{});else if(t.startsWith("on")||t.startsWith("@")){let i=t.startsWith("@")?t.slice(1).toLowerCase():t.slice(2).toLowerCase();n&&e.removeEventListener(r,i,n),o&&e.addEventListener(r,i,o)}else e.setAttribute(r,t,o)}function Y(e,r,t,o){for(let n in o){if(n==="key"||n==="ref")continue;let i=t[n],l=o[n];l!==i&&W(e,r,n,l,i)}for(let n in t)if(!(n==="key"||n==="ref")&&!(n in o))if(n==="class")e.setClass(r,"");else if(n==="style")e.setStyle(r,{});else if(n.startsWith("on")||n.startsWith("@")){let i=n.startsWith("@")?n.slice(1).toLowerCase():n.slice(2).toLowerCase();e.removeEventListener(r,i,t[n])}else e.removeAttribute(r,n)}function $(e,r,t,o,n,i){let{shapeFlag:l}=t;if(v(t)){ue(e,r,t,o,n,i);return}if(w(t)){let s=e.createText(t.children);t.el=s,e.insert(o,s,n);return}if(k(t)){let s=e.createComment(t.children);t.el=s,e.insert(o,s,n);return}if(l&1){de(e,r,t,o,n,i);return}if(l&6){fe(r,t,o,n,i);return}}function de(e,r,t,o,n,i){let l=t.type,s=e.createElement(l);if(t.el=s,t.props)for(let d in t.props){let g=t.props[d];te(e,s,d,g)}let{shapeFlag:a,children:p}=t;a&8?s.textContent=p:a&16&&A(r,p,s,null,i),e.insert(o,s,n)}function A(e,r,t,o,n){for(let i=0;i<r.length;i++)e(null,r[i],t,o,n)}function ue(e,r,t,o,n,i){let{children:l}=t,s=e.createComment("");e.insert(o,s,n),Array.isArray(l)&&l.length>0&&A(r,l,o,s,i),t.el=s,t.anchor=s}function fe(e,r,t,o,n){let i=r.component;i&&i.update&&i.update(),i&&i.subTree&&(e(null,i.subTree,t,o,i),r.el=i.subTree.el)}function oe(e,r,t,o){let{shapeFlag:n,children:i}=t;if(v(t)){if(Array.isArray(i))for(let l=0;l<i.length;l++)r(i[l],o);t.anchor&&t.anchor.parentNode&&e.remove(t.anchor);return}if(n&6){t.component&&t.component.subTree&&r(t.component.subTree,o);return}t.el&&e.remove(t.el)}function S(e,r){for(let t=0;t<r.length;t++)e(r[t])}import{patchKeyedChildren as me,patchUnkeyedChildren as ge}from"@lytjs/vdom";function L(e,r,t,o,n,i=null,l=null){if(o==null){t&&r(t,n);return}if(t===null){$(e,z(e,r),o,n,i,l);return}if(K(o)&&K(t)){Ce(e,r,t,o,n,l);return}if(!ne(t,o)){r(t,n),$(e,z(e,r),o,n,i,l);return}o.el=t.el,o.anchor=t.anchor;let{shapeFlag:s}=o;if(v(o)){Ve(e,r,t,o,n,i,l);return}if(w(o)){o.children!==t.children&&(o.el.nodeValue=o.children);return}if(k(o)){o.children!==t.children&&(o.el.nodeValue=o.children);return}if(s&1){ye(e,r,t,o,l);return}if(s&6){Ee(t,o,l);return}}function z(e,r){return(t,o,n,i,l)=>{L(e,r,t,o,n,i,l)}}function ye(e,r,t,o,n=null){let i=o.el=t.el,l=t.props||{},s=o.props||{},{patchFlag:a,dynamicProps:p}=o;if(a&&a>0){if(a&1&&t.children!==o.children&&(i.textContent=o.children),a&2&&l.class!==s.class&&e.setClass(i,s.class),a&4&&l.style!==s.style&&e.setStyle(i,s.style||{}),a&8&&p)for(let d=0;d<p.length;d++){let g=p[d],c=l[g],f=s[g];f!==c&&W(e,i,g,f,c)}a&16&&Y(e,i,l,s)}else Y(e,i,l,s);(!a||!(a&1))&&re(e,r,t,o,i,null,n)}function re(e,r,t,o,n,i,l){let s=t.shapeFlag,a=o.shapeFlag,p=t.children,d=o.children;if(a&8){s&16&&S(r,p),p!==d&&(n.textContent=d);return}if(a&16){s&16?he(e,r,p,d,n,i,l):(s&8&&(n.textContent=""),A(z(e,r),d,n,i,l));return}d==null&&(s&8?n.textContent="":s&16&&S(r,p))}function he(e,r,t,o,n,i,l){o.every(a=>a.key!==null&&a.key!==void 0)&&t.every(a=>a.key!==null&&a.key!==void 0)?me(t,o,n,i,l,null,!1):ge(t,o,n,i,l,null,!1)}function Ve(e,r,t,o,n,i,l){let s=t.children,a=o.children;Array.isArray(a)&&a.length>0?(re(e,r,t,o,n,i,l),o.el=a[0].el,o.anchor=a[a.length-1].el?e.nextSibling(a[a.length-1].el):i):Array.isArray(s)&&s.length>0&&a===null?(S(r,s),o.el=t.el,o.anchor=t.anchor):(o.el=t.el,o.anchor=t.anchor)}function Ce(e,r,t,o,n,i){let l=t.dynamicChildren,s=o.dynamicChildren;for(let a=0;a<s.length;a++)L(e,r,l[a],s[a],n,null,i)}function Ee(e,r,t){r.component=e.component,r.el=e.el,r.component&&r.component.update&&r.component.update()}function ve(e){function r(n,i){oe(e,r,n,i)}Ne({insert(n,i,l){e.insert(i,n,l)},createElement(n){return e.createElement(n)},createText(n){return e.createText(n)},setText(n,i){n.nodeValue=i},setElementText(n,i){n.textContent=i},remove(n){e.remove(n)},createComment(n){return e.createComment(n)},mount(n,i,l,s,a,p,d){o(null,n,i,l,s)},patch(n,i,l,s,a,p,d,g){o(n,i,l,s,a)},unmount(n,i,l,s){r(n)},move(n,i,l){e.insert(i,n.el,l)}});function o(n,i,l,s,a){L(e,r,n,i,l,s,a)}return{mount(n,i){i.nodeType===1&&(i.textContent=""),o(null,n,i,null,null)},patch(n,i,l){var s;o(n,i,l||((s=n.el)==null?void 0:s.parentNode),null,null)},unmount(n,i){r(n,i)}}}import{effect as C}from"@lytjs/reactivity/signal";function O(e,r){return C(()=>{let o=r();e.textContent=o==null?"":String(o)})}function _(e,r,t){return C(()=>{let n=t();e[r]=n})}function M(e,r,t){return C(()=>{let n=t();n==null||n===!1?e.removeAttribute(r):e.setAttribute(r,n===!0?"":String(n))})}function B(e,r){return C(()=>{let o=r();if(typeof o=="string")e.className=o;else if(Array.isArray(o))e.className=o.filter(Boolean).join(" ");else if(typeof o=="object"&&o!==null){let n=[],i=o;for(let l of Object.keys(i))i[l]&&n.push(l);e.className=n.join(" ")}else e.className=""})}function X(e,r,t){return e.addEventListener(r,t),()=>{e.removeEventListener(r,t)}}function I(e,r){return C(()=>{let o=r();if(typeof o=="string")e.style=o;else if(typeof o=="object"&&o!==null){let n=e.style;for(let i of Object.keys(n))n[i]="";for(let[i,l]of Object.entries(o))n[i]=l}else e.style=""})}function ie(e,r){return C(()=>{let o=r(),n=o==null?"":String(o);e.innerHTML!==n&&(e.innerHTML=n)})}function D(e,r,t){let o=e.parentNode!==null,n=t||null;!n&&e.parentNode&&(n=e.parentNode);let i=C(()=>{r()?o||(n&&n.parentNode?n.parentNode.insertBefore(e,n.nextSibling):n&&n.appendChild(e),o=!0):o&&e.parentNode&&(e.parentNode.removeChild(e),o=!1)});return()=>{i(),o&&e.parentNode&&e.parentNode.removeChild(e)}}function j(e,r,t,o){let n=[],i=[],l=new Map,s=C(()=>{let a=r();if(!Array.isArray(a))return;let p=a.map((f,u)=>o?o(f,u):u);if(p.length===i.length){let f=!0;for(let u=0;u<p.length;u++)if(p[u]!==i[u]){f=!1;break}if(f){for(let u=0;u<a.length;u++){let m=t(a[u],u),y=n[u];y&&y.parentNode===e&&e.replaceChild(m,y),n[u]=m,l.set(p[u],m)}return}}let d=new Set(i),g=new Set(p),c=new Map;for(let f=0;f<a.length;f++){let u=p[f];if(d.has(u)&&l.has(u)){let m=l.get(u);c.set(u,m),l.delete(u)}else{let m=t(a[f],f);c.set(u,m)}}for(let[f,u]of l)!g.has(f)&&u.parentNode===e&&e.removeChild(u);for(let f of n)f.parentNode===e&&e.removeChild(f);n=[],i=[];for(let f=0;f<a.length;f++){let u=p[f],m=c.get(u);e.appendChild(m),n.push(m),i.push(u)}l.clear();for(let[f,u]of c)l.set(f,u)});return()=>{s();for(let a of n)a.parentNode===e&&e.removeChild(a);n=[],i=[],l.clear()}}import{LytError as xe,LytErrorCodes as Re}from"@lytjs/common";var H=e=>{if(typeof document!="undefined")return document.createElement(e);throw new xe(Re.LYT_RENDERER_VAPOR_ERROR,"\u672A\u8BBE\u7F6E DOM \u5DE5\u5382\u51FD\u6570\u3002\u5728\u975E\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\u8BF7\u8C03\u7528 setVaporDOMFactory()")};function be(e){H=e}function b(){return H}function P(e,r,...t){let o={tag:e,children:[],props:{},events:{},bindings:[]};if(r)for(let[n,i]of Object.entries(r))if(n.startsWith("on")&&typeof i=="function"&&!se(i)){let l=n.slice(2).toLowerCase();o.events[l]=i}else se(i)?n==="textContent"||n==="text"?o.bindings.push({type:"text",target:"textContent",signal:i}):n==="className"||n==="class"?o.bindings.push({type:"class",target:"className",signal:i}):n==="style"?o.bindings.push({type:"style",target:"style",signal:i}):o.bindings.push({type:"prop",target:n,signal:i}):o.props[n]=i;for(let n of t)typeof n=="string"?o.children.push({tag:"#text",children:[],props:{},events:{},bindings:[],text:n}):o.children.push(n);return o}function se(e){if(typeof e!="function")return!1;let r=e;return!!r._subscribe||!!(r.set&&r._subscribe)}function h(e){if(e.tag==="#text"){let n=H("#text");return n.textContent=e.text||"",n.nodeType=3,n}let r=H(e.tag);e.el=r;let t=r;for(let[n,i]of Object.entries(e.props))if(n==="style"&&typeof i=="object"&&i!==null)for(let[l,s]of Object.entries(i))t.style[l]=s;else n==="className"||n==="class"?r.className=String(i):t[n]=i;let o=[];for(let n of e.bindings){if(!n.signal)continue;let i;if(n.type==="text")i=O(r,n.signal);else if(n.type==="prop")i=_(r,n.target,n.signal);else if(n.type==="attr")i=M(r,n.target,n.signal);else if(n.type==="class")i=B(r,n.signal);else if(n.type==="style")i=I(r,n.signal);else continue;o.push(i)}e._bindingCleanups=o;for(let[n,i]of Object.entries(e.events))X(r,n,i);for(let n of e.children){let i=h(n);r.appendChild(i)}return r}function le(e,r,t){if(e.tag!==r.tag){let s=h(r);e.el&&e.el.parentNode===t&&t.removeChild(e.el),t.appendChild(s);return}let o=e.el||h(e);r.el=o;let n=o;if(e._bindingCleanups)for(let s of e._bindingCleanups)s();let i=[];for(let s of r.bindings){if(!s.signal)continue;let a;if(s.type==="text")a=O(o,s.signal);else if(s.type==="prop")a=_(o,s.target,s.signal);else if(s.type==="attr")a=M(o,s.target,s.signal);else if(s.type==="class")a=B(o,s.signal);else if(s.type==="style")a=I(o,s.signal);else continue;i.push(a)}r._bindingCleanups=i;for(let[s,a]of Object.entries(r.props))if(s==="style"&&typeof a=="object"&&a!==null)for(let[p,d]of Object.entries(a))n.style[p]=d;else s==="className"||s==="class"?o.className=String(a):n[s]=a;r.text!==void 0&&(o.textContent=r.text);for(let[s,a]of Object.entries(e.events))r.events[s]||o.removeEventListener(s,a);for(let[s,a]of Object.entries(r.events))e.events[s]!==a&&(e.events[s]&&o.removeEventListener(s,e.events[s]),o.addEventListener(s,a));let l=Math.max(e.children.length,r.children.length);for(let s=0;s<l;s++){let a=e.children[s],p=r.children[s];if(!a&&p){let d=h(p);o.appendChild(d)}else a&&!p?a.el&&a.el.parentNode===o&&o.removeChild(a.el):a&&p&&le(a,p,o)}}function Z(e,r){let t=r.setup?r.setup():{};r.beforeMount&&r.beforeMount();let o;if(r.render){let l=r.render(t,P);o=Array.isArray(l)?l:[l]}else o=[];let n=[],i=[];for(let l of o){let s=h(l);e.appendChild(s),n.push(s),ae(l,i)}return r.mounted&&r.mounted(),()=>{r.beforeUnmount&&r.beforeUnmount();for(let l of i)l();for(let l of n)(l.parentNode===e||e===l.parentNode)&&e.removeChild(l);r.unmounted&&r.unmounted()}}function ae(e,r){e._bindingCleanups&&r.push(...e._bindingCleanups);for(let t of e.children)ae(t,r)}import{effect as pe}from"@lytjs/reactivity/signal";import{LytError as Te,LytErrorCodes as we}from"@lytjs/common";function G(e){var o,n,i,l,s;let r={type:"fragment",children:[]},t=e.trim();for(;t.length>0;){let a=t.match(/^<([a-zA-Z][a-zA-Z0-9-]*)([\s\S]*?)(\/?)>/);if(a){let p=a[1],d=a[2],g=a[3]==="/",{props:c,events:f,directives:u}=Ae(d),m={type:"element",tag:p,props:c,events:f,directives:u,children:[]};if(t=t.slice(a[0].length),g){((o=r.children)!=null?o:[]).push(m);continue}let y=`</${p}>`,V=ke(t,p);if(V===-1)throw new Te(we.LYT_RENDERER_VAPOR_COMPILER_ERROR,`\u672A\u627E\u5230\u95ED\u5408\u6807\u7B7E: </${p}>`);let E=t.slice(0,V);t=t.slice(V+y.length);let N=G(E);m.children=N.children||[],((n=r.children)!=null?n:[]).push(m)}else{let p=t.indexOf("<"),d;if(p===-1?(d=t,t=""):(d=t.slice(0,p),t=t.slice(p)),d.trim())if(d.includes("{{")){let g=Se(d);for(let c of g)c.type==="text"?((i=r.children)!=null?i:[]).push({type:"text",text:c.value}):((l=r.children)!=null?l:[]).push({type:"interpolation",expression:c.value})}else((s=r.children)!=null?s:[]).push({type:"text",text:d})}}return r}function ke(e,r){let t=1,o=0,n=`<${r}`,i=`</${r}>`;for(;o<e.length&&t>0;){let l=e.indexOf(n,o),s=e.indexOf(i,o);if(s===-1)return-1;if(l!==-1&&l<s){let a=e[l+n.length];a===">"||a===" "||a==="/"?(t++,o=l+n.length):(o=s+i.length,t--)}else o=s+i.length,t--}return t===0?o-i.length:-1}function Ae(e){let r={},t={},o={},n=/([a-zA-Z@:][a-zA-Z0-9@:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g,i;for(;(i=n.exec(e))!==null;){let l=i[1],s=i[2]||i[3];if(l.startsWith("on:")){let a=l.slice(3);t[a]=s}else if(l.startsWith(":")){let a=l.slice(1);r[a]=s}else if(l==="v-if")o.if=s;else if(l==="v-each"){let a=s.match(/^\s*(\w+)\s+in\s+(.+)\s*$/);a&&(o.each={item:a[1],expression:a[2]})}else r[l]=s}return{props:r,events:t,directives:o}}function Se(e){let r=[],t=/\{\{([\s\S]*?)\}\}/g,o=0,n;for(;(n=t.exec(e))!==null;)n.index>o&&r.push({type:"text",value:e.slice(o,n.index)}),r.push({type:"interpolation",value:n[1].trim()}),o=n.index+n[0].length;return o<e.length&&r.push({type:"text",value:e.slice(o)}),r}function q(e){let r=G(e);return{render:Le(r),ast:r}}function Le(e){return function(t){let o=b();return x(e,t,o)}}function x(e,r,t){var o,n;if(e.type==="fragment"){if(e.children&&e.children.length===1)return x(e.children[0],r,t);let i=t("div");if(i.nodeType=11,i.childNodes=i.childNodes||[],e.children)for(let l of e.children){let s=x(l,r,t);i.appendChild?i.appendChild(s):i.childNodes.push(s)}return i}if(e.type==="text"){let i=t("#text");return i.textContent=e.text||"",i.nodeType=3,i}if(e.type==="interpolation"){let i=t("span"),l=e.expression||"",s=T(r,l);if(F(s)){let a=s,p=t("#text");p.nodeType=3,p.textContent=String(a());let d=pe(()=>{p.textContent=a()===null||a()===void 0?"":String(a())});i.appendChild(p),i._bindingCleanup=d,ce(i,d)}else i.textContent=s!=null?String(s):"";return i}if(e.type==="element"){if((o=e.directives)!=null&&o.each){let{item:s,expression:a}=e.directives.each,p=T(r,a);if(F(p)){let c=t("#fragment");c.childNodes=[],c.nodeType=11;let f=c;return j(f,p,(u,m)=>{let y={...r,[s]:u,index:m},V=t(e.tag||"div");if(e.props)for(let[E,N]of Object.entries(e.props))E==="class"||E==="className"?V.className=N:V[E]=N;if(e.children)for(let E of e.children){let N=x(E,y,t);V.appendChild(N)}return V}),f}let d=Array.isArray(p)?p:[],g=t("#fragment");if(g.childNodes=[],g.nodeType=11,d.length>0)for(let c=0;c<d.length;c++){let f={...r,[s]:d[c],index:c},u=t(e.tag||"div");if(e.props)for(let[m,y]of Object.entries(e.props))m==="class"||m==="className"?u.className=y:u[m]=y;if(e.children)for(let m of e.children){let y=x(m,f,t);u.appendChild(y)}g.appendChild(u)}return g}let i=t(e.tag||"div"),l=i;if((n=e.directives)!=null&&n.if){let s=T(r,e.directives.if);F(s)?D(i,s):s||(l.style=l.style||{},l.style.display="none",l.hidden=!0)}if(e.props)for(let[s,a]of Object.entries(e.props))if(s.startsWith(":")){let p=s.slice(1),d=T(r,a);if(F(d)){let g=d,c=pe(()=>{l[p]=g()});i._propBindingCleanup=c,ce(i,c)}else l[p]=d}else s==="class"||s==="className"?i.className=a:l[s]=a;if(e.events)for(let[s,a]of Object.entries(e.events)){let p=T(r,a);typeof p=="function"&&i.addEventListener(s,p)}if(e.children)for(let s of e.children){let a=x(s,r,t);if(a.nodeType===11&&a.childNodes)for(let p of a.childNodes)i.appendChild(p);else i.appendChild(a)}return i}return t("div")}function T(e,r){let t=r.trim();if(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t))return e[t];let o=t.split("."),n=e;for(let i of o){if(n==null)return;n=n[i]}return n}function F(e){return typeof e!="function"?!1:!!e._subscribe}function ce(e,r){let t=e;t._cleanupEffects||(t._cleanupEffects=[]),t._cleanupEffects.push(r)}function Oe(e){return e.__vapor__=!0,e}function _e(e){let r=!1,t=null,o=null;return{mount(n){if(!r){if(typeof n=="string")if(typeof document!="undefined"){let i=document.querySelector(n);if(!i)throw new Error(`[lyt:vapor] \u672A\u627E\u5230\u6302\u8F7D\u76EE\u6807: ${n}`);o=i}else throw new Error("[lyt:vapor] \u5728\u975E\u6D4F\u89C8\u5668\u73AF\u5883\u4E2D\uFF0C\u8BF7\u76F4\u63A5\u4F20\u5165\u5BB9\u5668\u5143\u7D20");else o=n;t=Z(o,e),r=!0}},unmount(){r&&(t&&(t(),t=null),r=!1,o=null)}}}function Me(e,r){let t=e.setup?{...e.setup(),...r}:{...r};e.beforeMount&&e.beforeMount();let o;if(e.template){let{render:n}=q(e.template);o=n(t)}else if(e.render){let n=e.render(t,P),i=Array.isArray(n)?n:[n];if(i.length===1)o=h(i[0]);else{o=b()("div");for(let s of i)o.appendChild(h(s))}}else throw new Error("[lyt:vapor] \u7EC4\u4EF6\u5FC5\u987B\u63D0\u4F9B template \u6216 render \u51FD\u6570");return e.mounted&&e.mounted(),o}export{ee as Comment,J as Fragment,U as PatchFlags,R as ShapeFlags,Q as Text,M as bindAttr,B as bindClass,j as bindEach,X as bindEvent,ie as bindHTML,D as bindIf,_ as bindProp,I as bindStyle,O as bindText,q as compileToVapor,ve as createRenderer,_e as createVaporApp,P as createVaporElement,Oe as defineVaporComponent,b as getVaporDOMFactory,G as parseTemplate,Me as renderVaporComponent,h as renderVaporNode,be as setVaporDOMFactory,Z as vaporMount,le as vaporPatch};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lytjs/renderer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Lyt.js 渲染器 - 多平台渲染抽象层(DOM/SSR/Native/MiniApp)",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -68,8 +68,9 @@
|
|
|
68
68
|
"ssr"
|
|
69
69
|
],
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@lytjs/
|
|
72
|
-
"@lytjs/
|
|
71
|
+
"@lytjs/common": "^5.0.1",
|
|
72
|
+
"@lytjs/reactivity": "^5.0.1",
|
|
73
|
+
"@lytjs/vdom": "^5.0.1"
|
|
73
74
|
},
|
|
74
75
|
"engines": {
|
|
75
76
|
"node": ">=18.0.0"
|