solely 0.0.19 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -23
- package/dist/solely.js +13 -13
- package/dist/solely.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
我们致力于持续优化框架,确保它能够适应不断变化的前端开发需求,并根据用户反馈进行调整和改进。我们的目标是提供一个既满足小型项目需求,又不牺牲性能和易用性的前端解决方案。
|
|
16
16
|
|
|
17
17
|
## 安装
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
```shell
|
|
20
20
|
npm i solely
|
|
21
21
|
```
|
|
@@ -24,63 +24,58 @@ npm i solely
|
|
|
24
24
|
|
|
25
25
|
### 响应式数据
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
Solely 中内置了响应式数据 `$data`,每当 `$data` 中的数据更改时,页面也会同步更新。
|
|
28
28
|
|
|
29
29
|
### 模板语法
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Solely 使用基于 HTML 的模板语法,能够精准地将数据绑定到呈现的 DOM 上。所有模板都是语法正确的 HTML,可被标准的浏览器和 HTML 解析器顺利解析。
|
|
32
32
|
|
|
33
33
|
### 文本插值
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
文本插值是最基础的数据绑定形式,使用双大括号语法。在这些语法中,`this` 指向 `Element` 实例。为了简化书写,可以省略 `$data` 前面的 `this`,两种写法在功能上等同:
|
|
36
36
|
|
|
37
37
|
```html
|
|
38
38
|
<div>消息: {{ this.$data.msg }}</div>
|
|
39
39
|
<div>消息: {{ $data.msg }}</div>
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
双大括号标签会被替换为 Element 实例中
|
|
42
|
+
双大括号标签会被替换为 `Element` 实例中 `$data.msg` 的值。同时,每次 `$data.msg` 属性更改时,它也会同步更新。
|
|
43
43
|
|
|
44
44
|
### Attribute 绑定
|
|
45
45
|
|
|
46
|
-
双大括号不能在 HTML attributes 中使用。想要响应式地绑定一个 attribute,应该使用 s-[attribute] 指令,即在需要绑定的属性前面添加 s
|
|
46
|
+
双大括号不能在 HTML attributes 中使用。想要响应式地绑定一个 attribute,应该使用 `s-[attribute]` 指令,即在需要绑定的属性前面添加 `s-` 前缀:
|
|
47
47
|
|
|
48
48
|
```html
|
|
49
49
|
<div s-id="$data.id"></div>
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
s-[attribute] 指令指示
|
|
52
|
+
`s-[attribute]` 指令指示 Solely 将元素的 `id` attribute 与组件的 `$data.id` 属性保持一致。
|
|
53
53
|
|
|
54
|
-
**注意:** s-[attribute] 也可以用于 Class 与 Style 绑定,如 s-class
|
|
54
|
+
**注意:** `s-[attribute]` 也可以用于 Class 与 Style 绑定,如 `s-class`、`s-style` 等。
|
|
55
55
|
|
|
56
|
-
### 布尔型 Attribute
|
|
56
|
+
### 布尔型 Attribute
|
|
57
57
|
|
|
58
|
-
布尔型 attribute 依据 true / false 值来决定 attribute
|
|
59
|
-
s-[attribute] 在这种场景下的行为略有不同:
|
|
58
|
+
布尔型 attribute 依据 `true` / `false` 值来决定 attribute 是否应该存在于该元素上。如:`checked`、`disabled`、`readOnly`、`selected` 等。`s-[attribute]` 在这种场景下的行为略有不同:
|
|
60
59
|
|
|
61
60
|
```html
|
|
62
61
|
<button s-disabled="$data.disabled">Button</button>
|
|
63
62
|
```
|
|
64
63
|
|
|
65
|
-
当
|
|
64
|
+
当 `$data.disabled` 为真值时,元素会包含这个 `disabled` attribute。而当其为其他假值时,attribute 将被忽略。
|
|
66
65
|
|
|
67
|
-
### 使用 JavaScript 表达式
|
|
66
|
+
### 使用 JavaScript 表达式
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
Solely 在所有的数据绑定中都支持 JavaScript 表达式,除了 `eval`、`Function`、`setTimeout`、`setInterval` 等部分不安全代码。
|
|
70
69
|
|
|
71
70
|
```html
|
|
72
71
|
<div>{{ $data.number + 1 }}</div>
|
|
73
|
-
|
|
74
72
|
<div>{{ $data.ok ? 'YES' : 'NO' }}</div>
|
|
75
|
-
|
|
76
73
|
<div>{{ this.getMessage() }}</div>
|
|
77
74
|
```
|
|
78
75
|
|
|
79
76
|
```ts
|
|
80
77
|
@CustomElement({
|
|
81
|
-
// 模块名称
|
|
82
78
|
tagName: "sample-message",
|
|
83
|
-
// html模板字符串
|
|
84
79
|
template: template,
|
|
85
80
|
})
|
|
86
81
|
export class SampleMessage extends BaseElement {
|
|
@@ -88,7 +83,6 @@ export class SampleMessage extends BaseElement {
|
|
|
88
83
|
super();
|
|
89
84
|
}
|
|
90
85
|
|
|
91
|
-
// 初始化函数
|
|
92
86
|
async onInit() {
|
|
93
87
|
this.$data = {
|
|
94
88
|
number: 1,
|
|
@@ -99,7 +93,6 @@ export class SampleMessage extends BaseElement {
|
|
|
99
93
|
getMessage() {
|
|
100
94
|
return "message";
|
|
101
95
|
}
|
|
102
|
-
// 其他内容
|
|
103
96
|
}
|
|
104
97
|
```
|
|
105
98
|
|
|
@@ -107,7 +100,7 @@ export class SampleMessage extends BaseElement {
|
|
|
107
100
|
|
|
108
101
|
### 事件绑定
|
|
109
102
|
|
|
110
|
-
|
|
103
|
+
Solely 采用与标签中直接绑定事件相同的方式,不需要进行额外的处理。与文本插值和 Attribute 绑定相同,`this` 和 `$data` 也已经内置,不同的是,`value` 也可以直接被使用。
|
|
111
104
|
|
|
112
105
|
```html
|
|
113
106
|
<button onclick="$data.count++">Add 1</button>
|
|
@@ -120,9 +113,35 @@ solely 采用与标签中直接绑定事件相同的方式,不需要进行额
|
|
|
120
113
|
<button onclick="this.search()">搜索</button>
|
|
121
114
|
```
|
|
122
115
|
|
|
116
|
+
### 双向绑定(Model)
|
|
117
|
+
|
|
118
|
+
通过 `s-model` 指令实现表单元素与数据的双向绑定:
|
|
119
|
+
|
|
120
|
+
```html
|
|
121
|
+
<input type="text" s-model="$data.message">
|
|
122
|
+
<select s-model="$data.selected">
|
|
123
|
+
<option value="A">选项A</option>
|
|
124
|
+
</select>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
支持的表单元素:
|
|
128
|
+
|
|
129
|
+
- `<input>` (text/checkbox/radio)
|
|
130
|
+
- `<textarea>`
|
|
131
|
+
- `<select>`
|
|
132
|
+
|
|
133
|
+
**注意:** 双向绑定的表达式只支持 `$data` 中的属性。基于这个特性,你也可以省略 `$data` ,直接使用对应的属性,如 `$data.selected` 可以省略成 `selected`。
|
|
134
|
+
|
|
135
|
+
```html
|
|
136
|
+
<input type="text" s-model="$data.message">
|
|
137
|
+
<select s-model="selected">
|
|
138
|
+
<option value="A">选项A</option>
|
|
139
|
+
</select>
|
|
140
|
+
```
|
|
141
|
+
|
|
123
142
|
### 条件判断
|
|
124
143
|
|
|
125
|
-
|
|
144
|
+
Solely 引入了 `<If>` 标签,基于 `condition` 关键字绑定的表达式值的真假性,有条件地渲染元素或模板片段。该标签不会在 HTML 中渲染,只控制内部元素的展示。
|
|
126
145
|
|
|
127
146
|
```html
|
|
128
147
|
<If condition="$data.if">
|
|
@@ -134,7 +153,7 @@ solely 引入了 `<If>` 标签,基于 `condition` 关键字绑定的表达式
|
|
|
134
153
|
|
|
135
154
|
### 列表渲染
|
|
136
155
|
|
|
137
|
-
|
|
156
|
+
Solely 引入了 `<For>` 标签,根据由 `each` 关键字绑定的表达式值返回的数组来渲染列表。`item` 关键字是迭代的别名,默认为 `item`,但可以通过为其赋值进行修改。标签内部的元素可以使用 `item` 关键字绑定的内容,使用 `index` 关键字绑定内容的索引。该标签不会在 HTML 中渲染,只控制内部元素的展示。
|
|
138
157
|
|
|
139
158
|
```html
|
|
140
159
|
<For each="$data.f" item="i">
|
|
@@ -146,3 +165,111 @@ solely 引入了 `<For>` 标签,根据由 `each` 关键字绑定的表达式
|
|
|
146
165
|
<!-- 使用index指定索引 -->
|
|
147
166
|
<For each="$data.pages" item="page" index="i"></For>
|
|
148
167
|
```
|
|
168
|
+
|
|
169
|
+
### 类绑定
|
|
170
|
+
|
|
171
|
+
支持三种形式实现动态类绑定:
|
|
172
|
+
|
|
173
|
+
1. **对象语法**:
|
|
174
|
+
|
|
175
|
+
```html
|
|
176
|
+
<div s-class="{ active: $data.isActive, 'text-danger': $data.hasError }"></div>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
2. **字符串语法**:
|
|
180
|
+
|
|
181
|
+
```html
|
|
182
|
+
<div s-class="static-class dynamic-class"></div>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
3. **数组语法**:
|
|
186
|
+
|
|
187
|
+
```html
|
|
188
|
+
<div s-class="[$data.class1, $data.class2, { highlight: $data.isHighlight }]"></div>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 样式绑定
|
|
192
|
+
|
|
193
|
+
支持三种形式实现动态样式绑定:
|
|
194
|
+
|
|
195
|
+
1. **对象语法**(支持嵌套对象):
|
|
196
|
+
|
|
197
|
+
```html
|
|
198
|
+
<div s-style="{
|
|
199
|
+
color: $data.textColor,
|
|
200
|
+
fontSize: $data.fontSize + 'px',
|
|
201
|
+
border: {
|
|
202
|
+
width: '1px',
|
|
203
|
+
style: 'solid'
|
|
204
|
+
}
|
|
205
|
+
}"></div>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
2. **字符串语法**:
|
|
209
|
+
|
|
210
|
+
```html
|
|
211
|
+
<div s-style="color: red; font-size: 14px;"></div>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
3. **数组语法**(支持混合类型):
|
|
215
|
+
|
|
216
|
+
```html
|
|
217
|
+
<div s-style="[$data.baseStyles, { padding: $data.padding + 'px' }]"></div>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 自定义元素
|
|
221
|
+
|
|
222
|
+
通过继承 `BaseElement` 创建自定义组件:
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
import { BaseElement, CustomElement } from "solely";
|
|
226
|
+
|
|
227
|
+
@CustomElement({
|
|
228
|
+
tagName: "my-component",
|
|
229
|
+
template: `<div>{{ $data.count }}</div>`
|
|
230
|
+
})
|
|
231
|
+
class MyComponent extends BaseElement {
|
|
232
|
+
onInit() {
|
|
233
|
+
this.$data = { count: 0 };
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### 生命周期
|
|
239
|
+
|
|
240
|
+
组件生命周期方法:
|
|
241
|
+
|
|
242
|
+
- `onInit()`: 组件初始化时调用
|
|
243
|
+
|
|
244
|
+
### 注意事项
|
|
245
|
+
|
|
246
|
+
1. **性能优化**:
|
|
247
|
+
|
|
248
|
+
- 避免在模板表达式中进行复杂计算
|
|
249
|
+
- 列表渲染始终为 `<For>` 元素添加唯一的 `key` 属性
|
|
250
|
+
|
|
251
|
+
2. **命名空间**:
|
|
252
|
+
|
|
253
|
+
SVG 元素会自动应用 `svg` 命名空间:
|
|
254
|
+
|
|
255
|
+
```html
|
|
256
|
+
<svg s-width="$data.size">
|
|
257
|
+
<circle cx="50" cy="50" r="40"/>
|
|
258
|
+
</svg>
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
3. **组件通信**:
|
|
262
|
+
|
|
263
|
+
通过自定义事件实现父子组件通信:
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
// 触发事件
|
|
267
|
+
this.dispatchEvent(new CustomEvent('update', { detail: value }));
|
|
268
|
+
|
|
269
|
+
// 监听事件
|
|
270
|
+
<my-component onupdate="console.log(event.detail)"></my-component>
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## 许可证
|
|
274
|
+
|
|
275
|
+
MIT License
|
package/dist/solely.js
CHANGED
|
@@ -22,7 +22,7 @@ function gt(e, t) {
|
|
|
22
22
|
if (!a[0].trim()) continue;
|
|
23
23
|
const [o, i] = a[1] ? a[1].trim().split("=") : [a[2], a[3].trim().slice(1, -1)];
|
|
24
24
|
if (K.includes(o) || o.startsWith("on-"))
|
|
25
|
-
s.on[o.startsWith("on-") ? o.slice(3) : o.slice(2)] = G(e,
|
|
25
|
+
s.on[o.startsWith("on-") ? o.slice(3) : o.slice(2)] = G(e, i);
|
|
26
26
|
else if (o.startsWith("s-")) {
|
|
27
27
|
const h = o.slice(2);
|
|
28
28
|
switch (h) {
|
|
@@ -295,13 +295,13 @@ const yt = "http://www.w3.org/1999/xlink", wt = "http://www.w3.org/2000/xmlns/",
|
|
|
295
295
|
}
|
|
296
296
|
}, z = (e, t, n) => {
|
|
297
297
|
n ? e.insertBefore(t, n) : e.appendChild(t);
|
|
298
|
-
},
|
|
298
|
+
}, At = (e, t, n) => {
|
|
299
299
|
const s = N(t), r = document.createTextNode(s);
|
|
300
300
|
t.elm = r, z(e, r, n);
|
|
301
|
-
},
|
|
301
|
+
}, Rt = (e, t, n) => {
|
|
302
302
|
const s = t.content, r = document.createComment(s);
|
|
303
303
|
t.elm = r, z(e, r, n);
|
|
304
|
-
},
|
|
304
|
+
}, $t = (e, t, n, s) => {
|
|
305
305
|
t.tagName === "svg" && (s = _t);
|
|
306
306
|
const r = s ? document.createElementNS(s, t.tagName) : document.createElement(t.tagName);
|
|
307
307
|
Object.keys(t.attrs).forEach((a) => {
|
|
@@ -315,13 +315,13 @@ const yt = "http://www.w3.org/1999/xlink", wt = "http://www.w3.org/2000/xmlns/",
|
|
|
315
315
|
}, H = (e, t, n, s) => {
|
|
316
316
|
switch (t.tagName) {
|
|
317
317
|
case "comment":
|
|
318
|
-
|
|
318
|
+
Rt(e, t, n);
|
|
319
319
|
break;
|
|
320
320
|
case "text":
|
|
321
|
-
|
|
321
|
+
At(e, t, n);
|
|
322
322
|
break;
|
|
323
323
|
default:
|
|
324
|
-
|
|
324
|
+
$t(e, t, n, s);
|
|
325
325
|
break;
|
|
326
326
|
}
|
|
327
327
|
}, St = (e) => e && (e.tagName === "ElseIf" || e.tagName === "comment"), Wt = (e) => e && e.tagName === "Else", b = (e, t, n = [], s = 0, r = !0, a = !1) => {
|
|
@@ -390,19 +390,19 @@ const it = (e, t) => new Proxy(e, {
|
|
|
390
390
|
},
|
|
391
391
|
set: (n, s, r) => (n[s] !== r && (n[s] = r, t(s, r)), !0)
|
|
392
392
|
});
|
|
393
|
-
var I,
|
|
393
|
+
var I, A, R, y, $, w, C, O;
|
|
394
394
|
class Ft extends HTMLElement {
|
|
395
395
|
constructor() {
|
|
396
396
|
super();
|
|
397
397
|
p(this, C);
|
|
398
398
|
p(this, I, {});
|
|
399
|
-
p(this, $, []);
|
|
400
399
|
p(this, A, []);
|
|
400
|
+
p(this, R, []);
|
|
401
401
|
p(this, y, !1);
|
|
402
|
-
p(this,
|
|
402
|
+
p(this, $, !1);
|
|
403
403
|
p(this, w);
|
|
404
404
|
const n = this._manifest || {};
|
|
405
|
-
n.template && typeof n.template == "string" && f(this,
|
|
405
|
+
n.template && typeof n.template == "string" && f(this, A, vt(this, n.template)), n.shadowDOM && n.shadowDOM.use ? f(this, w, this.attachShadow({
|
|
406
406
|
mode: n.shadowDOM.mode || "open"
|
|
407
407
|
})) : f(this, w, this);
|
|
408
408
|
}
|
|
@@ -424,9 +424,9 @@ class Ft extends HTMLElement {
|
|
|
424
424
|
disconnectedCallback() {
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
-
I = new WeakMap(),
|
|
427
|
+
I = new WeakMap(), A = new WeakMap(), R = new WeakMap(), y = new WeakMap(), $ = new WeakMap(), w = new WeakMap(), C = new WeakSet(), O = function() {
|
|
428
428
|
g(this, y) || (f(this, y, !0), Et(() => {
|
|
429
|
-
f(this,
|
|
429
|
+
f(this, R, at(g(this, w), g(this, A), g(this, R))), f(this, y, !1), this.isConnected && !g(this, $) && (f(this, $, !0), this.onInit());
|
|
430
430
|
}));
|
|
431
431
|
};
|
|
432
432
|
const Ot = (e) => (t) => {
|
package/dist/solely.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.solely={}))})(this,function(l){"use strict";var gt=l=>{throw TypeError(l)};var tt=(l,f,p)=>f.has(l)||gt("Cannot "+p);var w=(l,f,p)=>(tt(l,f,"read from private field"),p?p.call(l):f.get(l)),E=(l,f,p)=>f.has(l)?gt("Cannot add the same private member more than once"):f instanceof WeakSet?f.add(l):f.set(l,p),d=(l,f,p,x)=>(tt(l,f,"write to private field"),x?x.call(l,p):f.set(l,p),p),j=(l,f,p)=>(tt(l,f,"access private method"),p);var S,W,H,_,O,k,I,D;const f=/<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g,p=/<\/?([^\s]+?)[/\s>]/,x=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g,vt=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],F=/\{\{(.+?)\}\}/g;function Et(n){return n.replace(/>\s+</g,"><").replace(/\s+/g," ")}function bt(n,t){const e=(t.match(p)||[])[1]||"",s={rootId:0,tagName:e,attrs:{},props:{},on:{},children:[]},r=new RegExp(x);for(;;){const a=r.exec(t);if(a===null)break;if(!a[0].trim())continue;const[o,i]=a[1]?a[1].trim().split("="):[a[2],a[3].trim().slice(1,-1)];if(q.includes(o)||o.startsWith("on-"))s.on[o.startsWith("on-")?o.slice(3):o.slice(2)]=nt(n,`return (${i})`);else if(o.startsWith("s-")){const u=o.slice(2);switch(u){case"model":s.model=i;break;case"style":s.styles=h=>g(n,i,h);break;case"class":s.classes=h=>g(n,i,h);break;case"readonly":s.props.readOnly=h=>g(n,i,h);break;default:s.props[u]=h=>g(n,i,h);break}}else s.attrs[o]=i;r.lastIndex--}if(e==="For"?s.fn=a=>g(n,s.attrs.each,a):(e==="If"||e==="ElseIf")&&(s.fn=a=>g(n,s.attrs.condition,a)),s.model){const a=s.model.replace("this.","").replace("$data.",""),o=u=>g(n,`$data.${a}`,u),i=u=>nt(n,`$data.${a}=${u}`);e==="input"?s.attrs.type==="checkbox"||s.attrs.type==="radio"?(s.props.checked=o,s.on.change=i("checked")):(s.props.value=o,s.on.input=i("value")):e==="textarea"?(s.props.value=o,s.on.input=i("value")):e==="select"&&(s.props.value=o,s.on.change=i("value"))}return s}function et(n,t){const e=[];if(!t)return e;t=Et(t);const s=[],r=[],a=()=>{var i;return s.length===0?e:(i=s[s.length-1]).children||(i.children=[])};let o=0;return t.replace(f,(i,u)=>{const h=a();if(u>o){const c=t.substring(o,u).trim();if(c){F.lastIndex=0;const L=!F.test(c)?c:N=>c.replace(F,(dt,Y)=>g(n,Y,N));h.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:L,children:[]})}}if(o=u+i.length,i.startsWith("<!--")&&i.endsWith("-->"))h.push({rootId:0,tagName:"comment",attrs:{},props:{},on:{},content:i.slice(4,-3),children:[]});else if(i.startsWith("</")){const c=r.pop();for(;s.length>0&&s[s.length-1].tagName!==c;)s.pop();s.pop()}else{const c=bt(n,i),m=i.endsWith("/>")||vt.includes(c.tagName);h.push(c),m||(s.push(c),r.push(c.tagName))}return""}),t.length>o&&e.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:t.substring(o).trim(),children:[]}),e}const g=(n,t,e)=>{try{return z(["$data",...e.map(r=>r.item),...e.map(r=>r.index),`return (${t})`]).bind(n)(n.$data,...e.map(r=>r.value),...e.map(r=>r.valueIndex))}catch(s){console.error(s)}},nt=(n,t)=>(e,s)=>z(["$data","event","value","checked",...s.map(a=>a.item),...s.map(a=>a.index),t]).bind(n)(n.$data,e,e.target.value,e.target.checked,...s.map(a=>a.value),...s.map(a=>a.valueIndex)),q=["onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragexit","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onwheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting"],st=(()=>{const n=typeof requestAnimationFrame=="function"?t=>requestAnimationFrame(t):typeof Promise<"u"?t=>Promise.resolve().then(t):t=>setTimeout(t,0);return(t,...e)=>{if(typeof t!="function")throw new Error("runInAsyncQueue expects a function as its first argument");n(()=>t(...e))}})(),U={};function z(n){const t=n.join(",");if(!U[t]){const e=n[n.length-1];if(e.trim()==="")throw new Error("Function body is empty");if(yt(e))throw new Error("Input contains potentially dangerous code: "+e);const s=new Function(...n);U[t]=s}return U[t]}function yt(n){return["eval","Function","setTimeout","setInterval","window","global","require","XMLHttpRequest","fetch","console","debugger","process","document","importScripts","String.raw","Object.prototype","JSON.parse"].some(e=>n.includes(e))}const wt="http://www.w3.org/1999/xlink",Ct="http://www.w3.org/2000/xmlns/",_t="http://www.w3.org/XML/1998/namespace",kt="http://www.w3.org/2000/svg",rt=n=>typeof n.content=="function"?n.content(n.loops||[]):n.content||"",It=n=>{const t=rt(n),e=n.elm;e.textContent!==t&&(e.textContent=t)},at=(n,t,e=[])=>{Object.keys(t).forEach(s=>{const r=t[s](e);n[s]!==r&&(n[s]=r)})},ot=(n,t)=>{const{styles:e,loops:s=[]}=t;if(!e)return;const r=e(s),a=B(r);Object.entries(a).forEach(([o,i])=>{n.style[o]=i})},it=(n,t)=>{const{classes:e,loops:s=[]}=t;if(!e)return;const r=e(s),a=ct(r);Object.entries(a).forEach(([o,i])=>{i?n.classList.add(o):n.classList.remove(o)})},B=n=>{let t={};return typeof n=="object"&&n!==null&&!Array.isArray(n)?Object.entries(n).forEach(([e,s])=>{if(typeof s=="object"&&s!==null&&!Array.isArray(s)){const r=B(s);Object.entries(r).forEach(([a,o])=>{t[`${e}-${a}`]=o})}else typeof s=="string"||typeof s=="number"?t[e]=`${s}`:t[e]=String(s)}):typeof n=="string"?n.split(";").forEach(e=>{const[s,r]=e.split(":").map(a=>a.trim());s&&r&&(t[s]=r)}):Array.isArray(n)&&n.forEach(e=>{const s=B(e);Object.entries(s).forEach(([r,a])=>{t[r]=a})}),t},ct=n=>{let t={};return typeof n=="object"&&!Array.isArray(n)?Object.entries(n).forEach(([e,s])=>{t[e]=!!s}):typeof n=="string"?n.split(" ").forEach(e=>{e!==""&&(t[e]=!0)}):Array.isArray(n)&&n.forEach(e=>{const s=ct(e);Object.entries(s).forEach(([r,a])=>{t[r]=a})}),t},lt=(n,t,e)=>{const s=r=>e.on[t](r,e.loops||[]);n.addEventListener(t,s,!1),e.handlers=e.handlers||{},e.handlers[t]=s},Rt=(n,t)=>{const e=t.elm;Object.keys(t.on).forEach(s=>{n.handlers&&n.handlers[s]&&e.removeEventListener(s,n.handlers[s],!1),lt(e,s,t)}),at(e,t.props,t.loops),it(e,t),ot(e,t),ht(e,n.children,t.children)},At=(n,t)=>{switch(t.elm=n.elm,t.tagName){case"comment":break;case"text":It(t);break;case"slot":break;default:Rt(n,t);break}},Q=(n,t,e)=>{e?n.insertBefore(t,e):n.appendChild(t)},$t=(n,t,e)=>{const s=rt(t),r=document.createTextNode(s);t.elm=r,Q(n,r,e)},St=(n,t,e)=>{const s=t.content,r=document.createComment(s);t.elm=r,Q(n,r,e)},Wt=(n,t,e,s)=>{t.tagName==="svg"&&(s=kt);const r=s?document.createElementNS(s,t.tagName):document.createElement(t.tagName);Object.keys(t.attrs).forEach(a=>{const o=t.attrs[a]||"";a.charAt(0)!=="x"?r.setAttribute(a,o):a.startsWith("xml:")?r.setAttributeNS(_t,a,o):a.startsWith("xlink:")?r.setAttributeNS(wt,a,o):a.startsWith("xmlns:")?r.setAttributeNS(Ct,a,o):r.setAttribute(a,o)}),Object.keys(t.on).forEach(a=>{lt(r,a,t)}),at(r,t.props,t.loops),it(r,t),ot(r,t),t.elm=r,Q(n,r,e),t.tagName==="foreignObject"&&(s=void 0),t.children.forEach(a=>{M(r,a,void 0,s)})},M=(n,t,e,s)=>{switch(t.tagName){case"comment":St(n,t,e);break;case"text":$t(n,t,e);break;default:Wt(n,t,e,s);break}},Ht=n=>n&&(n.tagName==="ElseIf"||n.tagName==="comment"),Ot=n=>n&&n.tagName==="Else",C=(n,t,e=[],s=0,r=!0,a=!1)=>{var o,i,u;for(let h=0;h<t.length;h++){const c=t[h];if(c.tagName==="If"){let m=!1;for(((o=c.fn)==null?void 0:o.call(c,e))&&(C(n,c.children,e,s,!1,!0),m=!0);h+1<t.length&&Ht(t[h+1]);)((u=(i=t[h+1]).fn)==null?void 0:u.call(i,e))&&!m&&(C(n,t[h+1].children,e,s,!1,!0),m=!0),h++;h+1<t.length&&Ot(t[h+1])&&(m||(C(n,t[h+1].children,e,s,!1,!0),m=!0),h++)}else if(c.tagName==="For"){const{item:m="item",index:L="index"}=c.attrs;(c.fn(e)||[]).forEach((dt,Y)=>{const jt={item:m,value:dt,index:L,valueIndex:Y};C(n,c.children,[...e,jt],s,!1)})}else{const m={...c,loops:e,children:[],rootId:s,isIf:a};C(m.children,c.children,e),n.push(m)}r&&s++}},ht=(n,t,e)=>{var a,o,i,u,h;let s=0,r=0;for(;s<t.length&&r<e.length;){const c=t[s],m=e[r];c.rootId===m.rootId?(m.isIf?((a=c.elm)==null||a.remove(),M(n,m,(o=t[s+1])==null?void 0:o.elm)):At(c,m),r++,s++):c.rootId>m.rootId?((i=c.elm)==null||i.remove(),s++):(M(n,m,(u=t[s+1])==null?void 0:u.elm),r++)}for(;s<t.length;)(h=t[s].elm)==null||h.remove(),s++;for(;r<e.length;){const c=e[r];M(n,c),r++}},X=(n,t,e=[])=>{if(!t||t.length===0)return[];const s=[];return C(s,t||[],[],0,!0),ht(n,e,s),s},G=n=>typeof n=="object"&&n!=null;function ut(n=window.location){let t;typeof n=="string"?t=new URL(n).hash:t=n.hash;const e=t.split("?"),s=e[0].substring(2),r=e[1],a={};return r&&r.split("&").forEach(o=>{const[i,u]=o.split("=");i&&u&&(a[decodeURIComponent(i)]=decodeURIComponent(u))}),{path:s.split("/"),query:a}}const J=(n,t)=>new Proxy(n,{get:(e,s)=>{let r=e[s];return G(r)&&(r=J(r,t)),r},set:(e,s,r)=>(e[s]!==r&&(e[s]=r,t(s,r)),!0)});class xt extends HTMLElement{constructor(){super();E(this,I);E(this,S,{});E(this,W,[]);E(this,H,[]);E(this,_,!1);E(this,O,!1);E(this,k);const e=this._manifest||{};e.template&&typeof e.template=="string"&&d(this,W,et(this,e.template)),e.shadowDOM&&e.shadowDOM.use?d(this,k,this.attachShadow({mode:e.shadowDOM.mode||"open"})):d(this,k,this)}get $data(){let e=w(this,S);return G(e)&&(e=J(e,()=>j(this,I,D).call(this))),e}set $data(e){d(this,S,e||{}),j(this,I,D).call(this)}connectedCallback(){const e=this._manifest||{};(e.className||e.tagName||"").split(" ").forEach(r=>{r&&this.classList.add(r)}),j(this,I,D).call(this)}onInit(){}disconnectedCallback(){}}S=new WeakMap,W=new WeakMap,H=new WeakMap,_=new WeakMap,O=new WeakMap,k=new WeakMap,I=new WeakSet,D=function(){w(this,_)||(d(this,_,!0),st(()=>{d(this,H,X(w(this,k),w(this,W),w(this,H))),d(this,_,!1),this.isConnected&&!w(this,O)&&(d(this,O,!0),this.onInit())}))};const ft=n=>t=>{if(customElements.get(n.tagName)){console.warn(`标签名称 "${n.tagName}" 已经被注册`);return}return t.prototype._manifest=Mt(n),customElements.define(n.tagName,t),t},Mt=n=>(n=Object.assign({hasConfig:!1},n),n);var Tt=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,mt=n=>{throw TypeError(n)},Vt=(n,t,e,s)=>{for(var r=s>1?void 0:s?Pt(t,e):t,a=n.length-1,o;a>=0;a--)(o=n[a])&&(r=(s?o(t,e,r):o(r))||r);return s&&r&&Tt(t,e,r),r},K=(n,t,e)=>t.has(n)||mt("Cannot "+e),b=(n,t,e)=>(K(n,t,"read from private field"),e?e.call(n):t.get(n)),y=(n,t,e)=>t.has(n)?mt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(n):t.set(n,e),v=(n,t,e,s)=>(K(n,t,"write to private field"),t.set(n,e),e),Lt=(n,t,e)=>(K(n,t,"access private method"),e),T,P,R,A,$,V,Z,pt;l.RouterViewElement=class extends HTMLElement{constructor(){super(),y(this,Z),y(this,T,[]),y(this,P,[]),y(this,R,null),y(this,A),y(this,$,[]),y(this,V,{})}get isRouterView(){return!0}get $routes(){return b(this,$)}set $routes(t){v(this,$,t),this.onHashChange()}get $remainingPath(){return b(this,P)}get $matchedRoute(){return b(this,R)}set $pipe(t){v(this,V,t||{}),this.onHashChange()}connectedCallback(){window.addEventListener("hashchange",this.onHashChange.bind(this)),this.onHashChange()}disconnectedCallback(){window.removeEventListener("hashchange",this.onHashChange.bind(this))}onHashChange(){var s;if(!this.isConnected)return;const{path:t}=ut(window.location),e=this.findAncestorWithRouterView(this);e?(v(this,A,e.$remainingPath),v(this,$,((s=e.$matchedRoute)==null?void 0:s.children)||[])):v(this,A,t),Lt(this,Z,pt).call(this)}matchRoute(t,e){for(const s of t){const r=s.path.split("/");let a=!0,o={};for(let i=0;i<r.length;i++){const u=r[i];if(u.startsWith(":"))o[u.substring(1)]=e[i];else if(u==="*"){a=!0;break}else if(u!==e[i]){a=!1;break}}if(a)return{matchedRoute:s,params:o,remainingPath:e.slice(r.length)}}return{matchedRoute:null,params:{},remainingPath:e}}propagateRoutes(t){for(let e of t.childNodes)if(e.isRouterView){e.onHashChange();continue}else this.propagateRoutes(e)}findAncestorWithRouterView(t){let e=t.parentNode;for(;e;){if(e.isRouterView)return e;e=e.parentElement}return null}},T=new WeakMap,P=new WeakMap,R=new WeakMap,A=new WeakMap,$=new WeakMap,V=new WeakMap,Z=new WeakSet,pt=function(){var u;const n=b(this,A)||[],{matchedRoute:t,params:e,remainingPath:s}=this.matchRoute(this.$routes,n);v(this,P,s);const r=(t==null?void 0:t.tagName)||"comment",a={},o={};for(const[h,c]of Object.entries(e))a[h]=()=>c;for(const[h,c]of Object.entries(b(this,V)))q.includes(h)||h.startsWith("on-")?o[h.startsWith("on-")?h.slice(3):h.slice(2)]=c:a[h]=()=>c;let i=[{tagName:r,rootId:0,attrs:{},props:a,on:o,children:[]}];((u=b(this,R))==null?void 0:u.tagName)!==r&&(i=[{rootId:0,tagName:"If",attrs:{},props:{},on:{},fn:()=>!0,children:i}]),v(this,T,X(this,i,b(this,T))),v(this,R,t||{tagName:"comment",path:"",children:[]}),this.propagateRoutes(this)},l.RouterViewElement=Vt([ft({tagName:"router-view"})],l.RouterViewElement),l.BaseElement=xt,l.CustomElement=ft,l.createFunction=z,l.isObject=G,l.listeners=q,l.observe=J,l.parseHashUrl=ut,l.parseHtml=et,l.patch=X,l.runInAsyncQueue=st,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.solely={}))})(this,function(l){"use strict";var gt=l=>{throw TypeError(l)};var tt=(l,f,p)=>f.has(l)||gt("Cannot "+p);var w=(l,f,p)=>(tt(l,f,"read from private field"),p?p.call(l):f.get(l)),E=(l,f,p)=>f.has(l)?gt("Cannot add the same private member more than once"):f instanceof WeakSet?f.add(l):f.set(l,p),d=(l,f,p,x)=>(tt(l,f,"write to private field"),x?x.call(l,p):f.set(l,p),p),j=(l,f,p)=>(tt(l,f,"access private method"),p);var $,W,H,_,O,k,I,D;const f=/<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g,p=/<\/?([^\s]+?)[/\s>]/,x=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g,vt=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],F=/\{\{(.+?)\}\}/g;function Et(n){return n.replace(/>\s+</g,"><").replace(/\s+/g," ")}function bt(n,t){const e=(t.match(p)||[])[1]||"",s={rootId:0,tagName:e,attrs:{},props:{},on:{},children:[]},r=new RegExp(x);for(;;){const a=r.exec(t);if(a===null)break;if(!a[0].trim())continue;const[o,i]=a[1]?a[1].trim().split("="):[a[2],a[3].trim().slice(1,-1)];if(q.includes(o)||o.startsWith("on-"))s.on[o.startsWith("on-")?o.slice(3):o.slice(2)]=nt(n,i);else if(o.startsWith("s-")){const u=o.slice(2);switch(u){case"model":s.model=i;break;case"style":s.styles=h=>g(n,i,h);break;case"class":s.classes=h=>g(n,i,h);break;case"readonly":s.props.readOnly=h=>g(n,i,h);break;default:s.props[u]=h=>g(n,i,h);break}}else s.attrs[o]=i;r.lastIndex--}if(e==="For"?s.fn=a=>g(n,s.attrs.each,a):(e==="If"||e==="ElseIf")&&(s.fn=a=>g(n,s.attrs.condition,a)),s.model){const a=s.model.replace("this.","").replace("$data.",""),o=u=>g(n,`$data.${a}`,u),i=u=>nt(n,`$data.${a}=${u}`);e==="input"?s.attrs.type==="checkbox"||s.attrs.type==="radio"?(s.props.checked=o,s.on.change=i("checked")):(s.props.value=o,s.on.input=i("value")):e==="textarea"?(s.props.value=o,s.on.input=i("value")):e==="select"&&(s.props.value=o,s.on.change=i("value"))}return s}function et(n,t){const e=[];if(!t)return e;t=Et(t);const s=[],r=[],a=()=>{var i;return s.length===0?e:(i=s[s.length-1]).children||(i.children=[])};let o=0;return t.replace(f,(i,u)=>{const h=a();if(u>o){const c=t.substring(o,u).trim();if(c){F.lastIndex=0;const L=!F.test(c)?c:N=>c.replace(F,(dt,Y)=>g(n,Y,N));h.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:L,children:[]})}}if(o=u+i.length,i.startsWith("<!--")&&i.endsWith("-->"))h.push({rootId:0,tagName:"comment",attrs:{},props:{},on:{},content:i.slice(4,-3),children:[]});else if(i.startsWith("</")){const c=r.pop();for(;s.length>0&&s[s.length-1].tagName!==c;)s.pop();s.pop()}else{const c=bt(n,i),m=i.endsWith("/>")||vt.includes(c.tagName);h.push(c),m||(s.push(c),r.push(c.tagName))}return""}),t.length>o&&e.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:t.substring(o).trim(),children:[]}),e}const g=(n,t,e)=>{try{return z(["$data",...e.map(r=>r.item),...e.map(r=>r.index),`return (${t})`]).bind(n)(n.$data,...e.map(r=>r.value),...e.map(r=>r.valueIndex))}catch(s){console.error(s)}},nt=(n,t)=>(e,s)=>z(["$data","event","value","checked",...s.map(a=>a.item),...s.map(a=>a.index),t]).bind(n)(n.$data,e,e.target.value,e.target.checked,...s.map(a=>a.value),...s.map(a=>a.valueIndex)),q=["onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragexit","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onwheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting"],st=(()=>{const n=typeof requestAnimationFrame=="function"?t=>requestAnimationFrame(t):typeof Promise<"u"?t=>Promise.resolve().then(t):t=>setTimeout(t,0);return(t,...e)=>{if(typeof t!="function")throw new Error("runInAsyncQueue expects a function as its first argument");n(()=>t(...e))}})(),U={};function z(n){const t=n.join(",");if(!U[t]){const e=n[n.length-1];if(e.trim()==="")throw new Error("Function body is empty");if(yt(e))throw new Error("Input contains potentially dangerous code: "+e);const s=new Function(...n);U[t]=s}return U[t]}function yt(n){return["eval","Function","setTimeout","setInterval","window","global","require","XMLHttpRequest","fetch","console","debugger","process","document","importScripts","String.raw","Object.prototype","JSON.parse"].some(e=>n.includes(e))}const wt="http://www.w3.org/1999/xlink",Ct="http://www.w3.org/2000/xmlns/",_t="http://www.w3.org/XML/1998/namespace",kt="http://www.w3.org/2000/svg",rt=n=>typeof n.content=="function"?n.content(n.loops||[]):n.content||"",It=n=>{const t=rt(n),e=n.elm;e.textContent!==t&&(e.textContent=t)},at=(n,t,e=[])=>{Object.keys(t).forEach(s=>{const r=t[s](e);n[s]!==r&&(n[s]=r)})},ot=(n,t)=>{const{styles:e,loops:s=[]}=t;if(!e)return;const r=e(s),a=B(r);Object.entries(a).forEach(([o,i])=>{n.style[o]=i})},it=(n,t)=>{const{classes:e,loops:s=[]}=t;if(!e)return;const r=e(s),a=ct(r);Object.entries(a).forEach(([o,i])=>{i?n.classList.add(o):n.classList.remove(o)})},B=n=>{let t={};return typeof n=="object"&&n!==null&&!Array.isArray(n)?Object.entries(n).forEach(([e,s])=>{if(typeof s=="object"&&s!==null&&!Array.isArray(s)){const r=B(s);Object.entries(r).forEach(([a,o])=>{t[`${e}-${a}`]=o})}else typeof s=="string"||typeof s=="number"?t[e]=`${s}`:t[e]=String(s)}):typeof n=="string"?n.split(";").forEach(e=>{const[s,r]=e.split(":").map(a=>a.trim());s&&r&&(t[s]=r)}):Array.isArray(n)&&n.forEach(e=>{const s=B(e);Object.entries(s).forEach(([r,a])=>{t[r]=a})}),t},ct=n=>{let t={};return typeof n=="object"&&!Array.isArray(n)?Object.entries(n).forEach(([e,s])=>{t[e]=!!s}):typeof n=="string"?n.split(" ").forEach(e=>{e!==""&&(t[e]=!0)}):Array.isArray(n)&&n.forEach(e=>{const s=ct(e);Object.entries(s).forEach(([r,a])=>{t[r]=a})}),t},lt=(n,t,e)=>{const s=r=>e.on[t](r,e.loops||[]);n.addEventListener(t,s,!1),e.handlers=e.handlers||{},e.handlers[t]=s},Rt=(n,t)=>{const e=t.elm;Object.keys(t.on).forEach(s=>{n.handlers&&n.handlers[s]&&e.removeEventListener(s,n.handlers[s],!1),lt(e,s,t)}),at(e,t.props,t.loops),it(e,t),ot(e,t),ht(e,n.children,t.children)},At=(n,t)=>{switch(t.elm=n.elm,t.tagName){case"comment":break;case"text":It(t);break;case"slot":break;default:Rt(n,t);break}},Q=(n,t,e)=>{e?n.insertBefore(t,e):n.appendChild(t)},St=(n,t,e)=>{const s=rt(t),r=document.createTextNode(s);t.elm=r,Q(n,r,e)},$t=(n,t,e)=>{const s=t.content,r=document.createComment(s);t.elm=r,Q(n,r,e)},Wt=(n,t,e,s)=>{t.tagName==="svg"&&(s=kt);const r=s?document.createElementNS(s,t.tagName):document.createElement(t.tagName);Object.keys(t.attrs).forEach(a=>{const o=t.attrs[a]||"";a.charAt(0)!=="x"?r.setAttribute(a,o):a.startsWith("xml:")?r.setAttributeNS(_t,a,o):a.startsWith("xlink:")?r.setAttributeNS(wt,a,o):a.startsWith("xmlns:")?r.setAttributeNS(Ct,a,o):r.setAttribute(a,o)}),Object.keys(t.on).forEach(a=>{lt(r,a,t)}),at(r,t.props,t.loops),it(r,t),ot(r,t),t.elm=r,Q(n,r,e),t.tagName==="foreignObject"&&(s=void 0),t.children.forEach(a=>{M(r,a,void 0,s)})},M=(n,t,e,s)=>{switch(t.tagName){case"comment":$t(n,t,e);break;case"text":St(n,t,e);break;default:Wt(n,t,e,s);break}},Ht=n=>n&&(n.tagName==="ElseIf"||n.tagName==="comment"),Ot=n=>n&&n.tagName==="Else",C=(n,t,e=[],s=0,r=!0,a=!1)=>{var o,i,u;for(let h=0;h<t.length;h++){const c=t[h];if(c.tagName==="If"){let m=!1;for(((o=c.fn)==null?void 0:o.call(c,e))&&(C(n,c.children,e,s,!1,!0),m=!0);h+1<t.length&&Ht(t[h+1]);)((u=(i=t[h+1]).fn)==null?void 0:u.call(i,e))&&!m&&(C(n,t[h+1].children,e,s,!1,!0),m=!0),h++;h+1<t.length&&Ot(t[h+1])&&(m||(C(n,t[h+1].children,e,s,!1,!0),m=!0),h++)}else if(c.tagName==="For"){const{item:m="item",index:L="index"}=c.attrs;(c.fn(e)||[]).forEach((dt,Y)=>{const jt={item:m,value:dt,index:L,valueIndex:Y};C(n,c.children,[...e,jt],s,!1)})}else{const m={...c,loops:e,children:[],rootId:s,isIf:a};C(m.children,c.children,e),n.push(m)}r&&s++}},ht=(n,t,e)=>{var a,o,i,u,h;let s=0,r=0;for(;s<t.length&&r<e.length;){const c=t[s],m=e[r];c.rootId===m.rootId?(m.isIf?((a=c.elm)==null||a.remove(),M(n,m,(o=t[s+1])==null?void 0:o.elm)):At(c,m),r++,s++):c.rootId>m.rootId?((i=c.elm)==null||i.remove(),s++):(M(n,m,(u=t[s+1])==null?void 0:u.elm),r++)}for(;s<t.length;)(h=t[s].elm)==null||h.remove(),s++;for(;r<e.length;){const c=e[r];M(n,c),r++}},X=(n,t,e=[])=>{if(!t||t.length===0)return[];const s=[];return C(s,t||[],[],0,!0),ht(n,e,s),s},G=n=>typeof n=="object"&&n!=null;function ut(n=window.location){let t;typeof n=="string"?t=new URL(n).hash:t=n.hash;const e=t.split("?"),s=e[0].substring(2),r=e[1],a={};return r&&r.split("&").forEach(o=>{const[i,u]=o.split("=");i&&u&&(a[decodeURIComponent(i)]=decodeURIComponent(u))}),{path:s.split("/"),query:a}}const J=(n,t)=>new Proxy(n,{get:(e,s)=>{let r=e[s];return G(r)&&(r=J(r,t)),r},set:(e,s,r)=>(e[s]!==r&&(e[s]=r,t(s,r)),!0)});class xt extends HTMLElement{constructor(){super();E(this,I);E(this,$,{});E(this,W,[]);E(this,H,[]);E(this,_,!1);E(this,O,!1);E(this,k);const e=this._manifest||{};e.template&&typeof e.template=="string"&&d(this,W,et(this,e.template)),e.shadowDOM&&e.shadowDOM.use?d(this,k,this.attachShadow({mode:e.shadowDOM.mode||"open"})):d(this,k,this)}get $data(){let e=w(this,$);return G(e)&&(e=J(e,()=>j(this,I,D).call(this))),e}set $data(e){d(this,$,e||{}),j(this,I,D).call(this)}connectedCallback(){const e=this._manifest||{};(e.className||e.tagName||"").split(" ").forEach(r=>{r&&this.classList.add(r)}),j(this,I,D).call(this)}onInit(){}disconnectedCallback(){}}$=new WeakMap,W=new WeakMap,H=new WeakMap,_=new WeakMap,O=new WeakMap,k=new WeakMap,I=new WeakSet,D=function(){w(this,_)||(d(this,_,!0),st(()=>{d(this,H,X(w(this,k),w(this,W),w(this,H))),d(this,_,!1),this.isConnected&&!w(this,O)&&(d(this,O,!0),this.onInit())}))};const ft=n=>t=>{if(customElements.get(n.tagName)){console.warn(`标签名称 "${n.tagName}" 已经被注册`);return}return t.prototype._manifest=Mt(n),customElements.define(n.tagName,t),t},Mt=n=>(n=Object.assign({hasConfig:!1},n),n);var Tt=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,mt=n=>{throw TypeError(n)},Vt=(n,t,e,s)=>{for(var r=s>1?void 0:s?Pt(t,e):t,a=n.length-1,o;a>=0;a--)(o=n[a])&&(r=(s?o(t,e,r):o(r))||r);return s&&r&&Tt(t,e,r),r},K=(n,t,e)=>t.has(n)||mt("Cannot "+e),b=(n,t,e)=>(K(n,t,"read from private field"),e?e.call(n):t.get(n)),y=(n,t,e)=>t.has(n)?mt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(n):t.set(n,e),v=(n,t,e,s)=>(K(n,t,"write to private field"),t.set(n,e),e),Lt=(n,t,e)=>(K(n,t,"access private method"),e),T,P,R,A,S,V,Z,pt;l.RouterViewElement=class extends HTMLElement{constructor(){super(),y(this,Z),y(this,T,[]),y(this,P,[]),y(this,R,null),y(this,A),y(this,S,[]),y(this,V,{})}get isRouterView(){return!0}get $routes(){return b(this,S)}set $routes(t){v(this,S,t),this.onHashChange()}get $remainingPath(){return b(this,P)}get $matchedRoute(){return b(this,R)}set $pipe(t){v(this,V,t||{}),this.onHashChange()}connectedCallback(){window.addEventListener("hashchange",this.onHashChange.bind(this)),this.onHashChange()}disconnectedCallback(){window.removeEventListener("hashchange",this.onHashChange.bind(this))}onHashChange(){var s;if(!this.isConnected)return;const{path:t}=ut(window.location),e=this.findAncestorWithRouterView(this);e?(v(this,A,e.$remainingPath),v(this,S,((s=e.$matchedRoute)==null?void 0:s.children)||[])):v(this,A,t),Lt(this,Z,pt).call(this)}matchRoute(t,e){for(const s of t){const r=s.path.split("/");let a=!0,o={};for(let i=0;i<r.length;i++){const u=r[i];if(u.startsWith(":"))o[u.substring(1)]=e[i];else if(u==="*"){a=!0;break}else if(u!==e[i]){a=!1;break}}if(a)return{matchedRoute:s,params:o,remainingPath:e.slice(r.length)}}return{matchedRoute:null,params:{},remainingPath:e}}propagateRoutes(t){for(let e of t.childNodes)if(e.isRouterView){e.onHashChange();continue}else this.propagateRoutes(e)}findAncestorWithRouterView(t){let e=t.parentNode;for(;e;){if(e.isRouterView)return e;e=e.parentElement}return null}},T=new WeakMap,P=new WeakMap,R=new WeakMap,A=new WeakMap,S=new WeakMap,V=new WeakMap,Z=new WeakSet,pt=function(){var u;const n=b(this,A)||[],{matchedRoute:t,params:e,remainingPath:s}=this.matchRoute(this.$routes,n);v(this,P,s);const r=(t==null?void 0:t.tagName)||"comment",a={},o={};for(const[h,c]of Object.entries(e))a[h]=()=>c;for(const[h,c]of Object.entries(b(this,V)))q.includes(h)||h.startsWith("on-")?o[h.startsWith("on-")?h.slice(3):h.slice(2)]=c:a[h]=()=>c;let i=[{tagName:r,rootId:0,attrs:{},props:a,on:o,children:[]}];((u=b(this,R))==null?void 0:u.tagName)!==r&&(i=[{rootId:0,tagName:"If",attrs:{},props:{},on:{},fn:()=>!0,children:i}]),v(this,T,X(this,i,b(this,T))),v(this,R,t||{tagName:"comment",path:"",children:[]}),this.propagateRoutes(this)},l.RouterViewElement=Vt([ft({tagName:"router-view"})],l.RouterViewElement),l.BaseElement=xt,l.CustomElement=ft,l.createFunction=z,l.isObject=G,l.listeners=q,l.observe=J,l.parseHashUrl=ut,l.parseHtml=et,l.patch=X,l.runInAsyncQueue=st,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|