solely 0.7.0 → 0.8.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 (347) hide show
  1. package/README.md +46 -4
  2. package/dist/compiler/index.d.ts +2 -2
  3. package/dist/compiler/ir/buildIR.d.ts +1 -1
  4. package/dist/compiler/ir/index.d.ts +1 -1
  5. package/dist/compiler/parser/index.d.ts +1 -1
  6. package/dist/compiler/parser/parser.d.ts +1 -1
  7. package/dist/components/commands/drawer/index.cjs +1 -1
  8. package/dist/components/commands/drawer/index.d.ts +1 -1
  9. package/dist/components/commands/drawer/index.js +1 -1
  10. package/dist/components/commands/drawer/style.css.cjs +1 -1
  11. package/dist/components/commands/drawer/style.css.js +1 -1
  12. package/dist/components/commands/index.d.ts +12 -12
  13. package/dist/components/commands/message/index.cjs +1 -1
  14. package/dist/components/commands/message/index.d.ts +1 -1
  15. package/dist/components/commands/message/index.js +1 -1
  16. package/dist/components/commands/message/style.css.cjs +1 -1
  17. package/dist/components/commands/message/style.css.js +1 -1
  18. package/dist/components/commands/message/types.d.ts +1 -1
  19. package/dist/components/commands/modal/index.cjs +1 -1
  20. package/dist/components/commands/modal/index.d.ts +1 -1
  21. package/dist/components/commands/modal/index.js +1 -1
  22. package/dist/components/commands/modal/style.css.cjs +1 -1
  23. package/dist/components/commands/modal/style.css.js +1 -1
  24. package/dist/components/commands/modal/types.d.ts +8 -3
  25. package/dist/components/commands/popconfirm/index.cjs +1 -1
  26. package/dist/components/commands/popconfirm/index.d.ts +1 -1
  27. package/dist/components/commands/popconfirm/index.js +1 -1
  28. package/dist/components/commands/popconfirm/style.css.cjs +1 -1
  29. package/dist/components/commands/popconfirm/style.css.js +1 -1
  30. package/dist/components/commands/popconfirm/types.d.ts +10 -3
  31. package/dist/components/commands/tooltip/index.cjs +1 -1
  32. package/dist/components/commands/tooltip/index.d.ts +1 -1
  33. package/dist/components/commands/tooltip/index.js +1 -1
  34. package/dist/components/commands/tooltip/style.css.cjs +1 -1
  35. package/dist/components/commands/tooltip/style.css.js +1 -1
  36. package/dist/components/commands/tooltip/types.d.ts +1 -3
  37. package/dist/components/commands/utils.cjs +1 -1
  38. package/dist/components/commands/utils.d.ts +11 -0
  39. package/dist/components/commands/utils.js +1 -1
  40. package/dist/components/elements/alert/index.cjs +1 -1
  41. package/dist/components/elements/alert/index.d.ts +68 -6
  42. package/dist/components/elements/alert/index.html.cjs +1 -1
  43. package/dist/components/elements/alert/index.html.js +1 -1
  44. package/dist/components/elements/alert/index.js +1 -1
  45. package/dist/components/elements/alert/style.css.cjs +1 -1
  46. package/dist/components/elements/alert/style.css.js +1 -1
  47. package/dist/components/elements/alert/types.d.ts +5 -1
  48. package/dist/components/elements/backtop/index.cjs +1 -1
  49. package/dist/components/elements/backtop/index.d.ts +14 -2
  50. package/dist/components/elements/backtop/index.html.cjs +1 -1
  51. package/dist/components/elements/backtop/index.html.js +1 -1
  52. package/dist/components/elements/backtop/index.js +1 -1
  53. package/dist/components/elements/backtop/style.css.cjs +1 -1
  54. package/dist/components/elements/backtop/style.css.js +1 -1
  55. package/dist/components/elements/badge/index.cjs +1 -1
  56. package/dist/components/elements/badge/index.d.ts +12 -6
  57. package/dist/components/elements/badge/index.html.cjs +1 -1
  58. package/dist/components/elements/badge/index.html.js +1 -1
  59. package/dist/components/elements/badge/index.js +1 -1
  60. package/dist/components/elements/badge/types.d.ts +2 -4
  61. package/dist/components/elements/breadcrumb/index.cjs +1 -1
  62. package/dist/components/elements/breadcrumb/index.d.ts +13 -3
  63. package/dist/components/elements/breadcrumb/index.html.cjs +1 -1
  64. package/dist/components/elements/breadcrumb/index.html.js +1 -1
  65. package/dist/components/elements/breadcrumb/index.js +1 -1
  66. package/dist/components/elements/breadcrumb/style.css.cjs +1 -1
  67. package/dist/components/elements/breadcrumb/style.css.js +1 -1
  68. package/dist/components/elements/breadcrumb/types.d.ts +2 -0
  69. package/dist/components/elements/button/index.cjs +1 -1
  70. package/dist/components/elements/button/index.d.ts +14 -2
  71. package/dist/components/elements/button/index.html.cjs +1 -1
  72. package/dist/components/elements/button/index.html.js +1 -1
  73. package/dist/components/elements/button/index.js +1 -1
  74. package/dist/components/elements/button/style.css.cjs +1 -1
  75. package/dist/components/elements/button/style.css.js +1 -1
  76. package/dist/components/elements/button/types.d.ts +4 -0
  77. package/dist/components/elements/card/index.cjs +1 -1
  78. package/dist/components/elements/card/index.d.ts +22 -2
  79. package/dist/components/elements/card/index.html.cjs +1 -1
  80. package/dist/components/elements/card/index.html.js +1 -1
  81. package/dist/components/elements/card/index.js +1 -1
  82. package/dist/components/elements/card/style.css.cjs +1 -1
  83. package/dist/components/elements/card/style.css.js +1 -1
  84. package/dist/components/elements/card/types.d.ts +4 -2
  85. package/dist/components/elements/checkbox/index.cjs +1 -1
  86. package/dist/components/elements/checkbox/index.d.ts +56 -3
  87. package/dist/components/elements/checkbox/index.html.cjs +1 -1
  88. package/dist/components/elements/checkbox/index.html.js +1 -1
  89. package/dist/components/elements/checkbox/index.js +1 -1
  90. package/dist/components/elements/checkbox/style.css.cjs +1 -1
  91. package/dist/components/elements/checkbox/style.css.js +1 -1
  92. package/dist/components/elements/checkbox/types.d.ts +10 -0
  93. package/dist/components/elements/coordinate-input/index.cjs +1 -1
  94. package/dist/components/elements/coordinate-input/index.d.ts +27 -2
  95. package/dist/components/elements/coordinate-input/index.html.cjs +1 -1
  96. package/dist/components/elements/coordinate-input/index.html.js +1 -1
  97. package/dist/components/elements/coordinate-input/index.js +1 -1
  98. package/dist/components/elements/coordinate-input/style.css.cjs +1 -1
  99. package/dist/components/elements/coordinate-input/style.css.js +1 -1
  100. package/dist/components/elements/coordinate-input/types.d.ts +4 -4
  101. package/dist/components/elements/divider/index.cjs +1 -1
  102. package/dist/components/elements/divider/index.d.ts +11 -2
  103. package/dist/components/elements/divider/index.js +1 -1
  104. package/dist/components/elements/empty/index.cjs +1 -1
  105. package/dist/components/elements/empty/index.d.ts +14 -2
  106. package/dist/components/elements/empty/index.html.cjs +1 -1
  107. package/dist/components/elements/empty/index.html.js +1 -1
  108. package/dist/components/elements/empty/index.js +1 -1
  109. package/dist/components/elements/empty/style.css.cjs +1 -1
  110. package/dist/components/elements/empty/style.css.js +1 -1
  111. package/dist/components/elements/empty/types.d.ts +4 -2
  112. package/dist/components/elements/fab/index.cjs +1 -1
  113. package/dist/components/elements/fab/index.d.ts +12 -3
  114. package/dist/components/elements/fab/index.html.cjs +1 -1
  115. package/dist/components/elements/fab/index.html.js +1 -1
  116. package/dist/components/elements/fab/index.js +1 -1
  117. package/dist/components/elements/fab/style.css.cjs +1 -1
  118. package/dist/components/elements/fab/style.css.js +1 -1
  119. package/dist/components/elements/icon/index.cjs +1 -1
  120. package/dist/components/elements/icon/index.d.ts +23 -2
  121. package/dist/components/elements/icon/index.js +1 -1
  122. package/dist/components/elements/icon/style.css.cjs +1 -1
  123. package/dist/components/elements/icon/style.css.js +1 -1
  124. package/dist/components/elements/index.cjs +1 -1
  125. package/dist/components/elements/index.d.ts +61 -60
  126. package/dist/components/elements/index.js +1 -1
  127. package/dist/components/elements/input/index.cjs +1 -1
  128. package/dist/components/elements/input/index.d.ts +120 -5
  129. package/dist/components/elements/input/index.html.cjs +1 -1
  130. package/dist/components/elements/input/index.html.js +1 -1
  131. package/dist/components/elements/input/index.js +1 -1
  132. package/dist/components/elements/input/style.css.cjs +1 -1
  133. package/dist/components/elements/input/style.css.js +1 -1
  134. package/dist/components/elements/input/types.d.ts +46 -7
  135. package/dist/components/elements/not-found/index.cjs +1 -1
  136. package/dist/components/elements/not-found/index.d.ts +38 -2
  137. package/dist/components/elements/not-found/index.html.cjs +1 -1
  138. package/dist/components/elements/not-found/index.html.js +1 -1
  139. package/dist/components/elements/not-found/index.js +1 -1
  140. package/dist/components/elements/not-found/style.css.cjs +1 -1
  141. package/dist/components/elements/not-found/style.css.js +1 -1
  142. package/dist/components/elements/not-found/types.d.ts +2 -0
  143. package/dist/components/elements/pagination/index.cjs +1 -1
  144. package/dist/components/elements/pagination/index.d.ts +52 -7
  145. package/dist/components/elements/pagination/index.html.cjs +1 -1
  146. package/dist/components/elements/pagination/index.html.js +1 -1
  147. package/dist/components/elements/pagination/index.js +1 -1
  148. package/dist/components/elements/pagination/style.css.cjs +1 -1
  149. package/dist/components/elements/pagination/style.css.js +1 -1
  150. package/dist/components/elements/pagination/types.d.ts +1 -1
  151. package/dist/components/elements/progress/index.cjs +1 -1
  152. package/dist/components/elements/progress/index.d.ts +16 -7
  153. package/dist/components/elements/progress/index.html.cjs +1 -1
  154. package/dist/components/elements/progress/index.html.js +1 -1
  155. package/dist/components/elements/progress/index.js +1 -1
  156. package/dist/components/elements/progress/style.css.cjs +1 -1
  157. package/dist/components/elements/progress/style.css.js +1 -1
  158. package/dist/components/elements/progress/types.d.ts +4 -2
  159. package/dist/components/elements/radio/index.cjs +1 -1
  160. package/dist/components/elements/radio/index.d.ts +82 -3
  161. package/dist/components/elements/radio/index.html.cjs +1 -1
  162. package/dist/components/elements/radio/index.html.js +1 -1
  163. package/dist/components/elements/radio/index.js +1 -1
  164. package/dist/components/elements/radio/style.css.cjs +1 -1
  165. package/dist/components/elements/radio/style.css.js +1 -1
  166. package/dist/components/elements/radio/types.d.ts +6 -0
  167. package/dist/components/elements/rate/index.cjs +1 -1
  168. package/dist/components/elements/rate/index.d.ts +75 -3
  169. package/dist/components/elements/rate/index.html.cjs +1 -1
  170. package/dist/components/elements/rate/index.html.js +1 -1
  171. package/dist/components/elements/rate/index.js +1 -1
  172. package/dist/components/elements/rate/style.css.cjs +1 -1
  173. package/dist/components/elements/rate/style.css.js +1 -1
  174. package/dist/components/elements/rate/types.d.ts +2 -0
  175. package/dist/components/elements/select/index.cjs +1 -1
  176. package/dist/components/elements/select/index.d.ts +197 -22
  177. package/dist/components/elements/select/index.html.cjs +1 -1
  178. package/dist/components/elements/select/index.html.js +1 -1
  179. package/dist/components/elements/select/index.js +1 -1
  180. package/dist/components/elements/select/option.cjs +1 -0
  181. package/dist/components/elements/select/option.d.ts +2 -2
  182. package/dist/components/elements/select/option.js +1 -0
  183. package/dist/components/elements/select/style.css.cjs +1 -1
  184. package/dist/components/elements/select/style.css.js +1 -1
  185. package/dist/components/elements/select/types.d.ts +42 -6
  186. package/dist/components/elements/skeleton/index.cjs +1 -1
  187. package/dist/components/elements/skeleton/index.d.ts +15 -2
  188. package/dist/components/elements/skeleton/index.html.cjs +1 -1
  189. package/dist/components/elements/skeleton/index.html.js +1 -1
  190. package/dist/components/elements/skeleton/index.js +1 -1
  191. package/dist/components/elements/skeleton/style.css.cjs +1 -1
  192. package/dist/components/elements/skeleton/style.css.js +1 -1
  193. package/dist/components/elements/skeleton/types.d.ts +2 -1
  194. package/dist/components/elements/slider/index.cjs +1 -1
  195. package/dist/components/elements/slider/index.d.ts +115 -11
  196. package/dist/components/elements/slider/index.html.cjs +1 -1
  197. package/dist/components/elements/slider/index.html.js +1 -1
  198. package/dist/components/elements/slider/index.js +1 -1
  199. package/dist/components/elements/slider/style.css.cjs +1 -1
  200. package/dist/components/elements/slider/style.css.js +1 -1
  201. package/dist/components/elements/slider/types.d.ts +15 -4
  202. package/dist/components/elements/steps/index.cjs +1 -1
  203. package/dist/components/elements/steps/index.d.ts +73 -10
  204. package/dist/components/elements/steps/index.html.cjs +1 -1
  205. package/dist/components/elements/steps/index.html.js +1 -1
  206. package/dist/components/elements/steps/index.js +1 -1
  207. package/dist/components/elements/steps/style.css.cjs +1 -1
  208. package/dist/components/elements/steps/style.css.js +1 -1
  209. package/dist/components/elements/steps/types.d.ts +9 -2
  210. package/dist/components/elements/switch/index.cjs +1 -1
  211. package/dist/components/elements/switch/index.d.ts +52 -9
  212. package/dist/components/elements/switch/index.html.cjs +1 -1
  213. package/dist/components/elements/switch/index.html.js +1 -1
  214. package/dist/components/elements/switch/index.js +1 -1
  215. package/dist/components/elements/switch/types.d.ts +12 -0
  216. package/dist/components/elements/table/index.cjs +1 -1
  217. package/dist/components/elements/table/index.d.ts +251 -4
  218. package/dist/components/elements/table/index.html.cjs +1 -1
  219. package/dist/components/elements/table/index.html.js +1 -1
  220. package/dist/components/elements/table/index.js +1 -1
  221. package/dist/components/elements/table/style.css.cjs +1 -1
  222. package/dist/components/elements/table/style.css.js +1 -1
  223. package/dist/components/elements/table/types.d.ts +152 -7
  224. package/dist/components/elements/tabs/index.cjs +1 -1
  225. package/dist/components/elements/tabs/index.d.ts +47 -4
  226. package/dist/components/elements/tabs/index.html.cjs +1 -1
  227. package/dist/components/elements/tabs/index.html.js +1 -1
  228. package/dist/components/elements/tabs/index.js +1 -1
  229. package/dist/components/elements/tabs/style.css.cjs +1 -1
  230. package/dist/components/elements/tabs/style.css.js +1 -1
  231. package/dist/components/elements/tabs/types.d.ts +10 -0
  232. package/dist/components/elements/tag/index.cjs +1 -1
  233. package/dist/components/elements/tag/index.d.ts +11 -3
  234. package/dist/components/elements/tag/index.html.cjs +1 -1
  235. package/dist/components/elements/tag/index.html.js +1 -1
  236. package/dist/components/elements/tag/index.js +1 -1
  237. package/dist/components/elements/tag/style.css.cjs +1 -1
  238. package/dist/components/elements/tag/style.css.js +1 -1
  239. package/dist/components/elements/timeline/index.cjs +1 -1
  240. package/dist/components/elements/timeline/index.d.ts +8 -2
  241. package/dist/components/elements/timeline/index.js +1 -1
  242. package/dist/components/elements/timeline/style.css.cjs +1 -1
  243. package/dist/components/elements/timeline/style.css.js +1 -1
  244. package/dist/components/elements/timeline/types.d.ts +0 -1
  245. package/dist/components/elements/tooltip/index.cjs +1 -1
  246. package/dist/components/elements/tooltip/index.d.ts +78 -5
  247. package/dist/components/elements/tooltip/index.html.cjs +1 -1
  248. package/dist/components/elements/tooltip/index.html.js +1 -1
  249. package/dist/components/elements/tooltip/index.js +1 -1
  250. package/dist/components/elements/tooltip/style.css.cjs +1 -1
  251. package/dist/components/elements/tooltip/style.css.js +1 -1
  252. package/dist/components/elements/tooltip/types.d.ts +1 -1
  253. package/dist/components/elements/tree/index.cjs +1 -1
  254. package/dist/components/elements/tree/index.d.ts +163 -13
  255. package/dist/components/elements/tree/index.html.cjs +1 -1
  256. package/dist/components/elements/tree/index.html.js +1 -1
  257. package/dist/components/elements/tree/index.js +1 -1
  258. package/dist/components/elements/tree/style.css.cjs +1 -1
  259. package/dist/components/elements/tree/style.css.js +1 -1
  260. package/dist/components/elements/tree/types.d.ts +18 -4
  261. package/dist/components/elements/upload/index.cjs +1 -1
  262. package/dist/components/elements/upload/index.d.ts +59 -8
  263. package/dist/components/elements/upload/index.html.cjs +1 -1
  264. package/dist/components/elements/upload/index.html.js +1 -1
  265. package/dist/components/elements/upload/index.js +1 -1
  266. package/dist/components/elements/upload/style.css.cjs +1 -1
  267. package/dist/components/elements/upload/style.css.js +1 -1
  268. package/dist/components/elements/upload/types.d.ts +89 -5
  269. package/dist/components/elements/utils/helpers.cjs +1 -1
  270. package/dist/components/elements/utils/helpers.d.ts +10 -0
  271. package/dist/components/elements/utils/helpers.js +1 -1
  272. package/dist/components/index.cjs +1 -1
  273. package/dist/components/index.d.ts +3 -21
  274. package/dist/components/index.js +1 -1
  275. package/dist/components/theme/auto-inject.cjs +1 -0
  276. package/dist/components/theme/auto-inject.d.ts +23 -0
  277. package/dist/components/theme/auto-inject.js +1 -0
  278. package/dist/components/theme/index.cjs +1 -1
  279. package/dist/components/theme/index.d.ts +7 -1
  280. package/dist/components/theme/index.js +1 -1
  281. package/dist/components/theme/variables.css +25 -0
  282. package/dist/components/theme/variables.css.cjs +1 -0
  283. package/dist/components/theme/variables.css.js +1 -0
  284. package/dist/index.cjs +1 -1
  285. package/dist/index.d.ts +5 -5
  286. package/dist/index.js +1 -1
  287. package/dist/plugin.d.ts +2 -2
  288. package/dist/plugins/index.d.ts +2 -2
  289. package/dist/plugins/solely-vite-plugin.d.ts +1 -1
  290. package/dist/router/core.cjs +1 -1
  291. package/dist/router/core.d.ts +31 -1
  292. package/dist/router/core.js +1 -1
  293. package/dist/router/index.d.ts +4 -4
  294. package/dist/router/router-link.d.ts +1 -1
  295. package/dist/router/router-view.cjs +1 -1
  296. package/dist/router/router-view.d.ts +12 -2
  297. package/dist/router/router-view.js +1 -1
  298. package/dist/router/types.d.ts +3 -1
  299. package/dist/runtime/component/base-element.cjs +1 -1
  300. package/dist/runtime/component/base-element.d.ts +7 -0
  301. package/dist/runtime/component/base-element.js +1 -1
  302. package/dist/runtime/component/decorators.d.ts +7 -2
  303. package/dist/runtime/component/index.d.ts +2 -2
  304. package/dist/runtime/index.d.ts +3 -3
  305. package/dist/runtime/reactivity/computed.d.ts +1 -1
  306. package/dist/runtime/reactivity/index.d.ts +6 -6
  307. package/dist/runtime/reactivity/watch.d.ts +1 -1
  308. package/dist/runtime/renderer/index.d.ts +2 -2
  309. package/dist/runtime/renderer/renderIR.cjs +1 -1
  310. package/dist/runtime/renderer/renderIR.d.ts +1 -1
  311. package/dist/runtime/renderer/renderIR.js +1 -1
  312. package/dist/shared/aria.cjs +1 -0
  313. package/dist/shared/aria.d.ts +67 -0
  314. package/dist/shared/aria.js +1 -0
  315. package/dist/shared/boolean.cjs +1 -0
  316. package/dist/shared/boolean.d.ts +9 -0
  317. package/dist/shared/boolean.js +1 -0
  318. package/dist/shared/enum.cjs +1 -0
  319. package/dist/shared/enum.d.ts +10 -0
  320. package/dist/shared/enum.js +1 -0
  321. package/dist/shared/env.cjs +1 -1
  322. package/dist/shared/env.js +1 -1
  323. package/dist/shared/floating/overlay-stack.cjs +1 -0
  324. package/dist/shared/floating/overlay-stack.d.ts +56 -0
  325. package/dist/shared/floating/overlay-stack.js +1 -0
  326. package/dist/shared/floating/position.cjs +1 -0
  327. package/dist/shared/floating/position.d.ts +32 -0
  328. package/dist/shared/floating/position.js +1 -0
  329. package/dist/shared/floating/types.d.ts +112 -0
  330. package/dist/shared/form-associated.cjs +1 -0
  331. package/dist/shared/form-associated.d.ts +253 -0
  332. package/dist/shared/form-associated.js +1 -0
  333. package/dist/shared/gen-function.d.ts +1 -1
  334. package/dist/shared/icons.cjs +1 -0
  335. package/dist/shared/icons.d.ts +31 -0
  336. package/dist/shared/icons.js +1 -0
  337. package/dist/shared/index.cjs +1 -1
  338. package/dist/shared/index.d.ts +11 -9
  339. package/dist/shared/index.js +1 -1
  340. package/dist/shared/size.cjs +1 -0
  341. package/dist/shared/size.d.ts +17 -0
  342. package/dist/shared/size.js +1 -0
  343. package/dist/shared/templateError.d.ts +1 -1
  344. package/dist/types/index.d.ts +4 -4
  345. package/dist/types/ir.d.ts +1 -1
  346. package/package.json +27 -11
  347. package/dist/solely.svg +0 -1
@@ -1 +1 @@
1
- import{isObject as t}from"../../shared/is-object.js";import{IS_DEV as e,SOLELY_VERSION as s}from"../../shared/env.js";import{camelToKebab as i}from"../../shared/case-convert.js";import{observe as r}from"../reactivity/observe.js";import{createRender as a}from"../renderer/renderIR.js";const o=Symbol.for("solely.manifest"),n="undefined"!=typeof HTMLElement?HTMLElement:class{};function d(t){if(null===t||"object"!=typeof t)return t;const e=globalThis.structuredClone;if("function"==typeof e)try{return e(t)}catch{}try{return JSON.parse(JSON.stringify(t))}catch{return t}}class h extends n{$refs={};#t;#e;#s;#i;#r;#a;#o=!1;#n=!1;#d=!1;#h=!1;#c=!1;#l=!1;#u=!1;#p=new Set;#f=!1;#m=!1;static#b=new Map;static#y=new WeakSet;#g=new Map;static#v=new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]);static get observedAttributes(){const t=this[o];return t?.attributeMap?Array.from(t.attributeMap.keys()):[]}constructor(t={}){super();const e=this.constructor;this.#t=e[o]||{tagName:"base-element"};const s=this.#t;this.#r=s.shadowDOM?.use?this.attachShadow({mode:s.shadowDOM.mode||"open"}):this,this.#A(t),this.#S(s),queueMicrotask(()=>this.#O())}#C(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=h.#v,i=new Map;let r=Object.getPrototypeOf(this);for(;r&&r!==n.prototype;){const t=Object.getOwnPropertyDescriptors(r);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);r=Object.getPrototypeOf(r)}for(const a of t){if(s.has(a))continue;if(e.some(t=>a.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,a);if(!t||!("value"in t))continue;const r=t.value,o=i.get(a);o?.set&&(delete this[a],this[a]=r)}}#A(t){e&&t&&"object"==typeof t&&(h.#y.has(t)&&console.warn(`[Solely] <${this.#t.tagName}>: 该初始数据对象已被其他实例使用,$data 会共享同一响应式代理(改一个实例会同时触发另一个实例刷新)。如需实例隔离,请为每个实例传入新对象。`),h.#y.add(t));const{proxy:s,dispose:i}=r(t,t=>{if("set"===t.type||"array-replace"===t.type){const{key:e,newValue:s}=t,i=this.#t,r=String(e),a=i.propMap?.get(r);a?.reflect&&this.#w(a,s)}!1!==this.#t.dataChangeEvent&&this.emit("dataChange",{...t}),this.#R()});this.#i=s,this.#a=i}#w(t,e){const s=i(t.name);this.#p.add(s);try{if(null==e)return void this.removeAttribute(s);if("boolean"===t.type)e?this.setAttribute(s,""):this.removeAttribute(s);else{const t="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,t)}}finally{this.#p.delete(s)}}#S(t){t.ir&&(this.#s=t.ir)}#$(t){const e=this.#g.get(t);if(void 0!==e)return e;let s=null,i=Object.getPrototypeOf(this);for(;i&&i!==n.prototype;){const e=Object.getOwnPropertyDescriptor(i,t);if(e){s=e.get||e.set?e:null;break}i=Object.getPrototypeOf(i)}return this.#g.set(t,s),s}#j(t,e){const s=this.#$(t.name);s?.set?this[t.name]=e:this.$data[t.name]=e}#P(){const t=this.#t;if(t.attributeMap)for(const[,e]of t.attributeMap)if(!1!==e.reactive&&!this.#$(e.name)){const t=Object.getOwnPropertyDescriptor(this,e.name);t&&"value"in t&&(this.$data[e.name]=t.value,delete this[e.name]),Object.defineProperty(this,e.name,{get:()=>this.$data[e.name],set:t=>{this.$data[e.name]=t},configurable:!0,enumerable:!0})}}#N(){this.#u||(this.#u=!0,this.#P())}get $data(){return this.#i}set $data(e){t(e)||(e={}),e!==this.#i&&(this.#a?.(),this.#A(e),this.#N(),this.#R())}#M(t,e,s){if(null===t)return"boolean"!==s&&e;switch(s){case"boolean":return!0;case"number":{const s=Number(t);return isNaN(s)?e:s}case"object":try{return JSON.parse(t)}catch(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=JSON.parse(t);return Array.isArray(s)?s:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}}#R(){this.#f||(this.#c?!this.#n&&this.#e&&(this.#n=!0,queueMicrotask(()=>{this.#f||(this.#n=!1,this.#U())})):this.#l=!0)}#U(){if(!this.#f&&!this.#o&&this.#c){this.#o=!0;try{this.#d&&this.beforeAttributesUpdate(),this.beforeUpdate(),this.#e?.update(),this.updated(),this.#d&&(this.afterAttributesUpdate(),this.#d=!1)}finally{this.#o=!1}}}refresh(){this.#R()}#D(){const t=this.#t;if(!t.styles)return;const e=this.#r;if(t.sheet&&e instanceof ShadowRoot&&"adoptedStyleSheets"in e){if(!e.adoptedStyleSheets.includes(t.sheet)){const s=Array.from(e.adoptedStyleSheets);s.push(t.sheet),e.adoptedStyleSheets=s}return void(this.#m=!0)}const i=e instanceof ShadowRoot?e:document.head,r=`solely-style-${s}-${t.tagName}`,a=!t.shadowDOM?.use,o="undefined"!=typeof CSS&&CSS.escape?CSS.escape(r):r.replace(/([.#:[\]()!])/g,"\\$1");if(!i.querySelector(`#${o}`)){const e=document.createElement("style");e.id=r,e.textContent=t.styles,i.appendChild(e)}if(a){const t=h.#b.get(r)||0;h.#b.set(r,t+1),this.#m=!0}}#k(){if(!this.#m)return;this.#m=!1;const t=this.#t;if(!t.shadowDOM?.use&&t.styles){const e=`solely-style-${s}-${t.tagName}`,i=h.#b.get(e)||0;if(i<=1){const t="undefined"!=typeof CSS&&CSS.escape?CSS.escape(e):e.replace(/([.#:[\]()!])/g,"\\$1");document.head.querySelector(`#${t}`)?.remove(),h.#b.delete(e)}else h.#b.set(e,i-1)}}connectedCallback(){if(this.#f)return e&&console.error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`),void this.remove();this.#c=!0;const s=this.#t;if(this.#O(),(s.className||s.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),this.#D(),s.attributeMap&&t(this.$data)){this.#N();for(const[t,e]of s.attributeMap){const s=e.name;if(this.hasAttribute(t)){const s=this.getAttribute(t),i=this.#M(s,d(e.default),e.type);this.#j(e,i)}else"default"in e&&void 0===this.$data[s]&&(this.#j(e,d(e.default)),"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}this.#C(),this.#s&&!this.#e&&(this.#e=a(this.#s,this.#r,this)),this.#l&&(this.#l=!1,this.#R()),this.mounted()}disconnectedCallback(){this.#c=!1,this.#f||this.#k(),this.unmounted()}attributeChangedCallback(e,s,i){if(this.#f||s===i||!t(this.$data))return;if(this.#p.has(e))return;const r=this.#t,a=r.attributeMap?.get(e);if(!a)return;const o=a.name,n=this.$data[o],h=void 0!==a.default?d(a.default):n,c=this.#M(i,h,a.type);n!==c&&(this.#d=!0,this.#j(a,c),this.$data[o]===n&&(this.#d=!1),this.attributeChanged(e,n,c))}#O(){this.#h||(this.#h=!0,this.created())}emit(t,e,s){this.#f||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){this.#f||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,s){if(e&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${s}`)}}error(t,s){if(e&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${s}`)}}dispose(){this.#f||(this.#f=!0,this.#c=!1,this.#k(),this.#e?.destroy(),this.#e=void 0,this.#a?.(),this.#a=void 0,this.remove())}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}}export{h as default};
1
+ import{isObject as t}from"../../shared/is-object.js";import{IS_DEV as e,SOLELY_VERSION as s}from"../../shared/env.js";import{camelToKebab as i}from"../../shared/case-convert.js";import{parseBooleanAttribute as r}from"../../shared/boolean.js";import{observe as a}from"../reactivity/observe.js";import{createRender as o}from"../renderer/renderIR.js";const n=Symbol.for("solely.manifest"),h="undefined"!=typeof HTMLElement?HTMLElement:class{};function c(t,e){return function(t){if(null===t||"object"!=typeof t)return t;const e=globalThis.structuredClone;if("function"==typeof e)try{return e(t)}catch{}try{return JSON.parse(JSON.stringify(t))}catch{return t}}("function"==typeof t?t(e):t)}const d=new Set(["value","checked"]);function l(s,i){if(null==i)return i;switch(s.type){case"number":if("string"==typeof i){if(""===i.trim())return i;const t=Number(i);return Number.isNaN(t)?(e&&console.warn(`[Solely] number prop 收到非法字符串 "${i}",已保留原值。`),i):t}return i;case"boolean":if("string"==typeof i){const t=i.trim().toLowerCase();return"false"!==t&&"0"!==t}return Boolean(i);case"array":if("string"==typeof i)try{const t=JSON.parse(i);if(Array.isArray(t))return t}catch{}return i;case"object":if("string"==typeof i)try{const e=JSON.parse(i);if(t(e))return e}catch{}return i;case"string":return"number"==typeof i||"boolean"==typeof i?String(i):i;default:return i}}class u extends h{$refs={};#t;#e;#s;#i;#r;#a;#o=!1;#n=!1;#h=!1;#c=0;#d=!1;#l=!1;#u=!1;#p=!1;#f=!1;#y=new Set;#b=0;#m=!1;#g=!1;static#A=new Map;static#S=new WeakSet;#v=new Map;static#C=new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]);static get observedAttributes(){const t=this[n];return t?.attributeMap?Array.from(t.attributeMap.keys()):[]}constructor(t={}){super();const e=this.constructor;this.#t=e[n]||{tagName:"base-element"};const s=this.#t;this.#r=s.shadowDOM?.use?this.attachShadow({mode:s.shadowDOM.mode||"open"}):this,this.#O(t),this.#w(s),queueMicrotask(()=>this.#$())}#j(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=u.#C,i=new Map;let r=Object.getPrototypeOf(this);for(;r&&r!==h.prototype;){const t=Object.getOwnPropertyDescriptors(r);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);r=Object.getPrototypeOf(r)}for(const a of t){if(s.has(a))continue;if(e.some(t=>a.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,a);if(!t||!("value"in t))continue;const r=t.value,o=i.get(a);if(o?.set){delete this[a],this.#c++;try{const t=this.#t.propMap?.get(a);this[a]=t?l(t,r):r}finally{this.#c--}}}}#O(t){e&&t&&"object"==typeof t&&(u.#S.has(t)&&console.warn(`[Solely] <${this.#t.tagName}>: 该初始数据对象已被其他实例使用,$data 会共享同一响应式代理(改一个实例会同时触发另一个实例刷新)。如需实例隔离,请为每个实例传入新对象。`),u.#S.add(t));const{proxy:s,dispose:i}=a(t,t=>{const e=t.path,s=!Array.isArray(e)||e.length<=1;if(("set"===t.type||"array-replace"===t.type)&&s){const{key:e,newValue:s}=t,i=this.#t,r=String(e),a=i.propMap?.get(r);a&&(!0===a.reflect?this.#R(a,s):0===this.#c&&0===this.#b&&this.#D(a)&&this.#N(a,s))}!1!==this.#t.dataChangeEvent&&this.emit("dataChange",{...t}),this.#P()});this.#i=s,this.#a=i}#R(t,e){const s=i(t.name);this.#y.add(s);try{if(null==e)return void this.removeAttribute(s);if("boolean"===t.type)e?this.setAttribute(s,""):this.removeAttribute(s);else{const t="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,t)}}finally{this.#y.delete(s)}}#D(t){return!1!==t.reflect&&"object"!==t.type&&"array"!==t.type&&!d.has(t.name)}#N(t,e){const s=i(t.name);if(!this.#y.has(s)){this.#y.add(s);try{if(null==e)return void(this.hasAttribute(s)&&this.removeAttribute(s));if("boolean"===t.type)return void(e?this.setAttribute(s,""):this.removeAttribute(s));const i="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,i)}finally{this.#y.delete(s)}}}#w(t){t.ir&&(this.#s=t.ir)}#M(t){const e=this.#v.get(t);if(void 0!==e)return e;let s=null,i=Object.getPrototypeOf(this);for(;i&&i!==h.prototype;){const e=Object.getOwnPropertyDescriptor(i,t);if(e){s=e.get||e.set?e:null;break}i=Object.getPrototypeOf(i)}return this.#v.set(t,s),s}#U(t,e){const s=l(t,e);this.#c++;try{const e=this.#M(t.name);e?.set?this[t.name]=s:this.$data[t.name]=s}finally{this.#c--}}get isSyncingProps(){return this.#c>0}#k(){const t=this.#t;if(t.attributeMap)for(const[,e]of t.attributeMap){if(!1===e.reactive)continue;const t=Object.getOwnPropertyDescriptor(this,e.name);if(t&&"value"in t){const s=l(e,t.value);if(delete this[e.name],this.#M(e.name)?.set){this.#c++;try{this.$data[e.name]=s}finally{this.#c--}this.#U(e,s)}else this.$data[e.name]=s}this.#M(e.name)||Object.defineProperty(this,e.name,{get:()=>this.$data[e.name],set:t=>{this.$data[e.name]=l(e,t)},configurable:!0,enumerable:!0})}}#E(){this.#p||(this.#p=!0,this.#k())}get $data(){return this.#i}set $data(e){t(e)||(e={}),e!==this.#i&&(this.#a?.(),this.#O(e),this.#E(),this.#P())}#T(t,e,s,i){if(null===t)return"boolean"===s?r(null,"boolean"==typeof e&&e):e;switch(s){case"boolean":return r(t);case"number":{const s=Number(t);return isNaN(s)?(this.warn(!0,`attribute ${i??""}="${t}" 不是合法数字,已回落到默认值 / 保留原值。`),e):s}case"object":try{return JSON.parse(t)}catch(a){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,a),e}case"array":try{const s=JSON.parse(t);return Array.isArray(s)?s:e}catch(a){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,a),e}default:return t}}#P(){this.#m||(this.#l?!this.#n&&this.#e&&(this.#n=!0,queueMicrotask(()=>{this.#m||(this.#n=!1,this.#J())})):this.#u=!0)}#J(){if(!this.#m&&!this.#o&&this.#l){this.#o=!0;try{this.#h&&this.beforeAttributesUpdate(),this.beforeUpdate(),this.#e?.update(),this.updated(),this.#h&&(this.afterAttributesUpdate(),this.#h=!1)}finally{this.#o=!1}}}refresh(){this.#P()}#L(){const t=this.#t;if(!t.styles)return;const e=this.#r;if(t.sheet&&e instanceof ShadowRoot&&"adoptedStyleSheets"in e){if(!e.adoptedStyleSheets.includes(t.sheet)){const s=Array.from(e.adoptedStyleSheets);s.push(t.sheet),e.adoptedStyleSheets=s}return void(this.#g=!0)}const i=e instanceof ShadowRoot?e:document.head,r=`solely-style-${s}-${t.tagName}`,a=!t.shadowDOM?.use,o="undefined"!=typeof CSS&&CSS.escape?CSS.escape(r):r.replace(/([.#:[\]()!])/g,"\\$1");if(!i.querySelector(`#${o}`)){const e=document.createElement("style");e.id=r,e.textContent=t.styles,i.appendChild(e)}if(a){const t=u.#A.get(r)||0;u.#A.set(r,t+1),this.#g=!0}}#H(){if(!this.#g)return;this.#g=!1;const t=this.#t;if(!t.shadowDOM?.use&&t.styles){const e=`solely-style-${s}-${t.tagName}`,i=u.#A.get(e)||0;if(i<=1){const t="undefined"!=typeof CSS&&CSS.escape?CSS.escape(e):e.replace(/([.#:[\]()!])/g,"\\$1");document.head.querySelector(`#${t}`)?.remove(),u.#A.delete(e)}else u.#A.set(e,i-1)}}connectedCallback(){if(this.#m)return e&&console.error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`),void this.remove();this.#l=!0;const s=this.#t;if(this.#$(),(s.className||s.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),this.#L(),s.attributeMap&&t(this.$data)&&(this.#E(),!this.#f))for(const[t,e]of s.attributeMap){const s=e.name;if(this.hasAttribute(t)){const s=this.getAttribute(t),i=this.#T(s,c(e.default,this),e.type,t);this.#U(e,i)}else"default"in e&&void 0===this.$data[s]&&(this.#U(e,c(e.default,this)),"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}this.#j(),this.#s&&!this.#e&&(this.#e=o(this.#s,this.#r,this)),this.#u&&(this.#u=!1,this.#P()),this.#f=!0,this.mounted()}disconnectedCallback(){this.#l=!1,this.#m||this.#H(),this.unmounted()}attributeChangedCallback(e,s,i){if(this.#m||s===i||!t(this.$data))return;if(this.#y.has(e))return;const r=this.#t,a=r.attributeMap?.get(e);if(!a)return;const o=a.name,n=this.$data[o],h=void 0!==a.default,d=h?c(a.default,this):void 0;let l;l=null===i?h?d:"boolean"!==a.type&&void 0:h?d:n;const u=this.#T(i,l,a.type,e);if(n!==u){this.#h=!0,this.#U(a,u),this.$data[o]===n&&(this.#h=!1),this.#b++;try{this.attributeChanged(e,n,u)}finally{this.#b--}}}#$(){this.#d||(this.#d=!0,this.created())}emit(t,e,s){this.#m||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){this.#m||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,s){if(e&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${s}`)}}error(t,s){if(e&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${s}`)}}dispose(){this.#m||(this.#m=!0,this.#l=!1,this.#H(),this.#e?.destroy(),this.#e=void 0,this.#a?.(),this.#a=void 0,this.remove())}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}}export{u as default};
@@ -1,4 +1,4 @@
1
- import { IRRoot } from '../../types';
1
+ import { IRRoot } from '../../types/index.js';
2
2
  /** Prop 配置,支持类型声明 */
3
3
  export type PropType = 'string' | 'number' | 'boolean' | 'object' | 'array';
4
4
  /** 属性描述符 */
@@ -7,7 +7,12 @@ export interface PropDescriptor {
7
7
  name: string;
8
8
  /** 输入转换类型 */
9
9
  type?: PropType;
10
- /** 渲染兜底值(非状态) */
10
+ /**
11
+ * 渲染兜底值(非状态)
12
+ *
13
+ * 传函数时视为工厂:在挂载 / attribute 移除回退时以当前元素实例为参数求值,
14
+ * 用于语言环境或依赖其它 prop 的动态默认值。
15
+ */
11
16
  default?: unknown;
12
17
  /** 是否同步回 HTML Attribute */
13
18
  reflect?: boolean;
@@ -1,2 +1,2 @@
1
- export { default as BaseElement } from './base-element';
2
- export * from './decorators';
1
+ export { default as BaseElement } from './base-element.js';
2
+ export * from './decorators.js';
@@ -1,3 +1,3 @@
1
- export * from './reactivity';
2
- export * from './component';
3
- export * from './renderer';
1
+ export * from './reactivity/index.js';
2
+ export * from './component/index.js';
3
+ export * from './renderer/index.js';
@@ -1,4 +1,4 @@
1
- import { ReactiveSource } from './observe';
1
+ import { ReactiveSource } from './observe.js';
2
2
  /** computed 选项 */
3
3
  export interface ComputedOptions {
4
4
  /** 是否启用深度比较,默认 false */
@@ -1,6 +1,6 @@
1
- export { observe, toRaw, isProxy, toProxy } from './observe';
2
- export type { ChangeItem, ObserveOptions, ObserveReturn, PathKey, ChangePayload, ReactiveSource } from './observe';
3
- export { computed } from './computed';
4
- export type { ComputedOptions, ComputedReturn } from './computed';
5
- export { watch, watchGetter } from './watch';
6
- export type { WatchOptions, WatchReturn } from './watch';
1
+ export { observe, toRaw, isProxy, toProxy } from './observe.js';
2
+ export type { ChangeItem, ObserveOptions, ObserveReturn, PathKey, ChangePayload, ReactiveSource } from './observe.js';
3
+ export { computed } from './computed.js';
4
+ export type { ComputedOptions, ComputedReturn } from './computed.js';
5
+ export { watch, watchGetter } from './watch.js';
6
+ export type { WatchOptions, WatchReturn } from './watch.js';
@@ -1,4 +1,4 @@
1
- import { ChangeItem, ReactiveSource } from './observe';
1
+ import { ChangeItem, ReactiveSource } from './observe.js';
2
2
  /** watch 选项 */
3
3
  export interface WatchOptions {
4
4
  /** 是否启用深度比较,默认 false */
@@ -1,2 +1,2 @@
1
- export * from './renderIR';
2
- export { default as htmlDecode } from './html-decode';
1
+ export * from './renderIR.js';
2
+ export { default as htmlDecode } from './html-decode.js';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../types/ast.cjs"),t=require("../../shared/templateError.cjs"),s=require("../../shared/env.cjs"),n=require("./html-decode.cjs"),i=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g,o={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},r={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),c=new Set(["value","selectedIndex"]),h=new Set(["href","src","srcset","action","formaction","xlink:href","poster"]),l=new Set(["srcdoc"]),p=/^\s*(?:javascript|vbscript)\s*:|^\s*data:text\/html(?:[;,]|$)/i,d=new WeakMap;function f(e,t,n){if(!s.IS_DEV)return;let i=d.get(e);i||(i=new Set,d.set(e,i)),i.has(t)||(i.add(t),console.warn(n))}const u=new WeakMap;function m(e){let t=u.get(e);return t||(t={loops:null,events:Object.create(null),prevClassObj:void 0,prevStyleObj:void 0},u.set(e,t)),t}function v(e,t){const s=t.a?.find(e=>"class"===e.k&&!e.d);s?.v&&e.setAttribute("class",s.v)}function y(e,t){if(!e.style)return;const s=t.a?.find(e=>"style"===e.k&&!e.d),n=s?S(s.v):{};for(const i in n){const t=n[i];i.startsWith("--")?e.style.setProperty(i,t):e.style[i]=t}}const g=e=>!(!e||0===e.length||/\s/.test(e)&&(s.IS_DEV&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function S(e){const t={},s=[[e]];for(;s.length;){const[e,n]=s.pop()||[];if(e){if("string"==typeof e){let s;for(i.lastIndex=0;null!==(s=i.exec(e));){const e=s[1].trim(),n=s[2].trim();e&&n&&(t[e]=n)}continue}if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push([e[t]]);else if("object"==typeof e){const i=e;for(const e in i){const o=i[e];if(null==o)continue;const r=n?`${n}-${e}`:e;"object"!=typeof o||Array.isArray(o)?t[r]=String(o):s.push([o,r])}}}}return t}function k(e,t,s){const n=null==s?"":String(s),i=t.indexOf(":");if(i>0){const s=t.slice(0,i),r=o[s];if(r)return void(e.getAttributeNS(r,t)!==n&&e.setAttributeNS(r,t,n))}e.getAttribute(t)!==n&&e.setAttribute(t,n)}function N(e,t,s,n){const i=r[t]||t;if(t.startsWith("data-")||t.startsWith("aria-")||a.has(t))return void k(e,t,s);if(l.has(t)&&null!=s)return void function(e,t){f(e,`srcdoc:${String(t)}`,'[Solely] Blocked "srcdoc" binding (HTML injection risk). Use a sandboxed iframe with "src" instead.')}(e,s);if((h.has(t)||h.has(i))&&function(e){return"string"==typeof e&&p.test(e.replace(/\s+/g,""))}(s))return void function(e,t,s){f(e,`${t}:${String(s)}`,`[Solely] Blocked unsafe URL for "${t}": ${String(s).slice(0,80)}. Use a http(s)/relative URL instead.`)}(e,t,s);const o=e,c=o.tagName;if(null!=s){if("src"===i||"href"===i){const t=String(s);if(o[i]===t||e.getAttribute(i)===t)return}if("value"!==i||"INPUT"!==c&&"TEXTAREA"!==c||o.value!==s)if("boolean"!=typeof s)(n??(e instanceof SVGElement||void 0!==o.ownerSVGElement))&&!r[t]?k(e,t,s):o[i]!==s&&(o[i]=s);else{if(o[i]===s)return;o[i]=s}}else if("boolean"==typeof o[i])!1!==o[i]&&(o[i]=!1);else{const s=o[i];""!==s&&void 0!==s&&(o[i]=""),e.hasAttribute(t)&&e.removeAttribute(t)}}class K{constructor(e,t,s={}){this.ir=e,this.container=t,this.scope=s}ir;container;scope;nodeMap=new Map;prevNodeMap=new Map;pathStack=[];pathKey="";staticSubtreeCache=new Map;keepaliveCache=new Map;currentKaKey=null;kaDepth=0;isKaRestoring=!1;rafIds=new Set;keepaliveAccessCounter=0;maxKeepalive=20;renderedKaKeys=new Set;scheduleRaf(e){const t=requestAnimationFrame(()=>{this.rafIds.delete(t),e()});return this.rafIds.add(t),t}pushPath(e){this.pathStack.push(e),this.pathKey=this.pathStack.join(".")}popPath(){this.pathStack.pop(),this.pathKey=this.pathStack.join(".")}evalIR(e,n,i){const o=this.ir.fns[e-1];if(s.IS_DEV)try{return o?o.apply(this.scope,n):""}catch(r){return t.showTemplateError(r.message||r.toString(),this.ir.m?.src||"",i,this.scope.tagName),""}return o?o.apply(this.scope,n):""}createElement(e,t){const s=e.g??"";return t instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):n.default(e.x||"");return document.createTextNode(s)}createComment(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):e.x||"";return document.createComment(s)}removeEventListenersFromNode(e){const t=u.get(e);if(t)for(const[s,n]of Object.entries(t.events))n.listener&&e.removeEventListener(s,n.listener)}applyAttrs(e,t,s,n=!1,i=!1){const o=[],r=m(e),a=e instanceof SVGElement||void 0!==e.ownerSVGElement;let h;r.loops=s;let l,p=!1,d=!1;for(const f of t){const{k:t,f:u,d:m,v:v}=f;if(":class"===t){h=this.evalIR(u??-1,[s],f.__m),p=!0;continue}if(":style"===t){l=this.evalIR(u??-1,[s],f.__m),d=!0;continue}if("class"===t||"style"===t)continue;const y=t[0];if("@"===y){const s=t.slice(1),i=f.r??"user";let o=r.events[s];if(!o){o={model:[],user:[],listener:null};const t=e=>{for(const t of o.model)t(e);for(const t of o.user)t(e)};o.listener=t,e.addEventListener(s,t),r.events[s]=o}if(!n){const e=e=>this.evalIR(u??-1,[e,r.loops],f.__m);o[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("ref"===t&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=e;continue}const g=m?this.evalIR(u??-1,[s],f.__m):v??"";if(":"===y){const s=t.slice(1);"SELECT"===e.tagName&&c.has(s)?o.push(()=>N(e,s,g,a)):N(e,s,g,a)}else n||k(e,t,String(g))}return p&&((e,t)=>{const s=m(e),n=s.prevClassObj,i=function(e){const t={},s=[e];for(;s.length;){const e=s.pop();if(e)if("string"==typeof e){const s=e.split(" ");for(let e=0;e<s.length;e++){const n=s[e].trim();n&&(t[n]=!0)}}else if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push(e[t]);else if("object"==typeof e){const s=e;for(const e in s)s[e]&&(t[e]=!0)}}return t}(t),o={};for(const c in i)g(c)&&(o[c]=i[c]);if(!n){const t=[];for(const e in o)t.push(e);return t.length&&e.classList.add(...t),void(s.prevClassObj=o)}const r=[],a=[];for(const c in n)o[c]||a.push(c);for(const c in o)n[c]||r.push(c);(r.length||a.length)&&(r.length&&e.classList.add(...r),a.length&&e.classList.remove(...a),s.prevClassObj=o)})(e,h),d&&((e,t)=>{const s=m(e),n=S(t),i=s.prevStyleObj;if(!i){for(const t in n){const s=n[t];t.startsWith("--")?e.style.setProperty(t,s):e.style[t]=s}return void(s.prevStyleObj=n)}let o=!1;for(const r in i)r in n||(r.startsWith("--")?e.style.removeProperty(r):e.style[r]="",o=!0);for(const r in n){const t=n[r];t!==i[r]&&(r.startsWith("--")?e.style.setProperty(r,t):e.style[r]=t,o=!0)}o&&(s.prevStyleObj=n)})(e,l),o}updateNode(e,t,s){const n=t.d?this.evalIR(t.f??-1,[s],t.__m):t.x||"";t.d&&e.textContent!==n&&(e.textContent=n)}createStaticSubtree(t,s,n){switch(t.t){case e.ASTType.Element:{const e=this.createElement(t,s);v(e,t),y(e,t);const i=this.applyAttrs(e,t.a??[],n);return t.c?.forEach(t=>{const s=this.createStaticSubtree(t,e,n);e.appendChild(s)}),i.forEach(e=>e()),e}case e.ASTType.Text:return this.createText(t,n);case e.ASTType.Comment:return this.createComment(t,n);default:return document.createComment("unknown")}}handleStaticSubtree(e,t,s,n){const i=this.staticSubtreeCache.get(t);if(i){const e=i.cloneNode(!0);return s.appendChild(e),e}const o=this.createStaticSubtree(e,s,n);return s.appendChild(o),this.staticSubtreeCache.set(t,o.cloneNode(!0)),o}currentKey(){return this.pathKey}findEntry(e){let t=this.nodeMap.get(e);return t||(t=this.prevNodeMap.get(e),t&&(this.prevNodeMap.delete(e),this.nodeMap.set(e,t))),t}registerNode(e,t,s,n){const i=this.currentKaKey?{irNode:t,node:s,loops:n,kaKey:this.currentKaKey}:{irNode:t,node:s,loops:n};this.nodeMap.set(e,i)}processNode(t,n,i){const o=this.currentKey(),r=this.findEntry(o);let a;if(1!==t.s)if(r){a=r.node;let s=[];t.d&&(t.t===e.ASTType.Element?s=this.applyAttrs(a,t.a??[],i,!0,this.isKaRestoring):this.updateNode(a,t,i)),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),s.forEach(e=>e())}else switch(t.t){case e.ASTType.Element:a=this.createElement(t,n),v(a,t),y(a,t);const r=this.applyAttrs(a,t.a??[],i);n.appendChild(a),this.registerNode(o,t,a,i),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),r.forEach(e=>e());break;case e.ASTType.Text:a=this.createText(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.ASTType.Comment:a=this.createComment(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.ASTType.For:{this.pushPath(-1);const s=this.currentKey();this.popPath();let o=this.findEntry(s)?.node;o||(o=document.createComment("for"),n.appendChild(o),this.registerNode(s,{t:e.ASTType.Comment},o,i));const r=this.evalIR(t.f??-1,[i],t.__m)||[],a=document.createDocumentFragment();r.forEach((e,s)=>{const n=[...i,{itmVal:e,idxVal:s}];t.c?.forEach((e,t)=>{this.pushPath(s),this.pushPath(t),this.processNode(e,a,n),this.popPath(),this.popPath()})}),o.parentNode?.insertBefore(a,o);break}case e.ASTType.Conditional:{this.pushPath(-1);const e=this.currentKey();this.popPath();let o=this.findEntry(e)?.node;o||(o=document.createComment("if"),n.appendChild(o),this.registerNode(e,{},o,i));for(let r=0;r<(t.b||[]).length;r++){const e=t.b?.[r];if(null===e.f||this.evalIR(e.f,[i],e.__m)){this.pushPath(r);const t=this.currentKey();if(this.popPath(),1===e.ka){this.renderedKaKeys.add(t);const a=this.keepaliveCache.get(t);if(a&&!a.active){o.parentNode?.insertBefore(a.fragment,o);for(const[e,t]of a.entries)this.prevNodeMap.set(e,t);a.active=!0,a.lastUsed=++this.keepaliveAccessCounter;const c=this.isKaRestoring;this.isKaRestoring=!0;const h=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly."),e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()}),this.kaDepth--,this.currentKaKey=h,this.isKaRestoring=c}else{a&&a.active&&(a.lastUsed=++this.keepaliveAccessCounter);const c=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly.");const h=t+".0";if(this.prevNodeMap.get(h))e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()});else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}this.kaDepth--,this.currentKaKey=c}}else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}break}}break}}else r?a=r.node:(a=this.handleStaticSubtree(t,o,n,i),this.registerNode(o,t,a,i))}evictKeepaliveIfNeeded(){let e=0;for(const[,n]of this.keepaliveCache.entries())n.active||e++;if(e<=this.maxKeepalive)return;let t=null,s=1/0;for(const[n,i]of this.keepaliveCache.entries())i.active||i.lastUsed<s&&(s=i.lastUsed,t=n);if(t){const e=this.keepaliveCache.get(t);for(const[,t]of e.entries){if(this.removeEventListenersFromNode(t.node),t.irNode.a){const e=t.irNode.a.find(e=>"unmounted"===e.k);e&&this.scheduleRaf(()=>{this.evalIR(e.f??-1,[t.node,t.loops],e.__m)})}t.node?.remove()}this.keepaliveCache.delete(t)}}cleanupOldNodes(){const e=this.prevNodeMap,t=new Map;for(const[s,n]of e.entries()){const{irNode:e,node:i,loops:o}=n,r=n.kaKey&&this.renderedKaKeys.has(n.kaKey);if(e.a){if(n.kaKey&&!r){const t=e.a.find(e=>"deactivated"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}else{const t=e.a.find(e=>"unmounted"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}const t=e.a.find(e=>"ref"===e.k);t&&t.v&&delete this.scope.$refs[t.v]}if(n.kaKey&&!r&&i.parentNode){let e=t.get(n.kaKey);e||(e={fragment:document.createDocumentFragment(),entries:[]},t.set(n.kaKey,e));const o=n.kaKey.split(".").length;s.split(".").length===o+1&&e.fragment.appendChild(i),e.entries.push([s,n])}else this.removeEventListenersFromNode(i),i?.remove()}for(const[s,n]of t.entries()){const e=this.keepaliveCache.get(s);e&&e.active?(e.fragment=n.fragment,e.entries=n.entries,e.active=!1,e.lastUsed=++this.keepaliveAccessCounter):e||this.keepaliveCache.set(s,{fragment:n.fragment,entries:n.entries,lastUsed:++this.keepaliveAccessCounter,active:!1})}this.evictKeepaliveIfNeeded(),e.clear()}mount(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}update(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}destroy(){this.rafIds.forEach(e=>cancelAnimationFrame(e)),this.rafIds.clear();const e=e=>{for(const[,t]of e.entries())this.removeEventListenersFromNode(t.node)};e(this.nodeMap),e(this.prevNodeMap);for(const[,t]of this.keepaliveCache.entries())for(const[,e]of t.entries){if(this.removeEventListenersFromNode(e.node),e.irNode.a){const t=e.irNode.a.find(e=>"unmounted"===e.k);t&&this.evalIR(t.f??-1,[e.node,e.loops],t.__m)}e.node?.remove()}this.container.innerHTML="",this.scope.$refs={},this.nodeMap.clear(),this.prevNodeMap.clear(),this.staticSubtreeCache.clear(),this.keepaliveCache.clear(),this.renderedKaKeys.clear()}irToNode(e,t,s,n){this.pushPath(t),this.processNode(e,s,n),this.popPath()}}exports.IRRenderer=K,exports.createRender=(e,t,s={})=>{const n=new K(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../types/ast.cjs"),t=require("../../shared/templateError.cjs"),s=require("../../shared/env.cjs"),n=require("./html-decode.cjs"),i=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g,r={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},o={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),c=new Set(["value","selectedIndex"]),h=new Set(["href","src","srcset","action","formaction","xlink:href","poster"]),l=new Set(["srcdoc"]),p=/^\s*(?:javascript|vbscript)\s*:|^\s*data:text\/html(?:[;,]|$)/i,d=new WeakMap;function f(e,t,n){if(!s.IS_DEV)return;let i=d.get(e);i||(i=new Set,d.set(e,i)),i.has(t)||(i.add(t),console.warn(n))}const u=new WeakMap;function m(e){let t=u.get(e);return t||(t={loops:null,events:Object.create(null),prevClassObj:void 0,prevStyleObj:void 0},u.set(e,t)),t}function v(e,t){const s=t.a?.find(e=>"class"===e.k&&!e.d);s?.v&&e.setAttribute("class",s.v)}function y(e,t){if(!e.style)return;const s=t.a?.find(e=>"style"===e.k&&!e.d),n=s?S(s.v):{};for(const i in n){const t=n[i];i.startsWith("--")?e.style.setProperty(i,t):e.style[i]=t}}const g=e=>!(!e||0===e.length||/\s/.test(e)&&(s.IS_DEV&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function S(e){const t={},s=[[e]];for(;s.length;){const[e,n]=s.pop()||[];if(e){if("string"==typeof e){let s;for(i.lastIndex=0;null!==(s=i.exec(e));){const e=s[1].trim(),n=s[2].trim();e&&n&&(t[e]=n)}continue}if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push([e[t]]);else if("object"==typeof e){const i=e;for(const e in i){const r=i[e];if(null==r)continue;const o=n?`${n}-${e}`:e;"object"!=typeof r||Array.isArray(r)?t[o]=String(r):s.push([r,o])}}}}return t}function k(e,t,s){const n=null==s?"":String(s),i=t.indexOf(":");if(i>0){const s=t.slice(0,i),o=r[s];if(o)return void(e.getAttributeNS(o,t)!==n&&e.setAttributeNS(o,t,n))}e.getAttribute(t)!==n&&e.setAttribute(t,n)}function N(e,t,s,n){const i=o[t]||t;if(t.startsWith("data-")||t.startsWith("aria-"))return null==s?void(e.hasAttribute(t)&&e.removeAttribute(t)):void k(e,t,s);if(a.has(t))return void k(e,t,s);if(l.has(t)&&null!=s)return void function(e,t){f(e,`srcdoc:${String(t)}`,'[Solely] Blocked "srcdoc" binding (HTML injection risk). Use a sandboxed iframe with "src" instead.')}(e,s);if((h.has(t)||h.has(i))&&function(e){return"string"==typeof e&&p.test(e.replace(/\s+/g,""))}(s))return void function(e,t,s){f(e,`${t}:${String(s)}`,`[Solely] Blocked unsafe URL for "${t}": ${String(s).slice(0,80)}. Use a http(s)/relative URL instead.`)}(e,t,s);const r=e,c=r.tagName;if(null!=s){if("src"===i||"href"===i){const t=String(s);if(r[i]===t||e.getAttribute(i)===t)return}if("value"!==i||"INPUT"!==c&&"TEXTAREA"!==c||r.value!==s)if("boolean"!=typeof s)(n??(e instanceof SVGElement||void 0!==r.ownerSVGElement))&&!o[t]?k(e,t,s):r[i]!==s&&(r[i]=s);else{if(r[i]===s)return;r[i]=s}}else if("boolean"==typeof r[i])!1!==r[i]&&(r[i]=!1);else{const s=r[i];""!==s&&void 0!==s&&(r[i]=""),e.hasAttribute(t)&&e.removeAttribute(t)}}class K{constructor(e,t,s={}){this.ir=e,this.container=t,this.scope=s}ir;container;scope;nodeMap=new Map;prevNodeMap=new Map;pathStack=[];pathKey="";staticSubtreeCache=new Map;keepaliveCache=new Map;currentKaKey=null;kaDepth=0;isKaRestoring=!1;rafIds=new Set;keepaliveAccessCounter=0;maxKeepalive=20;renderedKaKeys=new Set;scheduleRaf(e){const t=requestAnimationFrame(()=>{this.rafIds.delete(t),e()});return this.rafIds.add(t),t}pushPath(e){this.pathStack.push(e),this.pathKey=this.pathStack.join(".")}popPath(){this.pathStack.pop(),this.pathKey=this.pathStack.join(".")}evalIR(e,n,i){const r=this.ir.fns[e-1];if(s.IS_DEV)try{return r?r.apply(this.scope,n):""}catch(o){return t.showTemplateError(o.message||o.toString(),this.ir.m?.src||"",i,this.scope.tagName),""}return r?r.apply(this.scope,n):""}createElement(e,t){const s=e.g??"";return t instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):n.default(e.x||"");return document.createTextNode(s)}createComment(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):e.x||"";return document.createComment(s)}removeEventListenersFromNode(e){const t=u.get(e);if(t)for(const[s,n]of Object.entries(t.events))n.listener&&e.removeEventListener(s,n.listener)}applyAttrs(e,t,s,n=!1,i=!1){const r=[],o=m(e),a=e instanceof SVGElement||void 0!==e.ownerSVGElement;let h;o.loops=s;let l,p=!1,d=!1;for(const f of t){const{k:t,f:u,d:m,v:v}=f;if(":class"===t){h=this.evalIR(u??-1,[s],f.__m),p=!0;continue}if(":style"===t){l=this.evalIR(u??-1,[s],f.__m),d=!0;continue}if("class"===t||"style"===t)continue;const y=t[0];if("@"===y){const s=t.slice(1),i=f.r??"user";let r=o.events[s];if(!r){r={model:[],user:[],listener:null};const t=e=>{for(const t of r.model)t(e);for(const t of r.user)t(e)};r.listener=t,e.addEventListener(s,t),o.events[s]=r}if(!n){const e=e=>this.evalIR(u??-1,[e,o.loops],f.__m);r[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("ref"===t&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=e;continue}const g=m?this.evalIR(u??-1,[s],f.__m):v??"";if(":"===y){const s=t.slice(1);"SELECT"===e.tagName&&c.has(s)?r.push(()=>N(e,s,g,a)):N(e,s,g,a)}else n||k(e,t,String(g))}return p&&((e,t)=>{const s=m(e),n=s.prevClassObj,i=function(e){const t={},s=[e];for(;s.length;){const e=s.pop();if(e)if("string"==typeof e){const s=e.split(" ");for(let e=0;e<s.length;e++){const n=s[e].trim();n&&(t[n]=!0)}}else if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push(e[t]);else if("object"==typeof e){const s=e;for(const e in s)s[e]&&(t[e]=!0)}}return t}(t),r={};for(const c in i)g(c)&&(r[c]=i[c]);if(!n){const t=[];for(const e in r)t.push(e);return t.length&&e.classList.add(...t),void(s.prevClassObj=r)}const o=[],a=[];for(const c in n)r[c]||a.push(c);for(const c in r)n[c]||o.push(c);(o.length||a.length)&&(o.length&&e.classList.add(...o),a.length&&e.classList.remove(...a),s.prevClassObj=r)})(e,h),d&&((e,t)=>{const s=m(e),n=S(t),i=s.prevStyleObj;if(!i){for(const t in n){const s=n[t];t.startsWith("--")?e.style.setProperty(t,s):e.style[t]=s}return void(s.prevStyleObj=n)}let r=!1;for(const o in i)o in n||(o.startsWith("--")?e.style.removeProperty(o):e.style[o]="",r=!0);for(const o in n){const t=n[o];t!==i[o]&&(o.startsWith("--")?e.style.setProperty(o,t):e.style[o]=t,r=!0)}r&&(s.prevStyleObj=n)})(e,l),r}updateNode(e,t,s){const n=t.d?this.evalIR(t.f??-1,[s],t.__m):t.x||"";t.d&&e.textContent!==n&&(e.textContent=n)}createStaticSubtree(t,s,n){switch(t.t){case e.ASTType.Element:{const e=this.createElement(t,s);v(e,t),y(e,t);const i=this.applyAttrs(e,t.a??[],n);return t.c?.forEach(t=>{const s=this.createStaticSubtree(t,e,n);e.appendChild(s)}),i.forEach(e=>e()),e}case e.ASTType.Text:return this.createText(t,n);case e.ASTType.Comment:return this.createComment(t,n);default:return document.createComment("unknown")}}handleStaticSubtree(e,t,s,n){const i=this.staticSubtreeCache.get(t);if(i){const e=i.cloneNode(!0);return s.appendChild(e),e}const r=this.createStaticSubtree(e,s,n);return s.appendChild(r),this.staticSubtreeCache.set(t,r.cloneNode(!0)),r}currentKey(){return this.pathKey}findEntry(e){let t=this.nodeMap.get(e);return t||(t=this.prevNodeMap.get(e),t&&(this.prevNodeMap.delete(e),this.nodeMap.set(e,t))),t}registerNode(e,t,s,n){const i=this.currentKaKey?{irNode:t,node:s,loops:n,kaKey:this.currentKaKey}:{irNode:t,node:s,loops:n};this.nodeMap.set(e,i)}processNode(t,n,i){const r=this.currentKey(),o=this.findEntry(r);let a;if(1!==t.s)if(o){a=o.node;let s=[];t.d&&(t.t===e.ASTType.Element?s=this.applyAttrs(a,t.a??[],i,!0,this.isKaRestoring):this.updateNode(a,t,i)),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),s.forEach(e=>e())}else switch(t.t){case e.ASTType.Element:a=this.createElement(t,n),v(a,t),y(a,t);const o=this.applyAttrs(a,t.a??[],i);n.appendChild(a),this.registerNode(r,t,a,i),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),o.forEach(e=>e());break;case e.ASTType.Text:a=this.createText(t,i),n.appendChild(a),this.registerNode(r,t,a,i);break;case e.ASTType.Comment:a=this.createComment(t,i),n.appendChild(a),this.registerNode(r,t,a,i);break;case e.ASTType.For:{this.pushPath(-1);const s=this.currentKey();this.popPath();let r=this.findEntry(s)?.node;r||(r=document.createComment("for"),n.appendChild(r),this.registerNode(s,{t:e.ASTType.Comment},r,i));const o=this.evalIR(t.f??-1,[i],t.__m)||[],a=document.createDocumentFragment();o.forEach((e,s)=>{const n=[...i,{itmVal:e,idxVal:s}];t.c?.forEach((e,t)=>{this.pushPath(s),this.pushPath(t),this.processNode(e,a,n),this.popPath(),this.popPath()})}),r.parentNode?.insertBefore(a,r);break}case e.ASTType.Conditional:{this.pushPath(-1);const e=this.currentKey();this.popPath();let r=this.findEntry(e)?.node;r||(r=document.createComment("if"),n.appendChild(r),this.registerNode(e,{},r,i));for(let o=0;o<(t.b||[]).length;o++){const e=t.b?.[o];if(null===e.f||this.evalIR(e.f,[i],e.__m)){this.pushPath(o);const t=this.currentKey();if(this.popPath(),1===e.ka){this.renderedKaKeys.add(t);const a=this.keepaliveCache.get(t);if(a&&!a.active){r.parentNode?.insertBefore(a.fragment,r);for(const[e,t]of a.entries)this.prevNodeMap.set(e,t);a.active=!0,a.lastUsed=++this.keepaliveAccessCounter;const c=this.isKaRestoring;this.isKaRestoring=!0;const h=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly."),e.c.forEach((e,t)=>{this.pushPath(o),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()}),this.kaDepth--,this.currentKaKey=h,this.isKaRestoring=c}else{a&&a.active&&(a.lastUsed=++this.keepaliveAccessCounter);const c=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly.");const h=t+".0";if(this.prevNodeMap.get(h))e.c.forEach((e,t)=>{this.pushPath(o),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()});else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(o),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),r.parentNode?.insertBefore(t,r)}this.kaDepth--,this.currentKaKey=c}}else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(o),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),r.parentNode?.insertBefore(t,r)}break}}break}}else o?a=o.node:(a=this.handleStaticSubtree(t,r,n,i),this.registerNode(r,t,a,i))}evictKeepaliveIfNeeded(){let e=0;for(const[,n]of this.keepaliveCache.entries())n.active||e++;if(e<=this.maxKeepalive)return;let t=null,s=1/0;for(const[n,i]of this.keepaliveCache.entries())i.active||i.lastUsed<s&&(s=i.lastUsed,t=n);if(t){const e=this.keepaliveCache.get(t);for(const[,t]of e.entries){if(this.removeEventListenersFromNode(t.node),t.irNode.a){const e=t.irNode.a.find(e=>"unmounted"===e.k);e&&this.scheduleRaf(()=>{this.evalIR(e.f??-1,[t.node,t.loops],e.__m)})}t.node?.remove()}this.keepaliveCache.delete(t)}}cleanupOldNodes(){const e=this.prevNodeMap,t=new Map;for(const[s,n]of e.entries()){const{irNode:e,node:i,loops:r}=n,o=n.kaKey&&this.renderedKaKeys.has(n.kaKey);if(e.a){if(n.kaKey&&!o){const t=e.a.find(e=>"deactivated"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,r],t.__m))}else{const t=e.a.find(e=>"unmounted"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,r],t.__m))}const t=e.a.find(e=>"ref"===e.k);t&&t.v&&delete this.scope.$refs[t.v]}if(n.kaKey&&!o&&i.parentNode){let e=t.get(n.kaKey);e||(e={fragment:document.createDocumentFragment(),entries:[]},t.set(n.kaKey,e));const r=n.kaKey.split(".").length;s.split(".").length===r+1&&e.fragment.appendChild(i),e.entries.push([s,n])}else this.removeEventListenersFromNode(i),i?.remove()}for(const[s,n]of t.entries()){const e=this.keepaliveCache.get(s);e&&e.active?(e.fragment=n.fragment,e.entries=n.entries,e.active=!1,e.lastUsed=++this.keepaliveAccessCounter):e||this.keepaliveCache.set(s,{fragment:n.fragment,entries:n.entries,lastUsed:++this.keepaliveAccessCounter,active:!1})}this.evictKeepaliveIfNeeded(),e.clear()}mount(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}update(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}destroy(){this.rafIds.forEach(e=>cancelAnimationFrame(e)),this.rafIds.clear();const e=e=>{for(const[,t]of e.entries())this.removeEventListenersFromNode(t.node)};e(this.nodeMap),e(this.prevNodeMap);for(const[,t]of this.keepaliveCache.entries())for(const[,e]of t.entries){if(this.removeEventListenersFromNode(e.node),e.irNode.a){const t=e.irNode.a.find(e=>"unmounted"===e.k);t&&this.evalIR(t.f??-1,[e.node,e.loops],t.__m)}e.node?.remove()}this.container.innerHTML="",this.scope.$refs={},this.nodeMap.clear(),this.prevNodeMap.clear(),this.staticSubtreeCache.clear(),this.keepaliveCache.clear(),this.renderedKaKeys.clear()}irToNode(e,t,s,n){this.pushPath(t),this.processNode(e,s,n),this.popPath()}}exports.IRRenderer=K,exports.createRender=(e,t,s={})=>{const n=new K(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};
@@ -1,4 +1,4 @@
1
- import { IRRoot, Meta } from '../../types';
1
+ import { IRRoot, Meta } from '../../types/index.js';
2
2
  /**
3
3
  * IR 渲染器:将 IR 中间树渲染为真实 DOM
4
4
  * - 支持静态子树克隆缓存
@@ -1 +1 @@
1
- import{ASTType as e}from"../../types/ast.js";import{showTemplateError as t}from"../../shared/templateError.js";import{IS_DEV as s}from"../../shared/env.js";import n from"./html-decode.js";const i=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g,o={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},r={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),c=new Set(["value","selectedIndex"]),h=new Set(["href","src","srcset","action","formaction","xlink:href","poster"]),l=new Set(["srcdoc"]),p=/^\s*(?:javascript|vbscript)\s*:|^\s*data:text\/html(?:[;,]|$)/i,d=new WeakMap;function f(e,t,n){if(!s)return;let i=d.get(e);i||(i=new Set,d.set(e,i)),i.has(t)||(i.add(t),console.warn(n))}const u=new WeakMap;function m(e){let t=u.get(e);return t||(t={loops:null,events:Object.create(null),prevClassObj:void 0,prevStyleObj:void 0},u.set(e,t)),t}function v(e,t){const s=t.a?.find(e=>"class"===e.k&&!e.d);s?.v&&e.setAttribute("class",s.v)}function y(e,t){if(!e.style)return;const s=t.a?.find(e=>"style"===e.k&&!e.d),n=s?k(s.v):{};for(const i in n){const t=n[i];i.startsWith("--")?e.style.setProperty(i,t):e.style[i]=t}}const g=e=>!(!e||0===e.length||/\s/.test(e)&&(s&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function k(e){const t={},s=[[e]];for(;s.length;){const[e,n]=s.pop()||[];if(e){if("string"==typeof e){let s;for(i.lastIndex=0;null!==(s=i.exec(e));){const e=s[1].trim(),n=s[2].trim();e&&n&&(t[e]=n)}continue}if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push([e[t]]);else if("object"==typeof e){const i=e;for(const e in i){const o=i[e];if(null==o)continue;const r=n?`${n}-${e}`:e;"object"!=typeof o||Array.isArray(o)?t[r]=String(o):s.push([o,r])}}}}return t}function N(e,t,s){const n=null==s?"":String(s),i=t.indexOf(":");if(i>0){const s=t.slice(0,i),r=o[s];if(r)return void(e.getAttributeNS(r,t)!==n&&e.setAttributeNS(r,t,n))}e.getAttribute(t)!==n&&e.setAttribute(t,n)}function K(e,t,s,n){const i=r[t]||t;if(t.startsWith("data-")||t.startsWith("aria-")||a.has(t))return void N(e,t,s);if(l.has(t)&&null!=s)return void function(e,t){f(e,`srcdoc:${String(t)}`,'[Solely] Blocked "srcdoc" binding (HTML injection risk). Use a sandboxed iframe with "src" instead.')}(e,s);if((h.has(t)||h.has(i))&&function(e){return"string"==typeof e&&p.test(e.replace(/\s+/g,""))}(s))return void function(e,t,s){f(e,`${t}:${String(s)}`,`[Solely] Blocked unsafe URL for "${t}": ${String(s).slice(0,80)}. Use a http(s)/relative URL instead.`)}(e,t,s);const o=e,c=o.tagName;if(null!=s){if("src"===i||"href"===i){const t=String(s);if(o[i]===t||e.getAttribute(i)===t)return}if("value"!==i||"INPUT"!==c&&"TEXTAREA"!==c||o.value!==s)if("boolean"!=typeof s)(n??(e instanceof SVGElement||void 0!==o.ownerSVGElement))&&!r[t]?N(e,t,s):o[i]!==s&&(o[i]=s);else{if(o[i]===s)return;o[i]=s}}else if("boolean"==typeof o[i])!1!==o[i]&&(o[i]=!1);else{const s=o[i];""!==s&&void 0!==s&&(o[i]=""),e.hasAttribute(t)&&e.removeAttribute(t)}}class S{constructor(e,t,s={}){this.ir=e,this.container=t,this.scope=s}ir;container;scope;nodeMap=new Map;prevNodeMap=new Map;pathStack=[];pathKey="";staticSubtreeCache=new Map;keepaliveCache=new Map;currentKaKey=null;kaDepth=0;isKaRestoring=!1;rafIds=new Set;keepaliveAccessCounter=0;maxKeepalive=20;renderedKaKeys=new Set;scheduleRaf(e){const t=requestAnimationFrame(()=>{this.rafIds.delete(t),e()});return this.rafIds.add(t),t}pushPath(e){this.pathStack.push(e),this.pathKey=this.pathStack.join(".")}popPath(){this.pathStack.pop(),this.pathKey=this.pathStack.join(".")}evalIR(e,n,i){const o=this.ir.fns[e-1];if(s)try{return o?o.apply(this.scope,n):""}catch(r){return t(r.message||r.toString(),this.ir.m?.src||"",i,this.scope.tagName),""}return o?o.apply(this.scope,n):""}createElement(e,t){const s=e.g??"";return t instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):n(e.x||"");return document.createTextNode(s)}createComment(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):e.x||"";return document.createComment(s)}removeEventListenersFromNode(e){const t=u.get(e);if(t)for(const[s,n]of Object.entries(t.events))n.listener&&e.removeEventListener(s,n.listener)}applyAttrs(e,t,s,n=!1,i=!1){const o=[],r=m(e),a=e instanceof SVGElement||void 0!==e.ownerSVGElement;let h;r.loops=s;let l,p=!1,d=!1;for(const f of t){const{k:t,f:u,d:m,v:v}=f;if(":class"===t){h=this.evalIR(u??-1,[s],f.__m),p=!0;continue}if(":style"===t){l=this.evalIR(u??-1,[s],f.__m),d=!0;continue}if("class"===t||"style"===t)continue;const y=t[0];if("@"===y){const s=t.slice(1),i=f.r??"user";let o=r.events[s];if(!o){o={model:[],user:[],listener:null};const t=e=>{for(const t of o.model)t(e);for(const t of o.user)t(e)};o.listener=t,e.addEventListener(s,t),r.events[s]=o}if(!n){const e=e=>this.evalIR(u??-1,[e,r.loops],f.__m);o[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("ref"===t&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=e;continue}const g=m?this.evalIR(u??-1,[s],f.__m):v??"";if(":"===y){const s=t.slice(1);"SELECT"===e.tagName&&c.has(s)?o.push(()=>K(e,s,g,a)):K(e,s,g,a)}else n||N(e,t,String(g))}return p&&((e,t)=>{const s=m(e),n=s.prevClassObj,i=function(e){const t={},s=[e];for(;s.length;){const e=s.pop();if(e)if("string"==typeof e){const s=e.split(" ");for(let e=0;e<s.length;e++){const n=s[e].trim();n&&(t[n]=!0)}}else if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push(e[t]);else if("object"==typeof e){const s=e;for(const e in s)s[e]&&(t[e]=!0)}}return t}(t),o={};for(const c in i)g(c)&&(o[c]=i[c]);if(!n){const t=[];for(const e in o)t.push(e);return t.length&&e.classList.add(...t),void(s.prevClassObj=o)}const r=[],a=[];for(const c in n)o[c]||a.push(c);for(const c in o)n[c]||r.push(c);(r.length||a.length)&&(r.length&&e.classList.add(...r),a.length&&e.classList.remove(...a),s.prevClassObj=o)})(e,h),d&&((e,t)=>{const s=m(e),n=k(t),i=s.prevStyleObj;if(!i){for(const t in n){const s=n[t];t.startsWith("--")?e.style.setProperty(t,s):e.style[t]=s}return void(s.prevStyleObj=n)}let o=!1;for(const r in i)r in n||(r.startsWith("--")?e.style.removeProperty(r):e.style[r]="",o=!0);for(const r in n){const t=n[r];t!==i[r]&&(r.startsWith("--")?e.style.setProperty(r,t):e.style[r]=t,o=!0)}o&&(s.prevStyleObj=n)})(e,l),o}updateNode(e,t,s){const n=t.d?this.evalIR(t.f??-1,[s],t.__m):t.x||"";t.d&&e.textContent!==n&&(e.textContent=n)}createStaticSubtree(t,s,n){switch(t.t){case e.Element:{const e=this.createElement(t,s);v(e,t),y(e,t);const i=this.applyAttrs(e,t.a??[],n);return t.c?.forEach(t=>{const s=this.createStaticSubtree(t,e,n);e.appendChild(s)}),i.forEach(e=>e()),e}case e.Text:return this.createText(t,n);case e.Comment:return this.createComment(t,n);default:return document.createComment("unknown")}}handleStaticSubtree(e,t,s,n){const i=this.staticSubtreeCache.get(t);if(i){const e=i.cloneNode(!0);return s.appendChild(e),e}const o=this.createStaticSubtree(e,s,n);return s.appendChild(o),this.staticSubtreeCache.set(t,o.cloneNode(!0)),o}currentKey(){return this.pathKey}findEntry(e){let t=this.nodeMap.get(e);return t||(t=this.prevNodeMap.get(e),t&&(this.prevNodeMap.delete(e),this.nodeMap.set(e,t))),t}registerNode(e,t,s,n){const i=this.currentKaKey?{irNode:t,node:s,loops:n,kaKey:this.currentKaKey}:{irNode:t,node:s,loops:n};this.nodeMap.set(e,i)}processNode(t,n,i){const o=this.currentKey(),r=this.findEntry(o);let a;if(1!==t.s)if(r){a=r.node;let s=[];t.d&&(t.t===e.Element?s=this.applyAttrs(a,t.a??[],i,!0,this.isKaRestoring):this.updateNode(a,t,i)),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),s.forEach(e=>e())}else switch(t.t){case e.Element:a=this.createElement(t,n),v(a,t),y(a,t);const r=this.applyAttrs(a,t.a??[],i);n.appendChild(a),this.registerNode(o,t,a,i),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),r.forEach(e=>e());break;case e.Text:a=this.createText(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.Comment:a=this.createComment(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.For:{this.pushPath(-1);const s=this.currentKey();this.popPath();let o=this.findEntry(s)?.node;o||(o=document.createComment("for"),n.appendChild(o),this.registerNode(s,{t:e.Comment},o,i));const r=this.evalIR(t.f??-1,[i],t.__m)||[],a=document.createDocumentFragment();r.forEach((e,s)=>{const n=[...i,{itmVal:e,idxVal:s}];t.c?.forEach((e,t)=>{this.pushPath(s),this.pushPath(t),this.processNode(e,a,n),this.popPath(),this.popPath()})}),o.parentNode?.insertBefore(a,o);break}case e.Conditional:{this.pushPath(-1);const e=this.currentKey();this.popPath();let o=this.findEntry(e)?.node;o||(o=document.createComment("if"),n.appendChild(o),this.registerNode(e,{},o,i));for(let r=0;r<(t.b||[]).length;r++){const e=t.b?.[r];if(null===e.f||this.evalIR(e.f,[i],e.__m)){this.pushPath(r);const t=this.currentKey();if(this.popPath(),1===e.ka){this.renderedKaKeys.add(t);const a=this.keepaliveCache.get(t);if(a&&!a.active){o.parentNode?.insertBefore(a.fragment,o);for(const[e,t]of a.entries)this.prevNodeMap.set(e,t);a.active=!0,a.lastUsed=++this.keepaliveAccessCounter;const c=this.isKaRestoring;this.isKaRestoring=!0;const h=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly."),e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()}),this.kaDepth--,this.currentKaKey=h,this.isKaRestoring=c}else{a&&a.active&&(a.lastUsed=++this.keepaliveAccessCounter);const c=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly.");const h=t+".0";if(this.prevNodeMap.get(h))e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()});else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}this.kaDepth--,this.currentKaKey=c}}else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}break}}break}}else r?a=r.node:(a=this.handleStaticSubtree(t,o,n,i),this.registerNode(o,t,a,i))}evictKeepaliveIfNeeded(){let e=0;for(const[,n]of this.keepaliveCache.entries())n.active||e++;if(e<=this.maxKeepalive)return;let t=null,s=1/0;for(const[n,i]of this.keepaliveCache.entries())i.active||i.lastUsed<s&&(s=i.lastUsed,t=n);if(t){const e=this.keepaliveCache.get(t);for(const[,t]of e.entries){if(this.removeEventListenersFromNode(t.node),t.irNode.a){const e=t.irNode.a.find(e=>"unmounted"===e.k);e&&this.scheduleRaf(()=>{this.evalIR(e.f??-1,[t.node,t.loops],e.__m)})}t.node?.remove()}this.keepaliveCache.delete(t)}}cleanupOldNodes(){const e=this.prevNodeMap,t=new Map;for(const[s,n]of e.entries()){const{irNode:e,node:i,loops:o}=n,r=n.kaKey&&this.renderedKaKeys.has(n.kaKey);if(e.a){if(n.kaKey&&!r){const t=e.a.find(e=>"deactivated"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}else{const t=e.a.find(e=>"unmounted"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}const t=e.a.find(e=>"ref"===e.k);t&&t.v&&delete this.scope.$refs[t.v]}if(n.kaKey&&!r&&i.parentNode){let e=t.get(n.kaKey);e||(e={fragment:document.createDocumentFragment(),entries:[]},t.set(n.kaKey,e));const o=n.kaKey.split(".").length;s.split(".").length===o+1&&e.fragment.appendChild(i),e.entries.push([s,n])}else this.removeEventListenersFromNode(i),i?.remove()}for(const[s,n]of t.entries()){const e=this.keepaliveCache.get(s);e&&e.active?(e.fragment=n.fragment,e.entries=n.entries,e.active=!1,e.lastUsed=++this.keepaliveAccessCounter):e||this.keepaliveCache.set(s,{fragment:n.fragment,entries:n.entries,lastUsed:++this.keepaliveAccessCounter,active:!1})}this.evictKeepaliveIfNeeded(),e.clear()}mount(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}update(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}destroy(){this.rafIds.forEach(e=>cancelAnimationFrame(e)),this.rafIds.clear();const e=e=>{for(const[,t]of e.entries())this.removeEventListenersFromNode(t.node)};e(this.nodeMap),e(this.prevNodeMap);for(const[,t]of this.keepaliveCache.entries())for(const[,e]of t.entries){if(this.removeEventListenersFromNode(e.node),e.irNode.a){const t=e.irNode.a.find(e=>"unmounted"===e.k);t&&this.evalIR(t.f??-1,[e.node,e.loops],t.__m)}e.node?.remove()}this.container.innerHTML="",this.scope.$refs={},this.nodeMap.clear(),this.prevNodeMap.clear(),this.staticSubtreeCache.clear(),this.keepaliveCache.clear(),this.renderedKaKeys.clear()}irToNode(e,t,s,n){this.pushPath(t),this.processNode(e,s,n),this.popPath()}}const b=(e,t,s={})=>{const n=new S(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};export{S as IRRenderer,b as createRender};
1
+ import{ASTType as e}from"../../types/ast.js";import{showTemplateError as t}from"../../shared/templateError.js";import{IS_DEV as s}from"../../shared/env.js";import n from"./html-decode.js";const i=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g,o={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},r={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),c=new Set(["value","selectedIndex"]),h=new Set(["href","src","srcset","action","formaction","xlink:href","poster"]),l=new Set(["srcdoc"]),p=/^\s*(?:javascript|vbscript)\s*:|^\s*data:text\/html(?:[;,]|$)/i,d=new WeakMap;function f(e,t,n){if(!s)return;let i=d.get(e);i||(i=new Set,d.set(e,i)),i.has(t)||(i.add(t),console.warn(n))}const u=new WeakMap;function m(e){let t=u.get(e);return t||(t={loops:null,events:Object.create(null),prevClassObj:void 0,prevStyleObj:void 0},u.set(e,t)),t}function v(e,t){const s=t.a?.find(e=>"class"===e.k&&!e.d);s?.v&&e.setAttribute("class",s.v)}function y(e,t){if(!e.style)return;const s=t.a?.find(e=>"style"===e.k&&!e.d),n=s?k(s.v):{};for(const i in n){const t=n[i];i.startsWith("--")?e.style.setProperty(i,t):e.style[i]=t}}const g=e=>!(!e||0===e.length||/\s/.test(e)&&(s&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function k(e){const t={},s=[[e]];for(;s.length;){const[e,n]=s.pop()||[];if(e){if("string"==typeof e){let s;for(i.lastIndex=0;null!==(s=i.exec(e));){const e=s[1].trim(),n=s[2].trim();e&&n&&(t[e]=n)}continue}if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push([e[t]]);else if("object"==typeof e){const i=e;for(const e in i){const o=i[e];if(null==o)continue;const r=n?`${n}-${e}`:e;"object"!=typeof o||Array.isArray(o)?t[r]=String(o):s.push([o,r])}}}}return t}function N(e,t,s){const n=null==s?"":String(s),i=t.indexOf(":");if(i>0){const s=t.slice(0,i),r=o[s];if(r)return void(e.getAttributeNS(r,t)!==n&&e.setAttributeNS(r,t,n))}e.getAttribute(t)!==n&&e.setAttribute(t,n)}function K(e,t,s,n){const i=r[t]||t;if(t.startsWith("data-")||t.startsWith("aria-"))return null==s?void(e.hasAttribute(t)&&e.removeAttribute(t)):void N(e,t,s);if(a.has(t))return void N(e,t,s);if(l.has(t)&&null!=s)return void function(e,t){f(e,`srcdoc:${String(t)}`,'[Solely] Blocked "srcdoc" binding (HTML injection risk). Use a sandboxed iframe with "src" instead.')}(e,s);if((h.has(t)||h.has(i))&&function(e){return"string"==typeof e&&p.test(e.replace(/\s+/g,""))}(s))return void function(e,t,s){f(e,`${t}:${String(s)}`,`[Solely] Blocked unsafe URL for "${t}": ${String(s).slice(0,80)}. Use a http(s)/relative URL instead.`)}(e,t,s);const o=e,c=o.tagName;if(null!=s){if("src"===i||"href"===i){const t=String(s);if(o[i]===t||e.getAttribute(i)===t)return}if("value"!==i||"INPUT"!==c&&"TEXTAREA"!==c||o.value!==s)if("boolean"!=typeof s)(n??(e instanceof SVGElement||void 0!==o.ownerSVGElement))&&!r[t]?N(e,t,s):o[i]!==s&&(o[i]=s);else{if(o[i]===s)return;o[i]=s}}else if("boolean"==typeof o[i])!1!==o[i]&&(o[i]=!1);else{const s=o[i];""!==s&&void 0!==s&&(o[i]=""),e.hasAttribute(t)&&e.removeAttribute(t)}}class S{constructor(e,t,s={}){this.ir=e,this.container=t,this.scope=s}ir;container;scope;nodeMap=new Map;prevNodeMap=new Map;pathStack=[];pathKey="";staticSubtreeCache=new Map;keepaliveCache=new Map;currentKaKey=null;kaDepth=0;isKaRestoring=!1;rafIds=new Set;keepaliveAccessCounter=0;maxKeepalive=20;renderedKaKeys=new Set;scheduleRaf(e){const t=requestAnimationFrame(()=>{this.rafIds.delete(t),e()});return this.rafIds.add(t),t}pushPath(e){this.pathStack.push(e),this.pathKey=this.pathStack.join(".")}popPath(){this.pathStack.pop(),this.pathKey=this.pathStack.join(".")}evalIR(e,n,i){const o=this.ir.fns[e-1];if(s)try{return o?o.apply(this.scope,n):""}catch(r){return t(r.message||r.toString(),this.ir.m?.src||"",i,this.scope.tagName),""}return o?o.apply(this.scope,n):""}createElement(e,t){const s=e.g??"";return t instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):n(e.x||"");return document.createTextNode(s)}createComment(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):e.x||"";return document.createComment(s)}removeEventListenersFromNode(e){const t=u.get(e);if(t)for(const[s,n]of Object.entries(t.events))n.listener&&e.removeEventListener(s,n.listener)}applyAttrs(e,t,s,n=!1,i=!1){const o=[],r=m(e),a=e instanceof SVGElement||void 0!==e.ownerSVGElement;let h;r.loops=s;let l,p=!1,d=!1;for(const f of t){const{k:t,f:u,d:m,v:v}=f;if(":class"===t){h=this.evalIR(u??-1,[s],f.__m),p=!0;continue}if(":style"===t){l=this.evalIR(u??-1,[s],f.__m),d=!0;continue}if("class"===t||"style"===t)continue;const y=t[0];if("@"===y){const s=t.slice(1),i=f.r??"user";let o=r.events[s];if(!o){o={model:[],user:[],listener:null};const t=e=>{for(const t of o.model)t(e);for(const t of o.user)t(e)};o.listener=t,e.addEventListener(s,t),r.events[s]=o}if(!n){const e=e=>this.evalIR(u??-1,[e,r.loops],f.__m);o[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("ref"===t&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=e;continue}const g=m?this.evalIR(u??-1,[s],f.__m):v??"";if(":"===y){const s=t.slice(1);"SELECT"===e.tagName&&c.has(s)?o.push(()=>K(e,s,g,a)):K(e,s,g,a)}else n||N(e,t,String(g))}return p&&((e,t)=>{const s=m(e),n=s.prevClassObj,i=function(e){const t={},s=[e];for(;s.length;){const e=s.pop();if(e)if("string"==typeof e){const s=e.split(" ");for(let e=0;e<s.length;e++){const n=s[e].trim();n&&(t[n]=!0)}}else if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push(e[t]);else if("object"==typeof e){const s=e;for(const e in s)s[e]&&(t[e]=!0)}}return t}(t),o={};for(const c in i)g(c)&&(o[c]=i[c]);if(!n){const t=[];for(const e in o)t.push(e);return t.length&&e.classList.add(...t),void(s.prevClassObj=o)}const r=[],a=[];for(const c in n)o[c]||a.push(c);for(const c in o)n[c]||r.push(c);(r.length||a.length)&&(r.length&&e.classList.add(...r),a.length&&e.classList.remove(...a),s.prevClassObj=o)})(e,h),d&&((e,t)=>{const s=m(e),n=k(t),i=s.prevStyleObj;if(!i){for(const t in n){const s=n[t];t.startsWith("--")?e.style.setProperty(t,s):e.style[t]=s}return void(s.prevStyleObj=n)}let o=!1;for(const r in i)r in n||(r.startsWith("--")?e.style.removeProperty(r):e.style[r]="",o=!0);for(const r in n){const t=n[r];t!==i[r]&&(r.startsWith("--")?e.style.setProperty(r,t):e.style[r]=t,o=!0)}o&&(s.prevStyleObj=n)})(e,l),o}updateNode(e,t,s){const n=t.d?this.evalIR(t.f??-1,[s],t.__m):t.x||"";t.d&&e.textContent!==n&&(e.textContent=n)}createStaticSubtree(t,s,n){switch(t.t){case e.Element:{const e=this.createElement(t,s);v(e,t),y(e,t);const i=this.applyAttrs(e,t.a??[],n);return t.c?.forEach(t=>{const s=this.createStaticSubtree(t,e,n);e.appendChild(s)}),i.forEach(e=>e()),e}case e.Text:return this.createText(t,n);case e.Comment:return this.createComment(t,n);default:return document.createComment("unknown")}}handleStaticSubtree(e,t,s,n){const i=this.staticSubtreeCache.get(t);if(i){const e=i.cloneNode(!0);return s.appendChild(e),e}const o=this.createStaticSubtree(e,s,n);return s.appendChild(o),this.staticSubtreeCache.set(t,o.cloneNode(!0)),o}currentKey(){return this.pathKey}findEntry(e){let t=this.nodeMap.get(e);return t||(t=this.prevNodeMap.get(e),t&&(this.prevNodeMap.delete(e),this.nodeMap.set(e,t))),t}registerNode(e,t,s,n){const i=this.currentKaKey?{irNode:t,node:s,loops:n,kaKey:this.currentKaKey}:{irNode:t,node:s,loops:n};this.nodeMap.set(e,i)}processNode(t,n,i){const o=this.currentKey(),r=this.findEntry(o);let a;if(1!==t.s)if(r){a=r.node;let s=[];t.d&&(t.t===e.Element?s=this.applyAttrs(a,t.a??[],i,!0,this.isKaRestoring):this.updateNode(a,t,i)),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),s.forEach(e=>e())}else switch(t.t){case e.Element:a=this.createElement(t,n),v(a,t),y(a,t);const r=this.applyAttrs(a,t.a??[],i);n.appendChild(a),this.registerNode(o,t,a,i),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),r.forEach(e=>e());break;case e.Text:a=this.createText(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.Comment:a=this.createComment(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.For:{this.pushPath(-1);const s=this.currentKey();this.popPath();let o=this.findEntry(s)?.node;o||(o=document.createComment("for"),n.appendChild(o),this.registerNode(s,{t:e.Comment},o,i));const r=this.evalIR(t.f??-1,[i],t.__m)||[],a=document.createDocumentFragment();r.forEach((e,s)=>{const n=[...i,{itmVal:e,idxVal:s}];t.c?.forEach((e,t)=>{this.pushPath(s),this.pushPath(t),this.processNode(e,a,n),this.popPath(),this.popPath()})}),o.parentNode?.insertBefore(a,o);break}case e.Conditional:{this.pushPath(-1);const e=this.currentKey();this.popPath();let o=this.findEntry(e)?.node;o||(o=document.createComment("if"),n.appendChild(o),this.registerNode(e,{},o,i));for(let r=0;r<(t.b||[]).length;r++){const e=t.b?.[r];if(null===e.f||this.evalIR(e.f,[i],e.__m)){this.pushPath(r);const t=this.currentKey();if(this.popPath(),1===e.ka){this.renderedKaKeys.add(t);const a=this.keepaliveCache.get(t);if(a&&!a.active){o.parentNode?.insertBefore(a.fragment,o);for(const[e,t]of a.entries)this.prevNodeMap.set(e,t);a.active=!0,a.lastUsed=++this.keepaliveAccessCounter;const c=this.isKaRestoring;this.isKaRestoring=!0;const h=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly."),e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()}),this.kaDepth--,this.currentKaKey=h,this.isKaRestoring=c}else{a&&a.active&&(a.lastUsed=++this.keepaliveAccessCounter);const c=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly.");const h=t+".0";if(this.prevNodeMap.get(h))e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()});else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}this.kaDepth--,this.currentKaKey=c}}else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}break}}break}}else r?a=r.node:(a=this.handleStaticSubtree(t,o,n,i),this.registerNode(o,t,a,i))}evictKeepaliveIfNeeded(){let e=0;for(const[,n]of this.keepaliveCache.entries())n.active||e++;if(e<=this.maxKeepalive)return;let t=null,s=1/0;for(const[n,i]of this.keepaliveCache.entries())i.active||i.lastUsed<s&&(s=i.lastUsed,t=n);if(t){const e=this.keepaliveCache.get(t);for(const[,t]of e.entries){if(this.removeEventListenersFromNode(t.node),t.irNode.a){const e=t.irNode.a.find(e=>"unmounted"===e.k);e&&this.scheduleRaf(()=>{this.evalIR(e.f??-1,[t.node,t.loops],e.__m)})}t.node?.remove()}this.keepaliveCache.delete(t)}}cleanupOldNodes(){const e=this.prevNodeMap,t=new Map;for(const[s,n]of e.entries()){const{irNode:e,node:i,loops:o}=n,r=n.kaKey&&this.renderedKaKeys.has(n.kaKey);if(e.a){if(n.kaKey&&!r){const t=e.a.find(e=>"deactivated"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}else{const t=e.a.find(e=>"unmounted"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}const t=e.a.find(e=>"ref"===e.k);t&&t.v&&delete this.scope.$refs[t.v]}if(n.kaKey&&!r&&i.parentNode){let e=t.get(n.kaKey);e||(e={fragment:document.createDocumentFragment(),entries:[]},t.set(n.kaKey,e));const o=n.kaKey.split(".").length;s.split(".").length===o+1&&e.fragment.appendChild(i),e.entries.push([s,n])}else this.removeEventListenersFromNode(i),i?.remove()}for(const[s,n]of t.entries()){const e=this.keepaliveCache.get(s);e&&e.active?(e.fragment=n.fragment,e.entries=n.entries,e.active=!1,e.lastUsed=++this.keepaliveAccessCounter):e||this.keepaliveCache.set(s,{fragment:n.fragment,entries:n.entries,lastUsed:++this.keepaliveAccessCounter,active:!1})}this.evictKeepaliveIfNeeded(),e.clear()}mount(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}update(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}destroy(){this.rafIds.forEach(e=>cancelAnimationFrame(e)),this.rafIds.clear();const e=e=>{for(const[,t]of e.entries())this.removeEventListenersFromNode(t.node)};e(this.nodeMap),e(this.prevNodeMap);for(const[,t]of this.keepaliveCache.entries())for(const[,e]of t.entries){if(this.removeEventListenersFromNode(e.node),e.irNode.a){const t=e.irNode.a.find(e=>"unmounted"===e.k);t&&this.evalIR(t.f??-1,[e.node,e.loops],t.__m)}e.node?.remove()}this.container.innerHTML="",this.scope.$refs={},this.nodeMap.clear(),this.prevNodeMap.clear(),this.staticSubtreeCache.clear(),this.keepaliveCache.clear(),this.renderedKaKeys.clear()}irToNode(e,t,s,n){this.pushPath(t),this.processNode(e,s,n),this.popPath()}}const b=(e,t,s={})=>{const n=new S(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};export{S as IRRenderer,b as createRender};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./env.cjs"),t=new Set(["aria-activedescendant","aria-details","aria-error-message"]),n=new WeakMap,o=new WeakMap;let i=0;function r(e="solely-aria"){return`${e}-${++i}`}function s(e){return!!e&&"object"==typeof e&&1===e.nodeType}function l(e,n,o){0!==o.ids.length?t.has(n)?e.setAttribute(n,o.ids[o.ids.length-1]):e.setAttribute(n,function(e,t){const n=[];if(e)for(const o of e.split(/\s+/))o&&n.push(o);for(const o of t)n.includes(o)||n.push(o);return n.join(" ")}(o.original,o.ids)):null===o.original?e.removeAttribute(n):e.setAttribute(n,o.original)}exports.assertSameTree=function(t,n){const o=t.getRootNode()===n.getRootNode();return!o&&e.IS_DEV&&console.warn("[Solely] ARIA IDREF 引用方与被引用方不在同一棵树,已使用代理节点。"),o},exports.createAriaId=r,exports.linkAria=function(t,i,d,u={}){const c=s(d)?d:null,a=s(d)?null:d;let p=u.id??a?.id??c?.id??"";p||(p=r(),c&&(c.id=p));const f=u.role??a?.role??c?.getAttribute("role")??void 0,g=u.content??a?.content??(c?c.textContent??"":""),h=!!c&&c.getRootNode()===t.getRootNode(),b=function(e,t){let n=o.get(e);n||(n=new Map,o.set(e,n));let i=n.get(t);return i||(i={original:e.getAttribute(t),ids:[]},n.set(t,i)),i}(t,i);b.ids.push(p),l(t,i,b);let m=null,x=null;const y=t.ownerDocument??("undefined"!=typeof document?document:null);h||(x=u.container??function(e){const t=e.getRootNode();if(9===t.nodeType){const e=t;return e.body??e.documentElement??null}if(11===t.nodeType&&t.host)return t;const n=e.ownerDocument;return n?.body??n?.documentElement??null}(t),x&&y?m=function(e,t,o,i,r){let s=n.get(e);s||(s=new Map,n.set(e,s));let l=s.get(o);if(l)l.node.textContent=r,void 0!==i&&l.node.setAttribute("role",i),l.node.isConnected||e.appendChild(l.node);else{const n=t.createElement("div");n.id=o,n.style.cssText="position:fixed;top:0;left:0;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;",n.textContent=r,void 0!==i&&n.setAttribute("role",i),e.appendChild(n),l={node:n,refs:0},s.set(o,l)}return l.refs++,l}(x,y,p,f,g):e.IS_DEV&&console.warn(`[Solely] 无法为 ${i} 创建 IDREF 代理:缺少目标树容器。`));let w=!1;return{id:p,get proxy(){return m?m.node:null},update(e,t){!w&&m&&(m.node.textContent=e,void 0!==t&&m.node.setAttribute("role",t))},release(){w||(w=!0,function(e,t,n){const i=o.get(e),r=i?.get(t);if(!i||!r)return;const s=r.ids.indexOf(n);s>=0&&r.ids.splice(s,1),l(e,t,r),0===r.ids.length&&(i.delete(t),0===i.size&&o.delete(e))}(t,i,p),m&&x&&function(e,t){const o=n.get(e),i=o?.get(t);o&&i&&(i.refs--,i.refs>0||(i.node.remove(),o.delete(t),0===o.size&&n.delete(e)))}(x,p))}}};
@@ -0,0 +1,67 @@
1
+ /**
2
+ * ARIA IDREF 代理基座(0.8.0 框架层 F-3)
3
+ *
4
+ * 问题:ARIA 的 IDREF 属性(`aria-describedby` / `aria-labelledby` /
5
+ * `aria-controls` / `aria-activedescendant` 等)只在引用元素所属的树内解析。
6
+ * 当被引用 id 位于 shadow root 内、引用方位于 light DOM 或另一棵树时,
7
+ * 浏览器不会跨树查找,`document.getElementById()` 也查不到 shadow 内节点。
8
+ *
9
+ * 解决:被引用方(source)与引用方(target)不同树时,在 target 所在树内
10
+ * 创建一个视觉隐藏的代理节点,承载同一个 id、role 与文本内容,并让 target
11
+ * 的 aria 属性引用该代理 id。source 与 target 同树时直接引用原节点,不创建
12
+ * 代理,避免同树出现重复 id。
13
+ *
14
+ * 生命周期契约:
15
+ * - `linkAria()` 创建代理并挂上 aria 属性;
16
+ * - `release()` 移除代理,并精确还原 target 原有的 aria 属性(原本不存在时移除属性);
17
+ * - 代理按“容器 + id”共享引用计数,多个 target 引用同一 id 时不会产生重复 id;
18
+ * - 单值 IDREF(`aria-activedescendant` / `aria-details` / `aria-error-message`)
19
+ * 链接期间临时覆盖为用户值,释放后还原;多值 IDREF 则在原值基础上追加。
20
+ *
21
+ * 说明:jsdom 不构建无障碍树,本模块用“id 可在引用方根节点内被解析”作为断言,
22
+ * 与浏览器 IDREF 的树作用域规则一致。
23
+ */
24
+ /** 可代理的 ARIA IDREF 属性;同时允许传入其它 `aria-*` 字符串 */
25
+ export type AriaIdRefAttribute = 'aria-describedby' | 'aria-labelledby' | 'aria-controls' | 'aria-activedescendant' | (string & {});
26
+ /** 描述 source 的最小信息;用于 source 不是真实元素、只有逻辑 id 的场景 */
27
+ export interface AriaSourceSpec {
28
+ /** 被引用 id;缺省时自动生成 */
29
+ id?: string;
30
+ /** 代理节点 role;缺省沿用 source 元素的 role */
31
+ role?: string;
32
+ /** 代理节点文本内容;缺省沿用 source 元素的 textContent */
33
+ content?: string;
34
+ }
35
+ export interface LinkAriaOptions {
36
+ /** 代理节点 id;优先于 source.id,主要供“只有逻辑 id”的组件使用 */
37
+ id?: string;
38
+ /** 覆盖代理 role */
39
+ role?: string;
40
+ /** 覆盖代理文本内容 */
41
+ content?: string;
42
+ /** 代理插入容器;缺省按 target 的根节点推导 */
43
+ container?: Node | null;
44
+ }
45
+ export interface AriaLinkHandle {
46
+ /** 实际被引用的 id(写入 target 的 aria 属性) */
47
+ readonly id: string;
48
+ /** 代理节点;同树直连时为 null */
49
+ readonly proxy: HTMLElement | null;
50
+ /** 更新代理内容/role;同树直连时为空操作 */
51
+ update(content: string, role?: string): void;
52
+ /** 解除链接:移除代理并精确还原 target 原值;幂等 */
53
+ release(): void;
54
+ }
55
+ /** 生成代理 id;带前缀与自增序号,避免和业务 id 冲突 */
56
+ export declare function createAriaId(prefix?: string): string;
57
+ /** 两节点是否处于同一棵树;dev 模式对跨树引用给出提示 */
58
+ export declare function assertSameTree(a: Node, b: Node): boolean;
59
+ /**
60
+ * 建立一条 ARIA IDREF 关联。
61
+ *
62
+ * - `source` 为元素且与 `target` 同树:直接引用 source 的 id,不创建代理;
63
+ * - 否则在 target 所在树内创建代理节点,承载 id / role / 文本内容;
64
+ * - 返回的 handle 必须由调用方在“被描述内容隐藏/销毁”时 `release()`,
65
+ * 以保证读屏不会拿到过期描述。
66
+ */
67
+ export declare function linkAria(target: Element, attr: AriaIdRefAttribute, source: Element | AriaSourceSpec, options?: LinkAriaOptions): AriaLinkHandle;
@@ -0,0 +1 @@
1
+ import{IS_DEV as e}from"./env.js";const t=new Set(["aria-activedescendant","aria-details","aria-error-message"]),n=new WeakMap,o=new WeakMap;let i=0;function r(e="solely-aria"){return`${e}-${++i}`}function d(e){return!!e&&"object"==typeof e&&1===e.nodeType}function l(t,n){const o=t.getRootNode()===n.getRootNode();return!o&&e&&console.warn("[Solely] ARIA IDREF 引用方与被引用方不在同一棵树,已使用代理节点。"),o}function s(e,n,o){0!==o.ids.length?t.has(n)?e.setAttribute(n,o.ids[o.ids.length-1]):e.setAttribute(n,function(e,t){const n=[];if(e)for(const o of e.split(/\s+/))o&&n.push(o);for(const o of t)n.includes(o)||n.push(o);return n.join(" ")}(o.original,o.ids)):null===o.original?e.removeAttribute(n):e.setAttribute(n,o.original)}function u(t,i,l,u={}){const c=d(l)?l:null,a=d(l)?null:l;let p=u.id??a?.id??c?.id??"";p||(p=r(),c&&(c.id=p));const f=u.role??a?.role??c?.getAttribute("role")??void 0,g=u.content??a?.content??(c?c.textContent??"":""),h=!!c&&c.getRootNode()===t.getRootNode(),m=function(e,t){let n=o.get(e);n||(n=new Map,o.set(e,n));let i=n.get(t);return i||(i={original:e.getAttribute(t),ids:[]},n.set(t,i)),i}(t,i);m.ids.push(p),s(t,i,m);let b=null,w=null;const x=t.ownerDocument??("undefined"!=typeof document?document:null);h||(w=u.container??function(e){const t=e.getRootNode();if(9===t.nodeType){const e=t;return e.body??e.documentElement??null}if(11===t.nodeType&&t.host)return t;const n=e.ownerDocument;return n?.body??n?.documentElement??null}(t),w&&x?b=function(e,t,o,i,r){let d=n.get(e);d||(d=new Map,n.set(e,d));let l=d.get(o);if(l)l.node.textContent=r,void 0!==i&&l.node.setAttribute("role",i),l.node.isConnected||e.appendChild(l.node);else{const n=t.createElement("div");n.id=o,n.style.cssText="position:fixed;top:0;left:0;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;",n.textContent=r,void 0!==i&&n.setAttribute("role",i),e.appendChild(n),l={node:n,refs:0},d.set(o,l)}return l.refs++,l}(w,x,p,f,g):e&&console.warn(`[Solely] 无法为 ${i} 创建 IDREF 代理:缺少目标树容器。`));let y=!1;return{id:p,get proxy(){return b?b.node:null},update(e,t){!y&&b&&(b.node.textContent=e,void 0!==t&&b.node.setAttribute("role",t))},release(){y||(y=!0,function(e,t,n){const i=o.get(e),r=i?.get(t);if(!i||!r)return;const d=r.ids.indexOf(n);d>=0&&r.ids.splice(d,1),s(e,t,r),0===r.ids.length&&(i.delete(t),0===i.size&&o.delete(e))}(t,i,p),b&&w&&function(e,t){const o=n.get(e),i=o?.get(t);o&&i&&(i.refs--,i.refs>0||(i.node.remove(),o.delete(t),0===o.size&&n.delete(e)))}(w,p))}}}export{l as assertSameTree,r as createAriaId,u as linkAria};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),exports.parseBooleanAttribute=function(e,t=!1){if(null==e)return t;const r=e.trim().toLowerCase();return!("false"===r||"0"===r)};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 布尔 attribute 统一解析。
3
+ *
4
+ * 与 framework property 路径(normalizePropValue)保持一致的语义:
5
+ * - `"false"` / `"0"`(trim、大小写不敏感)→ false
6
+ * - `""`(仅属性名)及其他字符串 → true
7
+ * - 属性不存在(null / undefined)→ fallback(通常是 manifest 默认值)
8
+ */
9
+ export declare function parseBooleanAttribute(value: string | null | undefined, fallback?: boolean): boolean;
@@ -0,0 +1 @@
1
+ function r(r,t=!1){if(null==r)return t;const e=r.trim().toLowerCase();return!("false"===e||"0"===e)}export{r as parseBooleanAttribute};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),exports.PLACEMENTS=["top","bottom","left","right","topLeft","topRight","bottomLeft","bottomRight","leftTop","leftBottom","rightTop","rightBottom"],exports.oneOf=function(t,o,e){return"string"==typeof t&&o.includes(t)?t:e};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 枚举属性白名单
3
+ *
4
+ * 命令式与声明式 API 都可能收到运行时动态值(含非法值),
5
+ * 组件在读取枚举类属性时必须先经过这里回退到默认档位,
6
+ * 避免拼出无 CSS 的死类名、空模板或异常分支。
7
+ */
8
+ export declare function oneOf<T extends string>(value: unknown, allowed: readonly T[], fallback: T): T;
9
+ /** 浮层 12 方位白名单,供命令式组件复用(与 shared/floating/types 的 Placement 一致) */
10
+ export declare const PLACEMENTS: readonly ["top", "bottom", "left", "right", "topLeft", "topRight", "bottomLeft", "bottomRight", "leftTop", "leftBottom", "rightTop", "rightBottom"];
@@ -0,0 +1 @@
1
+ function t(t,o,e){return"string"==typeof t&&o.includes(t)?t:e}const o=["top","bottom","left","right","topLeft","topRight","bottomLeft","bottomRight","leftTop","leftBottom","rightTop","rightBottom"];export{o as PLACEMENTS,t as oneOf};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=(()=>{const e=globalThis;if(!0===e.__IS_PROD__)return!1;if("undefined"!=typeof window){if(window.location?.search.includes("debug"))return!0;if(!0===e.__DEBUG__||!0===e.__IS_DEV__)return!0}const o=e.process?.env?.NODE_ENV;return"production"!==o&&("development"===o||!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes(window.location?.hostname||"")))})(),o=!e;exports.IS_DEV=e,exports.IS_PROD=o,exports.SOLELY_VERSION="0.7.0";
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=(()=>{const e=globalThis;if(!0===e.__IS_PROD__)return!1;if("undefined"!=typeof window){if(window.location?.search.includes("debug"))return!0;if(!0===e.__DEBUG__||!0===e.__IS_DEV__)return!0}const o=e.process?.env?.NODE_ENV;return"production"!==o&&("development"===o||!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes(window.location?.hostname||"")))})(),o=!e;exports.IS_DEV=e,exports.IS_PROD=o,exports.SOLELY_VERSION="0.8.0";
@@ -1 +1 @@
1
- const n=(()=>{const n=globalThis;if(!0===n.__IS_PROD__)return!1;if("undefined"!=typeof window){if(window.location?.search.includes("debug"))return!0;if(!0===n.__DEBUG__||!0===n.__IS_DEV__)return!0}const o=n.process?.env?.NODE_ENV;return"production"!==o&&("development"===o||!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes(window.location?.hostname||"")))})(),o=!n,e="0.7.0";export{n as IS_DEV,o as IS_PROD,e as SOLELY_VERSION};
1
+ const n=(()=>{const n=globalThis;if(!0===n.__IS_PROD__)return!1;if("undefined"!=typeof window){if(window.location?.search.includes("debug"))return!0;if(!0===n.__DEBUG__||!0===n.__IS_DEV__)return!0}const o=n.process?.env?.NODE_ENV;return"production"!==o&&("development"===o||!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes(window.location?.hostname||"")))})(),o=!n,e="0.8.0";export{n as IS_DEV,o as IS_PROD,e as SOLELY_VERSION};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={dropdown:1e3,modal:1050,drawer:1050,popover:1060,tooltip:1070},t=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"[tabindex]"].join(","),n=new Set(["SCRIPT","STYLE","LINK"]),o=[],i=new Set;let r=!1,c=null;function s(e){return!(!e||!e.isConnected||e.closest("[inert]")||e.hasAttribute("hidden")||e.matches(":disabled")||"hidden"===getComputedStyle(e).visibility||0===e.getClientRects().length)}function u(e){return!!s(e)&&(e.tabIndex>=0||!0===e.isContentEditable)}function a(){let e=document.activeElement;for(;e?.shadowRoot?.activeElement;)e=e.shadowRoot.activeElement;return e}function l(e,t){let n=t;for(;n;){if(n===e)return!0;if(n.parentNode){n=n.parentNode;continue}const t="function"==typeof n.getRootNode?n.getRootNode():null;n=t instanceof ShadowRoot?t.host:null}return!1}function d(e){if(!e||"function"!=typeof e.focus)return!1;try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{return!1}}const t=a();return!!t&&(t===e||l(e,t))}function f(e){return Array.from(e.querySelectorAll(t)).filter(u)}function p(e){const t=e.container;t.hasAttribute("tabindex")||t.tabIndex>=0||t.isContentEditable||(t.setAttribute("tabindex","-1"),e.autoTabIndex=!0)}function m(e){if(!e.isComposing){if("Escape"===e.key){const t=function(){const e=[];for(let t=o.length-1;t>=0;t--){const n=o[t];if(!1===n.options.escClosable)continue;const i="passthrough"!==n.options.escClosable;if(e.push({layer:n,consume:i}),i)break}return e}();if(0===t.length)return;let n=!1;for(const{layer:e,consume:o}of t)if(e.options.onEscape?.(),o){n=!0;break}return void(n&&(e.preventDefault(),e.stopPropagation()))}if("Tab"===e.key){let t;for(let e=o.length-1;e>=0;e--)if(!0===o[e].options.trapFocus){t=o[e];break}if(!t)return;!function(e,t){const n=f(e.container),o=a(),i=!!o&&o!==e.container&&l(e.container,o);if(0===n.length)return t.preventDefault(),p(e),void d(e.container);const r=n[0],c=n[n.length-1];t.shiftKey?i&&o!==r||(t.preventDefault(),d(c)):i&&o!==c||(t.preventDefault(),d(r))}(t,e)}}}function b(){if("undefined"==typeof document)return;const e=o.length>0;e&&!r?(document.addEventListener("keydown",m,!0),r=!0):!e&&r&&(document.removeEventListener("keydown",m,!0),r=!1)}let h=0,y=null,v=null;function g(){if("undefined"==typeof document||!document.body)return()=>{};if(h+=1,1===h){const e=document.body;y=e.style.overflow,v=e.style.paddingRight;const t=window.innerWidth-document.documentElement.clientWidth;if(e.style.overflow="hidden",t>0){const n=Number.parseFloat(getComputedStyle(e).paddingRight)||0;e.style.paddingRight=`${n+t}px`}}let e=!1;return()=>{e||(e=!0,h=Math.max(0,h-1),h>0||null!==y&&null!==v&&(document.body.style.overflow=y,document.body.style.paddingRight=v,y=null,v=null))}}const E=new Map,F=new Map;function x(e,t){return t===e||l(e,t)}function w(e){return o[o.length-1]===e}function S(e){const t=o.indexOf(e);-1!==t&&o.splice(t,1)}function C(){if("undefined"==typeof document||"undefined"==typeof MutationObserver)return;const e=function(){for(const e of i)if(e.releaseScroll||e.inertElements)return!0;return!1}();e&&!c?(c=new MutationObserver(()=>{I()}),c.observe(document.documentElement,{childList:!0,subtree:!0})):!e&&c&&(c.disconnect(),c=null)}function I(){const e=[];i.forEach(t=>{t.containerWasConnected&&!t.container.isConnected&&e.push(t)}),0!==e.length&&(e.forEach(e=>k(e)),C())}let A=!1;function T(){A||(A=!0,queueMicrotask(()=>{A=!1,I()}))}function R(t){if("disposed"===t.state)return void console.warn("[solely] 已 dispose 的浮层句柄不能再次 activate。");if("active"===t.state)return;if(T(),!i.has(t))return;const r="idle"===t.state;if(t.state="active",t.wasTopWhenClosed=!1,t.container.isConnected&&(t.containerWasConnected=!0),t.zIndex=function(t,n){const o=function(t){const n=e[t];if("undefined"==typeof document||!document.documentElement)return n;const o=getComputedStyle(document.documentElement).getPropertyValue(`--solely-z-index-${t}`).trim();if(!o)return n;const i=Number.parseInt(o,10);return Number.isFinite(i)&&i>0?i:n}(t);let r=0;i.forEach(e=>{e!==n&&"disposed"!==e.state&&e.zIndex>r&&(r=e.zIndex)});const c=Math.max(o,r+10);return c>=1990&&o<1990?(console.warn(`[solely] 浮层 z-index 已达 ${c},回绕到 ${o}。`),o):c}(t.options.kind,t),r){const e=a();t.previousFocus=e&&e!==document.body?e:null}if(t.container.style.zIndex=String(t.zIndex),function(e){e.onFocus||(e.onFocus=t=>{const n=t.target;n&&l(e.container,n)&&(e.lastFocus=n)},e.container.addEventListener("focusin",e.onFocus,!0),e.container.addEventListener("focus",e.onFocus,!0))}(t),o.push(t),b(),r&&(!0===t.options.lockScroll&&(t.releaseScroll=g()),!0===t.options.inertBackground&&function(e,t){e.inertElements=new Set(t);const n="undefined"!=typeof HTMLElement&&"inert"in HTMLElement.prototype;t.forEach(e=>{const t=E.get(e)??0;E.set(e,t+1),t>0||(F.set(e,{inert:e.hasAttribute("inert"),ariaHidden:e.getAttribute("aria-hidden")}),e.setAttribute("inert",""),n||e.setAttribute("aria-hidden","true"))})}(t,function(e){const t=function(e){const t=e.getRootNode();return"undefined"!=typeof document&&t===document?document.body:"undefined"!=typeof ShadowRoot&&t instanceof ShadowRoot?t:null}(e.container);if(!t)return[];const o=new Set;i.forEach(t=>{t!==e&&o.add(t.container)});const r=[],c="undefined"!=typeof document&&t===document.body;return Array.from(t.children).forEach(t=>{if(t!==e.container&&!o.has(t)){if(c){if(n.has(t.tagName.toUpperCase()))return;if(t.matches("[aria-live]"))return;if(t.classList.contains("solely-message-container"))return}r.push(t)}}),r}(t))),C(),!1!==t.options.autoFocus){!function(e){const t=function(e){const{initialFocus:t}=e.options;return t?"function"==typeof t?t():t:null}(e);if(s(t)&&d(t))return;const n=e.container.querySelector("[autofocus]");if(u(n)&&d(n))return;const o=f(e.container)[0];o&&d(o)||(p(e),d(e.container))}(t);const e=a();e&&l(t.container,e)&&(t.lastFocus=e)}}function k(e){if("disposed"===e.state)return;const t="active"===e.state,n=t?w(e):e.wasTopWhenClosed;t&&S(e),e.state="disposed",i.delete(e),b();const r=a();r&&l(e.container,r)&&(e.lastFocus=r),function(e){const t=e.previousFocus;i.forEach(n=>{if(n===e)return;const o=n.previousFocus;o&&x(e.container,o)&&(n.previousFocus=t),n.lastFocus&&x(e.container,n.lastFocus)&&(n.lastFocus=t)})}(e),function(e){e.inertElements&&(e.inertElements.forEach(e=>{const t=E.get(e)??0;if(t>1)return void E.set(e,t-1);E.delete(e);const n=F.get(e);F.delete(e),n?(n.inert||e.removeAttribute("inert"),null===n.ariaHidden?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",n.ariaHidden)):e.removeAttribute("inert")}),e.inertElements=null)}(e),e.releaseScroll&&(e.releaseScroll(),e.releaseScroll=null),function(e){e.onFocus&&(e.container.removeEventListener("focusin",e.onFocus,!0),e.container.removeEventListener("focus",e.onFocus,!0),e.onFocus=null)}(e),function(e,t){if(!1===e.options.returnFocus)return!1;if(!t)return!1;const n=a();return!n||n===document.body||l(e.container,n)}(e,n)&&function(e){const t=o[o.length-1],n=[e.options.trigger??null,e.previousFocus,t?t.lastFocus:null,t?t.container:null,t?t.options.trigger??null:null,t?t.previousFocus:null];for(const o of n)if(s(o)&&d(o))return;const i=a();i&&i!==document.body&&"function"==typeof i.blur&&i.blur()}(e),e.autoTabIndex&&"-1"===e.container.getAttribute("tabindex")&&e.container.removeAttribute("tabindex"),e.autoTabIndex=!1,C()}exports.lockScroll=g,exports.registerOverlay=function(e){T();const t={options:e,container:e.container,state:"idle",zIndex:0,previousFocus:null,lastFocus:null,wasTopWhenClosed:!1,releaseScroll:null,inertElements:null,onFocus:null,autoTabIndex:!1,containerWasConnected:e.container.isConnected};return i.add(t),!1===e.escClosable||e.onEscape||console.warn(`[solely] ${e.kind} 浮层设置了 escClosable 但缺少 onEscape,Esc 将无效。`),C(),{activate(){R(t)},deactivate(){!function(e){"active"===e.state&&(e.wasTopWhenClosed=w(e),S(e),e.state="inactive",b(),C())}(t)},dispose(){k(t)},isTop:()=>w(t),getZIndex:()=>t.zIndex}};
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 浮层栈基座:Esc / 焦点 / 滚动锁 / z-index / inert
3
+ *
4
+ * 约束见 `docs/architecture/contracts.md`(浮层部分);完整编号版见本地审计材料 `docs/internal/design-contracts.md`(不入库)。
5
+ *
6
+ * 本模块已接线到 tooltip / select / popconfirm / modal / drawer:
7
+ * - 全库唯一的 `document` capture 阶段 `keydown` 监听在这里。
8
+ * - 类型按任务要求内联在本文件,不依赖 `./types.ts`(另一会话并行创建中)。
9
+ */
10
+ export type OverlayKind = 'modal' | 'drawer' | 'popover' | 'dropdown' | 'tooltip';
11
+ export interface OverlayOptions {
12
+ kind: OverlayKind;
13
+ /** 接收 Tab / 焦点 / 初始聚焦的节点,也是浮层根节点 */
14
+ container: HTMLElement;
15
+ /** 打开者,用于焦点还原 */
16
+ trigger?: HTMLElement | null;
17
+ /**
18
+ * Esc 行为:
19
+ * - `true`(默认):关闭当前层并消费 Esc(preventDefault + stopPropagation)
20
+ * - `false`:不响应 Esc,继续向下找
21
+ * - `'passthrough'`:关闭当前层但不消费,Esc 继续向下传递(tooltip)
22
+ */
23
+ escClosable?: boolean | 'passthrough';
24
+ /** 默认 false;仅 modal/drawer 打开 */
25
+ trapFocus?: boolean;
26
+ /** 默认 false;仅 modal/drawer 打开 */
27
+ lockScroll?: boolean;
28
+ /** 默认 false;仅 modal/drawer 打开 */
29
+ inertBackground?: boolean;
30
+ /** 默认 true;select 下拉传 false,焦点留在宿主 */
31
+ autoFocus?: boolean;
32
+ /** 默认 true */
33
+ returnFocus?: boolean;
34
+ initialFocus?: HTMLElement | (() => HTMLElement | null);
35
+ /** 仅 escClosable !== false 的层需要提供 */
36
+ onEscape?: () => void;
37
+ }
38
+ export interface OverlayHandle {
39
+ /** 打开:分配 z-index、入栈、聚焦、加锁 */
40
+ activate(): void;
41
+ /** 开始关闭:出栈,停止 Esc / Tab 陷阱;保留锁与 inert */
42
+ deactivate(): void;
43
+ /** 动画结束:还原焦点,释放锁与 inert */
44
+ dispose(): void;
45
+ isTop(): boolean;
46
+ getZIndex(): number;
47
+ }
48
+ /**
49
+ * 引用计数滚动锁;返回的 unlock 幂等,且只在最后一个锁释放时精确还原内联值。
50
+ */
51
+ export declare function lockScroll(): () => void;
52
+ /**
53
+ * 注册浮层。返回的 handle 由组件在 open/close 时序中驱动:
54
+ * open → activate;关闭动画开始 → deactivate;动画结束 → dispose。
55
+ */
56
+ export declare function registerOverlay(options: OverlayOptions): OverlayHandle;
@@ -0,0 +1 @@
1
+ const e={dropdown:1e3,modal:1050,drawer:1050,popover:1060,tooltip:1070},t=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"[tabindex]"].join(","),n=new Set(["SCRIPT","STYLE","LINK"]),o=[],i=new Set;let r=!1,c=null;function s(e){return!(!e||!e.isConnected||e.closest("[inert]")||e.hasAttribute("hidden")||e.matches(":disabled")||"hidden"===getComputedStyle(e).visibility||0===e.getClientRects().length)}function u(e){return!!s(e)&&(e.tabIndex>=0||!0===e.isContentEditable)}function a(){let e=document.activeElement;for(;e?.shadowRoot?.activeElement;)e=e.shadowRoot.activeElement;return e}function l(e,t){let n=t;for(;n;){if(n===e)return!0;if(n.parentNode){n=n.parentNode;continue}const t="function"==typeof n.getRootNode?n.getRootNode():null;n=t instanceof ShadowRoot?t.host:null}return!1}function d(e){if(!e||"function"!=typeof e.focus)return!1;try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{return!1}}const t=a();return!!t&&(t===e||l(e,t))}function f(e){return Array.from(e.querySelectorAll(t)).filter(u)}function p(e){const t=e.container;t.hasAttribute("tabindex")||t.tabIndex>=0||t.isContentEditable||(t.setAttribute("tabindex","-1"),e.autoTabIndex=!0)}function m(e){if(!e.isComposing){if("Escape"===e.key){const t=function(){const e=[];for(let t=o.length-1;t>=0;t--){const n=o[t];if(!1===n.options.escClosable)continue;const i="passthrough"!==n.options.escClosable;if(e.push({layer:n,consume:i}),i)break}return e}();if(0===t.length)return;let n=!1;for(const{layer:e,consume:o}of t)if(e.options.onEscape?.(),o){n=!0;break}return void(n&&(e.preventDefault(),e.stopPropagation()))}if("Tab"===e.key){let t;for(let e=o.length-1;e>=0;e--)if(!0===o[e].options.trapFocus){t=o[e];break}if(!t)return;!function(e,t){const n=f(e.container),o=a(),i=!!o&&o!==e.container&&l(e.container,o);if(0===n.length)return t.preventDefault(),p(e),void d(e.container);const r=n[0],c=n[n.length-1];t.shiftKey?i&&o!==r||(t.preventDefault(),d(c)):i&&o!==c||(t.preventDefault(),d(r))}(t,e)}}}function h(){if("undefined"==typeof document)return;const e=o.length>0;e&&!r?(document.addEventListener("keydown",m,!0),r=!0):!e&&r&&(document.removeEventListener("keydown",m,!0),r=!1)}let b=0,y=null,v=null;function g(){if("undefined"==typeof document||!document.body)return()=>{};if(b+=1,1===b){const e=document.body;y=e.style.overflow,v=e.style.paddingRight;const t=window.innerWidth-document.documentElement.clientWidth;if(e.style.overflow="hidden",t>0){const n=Number.parseFloat(getComputedStyle(e).paddingRight)||0;e.style.paddingRight=`${n+t}px`}}let e=!1;return()=>{e||(e=!0,b=Math.max(0,b-1),b>0||null!==y&&null!==v&&(document.body.style.overflow=y,document.body.style.paddingRight=v,y=null,v=null))}}const E=new Map,F=new Map;function w(e,t){return t===e||l(e,t)}function x(e){return o[o.length-1]===e}function C(e){const t=o.indexOf(e);-1!==t&&o.splice(t,1)}function S(){if("undefined"==typeof document||"undefined"==typeof MutationObserver)return;const e=function(){for(const e of i)if(e.releaseScroll||e.inertElements)return!0;return!1}();e&&!c?(c=new MutationObserver(()=>{I()}),c.observe(document.documentElement,{childList:!0,subtree:!0})):!e&&c&&(c.disconnect(),c=null)}function I(){const e=[];i.forEach(t=>{t.containerWasConnected&&!t.container.isConnected&&e.push(t)}),0!==e.length&&(e.forEach(e=>k(e)),S())}let A=!1;function R(){A||(A=!0,queueMicrotask(()=>{A=!1,I()}))}function T(t){if("disposed"===t.state)return void console.warn("[solely] 已 dispose 的浮层句柄不能再次 activate。");if("active"===t.state)return;if(R(),!i.has(t))return;const r="idle"===t.state;if(t.state="active",t.wasTopWhenClosed=!1,t.container.isConnected&&(t.containerWasConnected=!0),t.zIndex=function(t,n){const o=function(t){const n=e[t];if("undefined"==typeof document||!document.documentElement)return n;const o=getComputedStyle(document.documentElement).getPropertyValue(`--solely-z-index-${t}`).trim();if(!o)return n;const i=Number.parseInt(o,10);return Number.isFinite(i)&&i>0?i:n}(t);let r=0;i.forEach(e=>{e!==n&&"disposed"!==e.state&&e.zIndex>r&&(r=e.zIndex)});const c=Math.max(o,r+10);return c>=1990&&o<1990?(console.warn(`[solely] 浮层 z-index 已达 ${c},回绕到 ${o}。`),o):c}(t.options.kind,t),r){const e=a();t.previousFocus=e&&e!==document.body?e:null}if(t.container.style.zIndex=String(t.zIndex),function(e){e.onFocus||(e.onFocus=t=>{const n=t.target;n&&l(e.container,n)&&(e.lastFocus=n)},e.container.addEventListener("focusin",e.onFocus,!0),e.container.addEventListener("focus",e.onFocus,!0))}(t),o.push(t),h(),r&&(!0===t.options.lockScroll&&(t.releaseScroll=g()),!0===t.options.inertBackground&&function(e,t){e.inertElements=new Set(t);const n="undefined"!=typeof HTMLElement&&"inert"in HTMLElement.prototype;t.forEach(e=>{const t=E.get(e)??0;E.set(e,t+1),t>0||(F.set(e,{inert:e.hasAttribute("inert"),ariaHidden:e.getAttribute("aria-hidden")}),e.setAttribute("inert",""),n||e.setAttribute("aria-hidden","true"))})}(t,function(e){const t=function(e){const t=e.getRootNode();return"undefined"!=typeof document&&t===document?document.body:"undefined"!=typeof ShadowRoot&&t instanceof ShadowRoot?t:null}(e.container);if(!t)return[];const o=new Set;i.forEach(t=>{t!==e&&o.add(t.container)});const r=[],c="undefined"!=typeof document&&t===document.body;return Array.from(t.children).forEach(t=>{if(t!==e.container&&!o.has(t)){if(c){if(n.has(t.tagName.toUpperCase()))return;if(t.matches("[aria-live]"))return;if(t.classList.contains("solely-message-container"))return}r.push(t)}}),r}(t))),S(),!1!==t.options.autoFocus){!function(e){const t=function(e){const{initialFocus:t}=e.options;return t?"function"==typeof t?t():t:null}(e);if(s(t)&&d(t))return;const n=e.container.querySelector("[autofocus]");if(u(n)&&d(n))return;const o=f(e.container)[0];o&&d(o)||(p(e),d(e.container))}(t);const e=a();e&&l(t.container,e)&&(t.lastFocus=e)}}function k(e){if("disposed"===e.state)return;const t="active"===e.state,n=t?x(e):e.wasTopWhenClosed;t&&C(e),e.state="disposed",i.delete(e),h();const r=a();r&&l(e.container,r)&&(e.lastFocus=r),function(e){const t=e.previousFocus;i.forEach(n=>{if(n===e)return;const o=n.previousFocus;o&&w(e.container,o)&&(n.previousFocus=t),n.lastFocus&&w(e.container,n.lastFocus)&&(n.lastFocus=t)})}(e),function(e){e.inertElements&&(e.inertElements.forEach(e=>{const t=E.get(e)??0;if(t>1)return void E.set(e,t-1);E.delete(e);const n=F.get(e);F.delete(e),n?(n.inert||e.removeAttribute("inert"),null===n.ariaHidden?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",n.ariaHidden)):e.removeAttribute("inert")}),e.inertElements=null)}(e),e.releaseScroll&&(e.releaseScroll(),e.releaseScroll=null),function(e){e.onFocus&&(e.container.removeEventListener("focusin",e.onFocus,!0),e.container.removeEventListener("focus",e.onFocus,!0),e.onFocus=null)}(e),function(e,t){if(!1===e.options.returnFocus)return!1;if(!t)return!1;const n=a();return!n||n===document.body||l(e.container,n)}(e,n)&&function(e){const t=o[o.length-1],n=[e.options.trigger??null,e.previousFocus,t?t.lastFocus:null,t?t.container:null,t?t.options.trigger??null:null,t?t.previousFocus:null];for(const o of n)if(s(o)&&d(o))return;const i=a();i&&i!==document.body&&"function"==typeof i.blur&&i.blur()}(e),e.autoTabIndex&&"-1"===e.container.getAttribute("tabindex")&&e.container.removeAttribute("tabindex"),e.autoTabIndex=!1,S()}function L(e){R();const t={options:e,container:e.container,state:"idle",zIndex:0,previousFocus:null,lastFocus:null,wasTopWhenClosed:!1,releaseScroll:null,inertElements:null,onFocus:null,autoTabIndex:!1,containerWasConnected:e.container.isConnected};return i.add(t),!1===e.escClosable||e.onEscape||console.warn(`[solely] ${e.kind} 浮层设置了 escClosable 但缺少 onEscape,Esc 将无效。`),S(),{activate(){T(t)},deactivate(){!function(e){"active"===e.state&&(e.wasTopWhenClosed=x(e),C(e),e.state="inactive",h(),S())}(t)},dispose(){k(t)},isTop:()=>x(t),getZIndex:()=>t.zIndex}}export{g as lockScroll,L as registerOverlay};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=8,e=8,o={top:{side:"top",align:"center"},topLeft:{side:"top",align:"start"},topRight:{side:"top",align:"end"},bottom:{side:"bottom",align:"center"},bottomLeft:{side:"bottom",align:"start"},bottomRight:{side:"bottom",align:"end"},left:{side:"left",align:"center"},leftTop:{side:"left",align:"start"},leftBottom:{side:"left",align:"end"},right:{side:"right",align:"center"},rightTop:{side:"right",align:"start"},rightBottom:{side:"right",align:"end"}},n={top:{center:"top",start:"topLeft",end:"topRight"},bottom:{center:"bottom",start:"bottomLeft",end:"bottomRight"},left:{center:"left",start:"leftTop",end:"leftBottom"},right:{center:"right",start:"rightTop",end:"rightBottom"}},i=t=>"top"===t||"bottom"===t,r={top:"bottom",bottom:"top",left:"right",right:"left"},s=(t,e,n,r)=>{const{side:s,align:l}=o[t],d=e.left+(e.width-n.width)/2,c=e.top+(e.height-n.height)/2;if(i(s))return{x:"center"===l?d:"start"===l?e.left:e.right-n.width,y:"top"===s?e.top-n.height-r:e.bottom+r};const h="center"===l?c:"start"===l?e.top:e.bottom-n.height;return{x:"left"===s?e.left-n.width-r:e.right+r,y:h}},l=(t,e,o,n)=>Math.max(0,n-t,t+e-(o-n)),d=(t,e,n,r,s)=>{const{side:d}=o[e];return i(d)?l(t.y,n.height,r.height,s):l(t.x,n.width,r.width,s)},c=(t,e,o,n)=>{const i=o-e-n;return i<n?n:Math.min(Math.max(t,n),i)},h=new Set;let a=null,p=!1,f=null;function g(t){const e=w(t.anchor),o=t.scrollTargets;if(e.length!==o.length||!e.every((t,e)=>t===o[e])){for(const e of o)e.removeEventListener("scroll",t.onScroll,!0);for(const o of e)o.addEventListener("scroll",t.onScroll,{capture:!0,passive:!0});t.scrollTargets=e}}function m(){a=null;for(const t of Array.from(h))t.stopped||(t.anchor.isConnected?t.floating.isConnected&&(g(t),t.update()):t.onAnchorLost?.())}function u(){null===a&&(a="function"!=typeof requestAnimationFrame?setTimeout(m,16):requestAnimationFrame(m))}function w(t){const e=[];let o=t.parentNode;for(;o&&o!==document;){e.push(o);const t=o.parentNode;if(t){o=t;continue}const n=o.host;o=n?n.parentNode:null}return e}exports.DEFAULT_BOUNDARY_PADDING=e,exports.DEFAULT_OFFSET=t,exports.computePosition=(h,a,p)=>{const{placement:f,viewport:g,offset:m=t,boundaryPadding:u=e,flip:w=!0,shift:b=!0,strategy:v="fixed",container:y}=p,x={top:(T=h).top,left:T.left,width:T.width,height:T.height,right:T.right??T.left+T.width,bottom:T.bottom??T.top+T.height};var T;const L="auto"===f?((t,e,o,n,i)=>{const r=[{placement:"top",space:t.top-i,need:e.height+n},{placement:"bottom",space:o.height-t.bottom-i,need:e.height+n},{placement:"right",space:o.width-t.right-i,need:e.width+n},{placement:"left",space:t.left-i,need:e.width+n}];let s,l=Number.NEGATIVE_INFINITY,d="top",c=Number.POSITIVE_INFINITY;for(const h of r){const t=h.need-h.space;t<=0&&h.space>l&&(s=h.placement,l=h.space),t<c&&(d=h.placement,c=t)}return s??d})(x,a,g,m,u):f;let E=L,N=s(L,x,a,m),I=d(N,L,a,g,u),A=!1;const S=[L];if(w&&I>0){const t=(t=>{const{side:e,align:i}=o[t];return n[(t=>r[t])(e)][i]})(L);S.push(t);const e=s(t,x,a,m),i=d(e,t,a,g,u);i<I&&(E=t,N=e,I=i,A=!0)}b&&(i(o[E].side)?N.x=c(N.x,a.width,g.width,u):N.y=c(N.y,a.height,g.height,u)),i(o[E].side)?N.y=c(N.y,a.height,g.height,u):N.x=c(N.x,a.width,g.width,u);const F=((t,e,n,r,s)=>{const{side:d}=o[e];return i(d)?l(t.x,n.width,r.width,s):l(t.y,n.height,r.height,s)})(N,E,a,g,u),R=((t,e,n,r)=>{const{side:s,align:l}=o[t],d=i(s),c=d?r.width:r.height,h=d?e.x:e.y,a=d?n.left:n.top,p=d?n.right:n.bottom;let f;f="start"===l?a+16:"end"===l?p-16:(a+p)/2;const g=((t,e)=>{const o=e-8;return o<=8?e/2:Math.min(Math.max(t,8),o)})(f-h,c);return d?{x:g}:{y:g}})(E,N,x,a);let M=N.x,O=N.y;return"absolute"===v&&y&&(M=M-y.rect.left+(y.scrollLeft??0)-(y.clientLeft??0),O=O-y.rect.top+(y.scrollTop??0)-(y.clientTop??0)),{x:M,y:O,top:O,left:M,placement:E,arrow:R,overflow:{main:I,cross:F},flipState:{requested:f,preferred:L,final:E,flipped:A,tried:S}}},exports.observePosition=function(t){if("undefined"==typeof window)return()=>{};const e=()=>u(),o=w(t.anchor);for(const i of o)i.addEventListener("scroll",e,{capture:!0,passive:!0});const n={...t,stopped:!1,scrollTargets:o,onScroll:e};return h.add(n),p||"undefined"==typeof window||(p=!0,window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),"undefined"!=typeof ResizeObserver&&(f=new ResizeObserver(u))),f?.observe(t.anchor),f?.observe(t.floating),()=>{if(!n.stopped){n.stopped=!0,h.delete(n);for(const t of n.scrollTargets)t.removeEventListener("scroll",e,!0);f?.unobserve(t.anchor),f?.unobserve(t.floating),0===h.size&&p&&"undefined"!=typeof window&&(p=!1,window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u),f?.disconnect(),f=null)}}};
@@ -0,0 +1,32 @@
1
+ import { ComputeOptions, PositionResult, RectLike, Size } from './types.js';
2
+ /** 锚点与浮层默认间距 */
3
+ export declare const DEFAULT_OFFSET = 8;
4
+ /** 与视口边界默认内边距 */
5
+ export declare const DEFAULT_BOUNDARY_PADDING = 8;
6
+ /**
7
+ * 计算浮层坐标
8
+ *
9
+ * @param anchorRect 锚点矩形(`getBoundingClientRect()` 结果或等价数据)
10
+ * @param floatingSize 浮层尺寸
11
+ * @param options 期望方位、视口、偏移、边界与坐标策略
12
+ */
13
+ export declare const computePosition: (anchorRect: RectLike, floatingSize: Size, options: ComputeOptions) => PositionResult;
14
+ export interface ObservePositionOptions {
15
+ /** 锚点:位置变化时触发重新计算 */
16
+ anchor: HTMLElement;
17
+ /** 浮层:尺寸变化时触发重新计算 */
18
+ floating: HTMLElement;
19
+ /** 重新定位回调;由调用方自行读取几何并调用 `computePosition` */
20
+ update: () => void;
21
+ /** 锚点从文档中移除时的回调(例如滚动容器中被删除) */
22
+ onAnchorLost?: () => void;
23
+ }
24
+ /**
25
+ * 订阅锚点/浮层的位置与尺寸变化。
26
+ *
27
+ * 全局 window / resize / ResizeObserver 复用一组监听与单一 rAF 批处理;
28
+ * 每个订阅对滚动祖先使用独立的监听函数:同一祖先被多个浮层共享时,
29
+ * `addEventListener` 会按函数引用去重,若共用一个引用,任一订阅清理都会
30
+ * 摘掉其他订阅的监听,导致其余浮层滚动后不再重定位。
31
+ */
32
+ export declare function observePosition(options: ObservePositionOptions): () => void;
@@ -0,0 +1 @@
1
+ const t=8,e=8,o={top:{side:"top",align:"center"},topLeft:{side:"top",align:"start"},topRight:{side:"top",align:"end"},bottom:{side:"bottom",align:"center"},bottomLeft:{side:"bottom",align:"start"},bottomRight:{side:"bottom",align:"end"},left:{side:"left",align:"center"},leftTop:{side:"left",align:"start"},leftBottom:{side:"left",align:"end"},right:{side:"right",align:"center"},rightTop:{side:"right",align:"start"},rightBottom:{side:"right",align:"end"}},n={top:{center:"top",start:"topLeft",end:"topRight"},bottom:{center:"bottom",start:"bottomLeft",end:"bottomRight"},left:{center:"left",start:"leftTop",end:"leftBottom"},right:{center:"right",start:"rightTop",end:"rightBottom"}},i=t=>"top"===t||"bottom"===t,r={top:"bottom",bottom:"top",left:"right",right:"left"},s=(t,e,n,r)=>{const{side:s,align:l}=o[t],d=e.left+(e.width-n.width)/2,h=e.top+(e.height-n.height)/2;if(i(s))return{x:"center"===l?d:"start"===l?e.left:e.right-n.width,y:"top"===s?e.top-n.height-r:e.bottom+r};const c="center"===l?h:"start"===l?e.top:e.bottom-n.height;return{x:"left"===s?e.left-n.width-r:e.right+r,y:c}},l=(t,e,o,n)=>Math.max(0,n-t,t+e-(o-n)),d=(t,e,n,r,s)=>{const{side:d}=o[e];return i(d)?l(t.y,n.height,r.height,s):l(t.x,n.width,r.width,s)},h=(t,e,o,n)=>{const i=o-e-n;return i<n?n:Math.min(Math.max(t,n),i)},c=(c,a,f)=>{const{placement:p,viewport:g,offset:m=t,boundaryPadding:u=e,flip:w=!0,shift:b=!0,strategy:v="fixed",container:y}=f,x={top:(L=c).top,left:L.left,width:L.width,height:L.height,right:L.right??L.left+L.width,bottom:L.bottom??L.top+L.height};var L;const T="auto"===p?((t,e,o,n,i)=>{const r=[{placement:"top",space:t.top-i,need:e.height+n},{placement:"bottom",space:o.height-t.bottom-i,need:e.height+n},{placement:"right",space:o.width-t.right-i,need:e.width+n},{placement:"left",space:t.left-i,need:e.width+n}];let s,l=Number.NEGATIVE_INFINITY,d="top",h=Number.POSITIVE_INFINITY;for(const c of r){const t=c.need-c.space;t<=0&&c.space>l&&(s=c.placement,l=c.space),t<h&&(d=c.placement,h=t)}return s??d})(x,a,g,m,u):p;let E=T,N=s(T,x,a,m),I=d(N,T,a,g,u),R=!1;const S=[T];if(w&&I>0){const t=(t=>{const{side:e,align:i}=o[t];return n[(t=>r[t])(e)][i]})(T);S.push(t);const e=s(t,x,a,m),i=d(e,t,a,g,u);i<I&&(E=t,N=e,I=i,R=!0)}b&&(i(o[E].side)?N.x=h(N.x,a.width,g.width,u):N.y=h(N.y,a.height,g.height,u)),i(o[E].side)?N.y=h(N.y,a.height,g.height,u):N.x=h(N.x,a.width,g.width,u);const z=((t,e,n,r,s)=>{const{side:d}=o[e];return i(d)?l(t.x,n.width,r.width,s):l(t.y,n.height,r.height,s)})(N,E,a,g,u),A=((t,e,n,r)=>{const{side:s,align:l}=o[t],d=i(s),h=d?r.width:r.height,c=d?e.x:e.y,a=d?n.left:n.top,f=d?n.right:n.bottom;let p;p="start"===l?a+16:"end"===l?f-16:(a+f)/2;const g=((t,e)=>{const o=e-8;return o<=8?e/2:Math.min(Math.max(t,8),o)})(p-c,h);return d?{x:g}:{y:g}})(E,N,x,a);let M=N.x,B=N.y;return"absolute"===v&&y&&(M=M-y.rect.left+(y.scrollLeft??0)-(y.clientLeft??0),B=B-y.rect.top+(y.scrollTop??0)-(y.clientTop??0)),{x:M,y:B,top:B,left:M,placement:E,arrow:A,overflow:{main:I,cross:z},flipState:{requested:p,preferred:T,final:E,flipped:R,tried:S}}},a=new Set;let f=null,p=!1,g=null;function m(t){const e=b(t.anchor),o=t.scrollTargets;if(e.length!==o.length||!e.every((t,e)=>t===o[e])){for(const e of o)e.removeEventListener("scroll",t.onScroll,!0);for(const o of e)o.addEventListener("scroll",t.onScroll,{capture:!0,passive:!0});t.scrollTargets=e}}function u(){f=null;for(const t of Array.from(a))t.stopped||(t.anchor.isConnected?t.floating.isConnected&&(m(t),t.update()):t.onAnchorLost?.())}function w(){null===f&&(f="function"!=typeof requestAnimationFrame?setTimeout(u,16):requestAnimationFrame(u))}function b(t){const e=[];let o=t.parentNode;for(;o&&o!==document;){e.push(o);const t=o.parentNode;if(t){o=t;continue}const n=o.host;o=n?n.parentNode:null}return e}function v(t){if("undefined"==typeof window)return()=>{};const e=()=>w(),o=b(t.anchor);for(const i of o)i.addEventListener("scroll",e,{capture:!0,passive:!0});const n={...t,stopped:!1,scrollTargets:o,onScroll:e};return a.add(n),p||"undefined"==typeof window||(p=!0,window.addEventListener("scroll",w,!0),window.addEventListener("resize",w),"undefined"!=typeof ResizeObserver&&(g=new ResizeObserver(w))),g?.observe(t.anchor),g?.observe(t.floating),()=>{if(!n.stopped){n.stopped=!0,a.delete(n);for(const t of n.scrollTargets)t.removeEventListener("scroll",e,!0);g?.unobserve(t.anchor),g?.unobserve(t.floating),0===a.size&&p&&"undefined"!=typeof window&&(p=!1,window.removeEventListener("scroll",w,!0),window.removeEventListener("resize",w),g?.disconnect(),g=null)}}}export{e as DEFAULT_BOUNDARY_PADDING,t as DEFAULT_OFFSET,c as computePosition,v as observePosition};