vane-waterfall 2.0.1 → 2.0.3

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 (134) hide show
  1. package/README.md +4 -4
  2. package/dist/chunks/WaterfallCore-EdAZuWAY.js +695 -0
  3. package/dist/chunks/doc-BAhVW3g8.js +150 -0
  4. package/dist/chunks/doc-BU0CKW63.js +156 -0
  5. package/dist/chunks/doc-BrEd0oZB.js +100 -0
  6. package/dist/chunks/{doc-bTHwfIVb.js → doc-Bud0hbaz.js} +39 -25
  7. package/dist/chunks/{doc-DukOmDCo.js → doc-C-B3zK2o.js} +52 -23
  8. package/dist/chunks/{doc-DElLNjIc.js → doc-C206ZwYC.js} +33 -24
  9. package/dist/chunks/doc-C2L8kkeI.js +112 -0
  10. package/dist/chunks/doc-CE1DGMBV.js +166 -0
  11. package/dist/chunks/{doc-BXSy2aPP.js → doc-CHbQXLwY.js} +33 -19
  12. package/dist/chunks/{doc-BfWnfTst.js → doc-CInpKZNU.js} +38 -24
  13. package/dist/chunks/{doc-gTAsLjVx.js → doc-CYxwSuG6.js} +30 -16
  14. package/dist/chunks/{doc-DzvTrZ13.js → doc-CaJ02INP.js} +25 -16
  15. package/dist/chunks/{doc-BXElhF2h.js → doc-CiCso5Ti.js} +44 -30
  16. package/dist/chunks/doc-CkuMr8Ca.js +118 -0
  17. package/dist/chunks/{doc-3Fpag2G8.js → doc-D7m1OFCW.js} +38 -24
  18. package/dist/chunks/doc-DEN2WTDh.js +153 -0
  19. package/dist/chunks/{doc-C5xrHNoC.js → doc-DhICh9S2.js} +37 -23
  20. package/dist/chunks/doc-DlJICsyN.js +100 -0
  21. package/dist/chunks/{doc-BtzhgTYj.js → doc-DtxS1-P0.js} +35 -26
  22. package/dist/chunks/{doc-BIzjYAZW.js → doc-DudYCn_-.js} +25 -16
  23. package/dist/chunks/doc-HoyAFR_m.js +101 -0
  24. package/dist/chunks/doc-RlBMCMNs.js +170 -0
  25. package/dist/chunks/doc-RwKQqySd.js +102 -0
  26. package/dist/chunks/{doc-CTUoMe7o.js → doc-eYhNJy97.js} +31 -22
  27. package/dist/chunks/{doc-CcPFavOs.js → doc-i6FY1We1.js} +27 -13
  28. package/dist/chunks/doc-skPl6ZMP.js +101 -0
  29. package/dist/chunks/index-8gEIzUxi.js +15 -0
  30. package/dist/chunks/index-B96I5CKE.js +21 -0
  31. package/dist/chunks/index-Bjmhy8jW.js +11 -0
  32. package/dist/chunks/index-Cuq0ofv-.js +13 -0
  33. package/dist/chunks/{index-BAWlVYr3.js → index-Cz4YEqRF.js} +1 -1
  34. package/dist/chunks/{index-wLI6UXkY.js → index-FBJVUYmH.js} +1 -1
  35. package/dist/chunks/withPlugins-BOeDFhof.js +743 -0
  36. package/dist/components/WaterfallPlugin/WaterfallCore.d.ts +19 -0
  37. package/dist/components/WaterfallPlugin/WaterfallCore.d.ts.map +1 -1
  38. package/dist/components/WaterfallPlugin/layout.d.ts +7 -0
  39. package/dist/components/WaterfallPlugin/layout.d.ts.map +1 -1
  40. package/dist/components/WaterfallPlugin/plugins/types.d.ts +3 -0
  41. package/dist/components/WaterfallPlugin/plugins/types.d.ts.map +1 -1
  42. package/dist/components/WaterfallPlugin/withPlugins.d.ts.map +1 -1
  43. package/dist/custom-plugins/A11yPlugin/create.d.ts.map +1 -1
  44. package/dist/custom-plugins/A11yPlugin/doc.json.d.ts +64 -40
  45. package/dist/custom-plugins/A11yPlugin/index.js +1 -1
  46. package/dist/custom-plugins/AlignmentPlugin/doc.json.d.ts +42 -28
  47. package/dist/custom-plugins/AlignmentPlugin/index.js +1 -1
  48. package/dist/custom-plugins/AutoColumnPlugin/doc.json.d.ts +53 -44
  49. package/dist/custom-plugins/AutoColumnPlugin/index.js +1 -1
  50. package/dist/custom-plugins/BookmarkPlugin/create.d.ts.map +1 -1
  51. package/dist/custom-plugins/BookmarkPlugin/doc.json.d.ts +44 -35
  52. package/dist/custom-plugins/BookmarkPlugin/index.js +1 -1
  53. package/dist/custom-plugins/ClickAnalyticsPlugin/create.d.ts +2 -0
  54. package/dist/custom-plugins/ClickAnalyticsPlugin/create.d.ts.map +1 -1
  55. package/dist/custom-plugins/ClickAnalyticsPlugin/doc.json.d.ts +29 -0
  56. package/dist/custom-plugins/ClickAnalyticsPlugin/index.js +1 -1
  57. package/dist/custom-plugins/DebounceLayoutPlugin/doc.json.d.ts +37 -28
  58. package/dist/custom-plugins/DebounceLayoutPlugin/index.js +1 -1
  59. package/dist/custom-plugins/DragReorderPlugin/doc.json.d.ts +14 -0
  60. package/dist/custom-plugins/DragReorderPlugin/index.js +1 -1
  61. package/dist/custom-plugins/FilterPlugin/doc.json.d.ts +53 -39
  62. package/dist/custom-plugins/FilterPlugin/index.js +1 -1
  63. package/dist/custom-plugins/FixedHeightPlugin/doc.json.d.ts +42 -28
  64. package/dist/custom-plugins/FixedHeightPlugin/index.js +1 -1
  65. package/dist/custom-plugins/GapPlugin/create.d.ts.map +1 -1
  66. package/dist/custom-plugins/GapPlugin/doc.json.d.ts +61 -37
  67. package/dist/custom-plugins/GapPlugin/index.js +1 -1
  68. package/dist/custom-plugins/GroupingPlugin/create.d.ts.map +1 -1
  69. package/dist/custom-plugins/GroupingPlugin/doc.json.d.ts +61 -32
  70. package/dist/custom-plugins/GroupingPlugin/index.js +1 -1
  71. package/dist/custom-plugins/HeatmapAnalyticsPlugin/create.d.ts +2 -0
  72. package/dist/custom-plugins/HeatmapAnalyticsPlugin/create.d.ts.map +1 -1
  73. package/dist/custom-plugins/HeatmapAnalyticsPlugin/doc.json.d.ts +24 -0
  74. package/dist/custom-plugins/HeatmapAnalyticsPlugin/index.js +1 -1
  75. package/dist/custom-plugins/InfiniteScrollPlugin/create.d.ts.map +1 -1
  76. package/dist/custom-plugins/InfiniteScrollPlugin/doc.json.d.ts +55 -36
  77. package/dist/custom-plugins/InfiniteScrollPlugin/index.js +1 -1
  78. package/dist/custom-plugins/PaginationPlugin/create.d.ts.map +1 -1
  79. package/dist/custom-plugins/PaginationPlugin/doc.json.d.ts +56 -42
  80. package/dist/custom-plugins/PaginationPlugin/index.js +1 -1
  81. package/dist/custom-plugins/PinItemPlugin/doc.json.d.ts +49 -35
  82. package/dist/custom-plugins/PinItemPlugin/index.js +1 -1
  83. package/dist/custom-plugins/RecyclePlugin/create.d.ts.map +1 -1
  84. package/dist/custom-plugins/RecyclePlugin/doc.json.d.ts +57 -28
  85. package/dist/custom-plugins/RecyclePlugin/index.js +1 -1
  86. package/dist/custom-plugins/ReducedMotionPlugin/doc.json.d.ts +29 -0
  87. package/dist/custom-plugins/ReducedMotionPlugin/index.js +1 -1
  88. package/dist/custom-plugins/ResponsiveColumnsPlugin/doc.json.d.ts +40 -31
  89. package/dist/custom-plugins/ResponsiveColumnsPlugin/index.js +1 -1
  90. package/dist/custom-plugins/ScrollAnchorPlugin/doc.json.d.ts +42 -28
  91. package/dist/custom-plugins/ScrollAnchorPlugin/index.js +1 -1
  92. package/dist/custom-plugins/SearchPlugin/doc.json.d.ts +53 -39
  93. package/dist/custom-plugins/SearchPlugin/index.js +1 -1
  94. package/dist/custom-plugins/SortPlugin/doc.json.d.ts +52 -38
  95. package/dist/custom-plugins/SortPlugin/index.js +1 -1
  96. package/dist/custom-plugins/StatePersistencePlugin/create.d.ts.map +1 -1
  97. package/dist/custom-plugins/StatePersistencePlugin/doc.json.d.ts +71 -37
  98. package/dist/custom-plugins/StatePersistencePlugin/index.js +1 -1
  99. package/dist/custom-plugins/StickyHeaderPlugin/create.d.ts.map +1 -1
  100. package/dist/custom-plugins/StickyHeaderPlugin/doc.json.d.ts +43 -34
  101. package/dist/custom-plugins/StickyHeaderPlugin/index.js +1 -1
  102. package/dist/custom-plugins/ThrottlePlugin/doc.json.d.ts +43 -34
  103. package/dist/custom-plugins/ThrottlePlugin/index.js +1 -1
  104. package/dist/custom-plugins/TransitionPlugin/doc.json.d.ts +49 -35
  105. package/dist/custom-plugins/TransitionPlugin/index.js +1 -1
  106. package/dist/custom-plugins/URLSyncPlugin/create.d.ts.map +1 -1
  107. package/dist/custom-plugins/URLSyncPlugin/doc.json.d.ts +57 -33
  108. package/dist/custom-plugins/URLSyncPlugin/index.js +1 -1
  109. package/dist/custom-plugins/index.js +6 -6
  110. package/dist/entries/core.js +1 -1
  111. package/dist/entries/plugins.js +7 -7
  112. package/dist/index.js +2 -2
  113. package/dist/presets/dashboard/index.js +2 -2
  114. package/dist/presets/photo-feed/index.js +3 -3
  115. package/dist/presets/product-feed/index.js +2 -2
  116. package/package.json +16 -8
  117. package/dist/chunks/WaterfallCore-BSXw7bl_.js +0 -581
  118. package/dist/chunks/doc-78xF08vt.js +0 -82
  119. package/dist/chunks/doc-B-7dugGv.js +0 -79
  120. package/dist/chunks/doc-B6kLfMPv.js +0 -121
  121. package/dist/chunks/doc-BCGQ8Cp5.js +0 -114
  122. package/dist/chunks/doc-BP0DmB7-.js +0 -91
  123. package/dist/chunks/doc-CBHjiDG7.js +0 -88
  124. package/dist/chunks/doc-CraXjOaA.js +0 -68
  125. package/dist/chunks/doc-DJjxOYzW.js +0 -111
  126. package/dist/chunks/doc-NhL4Ux8q.js +0 -125
  127. package/dist/chunks/doc-f4Uijujv.js +0 -102
  128. package/dist/chunks/doc-j4W9SUrY.js +0 -76
  129. package/dist/chunks/doc-kTbJE7rY.js +0 -92
  130. package/dist/chunks/index-COaun3nf.js +0 -15
  131. package/dist/chunks/index-DXAtA2f6.js +0 -11
  132. package/dist/chunks/index-DsRLmBW-.js +0 -13
  133. package/dist/chunks/index-gjoCq0yC.js +0 -21
  134. package/dist/chunks/withPlugins-DLoKg4AP.js +0 -559
@@ -0,0 +1,743 @@
1
+ import { jsxs as pe, Fragment as ye, jsx as le } from "react/jsx-runtime";
2
+ import we, { useRef as E, useState as F, useCallback as $, useMemo as _, useLayoutEffect as ae, createContext as ve, forwardRef as be, useEffect as te } from "react";
3
+ function Pe() {
4
+ const o = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
5
+ let i = 0;
6
+ const a = (r, u) => {
7
+ const y = o.get(r);
8
+ if (y) {
9
+ if (i >= 50) {
10
+ console.warn(`[PluginBus] emit depth exceeded: "${r}"`);
11
+ return;
12
+ }
13
+ i += 1;
14
+ for (const w of [...y])
15
+ try {
16
+ w(u);
17
+ } catch (S) {
18
+ console.warn(`[PluginBus] handler error for event "${r}"`, S);
19
+ }
20
+ i -= 1;
21
+ }
22
+ }, l = (r, u) => {
23
+ let y = o.get(r);
24
+ return y || (y = /* @__PURE__ */ new Set(), o.set(r, y)), y.add(u), () => {
25
+ y?.delete(u);
26
+ };
27
+ }, p = (r, u) => {
28
+ const y = (w) => {
29
+ try {
30
+ u(w);
31
+ } finally {
32
+ c(r, y);
33
+ }
34
+ };
35
+ return l(r, y);
36
+ }, c = (r, u) => {
37
+ if (!u) {
38
+ o.delete(r);
39
+ return;
40
+ }
41
+ o.get(r)?.delete(u);
42
+ };
43
+ return { emit: a, on: l, once: p, off: c, getData: (r) => t.get(r), setData: (r, u) => {
44
+ const y = t.get(r);
45
+ t.set(r, u), y !== u && a(r, u);
46
+ }, deleteData: (r) => {
47
+ const u = t.has(r);
48
+ t.delete(r), u && a(r, void 0);
49
+ }, hasData: (r) => t.has(r), getAll: () => {
50
+ const r = /* @__PURE__ */ Object.create(null);
51
+ return t.forEach((u, y) => {
52
+ r[y] = u;
53
+ }), r;
54
+ }, clear: () => {
55
+ o.clear(), t.clear();
56
+ } };
57
+ }
58
+ function Ie(o) {
59
+ const t = new Map(o.map((r) => [r.name, r])), i = [];
60
+ for (const r of o)
61
+ for (const u of r.dependencies ?? [])
62
+ t.has(u) || i.push(`${r.name} -> ${u}`);
63
+ const a = [], l = /* @__PURE__ */ new Set(), p = [...o], c = (r) => (r.dependencies ?? []).every((u) => l.has(u) || !t.has(u));
64
+ for (; p.length > 0; ) {
65
+ const r = p.filter(c);
66
+ if (r.length === 0)
67
+ throw new Error(
68
+ `[vane/plugin-core] 插件循环依赖: ${p.map((y) => y.name).join(" <-> ")}`
69
+ );
70
+ let u = r[0];
71
+ for (const y of r)
72
+ (y.priority ?? 0) > (u.priority ?? 0) && (u = y);
73
+ a.push(u), l.add(u.name), p.splice(p.indexOf(u), 1);
74
+ }
75
+ return i.length > 0 && console.warn(
76
+ `[vane/plugin-core] 以下插件依赖未注册,将被忽略:
77
+ ${i.join(`
78
+ `)}`
79
+ ), a;
80
+ }
81
+ function ge(o, t) {
82
+ try {
83
+ return Ie(o);
84
+ } catch (i) {
85
+ return t?.(i), o;
86
+ }
87
+ }
88
+ async function ke(o, t = {}) {
89
+ const { timeout: i = 3e3, name: a = "anonymous", hook: l = "unknown" } = t;
90
+ if (!i || i <= 0)
91
+ return await o();
92
+ let p;
93
+ const c = new Promise((r, u) => {
94
+ p = setTimeout(() => {
95
+ u(new Error(`[vane/plugin-core] 插件 ${a} 的钩子 ${l} 超时(${i}ms)`));
96
+ }, i);
97
+ });
98
+ try {
99
+ return await Promise.race([Promise.resolve().then(o), c]);
100
+ } finally {
101
+ p && clearTimeout(p);
102
+ }
103
+ }
104
+ const xe = /* @__PURE__ */ new Set(["onMount", "onUnmount", "onPropsChange", "onError"]);
105
+ function Me(o = {}) {
106
+ const t = o.logger ?? console, i = o.sandbox ?? !0, a = o.timeout ?? 3e3, l = [];
107
+ let p = [];
108
+ const c = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set();
109
+ let y = 0, w = null, S = 0;
110
+ const I = (e, s, g) => {
111
+ l.push({ plugin: e, hook: s, error: g }), process.env.NODE_ENV !== "production" && l.length > 100 && l.splice(0, l.length - 100);
112
+ }, W = () => {
113
+ y += 1, w = null;
114
+ }, U = (e, s = /* @__PURE__ */ new Set()) => e.enabled === !1 ? !1 : s.has(e.name) ? !0 : (s.add(e.name), (e.dependencies ?? []).every((g) => {
115
+ const x = c.get(g);
116
+ return !x || U(x, s);
117
+ })), A = () => {
118
+ if (w) return w;
119
+ const e = [...c.values()].filter((s) => U(s) ? !0 : (I(s.name, "dependencies", new Error("依赖已停用")), !1));
120
+ return w = ge(
121
+ e,
122
+ (s) => I("[order]", "resolveDependencyOrder", s)
123
+ );
124
+ }, B = (e) => {
125
+ const s = p.filter(([g]) => !e || g === e).reverse();
126
+ p = e ? p.filter(([g]) => g !== e) : [];
127
+ for (const [, g] of s)
128
+ try {
129
+ g();
130
+ } catch (x) {
131
+ t.warn("[vane] cleanup failed", x);
132
+ }
133
+ }, V = (e) => (
134
+ // await 后 await:异步 destroy 既满足可等待,也保证旧资源先于新资源释放
135
+ Promise.resolve(e.destroy?.()).catch(
136
+ (s) => t.warn(`[vane] destroy failed: ${e.name}`, s)
137
+ )
138
+ ), Y = async (e, s, g, x, b) => {
139
+ const C = s === "onUnmount";
140
+ if (s === "onMount" || C) {
141
+ if (u.has(e.name) !== C) return {};
142
+ C ? u.delete(e.name) : u.add(e.name);
143
+ }
144
+ const D = e.hooks?.[s];
145
+ if (typeof D != "function") return {};
146
+ let v;
147
+ try {
148
+ const T = () => D(g, ...x);
149
+ v = e.sandbox ?? i ? await ke(T, {
150
+ timeout: e.timeout ?? a,
151
+ name: e.name,
152
+ hook: s
153
+ }) : await T();
154
+ } catch (T) {
155
+ return b !== y ? {} : (I(e.name, s, T), t.warn(`[vane] ${s} failed: ${e.name}`, T), o.onError?.(e.name, s, T), { stop: s === "onError" });
156
+ }
157
+ return b !== y ? {} : xe.has(s) && typeof v == "function" ? (p.push([e.name, v]), {}) : { value: v };
158
+ }, K = async (e, s, g) => {
159
+ const x = y;
160
+ for (const b of A()) {
161
+ if (x !== y) return;
162
+ const C = await Y(b, e, s, g, x);
163
+ if (C.stop) return;
164
+ if (C.value === !1) return !1;
165
+ if (C.value !== void 0 && C.value !== !0) return C.value;
166
+ }
167
+ }, N = (e, s, ...g) => K(e, s, g), j = (e) => {
168
+ c.get(e.name) && r.get(e.name) !== e && (t.warn(`[vane] duplicate plugin, destroy old: ${e.name}`), G(e.name)), c.set(e.name, { ...e, enabled: e.enabled ?? !0 }), r.set(e.name, e), u.delete(e.name), W(), e.init && Promise.resolve(e.init()).catch((s) => {
169
+ t.warn(`[vane] init failed: ${e.name}`, s);
170
+ });
171
+ }, q = (e) => e.forEach(j), z = (e) => {
172
+ c.delete(e), r.delete(e), u.delete(e), w = null;
173
+ }, G = (e) => {
174
+ const s = c.get(e);
175
+ s && (W(), B(e), V(s), z(e));
176
+ };
177
+ return {
178
+ register: j,
179
+ registerAll: q,
180
+ unregister: G,
181
+ getPlugin: (e) => c.get(e),
182
+ getAllPlugins: () => [...c.values()],
183
+ getEnabledPlugins: () => [...c.values()].filter((e) => e.enabled !== !1),
184
+ getExecutionOrder: () => [...A()],
185
+ enable: (e) => {
186
+ const s = c.get(e);
187
+ s && (s.enabled = !0, w = null);
188
+ },
189
+ disable: (e) => {
190
+ const s = c.get(e);
191
+ s && (s.enabled = !1, w = null);
192
+ },
193
+ has: (e) => c.has(e),
194
+ executeHook: N,
195
+ clear: () => {
196
+ W(), S += 1, B();
197
+ const e = [...c.values()].map(V);
198
+ return c.clear(), r.clear(), u.clear(), Promise.all(e).then(() => {
199
+ });
200
+ },
201
+ getErrors: () => [...l],
202
+ align: async (e, s) => {
203
+ const g = ++S, x = new Map(e.map((b) => [b.name, b]));
204
+ for (const b of [...c.keys()]) {
205
+ if (g !== S) return;
206
+ if (r.get(b) === x.get(b)) continue;
207
+ const C = c.get(b);
208
+ W(), await Y(C, "onUnmount", s, [], y), B(b), await V(C), z(b);
209
+ }
210
+ for (const b of e) {
211
+ if (g !== S) return;
212
+ r.get(b.name) !== b && j(b);
213
+ }
214
+ },
215
+ peekOrder: A
216
+ };
217
+ }
218
+ var Ce = Object.defineProperty, Le = (o, t, i) => t in o ? Ce(o, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : o[t] = i, Ee = (o, t, i) => Le(o, t + "", i);
219
+ class de extends we.Component {
220
+ constructor() {
221
+ super(...arguments), Ee(this, "state", { error: null });
222
+ }
223
+ static getDerivedStateFromError(t) {
224
+ return { error: t };
225
+ }
226
+ componentDidUpdate(t) {
227
+ const i = t.resetKeys ?? [], a = this.props.resetKeys ?? [];
228
+ this.state.error && (i.length !== a.length || i.some((l, p) => !Object.is(l, a[p]))) && (this.props.onReset?.(), this.setState({ error: null }));
229
+ }
230
+ componentDidCatch(t, i) {
231
+ console.warn("[vane/plugin-core] 插件渲染错误已被隔离", t, i), this.props.onError?.(t, i);
232
+ }
233
+ render() {
234
+ const { error: t } = this.state;
235
+ return t ? this.props.fallback ? this.props.fallback(t) : null : this.props.children;
236
+ }
237
+ }
238
+ let ne = null;
239
+ function Re(o = !1) {
240
+ if (ne && !o) return ne;
241
+ const t = typeof window < "u" ? window.innerWidth : 1024, i = typeof window < "u" ? window.innerHeight : 768, a = typeof window < "u" && window.devicePixelRatio || 1, l = typeof navigator < "u" && navigator.userAgent || "", p = /iPad|Tablet/i.test(l), c = /Mobile|Android|iPhone/i.test(l), r = typeof window < "u" && ("ontouchstart" in window || (navigator.maxTouchPoints ?? 0) > 0);
242
+ return ne = {
243
+ type: p ? "tablet" : c ? "mobile" : "desktop",
244
+ os: l,
245
+ browser: l,
246
+ devicePixelRatio: a,
247
+ viewportWidth: t,
248
+ viewportHeight: i,
249
+ isTouchDevice: r,
250
+ isRetina: a >= 2
251
+ }, ne;
252
+ }
253
+ function ce(o, t) {
254
+ if (Object.is(o, t)) return !0;
255
+ if (typeof o != "object" || typeof t != "object" || o === null || t === null)
256
+ return !1;
257
+ const i = Object.keys(o), a = Object.keys(t);
258
+ return i.length !== a.length ? !1 : i.every(
259
+ (l) => Object.is(o[l], t[l])
260
+ );
261
+ }
262
+ function He(o) {
263
+ const {
264
+ plugins: t,
265
+ props: i,
266
+ data: a,
267
+ initialState: l,
268
+ containerRef: p,
269
+ enableDebug: c = !1,
270
+ managerOptions: r,
271
+ extendContext: u
272
+ } = o, y = E(null), w = p ?? y, S = E(null);
273
+ S.current || (S.current = Me(
274
+ r
275
+ ));
276
+ const I = S.current, W = E(null);
277
+ W.current || (W.current = Pe());
278
+ const U = W.current, A = E(/* @__PURE__ */ new Map()), [B, V] = F(l ?? {}), [, Y] = F(0), K = $(() => Y((k) => k + 1), []), N = _(() => Re(), []), j = E(i);
279
+ ce(j.current, i) || (j.current = i);
280
+ const q = j.current, z = E(a);
281
+ ce(z.current, a) || (z.current = a);
282
+ const G = z.current, e = E(null), s = _(() => {
283
+ const k = {
284
+ props: q,
285
+ data: G,
286
+ bus: U,
287
+ refs: { container: w, getContainer: () => w.current },
288
+ state: B,
289
+ setState: (M) => V((n) => ({ ...n, ...M })),
290
+ shared: A.current,
291
+ deviceInfo: N,
292
+ forceUpdate: K,
293
+ getSize: () => {
294
+ const M = w.current;
295
+ return M ? { width: M.offsetWidth, height: M.offsetHeight } : { width: 0, height: 0 };
296
+ },
297
+ logger: console
298
+ };
299
+ return u ? u(k) : k;
300
+ }, [q, G, B, N, U, u]);
301
+ ae(() => {
302
+ e.current = s;
303
+ }, [s]);
304
+ const g = E(t), x = g.current;
305
+ x !== t && (x.length !== t.length || t.some((k, M) => k !== x[M])) && (g.current = t);
306
+ const b = g.current, C = E(0);
307
+ ae(() => {
308
+ const k = ++C.current, M = e.current;
309
+ return I.align(b, M).then(() => {
310
+ C.current === k && (c && console.debug(
311
+ "[vane/plugin-core] plugins registered:",
312
+ b.map((n) => n.name).join("|")
313
+ ), I.executeHook("onMount", M));
314
+ }), () => {
315
+ C.current += 1;
316
+ };
317
+ }, [b, I, c]), ae(
318
+ () => () => {
319
+ const k = e.current;
320
+ if (!I.getExecutionOrder().some((M) => typeof M.hooks?.onUnmount == "function")) {
321
+ I.clear();
322
+ return;
323
+ }
324
+ I.executeHook("onUnmount", k).finally(() => I.clear());
325
+ },
326
+ [I]
327
+ );
328
+ const D = I.peekOrder(), v = E([]), T = _(() => {
329
+ const k = new Map(b.map((d) => [d.name, d])), M = b.filter(
330
+ (d) => d.enabled !== !1 && I.getPlugin(d.name)?.enabled !== !1
331
+ ), n = D.length === M.length ? D.map((d) => k.get(d.name) ?? d) : ge(M), f = v.current;
332
+ return f.length === n.length && n.every((d, P) => d === f[P]) ? f : (v.current = n, n);
333
+ }, [b, I, D]), J = E(s);
334
+ J.current = s;
335
+ const Q = $(
336
+ (k, M) => {
337
+ const n = J.current;
338
+ let f = M;
339
+ for (const d of T) {
340
+ const P = d.hooks?.[k];
341
+ if (typeof P == "function")
342
+ try {
343
+ f = k === "transformData" ? P(n, f) : P(f);
344
+ } catch (m) {
345
+ (n.logger ?? console).warn(
346
+ `[plugin-core] ${d.name}.${k} 执行失败,已跳过`,
347
+ m
348
+ );
349
+ }
350
+ }
351
+ return f;
352
+ },
353
+ [T]
354
+ ), se = $(
355
+ (k) => Q("transformProps", k),
356
+ [Q]
357
+ ), X = $(
358
+ (k) => Q("transformData", k),
359
+ [Q]
360
+ ), ee = $(
361
+ (k, ...M) => I.executeHook(k, e.current, ...M),
362
+ [I]
363
+ );
364
+ return {
365
+ manager: I,
366
+ bus: U,
367
+ context: s,
368
+ state: B,
369
+ setState: s.setState,
370
+ execute: ee,
371
+ transformProps: se,
372
+ transformData: X,
373
+ orderedPlugins: T
374
+ };
375
+ }
376
+ ve(null);
377
+ function oe(o, t, i) {
378
+ if (o.enabled === !1 || typeof o.hooks?.[t] != "function") return !1;
379
+ const a = o.config?.slotPosition;
380
+ return i === "before" ? a === "before" : i === "footer" ? a === void 0 || a === "after" || a === "footer" : a === void 0 || a === "after";
381
+ }
382
+ function Se(o, t) {
383
+ return (o.config?.order ?? 0) - (t.config?.order ?? 0) || (t.priority ?? 0) - (o.priority ?? 0);
384
+ }
385
+ function re(o, t, i) {
386
+ const a = /* @__PURE__ */ new Set();
387
+ return o.map((l) => {
388
+ if (a.has(l.name)) return null;
389
+ a.add(l.name);
390
+ try {
391
+ const p = l.hooks?.[i], c = p?.(t);
392
+ return c == null ? null : /* @__PURE__ */ le(de, { children: c }, `vane-slot-${l.name}`);
393
+ } catch (p) {
394
+ return console.warn(`[vane/plugin-core] 插件 ${l.name} 的 ${i} 渲染失败`, p), null;
395
+ }
396
+ });
397
+ }
398
+ function Te(o, t, i) {
399
+ const a = {
400
+ headerBefore: [],
401
+ overlay: [],
402
+ headerAfter: [],
403
+ footer: []
404
+ };
405
+ for (const l of o)
406
+ oe(l, "renderHeader", "before") ? a.headerBefore.push(l) : oe(l, "renderHeader", "after") && a.headerAfter.push(l), oe(l, "renderOverlay", "after") && a.overlay.push(l), oe(l, "renderFooter", "footer") && a.footer.push(l);
407
+ for (const l of Object.keys(a)) a[l].sort(Se);
408
+ return /* @__PURE__ */ pe(ye, { children: [
409
+ re(a.headerBefore, t, "renderHeader"),
410
+ i,
411
+ re(a.overlay, t, "renderOverlay"),
412
+ re(a.headerAfter, t, "renderHeader"),
413
+ re(a.footer, t, "renderFooter")
414
+ ] });
415
+ }
416
+ const $e = {
417
+ columns: 0,
418
+ columnWidth: 0,
419
+ gap: 0,
420
+ columnHeights: [],
421
+ totalHeight: 0,
422
+ containerWidth: 0,
423
+ containerHeight: 0
424
+ }, We = {
425
+ scrollTop: 0,
426
+ scrollLeft: 0,
427
+ scrollHeight: 0,
428
+ scrollWidth: 0,
429
+ clientHeight: 0,
430
+ clientWidth: 0,
431
+ isScrolling: !1,
432
+ direction: null
433
+ };
434
+ function O(o, t, ...i) {
435
+ if (typeof t == "function")
436
+ try {
437
+ return t(...i);
438
+ } catch (a) {
439
+ console.warn(`[vane-waterfall] ${o} 回调抛错,已忽略`, a);
440
+ return;
441
+ }
442
+ }
443
+ async function fe(o, t, ...i) {
444
+ if (typeof t == "function")
445
+ try {
446
+ return await t(...i);
447
+ } catch (a) {
448
+ console.warn(`[vane-waterfall] ${o} 回调抛错,已忽略`, a);
449
+ return;
450
+ }
451
+ }
452
+ function Oe() {
453
+ const o = typeof navigator < "u" ? navigator : void 0, t = o?.connection || o?.mozConnection || o?.webkitConnection;
454
+ if (t)
455
+ return {
456
+ effectiveType: t.effectiveType || "4g",
457
+ downlink: Number(t.downlink || 10),
458
+ rtt: Number(t.rtt || 50),
459
+ saveData: !!t.saveData,
460
+ online: o?.onLine !== !1
461
+ };
462
+ }
463
+ function me(o, t, i) {
464
+ let a = Number.POSITIVE_INFINITY, l = -1;
465
+ return o.forEach((p, c) => {
466
+ Math.max(
467
+ 0,
468
+ Math.min(t + i, p.y + p.height) - Math.max(t, p.y)
469
+ ) > 0 && (c < a && (a = c), c > l && (l = c));
470
+ }), l < 0 ? { start: 0, end: 0 } : { start: a, end: l };
471
+ }
472
+ function je(o, t) {
473
+ const i = Array.isArray(t) ? { plugins: t } : t, { plugins: a, enableDebug: l = !1 } = i, p = be(
474
+ (c, r) => {
475
+ const u = E(null), y = E(/* @__PURE__ */ new Map()), w = E(null), S = _(() => Oe(), []), I = E(null), [W, U] = F($e), [A, B] = F(
476
+ () => /* @__PURE__ */ new Map()
477
+ ), [V, Y] = F(We), [K, N] = F(!1), [j, q] = F(0), z = $(
478
+ (n) => {
479
+ const f = () => w.current?.getLayoutInfo() ?? W, d = () => w.current?.getAllItemPositions() ?? A, P = () => w.current?.getViewportInfo() ?? V, m = () => I.current?.items ?? n.props?.items ?? [], H = () => n.props?.items ?? [], L = () => {
480
+ const h = w.current?.getVisibleItems();
481
+ if (h && h.size > 0) return h;
482
+ const Z = P(), ue = /* @__PURE__ */ new Set();
483
+ return d().forEach((ie, he) => {
484
+ Math.max(
485
+ 0,
486
+ Math.min(Z.scrollTop + Z.clientHeight, ie.y + ie.height) - Math.max(Z.scrollTop, ie.y)
487
+ ) > 0 && ue.add(he);
488
+ }), ue;
489
+ }, R = {
490
+ ...n,
491
+ items: m(),
492
+ itemCount: m().length,
493
+ rawItems: H(),
494
+ containerRef: u,
495
+ itemRefs: y.current,
496
+ getItemRef: (h) => y.current.get(h) ?? null,
497
+ layout: f(),
498
+ itemPositions: d(),
499
+ getItemPosition: (h) => d().get(h) ?? null,
500
+ viewport: P(),
501
+ visibleItems: L(),
502
+ visibleRange: me(
503
+ d(),
504
+ P().scrollTop,
505
+ P().clientHeight
506
+ ),
507
+ isLayouting: K,
508
+ isScrolling: V.isScrolling,
509
+ isDragging: !!n.state?.dragInfo?.isDragging,
510
+ isLoading: !!(n.state?.isLoading ?? !1),
511
+ hasMore: !!(n.state?.hasMore ?? !0),
512
+ error: n.state?.error ?? null,
513
+ sharedData: n.shared,
514
+ networkInfo: S,
515
+ dragInfo: n.state?.dragInfo,
516
+ relayout: () => w.current?.relayout(),
517
+ scrollToItem: (h, Z) => w.current?.scrollToItem(h, Z),
518
+ scrollToTop: (h) => w.current?.scrollToTop(h),
519
+ scrollToBottom: (h) => w.current?.scrollToBottom(h),
520
+ measureItem: (h) => w.current?.measureItem(h) ?? Promise.resolve({ width: 0, height: 0 })
521
+ };
522
+ return Object.defineProperties(R, {
523
+ layout: { get: f, enumerable: !0, configurable: !0 },
524
+ itemPositions: { get: d, enumerable: !0, configurable: !0 },
525
+ viewport: { get: P, enumerable: !0, configurable: !0 },
526
+ items: { get: m, enumerable: !0, configurable: !0 },
527
+ itemCount: {
528
+ get: () => m().length,
529
+ enumerable: !0,
530
+ configurable: !0
531
+ },
532
+ rawItems: { get: H, enumerable: !0, configurable: !0 },
533
+ visibleItems: { get: L, enumerable: !0, configurable: !0 },
534
+ // 宿主 props 优先:`hasMore` / `isLoading` 从「恒 true / 恒 false」改成
535
+ // 「props 能覆盖插件状态」,页面不用 hand-roll 一个插件就能控制(P2-2)
536
+ hasMore: {
537
+ get: () => I.current?.hasMore ?? n.state?.hasMore ?? !0,
538
+ enumerable: !0,
539
+ configurable: !0
540
+ },
541
+ isLoading: {
542
+ get: () => I.current?.isLoading ?? n.state?.isLoading ?? !1,
543
+ enumerable: !0,
544
+ configurable: !0
545
+ },
546
+ props: {
547
+ get: () => I.current ?? n.props,
548
+ enumerable: !0,
549
+ configurable: !0
550
+ },
551
+ visibleRange: {
552
+ get: () => {
553
+ const h = P();
554
+ return me(d(), h.scrollTop, h.clientHeight);
555
+ },
556
+ enumerable: !0,
557
+ configurable: !0
558
+ }
559
+ }), R;
560
+ },
561
+ [W, A, V, K, S]
562
+ ), e = He({
563
+ plugins: a,
564
+ props: c,
565
+ enableDebug: l,
566
+ containerRef: u,
567
+ extendContext: z
568
+ }), s = E(e.context);
569
+ ae(() => {
570
+ s.current = e.context;
571
+ }), te(
572
+ () => e.bus.on("props:invalidate", () => q((n) => n + 1)),
573
+ [e.bus]
574
+ );
575
+ const g = $(
576
+ (n, ...f) => e.execute(n, ...f),
577
+ // eslint-disable-next-line react-hooks/exhaustive-deps
578
+ [e.manager]
579
+ ), x = e.orderedPlugins, b = a.map((n) => n.name).join("|"), C = _(() => {
580
+ const n = x.filter(
581
+ (m) => typeof m.hooks?.calculateColumns == "function"
582
+ ), f = x.filter(
583
+ (m) => typeof m.hooks?.calculateColumnWidth == "function"
584
+ ), d = x.filter(
585
+ (m) => typeof m.hooks?.calculateItemPosition == "function"
586
+ );
587
+ if (!n.length && !f.length && !d.length)
588
+ return;
589
+ const P = (m, H, L) => console.warn(`[vane-waterfall] ${m} 的 ${H} 执行失败`, L);
590
+ return {
591
+ calculateColumns: n.length ? (m) => {
592
+ const H = s.current?.containerRef?.current?.clientWidth ?? 0;
593
+ for (const L of n)
594
+ try {
595
+ const R = L.hooks.calculateColumns(s.current, H);
596
+ if (typeof R == "number" && Number.isFinite(R)) return R;
597
+ } catch (R) {
598
+ P(L.name, "calculateColumns", R);
599
+ }
600
+ } : void 0,
601
+ calculateColumnWidth: f.length ? (m, H, L) => {
602
+ for (const R of f)
603
+ try {
604
+ const h = R.hooks.calculateColumnWidth(
605
+ s.current,
606
+ L,
607
+ H
608
+ );
609
+ if (typeof h == "number" && Number.isFinite(h)) return h;
610
+ } catch (h) {
611
+ P(R.name, "calculateColumnWidth", h);
612
+ }
613
+ } : void 0,
614
+ calculateItemPosition: d.length ? (m, H, L) => {
615
+ for (const R of d)
616
+ try {
617
+ const h = R.hooks.calculateItemPosition(
618
+ s.current,
619
+ m,
620
+ H,
621
+ L
622
+ );
623
+ if (h) return h;
624
+ } catch (h) {
625
+ P(R.name, "calculateItemPosition", h);
626
+ }
627
+ } : void 0
628
+ };
629
+ }, [x]), D = $(() => {
630
+ const n = w.current;
631
+ if (!n) return;
632
+ const f = n.getLayoutInfo(), d = n.getAllItemPositions(), P = n.getViewportInfo();
633
+ U(
634
+ (m) => m.totalHeight === f.totalHeight && m.columns === f.columns && m.columnWidth === f.columnWidth && m.containerWidth === f.containerWidth ? m : f
635
+ ), B((m) => {
636
+ if (m === d) return m;
637
+ if (m.size !== d.size) return d;
638
+ let H = !0;
639
+ return d.forEach((L, R) => {
640
+ if (H === !1) return;
641
+ const h = m.get(R);
642
+ (!h || h.x !== L.x || h.y !== L.y || h.width !== L.width || h.height !== L.height || h.column !== L.column) && (H = !1);
643
+ }), H ? m : d;
644
+ }), Y(
645
+ (m) => m.scrollTop === P.scrollTop && m.clientHeight === P.clientHeight && m.scrollHeight === P.scrollHeight && m.isScrolling === P.isScrolling ? m : P
646
+ );
647
+ }, []), v = _(() => e.transformProps(c), [e.transformProps, c, j]);
648
+ te(() => {
649
+ a.some((n) => n.name === "PaginationPlugin") && a.some((n) => n.name === "InfiniteScrollPlugin") && console.warn(
650
+ "[vane-waterfall] PaginationPlugin 与 InfiniteScrollPlugin 互斥:两者都会改写 items,请只保留一个"
651
+ );
652
+ }, [b]), te(() => {
653
+ g("onMount");
654
+ }, [g]);
655
+ const T = E(c);
656
+ te(() => {
657
+ const n = T.current;
658
+ n !== c && (T.current = c, g("onPropsChange", n, c));
659
+ }, [c, g]), I.current = v;
660
+ const J = $(async () => (N(!0), await g("onBeforeLayout") === !1 ? (N(!1), !1) : !0), [g]), Q = $(() => {
661
+ g("onLayout");
662
+ }, [g]), se = $(() => {
663
+ N(!1), g("onLayoutComplete"), Promise.resolve().then(D);
664
+ }, [g, D]), X = _(
665
+ () => x.filter((n) => typeof n.hooks?.renderItemWrapper == "function"),
666
+ [x]
667
+ ), ee = v.renderItem, k = $(
668
+ (n, f) => {
669
+ let d = ee?.(n, f) ?? null;
670
+ for (const P of X)
671
+ try {
672
+ const m = P.hooks.renderItemWrapper(s.current, d, f);
673
+ m != null && (d = m);
674
+ } catch (m) {
675
+ console.warn(`[vane-waterfall] ${P.name} 的 renderItemWrapper 失败`, m);
676
+ }
677
+ return d;
678
+ },
679
+ // 身份保持稳定(插件链与基础 renderItem 不变时不变):Core 里项单元是 memo 的,
680
+ // 这里每次渲染都给新函数等于把 memo 全部击穿(P2-11)
681
+ [ee, X]
682
+ ), M = {
683
+ ...v,
684
+ containerRefExternal: u,
685
+ itemRefsExternal: y,
686
+ debug: v.debug ?? l,
687
+ layoutHooks: C ?? v.layoutHooks,
688
+ renderItem: k,
689
+ children: /* @__PURE__ */ le(de, { children: Te(e.orderedPlugins, e.context, v.children) }),
690
+ onMount: () => {
691
+ O("onMount", v.onMount);
692
+ },
693
+ onUnmount: () => {
694
+ O("onUnmount", v.onUnmount);
695
+ },
696
+ onBeforeLayout: async () => await J() === !1 ? !1 : await fe("onBeforeLayout", v.onBeforeLayout) ?? !0,
697
+ onLayout: () => {
698
+ O("onLayout", v.onLayout), Q();
699
+ },
700
+ onLayoutComplete: () => {
701
+ O("onLayoutComplete", v.onLayoutComplete), se();
702
+ },
703
+ onItemMount: (n, f) => {
704
+ O("onItemMount", v.onItemMount, n, f), g("onItemMount", n, f);
705
+ },
706
+ onItemUnmount: (n) => {
707
+ O("onItemUnmount", v.onItemUnmount, n), g("onItemUnmount", n);
708
+ },
709
+ onItemEnterViewport: (n, f) => {
710
+ O("onItemEnterViewport", v.onItemEnterViewport, n, f), g("onItemEnterViewport", n, f);
711
+ },
712
+ onItemLeaveViewport: (n, f) => {
713
+ O("onItemLeaveViewport", v.onItemLeaveViewport, n, f), g("onItemLeaveViewport", n, f);
714
+ },
715
+ onScroll: (n, f) => {
716
+ O("onScroll", v.onScroll, n, f), g("onScroll", n, f), D();
717
+ },
718
+ onResize: (n, f) => {
719
+ O("onResize", v.onResize, n, f), g("onResize", n, f);
720
+ },
721
+ onReachBottom: async (n) => {
722
+ await fe("onReachBottom", v.onReachBottom, n), await g("onReachBottom", n);
723
+ },
724
+ onItemClick: (n, f, d) => {
725
+ O("onItemClick", v.onItemClick, n, f, d), g("onItemClick", n, f, d);
726
+ }
727
+ };
728
+ return /* @__PURE__ */ le(
729
+ o,
730
+ {
731
+ ref: (n) => {
732
+ w.current = n, typeof r == "function" ? r(n) : r && (r.current = n);
733
+ },
734
+ ...M
735
+ }
736
+ );
737
+ }
738
+ );
739
+ return p.displayName = "WithPlugins(WaterfallCore)", p;
740
+ }
741
+ export {
742
+ je as w
743
+ };