solely 0.5.8 → 0.7.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 (160) hide show
  1. package/README.md +82 -31
  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/components/commands/drawer/index.cjs +1 -1
  7. package/dist/components/commands/drawer/index.js +1 -1
  8. package/dist/components/commands/drawer/style.css.cjs +1 -1
  9. package/dist/components/commands/drawer/style.css.js +1 -1
  10. package/dist/components/commands/message/index.cjs +1 -1
  11. package/dist/components/commands/message/index.js +1 -1
  12. package/dist/components/commands/modal/index.cjs +1 -1
  13. package/dist/components/commands/modal/index.js +1 -1
  14. package/dist/components/commands/modal/style.css.cjs +1 -1
  15. package/dist/components/commands/modal/style.css.js +1 -1
  16. package/dist/components/commands/popconfirm/index.cjs +1 -1
  17. package/dist/components/commands/popconfirm/index.js +1 -1
  18. package/dist/components/commands/tooltip/index.cjs +1 -1
  19. package/dist/components/commands/tooltip/index.js +1 -1
  20. package/dist/components/commands/utils.cjs +1 -1
  21. package/dist/components/commands/utils.js +1 -1
  22. package/dist/components/elements/alert/index.cjs +1 -1
  23. package/dist/components/elements/alert/index.html.cjs +1 -1
  24. package/dist/components/elements/alert/index.html.js +1 -1
  25. package/dist/components/elements/alert/index.js +1 -1
  26. package/dist/components/elements/backtop/index.cjs +1 -1
  27. package/dist/components/elements/backtop/index.html.cjs +1 -1
  28. package/dist/components/elements/backtop/index.html.js +1 -1
  29. package/dist/components/elements/backtop/index.js +1 -1
  30. package/dist/components/elements/badge/index.html.cjs +1 -1
  31. package/dist/components/elements/badge/index.html.js +1 -1
  32. package/dist/components/elements/breadcrumb/index.cjs +1 -1
  33. package/dist/components/elements/breadcrumb/index.html.cjs +1 -1
  34. package/dist/components/elements/breadcrumb/index.html.js +1 -1
  35. package/dist/components/elements/breadcrumb/index.js +1 -1
  36. package/dist/components/elements/button/index.cjs +1 -1
  37. package/dist/components/elements/button/index.html.cjs +1 -1
  38. package/dist/components/elements/button/index.html.js +1 -1
  39. package/dist/components/elements/button/index.js +1 -1
  40. package/dist/components/elements/card/index.html.cjs +1 -1
  41. package/dist/components/elements/card/index.html.js +1 -1
  42. package/dist/components/elements/checkbox/index.cjs +1 -1
  43. package/dist/components/elements/checkbox/index.html.cjs +1 -1
  44. package/dist/components/elements/checkbox/index.html.js +1 -1
  45. package/dist/components/elements/checkbox/index.js +1 -1
  46. package/dist/components/elements/coordinate-input/index.html.cjs +1 -1
  47. package/dist/components/elements/coordinate-input/index.html.js +1 -1
  48. package/dist/components/elements/coordinate-input/style.css.cjs +1 -1
  49. package/dist/components/elements/coordinate-input/style.css.js +1 -1
  50. package/dist/components/elements/fab/index.cjs +1 -1
  51. package/dist/components/elements/fab/index.html.cjs +1 -1
  52. package/dist/components/elements/fab/index.html.js +1 -1
  53. package/dist/components/elements/fab/index.js +1 -1
  54. package/dist/components/elements/icon/index.cjs +1 -1
  55. package/dist/components/elements/icon/index.d.ts +8 -0
  56. package/dist/components/elements/icon/index.html.cjs +1 -1
  57. package/dist/components/elements/icon/index.html.js +1 -1
  58. package/dist/components/elements/icon/index.js +1 -1
  59. package/dist/components/elements/input/index.cjs +1 -1
  60. package/dist/components/elements/input/index.html.cjs +1 -1
  61. package/dist/components/elements/input/index.html.js +1 -1
  62. package/dist/components/elements/input/index.js +1 -1
  63. package/dist/components/elements/not-found/index.html.cjs +1 -1
  64. package/dist/components/elements/not-found/index.html.js +1 -1
  65. package/dist/components/elements/not-found/style.css.cjs +1 -1
  66. package/dist/components/elements/not-found/style.css.js +1 -1
  67. package/dist/components/elements/pagination/index.html.cjs +1 -1
  68. package/dist/components/elements/pagination/index.html.js +1 -1
  69. package/dist/components/elements/pagination/style.css.cjs +1 -1
  70. package/dist/components/elements/pagination/style.css.js +1 -1
  71. package/dist/components/elements/progress/index.html.cjs +1 -1
  72. package/dist/components/elements/progress/index.html.js +1 -1
  73. package/dist/components/elements/radio/index.cjs +1 -1
  74. package/dist/components/elements/radio/index.html.cjs +1 -1
  75. package/dist/components/elements/radio/index.html.js +1 -1
  76. package/dist/components/elements/radio/index.js +1 -1
  77. package/dist/components/elements/rate/index.cjs +1 -1
  78. package/dist/components/elements/rate/index.html.cjs +1 -1
  79. package/dist/components/elements/rate/index.html.js +1 -1
  80. package/dist/components/elements/rate/index.js +1 -1
  81. package/dist/components/elements/select/index.cjs +1 -1
  82. package/dist/components/elements/select/index.html.cjs +1 -1
  83. package/dist/components/elements/select/index.html.js +1 -1
  84. package/dist/components/elements/select/index.js +1 -1
  85. package/dist/components/elements/skeleton/index.html.cjs +1 -1
  86. package/dist/components/elements/skeleton/index.html.js +1 -1
  87. package/dist/components/elements/slider/index.cjs +1 -1
  88. package/dist/components/elements/slider/index.html.cjs +1 -1
  89. package/dist/components/elements/slider/index.html.js +1 -1
  90. package/dist/components/elements/slider/index.js +1 -1
  91. package/dist/components/elements/steps/index.cjs +1 -1
  92. package/dist/components/elements/steps/index.html.cjs +1 -1
  93. package/dist/components/elements/steps/index.html.js +1 -1
  94. package/dist/components/elements/steps/index.js +1 -1
  95. package/dist/components/elements/switch/index.cjs +1 -1
  96. package/dist/components/elements/switch/index.html.cjs +1 -1
  97. package/dist/components/elements/switch/index.html.js +1 -1
  98. package/dist/components/elements/switch/index.js +1 -1
  99. package/dist/components/elements/table/index.html.cjs +1 -1
  100. package/dist/components/elements/table/index.html.js +1 -1
  101. package/dist/components/elements/tabs/index.html.cjs +1 -1
  102. package/dist/components/elements/tabs/index.html.js +1 -1
  103. package/dist/components/elements/tag/index.html.cjs +1 -1
  104. package/dist/components/elements/tag/index.html.js +1 -1
  105. package/dist/components/elements/timeline/index.cjs +1 -1
  106. package/dist/components/elements/timeline/index.html.cjs +1 -1
  107. package/dist/components/elements/timeline/index.html.js +1 -1
  108. package/dist/components/elements/timeline/index.js +1 -1
  109. package/dist/components/elements/tooltip/index.cjs +1 -1
  110. package/dist/components/elements/tooltip/index.html.cjs +1 -1
  111. package/dist/components/elements/tooltip/index.html.js +1 -1
  112. package/dist/components/elements/tooltip/index.js +1 -1
  113. package/dist/components/elements/tree/index.cjs +1 -1
  114. package/dist/components/elements/tree/index.d.ts +5 -0
  115. package/dist/components/elements/tree/index.html.cjs +1 -1
  116. package/dist/components/elements/tree/index.html.js +1 -1
  117. package/dist/components/elements/tree/index.js +1 -1
  118. package/dist/components/elements/upload/index.cjs +1 -1
  119. package/dist/components/elements/upload/index.html.cjs +1 -1
  120. package/dist/components/elements/upload/index.html.js +1 -1
  121. package/dist/components/elements/upload/index.js +1 -1
  122. package/dist/index.cjs +1 -1
  123. package/dist/index.js +1 -1
  124. package/dist/plugins/solely-vite-plugin.cjs +1 -1
  125. package/dist/plugins/solely-vite-plugin.d.ts +10 -1
  126. package/dist/plugins/solely-vite-plugin.js +1 -1
  127. package/dist/router/core.cjs +1 -1
  128. package/dist/router/core.js +1 -1
  129. package/dist/router/router-link.cjs +1 -1
  130. package/dist/router/router-link.js +1 -1
  131. package/dist/router/router-view.cjs +1 -1
  132. package/dist/router/router-view.js +1 -1
  133. package/dist/runtime/component/base-element.cjs +1 -1
  134. package/dist/runtime/component/base-element.d.ts +8 -1
  135. package/dist/runtime/component/base-element.js +1 -1
  136. package/dist/runtime/component/decorators.cjs +1 -1
  137. package/dist/runtime/component/decorators.d.ts +7 -0
  138. package/dist/runtime/component/decorators.js +1 -1
  139. package/dist/runtime/reactivity/observe.cjs +1 -1
  140. package/dist/runtime/reactivity/observe.d.ts +1 -0
  141. package/dist/runtime/reactivity/observe.js +1 -1
  142. package/dist/runtime/renderer/html-decode.cjs +1 -1
  143. package/dist/runtime/renderer/html-decode.js +1 -1
  144. package/dist/runtime/renderer/renderIR.cjs +1 -1
  145. package/dist/runtime/renderer/renderIR.js +1 -1
  146. package/dist/shared/env.cjs +1 -1
  147. package/dist/shared/env.js +1 -1
  148. package/dist/shared/functions.d.ts +2 -2
  149. package/dist/shared/gen-function.cjs +1 -1
  150. package/dist/shared/gen-function.js +1 -1
  151. package/dist/shared/index.cjs +1 -1
  152. package/dist/shared/index.d.ts +1 -0
  153. package/dist/shared/index.js +1 -1
  154. package/dist/shared/svg-sanitize.cjs +1 -0
  155. package/dist/shared/svg-sanitize.d.ts +27 -0
  156. package/dist/shared/svg-sanitize.js +1 -0
  157. package/dist/shared/templateError.cjs +1 -1
  158. package/dist/shared/templateError.js +1 -1
  159. package/dist/types/ir.d.ts +2 -2
  160. package/package.json +19 -14
package/README.md CHANGED
@@ -10,26 +10,27 @@
10
10
  [![codecov](https://codecov.io/gh/solelyjs/solely/branch/main/graph/badge.svg)](https://codecov.io/gh/solelyjs/solely)
11
11
  [![VS Code Extension](https://img.shields.io/badge/VS%20Code-Solely-blue?logo=visualstudiocode)](https://marketplace.visualstudio.com/items?itemName=solely.solely-vscode)
12
12
  [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
13
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue.svg)](https://www.typescriptlang.org/)
13
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
14
14
 
15
15
  </div>
16
16
 
17
17
  ## ✨ 核心特性
18
18
 
19
- - **🚀 高性能**:轻量级架构,零运行时依赖,快速渲染
19
+ - **🚀 高性能**:轻量级架构,浏览器运行时零依赖(`magic-string` 仅构建期使用),快速渲染
20
20
  - **🔧 类型安全**:完整的 TypeScript 支持,类型提示完善
21
21
  - **🎨 强大模板**:基于 AST 的模板编译,支持条件渲染和列表渲染
22
- - **⚡ 响应式系统**:高效的响应式数据绑定,自动追踪依赖
22
+ - **⚡ 响应式系统**:高效的响应式数据绑定,变更按微任务批量刷新
23
23
  - **🧩 Web 组件**:原生 Web 组件支持,可自定义元素
24
- - **🛡️ 安全可靠**:编译时模板固定,自动 HTML 转义,内置 XSS 防护机制
24
+ - **🛡️ 安全可靠**:编译时模板固定,文本节点自动转义,SVG 图标注入前消毒
25
25
  - **📦 插件系统**:灵活的插件扩展机制
26
- - **🧪 测试完善**:完整的单元测试覆盖
26
+ - **🧪 测试覆盖**:440+ 个单元测试,核心模块覆盖率门禁 80%+
27
27
  - **🗺️ 路由支持**:内置路由系统,支持单页应用开发
28
28
 
29
29
  ## 📚 文档
30
30
 
31
31
  - [快速开始指南](./docs/guide.md) - 从零开始学习 Solely
32
32
  - [API 文档](./docs/api.md) - 完整的 API 参考
33
+ - [验证与发布检查清单](./docs/verification.md) - 改动后如何验证、发版前检查项
33
34
  - [示例项目](./examples/) - 实际应用示例
34
35
  - [VS Code 扩展](./vscode-extension/) - 语法高亮、智能跳转、错误诊断
35
36
  - [插件系统](#插件系统) - 了解 Vite 插件的使用方法
@@ -119,6 +120,10 @@ class MyCounter extends BaseElement<{ count: number }> {
119
120
  }
120
121
  ```
121
122
 
123
+ > **提示**:`super(initialData)` 传入的对象会成为该实例的 `$data` 响应式代理。若多个实例传入**同一个对象**,
124
+ > 它们会共享同一份状态(修改一个会同时触发另一个刷新)。需要实例隔离时,请为每个实例传入新对象;
125
+ > 开发模式下框架会对此输出告警。
126
+
122
127
  ### 2. 在 HTML 中使用
123
128
 
124
129
  ```html
@@ -376,8 +381,9 @@ solely/
376
381
  ├── runtime/ # 运行时核心
377
382
  │ ├── component/ # 组件基类和装饰器
378
383
  │ ├── reactivity/ # 响应式系统
379
- │ ├── renderer/ # 渲染器
380
- │ └── router/ # 路由系统
384
+ │ └── renderer/ # 渲染器
385
+ ├── router/ # 路由系统
386
+ ├── components/ # 组件库(元素组件 / 命令式组件 / 主题)
381
387
  ├── shared/ # 共享工具函数
382
388
  ├── types/ # TypeScript 类型定义
383
389
  ├── plugins/ # 插件系统
@@ -389,7 +395,7 @@ solely/
389
395
  1. **编译器**:将模板转换为高效的渲染函数,支持 AST 解析和中间表示优化
390
396
  2. **运行时**:包含组件系统、响应式系统、渲染器和路由系统
391
397
  3. **响应式系统**:基于 Proxy 的响应式数据绑定,采用 DAG 弱引用双向图和全局代理生成器自动追踪依赖,支持路径过滤、批量防抖与深度比较
392
- 4. **路由系统**:支持单页应用的路由管理,包括路由定义、导航和组件挂载
398
+ 4. **路由系统**:顶层独立模块,支持单页应用的路由管理,包括路由定义、嵌套路由、路由守卫和 keepAlive 缓存
393
399
  5. **插件系统**:提供扩展机制,支持自定义功能
394
400
 
395
401
  ## 🔌 插件系统
@@ -515,19 +521,35 @@ Solely 框架内置了多层安全防护机制,有效防止常见的 XSS(跨
515
521
 
516
522
  ### 编译时安全
517
523
 
518
- - **模板编译时固定**:所有模板在构建阶段编译为中间表示(IR),运行时无法更改模板结构
519
- - **无运行时解析**:不存在 `eval` 或动态模板解析,杜绝代码注入
524
+ - **模板编译时固定**:模板在构建阶段编译为中间表示(IR),运行时无法更改模板结构
525
+ - **预编译模式无 `eval`**:使用 `?solely` 预编译时,表达式在构建期编译为普通函数,运行时不需要 `new Function`
526
+ - **运行时编译模式**:直接传入模板字符串时会使用 `new Function` 编译表达式,受 CSP 约束(需要 `'unsafe-eval'` 或改用预编译)
520
527
 
521
- ### 自动 HTML 转义
528
+ ### 自动转义
522
529
 
523
- - **文本插值自动转义**:使用 `{{ }}` 插值时,框架自动进行 HTML 实体编码
530
+ - **文本插值安全**:`{{ }}` 的结果通过 `textContent` 写入,不会被浏览器解析为 HTML
524
531
 
525
532
  ```html
526
533
  <!-- 用户输入: <script>alert('XSS')</script> -->
527
534
  <div>{{ $data.userInput }}</div>
528
- <!-- 渲染结果: &lt;script&gt;alert('XSS')&lt;/script&gt; -->
535
+ <!-- 渲染结果: 原样显示 <script>alert('XSS')</script> 文本,不执行 -->
529
536
  ```
530
537
 
538
+ ### URL 协议防护
539
+
540
+ - `:href` / `:src` / `:srcset` / `:action` / `:formaction` / `:poster` / `:xlink:href` 绑定会自动拦截
541
+ `javascript:`、`vbscript:`、`data:text/html` 协议(含 `java\tscript:` 等混淆写法),开发模式下会打印告警
542
+ - `:srcdoc` 绑定默认拦截(iframe 内嵌 HTML 无法用协议白名单判断)
543
+ - 这只是兜底,仍建议业务层按白名单校验 URL
544
+
545
+ ### SVG 消毒
546
+
547
+ `registerIcon` / `loadIconSprite` 注入的 SVG 会经过白名单消毒:
548
+
549
+ - 仅保留合法 SVG 元素,移除 `script`、`foreignObject` 及未知命名空间
550
+ - 移除 `on*` 事件属性,以及 SMIL 动画通过 `attributeName` 写入事件/危险 URL 的载荷
551
+ - `<style>` 保留(iconfont 依赖),但会移除包含 `@import`、`expression()`、`behavior:`、`-moz-binding` 的样式块
552
+
531
553
  ### 安全最佳实践
532
554
 
533
555
  | ✅ 推荐做法 | ❌ 避免做法 |
@@ -551,9 +573,8 @@ Solely 框架内置了多层安全防护机制,有效防止常见的 XSS(跨
551
573
 
552
574
  ⚠️ **`:href` 属性绑定(高危)**:
553
575
 
554
- - **永远不要**将用户输入直接绑定到 `:href`
555
- - 恶意 URL 如 `javascript:alert('XSS')` 会在点击时执行代码
556
- - 建议对 URL 进行协议白名单过滤(只允许 `http://`, `https://`)
576
+ - 框架会默认拦截 `javascript:`、`vbscript:`、`data:text/html`(含混淆写法),但**不要**依赖它做业务校验
577
+ - 仍建议对 URL 进行协议白名单过滤(只允许 `http://`, `https://`)
557
578
  - 示例:
558
579
 
559
580
  ```typescript
@@ -586,7 +607,7 @@ Solely 框架内置了多层安全防护机制,有效防止常见的 XSS(跨
586
607
 
587
608
  查看 [安全演示示例](./examples/security-demo/) 了解框架如何防护 XSS 攻击。
588
609
 
589
- ## � API 参考
610
+ ## 📖 API 参考
590
611
 
591
612
  ### CustomElement 装饰器
592
613
 
@@ -595,10 +616,11 @@ Solely 框架内置了多层安全防护机制,有效防止常见的 XSS(跨
595
616
  ```typescript
596
617
  @CustomElement({
597
618
  tagName: 'my-component', // 必须:组件标签名
598
- template: '...', // 必须:HTML 模板字符串
619
+ template: '...', // 必须:HTML 模板字符串或预编译 IR
599
620
  props: [...], // 可选:属性定义,设置后会自动同步到 $data 中,外部修改会触发响应式
600
621
  styles: '...', // 可选:组件样式
601
- shadowDOM: { use: true } // 可选:使用 Shadow DOM
622
+ shadowDOM: { use: true }, // 可选:使用 Shadow DOM
623
+ dataChangeEvent: false // 可选:关闭每次数据变更时的 dataChange 事件派发(默认开启)
602
624
  })
603
625
  ```
604
626
 
@@ -655,7 +677,7 @@ class MyComponent extends BaseElement<MyData> {
655
677
  interface PropDescriptor {
656
678
  name: string; // 属性名(camelCase)
657
679
  type?: 'string' | 'number' | 'boolean' | 'object' | 'array'; // 类型转换
658
- default?: unknown; // 默认值
680
+ default?: unknown; // 默认值(object/array 会按实例克隆)
659
681
  reflect?: boolean; // 是否同步回 HTML attribute
660
682
  reactive?: boolean; // 是否响应式同步到 $data(默认 true)
661
683
  }
@@ -743,11 +765,13 @@ document.body.appendChild(element);
743
765
 
744
766
  **自动升级规则**:
745
767
 
746
- | 属性类型 | 升级行为 | 说明 |
747
- | ----------------------------- | -------------- | ------------------------------------ |
748
- | 声明在 `props` 中的属性 | 同步到 `$data` | 通过框架生成的 setter 自动同步 |
749
- | 有自定义 getter/setter 的属性 | 触发 setter | 用户自定义逻辑执行,同时同步 `$data` |
750
- | 普通数据属性 | 保持原样 | 不干预,作为普通实例属性 |
768
+ | 属性类型 | 升级行为 | 说明 |
769
+ | ----------------------------- | -------------- | --------------------------------------------------------- |
770
+ | 声明在 `props` 中的属性 | 同步到 `$data` | 通过框架生成的 setter 自动同步 |
771
+ | 有自定义 getter/setter 的属性 | 触发 setter | 用户自定义逻辑执行(是否写入 `$data` 由 setter 自身决定) |
772
+ | 普通数据属性 | 保持原样 | 不干预,作为普通实例属性 |
773
+
774
+ > 框架只调用自定义 setter,不会在调用后补写 `$data`;若 setter 未写入 `$data`,依赖该值的模板不会更新。
751
775
 
752
776
  #### 生命周期钩子
753
777
 
@@ -1245,18 +1269,19 @@ Solely 支持两种路由模式:
1245
1269
  | `hash` | 基于 URL hash | `#/users/123` | 兼容旧浏览器,无需服务器配置 |
1246
1270
  | `history` | 基于 HTML5 History API | `/users/123` | 更美观的 URL,需要服务器支持 |
1247
1271
 
1272
+ > 未指定 `mode` 时默认使用 `history`。
1273
+
1248
1274
  ```typescript
1249
- // Hash 模式(默认)
1275
+ // History 模式(默认)
1250
1276
  const router = createRouter({
1251
1277
  routes,
1252
- mode: 'hash',
1278
+ base: '/app', // 应用基础路径(可选)
1253
1279
  });
1254
1280
 
1255
- // History 模式
1281
+ // Hash 模式
1256
1282
  const router = createRouter({
1257
1283
  routes,
1258
- mode: 'history',
1259
- base: '/app', // 应用基础路径
1284
+ mode: 'hash',
1260
1285
  });
1261
1286
  ```
1262
1287
 
@@ -1274,6 +1299,17 @@ const unsubscribe = router.listen(() => {
1274
1299
  unsubscribe();
1275
1300
  ```
1276
1301
 
1302
+ #### 等待路由就绪
1303
+
1304
+ 组件可能先于 `createRouter()` 挂载,此时可以等待 `routerReady`:
1305
+
1306
+ ```typescript
1307
+ const router = await routerReady;
1308
+ ```
1309
+
1310
+ `routerReady` 的语义是「等待一个可用的 router 实例」:调用 `router.destroy()` 后它会保持 pending,
1311
+ 直到下一次 `createRouter()` 完成;若不再创建新实例,则不会 resolve(属预期行为,不会抛错)。
1312
+
1277
1313
  #### 路由组件
1278
1314
 
1279
1315
  Solely 提供了两个内置的路由组件:
@@ -1400,7 +1436,9 @@ npm run test:ui
1400
1436
  npm run test:coverage
1401
1437
  ```
1402
1438
 
1403
- > 当前测试套件包含 270+ 个单元测试,覆盖编译器、运行时、响应式系统、路由系统和组件接口等模块。
1439
+ > 当前测试套件包含 440+ 个单元测试,覆盖编译器、运行时、响应式系统、路由系统和组件接口等模块。
1440
+ > 覆盖率门禁(statements 80 / branches 75 / functions 85 / lines 80)针对编译器、运行时、响应式与路由核心模块;
1441
+ > `src/components/**` 暂不计入统计,组件测试仍在补齐中。
1404
1442
 
1405
1443
  ## 🔧 构建和开发
1406
1444
 
@@ -1418,6 +1456,19 @@ npm run link
1418
1456
  npm run pack:local
1419
1457
  ```
1420
1458
 
1459
+ ### 开发/生产环境判定
1460
+
1461
+ `IS_DEV` 依次按以下规则判定:
1462
+
1463
+ 1. `globalThis.__IS_PROD__ === true` → 生产(**最高优先级**,用于生产构建部署在 localhost / 内网 / Electron 的场景)
1464
+ 2. `?debug`、`globalThis.__DEBUG__`、`globalThis.__IS_DEV__` → 开发
1465
+ 3. `globalThis.process.env.NODE_ENV` → `production` / `development`
1466
+ 4. 主机名为 `localhost` / `127.0.0.1` / `0.0.0.0` → 开发
1467
+ 5. 其余 → 生产
1468
+
1469
+ > 若你的生产环境跑在 localhost(如桌面端、内网部署),在入口脚本最前面加一行
1470
+ > `globalThis.__IS_PROD__ = true` 即可关闭开发模式下的告警与错误面板。
1471
+
1421
1472
  ## 🤝 贡献指南
1422
1473
 
1423
1474
  欢迎贡献代码!请遵循以下步骤:
@@ -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 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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../shared/gen-function.cjs"),t=require("../../shared/env.cjs"),n=require("../../types/ast.cjs"),c=require("../../types/lifecycle.cjs"),o=/\{\{[\s\S]*?\}\}/,s={"solely-checkbox":{prop:"checked",event:"change"},"solely-switch":{prop:"checked",event:"change"},"solely-radio":{prop:"checked",event:"change"}},i=new class{compilers=new Map;get(e="anonymous"){let t=this.compilers.get(e);return t||(t=new r,this.compilers.set(e,t)),t}clear(e){if(e)this.compilers.get(e)?.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class r{cache=new Map;functions=[];makeCacheKey(e,t,n){return 0===n.length?`${e}:${t}`:`${e}:${t}:${n.map(e=>`${e.i}:${e.x}`).join(";")}`}compile(n,c,o){const s="template"===n?c??"":c?.trim()??"";if(!s.trim())return 0;const i=this.makeCacheKey(n,s,o),r=this.cache.get(i);if(void 0!==r)return r;let l;try{l=e.genFunction(s,n,o)}catch(p){t.IS_DEV&&console.error(`[Solely] IR Compile Error - Type: ${n}, Expr: "${s}"`,p),l=()=>""}const a=this.functions.push(l);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 l(e){const t=e[0];return":"===t?{isDynamic:!0,type:"expression"}:"@"===t?{isDynamic:!0,type:"handler"}:c.isLifecycleKind(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function a(e,t,n){e.__m={expr:t??"",loc:n??void 0}}function p(e){if(!e.attrs)return;const t=e.attrs.find(e=>"s-model"===e.key);if(!t)return;const n=t.value.trim(),c=n.startsWith("$data.")?n:`$data.${n.replace(/^this\./,"")}`,o=t.loc,i=(e.tag||"").toLowerCase(),r=e.attrs.find(e=>"type"===e.key),l=r?.value??"text";e.attrs=e.attrs.filter(e=>e!==t);const a=(t,n,c)=>{e.attrs?.push({key:t,value:n,role:c,loc:o})};if("input"===i){if("checkbox"===l){const t=e.attrs.find(e=>"value"===e.key),n=t?JSON.stringify(t.value):'"on"';return a(":checked",`Array.isArray(${c}) ? ${c}.includes(${n}) : ${c}`),void a("@change",`\n const _v = ${n};\n if(Array.isArray(${c})) {\n const _i = ${c}.indexOf(_v);\n if(checked && _i === -1) ${c}.push(_v);\n else if(!checked && _i > -1) ${c}.splice(_i,1);\n } else {\n ${c} = checked;\n }`,"model")}if("radio"===l){const t=e.attrs.find(e=>"value"===e.key),n=t?.value??"null";return a(":checked",`${c} == ${JSON.stringify(n)}`),void a("@change",`if (checked) ${c} = ${JSON.stringify(n)}`,"model")}return a(":value",c),void a("@input",`${c} = value`,"model")}if("textarea"===i)return a(":value",c),void a("@input",`${c} = value`,"model");if("select"===i){if(e.attrs.some(e=>"multiple"===e.key)){const e=`\n const values = Array.isArray(${c}) ? ${c} : ${c} != null ? [${c}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`;a("mounted",e),a("updated",e),a("@change",`${c} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")}else a(":value",c),a("@change",`${c} = value`,"model");return}const p=s[i],f=p?.prop??"value",y=p?.event??"change";a(`:${f}`,c),a(`@${y}`,`${c} = ${"checked"===f?"checked":"value"===f?"value":`event.target.${f}`}`,"model")}function f(e,t,n,c=null){if(!e.attrs||0===e.attrs.length)return[];const o=[];for(const s of e.attrs){if(c&&c.has(s.key))continue;const{key:i,value:r,role:p}=s,{isDynamic:f,type:y}=l(i);if(f&&y){const c={k:i,f:n.compile(y,r??"",t),d:1,r:p};a(c,r,s.loc??e.loc),o.push(c)}else o.push({k:i,v:r,d:0,r:p})}return o}function y(e){let t=0===e.d;if(e.c&&e.c.length>0)for(const n of e.c)y(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)y(e)||(t=!1);return!t||e.t!==n.ASTType.Element&&e.t!==n.ASTType.Text||(e.s=1),t}function u(e,c,s){const i={t:e.type,d:0};let r=!1;var y;switch(e.type===n.ASTType.Text?(y=e.content)&&o.test(y)&&(r=!0):(e.attrs?.some(e=>"s-model"===e.key||l(e.key).isDynamic)&&(r=!0),e.type===n.ASTType.For&&(r=!0)),i.d=r?1:0,e.type){case n.ASTType.Text:{const t=e.content??"";r?(i.f=s.compile("template",t,c),a(i,t,e.loc)):i.x=t;break}case n.ASTType.Element:i.g=e.tag,p(e),i.a=f(e,c,s),e.children&&(i.c=h(e.children,c,s));break;case n.ASTType.For:{const t=e.attrs?.find(e=>"each"===e.key),n=t?.value??"";i.f=s.compile("expression",n,c),i.i=e.attrs?.find(e=>"item"===e.key)?.value??"item",i.n=e.attrs?.find(e=>"index"===e.key)?.value??"index",a(i,n,t?.loc??e.loc);const o=new Set(["each","item","index"]);i.a=f(e,c,s,o);const r=[...c,{i:i.i,x:i.n}];e.children&&(i.c=h(e.children,r,s));break}case n.ASTType.If:case n.ASTType.ElseIf:case n.ASTType.Else:case n.ASTType.Show:t.IS_DEV&&console.warn(`[Solely] Orphaned conditional node found: ${n.ASTType[e.type]}`),i.a=f(e,c,s),e.children&&(i.c=h(e.children,c,s));break;case n.ASTType.Comment:i.x=e.content??""}return i}function h(e,t,c){const o=[];let s=0;for(;s<e.length;){const i=e[s];if(i.type===n.ASTType.If||i.type===n.ASTType.Show){const r=[];let l=s;for(;l<e.length;){const o=e[l],s=o.type;if(o.type===n.ASTType.Text&&!(o.content??"").trim()||o.type===n.ASTType.Comment){let t=l;for(;t<e.length;){const c=e[t];if((c.type!==n.ASTType.Text||(c.content??"").trim())&&c.type!==n.ASTType.Comment)break;t++}const c=e[t];if(c&&(c.type===n.ASTType.ElseIf||c.type===n.ASTType.Else)){l=t;continue}break}if(s!==n.ASTType.If&&s!==n.ASTType.ElseIf&&s!==n.ASTType.Else&&s!==n.ASTType.Show)break;if((s===n.ASTType.If||s===n.ASTType.Show)&&r.length>0)break;let i,a=null,p="";if(s!==n.ASTType.Else){const e=o.attrs?.find(e=>"test"===e.key||"condition"===e.key);p=e?.value??"false",a=c.compile("expression",p,t),i=e?.loc??o.loc}const y=o.children?h(o.children,t,c):[],u=f(o,t,c,new Set(["test","condition","keepalive"])),d=s===n.ASTType.Show||o.attrs?.some(e=>"keepalive"===e.key);if(r.push({f:a,c:y,a:u.length>0?u:void 0,ka:d?1:void 0,__m:{expr:p,loc:i}}),l++,s===n.ASTType.Else||s===n.ASTType.Show)break}o.push({t:n.ASTType.Conditional,d:1,b:r,__m:{loc:i.loc}}),s=l}else o.push(u(i,t,c)),s++}return o}exports.buildIR=function(e,n={}){const{filename:c="anonymous",source:o}=n,s=i.get(c);s.clear();const r=performance.now(),l=h(e,[],s);for(const t of l)y(t);const a=performance.now(),p=s.getStats(),f=l.filter(e=>1===e.d).length,u=l.filter(e=>1===e.s).length,d={t:"root",v:"1.2.0",fns:s.getFunctions(),n:l,s:{tf:p.total,cf:p.cached,dn:f,tn:l.length,sn:u},m:{...t.IS_DEV&&{t:(new Date).toISOString()},as:e.length,fn:c,...o&&{src:o}}};return t.IS_DEV&&console.info(`[Solely] Compiled <${c}> in ${(a-r).toFixed(2)}ms | Nodes: ${l.length} | Fns: ${p.total} | StaticSubtrees: ${u}`),d},exports.clearIRCache=function(e){i.clear(e)},exports.transformModel=p;
@@ -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 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
+ import{genFunction as e}from"../../shared/gen-function.js";import{IS_DEV as t}from"../../shared/env.js";import{ASTType as n}from"../../types/ast.js";import{isLifecycleKind as o}from"../../types/lifecycle.js";const c=/\{\{[\s\S]*?\}\}/,s={"solely-checkbox":{prop:"checked",event:"change"},"solely-switch":{prop:"checked",event:"change"},"solely-radio":{prop:"checked",event:"change"}},i=new class{compilers=new Map;get(e="anonymous"){let t=this.compilers.get(e);return t||(t=new r,this.compilers.set(e,t)),t}clear(e){if(e)this.compilers.get(e)?.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class r{cache=new Map;functions=[];makeCacheKey(e,t,n){return 0===n.length?`${e}:${t}`:`${e}:${t}:${n.map(e=>`${e.i}:${e.x}`).join(";")}`}compile(n,o,c){const s="template"===n?o??"":o?.trim()??"";if(!s.trim())return 0;const i=this.makeCacheKey(n,s,c),r=this.cache.get(i);if(void 0!==r)return r;let l;try{l=e(s,n,c)}catch(f){t&&console.error(`[Solely] IR Compile Error - Type: ${n}, Expr: "${s}"`,f),l=()=>""}const a=this.functions.push(l);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 l(e){const t=e[0];return":"===t?{isDynamic:!0,type:"expression"}:"@"===t?{isDynamic:!0,type:"handler"}:o(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function a(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,i=(e.tag||"").toLowerCase(),r=e.attrs.find(e=>"type"===e.key),l=r?.value??"text";e.attrs=e.attrs.filter(e=>e!==t);const a=(t,n,o)=>{e.attrs?.push({key:t,value:n,role:o,loc:c})};if("input"===i){if("checkbox"===l){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"===l){const t=e.attrs.find(e=>"value"===e.key),n=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"===i)return a(":value",o),void a("@input",`${o} = value`,"model");if("select"===i){if(e.attrs.some(e=>"multiple"===e.key)){const e=`\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("mounted",e),a("updated",e),a("@change",`${o} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")}else a(":value",o),a("@change",`${o} = value`,"model");return}const f=s[i],h=f?.prop??"value",u=f?.event??"change";a(`:${h}`,o),a(`@${u}`,`${o} = ${"checked"===h?"checked":"value"===h?"value":`event.target.${h}`}`,"model")}function h(e,t,n,o=null){if(!e.attrs||0===e.attrs.length)return[];const c=[];for(const s of e.attrs){if(o&&o.has(s.key))continue;const{key:i,value:r,role:f}=s,{isDynamic:h,type:u}=l(i);if(h&&u){const o={k:i,f:n.compile(u,r??"",t),d:1,r:f};a(o,r,s.loc??e.loc),c.push(o)}else c.push({k:i,v:r,d:0,r:f})}return c}function u(e){let t=0===e.d;if(e.c&&e.c.length>0)for(const n of e.c)u(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)u(e)||(t=!1);return!t||e.t!==n.Element&&e.t!==n.Text||(e.s=1),t}function p(e,o,s){const i={t:e.type,d:0};let r=!1;var u;switch(e.type===n.Text?(u=e.content)&&c.test(u)&&(r=!0):(e.attrs?.some(e=>"s-model"===e.key||l(e.key).isDynamic)&&(r=!0),e.type===n.For&&(r=!0)),i.d=r?1:0,e.type){case n.Text:{const t=e.content??"";r?(i.f=s.compile("template",t,o),a(i,t,e.loc)):i.x=t;break}case n.Element:i.g=e.tag,f(e),i.a=h(e,o,s),e.children&&(i.c=d(e.children,o,s));break;case n.For:{const t=e.attrs?.find(e=>"each"===e.key),n=t?.value??"";i.f=s.compile("expression",n,o),i.i=e.attrs?.find(e=>"item"===e.key)?.value??"item",i.n=e.attrs?.find(e=>"index"===e.key)?.value??"index",a(i,n,t?.loc??e.loc);const c=new Set(["each","item","index"]);i.a=h(e,o,s,c);const r=[...o,{i:i.i,x:i.n}];e.children&&(i.c=d(e.children,r,s));break}case n.If:case n.ElseIf:case n.Else:case n.Show:t&&console.warn(`[Solely] Orphaned conditional node found: ${n[e.type]}`),i.a=h(e,o,s),e.children&&(i.c=d(e.children,o,s));break;case n.Comment:i.x=e.content??""}return i}function d(e,t,o){const c=[];let s=0;for(;s<e.length;){const i=e[s];if(i.type===n.If||i.type===n.Show){const r=[];let l=s;for(;l<e.length;){const c=e[l],s=c.type;if(c.type===n.Text&&!(c.content??"").trim()||c.type===n.Comment){let t=l;for(;t<e.length;){const o=e[t];if((o.type!==n.Text||(o.content??"").trim())&&o.type!==n.Comment)break;t++}const o=e[t];if(o&&(o.type===n.ElseIf||o.type===n.Else)){l=t;continue}break}if(s!==n.If&&s!==n.ElseIf&&s!==n.Else&&s!==n.Show)break;if((s===n.If||s===n.Show)&&r.length>0)break;let i,a=null,f="";if(s!==n.Else){const e=c.attrs?.find(e=>"test"===e.key||"condition"===e.key);f=e?.value??"false",a=o.compile("expression",f,t),i=e?.loc??c.loc}const u=c.children?d(c.children,t,o):[],p=h(c,t,o,new Set(["test","condition","keepalive"])),m=s===n.Show||c.attrs?.some(e=>"keepalive"===e.key);if(r.push({f:a,c:u,a:p.length>0?p:void 0,ka:m?1:void 0,__m:{expr:f,loc:i}}),l++,s===n.Else||s===n.Show)break}c.push({t:n.Conditional,d:1,b:r,__m:{loc:i.loc}}),s=l}else c.push(p(i,t,o)),s++}return c}function m(e,n={}){const{filename:o="anonymous",source:c}=n,s=i.get(o);s.clear();const r=performance.now(),l=d(e,[],s);for(const t of l)u(t);const a=performance.now(),f=s.getStats(),h=l.filter(e=>1===e.d).length,p=l.filter(e=>1===e.s).length,m={t:"root",v:"1.2.0",fns:s.getFunctions(),n:l,s:{tf:f.total,cf:f.cached,dn:h,tn:l.length,sn:p},m:{...t&&{t:(new Date).toISOString()},as:e.length,fn:o,...c&&{src:c}}};return t&&console.info(`[Solely] Compiled <${o}> in ${(a-r).toFixed(2)}ms | Nodes: ${l.length} | Fns: ${f.total} | StaticSubtrees: ${p}`),m}function y(e){i.clear(e)}export{m as buildIR,y 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\/]/,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
+ "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"]),i=new Set(["html","head","body","div","p","section","article","aside","header","footer","main","nav","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","table","caption","colgroup","col","thead","tbody","tfoot","tr","td","th","form","fieldset","legend","blockquote","pre","hr","address","figure","figcaption","details","summary","dialog","menu","option","optgroup","datalist","template","script","style","title","noscript"]);function r(t,e){const n=/^<([a-zA-Z][a-zA-Z0-9-]*)/.exec(t.slice(e,e+32));return!!n&&i.has(n[1].toLowerCase())}const c=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function l(o,i){const r=(o.match(s)||[])[1]?.toLowerCase()??"",l=function(e,s){c.lastIndex=0;const o=[];let i;const r=e.replace(/^\s*[^\s"'/>]+/,""),l=e.length-r.length;for(;null!==(i=c.exec(r));){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],p=h.indexOf("=");let f;if(-1===p)f=h.indexOf(r)+r.length;else{let t=p+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++;f=e}else{let e=t;for(;e<h.length&&/\s/.test(h[e]);)e++;f=e}}const u=i.index+f+l,g=e.slice(0,u).split("\n"),d=s[0]+g.length-1,T=g.length>1?g[g.length-1].length+1:s[1]+u;o.push({key:a,value:c,loc:[d,T]})}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}[r]??e.ASTType.Element,tag:r,loc:i,children:[],attrs:l}}function a(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,i=e;for(;i<n;){const e=t[i];if("'"!==e||o)if('"'!==e||s){if(">"===e&&!s&&!o)return i}else o=!o;else s=!s;i++}return-1}exports.parseHtml=function(t){const n=[];if(!t)return[];const c=[],h=()=>0===c.length?n:c[c.length-1].children||=[];let p=0;const f=t.length,u=[0];let g=0;for(;-1!==(g=t.indexOf("\n",g));)u.push(++g);function d(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(;p<f;){const n=t.indexOf("<",p);if(-1===n||n>p){const s=t.substring(p,-1===n?void 0:n),o=c.length>0?c[c.length-1]:null,l=o&&("pre"===o.tag||"code"===o.tag||"textarea"===o.tag||"script"===o.tag||"style"===o.tag);let a,f;const u=h(),g=u[u.length-1];if(l)a=s,f=p;else{const c=!g||g.type===e.ASTType.Element&&i.has((g.tag||"").toLowerCase());let l=!0,h=!1;-1!==n&&(h=t.startsWith("</",n),l=h?!o||i.has(o.tag.toLowerCase()):r(t,n));const u=/\n\s*$/.test(s);if(a=s.replace(/\s+/g," "),/^\s+$/.test(s)){if(h||c||l){if(p=n,-1===n)break;continue}a=" "}else c&&(a=a.replace(/^ /,"")),(l||h&&u)&&(a=a.replace(/ $/,""));if(""===a){if(p=n,-1===n)break;continue}f=p+(s.length-s.trimStart().length)}if(g&&g.type===e.ASTType.Text)g.content+=a;else{const t=d(f);u.push({type:e.ASTType.Text,tag:"text",content:a,loc:t,children:[]})}if(-1===n)break;p=n}const u=a(t,p+1);if(-1===u){const n=t.substring(p);n.trim()&&h().push({type:e.ASTType.Text,tag:"text",content:n.trim(),children:[],loc:d(p)});break}const g=t.substring(p,u+1),T=h(),y=d(p);if(g.startsWith("\x3c!--")){T.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(4,-3),loc:y,children:[]}),p=u+1;continue}if(g.startsWith("<![CDATA[")){T.push({type:e.ASTType.Text,tag:"text",content:g.slice(9,-3),loc:y,children:[]}),p=u+1;continue}if(g.startsWith("<!")&&!g.startsWith("\x3c!--")){T.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(2,-1),loc:y,children:[]}),p=u+1;continue}if(g.startsWith("<?")){T.push({type:e.ASTType.Comment,tag:"comment",content:g.slice(2,-2),loc:y,children:[]}),p=u+1;continue}if(g.startsWith("</")){const t=(g.match(s)||[])[1]?.toLowerCase();if(t){let e=-1;for(let n=c.length-1;n>=0;n--)if(c[n].tag?.toLowerCase()===t){e=n;break}-1!==e&&(c.length=e)}p=u+1;continue}const m=l(g,y);T.push(m);const x=m.tag||"",A=x.toLowerCase().startsWith("script"),S=x.toLowerCase().startsWith("style"),b=g.endsWith("/>")||o.has(x.toLowerCase());if((A||S)&&!b){const n=`</${x}>`,s=t.toLowerCase().indexOf(n,u+1);if(-1!==s){const o=t.substring(u+1,s);o.length&&m.children.push({type:e.ASTType.Text,tag:"text",content:o,loc:d(u+1),children:[]}),p=s+n.length;continue}{const n=t.substring(u+1);n.length&&m.children.push({type:e.ASTType.Text,tag:"text",content:n,loc:d(u+1),children:[]}),p=f;continue}}b||m.type===e.ASTType.Text||m.type===e.ASTType.Comment||c.push(m),p=u+1}return n};
@@ -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,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};
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"]),i=new Set(["html","head","body","div","p","section","article","aside","header","footer","main","nav","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","table","caption","colgroup","col","thead","tbody","tfoot","tr","td","th","form","fieldset","legend","blockquote","pre","hr","address","figure","figcaption","details","summary","dialog","menu","option","optgroup","datalist","template","script","style","title","noscript"]);function r(t,e){const n=/^<([a-zA-Z][a-zA-Z0-9-]*)/.exec(t.slice(e,e+32));return!!n&&i.has(n[1].toLowerCase())}const c=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function l(o,i){const r=(o.match(s)||[])[1]?.toLowerCase()??"",l=function(e,s){c.lastIndex=0;const o=[];let i;const r=e.replace(/^\s*[^\s"'/>]+/,""),l=e.length-r.length;for(;null!==(i=c.exec(r));){const r=i[1];if(!r)continue;const c=i[2]??i[3]??i[4]??"";let a=r;t.has(r)&&(a=a.replace(/^on/,"@")),"s-model"!==a&&(a=a.replace(/^on-/,"@").replace(/^s-/,":")),a=n(a)||a;const h=i[0],f=h.indexOf("=");let g;if(-1===f)g=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++;g=e}else{let e=t;for(;e<h.length&&/\s/.test(h[e]);)e++;g=e}}const u=i.index+g+l,p=e.slice(0,u).split("\n"),d=s[0]+p.length-1,m=p.length>1?p[p.length-1].length+1:s[1]+u;o.push({key:a,value:c,loc:[d,m]})}return o}(o,i);return{type:{for:e.For,if:e.If,elseif:e.ElseIf,else:e.Else,show:e.Show}[r]??e.Element,tag:r,loc:i,children:[],attrs:l}}function a(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,i=e;for(;i<n;){const e=t[i];if("'"!==e||o)if('"'!==e||s){if(">"===e&&!s&&!o)return i}else o=!o;else s=!s;i++}return-1}function h(t){const n=[];if(!t)return[];const c=[],h=()=>0===c.length?n:c[c.length-1].children||=[];let f=0;const g=t.length,u=[0];let p=0;for(;-1!==(p=t.indexOf("\n",p));)u.push(++p);function d(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<g;){const n=t.indexOf("<",f);if(-1===n||n>f){const s=t.substring(f,-1===n?void 0:n),o=c.length>0?c[c.length-1]:null,l=o&&("pre"===o.tag||"code"===o.tag||"textarea"===o.tag||"script"===o.tag||"style"===o.tag);let a,g;const u=h(),p=u[u.length-1];if(l)a=s,g=f;else{const c=!p||p.type===e.Element&&i.has((p.tag||"").toLowerCase());let l=!0,h=!1;-1!==n&&(h=t.startsWith("</",n),l=h?!o||i.has(o.tag.toLowerCase()):r(t,n));const u=/\n\s*$/.test(s);if(a=s.replace(/\s+/g," "),/^\s+$/.test(s)){if(h||c||l){if(f=n,-1===n)break;continue}a=" "}else c&&(a=a.replace(/^ /,"")),(l||h&&u)&&(a=a.replace(/ $/,""));if(""===a){if(f=n,-1===n)break;continue}g=f+(s.length-s.trimStart().length)}if(p&&p.type===e.Text)p.content+=a;else{const t=d(g);u.push({type:e.Text,tag:"text",content:a,loc:t,children:[]})}if(-1===n)break;f=n}const u=a(t,f+1);if(-1===u){const n=t.substring(f);n.trim()&&h().push({type:e.Text,tag:"text",content:n.trim(),children:[],loc:d(f)});break}const p=t.substring(f,u+1),m=h(),x=d(f);if(p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(4,-3),loc:x,children:[]}),f=u+1;continue}if(p.startsWith("<![CDATA[")){m.push({type:e.Text,tag:"text",content:p.slice(9,-3),loc:x,children:[]}),f=u+1;continue}if(p.startsWith("<!")&&!p.startsWith("\x3c!--")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-1),loc:x,children:[]}),f=u+1;continue}if(p.startsWith("<?")){m.push({type:e.Comment,tag:"comment",content:p.slice(2,-2),loc:x,children:[]}),f=u+1;continue}if(p.startsWith("</")){const t=(p.match(s)||[])[1]?.toLowerCase();if(t){let e=-1;for(let n=c.length-1;n>=0;n--)if(c[n].tag?.toLowerCase()===t){e=n;break}-1!==e&&(c.length=e)}f=u+1;continue}const y=l(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,u+1);if(-1!==s){const o=t.substring(u+1,s);o.length&&y.children.push({type:e.Text,tag:"text",content:o,loc:d(u+1),children:[]}),f=s+n.length;continue}{const n=t.substring(u+1);n.length&&y.children.push({type:e.Text,tag:"text",content:n,loc:d(u+1),children:[]}),f=g;continue}}W||y.type===e.Text||y.type===e.Comment||c.push(y),f=u+1}return n}export{h as parseHtml};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),l={width:378,height:378,mask:!0,maskClosable:!0,closable:!0},n=[],s=new Set;async function o(t){var l;if(!s.has(t)){s.add(t);try{const s=n.findIndex(e=>e.id===t);if(-1===s)return;const o=n[s],i=o.element.querySelector(".solely-drawer-mask"),a=o.element.querySelector(".solely-drawer");i&&i.classList.add("is-closing"),a&&a.classList.add("is-closing"),await e.addClosingAnimation(o.element,e.ANIMATION_DURATION.NORMAL),null==(l=o.cleanup)||l.call(o);const r=n.findIndex(e=>e.id===t);-1!==r&&(n[r].element.remove(),n.splice(r,1)),0===n.length&&document.body.classList.remove("solely-drawer-open")}finally{s.delete(t)}}}const i={open:function(s){const i=e.generateId();e.injectStyle("solely-drawer-styles",t.default);const a=s.placement||"right",r=s.width??l.width,c=s.height??l.height,d=s.mask??l.mask,y=s.maskClosable??l.maskClosable,m=s.closable??l.closable,p=e.createElement("div",{className:"solely-drawer-wrap"}),h=e.observeTheme(()=>p),f=s.cloneElement??!0,u=[];if(!1!==d){const t=e.createElement("div",{className:"solely-drawer-mask"});if(y){const e=()=>{var e;o(i),null==(e=s.onClose)||e.call(s)};t.addEventListener("click",e),u.push({element:t,type:"click",handler:e})}p.appendChild(t)}const w=e.createElement("div",{className:`solely-drawer solely-drawer--${a}${s.className?` ${s.className}`:""}`,styles:s.style});if("left"===a||"right"===a?w.style.width="number"==typeof r?`${r}px`:r:w.style.height="number"==typeof c?`${c}px`:c,s.title||!1!==m){const t=e.createElement("div",{className:"solely-drawer__header"});if(s.title){const l=e.createElement("h3",{className:"solely-drawer__title"});"string"==typeof s.title?l.textContent=s.title:s.title instanceof HTMLElement&&l.appendChild(f?s.title.cloneNode(!0):s.title),t.appendChild(l)}if(!1!==m){const l=e.createElement("button",{className:"solely-drawer__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}}),n=()=>{var e;o(i),null==(e=s.onClose)||e.call(s)};l.addEventListener("click",n),u.push({element:l,type:"click",handler:n}),t.appendChild(l)}w.appendChild(t)}const g=e.createElement("div",{className:"solely-drawer__body",styles:s.bodyStyle});return"string"==typeof s.content?g.textContent=s.content||"":s.content instanceof HTMLElement&&g.appendChild(f?s.content.cloneNode(!0):s.content),w.appendChild(g),p.appendChild(w),document.body.appendChild(p),document.body.classList.add("solely-drawer-open"),n.push({id:i,element:p,options:s,cleanup:()=>{u.forEach(({element:e,type:t,handler:l})=>{e.removeEventListener(t,l)}),h()}}),{close:()=>{var e;o(i),null==(e=s.onClose)||e.call(s)},update:t=>{const l=t.cloneElement??f;if(void 0!==t.title){const n=p.querySelector(".solely-drawer__title");if(n)n.innerHTML="","string"==typeof t.title?n.textContent=t.title:t.title instanceof HTMLElement&&n.appendChild(l?t.title.cloneNode(!0):t.title);else if(t.title){const n=e.createElement("div",{className:"solely-drawer__header"}),s=e.createElement("h3",{className:"solely-drawer__title"});"string"==typeof t.title?s.textContent=t.title:t.title instanceof HTMLElement&&s.appendChild(l?t.title.cloneNode(!0):t.title),n.appendChild(s);const o=p.querySelector(".solely-drawer");null==o||o.insertBefore(n,o.firstChild)}}if(void 0!==t.content){const e=p.querySelector(".solely-drawer__body");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(l?t.content.cloneNode(!0):t.content))}const n=p.querySelector(".solely-drawer");if(n){const e=t.placement||s.placement||"right";void 0===t.width||"left"!==e&&"right"!==e||(n.style.width="number"==typeof t.width?`${t.width}px`:t.width),void 0===t.height||"top"!==e&&"bottom"!==e||(n.style.height="number"==typeof t.height?`${t.height}px`:t.height)}if(void 0!==t.className&&n){const e=s.placement||"right";n.className=`solely-drawer solely-drawer--${e} ${t.className}`.trim()}if(void 0!==t.style&&n&&Object.assign(n.style,t.style),void 0!==t.bodyStyle){const e=p.querySelector(".solely-drawer__body");e&&Object.assign(e.style,t.bodyStyle)}}}},config:function(e){Object.assign(l,e)},destroy:async function(){const e=[...n].reverse();for(const t of e)await o(t.id)}};exports.Drawer=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),l={width:378,height:378,mask:!0,maskClosable:!0,closable:!0},n=[],s=new Set;async function o(t){if(!s.has(t)){s.add(t);try{const l=n.findIndex(e=>e.id===t);if(-1===l)return;const s=n[l],o=s.element.querySelector(".solely-drawer-mask"),i=s.element.querySelector(".solely-drawer");o&&o.classList.add("is-closing"),i&&i.classList.add("is-closing"),await e.addClosingAnimation(s.element,e.ANIMATION_DURATION.NORMAL),s.cleanup?.();const a=n.findIndex(e=>e.id===t);-1!==a&&(n[a].element.remove(),n.splice(a,1)),0===n.length&&document.body.classList.remove("solely-drawer-open")}finally{s.delete(t)}}}const i={open:function(s){const i=e.generateId();e.injectStyle("solely-drawer-styles",t.default);const a=s.placement||"right",r=s.width??l.width,c=s.height??l.height,d=s.mask??l.mask,y=s.maskClosable??l.maskClosable,m=s.closable??l.closable,p=e.createElement("div",{className:"solely-drawer-wrap"}),h=e.observeTheme(()=>p),f=s.cloneElement??!0,w=[];if(!1!==d){const t=e.createElement("div",{className:"solely-drawer-mask"});if(y){const e=()=>{o(i),s.onClose?.()};t.addEventListener("click",e),w.push({element:t,type:"click",handler:e})}p.appendChild(t)}const u=e.createElement("div",{className:`solely-drawer solely-drawer--${a}${s.className?` ${s.className}`:""}`,styles:s.style});if("left"===a||"right"===a?u.style.width="number"==typeof r?`${r}px`:r:u.style.height="number"==typeof c?`${c}px`:c,s.title||!1!==m){const t=e.createElement("div",{className:"solely-drawer__header"});if(s.title){const l=e.createElement("h3",{className:"solely-drawer__title"});"string"==typeof s.title?l.textContent=s.title:s.title instanceof HTMLElement&&l.appendChild(f?s.title.cloneNode(!0):s.title),t.appendChild(l)}if(!1!==m){const l=e.createElement("button",{className:"solely-drawer__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}}),n=()=>{o(i),s.onClose?.()};l.addEventListener("click",n),w.push({element:l,type:"click",handler:n}),t.appendChild(l)}u.appendChild(t)}const g=e.createElement("div",{className:"solely-drawer__body",styles:s.bodyStyle});return"string"==typeof s.content?g.textContent=s.content||"":s.content instanceof HTMLElement&&g.appendChild(f?s.content.cloneNode(!0):s.content),u.appendChild(g),p.appendChild(u),document.body.appendChild(p),document.body.classList.add("solely-drawer-open"),n.push({id:i,element:p,options:s,cleanup:()=>{w.forEach(({element:e,type:t,handler:l})=>{e.removeEventListener(t,l)}),h()}}),{close:()=>{o(i),s.onClose?.()},update:t=>{const l=t.cloneElement??f;if(void 0!==t.title){const n=p.querySelector(".solely-drawer__title");if(n)n.innerHTML="","string"==typeof t.title?n.textContent=t.title:t.title instanceof HTMLElement&&n.appendChild(l?t.title.cloneNode(!0):t.title);else if(t.title){const n=e.createElement("div",{className:"solely-drawer__header"}),s=e.createElement("h3",{className:"solely-drawer__title"});"string"==typeof t.title?s.textContent=t.title:t.title instanceof HTMLElement&&s.appendChild(l?t.title.cloneNode(!0):t.title),n.appendChild(s);const o=p.querySelector(".solely-drawer");o?.insertBefore(n,o.firstChild)}}if(void 0!==t.content){const e=p.querySelector(".solely-drawer__body");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(l?t.content.cloneNode(!0):t.content))}const n=p.querySelector(".solely-drawer");if(n){const e=t.placement||s.placement||"right";void 0===t.width||"left"!==e&&"right"!==e||(n.style.width="number"==typeof t.width?`${t.width}px`:t.width),void 0===t.height||"top"!==e&&"bottom"!==e||(n.style.height="number"==typeof t.height?`${t.height}px`:t.height)}if(void 0!==t.className&&n){const e=s.placement||"right";n.className=`solely-drawer solely-drawer--${e} ${t.className}`.trim()}if(void 0!==t.style&&n&&Object.assign(n.style,t.style),void 0!==t.bodyStyle){const e=p.querySelector(".solely-drawer__body");e&&Object.assign(e.style,t.bodyStyle)}}}},config:function(e){Object.assign(l,e)},destroy:async function(){const e=[...n].reverse();for(const t of e)await o(t.id)}};exports.Drawer=i;
@@ -1 +1 @@
1
- import{createElement as e,observeTheme as t,addClosingAnimation as l,ANIMATION_DURATION as n,injectStyle as s,generateId as o}from"../utils.js";import i from"./style.css.js";const a={width:378,height:378,mask:!0,maskClosable:!0,closable:!0},d=[],c=new Set;async function r(e){var t;if(!c.has(e)){c.add(e);try{const s=d.findIndex(t=>t.id===e);if(-1===s)return;const o=d[s],i=o.element.querySelector(".solely-drawer-mask"),a=o.element.querySelector(".solely-drawer");i&&i.classList.add("is-closing"),a&&a.classList.add("is-closing"),await l(o.element,n.NORMAL),null==(t=o.cleanup)||t.call(o);const c=d.findIndex(t=>t.id===e);-1!==c&&(d[c].element.remove(),d.splice(c,1)),0===d.length&&document.body.classList.remove("solely-drawer-open")}finally{c.delete(e)}}}const y={open:function(l){const n=o();s("solely-drawer-styles",i);const c=l.placement||"right",y=l.width??a.width,p=l.height??a.height,h=l.mask??a.mask,m=l.maskClosable??a.maskClosable,f=l.closable??a.closable,w=e("div",{className:"solely-drawer-wrap"}),u=t(()=>w),b=l.cloneElement??!0,g=[];if(!1!==h){const t=e("div",{className:"solely-drawer-mask"});if(m){const e=()=>{var e;r(n),null==(e=l.onClose)||e.call(l)};t.addEventListener("click",e),g.push({element:t,type:"click",handler:e})}w.appendChild(t)}const C=e("div",{className:`solely-drawer solely-drawer--${c}${l.className?` ${l.className}`:""}`,styles:l.style});if("left"===c||"right"===c?C.style.width="number"==typeof y?`${y}px`:y:C.style.height="number"==typeof p?`${p}px`:p,l.title||!1!==f){const t=e("div",{className:"solely-drawer__header"});if(l.title){const n=e("h3",{className:"solely-drawer__title"});"string"==typeof l.title?n.textContent=l.title:l.title instanceof HTMLElement&&n.appendChild(b?l.title.cloneNode(!0):l.title),t.appendChild(n)}if(!1!==f){const s=e("button",{className:"solely-drawer__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}}),o=()=>{var e;r(n),null==(e=l.onClose)||e.call(l)};s.addEventListener("click",o),g.push({element:s,type:"click",handler:o}),t.appendChild(s)}C.appendChild(t)}const v=e("div",{className:"solely-drawer__body",styles:l.bodyStyle});return"string"==typeof l.content?v.textContent=l.content||"":l.content instanceof HTMLElement&&v.appendChild(b?l.content.cloneNode(!0):l.content),C.appendChild(v),w.appendChild(C),document.body.appendChild(w),document.body.classList.add("solely-drawer-open"),d.push({id:n,element:w,options:l,cleanup:()=>{g.forEach(({element:e,type:t,handler:l})=>{e.removeEventListener(t,l)}),u()}}),{close:()=>{var e;r(n),null==(e=l.onClose)||e.call(l)},update:t=>{const n=t.cloneElement??b;if(void 0!==t.title){const l=w.querySelector(".solely-drawer__title");if(l)l.innerHTML="","string"==typeof t.title?l.textContent=t.title:t.title instanceof HTMLElement&&l.appendChild(n?t.title.cloneNode(!0):t.title);else if(t.title){const l=e("div",{className:"solely-drawer__header"}),s=e("h3",{className:"solely-drawer__title"});"string"==typeof t.title?s.textContent=t.title:t.title instanceof HTMLElement&&s.appendChild(n?t.title.cloneNode(!0):t.title),l.appendChild(s);const o=w.querySelector(".solely-drawer");null==o||o.insertBefore(l,o.firstChild)}}if(void 0!==t.content){const e=w.querySelector(".solely-drawer__body");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(n?t.content.cloneNode(!0):t.content))}const s=w.querySelector(".solely-drawer");if(s){const e=t.placement||l.placement||"right";void 0===t.width||"left"!==e&&"right"!==e||(s.style.width="number"==typeof t.width?`${t.width}px`:t.width),void 0===t.height||"top"!==e&&"bottom"!==e||(s.style.height="number"==typeof t.height?`${t.height}px`:t.height)}if(void 0!==t.className&&s){const e=l.placement||"right";s.className=`solely-drawer solely-drawer--${e} ${t.className}`.trim()}if(void 0!==t.style&&s&&Object.assign(s.style,t.style),void 0!==t.bodyStyle){const e=w.querySelector(".solely-drawer__body");e&&Object.assign(e.style,t.bodyStyle)}}}},config:function(e){Object.assign(a,e)},destroy:async function(){const e=[...d].reverse();for(const t of e)await r(t.id)}};export{y as Drawer};
1
+ import{createElement as e,observeTheme as t,addClosingAnimation as l,ANIMATION_DURATION as n,injectStyle as s,generateId as o}from"../utils.js";import i from"./style.css.js";const a={width:378,height:378,mask:!0,maskClosable:!0,closable:!0},d=[],c=new Set;async function r(e){if(!c.has(e)){c.add(e);try{const t=d.findIndex(t=>t.id===e);if(-1===t)return;const s=d[t],o=s.element.querySelector(".solely-drawer-mask"),i=s.element.querySelector(".solely-drawer");o&&o.classList.add("is-closing"),i&&i.classList.add("is-closing"),await l(s.element,n.NORMAL),s.cleanup?.();const a=d.findIndex(t=>t.id===e);-1!==a&&(d[a].element.remove(),d.splice(a,1)),0===d.length&&document.body.classList.remove("solely-drawer-open")}finally{c.delete(e)}}}const y={open:function(l){const n=o();s("solely-drawer-styles",i);const c=l.placement||"right",y=l.width??a.width,p=l.height??a.height,h=l.mask??a.mask,m=l.maskClosable??a.maskClosable,f=l.closable??a.closable,w=e("div",{className:"solely-drawer-wrap"}),u=t(()=>w),b=l.cloneElement??!0,g=[];if(!1!==h){const t=e("div",{className:"solely-drawer-mask"});if(m){const e=()=>{r(n),l.onClose?.()};t.addEventListener("click",e),g.push({element:t,type:"click",handler:e})}w.appendChild(t)}const C=e("div",{className:`solely-drawer solely-drawer--${c}${l.className?` ${l.className}`:""}`,styles:l.style});if("left"===c||"right"===c?C.style.width="number"==typeof y?`${y}px`:y:C.style.height="number"==typeof p?`${p}px`:p,l.title||!1!==f){const t=e("div",{className:"solely-drawer__header"});if(l.title){const n=e("h3",{className:"solely-drawer__title"});"string"==typeof l.title?n.textContent=l.title:l.title instanceof HTMLElement&&n.appendChild(b?l.title.cloneNode(!0):l.title),t.appendChild(n)}if(!1!==f){const s=e("button",{className:"solely-drawer__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}}),o=()=>{r(n),l.onClose?.()};s.addEventListener("click",o),g.push({element:s,type:"click",handler:o}),t.appendChild(s)}C.appendChild(t)}const v=e("div",{className:"solely-drawer__body",styles:l.bodyStyle});return"string"==typeof l.content?v.textContent=l.content||"":l.content instanceof HTMLElement&&v.appendChild(b?l.content.cloneNode(!0):l.content),C.appendChild(v),w.appendChild(C),document.body.appendChild(w),document.body.classList.add("solely-drawer-open"),d.push({id:n,element:w,options:l,cleanup:()=>{g.forEach(({element:e,type:t,handler:l})=>{e.removeEventListener(t,l)}),u()}}),{close:()=>{r(n),l.onClose?.()},update:t=>{const n=t.cloneElement??b;if(void 0!==t.title){const l=w.querySelector(".solely-drawer__title");if(l)l.innerHTML="","string"==typeof t.title?l.textContent=t.title:t.title instanceof HTMLElement&&l.appendChild(n?t.title.cloneNode(!0):t.title);else if(t.title){const l=e("div",{className:"solely-drawer__header"}),s=e("h3",{className:"solely-drawer__title"});"string"==typeof t.title?s.textContent=t.title:t.title instanceof HTMLElement&&s.appendChild(n?t.title.cloneNode(!0):t.title),l.appendChild(s);const o=w.querySelector(".solely-drawer");o?.insertBefore(l,o.firstChild)}}if(void 0!==t.content){const e=w.querySelector(".solely-drawer__body");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(n?t.content.cloneNode(!0):t.content))}const s=w.querySelector(".solely-drawer");if(s){const e=t.placement||l.placement||"right";void 0===t.width||"left"!==e&&"right"!==e||(s.style.width="number"==typeof t.width?`${t.width}px`:t.width),void 0===t.height||"top"!==e&&"bottom"!==e||(s.style.height="number"==typeof t.height?`${t.height}px`:t.height)}if(void 0!==t.className&&s){const e=l.placement||"right";s.className=`solely-drawer solely-drawer--${e} ${t.className}`.trim()}if(void 0!==t.style&&s&&Object.assign(s.style,t.style),void 0!==t.bodyStyle){const e=w.querySelector(".solely-drawer__body");e&&Object.assign(e.style,t.bodyStyle)}}}},config:function(e){Object.assign(a,e)},destroy:async function(){const e=[...d].reverse();for(const t of e)await r(t.id)}};export{y as Drawer};
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),exports.default=".solely-drawer,.solely-drawer *,.solely-drawer *:before,.solely-drawer *:after,.solely-drawer-mask,.solely-drawer-wrap{box-sizing:border-box}.solely-drawer-mask{position:fixed;top:0;left:0;right:0;bottom:0;background-color:var(--solely-mask-bg);z-index:1;pointer-events:auto;animation:solely-drawer-mask-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer-mask.is-closing{animation:solely-drawer-mask-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer-wrap{position:fixed;top:0;left:0;right:0;bottom:0;z-index:var(--solely-z-index-modal);pointer-events:none}.solely-drawer{position:absolute;background-color:var(--solely-component-bg);box-shadow:var(--solely-shadow-lg);pointer-events:auto;display:flex;flex-direction:column;z-index:2}.solely-drawer--left{left:0;top:0;bottom:0;animation:solely-drawer-left-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--right{right:0;top:0;bottom:0;animation:solely-drawer-right-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--top{top:0;left:0;right:0;animation:solely-drawer-top-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--bottom{bottom:0;left:0;right:0;animation:solely-drawer-bottom-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer.is-closing.solely-drawer--left{animation:solely-drawer-left-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--right{animation:solely-drawer-right-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--top{animation:solely-drawer-top-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--bottom{animation:solely-drawer-bottom-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer__header{display:flex;align-items:center;justify-content:space-between;padding:var(--solely-spacing-lg) var(--solely-spacing-xl);border-bottom:1px solid var(--solely-border-color-split)}.solely-drawer__title{margin:0;font-size:var(--solely-font-size-lg);font-weight:500;color:var(--solely-text-primary);line-height:var(--solely-line-height-lg)}.solely-drawer__close{width:var(--solely-height-sm);height:var(--solely-height-sm);display:flex;align-items:center;justify-content:center;color:var(--solely-text-tertiary);cursor:pointer;transition:color var(--solely-transition-duration);font-size:var(--solely-font-size-lg);line-height:1;border:none;background:none;border-radius:var(--solely-border-radius-sm)}.solely-drawer__close:hover{color:var(--solely-text-secondary);background-color:var(--solely-gray-3)}.solely-drawer__close:active{color:var(--solely-text-primary)}.solely-drawer__body{flex:1;padding:var(--solely-spacing-xl);overflow:auto;font-size:var(--solely-font-size-md);line-height:var(--solely-line-height-md);color:var(--solely-text-secondary)}@keyframes solely-drawer-mask-in{0%{opacity:0}to{opacity:1}}@keyframes solely-drawer-mask-out{0%{opacity:1}to{opacity:0}}@keyframes solely-drawer-left-in{0%{transform:translate(-100%)}to{transform:translate(0)}}@keyframes solely-drawer-left-out{0%{transform:translate(0)}to{transform:translate(-100%)}}@keyframes solely-drawer-right-in{0%{transform:translate(100%)}to{transform:translate(0)}}@keyframes solely-drawer-right-out{0%{transform:translate(0)}to{transform:translate(100%)}}@keyframes solely-drawer-top-in{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes solely-drawer-top-out{0%{transform:translateY(0)}to{transform:translateY(-100%)}}@keyframes solely-drawer-bottom-in{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes solely-drawer-bottom-out{0%{transform:translateY(0)}to{transform:translateY(100%)}}";
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),exports.default=".solely-drawer,.solely-drawer *,.solely-drawer *:before,.solely-drawer *:after,.solely-drawer-mask,.solely-drawer-wrap{box-sizing:border-box}.solely-drawer-mask{position:fixed;inset:0;background-color:var(--solely-mask-bg);z-index:1;pointer-events:auto;animation:solely-drawer-mask-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer-mask.is-closing{animation:solely-drawer-mask-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer-wrap{position:fixed;inset:0;z-index:var(--solely-z-index-modal);pointer-events:none}.solely-drawer{position:absolute;background-color:var(--solely-component-bg);box-shadow:var(--solely-shadow-lg);pointer-events:auto;display:flex;flex-direction:column;z-index:2}.solely-drawer--left{left:0;top:0;bottom:0;animation:solely-drawer-left-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--right{right:0;top:0;bottom:0;animation:solely-drawer-right-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--top{top:0;left:0;right:0;animation:solely-drawer-top-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--bottom{bottom:0;left:0;right:0;animation:solely-drawer-bottom-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer.is-closing.solely-drawer--left{animation:solely-drawer-left-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--right{animation:solely-drawer-right-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--top{animation:solely-drawer-top-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--bottom{animation:solely-drawer-bottom-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer__header{display:flex;align-items:center;justify-content:space-between;padding:var(--solely-spacing-lg) var(--solely-spacing-xl);border-bottom:1px solid var(--solely-border-color-split)}.solely-drawer__title{margin:0;font-size:var(--solely-font-size-lg);font-weight:500;color:var(--solely-text-primary);line-height:var(--solely-line-height-lg)}.solely-drawer__close{width:var(--solely-height-sm);height:var(--solely-height-sm);display:flex;align-items:center;justify-content:center;color:var(--solely-text-tertiary);cursor:pointer;transition:color var(--solely-transition-duration);font-size:var(--solely-font-size-lg);line-height:1;border:none;background:none;border-radius:var(--solely-border-radius-sm)}.solely-drawer__close:hover{color:var(--solely-text-secondary);background-color:var(--solely-gray-3)}.solely-drawer__close:active{color:var(--solely-text-primary)}.solely-drawer__body{flex:1;padding:var(--solely-spacing-xl);overflow:auto;font-size:var(--solely-font-size-md);line-height:var(--solely-line-height-md);color:var(--solely-text-secondary)}@keyframes solely-drawer-mask-in{0%{opacity:0}to{opacity:1}}@keyframes solely-drawer-mask-out{0%{opacity:1}to{opacity:0}}@keyframes solely-drawer-left-in{0%{transform:translate(-100%)}to{transform:translate(0)}}@keyframes solely-drawer-left-out{0%{transform:translate(0)}to{transform:translate(-100%)}}@keyframes solely-drawer-right-in{0%{transform:translate(100%)}to{transform:translate(0)}}@keyframes solely-drawer-right-out{0%{transform:translate(0)}to{transform:translate(100%)}}@keyframes solely-drawer-top-in{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes solely-drawer-top-out{0%{transform:translateY(0)}to{transform:translateY(-100%)}}@keyframes solely-drawer-bottom-in{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes solely-drawer-bottom-out{0%{transform:translateY(0)}to{transform:translateY(100%)}}";
@@ -1 +1 @@
1
- const r=".solely-drawer,.solely-drawer *,.solely-drawer *:before,.solely-drawer *:after,.solely-drawer-mask,.solely-drawer-wrap{box-sizing:border-box}.solely-drawer-mask{position:fixed;top:0;left:0;right:0;bottom:0;background-color:var(--solely-mask-bg);z-index:1;pointer-events:auto;animation:solely-drawer-mask-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer-mask.is-closing{animation:solely-drawer-mask-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer-wrap{position:fixed;top:0;left:0;right:0;bottom:0;z-index:var(--solely-z-index-modal);pointer-events:none}.solely-drawer{position:absolute;background-color:var(--solely-component-bg);box-shadow:var(--solely-shadow-lg);pointer-events:auto;display:flex;flex-direction:column;z-index:2}.solely-drawer--left{left:0;top:0;bottom:0;animation:solely-drawer-left-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--right{right:0;top:0;bottom:0;animation:solely-drawer-right-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--top{top:0;left:0;right:0;animation:solely-drawer-top-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--bottom{bottom:0;left:0;right:0;animation:solely-drawer-bottom-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer.is-closing.solely-drawer--left{animation:solely-drawer-left-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--right{animation:solely-drawer-right-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--top{animation:solely-drawer-top-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--bottom{animation:solely-drawer-bottom-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer__header{display:flex;align-items:center;justify-content:space-between;padding:var(--solely-spacing-lg) var(--solely-spacing-xl);border-bottom:1px solid var(--solely-border-color-split)}.solely-drawer__title{margin:0;font-size:var(--solely-font-size-lg);font-weight:500;color:var(--solely-text-primary);line-height:var(--solely-line-height-lg)}.solely-drawer__close{width:var(--solely-height-sm);height:var(--solely-height-sm);display:flex;align-items:center;justify-content:center;color:var(--solely-text-tertiary);cursor:pointer;transition:color var(--solely-transition-duration);font-size:var(--solely-font-size-lg);line-height:1;border:none;background:none;border-radius:var(--solely-border-radius-sm)}.solely-drawer__close:hover{color:var(--solely-text-secondary);background-color:var(--solely-gray-3)}.solely-drawer__close:active{color:var(--solely-text-primary)}.solely-drawer__body{flex:1;padding:var(--solely-spacing-xl);overflow:auto;font-size:var(--solely-font-size-md);line-height:var(--solely-line-height-md);color:var(--solely-text-secondary)}@keyframes solely-drawer-mask-in{0%{opacity:0}to{opacity:1}}@keyframes solely-drawer-mask-out{0%{opacity:1}to{opacity:0}}@keyframes solely-drawer-left-in{0%{transform:translate(-100%)}to{transform:translate(0)}}@keyframes solely-drawer-left-out{0%{transform:translate(0)}to{transform:translate(-100%)}}@keyframes solely-drawer-right-in{0%{transform:translate(100%)}to{transform:translate(0)}}@keyframes solely-drawer-right-out{0%{transform:translate(0)}to{transform:translate(100%)}}@keyframes solely-drawer-top-in{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes solely-drawer-top-out{0%{transform:translateY(0)}to{transform:translateY(-100%)}}@keyframes solely-drawer-bottom-in{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes solely-drawer-bottom-out{0%{transform:translateY(0)}to{transform:translateY(100%)}}";export{r as default};
1
+ const r=".solely-drawer,.solely-drawer *,.solely-drawer *:before,.solely-drawer *:after,.solely-drawer-mask,.solely-drawer-wrap{box-sizing:border-box}.solely-drawer-mask{position:fixed;inset:0;background-color:var(--solely-mask-bg);z-index:1;pointer-events:auto;animation:solely-drawer-mask-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer-mask.is-closing{animation:solely-drawer-mask-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer-wrap{position:fixed;inset:0;z-index:var(--solely-z-index-modal);pointer-events:none}.solely-drawer{position:absolute;background-color:var(--solely-component-bg);box-shadow:var(--solely-shadow-lg);pointer-events:auto;display:flex;flex-direction:column;z-index:2}.solely-drawer--left{left:0;top:0;bottom:0;animation:solely-drawer-left-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--right{right:0;top:0;bottom:0;animation:solely-drawer-right-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--top{top:0;left:0;right:0;animation:solely-drawer-top-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer--bottom{bottom:0;left:0;right:0;animation:solely-drawer-bottom-in var(--solely-transition-duration) var(--solely-transition-timing)}.solely-drawer.is-closing.solely-drawer--left{animation:solely-drawer-left-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--right{animation:solely-drawer-right-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--top{animation:solely-drawer-top-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer.is-closing.solely-drawer--bottom{animation:solely-drawer-bottom-out var(--solely-transition-duration) var(--solely-transition-timing) forwards}.solely-drawer__header{display:flex;align-items:center;justify-content:space-between;padding:var(--solely-spacing-lg) var(--solely-spacing-xl);border-bottom:1px solid var(--solely-border-color-split)}.solely-drawer__title{margin:0;font-size:var(--solely-font-size-lg);font-weight:500;color:var(--solely-text-primary);line-height:var(--solely-line-height-lg)}.solely-drawer__close{width:var(--solely-height-sm);height:var(--solely-height-sm);display:flex;align-items:center;justify-content:center;color:var(--solely-text-tertiary);cursor:pointer;transition:color var(--solely-transition-duration);font-size:var(--solely-font-size-lg);line-height:1;border:none;background:none;border-radius:var(--solely-border-radius-sm)}.solely-drawer__close:hover{color:var(--solely-text-secondary);background-color:var(--solely-gray-3)}.solely-drawer__close:active{color:var(--solely-text-primary)}.solely-drawer__body{flex:1;padding:var(--solely-spacing-xl);overflow:auto;font-size:var(--solely-font-size-md);line-height:var(--solely-line-height-md);color:var(--solely-text-secondary)}@keyframes solely-drawer-mask-in{0%{opacity:0}to{opacity:1}}@keyframes solely-drawer-mask-out{0%{opacity:1}to{opacity:0}}@keyframes solely-drawer-left-in{0%{transform:translate(-100%)}to{transform:translate(0)}}@keyframes solely-drawer-left-out{0%{transform:translate(0)}to{transform:translate(-100%)}}@keyframes solely-drawer-right-in{0%{transform:translate(100%)}to{transform:translate(0)}}@keyframes solely-drawer-right-out{0%{transform:translate(0)}to{transform:translate(100%)}}@keyframes solely-drawer-top-in{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes solely-drawer-top-out{0%{transform:translateY(0)}to{transform:translateY(-100%)}}@keyframes solely-drawer-bottom-in{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes solely-drawer-bottom-out{0%{transform:translateY(0)}to{transform:translateY(100%)}}";export{r as default};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),n={duration:3e3,maxCount:5,gap:8,top:24,bottom:24,left:24,right:24,placement:"top"};let o;const s=new Set,i=[],l={info:"ℹ",success:"✓",warning:"⚠",error:"✕",loading:e.createElement("span",{className:"solely-message__loading-spinner"})},a=new Map;function r(t,n){const o=e.createElement("span",{className:`solely-message__icon solely-message__icon--${n}`});return"string"==typeof t?o.textContent=t:o.appendChild(t.cloneNode(!0)),o}async function c(t){var n;if(!s.has(t)){s.add(t);try{const s=i.findIndex(e=>e.id===t);if(-1===s)return;const r=i[s];r.timer&&(clearTimeout(r.timer),r.timer=void 0),await e.addClosingAnimation(r.element,e.ANIMATION_DURATION.NORMAL),r.element.remove();const c=i.findIndex(e=>e.id===t);-1!==c&&i.splice(c,1);try{null==(n=r.onClose)||n.call(r)}catch(l){console.error("[Solely Message] onClose callback error:",l)}o&&clearTimeout(o),o=window.setTimeout(()=>{0===i.length&&a.forEach((e,t)=>{0===e.element.childElementCount&&(e.element.remove(),e.cleanupTheme(),a.delete(t))}),o=void 0},300)}finally{s.delete(t)}}}function p(o){const s=e.generateId(),p=o.placement||n.placement,d=function(o=n.placement){const s=o;if(a.has(s))return a.get(s).element;const i=e.createElement("div",{className:"solely-message-container"}),l={position:"fixed",display:"flex",flexDirection:"column",gap:`${n.gap}px`,pointerEvents:"none",zIndex:String(e.Z_INDEX.TOAST)};switch(o){case"top":l.top=`${n.top}px`,l.left="50%",l.transform="translateX(-50%)";break;case"topLeft":l.top=`${n.top}px`,l.left=`${n.left}px`,l.alignItems="flex-start";break;case"topRight":l.top=`${n.top}px`,l.right=`${n.right}px`,l.alignItems="flex-end";break;case"bottom":l.bottom=`${n.bottom}px`,l.left="50%",l.transform="translateX(-50%)";break;case"bottomLeft":l.bottom=`${n.bottom}px`,l.left=`${n.left}px`,l.alignItems="flex-start";break;case"bottomRight":l.bottom=`${n.bottom}px`,l.right=`${n.right}px`,l.alignItems="flex-end";break;case"left":l.top="50%",l.left=`${n.left}px`,l.transform="translateY(-50%)",l.alignItems="flex-start";break;case"right":l.top="50%",l.right=`${n.right}px`,l.transform="translateY(-50%)",l.alignItems="flex-end"}Object.assign(i.style,l),document.body.appendChild(i),e.injectStyle("solely-message-styles",t.default);const r=e.observeTheme(()=>i);return a.set(s,{element:i,cleanupTheme:r}),i}(p),m=i.filter(e=>e.placement===p);if(m.length>=n.maxCount){const e=m[0];e&&c(e.id)}const f=function(t,n){const o=t.type||"info",s=!1!==t.showIcon,i=t.cloneElement??!0,a=e.createElement("div",{className:`solely-message solely-message--${o}${t.className?` ${t.className}`:""}`,styles:t.style});if(a.setAttribute("role","error"===o||"warning"===o?"alert":"status"),a.setAttribute("aria-live","error"===o||"warning"===o?"assertive":"polite"),s){const e=t.icon?r(t.icon,o):r(l[o],o);a.appendChild(e)}const p=e.createElement("span",{className:"solely-message__content"}),d=e.createElement("span",{className:"solely-message__text"});if("string"==typeof t.content?d.textContent=t.content:t.content instanceof HTMLElement&&d.appendChild(i?t.content.cloneNode(!0):t.content),p.appendChild(d),t.description){const n=e.createElement("span",{className:"solely-message__description"});"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(i?t.description.cloneNode(!0):t.description),p.appendChild(n)}if(a.appendChild(p),t.closable){const t=e.createElement("button",{className:"solely-message__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}});t.onclick=()=>c(n),a.appendChild(t)}return a}(o,s);d.appendChild(f);const g={id:s,element:f,onClose:o.onClose,placement:p},u=o.duration??n.duration;return u>0&&(g.timer=window.setTimeout(()=>{c(s)},u)),i.push(g),{close:()=>c(s),update:t=>{if("string"==typeof t||t instanceof HTMLElement){const e=f.querySelector(".solely-message__text");return void(e&&(e.innerHTML="","string"==typeof t?e.textContent=t:t instanceof HTMLElement&&e.appendChild(t.cloneNode(!0))))}if(void 0!==t.content){const e=f.querySelector(".solely-message__text");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(t.content.cloneNode(!0)))}if(void 0!==t.description){let n=f.querySelector(".solely-message__description");if(!n&&t.description){n=e.createElement("span",{className:"solely-message__description"}),"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0));const o=f.querySelector(".solely-message__content");null==o||o.appendChild(n)}else n&&(t.description?(n.innerHTML="","string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0))):n.remove())}}}}const d={open:p,info:function(e,t){return p({content:e,type:"info",..."number"==typeof t?{duration:t}:t})},success:function(e,t){return p({content:e,type:"success",..."number"==typeof t?{duration:t}:t})},warning:function(e,t){return p({content:e,type:"warning",..."number"==typeof t?{duration:t}:t})},error:function(e,t){return p({content:e,type:"error",..."number"==typeof t?{duration:t}:t})},loading:function(e,t){return p(void 0===t?{content:e,type:"loading",duration:0,closable:!0}:"number"==typeof t?{content:e,type:"loading",duration:t,closable:!0}:{content:e,type:"loading",duration:0,closable:!0,...t})},config:function(e){Object.assign(n,e),a.forEach((t,n)=>{const o=t.element;void 0!==e.top&&["top","topLeft","topRight"].includes(n)&&(o.style.top=`${e.top}px`),void 0!==e.bottom&&["bottom","bottomLeft","bottomRight"].includes(n)&&(o.style.bottom=`${e.bottom}px`),void 0!==e.left&&["topLeft","bottomLeft","left"].includes(n)&&(o.style.left=`${e.left}px`),void 0!==e.right&&["topRight","bottomRight","right"].includes(n)&&(o.style.right=`${e.right}px`),void 0!==e.gap&&(o.style.gap=`${e.gap}px`)})},destroy:async function(){o&&(clearTimeout(o),o=void 0);const e=[...i];await Promise.all(e.map(e=>c(e.id)))}};exports.Message=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),n={duration:3e3,maxCount:5,gap:8,top:24,bottom:24,left:24,right:24,placement:"top"};let o;const s=new Set,i=[],l={info:"ℹ",success:"✓",warning:"⚠",error:"✕",loading:function(){return e.createElement("span",{className:"solely-message__loading-spinner"})}},a=new Map;async function r(t){if(!s.has(t)){s.add(t);try{const s=i.findIndex(e=>e.id===t);if(-1===s)return;const l=i[s];l.timer&&(clearTimeout(l.timer),l.timer=void 0),await e.addClosingAnimation(l.element,e.ANIMATION_DURATION.NORMAL),l.element.remove();const r=i.findIndex(e=>e.id===t);-1!==r&&i.splice(r,1);try{l.onClose?.()}catch(n){console.error("[Solely Message] onClose callback error:",n)}o&&clearTimeout(o),o=window.setTimeout(()=>{0===i.length&&a.forEach((e,t)=>{0===e.element.childElementCount&&(e.element.remove(),e.cleanupTheme(),a.delete(t))}),o=void 0},300)}finally{s.delete(t)}}}function c(o){const s=e.generateId(),c=o.placement||n.placement,p=function(o=n.placement){const s=o;if(a.has(s))return a.get(s).element;const i=e.createElement("div",{className:"solely-message-container"}),l={position:"fixed",display:"flex",flexDirection:"column",gap:`${n.gap}px`,pointerEvents:"none",zIndex:String(e.Z_INDEX.TOAST)};switch(o){case"top":l.top=`${n.top}px`,l.left="50%",l.transform="translateX(-50%)";break;case"topLeft":l.top=`${n.top}px`,l.left=`${n.left}px`,l.alignItems="flex-start";break;case"topRight":l.top=`${n.top}px`,l.right=`${n.right}px`,l.alignItems="flex-end";break;case"bottom":l.bottom=`${n.bottom}px`,l.left="50%",l.transform="translateX(-50%)";break;case"bottomLeft":l.bottom=`${n.bottom}px`,l.left=`${n.left}px`,l.alignItems="flex-start";break;case"bottomRight":l.bottom=`${n.bottom}px`,l.right=`${n.right}px`,l.alignItems="flex-end";break;case"left":l.top="50%",l.left=`${n.left}px`,l.transform="translateY(-50%)",l.alignItems="flex-start";break;case"right":l.top="50%",l.right=`${n.right}px`,l.transform="translateY(-50%)",l.alignItems="flex-end"}Object.assign(i.style,l),document.body.appendChild(i),e.injectStyle("solely-message-styles",t.default);const r=e.observeTheme(()=>i);return a.set(s,{element:i,cleanupTheme:r}),i}(c),d=i.filter(e=>e.placement===c);if(d.length>=n.maxCount){const e=d[0];e&&r(e.id)}const m=function(t,n){const o=t.type||"info",s=!1!==t.showIcon,i=t.cloneElement??!0,a=e.createElement("div",{className:`solely-message solely-message--${o}${t.className?` ${t.className}`:""}`,styles:t.style});if(a.setAttribute("role","error"===o||"warning"===o?"alert":"status"),a.setAttribute("aria-live","error"===o||"warning"===o?"assertive":"polite"),s){const n=t.icon??l[o],s=function(t,n){const o=e.createElement("span",{className:`solely-message__icon solely-message__icon--${n}`});return"string"==typeof t?o.textContent=t:o.appendChild(t.cloneNode(!0)),o}("function"==typeof n?n():n,o);a.appendChild(s)}const c=e.createElement("span",{className:"solely-message__content"}),p=e.createElement("span",{className:"solely-message__text"});if("string"==typeof t.content?p.textContent=t.content:t.content instanceof HTMLElement&&p.appendChild(i?t.content.cloneNode(!0):t.content),c.appendChild(p),t.description){const n=e.createElement("span",{className:"solely-message__description"});"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(i?t.description.cloneNode(!0):t.description),c.appendChild(n)}if(a.appendChild(c),t.closable){const t=e.createElement("button",{className:"solely-message__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}});t.onclick=()=>r(n),a.appendChild(t)}return a}(o,s);p.appendChild(m);const f={id:s,element:m,onClose:o.onClose,placement:c},u=o.duration??n.duration;return u>0&&(f.timer=window.setTimeout(()=>{r(s)},u)),i.push(f),{close:()=>r(s),update:t=>{if("string"==typeof t||t instanceof HTMLElement){const e=m.querySelector(".solely-message__text");return void(e&&(e.innerHTML="","string"==typeof t?e.textContent=t:t instanceof HTMLElement&&e.appendChild(t.cloneNode(!0))))}if(void 0!==t.content){const e=m.querySelector(".solely-message__text");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(t.content.cloneNode(!0)))}if(void 0!==t.description){let n=m.querySelector(".solely-message__description");if(!n&&t.description){n=e.createElement("span",{className:"solely-message__description"}),"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0));const o=m.querySelector(".solely-message__content");o?.appendChild(n)}else n&&(t.description?(n.innerHTML="","string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0))):n.remove())}}}}const p={open:c,info:function(e,t){return c({content:e,type:"info",..."number"==typeof t?{duration:t}:t})},success:function(e,t){return c({content:e,type:"success",..."number"==typeof t?{duration:t}:t})},warning:function(e,t){return c({content:e,type:"warning",..."number"==typeof t?{duration:t}:t})},error:function(e,t){return c({content:e,type:"error",..."number"==typeof t?{duration:t}:t})},loading:function(e,t){return c(void 0===t?{content:e,type:"loading",duration:0,closable:!0}:"number"==typeof t?{content:e,type:"loading",duration:t,closable:!0}:{content:e,type:"loading",duration:0,closable:!0,...t})},config:function(e){Object.assign(n,e),a.forEach((t,n)=>{const o=t.element;void 0!==e.top&&["top","topLeft","topRight"].includes(n)&&(o.style.top=`${e.top}px`),void 0!==e.bottom&&["bottom","bottomLeft","bottomRight"].includes(n)&&(o.style.bottom=`${e.bottom}px`),void 0!==e.left&&["topLeft","bottomLeft","left"].includes(n)&&(o.style.left=`${e.left}px`),void 0!==e.right&&["topRight","bottomRight","right"].includes(n)&&(o.style.right=`${e.right}px`),void 0!==e.gap&&(o.style.gap=`${e.gap}px`)})},destroy:async function(){o&&(clearTimeout(o),o=void 0);const e=[...i];await Promise.all(e.map(e=>r(e.id)))}};exports.Message=p;
@@ -1 +1 @@
1
- import{createElement as e,addClosingAnimation as t,ANIMATION_DURATION as n,Z_INDEX as o,observeTheme as s,generateId as i,injectStyle as l}from"../utils.js";import a from"./style.css.js";const r={duration:3e3,maxCount:5,gap:8,top:24,bottom:24,left:24,right:24,placement:"top"};let c;const p=new Set,d=[],m={info:"ℹ",success:"✓",warning:"⚠",error:"✕",loading:e("span",{className:"solely-message__loading-spinner"})},f=new Map;function g(t,n){const o=e("span",{className:`solely-message__icon solely-message__icon--${n}`});return"string"==typeof t?o.textContent=t:o.appendChild(t.cloneNode(!0)),o}async function u(e){var o;if(!p.has(e)){p.add(e);try{const i=d.findIndex(t=>t.id===e);if(-1===i)return;const l=d[i];l.timer&&(clearTimeout(l.timer),l.timer=void 0),await t(l.element,n.NORMAL),l.element.remove();const a=d.findIndex(t=>t.id===e);-1!==a&&d.splice(a,1);try{null==(o=l.onClose)||o.call(l)}catch(s){console.error("[Solely Message] onClose callback error:",s)}c&&clearTimeout(c),c=window.setTimeout(()=>{0===d.length&&f.forEach((e,t)=>{0===e.element.childElementCount&&(e.element.remove(),e.cleanupTheme(),f.delete(t))}),c=void 0},300)}finally{p.delete(e)}}}function y(t){const n=i(),c=t.placement||r.placement,p=function(t=r.placement){const n=t;if(f.has(n))return f.get(n).element;const i=e("div",{className:"solely-message-container"}),c={position:"fixed",display:"flex",flexDirection:"column",gap:`${r.gap}px`,pointerEvents:"none",zIndex:String(o.TOAST)};switch(t){case"top":c.top=`${r.top}px`,c.left="50%",c.transform="translateX(-50%)";break;case"topLeft":c.top=`${r.top}px`,c.left=`${r.left}px`,c.alignItems="flex-start";break;case"topRight":c.top=`${r.top}px`,c.right=`${r.right}px`,c.alignItems="flex-end";break;case"bottom":c.bottom=`${r.bottom}px`,c.left="50%",c.transform="translateX(-50%)";break;case"bottomLeft":c.bottom=`${r.bottom}px`,c.left=`${r.left}px`,c.alignItems="flex-start";break;case"bottomRight":c.bottom=`${r.bottom}px`,c.right=`${r.right}px`,c.alignItems="flex-end";break;case"left":c.top="50%",c.left=`${r.left}px`,c.transform="translateY(-50%)",c.alignItems="flex-start";break;case"right":c.top="50%",c.right=`${r.right}px`,c.transform="translateY(-50%)",c.alignItems="flex-end"}Object.assign(i.style,c),document.body.appendChild(i),l("solely-message-styles",a);const p=s(()=>i);return f.set(n,{element:i,cleanupTheme:p}),i}(c),y=d.filter(e=>e.placement===c);if(y.length>=r.maxCount){const e=y[0];e&&u(e.id)}const h=function(t,n){const o=t.type||"info",s=!1!==t.showIcon,i=t.cloneElement??!0,l=e("div",{className:`solely-message solely-message--${o}${t.className?` ${t.className}`:""}`,styles:t.style});if(l.setAttribute("role","error"===o||"warning"===o?"alert":"status"),l.setAttribute("aria-live","error"===o||"warning"===o?"assertive":"polite"),s){const e=t.icon?g(t.icon,o):g(m[o],o);l.appendChild(e)}const a=e("span",{className:"solely-message__content"}),r=e("span",{className:"solely-message__text"});if("string"==typeof t.content?r.textContent=t.content:t.content instanceof HTMLElement&&r.appendChild(i?t.content.cloneNode(!0):t.content),a.appendChild(r),t.description){const n=e("span",{className:"solely-message__description"});"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(i?t.description.cloneNode(!0):t.description),a.appendChild(n)}if(l.appendChild(a),t.closable){const t=e("button",{className:"solely-message__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}});t.onclick=()=>u(n),l.appendChild(t)}return l}(t,n);p.appendChild(h);const x={id:n,element:h,onClose:t.onClose,placement:c},b=t.duration??r.duration;return b>0&&(x.timer=window.setTimeout(()=>{u(n)},b)),d.push(x),{close:()=>u(n),update:t=>{if("string"==typeof t||t instanceof HTMLElement){const e=h.querySelector(".solely-message__text");return void(e&&(e.innerHTML="","string"==typeof t?e.textContent=t:t instanceof HTMLElement&&e.appendChild(t.cloneNode(!0))))}if(void 0!==t.content){const e=h.querySelector(".solely-message__text");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(t.content.cloneNode(!0)))}if(void 0!==t.description){let n=h.querySelector(".solely-message__description");if(!n&&t.description){n=e("span",{className:"solely-message__description"}),"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0));const o=h.querySelector(".solely-message__content");null==o||o.appendChild(n)}else n&&(t.description?(n.innerHTML="","string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0))):n.remove())}}}}const h={open:y,info:function(e,t){return y({content:e,type:"info",..."number"==typeof t?{duration:t}:t})},success:function(e,t){return y({content:e,type:"success",..."number"==typeof t?{duration:t}:t})},warning:function(e,t){return y({content:e,type:"warning",..."number"==typeof t?{duration:t}:t})},error:function(e,t){return y({content:e,type:"error",..."number"==typeof t?{duration:t}:t})},loading:function(e,t){return y(void 0===t?{content:e,type:"loading",duration:0,closable:!0}:"number"==typeof t?{content:e,type:"loading",duration:t,closable:!0}:{content:e,type:"loading",duration:0,closable:!0,...t})},config:function(e){Object.assign(r,e),f.forEach((t,n)=>{const o=t.element;void 0!==e.top&&["top","topLeft","topRight"].includes(n)&&(o.style.top=`${e.top}px`),void 0!==e.bottom&&["bottom","bottomLeft","bottomRight"].includes(n)&&(o.style.bottom=`${e.bottom}px`),void 0!==e.left&&["topLeft","bottomLeft","left"].includes(n)&&(o.style.left=`${e.left}px`),void 0!==e.right&&["topRight","bottomRight","right"].includes(n)&&(o.style.right=`${e.right}px`),void 0!==e.gap&&(o.style.gap=`${e.gap}px`)})},destroy:async function(){c&&(clearTimeout(c),c=void 0);const e=[...d];await Promise.all(e.map(e=>u(e.id)))}};export{h as Message};
1
+ import{createElement as e,addClosingAnimation as t,ANIMATION_DURATION as n,Z_INDEX as o,observeTheme as s,generateId as i,injectStyle as l}from"../utils.js";import a from"./style.css.js";const r={duration:3e3,maxCount:5,gap:8,top:24,bottom:24,left:24,right:24,placement:"top"};let c;const p=new Set,d=[],m={info:"ℹ",success:"✓",warning:"⚠",error:"✕",loading:function(){return e("span",{className:"solely-message__loading-spinner"})}},f=new Map;async function g(e){if(!p.has(e)){p.add(e);try{const s=d.findIndex(t=>t.id===e);if(-1===s)return;const i=d[s];i.timer&&(clearTimeout(i.timer),i.timer=void 0),await t(i.element,n.NORMAL),i.element.remove();const l=d.findIndex(t=>t.id===e);-1!==l&&d.splice(l,1);try{i.onClose?.()}catch(o){console.error("[Solely Message] onClose callback error:",o)}c&&clearTimeout(c),c=window.setTimeout(()=>{0===d.length&&f.forEach((e,t)=>{0===e.element.childElementCount&&(e.element.remove(),e.cleanupTheme(),f.delete(t))}),c=void 0},300)}finally{p.delete(e)}}}function u(t){const n=i(),c=t.placement||r.placement,p=function(t=r.placement){const n=t;if(f.has(n))return f.get(n).element;const i=e("div",{className:"solely-message-container"}),c={position:"fixed",display:"flex",flexDirection:"column",gap:`${r.gap}px`,pointerEvents:"none",zIndex:String(o.TOAST)};switch(t){case"top":c.top=`${r.top}px`,c.left="50%",c.transform="translateX(-50%)";break;case"topLeft":c.top=`${r.top}px`,c.left=`${r.left}px`,c.alignItems="flex-start";break;case"topRight":c.top=`${r.top}px`,c.right=`${r.right}px`,c.alignItems="flex-end";break;case"bottom":c.bottom=`${r.bottom}px`,c.left="50%",c.transform="translateX(-50%)";break;case"bottomLeft":c.bottom=`${r.bottom}px`,c.left=`${r.left}px`,c.alignItems="flex-start";break;case"bottomRight":c.bottom=`${r.bottom}px`,c.right=`${r.right}px`,c.alignItems="flex-end";break;case"left":c.top="50%",c.left=`${r.left}px`,c.transform="translateY(-50%)",c.alignItems="flex-start";break;case"right":c.top="50%",c.right=`${r.right}px`,c.transform="translateY(-50%)",c.alignItems="flex-end"}Object.assign(i.style,c),document.body.appendChild(i),l("solely-message-styles",a);const p=s(()=>i);return f.set(n,{element:i,cleanupTheme:p}),i}(c),u=d.filter(e=>e.placement===c);if(u.length>=r.maxCount){const e=u[0];e&&g(e.id)}const y=function(t,n){const o=t.type||"info",s=!1!==t.showIcon,i=t.cloneElement??!0,l=e("div",{className:`solely-message solely-message--${o}${t.className?` ${t.className}`:""}`,styles:t.style});if(l.setAttribute("role","error"===o||"warning"===o?"alert":"status"),l.setAttribute("aria-live","error"===o||"warning"===o?"assertive":"polite"),s){const n=t.icon??m[o],s=function(t,n){const o=e("span",{className:`solely-message__icon solely-message__icon--${n}`});return"string"==typeof t?o.textContent=t:o.appendChild(t.cloneNode(!0)),o}("function"==typeof n?n():n,o);l.appendChild(s)}const a=e("span",{className:"solely-message__content"}),r=e("span",{className:"solely-message__text"});if("string"==typeof t.content?r.textContent=t.content:t.content instanceof HTMLElement&&r.appendChild(i?t.content.cloneNode(!0):t.content),a.appendChild(r),t.description){const n=e("span",{className:"solely-message__description"});"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(i?t.description.cloneNode(!0):t.description),a.appendChild(n)}if(l.appendChild(a),t.closable){const t=e("button",{className:"solely-message__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}});t.onclick=()=>g(n),l.appendChild(t)}return l}(t,n);p.appendChild(y);const h={id:n,element:y,onClose:t.onClose,placement:c},x=t.duration??r.duration;return x>0&&(h.timer=window.setTimeout(()=>{g(n)},x)),d.push(h),{close:()=>g(n),update:t=>{if("string"==typeof t||t instanceof HTMLElement){const e=y.querySelector(".solely-message__text");return void(e&&(e.innerHTML="","string"==typeof t?e.textContent=t:t instanceof HTMLElement&&e.appendChild(t.cloneNode(!0))))}if(void 0!==t.content){const e=y.querySelector(".solely-message__text");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(t.content.cloneNode(!0)))}if(void 0!==t.description){let n=y.querySelector(".solely-message__description");if(!n&&t.description){n=e("span",{className:"solely-message__description"}),"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0));const o=y.querySelector(".solely-message__content");o?.appendChild(n)}else n&&(t.description?(n.innerHTML="","string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0))):n.remove())}}}}const y={open:u,info:function(e,t){return u({content:e,type:"info",..."number"==typeof t?{duration:t}:t})},success:function(e,t){return u({content:e,type:"success",..."number"==typeof t?{duration:t}:t})},warning:function(e,t){return u({content:e,type:"warning",..."number"==typeof t?{duration:t}:t})},error:function(e,t){return u({content:e,type:"error",..."number"==typeof t?{duration:t}:t})},loading:function(e,t){return u(void 0===t?{content:e,type:"loading",duration:0,closable:!0}:"number"==typeof t?{content:e,type:"loading",duration:t,closable:!0}:{content:e,type:"loading",duration:0,closable:!0,...t})},config:function(e){Object.assign(r,e),f.forEach((t,n)=>{const o=t.element;void 0!==e.top&&["top","topLeft","topRight"].includes(n)&&(o.style.top=`${e.top}px`),void 0!==e.bottom&&["bottom","bottomLeft","bottomRight"].includes(n)&&(o.style.bottom=`${e.bottom}px`),void 0!==e.left&&["topLeft","bottomLeft","left"].includes(n)&&(o.style.left=`${e.left}px`),void 0!==e.right&&["topRight","bottomRight","right"].includes(n)&&(o.style.right=`${e.right}px`),void 0!==e.gap&&(o.style.gap=`${e.gap}px`)})},destroy:async function(){c&&(clearTimeout(c),c=void 0);const e=[...d];await Promise.all(e.map(e=>g(e.id)))}};export{y as Message};