@saolabs/client 1.0.0 → 1.1.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 (383) hide show
  1. package/README.md +52 -195
  2. package/dist/index.d.ts +20 -5
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +14 -3
  5. package/dist/index.js.map +1 -1
  6. package/dist/plugins.d.ts +2 -2
  7. package/dist/plugins.js +2 -2
  8. package/dist/src/core/app/Application.d.ts +25 -15
  9. package/dist/src/core/app/Application.d.ts.map +1 -1
  10. package/dist/src/core/app/Application.js +55 -18
  11. package/dist/src/core/app/Application.js.map +1 -1
  12. package/dist/src/core/bootstrap/app.d.ts +1 -1
  13. package/dist/src/core/bootstrap/app.d.ts.map +1 -1
  14. package/dist/src/core/bootstrap/app.js +77 -4
  15. package/dist/src/core/bootstrap/app.js.map +1 -1
  16. package/dist/src/core/bootstrap/bundle.d.ts +41 -0
  17. package/dist/src/core/bootstrap/bundle.d.ts.map +1 -0
  18. package/dist/src/core/bootstrap/bundle.js +98 -0
  19. package/dist/src/core/bootstrap/bundle.js.map +1 -0
  20. package/dist/src/core/bootstrap/providers/ApiServiceProvider.d.ts +1 -1
  21. package/dist/src/core/bootstrap/providers/ApiServiceProvider.d.ts.map +1 -1
  22. package/dist/src/core/bootstrap/providers/ApiServiceProvider.js +3 -3
  23. package/dist/src/core/bootstrap/providers/ApiServiceProvider.js.map +1 -1
  24. package/dist/src/core/bootstrap/providers/CoreServiceProvider.d.ts +1 -1
  25. package/dist/src/core/bootstrap/providers/CoreServiceProvider.d.ts.map +1 -1
  26. package/dist/src/core/bootstrap/providers/CoreServiceProvider.js +11 -8
  27. package/dist/src/core/bootstrap/providers/CoreServiceProvider.js.map +1 -1
  28. package/dist/src/core/bootstrap/providers/HelperServiceProvider.d.ts +3 -1
  29. package/dist/src/core/bootstrap/providers/HelperServiceProvider.d.ts.map +1 -1
  30. package/dist/src/core/bootstrap/providers/HelperServiceProvider.js +8 -3
  31. package/dist/src/core/bootstrap/providers/HelperServiceProvider.js.map +1 -1
  32. package/dist/src/core/bootstrap/providers/RouteServiceProvider.d.ts +2 -1
  33. package/dist/src/core/bootstrap/providers/RouteServiceProvider.d.ts.map +1 -1
  34. package/dist/src/core/bootstrap/providers/RouteServiceProvider.js +14 -4
  35. package/dist/src/core/bootstrap/providers/RouteServiceProvider.js.map +1 -1
  36. package/dist/src/core/bootstrap/providers/ServiceProvider.d.ts +4 -4
  37. package/dist/src/core/bootstrap/providers/ServiceProvider.d.ts.map +1 -1
  38. package/dist/src/core/bootstrap/providers/ServiceProvider.js +5 -5
  39. package/dist/src/core/bootstrap/providers/ServiceProvider.js.map +1 -1
  40. package/dist/src/core/bootstrap/providers/ViewServiceProvider.d.ts +1 -1
  41. package/dist/src/core/bootstrap/providers/ViewServiceProvider.d.ts.map +1 -1
  42. package/dist/src/core/bootstrap/providers/ViewServiceProvider.js +3 -3
  43. package/dist/src/core/bootstrap/providers/ViewServiceProvider.js.map +1 -1
  44. package/dist/src/core/bootstrap/providers/default-providers.d.ts +1 -1
  45. package/dist/src/core/bootstrap/providers/default-providers.d.ts.map +1 -1
  46. package/dist/src/core/bootstrap/providers/default-providers.js +44 -11
  47. package/dist/src/core/bootstrap/providers/default-providers.js.map +1 -1
  48. package/dist/src/core/bootstrap/providers/index.d.ts +9 -9
  49. package/dist/src/core/bootstrap/providers/index.d.ts.map +1 -1
  50. package/dist/src/core/bootstrap/providers/index.js +8 -8
  51. package/dist/src/core/bootstrap/providers/index.js.map +1 -1
  52. package/dist/src/core/bootstrap/providers/provider-order.d.ts +1 -1
  53. package/dist/src/core/bootstrap/providers/provider-order.d.ts.map +1 -1
  54. package/dist/src/core/bootstrap/ssr.d.ts +47 -0
  55. package/dist/src/core/bootstrap/ssr.d.ts.map +1 -0
  56. package/dist/src/core/bootstrap/ssr.js +129 -0
  57. package/dist/src/core/bootstrap/ssr.js.map +1 -0
  58. package/dist/src/core/cache/ViewCache.d.ts +1 -1
  59. package/dist/src/core/cache/ViewCache.d.ts.map +1 -1
  60. package/dist/src/core/cache/index.d.ts +1 -1
  61. package/dist/src/core/cache/index.d.ts.map +1 -1
  62. package/dist/src/core/cache/index.js +1 -1
  63. package/dist/src/core/cache/index.js.map +1 -1
  64. package/dist/src/core/contracts/ApplicationInterface.d.ts +15 -11
  65. package/dist/src/core/contracts/ApplicationInterface.d.ts.map +1 -1
  66. package/dist/src/core/contracts/BlockInterface.d.ts +10 -10
  67. package/dist/src/core/contracts/BlockInterface.d.ts.map +1 -1
  68. package/dist/src/core/contracts/BundleInterface.d.ts +38 -0
  69. package/dist/src/core/contracts/BundleInterface.d.ts.map +1 -0
  70. package/dist/src/core/contracts/BundleInterface.js +2 -0
  71. package/dist/src/core/contracts/BundleInterface.js.map +1 -0
  72. package/dist/src/core/contracts/ComponentInterface.d.ts +7 -6
  73. package/dist/src/core/contracts/ComponentInterface.d.ts.map +1 -1
  74. package/dist/src/core/contracts/ElementInterface.d.ts +91 -27
  75. package/dist/src/core/contracts/ElementInterface.d.ts.map +1 -1
  76. package/dist/src/core/contracts/HeadServiceInterface.d.ts +37 -0
  77. package/dist/src/core/contracts/HeadServiceInterface.d.ts.map +1 -0
  78. package/dist/src/core/contracts/HeadServiceInterface.js +3 -0
  79. package/dist/src/core/contracts/HeadServiceInterface.js.map +1 -0
  80. package/dist/src/core/contracts/HelperInterface.d.ts +9 -1
  81. package/dist/src/core/contracts/HelperInterface.d.ts.map +1 -1
  82. package/dist/src/core/contracts/HttpServiceInterface.d.ts +3 -0
  83. package/dist/src/core/contracts/HttpServiceInterface.d.ts.map +1 -1
  84. package/dist/src/core/contracts/MarkerInterface.d.ts +29 -44
  85. package/dist/src/core/contracts/MarkerInterface.d.ts.map +1 -1
  86. package/dist/src/core/contracts/ReactiveInterface.d.ts +9 -9
  87. package/dist/src/core/contracts/ReactiveInterface.d.ts.map +1 -1
  88. package/dist/src/core/contracts/RouterInterface.d.ts +5 -2
  89. package/dist/src/core/contracts/RouterInterface.d.ts.map +1 -1
  90. package/dist/src/core/contracts/SectionInterface.d.ts +48 -0
  91. package/dist/src/core/contracts/SectionInterface.d.ts.map +1 -0
  92. package/dist/src/core/contracts/SectionInterface.js +2 -0
  93. package/dist/src/core/contracts/SectionInterface.js.map +1 -0
  94. package/dist/src/core/contracts/ServiceProviderInterface.d.ts +3 -3
  95. package/dist/src/core/contracts/ServiceProviderInterface.d.ts.map +1 -1
  96. package/dist/src/core/contracts/ViewControllerInterface.d.ts +116 -15
  97. package/dist/src/core/contracts/ViewControllerInterface.d.ts.map +1 -1
  98. package/dist/src/core/contracts/ViewInterface.d.ts +31 -5
  99. package/dist/src/core/contracts/ViewInterface.d.ts.map +1 -1
  100. package/dist/src/core/contracts/ViewManagerInterface.d.ts +47 -5
  101. package/dist/src/core/contracts/ViewManagerInterface.d.ts.map +1 -1
  102. package/dist/src/core/contracts/ViewStateInterface.d.ts +39 -2
  103. package/dist/src/core/contracts/ViewStateInterface.d.ts.map +1 -1
  104. package/dist/src/core/contracts/common.d.ts +3 -3
  105. package/dist/src/core/contracts/common.js +3 -3
  106. package/dist/src/core/contracts/utils.d.ts +19 -19
  107. package/dist/src/core/contracts/utils.d.ts.map +1 -1
  108. package/dist/src/core/contracts/views.d.ts +1 -22
  109. package/dist/src/core/contracts/views.d.ts.map +1 -1
  110. package/dist/src/core/devtools/hook.d.ts +66 -0
  111. package/dist/src/core/devtools/hook.d.ts.map +1 -0
  112. package/dist/src/core/devtools/hook.js +114 -0
  113. package/dist/src/core/devtools/hook.js.map +1 -0
  114. package/dist/src/core/devtools/index.d.ts +34 -0
  115. package/dist/src/core/devtools/index.d.ts.map +1 -0
  116. package/dist/src/core/devtools/index.js +33 -0
  117. package/dist/src/core/devtools/index.js.map +1 -0
  118. package/dist/src/core/devtools/inspector.d.ts +31 -0
  119. package/dist/src/core/devtools/inspector.d.ts.map +1 -0
  120. package/dist/src/core/devtools/inspector.js +249 -0
  121. package/dist/src/core/devtools/inspector.js.map +1 -0
  122. package/dist/src/core/elements/Block.d.ts +9 -7
  123. package/dist/src/core/elements/Block.d.ts.map +1 -1
  124. package/dist/src/core/elements/Block.js +33 -9
  125. package/dist/src/core/elements/Block.js.map +1 -1
  126. package/dist/src/core/elements/BlockOutlet.d.ts +19 -8
  127. package/dist/src/core/elements/BlockOutlet.d.ts.map +1 -1
  128. package/dist/src/core/elements/BlockOutlet.js +57 -13
  129. package/dist/src/core/elements/BlockOutlet.js.map +1 -1
  130. package/dist/src/core/elements/Component.d.ts +83 -11
  131. package/dist/src/core/elements/Component.d.ts.map +1 -1
  132. package/dist/src/core/elements/Component.js +334 -13
  133. package/dist/src/core/elements/Component.js.map +1 -1
  134. package/dist/src/core/elements/ForeachSlotCache.d.ts +95 -0
  135. package/dist/src/core/elements/ForeachSlotCache.d.ts.map +1 -0
  136. package/dist/src/core/elements/ForeachSlotCache.js +149 -0
  137. package/dist/src/core/elements/ForeachSlotCache.js.map +1 -0
  138. package/dist/src/core/elements/Fragment.d.ts +19 -13
  139. package/dist/src/core/elements/Fragment.d.ts.map +1 -1
  140. package/dist/src/core/elements/Fragment.js +43 -20
  141. package/dist/src/core/elements/Fragment.js.map +1 -1
  142. package/dist/src/core/elements/Html.d.ts +89 -12
  143. package/dist/src/core/elements/Html.d.ts.map +1 -1
  144. package/dist/src/core/elements/Html.js +707 -106
  145. package/dist/src/core/elements/Html.js.map +1 -1
  146. package/dist/src/core/elements/Output.d.ts +34 -10
  147. package/dist/src/core/elements/Output.d.ts.map +1 -1
  148. package/dist/src/core/elements/Output.js +141 -26
  149. package/dist/src/core/elements/Output.js.map +1 -1
  150. package/dist/src/core/elements/Reactive.d.ts +85 -14
  151. package/dist/src/core/elements/Reactive.d.ts.map +1 -1
  152. package/dist/src/core/elements/Reactive.js +315 -41
  153. package/dist/src/core/elements/Reactive.js.map +1 -1
  154. package/dist/src/core/elements/TextElement.d.ts +11 -7
  155. package/dist/src/core/elements/TextElement.d.ts.map +1 -1
  156. package/dist/src/core/elements/TextElement.js +18 -11
  157. package/dist/src/core/elements/TextElement.js.map +1 -1
  158. package/dist/src/core/elements/Wrapper.d.ts +24 -13
  159. package/dist/src/core/elements/Wrapper.d.ts.map +1 -1
  160. package/dist/src/core/elements/Wrapper.js +65 -8
  161. package/dist/src/core/elements/Wrapper.js.map +1 -1
  162. package/dist/src/core/elements/Yield.d.ts +10 -9
  163. package/dist/src/core/elements/Yield.d.ts.map +1 -1
  164. package/dist/src/core/elements/Yield.js +31 -19
  165. package/dist/src/core/elements/Yield.js.map +1 -1
  166. package/dist/src/core/elements/helpers.d.ts +7 -7
  167. package/dist/src/core/elements/helpers.d.ts.map +1 -1
  168. package/dist/src/core/elements/helpers.js +4 -4
  169. package/dist/src/core/elements/index.d.ts +12 -11
  170. package/dist/src/core/elements/index.d.ts.map +1 -1
  171. package/dist/src/core/elements/index.js +12 -11
  172. package/dist/src/core/elements/index.js.map +1 -1
  173. package/dist/src/core/elements/reconcileChildren.d.ts +7 -0
  174. package/dist/src/core/elements/reconcileChildren.d.ts.map +1 -0
  175. package/dist/src/core/elements/reconcileChildren.js +74 -0
  176. package/dist/src/core/elements/reconcileChildren.js.map +1 -0
  177. package/dist/src/core/helpers/ApiClient.d.ts.map +1 -0
  178. package/dist/src/core/{hellpers → helpers}/ApiClient.js +10 -1
  179. package/dist/src/core/helpers/ApiClient.js.map +1 -0
  180. package/dist/src/core/helpers/app.d.ts +3 -0
  181. package/dist/src/core/helpers/app.d.ts.map +1 -0
  182. package/dist/src/core/{hellpers → helpers}/app.js +11 -1
  183. package/dist/src/core/helpers/app.js.map +1 -0
  184. package/dist/src/core/helpers/transition.d.ts +34 -0
  185. package/dist/src/core/helpers/transition.d.ts.map +1 -0
  186. package/dist/src/core/helpers/transition.js +118 -0
  187. package/dist/src/core/helpers/transition.js.map +1 -0
  188. package/dist/src/core/{hellpers → helpers}/utils.d.ts +2 -2
  189. package/dist/src/core/helpers/utils.d.ts.map +1 -0
  190. package/dist/src/core/{hellpers → helpers}/utils.js +4 -4
  191. package/dist/src/core/helpers/utils.js.map +1 -0
  192. package/dist/src/core/helpers/view.d.ts +39 -0
  193. package/dist/src/core/helpers/view.d.ts.map +1 -0
  194. package/dist/src/core/helpers/view.js +286 -0
  195. package/dist/src/core/helpers/view.js.map +1 -0
  196. package/dist/src/core/routers/Router.d.ts +108 -7
  197. package/dist/src/core/routers/Router.d.ts.map +1 -1
  198. package/dist/src/core/routers/Router.js +444 -68
  199. package/dist/src/core/routers/Router.js.map +1 -1
  200. package/dist/src/core/routers/index.d.ts +2 -2
  201. package/dist/src/core/routers/index.d.ts.map +1 -1
  202. package/dist/src/core/routers/index.js +1 -1
  203. package/dist/src/core/routers/index.js.map +1 -1
  204. package/dist/src/core/services/AssetManager.d.ts +112 -0
  205. package/dist/src/core/services/AssetManager.d.ts.map +1 -0
  206. package/dist/src/core/services/AssetManager.js +361 -0
  207. package/dist/src/core/services/AssetManager.js.map +1 -0
  208. package/dist/src/core/services/BlockManager.d.ts +73 -2
  209. package/dist/src/core/services/BlockManager.d.ts.map +1 -1
  210. package/dist/src/core/services/BlockManager.js +270 -48
  211. package/dist/src/core/services/BlockManager.js.map +1 -1
  212. package/dist/src/core/services/DomService.js +3 -3
  213. package/dist/src/core/services/DomService.js.map +1 -1
  214. package/dist/src/core/services/HeadService.d.ts +24 -0
  215. package/dist/src/core/services/HeadService.d.ts.map +1 -0
  216. package/dist/src/core/services/HeadService.js +120 -0
  217. package/dist/src/core/services/HeadService.js.map +1 -0
  218. package/dist/src/core/services/HelperService.d.ts +14 -3
  219. package/dist/src/core/services/HelperService.d.ts.map +1 -1
  220. package/dist/src/core/services/HelperService.js +32 -2
  221. package/dist/src/core/services/HelperService.js.map +1 -1
  222. package/dist/src/core/services/HttpService.d.ts +8 -0
  223. package/dist/src/core/services/HttpService.d.ts.map +1 -1
  224. package/dist/src/core/services/HttpService.js +121 -47
  225. package/dist/src/core/services/HttpService.js.map +1 -1
  226. package/dist/src/core/services/MarkerRegistry.d.ts +51 -8
  227. package/dist/src/core/services/MarkerRegistry.d.ts.map +1 -1
  228. package/dist/src/core/services/MarkerRegistry.js +135 -14
  229. package/dist/src/core/services/MarkerRegistry.js.map +1 -1
  230. package/dist/src/core/services/PageCache.d.ts +101 -0
  231. package/dist/src/core/services/PageCache.d.ts.map +1 -0
  232. package/dist/src/core/services/PageCache.js +184 -0
  233. package/dist/src/core/services/PageCache.js.map +1 -0
  234. package/dist/src/core/services/SectionManager.d.ts +100 -0
  235. package/dist/src/core/services/SectionManager.d.ts.map +1 -0
  236. package/dist/src/core/services/SectionManager.js +408 -0
  237. package/dist/src/core/services/SectionManager.js.map +1 -0
  238. package/dist/src/core/services/StorageService.js +1 -1
  239. package/dist/src/core/services/TranslationService.d.ts +21 -0
  240. package/dist/src/core/services/TranslationService.d.ts.map +1 -0
  241. package/dist/src/core/services/TranslationService.js +95 -0
  242. package/dist/src/core/services/TranslationService.js.map +1 -0
  243. package/dist/src/core/services/index.d.ts +11 -8
  244. package/dist/src/core/services/index.d.ts.map +1 -1
  245. package/dist/src/core/services/index.js +11 -8
  246. package/dist/src/core/services/index.js.map +1 -1
  247. package/dist/src/core/types/utils.d.ts +8 -8
  248. package/dist/src/core/types/utils.d.ts.map +1 -1
  249. package/dist/src/core/view/LoopContext.d.ts +21 -1
  250. package/dist/src/core/view/LoopContext.d.ts.map +1 -1
  251. package/dist/src/core/view/LoopContext.js +36 -0
  252. package/dist/src/core/view/LoopContext.js.map +1 -1
  253. package/dist/src/core/view/ResourceScope.d.ts +38 -0
  254. package/dist/src/core/view/ResourceScope.d.ts.map +1 -0
  255. package/dist/src/core/view/ResourceScope.js +167 -0
  256. package/dist/src/core/view/ResourceScope.js.map +1 -0
  257. package/dist/src/core/view/Section.d.ts +17 -32
  258. package/dist/src/core/view/Section.d.ts.map +1 -1
  259. package/dist/src/core/view/Section.js +14 -55
  260. package/dist/src/core/view/Section.js.map +1 -1
  261. package/dist/src/core/view/View.d.ts +43 -7
  262. package/dist/src/core/view/View.d.ts.map +1 -1
  263. package/dist/src/core/view/View.js +22 -4
  264. package/dist/src/core/view/View.js.map +1 -1
  265. package/dist/src/core/view/ViewController.d.ts +313 -40
  266. package/dist/src/core/view/ViewController.d.ts.map +1 -1
  267. package/dist/src/core/view/ViewController.js +1002 -147
  268. package/dist/src/core/view/ViewController.js.map +1 -1
  269. package/dist/src/core/view/ViewManager.d.ts +318 -27
  270. package/dist/src/core/view/ViewManager.d.ts.map +1 -1
  271. package/dist/src/core/view/ViewManager.js +1199 -258
  272. package/dist/src/core/view/ViewManager.js.map +1 -1
  273. package/dist/src/core/view/ViewState.d.ts +185 -6
  274. package/dist/src/core/view/ViewState.d.ts.map +1 -1
  275. package/dist/src/core/view/ViewState.js +851 -123
  276. package/dist/src/core/view/ViewState.js.map +1 -1
  277. package/dist/src/core/view/index.d.ts +5 -5
  278. package/dist/src/core/view/index.d.ts.map +1 -1
  279. package/dist/src/core/view/index.js +5 -5
  280. package/dist/src/core/view/index.js.map +1 -1
  281. package/dist/src/testing/index.d.ts +69 -0
  282. package/dist/src/testing/index.d.ts.map +1 -0
  283. package/dist/src/testing/index.js +140 -0
  284. package/dist/src/testing/index.js.map +1 -0
  285. package/index.ts +29 -5
  286. package/package.json +30 -21
  287. package/plugins.ts +2 -2
  288. package/src/core/app/Application.ts +72 -31
  289. package/src/core/bootstrap/app.ts +84 -6
  290. package/src/core/bootstrap/bundle.ts +101 -0
  291. package/src/core/bootstrap/providers/ApiServiceProvider.ts +4 -4
  292. package/src/core/bootstrap/providers/CoreServiceProvider.ts +14 -8
  293. package/src/core/bootstrap/providers/HelperServiceProvider.ts +8 -3
  294. package/src/core/bootstrap/providers/RouteServiceProvider.ts +15 -4
  295. package/src/core/bootstrap/providers/ServiceProvider.ts +8 -8
  296. package/src/core/bootstrap/providers/ViewServiceProvider.ts +3 -3
  297. package/src/core/bootstrap/providers/default-providers.ts +51 -16
  298. package/src/core/bootstrap/providers/index.ts +9 -9
  299. package/src/core/bootstrap/providers/provider-order.test.ts +16 -27
  300. package/src/core/bootstrap/providers/provider-order.ts +1 -1
  301. package/src/core/bootstrap/ssr.ts +141 -0
  302. package/src/core/cache/ViewCache.ts +1 -1
  303. package/src/core/cache/index.ts +1 -1
  304. package/src/core/contracts/ApplicationInterface.ts +15 -11
  305. package/src/core/contracts/BlockInterface.ts +18 -18
  306. package/src/core/contracts/BundleInterface.ts +40 -0
  307. package/src/core/contracts/ComponentInterface.ts +7 -6
  308. package/src/core/contracts/ElementInterface.ts +95 -27
  309. package/src/core/contracts/HeadServiceInterface.ts +41 -0
  310. package/src/core/contracts/HelperInterface.ts +9 -1
  311. package/src/core/contracts/HttpServiceInterface.ts +3 -0
  312. package/src/core/contracts/MarkerInterface.ts +22 -49
  313. package/src/core/contracts/ReactiveInterface.ts +9 -9
  314. package/src/core/contracts/RouterInterface.ts +5 -2
  315. package/src/core/contracts/SectionInterface.ts +49 -0
  316. package/src/core/contracts/ServiceProviderInterface.ts +3 -3
  317. package/src/core/contracts/ViewControllerInterface.ts +124 -16
  318. package/src/core/contracts/ViewInterface.ts +34 -5
  319. package/src/core/contracts/ViewManagerInterface.ts +40 -5
  320. package/src/core/contracts/ViewStateInterface.ts +39 -2
  321. package/src/core/contracts/common.ts +3 -3
  322. package/src/core/contracts/utils.ts +19 -19
  323. package/src/core/contracts/views.ts +2 -22
  324. package/src/core/devtools/hook.ts +142 -0
  325. package/src/core/devtools/index.ts +38 -0
  326. package/src/core/devtools/inspector.ts +270 -0
  327. package/src/core/elements/Block.ts +43 -21
  328. package/src/core/elements/BlockOutlet.ts +61 -21
  329. package/src/core/elements/Component.ts +352 -18
  330. package/src/core/elements/ElementManager.ts +9 -9
  331. package/src/core/elements/ForeachSlotCache.ts +170 -0
  332. package/src/core/elements/Fragment.ts +50 -32
  333. package/src/core/elements/Html.ts +696 -117
  334. package/src/core/elements/Output.ts +147 -30
  335. package/src/core/elements/Reactive.ts +329 -52
  336. package/src/core/elements/TextElement.ts +25 -16
  337. package/src/core/elements/Wrapper.ts +84 -18
  338. package/src/core/elements/Yield.ts +35 -24
  339. package/src/core/elements/helpers.ts +12 -12
  340. package/src/core/elements/index.ts +25 -24
  341. package/src/core/elements/reconcileChildren.ts +70 -0
  342. package/src/core/{hellpers → helpers}/ApiClient.ts +8 -1
  343. package/src/core/{hellpers → helpers}/app.ts +13 -2
  344. package/src/core/helpers/transition.ts +127 -0
  345. package/src/core/{hellpers → helpers}/utils.ts +4 -4
  346. package/src/core/helpers/view.ts +283 -0
  347. package/src/core/routers/Router.ts +458 -64
  348. package/src/core/routers/index.ts +2 -2
  349. package/src/core/services/AssetManager.ts +387 -0
  350. package/src/core/services/BlockManager.ts +272 -50
  351. package/src/core/services/DomService.ts +3 -3
  352. package/src/core/services/HeadService.ts +124 -0
  353. package/src/core/services/HelperService.ts +34 -4
  354. package/src/core/services/HttpService.ts +116 -55
  355. package/src/core/services/MarkerRegistry.ts +142 -16
  356. package/src/core/services/PageCache.ts +239 -0
  357. package/src/core/services/SectionManager.ts +387 -0
  358. package/src/core/services/StorageService.ts +1 -1
  359. package/src/core/services/TranslationService.ts +91 -0
  360. package/src/core/services/index.ts +11 -8
  361. package/src/core/types/utils.ts +8 -8
  362. package/src/core/view/LoopContext.ts +38 -1
  363. package/src/core/view/ResourceScope.ts +174 -0
  364. package/src/core/view/Section.ts +21 -68
  365. package/src/core/view/View.ts +57 -8
  366. package/src/core/view/ViewController.ts +1070 -186
  367. package/src/core/view/ViewManager.ts +1346 -272
  368. package/src/core/view/ViewState.ts +834 -116
  369. package/src/core/view/index.ts +5 -5
  370. package/src/testing/index.ts +184 -0
  371. package/dist/src/core/hellpers/ApiClient.d.ts.map +0 -1
  372. package/dist/src/core/hellpers/ApiClient.js.map +0 -1
  373. package/dist/src/core/hellpers/app.d.ts +0 -3
  374. package/dist/src/core/hellpers/app.d.ts.map +0 -1
  375. package/dist/src/core/hellpers/app.js.map +0 -1
  376. package/dist/src/core/hellpers/utils.d.ts.map +0 -1
  377. package/dist/src/core/hellpers/utils.js.map +0 -1
  378. package/dist/src/core/services/MarkerService.d.ts +0 -299
  379. package/dist/src/core/services/MarkerService.d.ts.map +0 -1
  380. package/dist/src/core/services/MarkerService.js +0 -723
  381. package/dist/src/core/services/MarkerService.js.map +0 -1
  382. package/src/core/services/MarkerService.ts +0 -923
  383. /package/dist/src/core/{hellpers → helpers}/ApiClient.d.ts +0 -0
@@ -1,2 +1,2 @@
1
- export { Router, ActiveRoute, useRoute, useParams, useQuery } from './Router';
2
- export type { RouteDefinition, Route, RouteMatch, RouterConfig, NavigationGuard, AfterNavigationHook } from './Router';
1
+ export { Router, ActiveRoute, useRoute, useParams, useQuery } from './Router.js';
2
+ export type { RouteDefinition, Route, RouteMatch, RouterConfig, NavigationGuard, AfterNavigationHook } from './Router.js';
@@ -0,0 +1,387 @@
1
+ /**
2
+ * AssetManager — quản lý insert/remove `<style>` và `<script>` của component (View)
3
+ * vào real DOM theo cơ chế **reference-counting**.
4
+ *
5
+ * Bối cảnh (Component = View — page/layout/super/nested đều là View):
6
+ * Mỗi `.sao` có thể khai báo `<style>` và `<script>` (không phải script
7
+ * `export default` — cái đó là method của component, do compiler gom vào
8
+ * userDefined). Style/link có mặt khi có ÍT NHẤT một instance đang sống;
9
+ * script đã execute được giữ tới teardown để không chạy lại ngoài ý muốn.
10
+ *
11
+ * Quy tắc (theo thiết kế):
12
+ * 1. Global style/link/script dùng identity của chính asset để các View khác
13
+ * path vẫn dùng chung. Scoped style thêm component path vào identity.
14
+ * 2. Insert đúng MỘT lần — khi ref 0 → 1. Các instance sau không insert lại.
15
+ * 3. Style/link remove khi ref 1 → 0; nếu nơi khác còn ref thì phải giữ.
16
+ * 4. Style/link remove khi ref về 0. Script đã execute thì giữ tới teardown
17
+ * document, vì remove tag không hoàn tác side effect và reinsert sẽ chạy lại.
18
+ *
19
+ * Style:
20
+ * - `scoped` → CSS chỉ áp dụng cho subtree của component (prefix selector bằng
21
+ * scope-id ổn định theo path, tag subtree instance bằng attribute tương ứng).
22
+ * - không `scoped` → global, insert nguyên văn vào <head>.
23
+ *
24
+ * Idempotency ở phía instance do `ViewController._assetsLive` đảm bảo (mỗi ctrl
25
+ * acquire/release tối đa một lần mỗi vòng), nên ref-count ở đây luôn cân bằng.
26
+ */
27
+
28
+ /** Một khai báo `<style>` (từ compiler register_data.styles). */
29
+ export interface StyleSpec {
30
+ /** 'code' = inline CSS; 'href' = external stylesheet. */
31
+ type: 'code' | 'href';
32
+ content?: string;
33
+ href?: string;
34
+ /** true → scoped vào component; mặc định false → global. */
35
+ scoped?: boolean;
36
+ id?: string;
37
+ className?: string;
38
+ attributes?: Record<string, any>;
39
+ }
40
+
41
+ /** Một khai báo `<script>` không-export (script thường / external). */
42
+ export interface ScriptSpec {
43
+ /** 'code' = inline JS; 'src' = external script. */
44
+ type: 'code' | 'src';
45
+ content?: string;
46
+ src?: string;
47
+ id?: string;
48
+ className?: string;
49
+ attributes?: Record<string, any>;
50
+ }
51
+
52
+ /** Thuộc tính đánh dấu node do AssetManager tạo (để debug / không đụng node khác). */
53
+ const OWNER_ATTR = 'data-sao-asset';
54
+ /** Attribute scope cho scoped style — value = scopeId của component path. */
55
+ export const SCOPE_ATTR = 'data-sao-scope';
56
+ /** Mốc của `<style>` do server in sẵn (core ViewHelperService::renderHeadAssets). */
57
+ const SSR_STYLE_ATTR = 'data-sao-style';
58
+
59
+ interface AssetRecord {
60
+ refs: number;
61
+ node: HTMLElement | null;
62
+ }
63
+
64
+ export class AssetManagerService {
65
+ /** key = semantic asset identity → record (ref-count + DOM node). */
66
+ private records: Map<string, AssetRecord> = new Map();
67
+ /** Legacy/debug lookup `(path, kind, index)` → semantic asset identity. */
68
+ private leaseKeys: Map<string, string> = new Map();
69
+ /** path → scopeId ổn định (cache để mọi instance dùng chung). */
70
+ private scopeIds: Map<string, string> = new Map();
71
+
72
+ private get headEl(): HTMLElement | null {
73
+ if (typeof document === 'undefined') return null;
74
+ return document.head || document.getElementsByTagName('head')[0] || document.documentElement;
75
+ }
76
+
77
+ // ─── Public API ─────────────────────────────────────────────
78
+
79
+ /**
80
+ * Một instance của `path` vào real DOM → tăng ref các asset; insert khi 0→1.
81
+ * @param subtreeRoots các node gốc của instance — dùng để tag scope cho scoped style.
82
+ */
83
+ acquire(path: string, styles?: StyleSpec[] | null, scripts?: ScriptSpec[] | null, subtreeRoots?: Node[] | null): void {
84
+ if (styles && styles.length) {
85
+ const scopeId = this.scopeIdFor(path, styles);
86
+ styles.forEach((style, idx) => {
87
+ const key = this.styleKey(path, style);
88
+ this.leaseKeys.set(this.leaseKey(path, 'sty', idx), key);
89
+ this.acquireOne(key, () => this.createStyleNode(path, style, scopeId));
90
+ });
91
+ // Tag scope cho subtree của instance này (mỗi instance tự tag — node <style> dùng chung).
92
+ if (scopeId && subtreeRoots && subtreeRoots.length) {
93
+ this.tagScope(subtreeRoots, scopeId);
94
+ }
95
+ }
96
+ if (scripts && scripts.length) {
97
+ scripts.forEach((script, idx) => {
98
+ const key = this.scriptKey(script);
99
+ this.leaseKeys.set(this.leaseKey(path, 'sc', idx), key);
100
+ this.acquireOne(key, () => this.createScriptNode(script));
101
+ });
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Một instance của `path` rời real DOM → giảm ref; style/link remove khi 1→0.
107
+ */
108
+ release(path: string, styles?: StyleSpec[] | null, scripts?: ScriptSpec[] | null): void {
109
+ if (styles && styles.length) {
110
+ styles.forEach((style) => this.releaseOne(this.styleKey(path, style), true));
111
+ }
112
+ if (scripts && scripts.length) {
113
+ scripts.forEach((script) => this.releaseOne(this.scriptKey(script), false));
114
+ }
115
+ }
116
+
117
+ /** Tổng số node asset đang trong DOM (test/debug). */
118
+ activeCount(): number {
119
+ let n = 0;
120
+ for (const rec of this.records.values()) if (rec.node) n++;
121
+ return n;
122
+ }
123
+
124
+ /** Ref-count hiện tại của một asset (test/debug). */
125
+ refCount(path: string, kind: 'sty' | 'sc', index: number): number {
126
+ const key = this.leaseKeys.get(this.leaseKey(path, kind, index));
127
+ return key ? this.records.get(key)?.refs ?? 0 : 0;
128
+ }
129
+
130
+ /** Dọn sạch — gỡ mọi node, reset (teardown app/test). */
131
+ clear(): void {
132
+ for (const rec of this.records.values()) {
133
+ rec.node?.parentNode?.removeChild(rec.node);
134
+ }
135
+ this.records.clear();
136
+ this.leaseKeys.clear();
137
+ this.scopeIds.clear();
138
+ }
139
+
140
+ // ─── Ref-count core ─────────────────────────────────────────
141
+
142
+ private acquireOne(key: string, factory: () => HTMLElement | null): void {
143
+ let rec = this.records.get(key);
144
+ if (!rec) {
145
+ rec = { refs: 0, node: null };
146
+ this.records.set(key, rec);
147
+ }
148
+ rec.refs++;
149
+ if (rec.refs === 1 && !rec.node) {
150
+ // 0 → 1: insert đúng một lần.
151
+ rec.node = factory();
152
+ }
153
+ }
154
+
155
+ private releaseOne(key: string, removeWhenUnused: boolean): void {
156
+ const rec = this.records.get(key);
157
+ if (!rec) return;
158
+ rec.refs = Math.max(0, rec.refs - 1);
159
+ if (rec.refs === 0 && removeWhenUnused) {
160
+ // 1 → 0: không còn instance nào → remove.
161
+ rec.node?.parentNode?.removeChild(rec.node);
162
+ rec.node = null;
163
+ this.records.delete(key);
164
+ }
165
+ }
166
+
167
+ private leaseKey(path: string, kind: 'sty' | 'sc', index: number): string {
168
+ return `${path}::${kind}::${index}`;
169
+ }
170
+
171
+ /**
172
+ * Global CSS/link dedup xuyên View. Scoped CSS phải giữ path trong key vì
173
+ * cùng source nhưng mỗi View được rewrite bằng scopeId khác nhau.
174
+ */
175
+ private styleKey(path: string, style: StyleSpec): string {
176
+ const scope = style.type === 'code' && style.scoped ? `scoped:${path}` : 'global';
177
+ return `sty::${scope}::${this.stableSerialize(style)}`;
178
+ }
179
+
180
+ /** Script là document-global side effect nên dedup xuyên View. */
181
+ private scriptKey(script: ScriptSpec): string {
182
+ return `sc::global::${this.stableSerialize(script)}`;
183
+ }
184
+
185
+ // ─── Style ──────────────────────────────────────────────────
186
+
187
+ private createStyleNode(path: string, style: StyleSpec, scopeId: string): HTMLElement | null {
188
+ const head = this.headEl;
189
+ if (!head) return null;
190
+
191
+ if (style.type === 'href') {
192
+ const existing = this.findExistingStylesheet(style);
193
+ if (existing) {
194
+ // Adopt link do Blade SSR phát ra thay vì chèn bản thứ hai khi hydrate.
195
+ existing.setAttribute(OWNER_ATTR, path);
196
+ return existing;
197
+ }
198
+ const link = document.createElement('link');
199
+ link.setAttribute('rel', 'stylesheet');
200
+ if (style.href) link.setAttribute('href', style.href);
201
+ this.applyExtraAttrs(link, style);
202
+ link.setAttribute(OWNER_ATTR, path);
203
+ head.appendChild(link);
204
+ return link;
205
+ }
206
+
207
+ const raw = style.content ?? '';
208
+ const css = style.scoped ? this.scopeCss(raw, scopeId) : raw;
209
+ const ssr = this.findExistingStyle(css, style);
210
+ if (ssr) {
211
+ // Adopt <style> do Blade SSR in trong <head> (`addStyle`) — nó đã có từ
212
+ // byte đầu nên trang không vẽ trần; nhận quyền sở hữu để còn gỡ được.
213
+ ssr.setAttribute(OWNER_ATTR, path);
214
+ return ssr;
215
+ }
216
+
217
+ const el = document.createElement('style');
218
+ el.textContent = css;
219
+ if (style.scoped) el.setAttribute(SCOPE_ATTR, scopeId);
220
+ this.applyExtraAttrs(el, style);
221
+ el.setAttribute(OWNER_ATTR, path);
222
+ head.appendChild(el);
223
+ return el;
224
+ }
225
+
226
+ /** Tìm stylesheet SSR cùng identity để hydration không tạo node trùng. */
227
+ private findExistingStylesheet(style: StyleSpec): HTMLLinkElement | null {
228
+ if (typeof document === 'undefined' || !style.href) return null;
229
+ const expectedHref = new URL(style.href, document.baseURI).href;
230
+ const links = document.querySelectorAll<HTMLLinkElement>('link[rel~="stylesheet"][href]');
231
+ for (const link of Array.from(links)) {
232
+ if (link.href !== expectedHref) continue;
233
+ if (!this.matchesExtraAttrs(link, style)) continue;
234
+ return link;
235
+ }
236
+ return null;
237
+ }
238
+
239
+ /** `<style data-sao-style>` SSR chưa ai nhận, cùng nội dung + attribute. */
240
+ private findExistingStyle(css: string, style: StyleSpec): HTMLStyleElement | null {
241
+ if (typeof document === 'undefined') return null;
242
+ const nodes = document.querySelectorAll<HTMLStyleElement>(`style[${SSR_STYLE_ATTR}]:not([${OWNER_ATTR}])`);
243
+ for (const node of Array.from(nodes)) {
244
+ if (node.textContent === css && this.matchesExtraAttrs(node, style)) return node;
245
+ }
246
+ return null;
247
+ }
248
+
249
+ private matchesExtraAttrs(el: HTMLElement, spec: StyleSpec | ScriptSpec): boolean {
250
+ if (spec.id && el.id !== spec.id) return false;
251
+ if (spec.className && el.getAttribute('class') !== spec.className) return false;
252
+ for (const [name, value] of Object.entries(spec.attributes ?? {})) {
253
+ const n = name.toLowerCase();
254
+ if (n === 'href' || n === 'rel' || n === 'src') continue;
255
+ if (value === true && !el.hasAttribute(name)) return false;
256
+ if (value === false || value == null) {
257
+ if (el.hasAttribute(name)) return false;
258
+ } else if (value !== true && el.getAttribute(name) !== String(value)) {
259
+ return false;
260
+ }
261
+ }
262
+ return true;
263
+ }
264
+
265
+ /** scopeId ổn định theo path (mọi instance + cả node <style> dùng chung). */
266
+ private scopeIdFor(path: string, styles: StyleSpec[]): string {
267
+ if (!styles.some(s => s.scoped)) return '';
268
+ let id = this.scopeIds.get(path);
269
+ if (!id) {
270
+ id = this.hash(path);
271
+ this.scopeIds.set(path, id);
272
+ }
273
+ return id;
274
+ }
275
+
276
+ /**
277
+ * Prefix mỗi selector top-level bằng `[SCOPE_ATTR="id"]` (kiểu Vue scoped):
278
+ * `.foo .bar { … }` → `[data-sao-scope="x"] .foo .bar { … }`
279
+ * Bỏ qua at-rule (@media/@keyframes…) ở mức selector — chỉ scope rule thường.
280
+ */
281
+ private scopeCss(css: string, scopeId: string): string {
282
+ if (!scopeId) return css;
283
+ const prefix = `[${SCOPE_ATTR}="${scopeId}"]`;
284
+ // Tách theo block { … }; với mỗi rule, prefix phần selector trước '{'.
285
+ return css.replace(/(^|})\s*([^{}@]+)\{/g, (_m, brace, selector) => {
286
+ const scoped = selector
287
+ .split(',')
288
+ .map((s: string) => {
289
+ const t = s.trim();
290
+ return t ? `${prefix} ${t}` : t;
291
+ })
292
+ .join(', ');
293
+ return `${brace} ${scoped} {`;
294
+ });
295
+ }
296
+
297
+ /** Tag subtree của instance bằng scope attribute (cho descendant selector). */
298
+ private tagScope(roots: Node[], scopeId: string): void {
299
+ const visit = (node: Node) => {
300
+ if (node.nodeType !== 1) return; // chỉ Element
301
+ const el = node as HTMLElement;
302
+ if (!el.hasAttribute(SCOPE_ATTR)) el.setAttribute(SCOPE_ATTR, scopeId);
303
+ for (let i = 0; i < el.children.length; i++) visit(el.children[i]);
304
+ };
305
+ for (const r of roots) visit(r);
306
+ }
307
+
308
+ // ─── Script ─────────────────────────────────────────────────
309
+
310
+ private createScriptNode(script: ScriptSpec): HTMLElement | null {
311
+ const head = this.headEl;
312
+ if (!head) return null;
313
+
314
+ if (script.type === 'src') {
315
+ const existing = this.findExistingScript(script);
316
+ if (existing) {
317
+ // Adopt <script src> do Blade SSR phát ra thay vì nạp & execute bản thứ hai
318
+ // khi hydrate: load lại (vd prism.min.js) reset global của lib, xoá mọi thứ
319
+ // đã đăng ký giữa hai lần load (grammar Prism, plugin…).
320
+ existing.setAttribute(OWNER_ATTR, 'script');
321
+ return existing;
322
+ }
323
+ }
324
+
325
+ const el = document.createElement('script');
326
+ if (script.type === 'src') {
327
+ if (script.src) el.setAttribute('src', script.src);
328
+ // Dynamic script tags default to async=true in browsers, causing dependencies to execute out-of-order.
329
+ // Setting async=false forces the browser to execute them in insertion order.
330
+ el.async = false;
331
+ } else {
332
+ el.textContent = script.content ?? '';
333
+ }
334
+ this.applyExtraAttrs(el, script);
335
+ el.setAttribute(OWNER_ATTR, 'script');
336
+ head.appendChild(el);
337
+ return el;
338
+ }
339
+
340
+ /** Tìm <script src> cùng src (SSR phát ra) để hydration không nạp lại lần hai. */
341
+ private findExistingScript(script: ScriptSpec): HTMLScriptElement | null {
342
+ if (typeof document === 'undefined' || !script.src) return null;
343
+ const expectedSrc = new URL(script.src, document.baseURI).href;
344
+ const nodes = document.querySelectorAll<HTMLScriptElement>('script[src]');
345
+ for (const node of Array.from(nodes)) {
346
+ if (node.src !== expectedSrc) continue;
347
+ if (node.hasAttribute(OWNER_ATTR)) continue; // node do AssetManager tạo — acquireOne tự quản
348
+ if (!this.matchesExtraAttrs(node, script)) continue;
349
+ return node;
350
+ }
351
+ return null;
352
+ }
353
+
354
+ // ─── Helpers ────────────────────────────────────────────────
355
+
356
+ private applyExtraAttrs(el: HTMLElement, spec: StyleSpec | ScriptSpec): void {
357
+ if (spec.id) el.setAttribute('id', spec.id);
358
+ if (spec.className) el.setAttribute('class', spec.className);
359
+ if (spec.attributes) {
360
+ for (const [k, v] of Object.entries(spec.attributes)) {
361
+ if (v === true) el.setAttribute(k, '');
362
+ else if (v !== false && v != null) el.setAttribute(k, String(v));
363
+ }
364
+ }
365
+ }
366
+
367
+ /** JSON ổn định theo key để object attributes khác thứ tự vẫn cùng identity. */
368
+ private stableSerialize(value: unknown): string {
369
+ if (value === null || typeof value !== 'object') return JSON.stringify(value) ?? 'undefined';
370
+ if (Array.isArray(value)) return `[${value.map(item => this.stableSerialize(item)).join(',')}]`;
371
+ const object = value as Record<string, unknown>;
372
+ return `{${Object.keys(object).sort().map((key) =>
373
+ `${JSON.stringify(key)}:${this.stableSerialize(object[key])}`
374
+ ).join(',')}}`;
375
+ }
376
+
377
+ /** Hash ngắn ổn định từ chuỗi (djb2) → dùng làm scopeId. */
378
+ private hash(str: string): string {
379
+ let h = 5381;
380
+ for (let i = 0; i < str.length; i++) h = ((h << 5) + h + str.charCodeAt(i)) >>> 0;
381
+ return h.toString(36).slice(0, 8);
382
+ }
383
+ }
384
+
385
+ /** Singleton dùng chung toàn app (asset là tài nguyên global của document). */
386
+ const AssetManager = new AssetManagerService();
387
+ export default AssetManager;