@composy/store-core 0.0.1 → 0.0.2

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 (300) hide show
  1. package/CHANGELOG.md +64 -3
  2. package/README.md +196 -172
  3. package/dist/index.js +1331 -1115
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +578 -417
  6. package/dist/index.min.js.map +1 -1
  7. package/es/.dts-output-manifest.json +1 -0
  8. package/es/.dts.tsbuildinfo +1 -0
  9. package/es/core/async-action.d.ts +1 -71
  10. package/es/core/async-action.js +83 -35
  11. package/es/core/async-action.js.map +1 -1
  12. package/es/core/base-store.d.ts +27 -62
  13. package/es/core/base-store.js +174 -74
  14. package/es/core/base-store.js.map +1 -1
  15. package/es/core/batch-manager.d.ts +0 -1
  16. package/es/core/batch-manager.js +15 -2
  17. package/es/core/batch-manager.js.map +1 -1
  18. package/es/core/create-store.d.ts +3 -3
  19. package/es/core/create-store.js +3 -3
  20. package/es/core/create-store.js.map +1 -1
  21. package/es/core/event-bus.d.ts +0 -1
  22. package/es/core/event-bus.js +1 -1
  23. package/es/core/event-bus.js.map +1 -1
  24. package/es/core/index.d.ts +1 -2
  25. package/es/core/index.js +2 -2
  26. package/es/core/pub-sub.d.ts +0 -1
  27. package/es/core/pub-sub.js +1 -1
  28. package/es/core/pub-sub.js.map +1 -1
  29. package/es/engine/index.d.ts +0 -1
  30. package/es/engine/index.js +1 -1
  31. package/es/engine/plugin.d.ts +0 -1
  32. package/es/engine/plugin.js +11 -2
  33. package/es/engine/plugin.js.map +1 -1
  34. package/es/engine/types.d.ts +0 -1
  35. package/es/engine/types.js +1 -1
  36. package/es/errors/index.d.ts +0 -1
  37. package/es/errors/index.js +17 -1
  38. package/es/errors/index.js.map +1 -1
  39. package/es/index.d.ts +3 -4
  40. package/es/index.js +8 -8
  41. package/es/index.js.map +1 -1
  42. package/es/middleware/index.d.ts +3 -4
  43. package/es/middleware/index.js +2 -2
  44. package/es/middleware/logger.d.ts +0 -1
  45. package/es/middleware/logger.js +2 -2
  46. package/es/middleware/logger.js.map +1 -1
  47. package/es/middleware/middleware-manager.d.ts +0 -1
  48. package/es/middleware/middleware-manager.js +5 -2
  49. package/es/middleware/middleware-manager.js.map +1 -1
  50. package/es/middleware/persist.d.ts +0 -1
  51. package/es/middleware/persist.js +3 -3
  52. package/es/middleware/persist.js.map +1 -1
  53. package/es/middleware/time-travel.d.ts +0 -1
  54. package/es/middleware/time-travel.js +1 -1
  55. package/es/middleware/time-travel.js.map +1 -1
  56. package/es/middleware/validation.d.ts +0 -1
  57. package/es/middleware/validation.js +2 -2
  58. package/es/middleware/validation.js.map +1 -1
  59. package/es/plugins/define-plugin.d.ts +1 -2
  60. package/es/plugins/define-plugin.js +2 -2
  61. package/es/plugins/define-plugin.js.map +1 -1
  62. package/es/plugins/index.d.ts +0 -1
  63. package/es/plugins/index.js +2 -2
  64. package/es/plugins/plugin-manager.d.ts +1 -31
  65. package/es/plugins/plugin-manager.js +58 -27
  66. package/es/plugins/plugin-manager.js.map +1 -1
  67. package/es/types/action.d.ts +2 -0
  68. package/es/types/action.js +10 -0
  69. package/es/types/batch.d.ts +2 -0
  70. package/es/types/batch.js +10 -0
  71. package/es/types/event.d.ts +2 -0
  72. package/es/types/event.js +10 -0
  73. package/es/types/index.d.ts +2 -3
  74. package/es/types/index.js +1 -1
  75. package/es/types/middleware.d.ts +10 -2
  76. package/es/types/middleware.js +1 -1
  77. package/es/types/mutation.d.ts +2 -0
  78. package/es/types/mutation.js +10 -0
  79. package/es/types/plugin.d.ts +4 -1
  80. package/es/types/plugin.js +1 -1
  81. package/es/types/state.d.ts +2 -0
  82. package/es/types/state.js +10 -0
  83. package/es/types/store.d.ts +19 -1
  84. package/es/types/store.js +1 -1
  85. package/es/types/subscription.d.ts +7 -2
  86. package/es/types/subscription.js +1 -1
  87. package/es/types/time-travel.d.ts +2 -0
  88. package/es/types/time-travel.js +10 -0
  89. package/es/types/utility.d.ts +3 -4
  90. package/es/types/utility.js +1 -1
  91. package/es/utils/debounce-throttle.d.ts +0 -1
  92. package/es/utils/debounce-throttle.js +1 -1
  93. package/es/utils/debounce-throttle.js.map +1 -1
  94. package/es/utils/deep-clone.d.ts +0 -1
  95. package/es/utils/deep-clone.js +1 -1
  96. package/es/utils/deep-clone.js.map +1 -1
  97. package/es/utils/index.d.ts +4 -5
  98. package/es/utils/index.js +1 -1
  99. package/es/utils/selector.d.ts +0 -1
  100. package/es/utils/selector.js +1 -1
  101. package/es/utils/selector.js.map +1 -1
  102. package/esm/core/async-action.js +83 -35
  103. package/esm/core/async-action.js.map +1 -1
  104. package/esm/core/base-store.js +174 -74
  105. package/esm/core/base-store.js.map +1 -1
  106. package/esm/core/batch-manager.js +15 -2
  107. package/esm/core/batch-manager.js.map +1 -1
  108. package/esm/core/create-store.js +3 -3
  109. package/esm/core/create-store.js.map +1 -1
  110. package/esm/core/event-bus.js +1 -1
  111. package/esm/core/event-bus.js.map +1 -1
  112. package/esm/core/index.js +2 -2
  113. package/esm/core/pub-sub.js +1 -1
  114. package/esm/core/pub-sub.js.map +1 -1
  115. package/esm/engine/index.js +1 -1
  116. package/esm/engine/plugin.js +11 -2
  117. package/esm/engine/plugin.js.map +1 -1
  118. package/esm/errors/index.js +17 -1
  119. package/esm/errors/index.js.map +1 -1
  120. package/esm/index.js +8 -8
  121. package/esm/index.js.map +1 -1
  122. package/esm/middleware/logger.js +2 -2
  123. package/esm/middleware/logger.js.map +1 -1
  124. package/esm/middleware/middleware-manager.js +5 -2
  125. package/esm/middleware/middleware-manager.js.map +1 -1
  126. package/esm/middleware/persist.js +3 -3
  127. package/esm/middleware/persist.js.map +1 -1
  128. package/esm/middleware/time-travel.js +1 -1
  129. package/esm/middleware/time-travel.js.map +1 -1
  130. package/esm/middleware/validation.js +2 -2
  131. package/esm/middleware/validation.js.map +1 -1
  132. package/esm/plugins/define-plugin.js +2 -2
  133. package/esm/plugins/define-plugin.js.map +1 -1
  134. package/esm/plugins/plugin-manager.js +58 -27
  135. package/esm/plugins/plugin-manager.js.map +1 -1
  136. package/esm/utils/debounce-throttle.js +1 -1
  137. package/esm/utils/debounce-throttle.js.map +1 -1
  138. package/esm/utils/deep-clone.js +1 -1
  139. package/esm/utils/deep-clone.js.map +1 -1
  140. package/esm/utils/selector.js +1 -1
  141. package/esm/utils/selector.js.map +1 -1
  142. package/lib/core/async-action.cjs +83 -35
  143. package/lib/core/async-action.cjs.map +1 -1
  144. package/lib/core/async-action.d.cts +25 -0
  145. package/lib/core/base-store.cjs +174 -74
  146. package/lib/core/base-store.cjs.map +1 -1
  147. package/lib/core/base-store.d.cts +50 -0
  148. package/lib/core/batch-manager.cjs +15 -2
  149. package/lib/core/batch-manager.cjs.map +1 -1
  150. package/{esm/core/batch-manager.d.ts → lib/core/batch-manager.d.cts} +0 -1
  151. package/lib/core/create-store.cjs +3 -3
  152. package/lib/core/create-store.cjs.map +1 -1
  153. package/lib/core/{create-store.d.ts → create-store.d.cts} +3 -3
  154. package/lib/core/event-bus.cjs +1 -1
  155. package/lib/core/event-bus.cjs.map +1 -1
  156. package/lib/core/{event-bus.d.ts → event-bus.d.cts} +0 -1
  157. package/lib/core/index.cjs +2 -2
  158. package/{esm/core/index.d.ts → lib/core/index.d.cts} +1 -2
  159. package/lib/core/pub-sub.cjs +1 -1
  160. package/lib/core/pub-sub.cjs.map +1 -1
  161. package/lib/core/{pub-sub.d.ts → pub-sub.d.cts} +0 -1
  162. package/lib/engine/index.cjs +1 -1
  163. package/{esm/engine/index.d.ts → lib/engine/index.d.cts} +0 -1
  164. package/lib/engine/plugin.cjs +11 -2
  165. package/lib/engine/plugin.cjs.map +1 -1
  166. package/{esm/engine/plugin.d.ts → lib/engine/plugin.d.cts} +0 -1
  167. package/lib/engine/types.cjs +1 -1
  168. package/lib/engine/{types.d.ts → types.d.cts} +0 -1
  169. package/lib/errors/index.cjs +17 -1
  170. package/lib/errors/index.cjs.map +1 -1
  171. package/lib/errors/{index.d.ts → index.d.cts} +0 -1
  172. package/lib/index.cjs +8 -8
  173. package/lib/index.cjs.map +1 -1
  174. package/lib/{index.d.ts → index.d.cts} +3 -4
  175. package/lib/middleware/index.cjs +2 -2
  176. package/lib/middleware/{index.d.ts → index.d.cts} +3 -4
  177. package/lib/middleware/logger.cjs +2 -2
  178. package/lib/middleware/logger.cjs.map +1 -1
  179. package/lib/middleware/{logger.d.ts → logger.d.cts} +0 -1
  180. package/lib/middleware/middleware-manager.cjs +5 -2
  181. package/lib/middleware/middleware-manager.cjs.map +1 -1
  182. package/lib/middleware/{middleware-manager.d.ts → middleware-manager.d.cts} +0 -1
  183. package/lib/middleware/persist.cjs +3 -3
  184. package/lib/middleware/persist.cjs.map +1 -1
  185. package/{esm/middleware/persist.d.ts → lib/middleware/persist.d.cts} +0 -1
  186. package/lib/middleware/time-travel.cjs +1 -1
  187. package/lib/middleware/time-travel.cjs.map +1 -1
  188. package/{esm/middleware/time-travel.d.ts → lib/middleware/time-travel.d.cts} +0 -1
  189. package/lib/middleware/validation.cjs +2 -2
  190. package/lib/middleware/validation.cjs.map +1 -1
  191. package/{esm/middleware/validation.d.ts → lib/middleware/validation.d.cts} +0 -1
  192. package/lib/plugins/define-plugin.cjs +2 -2
  193. package/lib/plugins/define-plugin.cjs.map +1 -1
  194. package/{esm/plugins/define-plugin.d.ts → lib/plugins/define-plugin.d.cts} +1 -2
  195. package/lib/plugins/index.cjs +2 -2
  196. package/{esm/plugins/index.d.ts → lib/plugins/index.d.cts} +0 -1
  197. package/lib/plugins/plugin-manager.cjs +58 -27
  198. package/lib/plugins/plugin-manager.cjs.map +1 -1
  199. package/lib/plugins/plugin-manager.d.cts +5 -0
  200. package/lib/types/action.cjs +12 -0
  201. package/lib/types/action.d.cts +2 -0
  202. package/lib/types/batch.cjs +12 -0
  203. package/lib/types/batch.d.cts +2 -0
  204. package/lib/types/event.cjs +12 -0
  205. package/lib/types/event.d.cts +2 -0
  206. package/lib/types/index.cjs +1 -1
  207. package/{esm/types/index.d.ts → lib/types/index.d.cts} +2 -3
  208. package/lib/types/middleware.cjs +1 -1
  209. package/lib/types/{middleware.d.ts → middleware.d.cts} +10 -2
  210. package/lib/types/mutation.cjs +12 -0
  211. package/lib/types/mutation.d.cts +2 -0
  212. package/lib/types/plugin.cjs +1 -1
  213. package/lib/types/{plugin.d.ts → plugin.d.cts} +4 -1
  214. package/lib/types/state.cjs +12 -0
  215. package/lib/types/state.d.cts +2 -0
  216. package/lib/types/store.cjs +1 -1
  217. package/lib/types/{store.d.ts → store.d.cts} +19 -1
  218. package/lib/types/subscription.cjs +1 -1
  219. package/lib/types/{subscription.d.ts → subscription.d.cts} +7 -2
  220. package/lib/types/time-travel.cjs +12 -0
  221. package/lib/types/time-travel.d.cts +2 -0
  222. package/lib/types/utility.cjs +1 -1
  223. package/lib/types/{utility.d.ts → utility.d.cts} +3 -4
  224. package/lib/utils/debounce-throttle.cjs +1 -1
  225. package/lib/utils/debounce-throttle.cjs.map +1 -1
  226. package/{esm/utils/debounce-throttle.d.ts → lib/utils/debounce-throttle.d.cts} +0 -1
  227. package/lib/utils/deep-clone.cjs +1 -1
  228. package/lib/utils/deep-clone.cjs.map +1 -1
  229. package/lib/utils/{deep-clone.d.ts → deep-clone.d.cts} +0 -1
  230. package/lib/utils/index.cjs +1 -1
  231. package/lib/utils/{index.d.ts → index.d.cts} +4 -5
  232. package/lib/utils/selector.cjs +1 -1
  233. package/lib/utils/selector.cjs.map +1 -1
  234. package/lib/utils/{selector.d.ts → selector.d.cts} +0 -1
  235. package/package.json +14 -11
  236. package/es/core/async-action.d.ts.map +0 -1
  237. package/es/core/base-store.d.ts.map +0 -1
  238. package/es/core/batch-manager.d.ts.map +0 -1
  239. package/es/core/create-store.d.ts.map +0 -1
  240. package/es/core/event-bus.d.ts.map +0 -1
  241. package/es/core/index.d.ts.map +0 -1
  242. package/es/core/pub-sub.d.ts.map +0 -1
  243. package/es/engine/index.d.ts.map +0 -1
  244. package/es/engine/plugin.d.ts.map +0 -1
  245. package/es/engine/types.d.ts.map +0 -1
  246. package/es/errors/index.d.ts.map +0 -1
  247. package/es/index.d.ts.map +0 -1
  248. package/es/middleware/index.d.ts.map +0 -1
  249. package/es/middleware/logger.d.ts.map +0 -1
  250. package/es/middleware/middleware-manager.d.ts.map +0 -1
  251. package/es/middleware/persist.d.ts.map +0 -1
  252. package/es/middleware/time-travel.d.ts.map +0 -1
  253. package/es/middleware/validation.d.ts.map +0 -1
  254. package/es/plugins/define-plugin.d.ts.map +0 -1
  255. package/es/plugins/index.d.ts.map +0 -1
  256. package/es/plugins/plugin-manager.d.ts.map +0 -1
  257. package/es/types/index.d.ts.map +0 -1
  258. package/es/types/middleware.d.ts.map +0 -1
  259. package/es/types/plugin.d.ts.map +0 -1
  260. package/es/types/store.d.ts.map +0 -1
  261. package/es/types/subscription.d.ts.map +0 -1
  262. package/es/types/utility.d.ts.map +0 -1
  263. package/es/utils/debounce-throttle.d.ts.map +0 -1
  264. package/es/utils/deep-clone.d.ts.map +0 -1
  265. package/es/utils/index.d.ts.map +0 -1
  266. package/es/utils/selector.d.ts.map +0 -1
  267. package/esm/core/async-action.d.ts +0 -95
  268. package/esm/core/base-store.d.ts +0 -85
  269. package/esm/core/create-store.d.ts +0 -66
  270. package/esm/core/event-bus.d.ts +0 -34
  271. package/esm/core/pub-sub.d.ts +0 -41
  272. package/esm/engine/types.d.ts +0 -81
  273. package/esm/errors/index.d.ts +0 -208
  274. package/esm/index.d.ts +0 -27
  275. package/esm/middleware/index.d.ts +0 -13
  276. package/esm/middleware/logger.d.ts +0 -67
  277. package/esm/middleware/middleware-manager.d.ts +0 -40
  278. package/esm/plugins/plugin-manager.d.ts +0 -35
  279. package/esm/types/middleware.d.ts +0 -172
  280. package/esm/types/plugin.d.ts +0 -136
  281. package/esm/types/store.d.ts +0 -198
  282. package/esm/types/subscription.d.ts +0 -158
  283. package/esm/types/utility.d.ts +0 -312
  284. package/esm/utils/deep-clone.d.ts +0 -143
  285. package/esm/utils/index.d.ts +0 -13
  286. package/esm/utils/selector.d.ts +0 -213
  287. package/lib/core/async-action.d.ts +0 -95
  288. package/lib/core/base-store.d.ts +0 -85
  289. package/lib/core/batch-manager.d.ts +0 -46
  290. package/lib/core/index.d.ts +0 -14
  291. package/lib/engine/index.d.ts +0 -10
  292. package/lib/engine/plugin.d.ts +0 -20
  293. package/lib/middleware/persist.d.ts +0 -34
  294. package/lib/middleware/time-travel.d.ts +0 -30
  295. package/lib/middleware/validation.d.ts +0 -100
  296. package/lib/plugins/define-plugin.d.ts +0 -74
  297. package/lib/plugins/index.d.ts +0 -8
  298. package/lib/plugins/plugin-manager.d.ts +0 -35
  299. package/lib/types/index.d.ts +0 -12
  300. package/lib/utils/debounce-throttle.d.ts +0 -86
package/dist/index.min.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * ***********************************
3
3
  * @composy/store-core v0.0.1 *
4
4
  * Built with rollup *
5
- * Build time: 2024-08-17 11:27:33 *
5
+ * Build time: 2024-10-12 17:23:58 *
6
6
  * Build mode: production *
7
7
  * Minified: No *
8
8
  * ***********************************
@@ -39,6 +39,275 @@
39
39
  };
40
40
  }
41
41
  function e() {
42
+ return /* @__PURE__ */ new Error("Aborted");
43
+ }
44
+ function r() {
45
+ const t = /* @__PURE__ */ new Map();
46
+ let e = null;
47
+ const r = () => (null === e && (e = Array.from(t.values()).sort((t, e) => (t.priority ?? 100) - (e.priority ?? 100))), e), n = () => {
48
+ e = null;
49
+ };
50
+ return {
51
+ use: (e) => {
52
+ t.has(e.name) && console.warn(`[Middleware] 中间件 "${e.name}" 已存在,将被覆盖`), t.set(e.name, e), n();
53
+ },
54
+ remove: (e) => {
55
+ t.delete(e) && n();
56
+ },
57
+ get: (e) => t.get(e),
58
+ has: (e) => t.has(e),
59
+ execute: async (t) => {
60
+ const e = r();
61
+ if (0 === e.length) return;
62
+ const n = async (r) => {
63
+ const o = e[r];
64
+ if (!o) return void t.meta?.commit?.();
65
+ let s = !1;
66
+ await o.handler(t, async () => {
67
+ if (s) throw new Error(`[Middleware] next() called multiple times in "${o.name}"`);
68
+ s = !0, await n(r + 1);
69
+ });
70
+ };
71
+ await n(0);
72
+ },
73
+ getAll: () => r(),
74
+ clear: () => {
75
+ t.clear(), n();
76
+ }
77
+ };
78
+ }
79
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
80
+ let n = null;
81
+ function o() {
82
+ return n || (n = r()), n;
83
+ }
84
+ function s(t, e, r) {
85
+ console.error(`[Plugin] ${t} failed for "${e}":`, r);
86
+ }
87
+ function i() {
88
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), n = {
89
+ getStore: (t) => r.get(t),
90
+ hasStore: (t) => r.has(t),
91
+ getStoreIds: () => Array.from(r.keys())
92
+ };
93
+ return {
94
+ use: (o, i) => {
95
+ const a = t.get(o.name), c = e.get(o.name);
96
+ a && c && Promise.resolve(a.uninstall?.(c)).catch((t) => {
97
+ s("uninstall", o.name, t);
98
+ });
99
+ const l = ((t) => ({
100
+ storeManager: n,
101
+ storeId: "",
102
+ store: null,
103
+ options: t || {}
104
+ }))(i);
105
+ t.set(o.name, o), e.set(o.name, l), Promise.resolve(o.install(l, i)).catch((t) => {
106
+ s("install", o.name, t);
107
+ }), r.forEach((t) => o.onStoreCreated?.(t));
108
+ },
109
+ remove: (r) => {
110
+ const n = t.get(r), o = e.get(r);
111
+ n && o && Promise.resolve(n.uninstall?.(o)).catch((t) => {
112
+ s("uninstall", r, t);
113
+ }), t.delete(r), e.delete(r);
114
+ },
115
+ get: (e) => t.get(e),
116
+ has: (e) => t.has(e),
117
+ getAll: () => new Map(t),
118
+ size: () => t.size,
119
+ clear: () => {
120
+ t.forEach((t, r) => {
121
+ const n = e.get(r);
122
+ n && Promise.resolve(t.uninstall?.(n)).catch((t) => {
123
+ s("uninstall", r, t);
124
+ });
125
+ }), t.clear(), e.clear();
126
+ },
127
+ notifyStoreCreated: (e) => {
128
+ const n = a(e);
129
+ n && r.set(n, e), t.forEach((t) => t.onStoreCreated?.(e));
130
+ },
131
+ notifyStoreDisposed: (e) => {
132
+ const n = a(e);
133
+ n && r.delete(n), t.forEach((t) => t.onStoreDisposed?.(e));
134
+ },
135
+ notifyStateChange: (e, r, n) => {
136
+ t.forEach((t) => t.onStateChange?.(e, r, n));
137
+ }
138
+ };
139
+ }
140
+ function a(t) {
141
+ if (!t || "object" != typeof t) return;
142
+ const e = t.$id;
143
+ return "string" == typeof e ? e : void 0;
144
+ }
145
+ let c = null;
146
+ function l() {
147
+ return c || (c = i()), c;
148
+ }
149
+ function u(t, e, r = !1) {
150
+ let n = null, o = null;
151
+ const s = (...s) => {
152
+ o = s, n && clearTimeout(n), r && !n ? (t(...s), n = setTimeout(() => {
153
+ n = null, o = null;
154
+ }, e)) : n = setTimeout(() => {
155
+ t(...s), n = null, o = null;
156
+ }, e);
157
+ };
158
+ return s.cancel = () => {
159
+ n && (clearTimeout(n), n = null, o = null);
160
+ }, s.flush = () => {
161
+ n && o && (clearTimeout(n), t(...o), n = null, o = null);
162
+ }, s.pending = () => null !== n, s;
163
+ }
164
+ const f = Object.prototype.hasOwnProperty;
165
+ function d(t, e) {
166
+ return f.call(t, e);
167
+ }
168
+ function h(t) {
169
+ return null !== t && "object" == typeof t;
170
+ }
171
+ function p(t) {
172
+ if (!h(t)) return !1;
173
+ const e = Object.getPrototypeOf(t);
174
+ return null === e || e === Object.prototype;
175
+ }
176
+ function g(t) {
177
+ return null == t || "boolean" == typeof t || "number" == typeof t || "string" == typeof t || "bigint" == typeof t || "function" != typeof t && "symbol" != typeof t && (t instanceof Date || t instanceof RegExp || t instanceof ArrayBuffer || t instanceof DataView || t instanceof Map || t instanceof Set || !!ArrayBuffer.isView(t) || (Array.isArray(t) ? t.every((t) => g(t)) : !!p(t) && Object.values(t).every((t) => g(t))));
178
+ }
179
+ function y(t, e = {}) {
180
+ const { useStructuredClone: r = !0, cloneFunctions: n = !1, cloneSymbols: o = !1, maxDepth: s = Infinity, customCloner: i } = e;
181
+ if (r && "function" == typeof structuredClone && g(t)) try {
182
+ return structuredClone(t);
183
+ } catch {}
184
+ const a = /* @__PURE__ */ new WeakMap();
185
+ return function t(e, r) {
186
+ if (null == e) return e;
187
+ if ("boolean" == typeof e || "number" == typeof e || "string" == typeof e) return e;
188
+ if ("bigint" == typeof e) return e;
189
+ if ("symbol" == typeof e) return o ? Symbol(e.description) : e;
190
+ if ("function" == typeof e) return n ? e.bind({}) : e;
191
+ if (r > s) return e;
192
+ if (i) {
193
+ const n = i(e, (e) => t(e, r + 1));
194
+ if (void 0 !== n) return n;
195
+ }
196
+ if ("object" == typeof e && null !== e && a.has(e)) return a.get(e);
197
+ if (e instanceof Date) return new Date(e.getTime());
198
+ if (e instanceof RegExp) {
199
+ const t = new RegExp(e.source, e.flags);
200
+ return t.lastIndex = e.lastIndex, t;
201
+ }
202
+ if (e instanceof Error) {
203
+ const t = new e.constructor(e.message);
204
+ return t.stack = e.stack, t.name = e.name, t;
205
+ }
206
+ if (e instanceof Map) {
207
+ const n = /* @__PURE__ */ new Map();
208
+ return a.set(e, n), e.forEach((e, o) => {
209
+ n.set(t(o, r + 1), t(e, r + 1));
210
+ }), n;
211
+ }
212
+ if (e instanceof Set) {
213
+ const n = /* @__PURE__ */ new Set();
214
+ return a.set(e, n), e.forEach((e) => {
215
+ n.add(t(e, r + 1));
216
+ }), n;
217
+ }
218
+ if (e instanceof ArrayBuffer) return e.slice(0);
219
+ if (ArrayBuffer.isView(e) && !(e instanceof DataView)) return new e.constructor(e.buffer.slice(0));
220
+ if (Array.isArray(e)) {
221
+ const n = [];
222
+ a.set(e, n);
223
+ for (let o = 0; o < e.length; o++) n[o] = t(e[o], r + 1);
224
+ return n;
225
+ }
226
+ if (p(e)) {
227
+ const n = {};
228
+ a.set(e, n);
229
+ const s = Object.keys(e);
230
+ for (const o of s) n[o] = t(e[o], r + 1);
231
+ if (o) {
232
+ const o = Object.getOwnPropertySymbols(e);
233
+ for (const s of o) n[s] = t(e[s], r + 1);
234
+ }
235
+ return n;
236
+ }
237
+ return e;
238
+ }(t, 0);
239
+ }
240
+ function m(t, e, ...r) {
241
+ const { arrayStrategy: n = "replace", clone: o = !0, maxDepth: s = Infinity } = e;
242
+ function i(t, e, r) {
243
+ if (r > s) return t;
244
+ for (const s of Object.keys(e)) {
245
+ const a = e[s], c = t[s];
246
+ if (Array.isArray(a)) if ("concat" === n && Array.isArray(c)) t[s] = [...c, ...a];
247
+ else if ("merge" === n && Array.isArray(c)) {
248
+ const e = [...c];
249
+ a.forEach((t, n) => {
250
+ p(t) && p(e[n]) ? e[n] = i(e[n], t, r + 1) : e[n] = o ? y(t) : t;
251
+ }), t[s] = e;
252
+ } else t[s] = o ? y(a) : a;
253
+ else p(a) ? p(c) ? t[s] = i(c, a, r + 1) : t[s] = o ? y(a) : a : t[s] = o && h(a) ? y(a) : a;
254
+ }
255
+ return t;
256
+ }
257
+ let a = t;
258
+ for (const t of r) null != t && (a = i(a, t, 0));
259
+ return a;
260
+ }
261
+ const S = /^\d+$/;
262
+ function b(t, e = Object.is) {
263
+ let r, n, o = !1;
264
+ return (s) => {
265
+ if (o && r === s) return n;
266
+ const i = t(s);
267
+ return o && e(i, n) || (n = i), r = s, o = !0, n;
268
+ };
269
+ }
270
+ function E(t) {
271
+ let e = 0;
272
+ const r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), o = () => {
273
+ if (n.size > 0) {
274
+ const e = new Set(n);
275
+ n.clear(), t?.(e), r.forEach((t) => {
276
+ try {
277
+ t(e);
278
+ } catch (t) {
279
+ console.error("[Batch] flush listener failed:", t);
280
+ }
281
+ });
282
+ }
283
+ }, s = () => {
284
+ e++;
285
+ }, i = () => {
286
+ 0 !== e && (e--, 0 === e && o());
287
+ };
288
+ return {
289
+ start: s,
290
+ end: i,
291
+ markDirty: (t) => {
292
+ n.add(t), 0 === e && o();
293
+ },
294
+ batch: (t) => {
295
+ s();
296
+ try {
297
+ return t();
298
+ } finally {
299
+ i();
300
+ }
301
+ },
302
+ isBatching: () => e > 0,
303
+ onFlush: (t) => (r.add(t), () => r.delete(t))
304
+ };
305
+ }
306
+ let R = null;
307
+ function w() {
308
+ return R || (R = E()), R;
309
+ }
310
+ function I() {
42
311
  const t = /* @__PURE__ */ new Map(), e = (e, r) => {
43
312
  const n = ((e) => {
44
313
  let r = t.get(e);
@@ -77,68 +346,149 @@
77
346
  }
78
347
  };
79
348
  }
80
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
81
- const r = e();
82
- async function n(t, e) {
349
+ const A = I();
350
+ var O = Object.defineProperty, M = (t, e, r) => ((t, e, r) => e in t ? O(t, e, {
351
+ enumerable: !0,
352
+ configurable: !0,
353
+ writable: !0,
354
+ value: r
355
+ }) : t[e] = r)(t, "symbol" != typeof e ? e + "" : e, r);
356
+ async function v(t, e) {
83
357
  for (const r of t) await r(e);
84
358
  }
85
- var o = class {
86
- constructor(e, n = {}) {
87
- this.stateSubscribers = t(), this.actionSubscribers = t(), this.disposed = !1, this.$id = e.id, this.initialStateFactory = e.state, this._state = e.state(), this.getters = this.createGetters(e.getters || {}), this.actions = this.createActions(e.actions || {}), r.emit("store:created", { storeId: this.$id });
359
+ var P = class {
360
+ constructor(e, r = {}) {
361
+ M(this, "$id"), M(this, "getters"), M(this, "actions"), M(this, "stateSubscribers", t()), M(this, "actionSubscribers", t()), M(this, "initialStateFactory"), M(this, "middlewareManager"), M(this, "pluginManager"), M(this, "batchManager"), M(this, "pendingBatchMutation", null), M(this, "stopBatchFlush"), M(this, "mutationQueue", Promise.resolve()), M(this, "pendingMutations", 0), M(this, "_state"), M(this, "disposed", !1), this.$id = e.id, this.initialStateFactory = e.state, this._state = e.state(), this.middlewareManager = r.middleware ?? o(), this.pluginManager = r.plugins ?? l(), this.batchManager = r.batch ?? w(), this.getters = this.createGetters(e.getters || {}), this.actions = this.createActions(e.actions || {}), this.stopBatchFlush = this.batchManager.onFlush?.((t) => {
362
+ if (!t.has(this.$id) || !this.pendingBatchMutation) return;
363
+ const e = this.pendingBatchMutation;
364
+ this.pendingBatchMutation = null, this.publishStateChange(e);
365
+ }), A.emit("store:created", { storeId: this.$id }), this.notifyPluginStoreCreated();
88
366
  }
89
367
  get $state() {
90
368
  return this._state;
91
369
  }
92
370
  set $state(t) {
93
- this._state = t;
371
+ this.checkDisposed();
372
+ const e = y(t);
373
+ this.scheduleMutation(() => this.runStateMutation(e, t)).catch((t) => {
374
+ console.error(`[Store] Failed to replace state for "${this.$id}":`, t);
375
+ });
94
376
  }
95
377
  $reset() {
96
- this.checkDisposed();
97
- const t = { ...this._state };
98
- this._state = this.initialStateFactory(), this.notifyStateChange({
99
- type: "direct",
100
- storeId: this.$id,
101
- oldState: t
378
+ this.checkDisposed(), this.scheduleMutation(() => this.runStateMutation()).catch((t) => {
379
+ console.error(`[Store] Failed to reset "${this.$id}":`, t);
102
380
  });
103
381
  }
104
382
  $patch(t) {
105
383
  this.checkDisposed();
106
- const e = { ...this._state };
107
- "function" == typeof t ? (t(this._state), this.notifyStateChange({
108
- type: "patch function",
109
- storeId: this.$id,
110
- oldState: e
111
- })) : (Object.assign(this._state, t), this.notifyStateChange({
112
- type: "patch object",
113
- storeId: this.$id,
114
- oldState: e,
115
- events: Object.keys(t)
116
- }));
384
+ const e = "function" == typeof t ? t : y(t);
385
+ this.scheduleMutation(() => this.runPatchMutation(e)).catch((t) => {
386
+ console.error(`[Store] Failed to patch "${this.$id}":`, t);
387
+ });
388
+ }
389
+ async $patchAsync(t) {
390
+ this.checkDisposed();
391
+ const e = "function" == typeof t ? t : y(t);
392
+ await this.scheduleMutation(() => this.runPatchMutation(e));
117
393
  }
118
394
  $subscribe(t, e = {}) {
119
- return this.checkDisposed(), this.stateSubscribers.subscribe(({ mutation: e, state: r }) => t(e, r), { immediate: e.immediate });
395
+ this.checkDisposed();
396
+ const r = this.stateSubscribers.subscribe(({ mutation: e, state: r }) => t(e, r), { immediate: e.immediate });
397
+ if (e.immediate) try {
398
+ t({
399
+ type: "direct",
400
+ storeId: this.$id
401
+ }, y(this._state));
402
+ } catch (t) {
403
+ console.error("[Store] immediate subscriber failed:", t);
404
+ }
405
+ return r;
120
406
  }
121
407
  $onAction(t) {
122
408
  return this.checkDisposed(), this.actionSubscribers.subscribe(t);
123
409
  }
124
410
  $dispose() {
125
- this.disposed || (this.disposed = !0, this.stateSubscribers.clear(), this.actionSubscribers.clear(), r.emit("store:disposed", { storeId: this.$id }));
411
+ this.disposed || (this.disposed = !0, this.stopBatchFlush?.(), this.stopBatchFlush = void 0, this.mutationQueue = Promise.resolve(), this.pendingMutations = 0, this.stateSubscribers.clear(), this.actionSubscribers.clear(), this.notifyPluginStoreDisposed(), A.emit("store:disposed", { storeId: this.$id }));
126
412
  }
127
413
  notifyStateChange(t) {
414
+ this.publishStateChange(t);
415
+ }
416
+ publishStateChange(t) {
417
+ const e = y(this._state);
128
418
  this.stateSubscribers.publish({
129
419
  mutation: t,
130
- state: this._state
131
- }), r.emit("state:changed", {
420
+ state: e
421
+ }), A.emit("state:changed", {
132
422
  storeId: this.$id,
133
- state: this._state,
423
+ state: e,
134
424
  mutation: t
135
425
  });
136
426
  }
137
- notifyAction(t) {
138
- this.actionSubscribers.publish(t);
427
+ async runMutation(t, e, r, n) {
428
+ this.checkDisposed();
429
+ let o = !1;
430
+ const s = () => {
431
+ o || this.disposed || (o = !0, this._state = t, this.notifyPluginStateChange(t, n), this.batchManager.isBatching() && this.batchManager.onFlush ? (this.pendingBatchMutation = this.pendingBatchMutation ? {
432
+ ...e,
433
+ oldState: this.pendingBatchMutation.oldState
434
+ } : e, this.batchManager.markDirty(this.$id)) : this.publishStateChange(e));
435
+ };
436
+ 0 !== this.middlewareManager.getAll().length ? (await this.middlewareManager.execute({
437
+ storeId: this.$id,
438
+ state: t,
439
+ type: "direct" === e.type ? "state:reset" : "state:patch",
440
+ payload: r,
441
+ meta: {
442
+ candidateState: t,
443
+ previousState: n,
444
+ commit: s
445
+ }
446
+ }), s()) : s();
447
+ }
448
+ runStateMutation(t, e) {
449
+ this.checkDisposed();
450
+ const r = y(this._state), n = {
451
+ type: "direct",
452
+ storeId: this.$id,
453
+ oldState: r
454
+ };
455
+ return this.runMutation(y(t ?? this.initialStateFactory()), n, e, r);
456
+ }
457
+ runPatchMutation(t) {
458
+ this.checkDisposed();
459
+ const e = y(this._state), r = y(this._state), n = "function" == typeof t ? {
460
+ type: "patch function",
461
+ storeId: this.$id,
462
+ oldState: e
463
+ } : {
464
+ type: "patch object",
465
+ storeId: this.$id,
466
+ oldState: e,
467
+ events: Object.keys(t)
468
+ };
469
+ return "function" == typeof t ? t(r) : Object.assign(r, t), this.runMutation(r, n, t, e);
470
+ }
471
+ scheduleMutation(t) {
472
+ if (0 === this.pendingMutations && 0 === this.middlewareManager.getAll().length) return t();
473
+ this.pendingMutations += 1;
474
+ const e = this.mutationQueue.then(t);
475
+ return this.mutationQueue = e.catch(() => {}), e.then(() => {
476
+ this.pendingMutations -= 1;
477
+ }, () => {
478
+ this.pendingMutations -= 1;
479
+ }), e;
480
+ }
481
+ notifyPluginStoreCreated() {
482
+ this.pluginManager.notifyStoreCreated ? this.pluginManager.notifyStoreCreated(this) : this.pluginManager.getAll().forEach((t) => t.onStoreCreated?.(this));
483
+ }
484
+ notifyPluginStoreDisposed() {
485
+ this.pluginManager.notifyStoreDisposed ? this.pluginManager.notifyStoreDisposed(this) : this.pluginManager.getAll().forEach((t) => t.onStoreDisposed?.(this));
486
+ }
487
+ notifyPluginStateChange(t, e) {
488
+ this.pluginManager.notifyStateChange ? this.pluginManager.notifyStateChange(this.$id, y(t), y(e)) : this.pluginManager.getAll().forEach((r) => r.onStateChange?.(this.$id, y(t), y(e)));
139
489
  }
140
490
  checkDisposed() {
141
- if (this.disposed) throw new Error(`[Store] Store "${this.$id}" 已被销毁`);
491
+ if (this.disposed) throw new Error(`[Store] Store "${this.$id}" has been disposed`);
142
492
  }
143
493
  createGetters(t) {
144
494
  const e = {};
@@ -151,85 +501,60 @@
151
501
  createActions(t) {
152
502
  const e = {};
153
503
  for (const r of Object.keys(t)) {
154
- const o = t[r];
504
+ const n = t[r];
155
505
  e[r] = (...t) => {
156
506
  this.checkDisposed();
157
- const e = [], s = [], i = {
507
+ const e = [], o = [], s = {
158
508
  after: (t) => e.push(t),
159
509
  args: t,
160
510
  name: r,
161
- onError: (t) => s.push(t),
511
+ onError: (t) => o.push(t),
162
512
  storeId: this.$id
163
513
  };
164
- this.notifyAction(i);
514
+ this.notifyAction(s);
165
515
  try {
166
- const r = o.apply(this, t);
167
- return (a = r) && "function" == typeof a.then ? r.then(async (t) => (await n(e, t), t)).catch(async (t) => {
168
- throw await n(s, t), t;
169
- }) : (n(e, r), r);
516
+ const r = n.apply(this, t);
517
+ return (i = r) && "function" == typeof i.then ? r.then(async (t) => (await v(e, t), t)).catch(async (t) => {
518
+ throw await v(o, t), t;
519
+ }) : (v(e, r), r);
170
520
  } catch (t) {
171
- throw n(s, t), t;
521
+ throw v(o, t), t;
172
522
  }
173
- var a;
523
+ var i;
174
524
  };
175
525
  }
176
526
  return e;
177
527
  }
528
+ notifyAction(t) {
529
+ this.actionSubscribers.publish(t);
530
+ }
178
531
  };
179
- function s(t) {
180
- let e = 0;
181
- const r = /* @__PURE__ */ new Set(), n = () => {
182
- if (r.size > 0) {
183
- const e = new Set(r);
184
- r.clear(), t?.(e);
185
- }
186
- }, o = () => {
187
- e++;
188
- }, s = () => {
189
- 0 !== e && (e--, 0 === e && n());
190
- };
191
- return {
192
- start: o,
193
- end: s,
194
- markDirty: (t) => {
195
- r.add(t), 0 === e && n();
196
- },
197
- batch: (t) => {
198
- o();
199
- try {
200
- return t();
201
- } finally {
202
- s();
203
- }
204
- },
205
- isBatching: () => e > 0
206
- };
207
- }
208
- let i = null;
209
- function a() {
210
- return i || (i = s()), i;
211
- }
212
- const c = {
532
+ const T = {
213
533
  BUS: "store:bus",
214
534
  PINIA: "store:pinia",
215
535
  API: "store:api",
216
536
  REGISTRY: "store:registry",
217
537
  RUNTIME: "store:runtime"
218
- }, l = {
538
+ }, $ = {
219
539
  INSTALLED: "store:installed",
220
540
  UNINSTALLED: "store:uninstalled"
221
541
  };
222
- function u(t) {
542
+ function D(t) {
223
543
  const e = t;
224
544
  return e && "object" == typeof e && "engine" in e ? e.engine ?? {} : e ?? {};
225
545
  }
226
- function f(t, e, r) {
546
+ function N(t, e, r) {
227
547
  const n = r;
228
548
  return n?.app ?? n?.framework?.app ?? t.getApp?.() ?? e?.framework?.app;
229
549
  }
230
- var d = ((t) => (t.STORE_DISPOSED = "STORE_DISPOSED", t.STORE_NOT_FOUND = "STORE_NOT_FOUND", t.STORE_ALREADY_EXISTS = "STORE_ALREADY_EXISTS", t.INVALID_STATE = "INVALID_STATE", t.INVALID_ACTION = "INVALID_ACTION", t.SERIALIZATION_ERROR = "SERIALIZATION_ERROR", t.DESERIALIZATION_ERROR = "DESERIALIZATION_ERROR", t.STORAGE_ERROR = "STORAGE_ERROR", t.PLUGIN_ERROR = "PLUGIN_ERROR", t.MIDDLEWARE_ERROR = "MIDDLEWARE_ERROR", t.SUBSCRIPTION_ERROR = "SUBSCRIPTION_ERROR", t.TIMEOUT_ERROR = "TIMEOUT_ERROR", t.UNKNOWN_ERROR = "UNKNOWN_ERROR", t))(d || {}), p = ((t) => (t.WARNING = "warning", t.ERROR = "error", t.FATAL = "fatal", t))(p || {}), g = class t extends Error {
550
+ var C = Object.defineProperty, _ = (t, e, r) => ((t, e, r) => e in t ? C(t, e, {
551
+ enumerable: !0,
552
+ configurable: !0,
553
+ writable: !0,
554
+ value: r
555
+ }) : t[e] = r)(t, "symbol" != typeof e ? e + "" : e, r), x = ((t) => (t.STORE_DISPOSED = "STORE_DISPOSED", t.STORE_NOT_FOUND = "STORE_NOT_FOUND", t.STORE_ALREADY_EXISTS = "STORE_ALREADY_EXISTS", t.INVALID_STATE = "INVALID_STATE", t.INVALID_ACTION = "INVALID_ACTION", t.SERIALIZATION_ERROR = "SERIALIZATION_ERROR", t.DESERIALIZATION_ERROR = "DESERIALIZATION_ERROR", t.STORAGE_ERROR = "STORAGE_ERROR", t.PLUGIN_ERROR = "PLUGIN_ERROR", t.MIDDLEWARE_ERROR = "MIDDLEWARE_ERROR", t.SUBSCRIPTION_ERROR = "SUBSCRIPTION_ERROR", t.TIMEOUT_ERROR = "TIMEOUT_ERROR", t.UNKNOWN_ERROR = "UNKNOWN_ERROR", t))(x || {}), j = ((t) => (t.WARNING = "warning", t.ERROR = "error", t.FATAL = "fatal", t))(j || {}), k = class t extends Error {
231
556
  constructor(e, r = "UNKNOWN_ERROR", n = {}, o = "error", s) {
232
- super(e), this.name = "StoreError", this.code = r, this.context = {
557
+ super(e), _(this, "code"), _(this, "context"), _(this, "severity"), _(this, "cause"), this.name = "StoreError", this.code = r, this.context = {
233
558
  ...n,
234
559
  timestamp: n.timestamp ?? Date.now()
235
560
  }, this.severity = o, this.cause = s, Object.setPrototypeOf(this, t.prototype), Error.captureStackTrace && Error.captureStackTrace(this, t);
@@ -248,23 +573,23 @@
248
573
  const t = [`[${this.code}] ${this.message}`];
249
574
  return this.context.storeId && t.push(`Store: ${this.context.storeId}`), this.context.action && t.push(`Action: ${this.context.action}`), t.join(" | ");
250
575
  }
251
- }, h = class t extends g {
576
+ }, B = class t extends k {
252
577
  constructor(e, r, n) {
253
578
  super(e, "MIDDLEWARE_ERROR", { middleware: r }, "error", n), this.name = "MiddlewareError", Object.setPrototypeOf(this, t.prototype);
254
579
  }
255
580
  };
256
- const y = {
257
- isStoreError: (t) => t instanceof g,
258
- isErrorCode: (t, e) => t instanceof g && t.code === e,
581
+ const L = {
582
+ isStoreError: (t) => t instanceof k,
583
+ isErrorCode: (t, e) => t instanceof k && t.code === e,
259
584
  wrap(t, e = "UNKNOWN_ERROR", r = {}) {
260
- if (t instanceof g) return t;
261
- return new g(t instanceof Error ? t.message : String(t), e, r, "error", t instanceof Error ? t : void 0);
585
+ if (t instanceof k) return t;
586
+ return new k(t instanceof Error ? t.message : String(t), e, r, "error", t instanceof Error ? t : void 0);
262
587
  },
263
588
  async tryCatch(t, e = "UNKNOWN_ERROR", r = {}) {
264
589
  try {
265
590
  return await t();
266
591
  } catch (t) {
267
- throw y.wrap(t, e, r);
592
+ throw L.wrap(t, e, r);
268
593
  }
269
594
  },
270
595
  createLogger: (t) => ({
@@ -278,199 +603,41 @@
278
603
  "fatal" === t.severity || "error" === t.severity ? this.error(t) : this.warn(t);
279
604
  }
280
605
  })
281
- };
282
- function S(t, e, r = !1) {
283
- let n = null, o = null;
284
- const s = (...s) => {
285
- o = s, n && clearTimeout(n), r && !n ? (t(...s), n = setTimeout(() => {
286
- n = null, o = null;
287
- }, e)) : n = setTimeout(() => {
288
- t(...s), n = null, o = null;
289
- }, e);
290
- };
291
- return s.cancel = () => {
292
- n && (clearTimeout(n), n = null, o = null);
293
- }, s.flush = () => {
294
- n && o && (clearTimeout(n), t(...o), n = null, o = null);
295
- }, s.pending = () => null !== n, s;
296
- }
297
- const m = Object.prototype.hasOwnProperty;
298
- function b(t, e) {
299
- return m.call(t, e);
300
- }
301
- function E(t) {
302
- return null !== t && "object" == typeof t;
303
- }
304
- function R(t) {
305
- if (!E(t)) return !1;
306
- const e = Object.getPrototypeOf(t);
307
- return null === e || e === Object.prototype;
308
- }
309
- function w(t) {
310
- return null == t || "boolean" == typeof t || "number" == typeof t || "string" == typeof t || "bigint" == typeof t || "function" != typeof t && "symbol" != typeof t && (t instanceof Date || t instanceof RegExp || t instanceof ArrayBuffer || t instanceof DataView || t instanceof Map || t instanceof Set || !!ArrayBuffer.isView(t) || (Array.isArray(t) ? t.every((t) => w(t)) : !!R(t) && Object.values(t).every((t) => w(t))));
311
- }
312
- function O(t, e = {}) {
313
- const { useStructuredClone: r = !0, cloneFunctions: n = !1, cloneSymbols: o = !1, maxDepth: s = Infinity, customCloner: i } = e;
314
- if (r && "function" == typeof structuredClone && w(t)) try {
315
- return structuredClone(t);
316
- } catch {}
317
- const a = /* @__PURE__ */ new WeakMap();
318
- return function t(e, r) {
319
- if (null == e) return e;
320
- if ("boolean" == typeof e || "number" == typeof e || "string" == typeof e) return e;
321
- if ("bigint" == typeof e) return e;
322
- if ("symbol" == typeof e) return o ? Symbol(e.description) : e;
323
- if ("function" == typeof e) return n ? e.bind({}) : e;
324
- if (r > s) return e;
325
- if (i) {
326
- const n = i(e, (e) => t(e, r + 1));
327
- if (void 0 !== n) return n;
328
- }
329
- if ("object" == typeof e && null !== e && a.has(e)) return a.get(e);
330
- if (e instanceof Date) return new Date(e.getTime());
331
- if (e instanceof RegExp) {
332
- const t = new RegExp(e.source, e.flags);
333
- return t.lastIndex = e.lastIndex, t;
334
- }
335
- if (e instanceof Error) {
336
- const t = new e.constructor(e.message);
337
- return t.stack = e.stack, t.name = e.name, t;
338
- }
339
- if (e instanceof Map) {
340
- const n = /* @__PURE__ */ new Map();
341
- return a.set(e, n), e.forEach((e, o) => {
342
- n.set(t(o, r + 1), t(e, r + 1));
343
- }), n;
344
- }
345
- if (e instanceof Set) {
346
- const n = /* @__PURE__ */ new Set();
347
- return a.set(e, n), e.forEach((e) => {
348
- n.add(t(e, r + 1));
349
- }), n;
350
- }
351
- if (e instanceof ArrayBuffer) return e.slice(0);
352
- if (ArrayBuffer.isView(e) && !(e instanceof DataView)) return new e.constructor(e.buffer.slice(0));
353
- if (Array.isArray(e)) {
354
- const n = [];
355
- a.set(e, n);
356
- for (let o = 0; o < e.length; o++) n[o] = t(e[o], r + 1);
357
- return n;
358
- }
359
- if (R(e)) {
360
- const n = {};
361
- a.set(e, n);
362
- const s = Object.keys(e);
363
- for (const o of s) n[o] = t(e[o], r + 1);
364
- if (o) {
365
- const o = Object.getOwnPropertySymbols(e);
366
- for (const s of o) n[s] = t(e[s], r + 1);
367
- }
368
- return n;
369
- }
370
- return e;
371
- }(t, 0);
372
- }
373
- function I(t, e, ...r) {
374
- const { arrayStrategy: n = "replace", clone: o = !0, maxDepth: s = Infinity } = e;
375
- function i(t, e, r) {
376
- if (r > s) return t;
377
- for (const s of Object.keys(e)) {
378
- const a = e[s], c = t[s];
379
- if (Array.isArray(a)) if ("concat" === n && Array.isArray(c)) t[s] = [...c, ...a];
380
- else if ("merge" === n && Array.isArray(c)) {
381
- const e = [...c];
382
- a.forEach((t, n) => {
383
- R(t) && R(e[n]) ? e[n] = i(e[n], t, r + 1) : e[n] = o ? O(t) : t;
384
- }), t[s] = e;
385
- } else t[s] = o ? O(a) : a;
386
- else R(a) ? R(c) ? t[s] = i(c, a, r + 1) : t[s] = o ? O(a) : a : t[s] = o && E(a) ? O(a) : a;
387
- }
388
- return t;
389
- }
390
- let a = t;
391
- for (const t of r) null != t && (a = i(a, t, 0));
392
- return a;
393
- }
394
- const A = /^\d+$/;
395
- function T(t, e = Object.is) {
396
- let r, n, o = !1;
397
- return (s) => {
398
- if (o && r === s) return n;
399
- const i = t(s);
400
- return o && e(i, n) || (n = i), r = s, o = !0, n;
401
- };
402
- }
403
- const v = {
606
+ }, F = {
404
607
  logState: !0,
405
608
  logAction: !0,
406
609
  collapsed: !0,
407
610
  timestamp: !0,
408
611
  level: "log"
409
- }, P = "color: #9E9E9E; font-weight: bold", $ = "color: #03A9F4; font-weight: bold", D = "color: #4CAF50; font-weight: bold", N = "color: #F44336; font-weight: bold", _ = "color: #9C27B0; font-weight: normal", x = "color: inherit; font-weight: bold";
410
- function M(t) {
612
+ }, z = "color: #9E9E9E; font-weight: bold", U = "color: #03A9F4; font-weight: bold", G = "color: #4CAF50; font-weight: bold", W = "color: #F44336; font-weight: bold", V = "color: #9C27B0; font-weight: normal", H = "color: inherit; font-weight: bold";
613
+ function K(t) {
411
614
  try {
412
- return O(t);
615
+ return y(t);
413
616
  } catch {
414
617
  return { ...t };
415
618
  }
416
619
  }
417
- function j() {
418
- const t = /* @__PURE__ */ new Map();
419
- let e = null;
420
- const r = () => (null === e && (e = Array.from(t.values()).sort((t, e) => (t.priority ?? 100) - (e.priority ?? 100))), e), n = () => {
421
- e = null;
422
- };
423
- return {
424
- use: (e) => {
425
- t.has(e.name) && console.warn(`[Middleware] 中间件 "${e.name}" 已存在,将被覆盖`), t.set(e.name, e), n();
426
- },
427
- remove: (e) => {
428
- t.delete(e) && n();
429
- },
430
- get: (e) => t.get(e),
431
- has: (e) => t.has(e),
432
- execute: async (t) => {
433
- const e = r();
434
- if (0 === e.length) return;
435
- const n = async (r) => {
436
- const o = e[r];
437
- if (!o) return;
438
- let s = !1;
439
- await o.handler(t, async () => {
440
- if (s) throw new Error(`[Middleware] next() called multiple times in "${o.name}"`);
441
- s = !0, await n(r + 1);
442
- });
443
- };
444
- await n(0);
445
- },
446
- getAll: () => r(),
447
- clear: () => {
448
- t.clear(), n();
449
- }
450
- };
451
- }
452
- let C = null;
453
- const k = {
620
+ const Y = {
454
621
  keyPrefix: "ldesign-store:",
455
622
  storage: "localStorage",
456
623
  debounce: 100,
457
- serialize: JSON.stringify,
458
- deserialize: JSON.parse
624
+ serialize: (t) => JSON.stringify(t),
625
+ deserialize: (t) => JSON.parse(t)
459
626
  };
460
- function L(t) {
627
+ function Z(t) {
461
628
  return {
462
- ...k,
629
+ ...Y,
463
630
  ...t
464
631
  };
465
632
  }
466
- function z(t) {
633
+ function Q(t) {
467
634
  return "undefined" == typeof window ? null : "localStorage" === t ? localStorage : sessionStorage;
468
635
  }
469
- const B = {
636
+ const q = {
470
637
  maxHistory: 100,
471
638
  enabled: !0
472
639
  };
473
- function U(t) {
640
+ function J(t) {
474
641
  return {
475
642
  name: t.name,
476
643
  version: t.version,
@@ -482,83 +649,49 @@
482
649
  onStateChange: t.onStateChange
483
650
  };
484
651
  }
485
- function F() {
486
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map();
487
- return {
488
- use: (r, n) => {
489
- t.has(r.name) && console.warn(`[Plugin] 插件 "${r.name}" 已存在,将被覆盖`), t.set(r.name, r);
490
- const o = {
491
- storeManager: {
492
- getStore: () => null,
493
- hasStore: () => !1,
494
- getStoreIds: () => []
495
- },
496
- storeId: "",
497
- store: null,
498
- options: n || {}
499
- };
500
- e.set(r.name, o);
501
- },
502
- remove: (r) => {
503
- const n = t.get(r), o = e.get(r);
504
- n && o && n.uninstall?.(o), t.delete(r), e.delete(r);
505
- },
506
- get: (e) => t.get(e),
507
- has: (e) => t.has(e),
508
- getAll: () => new Map(t),
509
- size: () => t.size,
510
- clear: () => {
511
- t.forEach((t, r) => {
512
- const n = e.get(r);
513
- n && t.uninstall?.(n);
514
- }), t.clear(), e.clear();
515
- }
516
- };
517
- }
518
- let G = null;
519
- exports.BaseStore = o, exports.DeserializationError = class t extends g {
652
+ exports.BaseStore = P, exports.DeserializationError = class t extends k {
520
653
  constructor(e, r, n) {
521
654
  super(e, "DESERIALIZATION_ERROR", { storeId: n }, "error", r), this.name = "DeserializationError", Object.setPrototypeOf(this, t.prototype);
522
655
  }
523
- }, exports.ErrorSeverity = p, exports.InvalidStateError = class t extends g {
656
+ }, exports.ErrorSeverity = j, exports.InvalidStateError = class t extends k {
524
657
  constructor(e, r, n) {
525
658
  super(e, "INVALID_STATE", {
526
659
  storeId: r,
527
660
  data: n
528
661
  }, "error"), this.name = "InvalidStateError", Object.setPrototypeOf(this, t.prototype);
529
662
  }
530
- }, exports.MiddlewareError = h, exports.PluginError = class t extends g {
663
+ }, exports.MiddlewareError = B, exports.PluginError = class t extends k {
531
664
  constructor(e, r, n) {
532
665
  super(e, "PLUGIN_ERROR", { plugin: r }, "error", n), this.name = "PluginError", Object.setPrototypeOf(this, t.prototype);
533
666
  }
534
- }, exports.SerializationError = class t extends g {
667
+ }, exports.SerializationError = class t extends k {
535
668
  constructor(e, r, n) {
536
669
  super(e, "SERIALIZATION_ERROR", { storeId: n }, "error", r), this.name = "SerializationError", Object.setPrototypeOf(this, t.prototype);
537
670
  }
538
- }, exports.StorageError = class t extends g {
671
+ }, exports.StorageError = class t extends k {
539
672
  constructor(e, r, n) {
540
673
  super(e, "STORAGE_ERROR", { storeId: n }, "error", r), this.name = "StorageError", Object.setPrototypeOf(this, t.prototype);
541
674
  }
542
- }, exports.StoreAlreadyExistsError = class t extends g {
675
+ }, exports.StoreAlreadyExistsError = class t extends k {
543
676
  constructor(e) {
544
677
  super(`Store "${e}" 已存在`, "STORE_ALREADY_EXISTS", { storeId: e }, "warning"), this.name = "StoreAlreadyExistsError", Object.setPrototypeOf(this, t.prototype);
545
678
  }
546
- }, exports.StoreDisposedError = class t extends g {
679
+ }, exports.StoreDisposedError = class t extends k {
547
680
  constructor(e, r) {
548
681
  super(`Store "${e}" 已被销毁,无法执行操作${r ? `: ${r}` : ""}`, "STORE_DISPOSED", {
549
682
  storeId: e,
550
683
  action: r
551
684
  }, "error"), this.name = "StoreDisposedError", Object.setPrototypeOf(this, t.prototype);
552
685
  }
553
- }, exports.StoreError = g, exports.StoreErrorCode = d, exports.StoreNotFoundError = class t extends g {
686
+ }, exports.StoreError = k, exports.StoreErrorCode = x, exports.StoreNotFoundError = class t extends k {
554
687
  constructor(e) {
555
688
  super(`Store "${e}" 不存在`, "STORE_NOT_FOUND", { storeId: e }, "error"), this.name = "StoreNotFoundError", Object.setPrototypeOf(this, t.prototype);
556
689
  }
557
- }, exports.SubscriptionError = class t extends g {
690
+ }, exports.SubscriptionError = class t extends k {
558
691
  constructor(e, r, n) {
559
692
  super(e, "SUBSCRIPTION_ERROR", { storeId: n }, "warning", r), this.name = "SubscriptionError", Object.setPrototypeOf(this, t.prototype);
560
693
  }
561
- }, exports.TimeoutError = class t extends g {
694
+ }, exports.TimeoutError = class t extends k {
562
695
  constructor(e, r, n) {
563
696
  super(e, "TIMEOUT_ERROR", {
564
697
  storeId: r,
@@ -566,13 +699,13 @@
566
699
  }, "error"), this.name = "TimeoutError", Object.setPrototypeOf(this, t.prototype);
567
700
  }
568
701
  }, exports.batch = function(t) {
569
- return a().batch(t);
702
+ return w().batch(t);
570
703
  }, exports.combineSelectors = function(t, e) {
571
704
  return (r) => e(...t.map((t) => t(r)));
572
705
  }, exports.composePlugins = function(t) {
573
706
  return {
574
707
  name: "composed-plugins",
575
- version: "1.0.0",
708
+ version: "0.0.1",
576
709
  async install(e, r) {
577
710
  for (const n of t) await n.install(e, r);
578
711
  },
@@ -589,63 +722,91 @@
589
722
  t.forEach((t) => t.onStateChange?.(e, r, n));
590
723
  }
591
724
  };
592
- }, exports.createAsyncAction = function(e, r = {}) {
593
- const { retryCount: n = 0, retryDelay: o = 1e3, timeout: s = 0, resetOnExecute: i = !0 } = r, a = {
725
+ }, exports.createAsyncAction = function(r, n = {}) {
726
+ const { retryCount: o = 0, retryDelay: s = 1e3, timeout: i = 0, resetOnExecute: a = !0 } = n, c = {
594
727
  data: null,
595
728
  error: null,
596
729
  loading: !1,
597
730
  executionCount: 0,
598
731
  lastExecutedAt: null
599
- }, c = t(), l = t(), u = t();
600
- let f = null;
601
- const d = () => {
602
- c.publish({ ...a });
603
- }, p = async (t, r) => {
732
+ }, l = t(), u = t(), f = t();
733
+ let d = 0, h = null;
734
+ const p = () => l.publish({ ...c }), g = r, y = async (t, r, n) => {
735
+ if (n.controller.signal.aborted) throw n.abortReason ?? e();
604
736
  try {
605
- return await e(...t);
606
- } catch (e) {
607
- if (r > 0 && !f?.signal.aborted) {
608
- if (await (n = o, new Promise((t) => setTimeout(t, n))), f?.signal.aborted) throw new Error("Aborted");
609
- return p(t, r - 1);
610
- }
611
- throw e;
737
+ const r = await g(...t, n.controller.signal);
738
+ if (n.controller.signal.aborted) throw n.abortReason ?? e();
739
+ return r;
740
+ } catch (a) {
741
+ if (n.controller.signal.aborted) throw n.abortReason ?? e();
742
+ if (r <= 0) throw a;
743
+ return await (o = s, i = n.controller.signal, i.aborted ? Promise.reject(e()) : new Promise((t, r) => {
744
+ let n;
745
+ const s = () => {
746
+ clearTimeout(n), i.removeEventListener("abort", s), r(e());
747
+ };
748
+ n = setTimeout(() => {
749
+ i.removeEventListener("abort", s), t();
750
+ }, o), i.addEventListener("abort", s, { once: !0 });
751
+ })), y(t, r - 1, n);
612
752
  }
613
- var n;
753
+ var o, i;
754
+ }, m = (t, e) => {
755
+ t.abortReason = e, t.controller.signal.aborted || t.controller.abort(), t.rejectAbort?.(e), t.timeoutId && (clearTimeout(t.timeoutId), t.timeoutId = void 0);
614
756
  };
615
757
  return {
616
758
  get state() {
617
- return { ...a };
759
+ return { ...c };
618
760
  },
619
761
  execute: async (...t) => {
620
- f && f.abort(), f = new AbortController(), i && (a.error = null), a.loading = !0, a.executionCount++, a.lastExecutedAt = Date.now(), d();
762
+ h && m(h, e());
763
+ const r = {
764
+ id: ++d,
765
+ controller: new AbortController()
766
+ };
767
+ h = r, a && (c.error = null), c.loading = !0, c.executionCount++, c.lastExecutedAt = Date.now(), p();
621
768
  try {
622
- let e;
623
- if (s > 0) {
624
- const r = new Promise((t, e) => {
625
- setTimeout(() => e(/* @__PURE__ */ new Error(`Timeout after ${s}ms`)), s);
626
- });
627
- e = await Promise.race([p(t, n), r]);
628
- } else e = await p(t, n);
629
- return f.signal.aborted || (a.data = e, a.error = null, a.loading = !1, d(), l.publish(e)), e;
769
+ const e = y(t, o, r), n = new Promise((t, e) => {
770
+ r.rejectAbort = e;
771
+ }), s = i > 0 ? new Promise((t, e) => {
772
+ r.timeoutId = setTimeout(() => {
773
+ const t = /* @__PURE__ */ new Error(`Timeout after ${i}ms`);
774
+ r.abortReason = t, r.controller.abort(), e(t);
775
+ }, i);
776
+ }) : null;
777
+ r.result = s ? Promise.race([
778
+ e,
779
+ n,
780
+ s
781
+ ]) : Promise.race([e, n]);
782
+ const a = await r.result;
783
+ return h?.id !== r.id || r.controller.signal.aborted || (c.data = a, c.error = null, c.loading = !1, p(), u.publish(a)), a;
630
784
  } catch (t) {
631
- if (!f.signal.aborted) {
785
+ if (h?.id === r.id) {
632
786
  const e = t instanceof Error ? t : new Error(String(t));
633
- a.error = e, a.loading = !1, d(), u.publish(e);
787
+ c.error = e, c.loading = !1, p(), "Aborted" !== r.abortReason?.message && f.publish(e);
634
788
  }
635
789
  throw t;
790
+ } finally {
791
+ r.timeoutId && (clearTimeout(r.timeoutId), r.timeoutId = void 0), h?.id === r.id && (h = null);
636
792
  }
637
793
  },
638
794
  reset: () => {
639
- f && (f.abort(), f = null), a.data = null, a.error = null, a.loading = !1, a.executionCount = 0, a.lastExecutedAt = null, d();
795
+ if (h) {
796
+ const t = h;
797
+ h = null, m(t, e());
798
+ }
799
+ c.data = null, c.error = null, c.loading = !1, c.executionCount = 0, c.lastExecutedAt = null, p();
640
800
  },
641
801
  abort: () => {
642
- f && (f.abort(), f = null), a.loading && (a.loading = !1, a.error = /* @__PURE__ */ new Error("Aborted"), d());
802
+ const t = h;
803
+ t && (h = null, m(t, e()), c.loading && (c.loading = !1, c.error = t.abortReason ?? e(), p()));
643
804
  },
644
- subscribe: (t) => c.subscribe(t),
645
- onSuccess: (t) => l.subscribe(t),
646
- onError: (t) => u.subscribe(t)
805
+ subscribe: (t) => l.subscribe(t),
806
+ onSuccess: (t) => u.subscribe(t),
807
+ onError: (t) => f.subscribe(t)
647
808
  };
648
- }, exports.createBatchManager = s, exports.createCachedSelector = function(t, e = {}) {
809
+ }, exports.createBatchManager = E, exports.createCachedSelector = function(t, e = {}) {
649
810
  const { maxSize: r = 10 } = e, n = /* @__PURE__ */ new Map(), o = (e) => {
650
811
  if (n.has(e)) {
651
812
  const t = n.get(e);
@@ -659,9 +820,9 @@
659
820
  return n.set(e, o), o;
660
821
  };
661
822
  return o.clearCache = () => n.clear(), o.getCacheSize = () => n.size, o;
662
- }, exports.createEventBus = e, exports.createLoggerMiddleware = function(t = {}) {
823
+ }, exports.createEventBus = I, exports.createLoggerMiddleware = function(t = {}) {
663
824
  const e = {
664
- ...v,
825
+ ...F,
665
826
  ...t
666
827
  }, r = e.logger ?? console;
667
828
  return {
@@ -674,27 +835,27 @@
674
835
  if (c && !e.logState || l && !e.logAction) return void await n();
675
836
  const u = e.timestamp ? `${(f = /* @__PURE__ */ new Date()).getHours().toString().padStart(2, "0")}:${f.getMinutes().toString().padStart(2, "0")}:${f.getSeconds().toString().padStart(2, "0")}.${f.getMilliseconds().toString().padStart(3, "0")}` : "";
676
837
  var f;
677
- const d = `[Store: ${o}]`, p = performance.now(), g = M(i), y = u ? `${u} ${d} ${s}` : `${d} ${s}`;
678
- e.collapsed && "function" == typeof r.groupCollapsed ? r.groupCollapsed(`%c${y}`, x) : "function" == typeof r.group && r.group(`%c${y}`, x);
838
+ const d = `[Store: ${o}]`, h = performance.now(), p = K(i), g = u ? `${u} ${d} ${s}` : `${d} ${s}`;
839
+ e.collapsed && "function" == typeof r.groupCollapsed ? r.groupCollapsed(`%c${g}`, H) : "function" == typeof r.group && r.group(`%c${g}`, H);
679
840
  try {
680
841
  const o = r[e.level ?? "log"] ?? r.log;
681
- "function" == typeof o && (o.call(r, "%c prev state", P, g), void 0 !== a && o.call(r, "%c payload", $, a)), await n();
842
+ "function" == typeof o && (o.call(r, "%c prev state", z, p), void 0 !== a && o.call(r, "%c payload", U, a)), await n();
682
843
  const s = performance.now();
683
- "function" == typeof o && (o.call(r, "%c next state", D, M(t.state)), o.call(r, "%c duration", _, function(t, e) {
844
+ "function" == typeof o && (o.call(r, "%c next state", G, K(t.state)), o.call(r, "%c duration", V, function(t, e) {
684
845
  const r = e - t;
685
846
  return r < 1 ? "< 1ms" : `${r.toFixed(2)}ms`;
686
- }(p, s)));
847
+ }(h, s)));
687
848
  } catch (t) {
688
- throw "function" == typeof r.error && r.error("%c error", N, t), new h(`日志中间件执行错误: ${t instanceof Error ? t.message : String(t)}`, "logger", t instanceof Error ? t : void 0);
849
+ throw "function" == typeof r.error && r.error("%c error", W, t), new B(`日志中间件执行错误: ${t instanceof Error ? t.message : String(t)}`, "logger", t instanceof Error ? t : void 0);
689
850
  } finally {
690
851
  "function" == typeof r.groupEnd && r.groupEnd();
691
852
  }
692
853
  }
693
854
  };
694
855
  }, exports.createMemoizedSelector = function(t, e = {}) {
695
- return T(t, e.equalityFn);
696
- }, exports.createMiddlewareManager = j, exports.createPersistMiddleware = function(t = {}) {
697
- const e = L(t), r = z(e.storage), n = /* @__PURE__ */ new Map(), o = (t, n) => {
856
+ return b(t, e.equalityFn);
857
+ }, exports.createMiddlewareManager = r, exports.createPersistMiddleware = function(t = {}) {
858
+ const e = Z(t), r = Q(e.storage), n = /* @__PURE__ */ new Map(), o = (t, n) => {
698
859
  if (r) try {
699
860
  const o = ((t, r) => {
700
861
  const n = e.paths?.[t];
@@ -723,13 +884,13 @@
723
884
  const { storeId: s, type: i, state: a } = t;
724
885
  i.startsWith("state:") && (e.stores && !e.stores.includes(s) || ((t) => {
725
886
  let r = n.get(t);
726
- return r || (r = S((e) => o(t, e), e.debounce), n.set(t, r)), r;
887
+ return r || (r = u((e) => o(t, e), e.debounce), n.set(t, r)), r;
727
888
  })(s)(a));
728
889
  }
729
890
  };
730
891
  }, exports.createPluginFactory = function(t) {
731
- return (e) => U(t(e));
732
- }, exports.createPluginManager = F, exports.createPubSub = t, exports.createPubSubWithValue = function(e) {
892
+ return (e) => J(t(e));
893
+ }, exports.createPluginManager = i, exports.createPubSub = t, exports.createPubSubWithValue = function(e) {
733
894
  let r = e;
734
895
  const n = t();
735
896
  return {
@@ -746,7 +907,7 @@
746
907
  r = t, n.publish(t, e);
747
908
  }
748
909
  };
749
- }, exports.createSelector = T, exports.createSelectorWithDeps = function(t, e, r = {}) {
910
+ }, exports.createSelector = b, exports.createSelectorWithDeps = function(t, e, r = {}) {
750
911
  const { equalityFn: n = Object.is, trackHitRate: o = !1 } = r;
751
912
  let s, i, a = !1, c = 0, l = 0;
752
913
  const u = (r) => {
@@ -776,23 +937,23 @@
776
937
  e && void 0 !== a ? console.info(c, a) : console.info(c), await o();
777
938
  }
778
939
  };
779
- }, exports.createStore = function(t) {
780
- let e = null;
940
+ }, exports.createStore = function(t, e = {}) {
941
+ let r = null;
781
942
  return () => {
782
- if (e) return e;
783
- const r = new o(t), n = r.$dispose.bind(r);
784
- return r.$dispose = () => {
785
- n(), e = null;
786
- }, e = r, r;
943
+ if (r) return r;
944
+ const n = new P(t, e), o = n.$dispose.bind(n);
945
+ return n.$dispose = () => {
946
+ o(), r = null;
947
+ }, r = n, n;
787
948
  };
788
949
  }, exports.createStoreEngineBridge = function(t) {
789
- const { createRuntime: e, debug: n = !1, name: o = "store", onRuntimeChange: s, version: i = "1.0.0" } = t;
790
- let a, d = {}, p = null, g = null;
791
- const h = (e, n) => {
792
- const l = p, u = g;
793
- return p = e, g = n, s?.(e), function(t, e, n, o) {
794
- t.state?.set?.(c.RUNTIME, o), t.state?.set?.(c.PINIA, o.pinia), t.state?.set?.(c.API, o.storeAPI), t.state?.set?.(c.REGISTRY, o.registry), t.state?.set?.(c.BUS, r), t.state?.set?.(`plugins.${e}`, o.storeAPI), t.state?.set?.(`plugins.${e}.config`, n);
795
- }(d, o, t, e), function(t, e, r, n) {
950
+ const { createRuntime: e, debug: r = !1, name: n = "store", onRuntimeChange: o, version: s = "0.0.1" } = t;
951
+ let i, a = {}, c = null, l = null, u = 0, f = null;
952
+ const d = (e, r) => {
953
+ const u = c, f = l;
954
+ return c = e, l = r, o?.(e), function(t, e, r, n) {
955
+ t.state?.set?.(T.RUNTIME, n), t.state?.set?.(T.PINIA, n.pinia), t.state?.set?.(T.API, n.storeAPI), t.state?.set?.(T.REGISTRY, n.registry), t.state?.set?.(T.BUS, A), t.state?.set?.(`plugins.${e}`, n.storeAPI), t.state?.set?.(`plugins.${e}.config`, r);
956
+ }(a, n, t, e), function(t, e, r, n) {
796
957
  if (!t.api?.register) return;
797
958
  const o = function(t, e, r) {
798
959
  return {
@@ -806,68 +967,72 @@
806
967
  };
807
968
  }(e, r, n);
808
969
  t.api.unregister?.(e), t.api.register.length >= 2 ? t.api.register(e, o) : t.api.register(o);
809
- }(d, o, i, e), function(t, e) {
970
+ }(a, n, s, e), function(t, e) {
810
971
  if (t?.container?.singleton) try {
811
972
  t.container.singleton("pinia", e.pinia), t.container.singleton("storeAPI", e.storeAPI), t.container.singleton("storeRegistry", e.registry), t.container.singleton("storeRuntime", e);
812
973
  } catch {}
813
- }(a, e), l && l !== e && "engine" === u && l.dispose?.(), e;
814
- }, y = () => p && "engine" === g ? p : e(), S = (e) => {
974
+ }(i, e), u && u !== e && "engine" === f && u.dispose?.(), e;
975
+ }, h = () => c && "engine" === l ? c : e(), p = (e) => {
815
976
  const r = t.getRuntimeFromApp?.(e);
816
- if (r) return h(r, "external");
817
- const n = y(), o = t.attachToApp ? t.attachToApp(e, n) : n;
818
- return h(o, o === n ? "engine" : "external");
977
+ if (r) return d(r, "external");
978
+ const n = h(), o = t.attachToApp ? t.attachToApp(e, n) : n;
979
+ return d(o, o === n ? "engine" : "external");
819
980
  };
820
981
  return {
821
- attachToApp: S,
822
- getRuntime: () => p,
982
+ attachToApp: p,
983
+ getRuntime: () => c,
823
984
  install: async (e) => {
824
- d = u(e), a = function(t) {
985
+ const o = ++u;
986
+ f = null, a = D(e), i = function(t) {
825
987
  return t && "object" == typeof t ? t : void 0;
826
988
  }(e);
827
- const r = t.resolveApp ? t.resolveApp(d, a ?? {}, void 0) : f(d, a);
828
- !r || t.isApp && !t.isApp(r) ? (h(y(), "engine"), d.events?.once?.("app:created", (e) => {
829
- const r = t.resolveApp ? t.resolveApp(d, a ?? {}, e) : f(d, a, e);
830
- !r || t.isApp && !t.isApp(r) || S(r);
831
- })) : S(r), await d.events?.emit?.(l.INSTALLED, {
832
- name: o,
833
- version: i,
834
- pinia: p?.pinia,
835
- storeAPI: p?.storeAPI
836
- }), n && d.logger?.info?.("[StoreEngineBridge] installed");
989
+ const l = t.resolveApp ? t.resolveApp(a, i ?? {}, void 0) : N(a, i);
990
+ !l || t.isApp && !t.isApp(l) ? (d(h(), "engine"), f = o, a.events?.once?.("app:created", (e) => {
991
+ if (f !== o || u !== o || !c) return;
992
+ f = null;
993
+ const r = t.resolveApp ? t.resolveApp(a, i ?? {}, e) : N(a, i, e);
994
+ !r || t.isApp && !t.isApp(r) || p(r);
995
+ })) : p(l), await a.events?.emit?.($.INSTALLED, {
996
+ name: n,
997
+ version: s,
998
+ pinia: c?.pinia,
999
+ storeAPI: c?.storeAPI
1000
+ }), r && a.logger?.info?.("[StoreEngineBridge] installed");
837
1001
  },
838
1002
  uninstall: async (t) => {
839
- const e = t ? u(t) : d;
840
- e.api?.unregister?.(o), function(t, e) {
841
- t.state?.delete?.(c.RUNTIME), t.state?.delete?.(c.PINIA), t.state?.delete?.(c.API), t.state?.delete?.(c.REGISTRY), t.state?.delete?.(c.BUS), t.state?.delete?.(`plugins.${e}`), t.state?.delete?.(`plugins.${e}.config`);
842
- }(e, o), await e.events?.emit?.(l.UNINSTALLED, { name: o }), p && "engine" === g && p.dispose?.(), p = null, g = null, s?.(null), n && e.logger?.info?.("[StoreEngineBridge] uninstalled");
1003
+ u++, f = null;
1004
+ const e = t ? D(t) : a;
1005
+ e.api?.unregister?.(n), function(t, e) {
1006
+ t.state?.delete?.(T.RUNTIME), t.state?.delete?.(T.PINIA), t.state?.delete?.(T.API), t.state?.delete?.(T.REGISTRY), t.state?.delete?.(T.BUS), t.state?.delete?.(`plugins.${e}`), t.state?.delete?.(`plugins.${e}.config`);
1007
+ }(e, n), await e.events?.emit?.($.UNINSTALLED, { name: n }), c && "engine" === l && c.dispose?.(), c = null, l = null, o?.(null), r && e.logger?.info?.("[StoreEngineBridge] uninstalled");
843
1008
  }
844
1009
  };
845
1010
  }, exports.createTimeTravelMiddleware = function(t = {}) {
846
1011
  const e = {
847
- ...B,
1012
+ ...q,
848
1013
  ...t
849
- }, r = e.maxHistory ?? B.maxHistory ?? 100, n = [];
1014
+ }, r = e.maxHistory ?? q.maxHistory ?? 100, n = [];
850
1015
  let o = -1, s = !1, i = () => {};
851
1016
  const a = {
852
1017
  undo: () => {
853
1018
  if (!a.canUndo()) return;
854
1019
  s = !0, o--;
855
1020
  const t = n[o];
856
- i(t.storeId, O(t.state)), s = !1;
1021
+ i(t.storeId, y(t.state)), s = !1;
857
1022
  },
858
1023
  redo: () => {
859
1024
  if (!a.canRedo()) return;
860
1025
  s = !0, o++;
861
1026
  const t = n[o];
862
- i(t.storeId, O(t.state)), s = !1;
1027
+ i(t.storeId, y(t.state)), s = !1;
863
1028
  },
864
1029
  goto: (t) => {
865
1030
  if (t < 0 || t >= n.length) return;
866
1031
  s = !0, o = t;
867
1032
  const e = n[o];
868
- i(e.storeId, O(e.state)), s = !1;
1033
+ i(e.storeId, y(e.state)), s = !1;
869
1034
  },
870
- getHistory: () => O(n),
1035
+ getHistory: () => y(n),
871
1036
  getCurrentIndex: () => o,
872
1037
  canUndo: () => o > 0,
873
1038
  canRedo: () => o < n.length - 1,
@@ -887,7 +1052,7 @@
887
1052
  if (!c.startsWith("state:") || s) return void await i();
888
1053
  const u = {
889
1054
  timestamp: Date.now(),
890
- state: O(l),
1055
+ state: y(l),
891
1056
  type: c,
892
1057
  storeId: a
893
1058
  };
@@ -938,10 +1103,10 @@
938
1103
  handler: async (t, a) => {
939
1104
  const { storeId: c, type: l, state: u } = t;
940
1105
  if (!(o ? "state:patch" === l : l.startsWith("state:")) || !e[c]) return void await a();
941
- await a();
942
1106
  const f = await i(c, u);
943
1107
  if (f.valid) s = s.filter((t) => t.storeId !== c);
944
1108
  else if (s = f.errors, r?.(f), n) throw new Error(`[Validation] ${c}: ${f.errors.map((t) => t.message).join("; ")}`);
1109
+ await a();
945
1110
  }
946
1111
  },
947
1112
  validate: i,
@@ -950,7 +1115,7 @@
950
1115
  s = [];
951
1116
  }
952
1117
  };
953
- }, exports.debounce = S, exports.deepClone = O, exports.deepEqual = function t(e, r) {
1118
+ }, exports.debounce = u, exports.deepClone = y, exports.deepEqual = function t(e, r) {
954
1119
  if (e === r) return !0;
955
1120
  if (null === e || null === r || void 0 === e || void 0 === r) return e === r;
956
1121
  if (typeof e != typeof r) return !1;
@@ -972,11 +1137,11 @@
972
1137
  for (let n = 0; n < e.length; n++) if (!t(e[n], r[n])) return !1;
973
1138
  return !0;
974
1139
  }
975
- if (R(e) && R(r)) {
1140
+ if (p(e) && p(r)) {
976
1141
  const n = Object.keys(e), o = Object.keys(r);
977
1142
  if (n.length !== o.length) return !1;
978
1143
  for (const o of n) {
979
- if (!b(r, o)) return !1;
1144
+ if (!d(r, o)) return !1;
980
1145
  if (!t(e[o], r[o])) return !1;
981
1146
  }
982
1147
  return !0;
@@ -990,8 +1155,8 @@
990
1155
  }
991
1156
  return Object.freeze(e);
992
1157
  }, exports.deepMerge = function(t, ...e) {
993
- return I(t, {}, ...e);
994
- }, exports.deepMergeWithOptions = I, exports.defineStorePlugin = U, exports.deleteByPath = function(t, e) {
1158
+ return m(t, {}, ...e);
1159
+ }, exports.deepMergeWithOptions = m, exports.defineStorePlugin = J, exports.deleteByPath = function(t, e) {
995
1160
  if (!e || 0 === e.length) return !1;
996
1161
  const r = e.replace(/\[([^\]]+)\]/g, ".$1").split(".").filter(Boolean);
997
1162
  let n = t;
@@ -1009,7 +1174,7 @@
1009
1174
  return delete n[o], !0;
1010
1175
  }
1011
1176
  return !1;
1012
- }, exports.errorUtils = y, exports.getByPath = function(t, e, r) {
1177
+ }, exports.errorUtils = L, exports.getByPath = function(t, e, r) {
1013
1178
  if (!e || 0 === e.length) return t;
1014
1179
  const n = e.replace(/\[([^\]]+)\]/g, ".$1").split(".").filter(Boolean);
1015
1180
  let o = t;
@@ -1019,11 +1184,7 @@
1019
1184
  o = o[t];
1020
1185
  }
1021
1186
  return void 0 === o ? r : o;
1022
- }, exports.getGlobalBatchManager = a, exports.getGlobalMiddlewareManager = function() {
1023
- return C || (C = j()), C;
1024
- }, exports.getGlobalPluginManager = function() {
1025
- return G || (G = F()), G;
1026
- }, exports.globalEventBus = r, exports.hasPath = function(t, e) {
1187
+ }, exports.getGlobalBatchManager = w, exports.getGlobalMiddlewareManager = o, exports.getGlobalPluginManager = l, exports.globalEventBus = A, exports.hasPath = function(t, e) {
1027
1188
  if (!e || 0 === e.length) return !0;
1028
1189
  const r = e.replace(/\[([^\]]+)\]/g, ".$1").split(".").filter(Boolean);
1029
1190
  let n = t;
@@ -1034,8 +1195,8 @@
1034
1195
  n = n[t];
1035
1196
  }
1036
1197
  return !0;
1037
- }, exports.isObject = E, exports.isPlainObject = R, exports.name = "@composy/store-core", exports.restoreState = function(t, e = {}) {
1038
- const r = L(e), n = z(r.storage);
1198
+ }, exports.isObject = h, exports.isPlainObject = p, exports.name = "@composy/store-core", exports.restoreState = function(t, e = {}) {
1199
+ const r = Z(e), n = Q(r.storage);
1039
1200
  if (!n) return null;
1040
1201
  try {
1041
1202
  const e = `${r.keyPrefix}${t}`, o = n.getItem(e);
@@ -1049,22 +1210,22 @@
1049
1210
  const n = e.replace(/\[([^\]]+)\]/g, ".$1").split(".").filter(Boolean);
1050
1211
  let o = t;
1051
1212
  for (let t = 0; t < n.length - 1; t++) {
1052
- const e = n[t], r = n[t + 1] ?? "", s = o[e] ?? (A.test(r) ? [] : {});
1213
+ const e = n[t], r = n[t + 1] ?? "", s = o[e] ?? (S.test(r) ? [] : {});
1053
1214
  o[e] = s, o = o[e];
1054
1215
  }
1055
1216
  return o[n[n.length - 1]] = r, !0;
1056
1217
  }, exports.setGlobalBatchManager = function(t) {
1057
- i = t;
1218
+ R = t;
1058
1219
  }, exports.setGlobalMiddlewareManager = function(t) {
1059
- C = t;
1220
+ n = t;
1060
1221
  }, exports.setGlobalPluginManager = function(t) {
1061
- G = t;
1222
+ c = t;
1062
1223
  }, exports.setRestoreCallback = function(t, e) {
1063
1224
  const r = t;
1064
1225
  "function" != typeof r.__setRestoreCallback ? console.warn("[TimeTravel] 请使用 createTimeTravelMiddleware 返回的 controller") : r.__setRestoreCallback(e);
1065
1226
  }, exports.shallowClone = function(t) {
1066
1227
  return null == t || "object" != typeof t ? t : Array.isArray(t) ? [...t] : t instanceof Map ? new Map(t) : t instanceof Set ? new Set(t) : t instanceof Date ? new Date(t.getTime()) : { ...t };
1067
- }, exports.storeEventKeys = l, exports.storeStateKeys = c, exports.throttle = function(t, e, r = {}) {
1228
+ }, exports.storeEventKeys = $, exports.storeStateKeys = T, exports.throttle = function(t, e, r = {}) {
1068
1229
  const { leading: n = !0, trailing: o = !0 } = r;
1069
1230
  let s = null, i = 0, a = null;
1070
1231
  const c = (...r) => {
@@ -1076,7 +1237,7 @@
1076
1237
  return c.cancel = () => {
1077
1238
  s && (clearTimeout(s), s = null), i = 0, a = null;
1078
1239
  }, c;
1079
- }, exports.version = "1.0.0";
1240
+ }, exports.version = "0.0.1";
1080
1241
  });
1081
1242
  /*! End of @composy/store-core | Powered by @composy/builder */
1082
1243
  //# sourceMappingURL=index.min.js.map