solely 0.4.21 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +138 -38
  2. package/dist/compiler/ir/buildIR.cjs +1 -1
  3. package/dist/compiler/ir/buildIR.js +1 -1
  4. package/dist/compiler/parser/parser.cjs +1 -1
  5. package/dist/compiler/parser/parser.js +1 -1
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/plugins/solely-vite-plugin.cjs +1 -1
  9. package/dist/plugins/solely-vite-plugin.js +1 -1
  10. package/dist/runtime/component/base-element.cjs +1 -1
  11. package/dist/runtime/component/base-element.d.ts +6 -1
  12. package/dist/runtime/component/base-element.js +1 -1
  13. package/dist/runtime/component/decorators.cjs +1 -1
  14. package/dist/runtime/component/decorators.js +1 -1
  15. package/dist/runtime/index.cjs +1 -1
  16. package/dist/runtime/index.js +1 -1
  17. package/dist/runtime/reactivity/computed.cjs +1 -0
  18. package/dist/runtime/reactivity/computed.d.ts +36 -0
  19. package/dist/runtime/reactivity/computed.js +1 -0
  20. package/dist/runtime/reactivity/index.d.ts +6 -2
  21. package/dist/runtime/reactivity/observe.cjs +1 -1
  22. package/dist/runtime/reactivity/observe.d.ts +4 -32
  23. package/dist/runtime/reactivity/observe.js +1 -1
  24. package/dist/runtime/reactivity/watch.cjs +1 -0
  25. package/dist/runtime/reactivity/watch.d.ts +64 -0
  26. package/dist/runtime/reactivity/watch.js +1 -0
  27. package/dist/runtime/renderer/renderIR.cjs +1 -1
  28. package/dist/runtime/renderer/renderIR.d.ts +30 -20
  29. package/dist/runtime/renderer/renderIR.js +1 -1
  30. package/dist/shared/env.cjs +1 -1
  31. package/dist/shared/env.d.ts +2 -0
  32. package/dist/shared/env.js +1 -1
  33. package/dist/shared/index.cjs +1 -1
  34. package/dist/shared/index.js +1 -1
  35. package/dist/shared/is-object.d.ts +1 -1
  36. package/dist/types/ast.cjs +1 -1
  37. package/dist/types/ast.d.ts +1 -0
  38. package/dist/types/ast.js +1 -1
  39. package/dist/types/ir.d.ts +2 -0
  40. package/dist/types/lifecycle.cjs +1 -1
  41. package/dist/types/lifecycle.d.ts +1 -1
  42. package/dist/types/lifecycle.js +1 -1
  43. package/package.json +1 -1
package/README.md CHANGED
@@ -151,7 +151,9 @@ class MyCounter extends BaseElement<{ count: number }> {
151
151
  | **双向绑定** | `s-model="字段路径"` | `s-model="字段路径"` | `<input s-model="$data.username">` |
152
152
  | **原始事件** | `@事件名="语句"` | `on-事件名="语句"` | `<button @click="$data.count++">增加</button>` |
153
153
  | **条件渲染** | `<If test="表达式">` | `<If condition="表达式">` | `<If test="$data.ok"><p>成功</p></If>` |
154
+ | **显隐控制** | `<Show test="表达式">` | `<Show condition="表达式">` | `<Show test="$data.visible">内容</Show>` |
154
155
  | **列表渲染** | `<For each="数组" item="项变量">` | `<For each="数组" item="项变量">` | `<For each="$data.list" item="it">{{ it }}</For>` |
156
+ | **组件缓存** | `<If keepalive>` | - | `<If test="$data.ok" keepalive>...</If>` |
155
157
  | **动态类** | `:class="对象/数组/字符串"` | `s-class="对象/数组/字符串"` | `<div :class="{ active: $data.isActive }">` |
156
158
  | **动态样式** | `:style="对象"` | `s-style="对象"` | `<div :style="{ color: $data.c }">` |
157
159
 
@@ -267,7 +269,29 @@ class MyCounter extends BaseElement<{ count: number }> {
267
269
  </Else>
268
270
  ```
269
271
 
270
- #### 7. 列表渲染
272
+ #### 7. 显隐控制
273
+
274
+ 使用 `<Show>` 控制元素显隐(隐藏时缓存 DOM 而非销毁,显示时从缓存恢复):
275
+
276
+ ```html
277
+ <Show test="$data.isVisible">
278
+ <p>隐藏时 DOM 被缓存,显示时恢复,状态不丢失</p>
279
+ </Show>
280
+ ```
281
+
282
+ > **`<Show>` 是 `<If keepalive>` 的语法糖**,编译时自动转换为单分支 Conditional + keepalive。适合频繁切换且需要保持状态的场景。
283
+ >
284
+ > **`<Show>` vs `<If>`**:`<Show>` 隐藏时将 DOM 移入缓存,显示时从缓存恢复,状态保留;`<If>` 根据条件渲染对应分支,切换时销毁/重建 DOM,适合条件稳定或需要完整生命周期控制的场景。
285
+
286
+ 兼容语法:
287
+
288
+ ```html
289
+ <Show condition="$data.isVisible">
290
+ <p>隐藏时 DOM 被缓存,显示时恢复,状态不丢失</p>
291
+ </Show>
292
+ ```
293
+
294
+ #### 8. 列表渲染
271
295
 
272
296
  使用 `<For>` 渲染列表:
273
297
 
@@ -289,7 +313,26 @@ class MyCounter extends BaseElement<{ count: number }> {
289
313
  </ul>
290
314
  ```
291
315
 
292
- #### 8. 动态类
316
+ #### 9. 组件缓存
317
+
318
+ 在 `<If>` / `<ElseIf>` / `<Else>` 上添加 `keepalive` 属性,条件不满足时将 DOM 移入缓存而非销毁,切换回来时从缓存恢复:
319
+
320
+ ```html
321
+ <If test="$data.tab === 'list'" keepalive>
322
+ <my-heavy-list />
323
+ </If>
324
+ <ElseIf test="$data.tab === 'detail'" keepalive>
325
+ <my-detail-view />
326
+ </ElseIf>
327
+ ```
328
+
329
+ > **`keepalive` vs 普通 `If`**:普通 `If` 切换时会销毁/重建 DOM,状态丢失;`keepalive` 切换时将 DOM 移入缓存,状态保留。适合标签页切换等需要保持组件状态的场景。
330
+ >
331
+ > **keepalive 生命周期**:keepalive 分支失活时触发 `deactivated`(而非 `unmounted`),恢复时触发 `activated`(而非 `mounted`)。LRU 缓存淘汰时触发 `unmounted`(永久销毁)。嵌套 keepalive 不受支持。
332
+ >
333
+ > **keepalive 语义说明**:恢复时执行完整的 Reconciliation——内部 `<If>`/`<For>` 会根据当前数据重新求值,动态属性和动态文本也会同步更新。分支内部因条件/列表变化产生的多余节点会触发 `unmounted` 并清理事件,而非错误地进入 keepalive 缓存。
334
+
335
+ #### 10. 动态类
293
336
 
294
337
  使用 `:class` 动态控制 CSS 类(推荐):
295
338
 
@@ -307,7 +350,7 @@ class MyCounter extends BaseElement<{ count: number }> {
307
350
  <div s-class="[$data.class1, $data.class2]">内容</div>
308
351
  ```
309
352
 
310
- #### 9. 动态样式
353
+ #### 11. 动态样式
311
354
 
312
355
  使用 `:style` 动态设置样式(推荐):
313
356
 
@@ -345,7 +388,7 @@ solely/
345
388
 
346
389
  1. **编译器**:将模板转换为高效的渲染函数,支持 AST 解析和中间表示优化
347
390
  2. **运行时**:包含组件系统、响应式系统、渲染器和路由系统
348
- 3. **响应式系统**:基于 Proxy 的响应式数据绑定,自动追踪依赖
391
+ 3. **响应式系统**:基于 Proxy 的响应式数据绑定,采用 DAG 弱引用双向图和全局代理生成器自动追踪依赖,支持路径过滤、批量防抖与深度比较
349
392
  4. **路由系统**:支持单页应用的路由管理,包括路由定义、导航和组件挂载
350
393
  5. **插件系统**:提供扩展机制,支持自定义功能
351
394
 
@@ -710,33 +753,39 @@ document.body.appendChild(element);
710
753
 
711
754
  Solely 提供了完整的生命周期钩子函数,用于在组件的不同阶段执行自定义逻辑:
712
755
 
713
- | 钩子函数 | 调用时机 | 说明 |
714
- | -------------------------------------------- | ----------------- | --------------------------------------------------------------------- |
715
- | `created()` | 组件实例创建后 | 在组件构造函数执行完成后调用,此时组件尚未挂载到 DOM |
716
- | `mounted()` | 组件挂载到 DOM 后 | 组件首次渲染完成后调用,可在此进行 DOM 操作 |
717
- | `onInit()` | 组件初始化后 | 在 `mounted()` 之后调用,支持返回 Promise,适用于需要异步初始化的场景 |
718
- | `beforeUpdate()` | 数据更新前 | 在组件数据更新导致重新渲染前调用 |
719
- | `updated()` | 数据更新后 | 在组件数据更新导致重新渲染后调用 |
720
- | `beforeAttributesUpdate()` | 属性更新前 | 在属性更新导致重新渲染前调用 |
721
- | `afterAttributesUpdate()` | 属性更新后 | 在属性更新导致重新渲染后调用 |
722
- | `attributeChanged(name, oldValue, newValue)` | 属性变化时 | 当组件的观察属性发生变化时调用,参数分别为属性名、旧值和新值 |
723
- | `unmounted()` | 组件从 DOM 移除后 | 组件被销毁时调用,可在此清理资源 |
756
+ | 钩子函数 | 调用时机 | 说明 |
757
+ | -------------------------------------------- | ----------------- | ----------------------------------------------------------------- |
758
+ | `created()` | 组件实例创建后 | 在组件构造函数执行完成后调用,此时组件尚未挂载到 DOM |
759
+ | `mounted()` | 组件挂载到 DOM 后 | 组件首次渲染完成后调用,可在此进行 DOM 操作 |
760
+ | `beforeUpdate()` | 数据更新前 | 在组件数据更新导致重新渲染前调用 |
761
+ | `updated()` | 数据更新后 | 在组件数据更新导致重新渲染后调用 |
762
+ | `beforeAttributesUpdate()` | 属性更新前 | 在属性更新导致重新渲染前调用 |
763
+ | `afterAttributesUpdate()` | 属性更新后 | 在属性更新导致重新渲染后调用 |
764
+ | `attributeChanged(name, oldValue, newValue)` | 属性变化时 | 当组件的观察属性发生变化时调用,参数分别为属性名、旧值和新值 |
765
+ | `unmounted()` | 组件从 DOM 移除后 | 组件被永久销毁时调用(keepalive 缓存时不触发),可在此清理资源 |
766
+ | `activated()` | keepalive 恢复后 | keepalive 缓存的组件从缓存恢复到 DOM 时调用 |
767
+ | `deactivated()` | keepalive 缓存时 | keepalive 缓存的组件从 DOM 移入缓存时调用(临时失活,非永久销毁) |
724
768
 
725
769
  #### 生命周期调用顺序
726
770
 
727
- 1. **组件创建阶段**:`created()` → `mounted()` → `onInit()`
771
+ 1. **组件创建阶段**:`created()` → `mounted()`
728
772
  2. **数据更新阶段**:`beforeUpdate()` → 渲染更新 → `updated()`
729
773
  3. **属性更新阶段**:`attributeChanged()` → `beforeAttributesUpdate()` → 渲染更新 → `updated()` → `afterAttributesUpdate()`
730
- 4. **组件销毁阶段**:`unmounted()`
774
+ 4. **组件销毁阶段**:`unmounted()`(普通销毁)或 `deactivated()`(keepalive 缓存)
775
+ 5. **keepalive 恢复阶段**:`activated()` → `beforeUpdate()` → 渲染更新 → `updated()`
776
+
777
+ > **迁移提示**:`onInit()` 生命周期钩子已移除,原有的异步初始化逻辑请迁移到 `mounted()` 中执行。
731
778
 
732
779
  #### 模板级生命周期钩子
733
780
 
734
781
  Solely 支持在组件模板的普通元素上定义生命周期钩子,用于在元素的挂载和更新时执行自定义逻辑:
735
782
 
736
- | 钩子属性 | 调用时机 | 说明 |
737
- | --------- | ---------- | ---------------------------------------------------------------------- |
738
- | `mounted` | 元素挂载后 | 在元素首次渲染完成后调用,可调用组件方法并接收元素本身作为参数 |
739
- | `updated` | 元素更新后 | 在元素数据更新导致重新渲染后调用,可调用组件方法并接收元素本身作为参数 |
783
+ | 钩子属性 | 调用时机 | 说明 |
784
+ | ------------- | ---------------- | ---------------------------------------------------------------------- |
785
+ | `mounted` | 元素挂载后 | 在元素首次渲染完成后调用,可调用组件方法并接收元素本身作为参数 |
786
+ | `updated` | 元素更新后 | 在元素数据更新导致重新渲染后调用,可调用组件方法并接收元素本身作为参数 |
787
+ | `activated` | keepalive 恢复后 | keepalive 缓存的元素从缓存恢复到 DOM 时调用 |
788
+ | `deactivated` | keepalive 缓存时 | keepalive 缓存的元素从 DOM 移入缓存时调用 |
740
789
 
741
790
  **示例**:
742
791
 
@@ -843,8 +892,8 @@ class MyComponent extends BaseElement<MyData> {
843
892
  console.log(`属性 ${name} 从 ${oldValue} 变为 ${newValue}`);
844
893
  }
845
894
 
846
- // 组件初始化后调用,支持异步操作
847
- async onInit() {
895
+ // 组件挂载后调用,支持异步初始化
896
+ async mounted() {
848
897
  console.log('组件初始化中');
849
898
  // 可在此进行异步操作,如数据获取
850
899
  await fetchData();
@@ -869,13 +918,13 @@ class MyComponent extends BaseElement<MyData> {
869
918
  ```typescript
870
919
  import { observe } from 'solely';
871
920
 
872
- const state = observe(
921
+ const { proxy: state } = observe(
873
922
  {
874
923
  name: 'Solely',
875
924
  items: [1, 2, 3],
876
925
  },
877
- (path, newValue, oldValue) => {
878
- console.log('数据变化:', path, oldValue, '->', newValue);
926
+ change => {
927
+ console.log('数据变化:', change);
879
928
  },
880
929
  );
881
930
 
@@ -886,21 +935,20 @@ state.name = 'New Name'; // 触发回调
886
935
 
887
936
  响应式系统会自动处理以下特殊情况:
888
937
 
889
- | 对象类型 | 处理方式 | 说明 |
890
- | ---------------------- | -------- | -------------------------------------- |
891
- | `Object.freeze()` | 跳过代理 | 被冻结的对象不会被代理,直接返回原对象 |
892
- | `Object.seal()` | 跳过代理 | 被密封的对象不会被代理,直接返回原对象 |
893
- | `File` / `Blob` | 跳过代理 | 浏览器原生文件对象不会被代理 |
894
- | `FormData` | 跳过代理 | 表单数据对象不会被代理 |
895
- | `ArrayBuffer` | 跳过代理 | 二进制数据缓冲区不会被代理 |
896
- | `Response` / `Request` | 跳过代理 | Fetch API 对象不会被代理 |
938
+ | 对象类型 | 处理方式 | 说明 |
939
+ | ---------------------- | -------- | ------------------------------------------------------------------------------ |
940
+ | 不可扩展对象 | 跳过代理 | `Object.freeze()` / `Object.seal()` 等不可扩展的对象不会被代理,直接返回原对象 |
941
+ | `File` / `Blob` | 跳过代理 | 浏览器原生文件对象不会被代理 |
942
+ | `FormData` | 跳过代理 | 表单数据对象不会被代理 |
943
+ | `ArrayBuffer` | 跳过代理 | 二进制数据缓冲区不会被代理 |
944
+ | `Response` / `Request` | 跳过代理 | Fetch API 对象不会被代理 |
897
945
 
898
946
  **示例**:
899
947
 
900
948
  ```typescript
901
949
  // 冻结对象不会被代理
902
950
  const frozen = Object.freeze({ count: 0 });
903
- const state = observe({ frozen }, change => {
951
+ const { proxy: state } = observe({ frozen }, change => {
904
952
  console.log('变化:', change);
905
953
  });
906
954
 
@@ -909,7 +957,7 @@ state.frozen.count = 1; // 静默失败,无回调
909
957
 
910
958
  // File 对象不会被代理
911
959
  const file = new File(['content'], 'test.txt');
912
- const state2 = observe({ file }, change => {
960
+ const { proxy: state2 } = observe({ file }, change => {
913
961
  console.log('变化:', change);
914
962
  });
915
963
 
@@ -917,6 +965,56 @@ const state2 = observe({ file }, change => {
917
965
  console.log(state2.file instanceof File); // true
918
966
  ```
919
967
 
968
+ #### 配置选项
969
+
970
+ `observe` 支持通过第三个参数传入配置选项:
971
+
972
+ | 选项 | 类型 | 默认值 | 说明 |
973
+ | ------------- | --------------------------------- | ------- | -------------------------------------------------------------------------- |
974
+ | `throttle` | `number` | `0` | 变更回调的防抖间隔(毫秒),`0` 表示不防抖 |
975
+ | `immediate` | `boolean` | `false` | 是否在初始化时立即触发一次所有属性的 `set` 回调 |
976
+ | `filter` | `string \| string[]` | `[]` | 路径过滤规则,支持完整路径或父路径匹配(如 `'user'` 可匹配 `'user.name'`) |
977
+ | `deepCompare` | `boolean` | `false` | 是否对新旧值进行深度比较,避免无意义更新 |
978
+ | `onBatch` | `(changes: ChangeItem[]) => void` | - | 批量回调,在 `throttle` 间隔结束后一次性接收所有变更 |
979
+
980
+ #### 返回值
981
+
982
+ | 属性/方法 | 说明 |
983
+ | ------------- | ------------------------------------ |
984
+ | `proxy` | 响应式代理对象,修改其属性会触发回调 |
985
+ | `unobserve()` | 暂停观察,后续变更不再触发回调 |
986
+ | `resume()` | 恢复观察 |
987
+ | `dispose()` | 彻底销毁观察器,清理所有引用 |
988
+
989
+ #### 变更对象结构
990
+
991
+ 回调接收的 `ChangeItem` 对象包含以下字段:
992
+
993
+ | 字段 | 说明 |
994
+ | ----------------------- | --------------------------------------------------------------------------------------- |
995
+ | `type` | 变更类型:`set`、`delete`、`array-push`、`array-splice`、`array-replace`、`array-reset` |
996
+ | `key` | 发生变更的属性键(数组变更类型除外) |
997
+ | `path` | 完整路径数组,从根对象到变更属性的全路径(**包含 `key`**) |
998
+ | `newValue` / `oldValue` | 新值与旧值(依变更类型而异) |
999
+
1000
+ **示例**:
1001
+
1002
+ ```typescript
1003
+ const { proxy, unobserve, resume, dispose } = observe(
1004
+ { user: { name: 'Solely' } },
1005
+ change => {
1006
+ console.log(`Change at ${change.path.join('.')}:`, change);
1007
+ },
1008
+ { filter: 'user', throttle: 16 },
1009
+ );
1010
+
1011
+ proxy.user.name = 'New Name'; // 触发回调,path 为 ['user', 'name']
1012
+ unobserve(); // 暂停
1013
+ proxy.user.name = 'Another'; // 不触发
1014
+ resume(); // 恢复
1015
+ dispose(); // 彻底销毁
1016
+ ```
1017
+
920
1018
  ### 路由系统
921
1019
 
922
1020
  Solely 提供了功能强大的内置路由系统,支持单页应用开发,包括路由定义、导航、参数传递、路由守卫等功能。
@@ -1022,7 +1120,7 @@ const router = createRouter({
1022
1120
  }
1023
1121
 
1024
1122
  // 阻止导航
1025
- if (to.path === '/admin' && !isAdmin) {
1123
+ if (to.fullPath === '/admin' && !isAdmin) {
1026
1124
  return false;
1027
1125
  }
1028
1126
 
@@ -1031,7 +1129,7 @@ const router = createRouter({
1031
1129
  },
1032
1130
  afterEach: (to, from) => {
1033
1131
  // 导航完成后执行
1034
- console.log('从', from.fullPath, '导航到', to.fullPath);
1132
+ console.log('从', from?.fullPath ?? '初始', '导航到', to.fullPath);
1035
1133
  document.title = to.meta.title || 'Solely App';
1036
1134
  },
1037
1135
  });
@@ -1302,6 +1400,8 @@ npm run test:ui
1302
1400
  npm run test:coverage
1303
1401
  ```
1304
1402
 
1403
+ > 当前测试套件包含 270+ 个单元测试,覆盖编译器、运行时、响应式系统、路由系统和组件接口等模块。
1404
+
1305
1405
  ## 🔧 构建和开发
1306
1406
 
1307
1407
  ```bash
@@ -1 +1 @@
1
- "use strict";var e=Object.defineProperty,t=(t,n,o)=>((t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o)(t,"symbol"!=typeof n?n+"":n,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../shared/gen-function.cjs"),o=require("../../shared/env.cjs"),c=require("../../types/ast.cjs"),l=require("../../types/lifecycle.cjs"),i=/\{\{[\s\S]*?\}\}/,s={"solely-checkbox":{prop:"checked",event:"change"},"solely-switch":{prop:"checked",event:"change"},"solely-radio":{prop:"checked",event:"change"}},r=new class{constructor(){t(this,"compilers",new Map)}get(e="anonymous"){let t=this.compilers.get(e);return t||(t=new a,this.compilers.set(e,t)),t}clear(e){var t;if(e)null==(t=this.compilers.get(e))||t.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class a{constructor(){t(this,"cache",new Map),t(this,"functions",[])}makeCacheKey(e,t,n){return 0===n.length?`${e}:${t}`:`${e}:${t}:${n.map(e=>`${e.i}:${e.x}`).join(";")}`}compile(e,t,c){const l=null==t?void 0:t.trim();if(!l)return 0;const i=this.makeCacheKey(e,l,c),s=this.cache.get(i);if(void 0!==s)return s;let r;try{r=n.genFunction(l,e,c)}catch(u){o.IS_DEV&&console.error(`[Solely] IR Compile Error - Type: ${e}, Expr: "${l}"`,u),r=()=>""}const a=this.functions.push(r);return this.cache.set(i,a),a}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function u(e){const t=e[0];return":"===t?{isDynamic:!0,type:"expression"}:"@"===t?{isDynamic:!0,type:"handler"}:l.isLifecycleKind(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function d(e,t,n){e.__m={expr:t??"",loc:n??void 0}}function f(e){if(!e.attrs)return;const t=e.attrs.find(e=>"s-model"===e.key);if(!t)return;const n=t.value.trim(),o=n.startsWith("$data.")?n:`$data.${n.replace(/^this\./,"")}`,c=t.loc,l=(e.tag||"").toLowerCase(),i=e.attrs.find(e=>"type"===e.key),r=(null==i?void 0:i.value)??"text";e.attrs=e.attrs.filter(e=>e!==t);const a=(t,n,o)=>{var l;null==(l=e.attrs)||l.push({key:t,value:n,role:o,loc:c})};if("input"===l){if("checkbox"===r){const t=e.attrs.find(e=>"value"===e.key),n=t?JSON.stringify(t.value):'"on"';return a(":checked",`Array.isArray(${o}) ? ${o}.includes(${n}) : ${o}`),void a("@change",`\n const _v = ${n};\n if(Array.isArray(${o})) {\n const _i = ${o}.indexOf(_v);\n if(checked && _i === -1) ${o}.push(_v);\n else if(!checked && _i > -1) ${o}.splice(_i,1);\n } else {\n ${o} = checked;\n }`,"model")}if("radio"===r){const t=e.attrs.find(e=>"value"===e.key),n=(null==t?void 0:t.value)??"null";return a(":checked",`${o} == ${JSON.stringify(n)}`),void a("@change",`if (checked) ${o} = ${JSON.stringify(n)}`,"model")}return a(":value",o),void a("@input",`${o} = value`,"model")}if("textarea"===l)return a(":value",o),void a("@input",`${o} = value`,"model");if("select"===l)return void(e.attrs.some(e=>"multiple"===e.key)?(a("updated",`\n const values = Array.isArray(${o}) ? ${o} : ${o} != null ? [${o}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),a("@change",`${o} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(a(":value",o),a("@change",`${o} = value`,"model")));const u=s[l],d=(null==u?void 0:u.prop)??"value",f=(null==u?void 0:u.event)??"change";a(`:${d}`,o),a(`@${f}`,`${o} = ${"checked"===d?"checked":"value"===d?"value":`event.target.${d}`}`,"model")}function p(e,t,n,o=null){if(!e.attrs||0===e.attrs.length)return[];const c=[];for(const l of e.attrs){if(o&&o.has(l.key))continue;const{key:i,value:s,role:r}=l,{isDynamic:a,type:f}=u(i);if(a&&f){const o={k:i,f:n.compile(f,s??"",t),d:1,r:r};d(o,s,l.loc??e.loc),c.push(o)}else c.push({k:i,v:s,d:0,r:r})}return c}function h(e){let t=0===e.d;if(e.c&&e.c.length>0)for(const n of e.c)h(n)||(t=!1);if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)h(e)||(t=!1);return!t||e.t!==c.ASTType.Element&&e.t!==c.ASTType.Text||(e.s=1),t}function y(e,t,n){var l,s,r,a,h,y;const m={t:e.type,d:0};let g=!1;var T;switch(e.type===c.ASTType.Text?(T=e.content)&&i.test(T)&&(g=!0):((null==(l=e.attrs)?void 0:l.some(e=>"s-model"===e.key||u(e.key).isDynamic))&&(g=!0),e.type===c.ASTType.For&&(g=!0)),m.d=g?1:0,e.type){case c.ASTType.Text:{const o=e.content??"";g?(m.f=n.compile("template",o,t),d(m,o,e.loc)):m.x=o;break}case c.ASTType.Element:m.g=e.tag,f(e),m.a=p(e,t,n),e.children&&(m.c=v(e.children,t,n));break;case c.ASTType.For:{const o=null==(s=e.attrs)?void 0:s.find(e=>"each"===e.key),c=(null==o?void 0:o.value)??"";m.f=n.compile("expression",c,t),m.i=(null==(a=null==(r=e.attrs)?void 0:r.find(e=>"item"===e.key))?void 0:a.value)??"item",m.n=(null==(y=null==(h=e.attrs)?void 0:h.find(e=>"index"===e.key))?void 0:y.value)??"index",d(m,c,(null==o?void 0:o.loc)??e.loc);const l=new Set(["each","item","index"]);m.a=p(e,t,n,l);const i=[...t,{i:m.i,x:m.n}];e.children&&(m.c=v(e.children,i,n));break}case c.ASTType.If:case c.ASTType.ElseIf:case c.ASTType.Else:o.IS_DEV&&console.warn(`[Solely] Orphaned conditional node found: ${c.ASTType[e.type]}`),m.a=p(e,t,n),e.children&&(m.c=v(e.children,t,n));break;case c.ASTType.Comment:m.x=e.content??""}return m}function v(e,t,n){var o;const l=[];let i=0;for(;i<e.length;){const s=e[i];if(s.type===c.ASTType.If){const r=[];let a=i;for(;a<e.length;){const l=e[a],i=l.type;if(i!==c.ASTType.If&&i!==c.ASTType.ElseIf&&i!==c.ASTType.Else)break;if(i===c.ASTType.If&&r.length>0)break;let s,u=null,d="";if(i!==c.ASTType.Else){const e=null==(o=l.attrs)?void 0:o.find(e=>"test"===e.key||"condition"===e.key);d=(null==e?void 0:e.value)??"false",u=n.compile("expression",d,t),s=(null==e?void 0:e.loc)??l.loc}const f=l.children?v(l.children,t,n):[],h=p(l,t,n,new Set(["test","condition"]));if(r.push({f:u,c:f,a:h.length>0?h:void 0,__m:{expr:d,loc:s}}),a++,i===c.ASTType.Else)break}l.push({t:c.ASTType.Conditional,d:1,b:r,__m:{loc:s.loc}}),i=a}else l.push(y(s,t,n)),i++}return l}exports.buildIR=function(e,t={}){const{filename:n="anonymous",source:c}=t,l=r.get(n);l.clear();const i=performance.now(),s=v(e,[],l);for(const o of s)h(o);const a=performance.now(),u=l.getStats(),d=s.filter(e=>1===e.d).length,f=s.filter(e=>1===e.s).length,p={t:"root",v:"1.2.0",fns:l.getFunctions(),n:s,s:{tf:u.total,cf:u.cached,dn:d,tn:s.length,sn:f},m:{t:(new Date).toISOString(),as:e.length,fn:n,...c&&{src:c}}};return o.IS_DEV&&console.info(`[Solely] Compiled <${n}> in ${(a-i).toFixed(2)}ms | Nodes: ${s.length} | Fns: ${u.total} | StaticSubtrees: ${f}`),p},exports.clearIRCache=function(e){r.clear(e)},exports.transformModel=f;
1
+ "use strict";var e=Object.defineProperty,t=(t,n,o)=>((t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o)(t,"symbol"!=typeof n?n+"":n,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../shared/gen-function.cjs"),o=require("../../shared/env.cjs"),c=require("../../types/ast.cjs"),l=require("../../types/lifecycle.cjs"),i=/\{\{[\s\S]*?\}\}/,s={"solely-checkbox":{prop:"checked",event:"change"},"solely-switch":{prop:"checked",event:"change"},"solely-radio":{prop:"checked",event:"change"}},r=new class{constructor(){t(this,"compilers",new Map)}get(e="anonymous"){let t=this.compilers.get(e);return t||(t=new a,this.compilers.set(e,t)),t}clear(e){var t;if(e)null==(t=this.compilers.get(e))||t.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class a{constructor(){t(this,"cache",new Map),t(this,"functions",[])}makeCacheKey(e,t,n){return 0===n.length?`${e}:${t}`:`${e}:${t}:${n.map(e=>`${e.i}:${e.x}`).join(";")}`}compile(e,t,c){const l=null==t?void 0:t.trim();if(!l)return 0;const i=this.makeCacheKey(e,l,c),s=this.cache.get(i);if(void 0!==s)return s;let r;try{r=n.genFunction(l,e,c)}catch(u){o.IS_DEV&&console.error(`[Solely] IR Compile Error - Type: ${e}, Expr: "${l}"`,u),r=()=>""}const a=this.functions.push(r);return this.cache.set(i,a),a}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function u(e){const t=e[0];return":"===t?{isDynamic:!0,type:"expression"}:"@"===t?{isDynamic:!0,type:"handler"}:l.isLifecycleKind(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function p(e,t,n){e.__m={expr:t??"",loc:n??void 0}}function d(e){if(!e.attrs)return;const t=e.attrs.find(e=>"s-model"===e.key);if(!t)return;const n=t.value.trim(),o=n.startsWith("$data.")?n:`$data.${n.replace(/^this\./,"")}`,c=t.loc,l=(e.tag||"").toLowerCase(),i=e.attrs.find(e=>"type"===e.key),r=(null==i?void 0:i.value)??"text";e.attrs=e.attrs.filter(e=>e!==t);const a=(t,n,o)=>{var l;null==(l=e.attrs)||l.push({key:t,value:n,role:o,loc:c})};if("input"===l){if("checkbox"===r){const t=e.attrs.find(e=>"value"===e.key),n=t?JSON.stringify(t.value):'"on"';return a(":checked",`Array.isArray(${o}) ? ${o}.includes(${n}) : ${o}`),void a("@change",`\n const _v = ${n};\n if(Array.isArray(${o})) {\n const _i = ${o}.indexOf(_v);\n if(checked && _i === -1) ${o}.push(_v);\n else if(!checked && _i > -1) ${o}.splice(_i,1);\n } else {\n ${o} = checked;\n }`,"model")}if("radio"===r){const t=e.attrs.find(e=>"value"===e.key),n=(null==t?void 0:t.value)??"null";return a(":checked",`${o} == ${JSON.stringify(n)}`),void a("@change",`if (checked) ${o} = ${JSON.stringify(n)}`,"model")}return a(":value",o),void a("@input",`${o} = value`,"model")}if("textarea"===l)return a(":value",o),void a("@input",`${o} = value`,"model");if("select"===l)return void(e.attrs.some(e=>"multiple"===e.key)?(a("updated",`\n const values = Array.isArray(${o}) ? ${o} : ${o} != null ? [${o}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),a("@change",`${o} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(a(":value",o),a("@change",`${o} = value`,"model")));const u=s[l],p=(null==u?void 0:u.prop)??"value",d=(null==u?void 0:u.event)??"change";a(`:${p}`,o),a(`@${d}`,`${o} = ${"checked"===p?"checked":"value"===p?"value":`event.target.${p}`}`,"model")}function f(e,t,n,o=null){if(!e.attrs||0===e.attrs.length)return[];const c=[];for(const l of e.attrs){if(o&&o.has(l.key))continue;const{key:i,value:s,role:r}=l,{isDynamic:a,type:d}=u(i);if(a&&d){const o={k:i,f:n.compile(d,s??"",t),d:1,r:r};p(o,s,l.loc??e.loc),c.push(o)}else c.push({k:i,v:s,d:0,r:r})}return c}function h(e){let t=0===e.d;if(e.c&&e.c.length>0)for(const n of e.c)h(n)||(t=!1);if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)h(e)||(t=!1);return!t||e.t!==c.ASTType.Element&&e.t!==c.ASTType.Text||(e.s=1),t}function y(e,t,n){var l,s,r,a,h,y;const m={t:e.type,d:0};let T=!1;var S;switch(e.type===c.ASTType.Text?(S=e.content)&&i.test(S)&&(T=!0):((null==(l=e.attrs)?void 0:l.some(e=>"s-model"===e.key||u(e.key).isDynamic))&&(T=!0),e.type===c.ASTType.For&&(T=!0)),m.d=T?1:0,e.type){case c.ASTType.Text:{const o=e.content??"";T?(m.f=n.compile("template",o,t),p(m,o,e.loc)):m.x=o;break}case c.ASTType.Element:m.g=e.tag,d(e),m.a=f(e,t,n),e.children&&(m.c=v(e.children,t,n));break;case c.ASTType.For:{const o=null==(s=e.attrs)?void 0:s.find(e=>"each"===e.key),c=(null==o?void 0:o.value)??"";m.f=n.compile("expression",c,t),m.i=(null==(a=null==(r=e.attrs)?void 0:r.find(e=>"item"===e.key))?void 0:a.value)??"item",m.n=(null==(y=null==(h=e.attrs)?void 0:h.find(e=>"index"===e.key))?void 0:y.value)??"index",p(m,c,(null==o?void 0:o.loc)??e.loc);const l=new Set(["each","item","index"]);m.a=f(e,t,n,l);const i=[...t,{i:m.i,x:m.n}];e.children&&(m.c=v(e.children,i,n));break}case c.ASTType.If:case c.ASTType.ElseIf:case c.ASTType.Else:case c.ASTType.Show:o.IS_DEV&&console.warn(`[Solely] Orphaned conditional node found: ${c.ASTType[e.type]}`),m.a=f(e,t,n),e.children&&(m.c=v(e.children,t,n));break;case c.ASTType.Comment:m.x=e.content??""}return m}function v(e,t,n){var o,l;const i=[];let s=0;for(;s<e.length;){const r=e[s];if(r.type===c.ASTType.If||r.type===c.ASTType.Show){const a=[];let u=s;for(;u<e.length;){const i=e[u],s=i.type;if(s!==c.ASTType.If&&s!==c.ASTType.ElseIf&&s!==c.ASTType.Else&&s!==c.ASTType.Show)break;if((s===c.ASTType.If||s===c.ASTType.Show)&&a.length>0)break;let r,p=null,d="";if(s!==c.ASTType.Else){const e=null==(o=i.attrs)?void 0:o.find(e=>"test"===e.key||"condition"===e.key);d=(null==e?void 0:e.value)??"false",p=n.compile("expression",d,t),r=(null==e?void 0:e.loc)??i.loc}const h=i.children?v(i.children,t,n):[],y=f(i,t,n,new Set(["test","condition","keepalive"])),m=s===c.ASTType.Show||(null==(l=i.attrs)?void 0:l.some(e=>"keepalive"===e.key));if(a.push({f:p,c:h,a:y.length>0?y:void 0,ka:m?1:void 0,__m:{expr:d,loc:r}}),u++,s===c.ASTType.Else||s===c.ASTType.Show)break}i.push({t:c.ASTType.Conditional,d:1,b:a,__m:{loc:r.loc}}),s=u}else i.push(y(r,t,n)),s++}return i}exports.buildIR=function(e,t={}){const{filename:n="anonymous",source:c}=t,l=r.get(n);l.clear();const i=performance.now(),s=v(e,[],l);for(const o of s)h(o);const a=performance.now(),u=l.getStats(),p=s.filter(e=>1===e.d).length,d=s.filter(e=>1===e.s).length,f={t:"root",v:"1.2.0",fns:l.getFunctions(),n:s,s:{tf:u.total,cf:u.cached,dn:p,tn:s.length,sn:d},m:{t:(new Date).toISOString(),as:e.length,fn:n,...c&&{src:c}}};return o.IS_DEV&&console.info(`[Solely] Compiled <${n}> in ${(a-i).toFixed(2)}ms | Nodes: ${s.length} | Fns: ${u.total} | StaticSubtrees: ${d}`),f},exports.clearIRCache=function(e){r.clear(e)},exports.transformModel=d;
@@ -1 +1 @@
1
- var e=Object.defineProperty,t=(t,n,o)=>((t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o)(t,"symbol"!=typeof n?n+"":n,o);import{genFunction as n}from"../../shared/gen-function.js";import{IS_DEV as o}from"../../shared/env.js";import{ASTType as c}from"../../types/ast.js";import{isLifecycleKind as l}from"../../types/lifecycle.js";const i=/\{\{[\s\S]*?\}\}/,s={"solely-checkbox":{prop:"checked",event:"change"},"solely-switch":{prop:"checked",event:"change"},"solely-radio":{prop:"checked",event:"change"}},r=new class{constructor(){t(this,"compilers",new Map)}get(e="anonymous"){let t=this.compilers.get(e);return t||(t=new a,this.compilers.set(e,t)),t}clear(e){var t;if(e)null==(t=this.compilers.get(e))||t.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class a{constructor(){t(this,"cache",new Map),t(this,"functions",[])}makeCacheKey(e,t,n){return 0===n.length?`${e}:${t}`:`${e}:${t}:${n.map(e=>`${e.i}:${e.x}`).join(";")}`}compile(e,t,c){const l=null==t?void 0:t.trim();if(!l)return 0;const i=this.makeCacheKey(e,l,c),s=this.cache.get(i);if(void 0!==s)return s;let r;try{r=n(l,e,c)}catch(u){o&&console.error(`[Solely] IR Compile Error - Type: ${e}, Expr: "${l}"`,u),r=()=>""}const a=this.functions.push(r);return this.cache.set(i,a),a}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function u(e){const t=e[0];return":"===t?{isDynamic:!0,type:"expression"}:"@"===t?{isDynamic:!0,type:"handler"}:l(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function f(e,t,n){e.__m={expr:t??"",loc:n??void 0}}function d(e){if(!e.attrs)return;const t=e.attrs.find(e=>"s-model"===e.key);if(!t)return;const n=t.value.trim(),o=n.startsWith("$data.")?n:`$data.${n.replace(/^this\./,"")}`,c=t.loc,l=(e.tag||"").toLowerCase(),i=e.attrs.find(e=>"type"===e.key),r=(null==i?void 0:i.value)??"text";e.attrs=e.attrs.filter(e=>e!==t);const a=(t,n,o)=>{var l;null==(l=e.attrs)||l.push({key:t,value:n,role:o,loc:c})};if("input"===l){if("checkbox"===r){const t=e.attrs.find(e=>"value"===e.key),n=t?JSON.stringify(t.value):'"on"';return a(":checked",`Array.isArray(${o}) ? ${o}.includes(${n}) : ${o}`),void a("@change",`\n const _v = ${n};\n if(Array.isArray(${o})) {\n const _i = ${o}.indexOf(_v);\n if(checked && _i === -1) ${o}.push(_v);\n else if(!checked && _i > -1) ${o}.splice(_i,1);\n } else {\n ${o} = checked;\n }`,"model")}if("radio"===r){const t=e.attrs.find(e=>"value"===e.key),n=(null==t?void 0:t.value)??"null";return a(":checked",`${o} == ${JSON.stringify(n)}`),void a("@change",`if (checked) ${o} = ${JSON.stringify(n)}`,"model")}return a(":value",o),void a("@input",`${o} = value`,"model")}if("textarea"===l)return a(":value",o),void a("@input",`${o} = value`,"model");if("select"===l)return void(e.attrs.some(e=>"multiple"===e.key)?(a("updated",`\n const values = Array.isArray(${o}) ? ${o} : ${o} != null ? [${o}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),a("@change",`${o} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(a(":value",o),a("@change",`${o} = value`,"model")));const u=s[l],f=(null==u?void 0:u.prop)??"value",d=(null==u?void 0:u.event)??"change";a(`:${f}`,o),a(`@${d}`,`${o} = ${"checked"===f?"checked":"value"===f?"value":`event.target.${f}`}`,"model")}function h(e,t,n,o=null){if(!e.attrs||0===e.attrs.length)return[];const c=[];for(const l of e.attrs){if(o&&o.has(l.key))continue;const{key:i,value:s,role:r}=l,{isDynamic:a,type:d}=u(i);if(a&&d){const o={k:i,f:n.compile(d,s??"",t),d:1,r:r};f(o,s,l.loc??e.loc),c.push(o)}else c.push({k:i,v:s,d:0,r:r})}return c}function p(e){let t=0===e.d;if(e.c&&e.c.length>0)for(const n of e.c)p(n)||(t=!1);if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)p(e)||(t=!1);return!t||e.t!==c.Element&&e.t!==c.Text||(e.s=1),t}function v(e,t,n){var l,s,r,a,p,v;const y={t:e.type,d:0};let $=!1;var g;switch(e.type===c.Text?(g=e.content)&&i.test(g)&&($=!0):((null==(l=e.attrs)?void 0:l.some(e=>"s-model"===e.key||u(e.key).isDynamic))&&($=!0),e.type===c.For&&($=!0)),y.d=$?1:0,e.type){case c.Text:{const o=e.content??"";$?(y.f=n.compile("template",o,t),f(y,o,e.loc)):y.x=o;break}case c.Element:y.g=e.tag,d(e),y.a=h(e,t,n),e.children&&(y.c=m(e.children,t,n));break;case c.For:{const o=null==(s=e.attrs)?void 0:s.find(e=>"each"===e.key),c=(null==o?void 0:o.value)??"";y.f=n.compile("expression",c,t),y.i=(null==(a=null==(r=e.attrs)?void 0:r.find(e=>"item"===e.key))?void 0:a.value)??"item",y.n=(null==(v=null==(p=e.attrs)?void 0:p.find(e=>"index"===e.key))?void 0:v.value)??"index",f(y,c,(null==o?void 0:o.loc)??e.loc);const l=new Set(["each","item","index"]);y.a=h(e,t,n,l);const i=[...t,{i:y.i,x:y.n}];e.children&&(y.c=m(e.children,i,n));break}case c.If:case c.ElseIf:case c.Else:o&&console.warn(`[Solely] Orphaned conditional node found: ${c[e.type]}`),y.a=h(e,t,n),e.children&&(y.c=m(e.children,t,n));break;case c.Comment:y.x=e.content??""}return y}function m(e,t,n){var o;const l=[];let i=0;for(;i<e.length;){const s=e[i];if(s.type===c.If){const r=[];let a=i;for(;a<e.length;){const l=e[a],i=l.type;if(i!==c.If&&i!==c.ElseIf&&i!==c.Else)break;if(i===c.If&&r.length>0)break;let s,u=null,f="";if(i!==c.Else){const e=null==(o=l.attrs)?void 0:o.find(e=>"test"===e.key||"condition"===e.key);f=(null==e?void 0:e.value)??"false",u=n.compile("expression",f,t),s=(null==e?void 0:e.loc)??l.loc}const d=l.children?m(l.children,t,n):[],p=h(l,t,n,new Set(["test","condition"]));if(r.push({f:u,c:d,a:p.length>0?p:void 0,__m:{expr:f,loc:s}}),a++,i===c.Else)break}l.push({t:c.Conditional,d:1,b:r,__m:{loc:s.loc}}),i=a}else l.push(v(s,t,n)),i++}return l}function y(e,t={}){const{filename:n="anonymous",source:c}=t,l=r.get(n);l.clear();const i=performance.now(),s=m(e,[],l);for(const o of s)p(o);const a=performance.now(),u=l.getStats(),f=s.filter(e=>1===e.d).length,d=s.filter(e=>1===e.s).length,h={t:"root",v:"1.2.0",fns:l.getFunctions(),n:s,s:{tf:u.total,cf:u.cached,dn:f,tn:s.length,sn:d},m:{t:(new Date).toISOString(),as:e.length,fn:n,...c&&{src:c}}};return o&&console.info(`[Solely] Compiled <${n}> in ${(a-i).toFixed(2)}ms | Nodes: ${s.length} | Fns: ${u.total} | StaticSubtrees: ${d}`),h}function $(e){r.clear(e)}export{y as buildIR,$ as clearIRCache,d as transformModel};
1
+ var e=Object.defineProperty,t=(t,n,o)=>((t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o)(t,"symbol"!=typeof n?n+"":n,o);import{genFunction as n}from"../../shared/gen-function.js";import{IS_DEV as o}from"../../shared/env.js";import{ASTType as l}from"../../types/ast.js";import{isLifecycleKind as c}from"../../types/lifecycle.js";const i=/\{\{[\s\S]*?\}\}/,s={"solely-checkbox":{prop:"checked",event:"change"},"solely-switch":{prop:"checked",event:"change"},"solely-radio":{prop:"checked",event:"change"}},r=new class{constructor(){t(this,"compilers",new Map)}get(e="anonymous"){let t=this.compilers.get(e);return t||(t=new a,this.compilers.set(e,t)),t}clear(e){var t;if(e)null==(t=this.compilers.get(e))||t.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class a{constructor(){t(this,"cache",new Map),t(this,"functions",[])}makeCacheKey(e,t,n){return 0===n.length?`${e}:${t}`:`${e}:${t}:${n.map(e=>`${e.i}:${e.x}`).join(";")}`}compile(e,t,l){const c=null==t?void 0:t.trim();if(!c)return 0;const i=this.makeCacheKey(e,c,l),s=this.cache.get(i);if(void 0!==s)return s;let r;try{r=n(c,e,l)}catch(u){o&&console.error(`[Solely] IR Compile Error - Type: ${e}, Expr: "${c}"`,u),r=()=>""}const a=this.functions.push(r);return this.cache.set(i,a),a}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function u(e){const t=e[0];return":"===t?{isDynamic:!0,type:"expression"}:"@"===t?{isDynamic:!0,type:"handler"}:c(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function d(e,t,n){e.__m={expr:t??"",loc:n??void 0}}function f(e){if(!e.attrs)return;const t=e.attrs.find(e=>"s-model"===e.key);if(!t)return;const n=t.value.trim(),o=n.startsWith("$data.")?n:`$data.${n.replace(/^this\./,"")}`,l=t.loc,c=(e.tag||"").toLowerCase(),i=e.attrs.find(e=>"type"===e.key),r=(null==i?void 0:i.value)??"text";e.attrs=e.attrs.filter(e=>e!==t);const a=(t,n,o)=>{var c;null==(c=e.attrs)||c.push({key:t,value:n,role:o,loc:l})};if("input"===c){if("checkbox"===r){const t=e.attrs.find(e=>"value"===e.key),n=t?JSON.stringify(t.value):'"on"';return a(":checked",`Array.isArray(${o}) ? ${o}.includes(${n}) : ${o}`),void a("@change",`\n const _v = ${n};\n if(Array.isArray(${o})) {\n const _i = ${o}.indexOf(_v);\n if(checked && _i === -1) ${o}.push(_v);\n else if(!checked && _i > -1) ${o}.splice(_i,1);\n } else {\n ${o} = checked;\n }`,"model")}if("radio"===r){const t=e.attrs.find(e=>"value"===e.key),n=(null==t?void 0:t.value)??"null";return a(":checked",`${o} == ${JSON.stringify(n)}`),void a("@change",`if (checked) ${o} = ${JSON.stringify(n)}`,"model")}return a(":value",o),void a("@input",`${o} = value`,"model")}if("textarea"===c)return a(":value",o),void a("@input",`${o} = value`,"model");if("select"===c)return void(e.attrs.some(e=>"multiple"===e.key)?(a("updated",`\n const values = Array.isArray(${o}) ? ${o} : ${o} != null ? [${o}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),a("@change",`${o} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(a(":value",o),a("@change",`${o} = value`,"model")));const u=s[c],d=(null==u?void 0:u.prop)??"value",f=(null==u?void 0:u.event)??"change";a(`:${d}`,o),a(`@${f}`,`${o} = ${"checked"===d?"checked":"value"===d?"value":`event.target.${d}`}`,"model")}function h(e,t,n,o=null){if(!e.attrs||0===e.attrs.length)return[];const l=[];for(const c of e.attrs){if(o&&o.has(c.key))continue;const{key:i,value:s,role:r}=c,{isDynamic:a,type:f}=u(i);if(a&&f){const o={k:i,f:n.compile(f,s??"",t),d:1,r:r};d(o,s,c.loc??e.loc),l.push(o)}else l.push({k:i,v:s,d:0,r:r})}return l}function p(e){let t=0===e.d;if(e.c&&e.c.length>0)for(const n of e.c)p(n)||(t=!1);if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)p(e)||(t=!1);return!t||e.t!==l.Element&&e.t!==l.Text||(e.s=1),t}function v(e,t,n){var c,s,r,a,p,v;const y={t:e.type,d:0};let $=!1;var g;switch(e.type===l.Text?(g=e.content)&&i.test(g)&&($=!0):((null==(c=e.attrs)?void 0:c.some(e=>"s-model"===e.key||u(e.key).isDynamic))&&($=!0),e.type===l.For&&($=!0)),y.d=$?1:0,e.type){case l.Text:{const o=e.content??"";$?(y.f=n.compile("template",o,t),d(y,o,e.loc)):y.x=o;break}case l.Element:y.g=e.tag,f(e),y.a=h(e,t,n),e.children&&(y.c=m(e.children,t,n));break;case l.For:{const o=null==(s=e.attrs)?void 0:s.find(e=>"each"===e.key),l=(null==o?void 0:o.value)??"";y.f=n.compile("expression",l,t),y.i=(null==(a=null==(r=e.attrs)?void 0:r.find(e=>"item"===e.key))?void 0:a.value)??"item",y.n=(null==(v=null==(p=e.attrs)?void 0:p.find(e=>"index"===e.key))?void 0:v.value)??"index",d(y,l,(null==o?void 0:o.loc)??e.loc);const c=new Set(["each","item","index"]);y.a=h(e,t,n,c);const i=[...t,{i:y.i,x:y.n}];e.children&&(y.c=m(e.children,i,n));break}case l.If:case l.ElseIf:case l.Else:case l.Show:o&&console.warn(`[Solely] Orphaned conditional node found: ${l[e.type]}`),y.a=h(e,t,n),e.children&&(y.c=m(e.children,t,n));break;case l.Comment:y.x=e.content??""}return y}function m(e,t,n){var o,c;const i=[];let s=0;for(;s<e.length;){const r=e[s];if(r.type===l.If||r.type===l.Show){const a=[];let u=s;for(;u<e.length;){const i=e[u],s=i.type;if(s!==l.If&&s!==l.ElseIf&&s!==l.Else&&s!==l.Show)break;if((s===l.If||s===l.Show)&&a.length>0)break;let r,d=null,f="";if(s!==l.Else){const e=null==(o=i.attrs)?void 0:o.find(e=>"test"===e.key||"condition"===e.key);f=(null==e?void 0:e.value)??"false",d=n.compile("expression",f,t),r=(null==e?void 0:e.loc)??i.loc}const p=i.children?m(i.children,t,n):[],v=h(i,t,n,new Set(["test","condition","keepalive"])),y=s===l.Show||(null==(c=i.attrs)?void 0:c.some(e=>"keepalive"===e.key));if(a.push({f:d,c:p,a:v.length>0?v:void 0,ka:y?1:void 0,__m:{expr:f,loc:r}}),u++,s===l.Else||s===l.Show)break}i.push({t:l.Conditional,d:1,b:a,__m:{loc:r.loc}}),s=u}else i.push(v(r,t,n)),s++}return i}function y(e,t={}){const{filename:n="anonymous",source:l}=t,c=r.get(n);c.clear();const i=performance.now(),s=m(e,[],c);for(const o of s)p(o);const a=performance.now(),u=c.getStats(),d=s.filter(e=>1===e.d).length,f=s.filter(e=>1===e.s).length,h={t:"root",v:"1.2.0",fns:c.getFunctions(),n:s,s:{tf:u.total,cf:u.cached,dn:d,tn:s.length,sn:f},m:{t:(new Date).toISOString(),as:e.length,fn:n,...l&&{src:l}}};return o&&console.info(`[Solely] Compiled <${n}> in ${(a-i).toFixed(2)}ms | Nodes: ${s.length} | Fns: ${u.total} | StaticSubtrees: ${f}`),h}function $(e){r.clear(e)}export{y as buildIR,$ as clearIRCache,f as transformModel};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../shared/event-listeners.cjs"),e=require("../../types/ast.cjs"),n=require("../../types/lifecycle.cjs"),s=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,r=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),o=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function i(r,i){var c;const l=(null==(c=(r.match(s)||[])[1])?void 0:c.toLowerCase())??"",a=function(e,s){o.lastIndex=0;const r=[];let i;const c=e.replace(/^\s*[^\s"'/>]+/,""),l=e.length-c.length;for(;null!==(i=o.exec(c));){const o=i[1];if(!o)continue;const c=i[2]??i[3]??i[4]??"";let a=o;t.default.has(o)&&(a=a.replace(/^on/,"@")),"s-model"!==a&&(a=a.replace(/^on-/,"@").replace(/^s-/,":")),a=n.mapAttrKeyToLifecycleKind(a)||a;const h=i[0],f=h.indexOf("=");let u;if(-1===f)u=h.indexOf(o)+o.length;else{let t=f+1;for(;t<h.length&&/\s/.test(h[t]);)t++;if('"'===h[t]||"'"===h[t]){let e=t+1;for(;e<h.length&&/\s/.test(h[e]);)e++;u=e}else{let e=t;for(;e<h.length&&/\s/.test(h[e]);)e++;u=e}}const p=i.index+u+l,g=e.slice(0,p).split("\n"),T=s[0]+g.length-1,y=g.length>1?g[g.length-1].length+1:s[1]+p;r.push({key:a,value:c,loc:[T,y]})}return r}(r,i);return{type:{for:e.ASTType.For,if:e.ASTType.If,elseif:e.ASTType.ElseIf,else:e.ASTType.Else}[l]??e.ASTType.Element,tag:l,loc:i,children:[],attrs:a}}function c(t,e){const n=t.length;if(t.startsWith("!--",e)){const n=t.indexOf("--\x3e",e+3);return-1===n?-1:n+2}if(t.startsWith("![CDATA[",e)){const n=t.indexOf("]]>",e+8);return-1===n?-1:n+2}if("!"===t[e])return t.indexOf(">",e+1);if("?"===t[e]){const n=t.indexOf("?>",e+1);return-1===n?-1:n+1}let s=!1,r=!1,o=e;for(;o<n;){const e=t[o];if("'"!==e||r)if('"'!==e||s){if(">"===e&&!s&&!r)return o}else r=!r;else s=!s;o++}return-1}exports.parseHtml=function(t){var n,o;const l=[];if(!t)return[];const a=[],h=()=>{var t;return 0===a.length?l:(t=a[a.length-1]).children||(t.children=[])};let f=0;const u=t.length,p=[0];let g=0;for(;-1!==(g=t.indexOf("\n",g));)p.push(++g);function T(t){let e=0,n=p.length-1;for(;e<=n;){const s=e+n>>>1;p[s]<=t?e=s+1:n=s-1}return[n+1,t-p[n]+1]}for(;f<u;){const l=t.indexOf("<",f);if(-1===l||l>f){const n=t.substring(f,-1===l?void 0:l),s=a.length>0?a[a.length-1]:null;let r,o;if(!s||"pre"!==s.tag&&"code"!==s.tag&&"textarea"!==s.tag&&"script"!==s.tag&&"style"!==s.tag){if(r=n.trim(),""===r){if(f=l,-1===l)break;continue}o=f+(n.length-n.trimStart().length)}else r=n,o=f;const i=h(),c=i[i.length-1];if(c&&c.type===e.ASTType.Text)c.content+=r;else{const t=T(o);i.push({type:e.ASTType.Text,tag:"text",content:r,loc:t,children:[]})}if(-1===l)break;f=l}const p=c(t,f+1);if(-1===p){const n=t.substring(f);n.trim()&&h().push({type:e.ASTType.Text,tag:"text",content:n.trim(),children:[],loc:T(f)});break}const g=t.substring(f,p+1),y=h(),d=T(f);if(g.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(4,-3),loc:d,children:[]}),f=p+1;continue}if(g.startsWith("<![CDATA[")){y.push({type:e.ASTType.Text,tag:"text",content:g.slice(9,-3),loc:d,children:[]}),f=p+1;continue}if(g.startsWith("<!")&&!g.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(2,-1),loc:d,children:[]}),f=p+1;continue}if(g.startsWith("<?")){y.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(2,-2),loc:d,children:[]}),f=p+1;continue}if(g.startsWith("</")){const t=null==(n=(g.match(s)||[])[1])?void 0:n.toLowerCase();if(t){let e=-1;for(let n=a.length-1;n>=0;n--)if((null==(o=a[n].tag)?void 0:o.toLowerCase())===t){e=n;break}-1!==e&&(a.length=e)}f=p+1;continue}const x=i(g,d);y.push(x);const m=x.tag||"",A=m.toLowerCase().startsWith("script"),S=m.toLowerCase().startsWith("style"),b=g.endsWith("/>")||r.has(m.toLowerCase());if((A||S)&&!b){const n=`</${m}>`,s=t.toLowerCase().indexOf(n,p+1);if(-1!==s){const r=t.substring(p+1,s);r.length&&x.children.push({type:e.ASTType.Text,tag:"text",content:r,loc:T(p+1),children:[]}),f=s+n.length;continue}{const n=t.substring(p+1);n.length&&x.children.push({type:e.ASTType.Text,tag:"text",content:n,loc:T(p+1),children:[]}),f=u;continue}}b||x.type===e.ASTType.Text||x.type===e.ASTType.Comment||a.push(x),f=p+1}return l};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../shared/event-listeners.cjs"),e=require("../../types/ast.cjs"),n=require("../../types/lifecycle.cjs"),s=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,o=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function i(o,i){var c;const l=(null==(c=(o.match(s)||[])[1])?void 0:c.toLowerCase())??"",a=function(e,s){r.lastIndex=0;const o=[];let i;const c=e.replace(/^\s*[^\s"'/>]+/,""),l=e.length-c.length;for(;null!==(i=r.exec(c));){const r=i[1];if(!r)continue;const c=i[2]??i[3]??i[4]??"";let a=r;t.default.has(r)&&(a=a.replace(/^on/,"@")),"s-model"!==a&&(a=a.replace(/^on-/,"@").replace(/^s-/,":")),a=n.mapAttrKeyToLifecycleKind(a)||a;const h=i[0],f=h.indexOf("=");let p;if(-1===f)p=h.indexOf(r)+r.length;else{let t=f+1;for(;t<h.length&&/\s/.test(h[t]);)t++;if('"'===h[t]||"'"===h[t]){let e=t+1;for(;e<h.length&&/\s/.test(h[e]);)e++;p=e}else{let e=t;for(;e<h.length&&/\s/.test(h[e]);)e++;p=e}}const u=i.index+p+l,g=e.slice(0,u).split("\n"),T=s[0]+g.length-1,y=g.length>1?g[g.length-1].length+1:s[1]+u;o.push({key:a,value:c,loc:[T,y]})}return o}(o,i);return{type:{for:e.ASTType.For,if:e.ASTType.If,elseif:e.ASTType.ElseIf,else:e.ASTType.Else,show:e.ASTType.Show}[l]??e.ASTType.Element,tag:l,loc:i,children:[],attrs:a}}function c(t,e){const n=t.length;if(t.startsWith("!--",e)){const n=t.indexOf("--\x3e",e+3);return-1===n?-1:n+2}if(t.startsWith("![CDATA[",e)){const n=t.indexOf("]]>",e+8);return-1===n?-1:n+2}if("!"===t[e])return t.indexOf(">",e+1);if("?"===t[e]){const n=t.indexOf("?>",e+1);return-1===n?-1:n+1}let s=!1,o=!1,r=e;for(;r<n;){const e=t[r];if("'"!==e||o)if('"'!==e||s){if(">"===e&&!s&&!o)return r}else o=!o;else s=!s;r++}return-1}exports.parseHtml=function(t){var n,r;const l=[];if(!t)return[];const a=[],h=()=>{var t;return 0===a.length?l:(t=a[a.length-1]).children||(t.children=[])};let f=0;const p=t.length,u=[0];let g=0;for(;-1!==(g=t.indexOf("\n",g));)u.push(++g);function T(t){let e=0,n=u.length-1;for(;e<=n;){const s=e+n>>>1;u[s]<=t?e=s+1:n=s-1}return[n+1,t-u[n]+1]}for(;f<p;){const l=t.indexOf("<",f);if(-1===l||l>f){const n=t.substring(f,-1===l?void 0:l),s=a.length>0?a[a.length-1]:null;let o,r;if(!s||"pre"!==s.tag&&"code"!==s.tag&&"textarea"!==s.tag&&"script"!==s.tag&&"style"!==s.tag){if(o=n.trim(),""===o){if(f=l,-1===l)break;continue}r=f+(n.length-n.trimStart().length)}else o=n,r=f;const i=h(),c=i[i.length-1];if(c&&c.type===e.ASTType.Text)c.content+=o;else{const t=T(r);i.push({type:e.ASTType.Text,tag:"text",content:o,loc:t,children:[]})}if(-1===l)break;f=l}const u=c(t,f+1);if(-1===u){const n=t.substring(f);n.trim()&&h().push({type:e.ASTType.Text,tag:"text",content:n.trim(),children:[],loc:T(f)});break}const g=t.substring(f,u+1),y=h(),d=T(f);if(g.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(4,-3),loc:d,children:[]}),f=u+1;continue}if(g.startsWith("<![CDATA[")){y.push({type:e.ASTType.Text,tag:"text",content:g.slice(9,-3),loc:d,children:[]}),f=u+1;continue}if(g.startsWith("<!")&&!g.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(2,-1),loc:d,children:[]}),f=u+1;continue}if(g.startsWith("<?")){y.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(2,-2),loc:d,children:[]}),f=u+1;continue}if(g.startsWith("</")){const t=null==(n=(g.match(s)||[])[1])?void 0:n.toLowerCase();if(t){let e=-1;for(let n=a.length-1;n>=0;n--)if((null==(r=a[n].tag)?void 0:r.toLowerCase())===t){e=n;break}-1!==e&&(a.length=e)}f=u+1;continue}const x=i(g,d);y.push(x);const m=x.tag||"",A=m.toLowerCase().startsWith("script"),S=m.toLowerCase().startsWith("style"),b=g.endsWith("/>")||o.has(m.toLowerCase());if((A||S)&&!b){const n=`</${m}>`,s=t.toLowerCase().indexOf(n,u+1);if(-1!==s){const o=t.substring(u+1,s);o.length&&x.children.push({type:e.ASTType.Text,tag:"text",content:o,loc:T(u+1),children:[]}),f=s+n.length;continue}{const n=t.substring(u+1);n.length&&x.children.push({type:e.ASTType.Text,tag:"text",content:n,loc:T(u+1),children:[]}),f=p;continue}}b||x.type===e.ASTType.Text||x.type===e.ASTType.Comment||a.push(x),f=u+1}return l};
@@ -1 +1 @@
1
- import t from"../../shared/event-listeners.js";import{ASTType as e}from"../../types/ast.js";import{mapAttrKeyToLifecycleKind as n}from"../../types/lifecycle.js";const s=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,o=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function i(o,i){var l;const c=(null==(l=(o.match(s)||[])[1])?void 0:l.toLowerCase())??"",h=function(e,s){r.lastIndex=0;const o=[];let i;const l=e.replace(/^\s*[^\s"'/>]+/,""),c=e.length-l.length;for(;null!==(i=r.exec(l));){const r=i[1];if(!r)continue;const l=i[2]??i[3]??i[4]??"";let h=r;t.has(r)&&(h=h.replace(/^on/,"@")),"s-model"!==h&&(h=h.replace(/^on-/,"@").replace(/^s-/,":")),h=n(h)||h;const a=i[0],f=a.indexOf("=");let u;if(-1===f)u=a.indexOf(r)+r.length;else{let t=f+1;for(;t<a.length&&/\s/.test(a[t]);)t++;if('"'===a[t]||"'"===a[t]){let e=t+1;for(;e<a.length&&/\s/.test(a[e]);)e++;u=e}else{let e=t;for(;e<a.length&&/\s/.test(a[e]);)e++;u=e}}const g=i.index+u+c,p=e.slice(0,g).split("\n"),d=s[0]+p.length-1,m=p.length>1?p[p.length-1].length+1:s[1]+g;o.push({key:h,value:l,loc:[d,m]})}return o}(o,i);return{type:{for:e.For,if:e.If,elseif:e.ElseIf,else:e.Else}[c]??e.Element,tag:c,loc:i,children:[],attrs:h}}function l(t,e){const n=t.length;if(t.startsWith("!--",e)){const n=t.indexOf("--\x3e",e+3);return-1===n?-1:n+2}if(t.startsWith("![CDATA[",e)){const n=t.indexOf("]]>",e+8);return-1===n?-1:n+2}if("!"===t[e])return t.indexOf(">",e+1);if("?"===t[e]){const n=t.indexOf("?>",e+1);return-1===n?-1:n+1}let s=!1,o=!1,r=e;for(;r<n;){const e=t[r];if("'"!==e||o)if('"'!==e||s){if(">"===e&&!s&&!o)return r}else o=!o;else s=!s;r++}return-1}function c(t){var n,r;const c=[];if(!t)return[];const h=[],a=()=>{var t;return 0===h.length?c:(t=h[h.length-1]).children||(t.children=[])};let f=0;const u=t.length,g=[0];let p=0;for(;-1!==(p=t.indexOf("\n",p));)g.push(++p);function d(t){let e=0,n=g.length-1;for(;e<=n;){const s=e+n>>>1;g[s]<=t?e=s+1:n=s-1}return[n+1,t-g[n]+1]}for(;f<u;){const c=t.indexOf("<",f);if(-1===c||c>f){const n=t.substring(f,-1===c?void 0:c),s=h.length>0?h[h.length-1]:null;let o,r;if(!s||"pre"!==s.tag&&"code"!==s.tag&&"textarea"!==s.tag&&"script"!==s.tag&&"style"!==s.tag){if(o=n.trim(),""===o){if(f=c,-1===c)break;continue}r=f+(n.length-n.trimStart().length)}else o=n,r=f;const i=a(),l=i[i.length-1];if(l&&l.type===e.Text)l.content+=o;else{const t=d(r);i.push({type:e.Text,tag:"text",content:o,loc:t,children:[]})}if(-1===c)break;f=c}const g=l(t,f+1);if(-1===g){const n=t.substring(f);n.trim()&&a().push({type:e.Text,tag:"text",content:n.trim(),children:[],loc:d(f)});break}const p=t.substring(f,g+1),m=a(),x=d(f);if(p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(4,-3),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<![CDATA[")){m.push({type:e.Text,tag:"text",content:p.slice(9,-3),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<!")&&!p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-1),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<?")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-2),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("</")){const t=null==(n=(p.match(s)||[])[1])?void 0:n.toLowerCase();if(t){let e=-1;for(let n=h.length-1;n>=0;n--)if((null==(r=h[n].tag)?void 0:r.toLowerCase())===t){e=n;break}-1!==e&&(h.length=e)}f=g+1;continue}const y=i(p,x);m.push(y);const b=y.tag||"",C=b.toLowerCase().startsWith("script"),W=b.toLowerCase().startsWith("style"),v=p.endsWith("/>")||o.has(b.toLowerCase());if((C||W)&&!v){const n=`</${b}>`,s=t.toLowerCase().indexOf(n,g+1);if(-1!==s){const o=t.substring(g+1,s);o.length&&y.children.push({type:e.Text,tag:"text",content:o,loc:d(g+1),children:[]}),f=s+n.length;continue}{const n=t.substring(g+1);n.length&&y.children.push({type:e.Text,tag:"text",content:n,loc:d(g+1),children:[]}),f=u;continue}}v||y.type===e.Text||y.type===e.Comment||h.push(y),f=g+1}return c}export{c as parseHtml};
1
+ import t from"../../shared/event-listeners.js";import{ASTType as e}from"../../types/ast.js";import{mapAttrKeyToLifecycleKind as n}from"../../types/lifecycle.js";const s=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,o=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function i(o,i){var l;const c=(null==(l=(o.match(s)||[])[1])?void 0:l.toLowerCase())??"",h=function(e,s){r.lastIndex=0;const o=[];let i;const l=e.replace(/^\s*[^\s"'/>]+/,""),c=e.length-l.length;for(;null!==(i=r.exec(l));){const r=i[1];if(!r)continue;const l=i[2]??i[3]??i[4]??"";let h=r;t.has(r)&&(h=h.replace(/^on/,"@")),"s-model"!==h&&(h=h.replace(/^on-/,"@").replace(/^s-/,":")),h=n(h)||h;const a=i[0],f=a.indexOf("=");let u;if(-1===f)u=a.indexOf(r)+r.length;else{let t=f+1;for(;t<a.length&&/\s/.test(a[t]);)t++;if('"'===a[t]||"'"===a[t]){let e=t+1;for(;e<a.length&&/\s/.test(a[e]);)e++;u=e}else{let e=t;for(;e<a.length&&/\s/.test(a[e]);)e++;u=e}}const g=i.index+u+c,p=e.slice(0,g).split("\n"),d=s[0]+p.length-1,m=p.length>1?p[p.length-1].length+1:s[1]+g;o.push({key:h,value:l,loc:[d,m]})}return o}(o,i);return{type:{for:e.For,if:e.If,elseif:e.ElseIf,else:e.Else,show:e.Show}[c]??e.Element,tag:c,loc:i,children:[],attrs:h}}function l(t,e){const n=t.length;if(t.startsWith("!--",e)){const n=t.indexOf("--\x3e",e+3);return-1===n?-1:n+2}if(t.startsWith("![CDATA[",e)){const n=t.indexOf("]]>",e+8);return-1===n?-1:n+2}if("!"===t[e])return t.indexOf(">",e+1);if("?"===t[e]){const n=t.indexOf("?>",e+1);return-1===n?-1:n+1}let s=!1,o=!1,r=e;for(;r<n;){const e=t[r];if("'"!==e||o)if('"'!==e||s){if(">"===e&&!s&&!o)return r}else o=!o;else s=!s;r++}return-1}function c(t){var n,r;const c=[];if(!t)return[];const h=[],a=()=>{var t;return 0===h.length?c:(t=h[h.length-1]).children||(t.children=[])};let f=0;const u=t.length,g=[0];let p=0;for(;-1!==(p=t.indexOf("\n",p));)g.push(++p);function d(t){let e=0,n=g.length-1;for(;e<=n;){const s=e+n>>>1;g[s]<=t?e=s+1:n=s-1}return[n+1,t-g[n]+1]}for(;f<u;){const c=t.indexOf("<",f);if(-1===c||c>f){const n=t.substring(f,-1===c?void 0:c),s=h.length>0?h[h.length-1]:null;let o,r;if(!s||"pre"!==s.tag&&"code"!==s.tag&&"textarea"!==s.tag&&"script"!==s.tag&&"style"!==s.tag){if(o=n.trim(),""===o){if(f=c,-1===c)break;continue}r=f+(n.length-n.trimStart().length)}else o=n,r=f;const i=a(),l=i[i.length-1];if(l&&l.type===e.Text)l.content+=o;else{const t=d(r);i.push({type:e.Text,tag:"text",content:o,loc:t,children:[]})}if(-1===c)break;f=c}const g=l(t,f+1);if(-1===g){const n=t.substring(f);n.trim()&&a().push({type:e.Text,tag:"text",content:n.trim(),children:[],loc:d(f)});break}const p=t.substring(f,g+1),m=a(),x=d(f);if(p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(4,-3),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<![CDATA[")){m.push({type:e.Text,tag:"text",content:p.slice(9,-3),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<!")&&!p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-1),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("<?")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-2),loc:x,children:[]}),f=g+1;continue}if(p.startsWith("</")){const t=null==(n=(p.match(s)||[])[1])?void 0:n.toLowerCase();if(t){let e=-1;for(let n=h.length-1;n>=0;n--)if((null==(r=h[n].tag)?void 0:r.toLowerCase())===t){e=n;break}-1!==e&&(h.length=e)}f=g+1;continue}const y=i(p,x);m.push(y);const b=y.tag||"",C=b.toLowerCase().startsWith("script"),w=b.toLowerCase().startsWith("style"),W=p.endsWith("/>")||o.has(b.toLowerCase());if((C||w)&&!W){const n=`</${b}>`,s=t.toLowerCase().indexOf(n,g+1);if(-1!==s){const o=t.substring(g+1,s);o.length&&y.children.push({type:e.Text,tag:"text",content:o,loc:d(g+1),children:[]}),f=s+n.length;continue}{const n=t.substring(g+1);n.length&&y.children.push({type:e.Text,tag:"text",content:n,loc:d(g+1),children:[]}),f=u;continue}}W||y.type===e.Text||y.type===e.Comment||h.push(y),f=g+1}return c}export{c as parseHtml};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./router/index.cjs"),r=require("./shared/templateError.cjs"),t=require("./shared/gen-function.cjs"),s=require("./shared/functions.cjs"),o=require("./shared/event-listeners.cjs"),c=require("./shared/is-object.cjs"),i=require("./shared/url.cjs"),u=require("./shared/env.cjs"),a=require("./shared/case-convert.cjs"),n=require("./types/ast.cjs"),p=require("./types/lifecycle.cjs"),l=require("./runtime/component/base-element.cjs"),d=require("./router/router-link.cjs"),x=require("./router/router-view.cjs"),m=require("./runtime/renderer/html-decode.cjs"),R=require("./runtime/component/decorators.cjs"),j=require("./runtime/renderer/renderIR.cjs"),q=require("./router/core.cjs"),b=require("./compiler/ir/buildIR.cjs"),y=require("./runtime/reactivity/observe.cjs"),f=require("./compiler/parser/parser.cjs");exports.createRouter=e.createRouter,exports.showTemplateError=r.showTemplateError,exports.genFunction=t.genFunction,exports.createFunction=s.createFunction,exports.isCSPBlocked=s.isCSPBlocked,exports.listeners=o.default,exports.isObject=c.isObject,exports.parseHashUrl=i.parseHashUrl,exports.IS_DEV=u.IS_DEV,exports.IS_PROD=u.IS_PROD,exports.camelToKebab=a.camelToKebab,exports.ASTType=n.ASTType,exports.LIFECYCLE_ATTRS_MAP=p.LIFECYCLE_ATTRS_MAP,exports.isLifecycleKind=p.isLifecycleKind,exports.mapAttrKeyToLifecycleKind=p.mapAttrKeyToLifecycleKind,exports.BaseElement=l.default,Object.defineProperty(exports,"RouterLink",{enumerable:!0,get:()=>d.default}),Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>x.default}),exports.htmlDecode=m.default,exports.CustomElement=R.CustomElement,exports.IRRenderer=j.IRRenderer,exports.createRender=j.createRender,exports.Router=q.Router,exports.getRouter=q.getRouter,exports.routerReady=q.routerReady,exports.buildIR=b.buildIR,exports.clearIRCache=b.clearIRCache,exports.transformModel=b.transformModel,exports.isProxy=y.isProxy,exports.observe=y.observe,exports.toRaw=y.toRaw,exports.parseHtml=f.parseHtml;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./router/index.cjs"),r=require("./shared/templateError.cjs"),t=require("./shared/gen-function.cjs"),o=require("./shared/functions.cjs"),s=require("./shared/event-listeners.cjs"),c=require("./shared/is-object.cjs"),i=require("./shared/url.cjs"),u=require("./shared/env.cjs"),a=require("./shared/case-convert.cjs"),p=require("./types/ast.cjs"),n=require("./types/lifecycle.cjs"),l=require("./runtime/component/base-element.cjs"),d=require("./router/router-link.cjs"),x=require("./router/router-view.cjs"),m=require("./runtime/renderer/html-decode.cjs"),R=require("./runtime/component/decorators.cjs"),j=require("./runtime/renderer/renderIR.cjs"),y=require("./router/core.cjs"),q=require("./compiler/ir/buildIR.cjs"),h=require("./runtime/reactivity/computed.cjs"),b=require("./runtime/reactivity/observe.cjs"),f=require("./compiler/parser/parser.cjs"),E=require("./runtime/reactivity/watch.cjs");exports.createRouter=e.createRouter,exports.showTemplateError=r.showTemplateError,exports.genFunction=t.genFunction,exports.createFunction=o.createFunction,exports.isCSPBlocked=o.isCSPBlocked,exports.listeners=s.default,exports.isObject=c.isObject,exports.parseHashUrl=i.parseHashUrl,exports.IS_DEV=u.IS_DEV,exports.IS_PROD=u.IS_PROD,exports.SOLELY_VERSION=u.SOLELY_VERSION,exports.camelToKebab=a.camelToKebab,exports.ASTType=p.ASTType,exports.LIFECYCLE_ATTRS_MAP=n.LIFECYCLE_ATTRS_MAP,exports.isLifecycleKind=n.isLifecycleKind,exports.mapAttrKeyToLifecycleKind=n.mapAttrKeyToLifecycleKind,exports.BaseElement=l.default,Object.defineProperty(exports,"RouterLink",{enumerable:!0,get:()=>d.default}),Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>x.default}),exports.htmlDecode=m.default,exports.CustomElement=R.CustomElement,exports.IRRenderer=j.IRRenderer,exports.createRender=j.createRender,exports.Router=y.Router,exports.getRouter=y.getRouter,exports.routerReady=y.routerReady,exports.buildIR=q.buildIR,exports.clearIRCache=q.clearIRCache,exports.transformModel=q.transformModel,exports.computed=h.computed,exports.isProxy=b.isProxy,exports.observe=b.observe,exports.toProxy=b.toProxy,exports.toRaw=b.toRaw,exports.parseHtml=f.parseHtml,exports.watch=E.watch,exports.watchGetter=E.watchGetter;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{createRouter as r}from"./router/index.js";import{showTemplateError as e}from"./shared/templateError.js";import{genFunction as o}from"./shared/gen-function.js";import{createFunction as t,isCSPBlocked as m}from"./shared/functions.js";import{default as s}from"./shared/event-listeners.js";import{isObject as i}from"./shared/is-object.js";import{parseHashUrl as a}from"./shared/url.js";import{IS_DEV as p,IS_PROD as f}from"./shared/env.js";import{camelToKebab as n}from"./shared/case-convert.js";import{ASTType as d}from"./types/ast.js";import{LIFECYCLE_ATTRS_MAP as j,isLifecycleKind as u,mapAttrKeyToLifecycleKind as l}from"./types/lifecycle.js";import{default as c}from"./runtime/component/base-element.js";import{default as h}from"./router/router-link.js";import{default as v}from"./router/router-view.js";import{default as b}from"./runtime/renderer/html-decode.js";import{CustomElement as y}from"./runtime/component/decorators.js";import{IRRenderer as R,createRender as k}from"./runtime/renderer/renderIR.js";import{Router as w,getRouter as x,routerReady as E}from"./router/core.js";import{buildIR as I,clearIRCache as g,transformModel as B}from"./compiler/ir/buildIR.js";import{isProxy as D,observe as L,toRaw as V}from"./runtime/reactivity/observe.js";import{parseHtml as q}from"./compiler/parser/parser.js";export{d as ASTType,c as BaseElement,y as CustomElement,R as IRRenderer,p as IS_DEV,f as IS_PROD,j as LIFECYCLE_ATTRS_MAP,w as Router,h as RouterLink,v as RouterView,I as buildIR,n as camelToKebab,g as clearIRCache,t as createFunction,k as createRender,r as createRouter,o as genFunction,x as getRouter,b as htmlDecode,m as isCSPBlocked,u as isLifecycleKind,i as isObject,D as isProxy,s as listeners,l as mapAttrKeyToLifecycleKind,L as observe,a as parseHashUrl,q as parseHtml,E as routerReady,e as showTemplateError,V as toRaw,B as transformModel};
1
+ import{createRouter as r}from"./router/index.js";import{showTemplateError as e}from"./shared/templateError.js";import{genFunction as o}from"./shared/gen-function.js";import{createFunction as t,isCSPBlocked as m}from"./shared/functions.js";import{default as s}from"./shared/event-listeners.js";import{isObject as i}from"./shared/is-object.js";import{parseHashUrl as a}from"./shared/url.js";import{IS_DEV as p,IS_PROD as f,SOLELY_VERSION as n}from"./shared/env.js";import{camelToKebab as u}from"./shared/case-convert.js";import{ASTType as j}from"./types/ast.js";import{LIFECYCLE_ATTRS_MAP as d,isLifecycleKind as c,mapAttrKeyToLifecycleKind as l}from"./types/lifecycle.js";import{default as h}from"./runtime/component/base-element.js";import{default as v}from"./router/router-link.js";import{default as y}from"./router/router-view.js";import{default as b}from"./runtime/renderer/html-decode.js";import{CustomElement as R}from"./runtime/component/decorators.js";import{IRRenderer as w,createRender as k}from"./runtime/renderer/renderIR.js";import{Router as x,getRouter as E,routerReady as I}from"./router/core.js";import{buildIR as g,clearIRCache as B,transformModel as D}from"./compiler/ir/buildIR.js";import{computed as L}from"./runtime/reactivity/computed.js";import{isProxy as V,observe as q,toProxy as z,toRaw as A}from"./runtime/reactivity/observe.js";import{parseHtml as C}from"./compiler/parser/parser.js";import{watch as F,watchGetter as G}from"./runtime/reactivity/watch.js";export{j as ASTType,h as BaseElement,R as CustomElement,w as IRRenderer,p as IS_DEV,f as IS_PROD,d as LIFECYCLE_ATTRS_MAP,x as Router,v as RouterLink,y as RouterView,n as SOLELY_VERSION,g as buildIR,u as camelToKebab,B as clearIRCache,L as computed,t as createFunction,k as createRender,r as createRouter,o as genFunction,E as getRouter,b as htmlDecode,m as isCSPBlocked,c as isLifecycleKind,i as isObject,V as isProxy,s as listeners,l as mapAttrKeyToLifecycleKind,q as observe,a as parseHashUrl,C as parseHtml,I as routerReady,e as showTemplateError,z as toProxy,A as toRaw,D as transformModel,F as watch,G as watchGetter};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("magic-string"),n=require("../compiler/parser/parser.cjs"),o=require("../compiler/ir/buildIR.cjs"),r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function t(e,r="anonymous"){const t=n.parseHtml(e);return o.buildIR(t,{filename:r,source:e})}function p(e,n){return(Array.isArray(n)?n:[n]).some(n=>"string"==typeof n?e.includes(n):n.test(e))}function i(n,o,r){const t=new e.default(n),p=n.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return t.overwrite(0,n.length,`\nconst __SOLELY_TEMPLATE__ = \`${p}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:t.toString(),map:t.generateMap({source:o,includeContent:!r})}}function l(n={}){const o={...r,...n};return{name:"solely-vite-plugin",enforce:"pre",configResolved(e){o.debug&&console.info("[Solely] Plugin initialized with options:",o)},transform(n,r){if(!p(r,o.include)||p(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug&&console.info(`[Solely] Processing: ${r}`),o.precompile){const p=t(n,r),i=function(n,o,r,t){const p=new e.default(o);p.remove(0,o.length),t||(p.append("\n// ============================================\n"),p.append("// Solely Precompiled Template\n"),p.append(`// Compiled at: ${(new Date).toISOString()}\n`),p.append("// ============================================\n\n")),p.append("const __SOLELY_IR__ = {\n"),p.append(" t: 'root',\n"),p.append(` v: '${n.v}',\n\n`),t||p.append(" // 编译后的函数数组\n"),p.append(" fns: [\n"),n.fns.forEach((e,o)=>{const r="string"==typeof e?e:e.toString(),i=o===n.fns.length-1;t||p.append(` // Function ${o+1}\n`),p.append(` ${r}${i?"":","}\n`)}),p.append(" ],\n\n");const i=e=>{const n={t:e.t,d:e.d};return void 0!==e.s&&(n.s=e.s),void 0!==e.g&&(n.g=e.g),void 0!==e.x&&(n.x=e.x),void 0!==e.f&&(n.f=e.f),void 0!==e.i&&(n.i=e.i),void 0!==e.n&&(n.n=e.n),!t&&e.__m&&(n.__m={...e.__m}),e.a&&(n.a=e.a.map(e=>({k:e.k,v:e.v,f:e.f,d:e.d,r:e.r,...!t&&e.__m&&{__m:{...e.__m}}}))),e.c&&(n.c=e.c.map(i)),e.b&&(n.b=e.b.map(e=>{var n;return{f:e.f,c:e.c.map(i),a:null==(n=e.a)?void 0:n.map(e=>({k:e.k,v:e.v,f:e.f,d:e.d,r:e.r})),...!t&&e.__m&&{__m:{...e.__m}}}})),n},l=n.n.map(i);return t||p.append(" // IR 节点树\n"),p.append(` n: ${JSON.stringify(l,null,t?0:2)},\n\n`),t||p.append(" // 编译统计\n"),p.append(` s: ${JSON.stringify(n.s)},\n\n`),t||(p.append(" // 元数据\n"),p.append(` m: ${JSON.stringify(n.m)}\n`)),p.append("};\n\n"),t||p.append("// 导出 IR 对象\n"),p.append("export default __SOLELY_IR__;\n"),p.append("export { __SOLELY_IR__ };\n\n"),t||p.append("// 同时导出模板字符串(向后兼容)\n"),p.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:p.toString(),map:p.generateMap({source:r,includeContent:!t,hires:!t})}}(p,n,r,!!o.minify);return o.debug&&(console.info(`[Solely] Compiled IR for: ${r}`),console.info("[Solely] Stats:",p.s)),{code:i.code,map:o.sourceMap?i.map:null}}{const e=i(n,r,!!o.minify);return{code:e.code,map:o.sourceMap?e.map:null}}}catch(l){const e=`[Solely] Error processing ${r}: ${l instanceof Error?l.message:String(l)}`;console.error(e),console.warn(`[Solely] Falling back to raw template for: ${r}`);const t=i(n,r,!!o.minify);return{code:t.code,map:o.sourceMap?t.map:null}}},handleHotUpdate({file:e,server:n,modules:r}){if(p(e,o.include)&&!p(e,o.exclude))return o.debug&&console.info(`[Solely] HMR triggered for: ${e}`),n.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=l),exports.compileTemplate=t,exports.solelyVitePlugin=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("magic-string"),n=require("../compiler/parser/parser.cjs"),o=require("../compiler/ir/buildIR.cjs"),r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function t(e,r="anonymous"){const t=n.parseHtml(e);return o.buildIR(t,{filename:r,source:e})}function p(e,n){return(Array.isArray(n)?n:[n]).some(n=>"string"==typeof n?e.includes(n):n.test(e))}function i(n,o,r){const t=new e.default(n),p=n.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return t.overwrite(0,n.length,`\nconst __SOLELY_TEMPLATE__ = \`${p}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:t.toString(),map:t.generateMap({source:o,includeContent:!r})}}function l(n={}){const o={...r,...n};return{name:"solely-vite-plugin",enforce:"pre",configResolved(e){o.debug&&console.info("[Solely] Plugin initialized with options:",o)},transform(n,r){if(!p(r,o.include)||p(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug&&console.info(`[Solely] Processing: ${r}`),o.precompile){const p=t(n,r),i=function(n,o,r,t){const p=new e.default(o);p.remove(0,o.length),t||(p.append("\n// ============================================\n"),p.append("// Solely Precompiled Template\n"),p.append(`// Compiled at: ${(new Date).toISOString()}\n`),p.append("// ============================================\n\n")),p.append("const __SOLELY_IR__ = {\n"),p.append(" t: 'root',\n"),p.append(` v: '${n.v}',\n\n`),t||p.append(" // 编译后的函数数组\n"),p.append(" fns: [\n"),n.fns.forEach((e,o)=>{const r="string"==typeof e?e:e.toString(),i=o===n.fns.length-1;t||p.append(` // Function ${o+1}\n`),p.append(` ${r}${i?"":","}\n`)}),p.append(" ],\n\n");const i=e=>{const n={t:e.t,d:e.d};return void 0!==e.s&&(n.s=e.s),void 0!==e.g&&(n.g=e.g),void 0!==e.x&&(n.x=e.x),void 0!==e.f&&(n.f=e.f),void 0!==e.i&&(n.i=e.i),void 0!==e.n&&(n.n=e.n),!t&&e.__m&&(n.__m={...e.__m}),e.a&&(n.a=e.a.map(e=>({k:e.k,v:e.v,f:e.f,d:e.d,r:e.r,...!t&&e.__m&&{__m:{...e.__m}}}))),e.c&&(n.c=e.c.map(i)),e.b&&(n.b=e.b.map(e=>{var n;return{f:e.f,c:e.c.map(i),a:null==(n=e.a)?void 0:n.map(e=>({k:e.k,v:e.v,f:e.f,d:e.d,r:e.r})),...void 0!==e.ka&&{ka:e.ka},...!t&&e.__m&&{__m:{...e.__m}}}})),n},l=n.n.map(i);return t||p.append(" // IR 节点树\n"),p.append(` n: ${JSON.stringify(l,null,t?0:2)},\n\n`),t||p.append(" // 编译统计\n"),p.append(` s: ${JSON.stringify(n.s)},\n\n`),t||(p.append(" // 元数据\n"),p.append(` m: ${JSON.stringify(n.m)}\n`)),p.append("};\n\n"),t||p.append("// 导出 IR 对象\n"),p.append("export default __SOLELY_IR__;\n"),p.append("export { __SOLELY_IR__ };\n\n"),t||p.append("// 同时导出模板字符串(向后兼容)\n"),p.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:p.toString(),map:p.generateMap({source:r,includeContent:!t,hires:!t})}}(p,n,r,!!o.minify);return o.debug&&(console.info(`[Solely] Compiled IR for: ${r}`),console.info("[Solely] Stats:",p.s)),{code:i.code,map:o.sourceMap?i.map:null}}{const e=i(n,r,!!o.minify);return{code:e.code,map:o.sourceMap?e.map:null}}}catch(l){const e=`[Solely] Error processing ${r}: ${l instanceof Error?l.message:String(l)}`;console.error(e),console.warn(`[Solely] Falling back to raw template for: ${r}`);const t=i(n,r,!!o.minify);return{code:t.code,map:o.sourceMap?t.map:null}}},handleHotUpdate({file:e,server:n,modules:r}){if(p(e,o.include)&&!p(e,o.exclude))return o.debug&&console.info(`[Solely] HMR triggered for: ${e}`),n.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=l),exports.compileTemplate=t,exports.solelyVitePlugin=l;
@@ -1 +1 @@
1
- import n from"magic-string";import{parseHtml as e}from"../compiler/parser/parser.js";import{buildIR as o}from"../compiler/ir/buildIR.js";const r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function p(n,r="anonymous"){const p=e(n);return o(p,{filename:r,source:n})}function t(n,e){return(Array.isArray(e)?e:[e]).some(e=>"string"==typeof e?n.includes(e):e.test(n))}function i(e,o,r){const p=new n(e),t=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return p.overwrite(0,e.length,`\nconst __SOLELY_TEMPLATE__ = \`${t}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:p.toString(),map:p.generateMap({source:o,includeContent:!r})}}function l(e={}){const o={...r,...e};return{name:"solely-vite-plugin",enforce:"pre",configResolved(n){o.debug&&console.info("[Solely] Plugin initialized with options:",o)},transform(e,r){if(!t(r,o.include)||t(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug&&console.info(`[Solely] Processing: ${r}`),o.precompile){const t=p(e,r),i=function(e,o,r,p){const t=new n(o);t.remove(0,o.length),p||(t.append("\n// ============================================\n"),t.append("// Solely Precompiled Template\n"),t.append(`// Compiled at: ${(new Date).toISOString()}\n`),t.append("// ============================================\n\n")),t.append("const __SOLELY_IR__ = {\n"),t.append(" t: 'root',\n"),t.append(` v: '${e.v}',\n\n`),p||t.append(" // 编译后的函数数组\n"),t.append(" fns: [\n"),e.fns.forEach((n,o)=>{const r="string"==typeof n?n:n.toString(),i=o===e.fns.length-1;p||t.append(` // Function ${o+1}\n`),t.append(` ${r}${i?"":","}\n`)}),t.append(" ],\n\n");const i=n=>{const e={t:n.t,d:n.d};return void 0!==n.s&&(e.s=n.s),void 0!==n.g&&(e.g=n.g),void 0!==n.x&&(e.x=n.x),void 0!==n.f&&(e.f=n.f),void 0!==n.i&&(e.i=n.i),void 0!==n.n&&(e.n=n.n),!p&&n.__m&&(e.__m={...n.__m}),n.a&&(e.a=n.a.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r,...!p&&n.__m&&{__m:{...n.__m}}}))),n.c&&(e.c=n.c.map(i)),n.b&&(e.b=n.b.map(n=>{var e;return{f:n.f,c:n.c.map(i),a:null==(e=n.a)?void 0:e.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r})),...!p&&n.__m&&{__m:{...n.__m}}}})),e},l=e.n.map(i);return p||t.append(" // IR 节点树\n"),t.append(` n: ${JSON.stringify(l,null,p?0:2)},\n\n`),p||t.append(" // 编译统计\n"),t.append(` s: ${JSON.stringify(e.s)},\n\n`),p||(t.append(" // 元数据\n"),t.append(` m: ${JSON.stringify(e.m)}\n`)),t.append("};\n\n"),p||t.append("// 导出 IR 对象\n"),t.append("export default __SOLELY_IR__;\n"),t.append("export { __SOLELY_IR__ };\n\n"),p||t.append("// 同时导出模板字符串(向后兼容)\n"),t.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:t.toString(),map:t.generateMap({source:r,includeContent:!p,hires:!p})}}(t,e,r,!!o.minify);return o.debug&&(console.info(`[Solely] Compiled IR for: ${r}`),console.info("[Solely] Stats:",t.s)),{code:i.code,map:o.sourceMap?i.map:null}}{const n=i(e,r,!!o.minify);return{code:n.code,map:o.sourceMap?n.map:null}}}catch(l){const n=`[Solely] Error processing ${r}: ${l instanceof Error?l.message:String(l)}`;console.error(n),console.warn(`[Solely] Falling back to raw template for: ${r}`);const p=i(e,r,!!o.minify);return{code:p.code,map:o.sourceMap?p.map:null}}},handleHotUpdate({file:n,server:e,modules:r}){if(t(n,o.include)&&!t(n,o.exclude))return o.debug&&console.info(`[Solely] HMR triggered for: ${n}`),e.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=l);export{p as compileTemplate,l as solelyVitePlugin};
1
+ import n from"magic-string";import{parseHtml as e}from"../compiler/parser/parser.js";import{buildIR as o}from"../compiler/ir/buildIR.js";const r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function p(n,r="anonymous"){const p=e(n);return o(p,{filename:r,source:n})}function t(n,e){return(Array.isArray(e)?e:[e]).some(e=>"string"==typeof e?n.includes(e):e.test(n))}function i(e,o,r){const p=new n(e),t=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return p.overwrite(0,e.length,`\nconst __SOLELY_TEMPLATE__ = \`${t}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:p.toString(),map:p.generateMap({source:o,includeContent:!r})}}function a(e={}){const o={...r,...e};return{name:"solely-vite-plugin",enforce:"pre",configResolved(n){o.debug&&console.info("[Solely] Plugin initialized with options:",o)},transform(e,r){if(!t(r,o.include)||t(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug&&console.info(`[Solely] Processing: ${r}`),o.precompile){const t=p(e,r),i=function(e,o,r,p){const t=new n(o);t.remove(0,o.length),p||(t.append("\n// ============================================\n"),t.append("// Solely Precompiled Template\n"),t.append(`// Compiled at: ${(new Date).toISOString()}\n`),t.append("// ============================================\n\n")),t.append("const __SOLELY_IR__ = {\n"),t.append(" t: 'root',\n"),t.append(` v: '${e.v}',\n\n`),p||t.append(" // 编译后的函数数组\n"),t.append(" fns: [\n"),e.fns.forEach((n,o)=>{const r="string"==typeof n?n:n.toString(),i=o===e.fns.length-1;p||t.append(` // Function ${o+1}\n`),t.append(` ${r}${i?"":","}\n`)}),t.append(" ],\n\n");const i=n=>{const e={t:n.t,d:n.d};return void 0!==n.s&&(e.s=n.s),void 0!==n.g&&(e.g=n.g),void 0!==n.x&&(e.x=n.x),void 0!==n.f&&(e.f=n.f),void 0!==n.i&&(e.i=n.i),void 0!==n.n&&(e.n=n.n),!p&&n.__m&&(e.__m={...n.__m}),n.a&&(e.a=n.a.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r,...!p&&n.__m&&{__m:{...n.__m}}}))),n.c&&(e.c=n.c.map(i)),n.b&&(e.b=n.b.map(n=>{var e;return{f:n.f,c:n.c.map(i),a:null==(e=n.a)?void 0:e.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r})),...void 0!==n.ka&&{ka:n.ka},...!p&&n.__m&&{__m:{...n.__m}}}})),e},a=e.n.map(i);return p||t.append(" // IR 节点树\n"),t.append(` n: ${JSON.stringify(a,null,p?0:2)},\n\n`),p||t.append(" // 编译统计\n"),t.append(` s: ${JSON.stringify(e.s)},\n\n`),p||(t.append(" // 元数据\n"),t.append(` m: ${JSON.stringify(e.m)}\n`)),t.append("};\n\n"),p||t.append("// 导出 IR 对象\n"),t.append("export default __SOLELY_IR__;\n"),t.append("export { __SOLELY_IR__ };\n\n"),p||t.append("// 同时导出模板字符串(向后兼容)\n"),t.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:t.toString(),map:t.generateMap({source:r,includeContent:!p,hires:!p})}}(t,e,r,!!o.minify);return o.debug&&(console.info(`[Solely] Compiled IR for: ${r}`),console.info("[Solely] Stats:",t.s)),{code:i.code,map:o.sourceMap?i.map:null}}{const n=i(e,r,!!o.minify);return{code:n.code,map:o.sourceMap?n.map:null}}}catch(a){const n=`[Solely] Error processing ${r}: ${a instanceof Error?a.message:String(a)}`;console.error(n),console.warn(`[Solely] Falling back to raw template for: ${r}`);const p=i(e,r,!!o.minify);return{code:p.code,map:o.sourceMap?p.map:null}}},handleHotUpdate({file:n,server:e,modules:r}){if(t(n,o.include)&&!t(n,o.exclude))return o.debug&&console.info(`[Solely] HMR triggered for: ${n}`),e.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=a);export{p as compileTemplate,a as solelyVitePlugin};
@@ -1 +1 @@
1
- "use strict";var t,e,s,i,a,n,o,r,h,c,l,u,d,p,f,b,m,y,v,w,g,M,S,O,k,$,j=Object.defineProperty,C=t=>{throw TypeError(t)},W=(t,e,s)=>e.has(t)||C("Cannot "+s),A=(t,e,s)=>(W(t,e,"read from private field"),s?s.call(t):e.get(t)),E=(t,e,s)=>e.has(t)?C("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),N=(t,e,s,i)=>(W(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),D=(t,e,s)=>(W(t,e,"access private method"),s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("../../shared/is-object.cjs"),q=require("../../shared/env.cjs"),U=require("../../shared/case-convert.cjs"),I=require("../reactivity/observe.cjs"),_=require("../renderer/renderIR.cjs"),x=Symbol.for("solely.manifest"),L=class y extends HTMLElement{constructor(p={}){var b,y;super(),E(this,f),((t,e,s)=>{e in t?j(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(y="$refs")?y+"":y,{}),E(this,t),E(this,e),E(this,s),E(this,i),E(this,a),E(this,n),E(this,o,!1),E(this,r,!1),E(this,h,!1),E(this,c,!1),E(this,l,!1),E(this,u,!1),E(this,d,!1);const w=this.constructor;N(this,t,w[x]||{tagName:"base-element"});const g=A(this,t);N(this,a,(null==(b=g.shadowDOM)?void 0:b.use)?this.attachShadow({mode:g.shadowDOM.mode||"open"}):this),D(this,f,m).call(this,p),D(this,f,v).call(this,g),queueMicrotask(()=>D(this,f,$).call(this))}static get observedAttributes(){const t=this[x];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return A(this,i)}set $data(t){var e;P.isObject(t)||(t={}),t!==A(this,i)&&(null==(e=A(this,n))||e.call(this),D(this,f,m).call(this,t),D(this,f,g).call(this),D(this,f,S).call(this))}refresh(){D(this,f,S).call(this)}connectedCallback(){var i;N(this,l,!0);const n=A(this,t);if(D(this,f,$).call(this),(n.className||n.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),D(this,f,k).call(this),n.attributeMap&&P.isObject(this.$data)){D(this,f,g).call(this);for(const[t,e]of n.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=D(this,f,M).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}D(this,f,b).call(this),A(this,s)&&!A(this,e)&&N(this,e,_.createRender(A(this,s),A(this,a),this)),A(this,u)&&(N(this,u,!1),D(this,f,S).call(this)),this.mounted(),null==(i=this.onInit)||i.call(this)}disconnectedCallback(){var e,s;N(this,l,!1);const i=A(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${i.tagName}`,e=A(y,p).get(t)||0;e<=1?(null==(s=document.head.querySelector(`#${t}`))||s.remove(),A(y,p).delete(t)):A(y,p).set(t,e-1)}this.unmounted()}attributeChangedCallback(e,s,i){var a;if(s===i||!P.isObject(this.$data))return;const n=null==(a=A(this,t).attributeMap)?void 0:a.get(e);if(!n)return;const o=n.name,r=this.$data[o],c=D(this,f,M).call(this,i,n.default??r,n.type);this.$data[o]=c,N(this,h,!0),this.attributeChanged(e,r,c)}emit(t,e,s){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(q.IS_DEV&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(q.IS_DEV&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}onInit(){}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,n=new WeakMap,o=new WeakMap,r=new WeakMap,h=new WeakMap,c=new WeakMap,l=new WeakMap,u=new WeakMap,d=new WeakMap,p=new WeakMap,f=new WeakSet,b=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=new Set(["$data","$refs","constructor","onInit","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","refresh"]),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const n of t){if(s.has(n))continue;if(e.some(t=>n.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,n);if(!t||!("value"in t))continue;const a=t.value,o=i.get(n);(null==o?void 0:o.set)&&(delete this[n],this[n]=a)}},m=function(e){const{proxy:s,dispose:a}=I.observe(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,n=A(this,t),o=String(i),r=null==(s=n.propMap)?void 0:s.get(o);(null==r?void 0:r.reflect)&&D(this,f,y).call(this,r,a)}this.emit("dataChange",{...e}),D(this,f,S).call(this)});N(this,i,s),N(this,n,a)},y=function(t,e){const s=U.camelToKebab(t.name);if("boolean"===t.type)e?this.setAttribute(s,""):this.removeAttribute(s);else{const t="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,t)}},v=function(t){t.ir&&N(this,s,t.ir)},w=function(){const e=A(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;const e=Object.getOwnPropertyDescriptor(this.constructor.prototype,t.name);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},g=function(){A(this,d)||(N(this,d,!0),D(this,f,w).call(this))},M=function(t,e,s){if(null===t)return"boolean"!==s&&e;switch(s){case"boolean":return!0;case"number":{const s=Number(t);return isNaN(s)?e:s}case"object":try{return JSON.parse(t)}catch(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=t.replace(/'/g,'"'),i=JSON.parse(s);return Array.isArray(i)?i:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},S=function(){A(this,l)?!A(this,r)&&A(this,e)&&(N(this,r,!0),queueMicrotask(()=>{N(this,r,!1),D(this,f,O).call(this)})):N(this,u,!0)},O=function(){if(!A(this,o)&&A(this,l)){N(this,o,!0);try{A(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),A(this,e).update(),this.updated(),A(this,h)&&(this.afterAttributesUpdate(),N(this,h,!1))}finally{N(this,o,!1)}}},k=function(){var e;const s=A(this,t);if(!s.styles)return;const i=A(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return}const n=i instanceof ShadowRoot?i:document.head,o=`solely-style-${s.tagName}`,r=!(null==(e=s.shadowDOM)?void 0:e.use);if(!n.querySelector(`#${o}`)){const t=document.createElement("style");t.id=o,t.textContent=s.styles,n.appendChild(t)}if(r){const t=A(L,p).get(o)||0;A(L,p).set(o,t+1)}},$=function(){A(this,c)||(N(this,c,!0),this.created())},E(L,p,new Map),(()=>{if(q.IS_DEV&&"undefined"!=typeof customElements){const t=customElements.define,e=new WeakSet;customElements.define=function(s,i,a){if(L.isPrototypeOf(i)&&!e.has(i)){e.add(i);const t=i.prototype,a=["connectedCallback","disconnectedCallback","attributeChangedCallback"];for(const e of a)t[e]!==L.prototype[e]&&console.error(`[${s}] 禁止重写 ${e}(),请使用框架钩子`)}return t.call(this,s,i,a)}}})();let T=L;exports.default=T;
1
+ "use strict";var t,e,s,i,a,r,n,o,h,l,c,u,d,p,f,b,m,y,v,w,g,S,M,O,$,k,j,W,C,N,A,E=Object.defineProperty,P=t=>{throw TypeError(t)},L=(t,e,s)=>e.has(t)||P("Cannot "+s),D=(t,e,s)=>(L(t,e,"read from private field"),s?s.call(t):e.get(t)),q=(t,e,s)=>e.has(t)?P("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),U=(t,e,s,i)=>(L(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),_=(t,e,s)=>(L(t,e,"access private method"),s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=require("../../shared/is-object.cjs"),T=require("../../shared/env.cjs"),x=require("../../shared/case-convert.cjs"),I=require("../reactivity/observe.cjs"),V=require("../renderer/renderIR.cjs"),H=Symbol.for("solely.manifest"),J=class extends HTMLElement{constructor(m={}){var y,w;super(),q(this,v),((t,e,s)=>{e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(w="$refs")?w+"":w,{}),q(this,t),q(this,e),q(this,s),q(this,i),q(this,a),q(this,r),q(this,n,!1),q(this,o,!1),q(this,h,!1),q(this,l,!1),q(this,c,!1),q(this,u,!1),q(this,d,!1),q(this,p,new Set),q(this,f,!1),q(this,b,!1);const S=this.constructor;U(this,t,S[H]||{tagName:"base-element"});const O=D(this,t);U(this,a,(null==(y=O.shadowDOM)?void 0:y.use)?this.attachShadow({mode:O.shadowDOM.mode||"open"}):this),_(this,v,g).call(this,m),_(this,v,M).call(this,O),queueMicrotask(()=>_(this,v,A).call(this))}static get observedAttributes(){const t=this[H];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return D(this,i)}set $data(t){var e;R.isObject(t)||(t={}),t!==D(this,i)&&(null==(e=D(this,r))||e.call(this),_(this,v,g).call(this,t),_(this,v,$).call(this),_(this,v,j).call(this))}refresh(){_(this,v,j).call(this)}connectedCallback(){if(D(this,f))throw new Error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`);U(this,c,!0);const i=D(this,t);if(_(this,v,A).call(this),(i.className||i.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),_(this,v,C).call(this),i.attributeMap&&R.isObject(this.$data)){_(this,v,$).call(this);for(const[t,e]of i.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=_(this,v,k).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}_(this,v,w).call(this),D(this,s)&&!D(this,e)&&U(this,e,V.createRender(D(this,s),D(this,a),this)),D(this,u)&&(U(this,u,!1),_(this,v,j).call(this)),this.mounted()}disconnectedCallback(){U(this,c,!1),D(this,f)||_(this,v,N).call(this),this.unmounted()}attributeChangedCallback(e,s,i){var a;if(D(this,f)||s===i||!R.isObject(this.$data))return;if(D(this,p).has(e))return;const r=null==(a=D(this,t).attributeMap)?void 0:a.get(e);if(!r)return;const n=r.name,o=this.$data[n],l=_(this,v,k).call(this,i,r.default??o,r.type);o!==l&&(U(this,h,!0),this.$data[n]=l,this.attributeChanged(e,o,l))}emit(t,e,s){D(this,f)||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){D(this,f)||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(T.IS_DEV&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(T.IS_DEV&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}dispose(){var t,s;D(this,f)||(U(this,f,!0),U(this,c,!1),_(this,v,N).call(this),null==(t=D(this,e))||t.destroy(),U(this,e,void 0),null==(s=D(this,r))||s.call(this),U(this,r,void 0))}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,r=new WeakMap,n=new WeakMap,o=new WeakMap,h=new WeakMap,l=new WeakMap,c=new WeakMap,u=new WeakMap,d=new WeakMap,p=new WeakMap,f=new WeakMap,b=new WeakMap,m=new WeakMap,y=new WeakMap,v=new WeakSet,w=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=D(J,y),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const r of t){if(s.has(r))continue;if(e.some(t=>r.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,r);if(!t||!("value"in t))continue;const a=t.value,n=i.get(r);(null==n?void 0:n.set)&&(delete this[r],this[r]=a)}},g=function(e){const{proxy:s,dispose:a}=I.observe(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,r=D(this,t),n=String(i),o=null==(s=r.propMap)?void 0:s.get(n);(null==o?void 0:o.reflect)&&_(this,v,S).call(this,o,a)}this.emit("dataChange",{...e}),_(this,v,j).call(this)});U(this,i,s),U(this,r,a)},S=function(t,e){const s=x.camelToKebab(t.name);D(this,p).add(s);try{if(null==e)return void this.removeAttribute(s);if("boolean"===t.type)e?this.setAttribute(s,""):this.removeAttribute(s);else{const t="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,t)}}finally{D(this,p).delete(s)}},M=function(t){t.ir&&U(this,s,t.ir)},O=function(){const e=D(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;let e,s=Object.getPrototypeOf(this);for(;s&&s!==HTMLElement.prototype&&(e=Object.getOwnPropertyDescriptor(s,t.name),!e);)s=Object.getPrototypeOf(s);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},$=function(){D(this,d)||(U(this,d,!0),_(this,v,O).call(this))},k=function(t,e,s){if(null===t)return"boolean"!==s&&e;switch(s){case"boolean":return!0;case"number":{const s=Number(t);return isNaN(s)?e:s}case"object":try{return JSON.parse(t)}catch(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=JSON.parse(t);return Array.isArray(s)?s:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},j=function(){D(this,f)||(D(this,c)?!D(this,o)&&D(this,e)&&(U(this,o,!0),queueMicrotask(()=>{D(this,f)||(U(this,o,!1),_(this,v,W).call(this))})):U(this,u,!0))},W=function(){var t;if(!D(this,f)&&!D(this,n)&&D(this,c)){U(this,n,!0);try{D(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),null==(t=D(this,e))||t.update(),this.updated(),D(this,h)&&(this.afterAttributesUpdate(),U(this,h,!1))}finally{U(this,n,!1)}}},C=function(){var e;const s=D(this,t);if(!s.styles)return;const i=D(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return void U(this,b,!0)}const r=i instanceof ShadowRoot?i:document.head,n=`solely-style-${T.SOLELY_VERSION}-${s.tagName}`,o=!(null==(e=s.shadowDOM)?void 0:e.use),h="undefined"!=typeof CSS&&CSS.escape?CSS.escape(n):n.replace(/([.#:[\]()!])/g,"\\$1");if(!r.querySelector(`#${h}`)){const t=document.createElement("style");t.id=n,t.textContent=s.styles,r.appendChild(t)}if(o){const t=D(J,m).get(n)||0;D(J,m).set(n,t+1),U(this,b,!0)}},N=function(){var e,s;if(!D(this,b))return;U(this,b,!1);const i=D(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${T.SOLELY_VERSION}-${i.tagName}`,e=D(J,m).get(t)||0;if(e<=1){const e=CSS.escape(t);null==(s=document.head.querySelector(`#${e}`))||s.remove(),D(J,m).delete(t)}else D(J,m).set(t,e-1)}},A=function(){D(this,l)||(U(this,l,!0),this.created())},q(J,m,new Map),q(J,y,new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]));let F=J;exports.default=F;
@@ -31,7 +31,12 @@ declare class BaseElement<TData extends object = Record<string, unknown>, TRefs
31
31
  * @param message - 错误信息
32
32
  */
33
33
  protected error(condition: boolean, message: string): void;
34
- onInit(): void | Promise<void>;
34
+ /**
35
+ * 显式销毁组件,清理 renderer 等资源。
36
+ * 适用于确认组件不再 reconnect 的场景。
37
+ * 调用后如需重新使用组件,需重新创建实例。
38
+ */
39
+ dispose(): void;
35
40
  created(): void;
36
41
  mounted(): void;
37
42
  beforeUpdate(): void;