@fragmentsx/runtime-react 0.2.0-dev-20261025070649 → 0.2.0-dev-20261025103802
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.
- package/dist/index.es.js +354 -267
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -1,37 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
import * as
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import * as Be from "react/jsx-runtime";
|
|
3
|
+
import { jsx as l, jsxs as De, Fragment as He } from "react/jsx-runtime";
|
|
4
|
+
import * as ge from "react";
|
|
5
|
+
import { createContext as I, useContext as w, useState as j, useEffect as R, useLayoutEffect as Ue, version as $e, Component as Ve, Suspense as he, useMemo as L, createElement as ze, useRef as A, useCallback as B, useReducer as Ge } from "react";
|
|
6
|
+
import { FragmentsAreaError as ve, toScopeClassName as Ke, AREA_GLOBAL_CSS_KEY as Ye, resolveStylesHref as Je, fragmentCssKey as We, createSourceCache as Ee, sourceCallKey as ue, sourceTransportKey as Xe, resolveSourceRequest as qe, runSourceFetch as Qe, createFragmentsClient as Ze, FragmentsApiVersionError as er, FragmentsLoadError as rr } from "@fragmentsx/fragments-client";
|
|
7
|
+
import { FragmentsApiVersionError as Lr, FragmentsAreaError as Br, FragmentsLoadError as Dr, createSourceCache as Hr } from "@fragmentsx/fragments-client";
|
|
8
|
+
const tr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
9
|
+
__proto__: null,
|
|
10
|
+
get AREA_UNRESOLVED() {
|
|
11
|
+
return W;
|
|
12
|
+
},
|
|
13
|
+
get Area() {
|
|
14
|
+
return xr;
|
|
15
|
+
},
|
|
16
|
+
get AreaExposureContext() {
|
|
17
|
+
return K;
|
|
18
|
+
},
|
|
19
|
+
get FragmentRenderer() {
|
|
20
|
+
return mr;
|
|
21
|
+
},
|
|
22
|
+
get FragmentStylesheet() {
|
|
23
|
+
return X;
|
|
24
|
+
},
|
|
25
|
+
get FragmentsApiVersionError() {
|
|
26
|
+
return er;
|
|
27
|
+
},
|
|
28
|
+
get FragmentsAreaError() {
|
|
29
|
+
return ve;
|
|
30
|
+
},
|
|
31
|
+
get FragmentsClientContext() {
|
|
32
|
+
return _;
|
|
33
|
+
},
|
|
34
|
+
get FragmentsClientProvider() {
|
|
35
|
+
return ye;
|
|
36
|
+
},
|
|
37
|
+
get FragmentsLoadError() {
|
|
38
|
+
return rr;
|
|
39
|
+
},
|
|
40
|
+
get FragmentsProvider() {
|
|
41
|
+
return Pr;
|
|
42
|
+
},
|
|
43
|
+
get InstanceIdContext() {
|
|
44
|
+
return q;
|
|
45
|
+
},
|
|
46
|
+
get ModulesMapContext() {
|
|
47
|
+
return D;
|
|
48
|
+
},
|
|
49
|
+
get ModulesMapProvider() {
|
|
50
|
+
return pe;
|
|
51
|
+
},
|
|
52
|
+
get ProjectPropertiesContext() {
|
|
53
|
+
return G;
|
|
54
|
+
},
|
|
55
|
+
get createBrowserClient() {
|
|
56
|
+
return _r;
|
|
57
|
+
},
|
|
58
|
+
get createSourceCache() {
|
|
59
|
+
return Ee;
|
|
60
|
+
},
|
|
61
|
+
get defaultProjectProperties() {
|
|
62
|
+
return Z;
|
|
63
|
+
},
|
|
64
|
+
get injectStylesheet() {
|
|
65
|
+
return Q;
|
|
66
|
+
},
|
|
67
|
+
get useArea() {
|
|
68
|
+
return we;
|
|
69
|
+
},
|
|
70
|
+
get useCssChunk() {
|
|
71
|
+
return ar;
|
|
72
|
+
},
|
|
73
|
+
get useFragmentComponent() {
|
|
74
|
+
return xe;
|
|
75
|
+
},
|
|
76
|
+
get useFragmentStylesheet() {
|
|
77
|
+
return Pe;
|
|
78
|
+
},
|
|
79
|
+
get useGoal() {
|
|
80
|
+
return Ar;
|
|
81
|
+
},
|
|
82
|
+
get useProjectProperty() {
|
|
83
|
+
return br;
|
|
84
|
+
},
|
|
85
|
+
get useSource() {
|
|
86
|
+
return Ir;
|
|
87
|
+
}
|
|
88
|
+
}, Symbol.toStringTag, { value: "Module" })), _ = I(
|
|
7
89
|
null
|
|
8
90
|
);
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
return /* @__PURE__ */ l(
|
|
91
|
+
_.displayName = "FragmentsClientContext";
|
|
92
|
+
function ye(r) {
|
|
93
|
+
return /* @__PURE__ */ l(_.Provider, { value: r.value, children: r.children });
|
|
12
94
|
}
|
|
13
|
-
function
|
|
14
|
-
return w(
|
|
95
|
+
function nr() {
|
|
96
|
+
return w(_);
|
|
15
97
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
98
|
+
const q = I(null);
|
|
99
|
+
q.displayName = "InstanceIdContext";
|
|
100
|
+
const D = I(
|
|
19
101
|
null
|
|
20
102
|
);
|
|
21
|
-
|
|
22
|
-
function
|
|
103
|
+
D.displayName = "ModulesMapContext";
|
|
104
|
+
function pe({
|
|
23
105
|
value: r,
|
|
24
106
|
children: e
|
|
25
107
|
}) {
|
|
26
|
-
return /* @__PURE__ */ l(
|
|
108
|
+
return /* @__PURE__ */ l(D.Provider, { value: r, children: e });
|
|
27
109
|
}
|
|
28
|
-
function
|
|
29
|
-
const e = w(
|
|
110
|
+
function xe(r) {
|
|
111
|
+
const e = w(D);
|
|
30
112
|
if (!e)
|
|
31
113
|
throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");
|
|
32
114
|
return e.read(r);
|
|
33
115
|
}
|
|
34
|
-
const
|
|
116
|
+
const ce = typeof window < "u", W = Object.freeze({
|
|
35
117
|
rootFragmentId: 0,
|
|
36
118
|
variantId: null,
|
|
37
119
|
experiment: null,
|
|
@@ -46,22 +128,22 @@ const te = typeof window < "u", ne = Object.freeze({
|
|
|
46
128
|
slots: {},
|
|
47
129
|
sources: {}
|
|
48
130
|
});
|
|
49
|
-
function
|
|
131
|
+
function J(r) {
|
|
50
132
|
const e = r.$area;
|
|
51
133
|
if (!(e != null && e.read))
|
|
52
134
|
throw new Error("[useArea] $area plugin not mounted");
|
|
53
135
|
return e;
|
|
54
136
|
}
|
|
55
|
-
function
|
|
56
|
-
const t = w(
|
|
137
|
+
function we(r, e) {
|
|
138
|
+
const t = w(_);
|
|
57
139
|
if (!t)
|
|
58
140
|
throw new Error("[useArea] No FragmentsClientProvider in tree");
|
|
59
|
-
const n = (e == null ? void 0 : e.suspense) ?? !0, s = (e == null ? void 0 : e.pause) === !0 || !
|
|
141
|
+
const n = (e == null ? void 0 : e.suspense) ?? !0, s = (e == null ? void 0 : e.pause) === !0 || !ce && (e == null ? void 0 : e.ssr) === !1, u = (e == null ? void 0 : e.timeout) != null ? { timeout: e.timeout } : void 0, [, o] = j(0);
|
|
60
142
|
if (R(() => {
|
|
61
143
|
if (n || s) return;
|
|
62
|
-
const
|
|
144
|
+
const c = J(t);
|
|
63
145
|
let a = !0;
|
|
64
|
-
return Promise.resolve(
|
|
146
|
+
return Promise.resolve(c.resolve(r, u)).catch(() => {
|
|
65
147
|
}).finally(() => {
|
|
66
148
|
a && o((d) => d + 1);
|
|
67
149
|
}), () => {
|
|
@@ -69,77 +151,77 @@ function Qe(r, e) {
|
|
|
69
151
|
};
|
|
70
152
|
}, [r, n, e == null ? void 0 : e.pause, e == null ? void 0 : e.timeout, e == null ? void 0 : e.ssr]), n) {
|
|
71
153
|
if (s)
|
|
72
|
-
return
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
}), !
|
|
154
|
+
return W;
|
|
155
|
+
const c = J(t);
|
|
156
|
+
if (c.has(r) || Promise.resolve(c.resolve(r, u)).catch(() => {
|
|
157
|
+
}), !ce)
|
|
76
158
|
try {
|
|
77
|
-
return
|
|
159
|
+
return c.read(r);
|
|
78
160
|
} catch (a) {
|
|
79
161
|
if (a != null && typeof a.then == "function")
|
|
80
162
|
throw a;
|
|
81
163
|
return process.env.NODE_ENV !== "production" && console.error(
|
|
82
164
|
`[useArea] Area ${r} remained unresolved on the server because its cache reached a terminal state`,
|
|
83
165
|
a
|
|
84
|
-
),
|
|
166
|
+
), W;
|
|
85
167
|
}
|
|
86
|
-
return
|
|
168
|
+
return c.read(r);
|
|
87
169
|
}
|
|
88
170
|
if (s)
|
|
89
171
|
return { status: "idle", data: null, error: null };
|
|
90
|
-
const m =
|
|
172
|
+
const m = J(t);
|
|
91
173
|
if (m.has(r))
|
|
92
174
|
try {
|
|
93
175
|
return { status: "ready", data: m.read(r), error: null };
|
|
94
|
-
} catch (
|
|
176
|
+
} catch (c) {
|
|
95
177
|
return {
|
|
96
178
|
status: "not-found",
|
|
97
179
|
data: null,
|
|
98
|
-
error:
|
|
180
|
+
error: c instanceof Error ? c : new Error(String(c))
|
|
99
181
|
};
|
|
100
182
|
}
|
|
101
|
-
return Promise.resolve(m.resolve(r,
|
|
183
|
+
return Promise.resolve(m.resolve(r, u)).catch(() => {
|
|
102
184
|
}), { status: "loading", data: null, error: null };
|
|
103
185
|
}
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
106
|
-
const
|
|
186
|
+
const Se = typeof window < "u", or = 3e3, V = /* @__PURE__ */ new Map(), Q = (r, e) => {
|
|
187
|
+
if (!Se) {
|
|
188
|
+
const g = () => {
|
|
107
189
|
};
|
|
108
|
-
return
|
|
190
|
+
return g.loaded = Promise.resolve(), g;
|
|
109
191
|
}
|
|
110
|
-
const t =
|
|
192
|
+
const t = V.get(e);
|
|
111
193
|
if (t) {
|
|
112
194
|
t.refCount += 1;
|
|
113
|
-
const
|
|
114
|
-
t.refCount -= 1, t.refCount === 0 && (t.clearReadyTimer(), t.linkEl.remove(),
|
|
195
|
+
const g = () => {
|
|
196
|
+
t.refCount -= 1, t.refCount === 0 && (t.clearReadyTimer(), t.linkEl.remove(), V.delete(e));
|
|
115
197
|
};
|
|
116
|
-
return
|
|
198
|
+
return g.loaded = t.loaded, g;
|
|
117
199
|
}
|
|
118
200
|
const n = document.createElement("link");
|
|
119
201
|
n.rel = "stylesheet", n.href = r, n.setAttribute("data-fragment-key", e);
|
|
120
202
|
let s;
|
|
121
|
-
const
|
|
122
|
-
s =
|
|
203
|
+
const u = new Promise((g) => {
|
|
204
|
+
s = g;
|
|
123
205
|
}), o = () => {
|
|
124
|
-
|
|
125
|
-
}, m = setTimeout(o,
|
|
206
|
+
c(), s();
|
|
207
|
+
}, m = setTimeout(o, or), c = () => clearTimeout(m);
|
|
126
208
|
n.addEventListener("load", o), n.addEventListener("error", o), document.head.appendChild(n);
|
|
127
|
-
const a = { refCount: 1, linkEl: n, loaded:
|
|
128
|
-
|
|
209
|
+
const a = { refCount: 1, linkEl: n, loaded: u, clearReadyTimer: c };
|
|
210
|
+
V.set(e, a);
|
|
129
211
|
const d = () => {
|
|
130
|
-
a.refCount -= 1, a.refCount === 0 && (a.clearReadyTimer(), a.linkEl.remove(),
|
|
212
|
+
a.refCount -= 1, a.refCount === 0 && (a.clearReadyTimer(), a.linkEl.remove(), V.delete(e));
|
|
131
213
|
};
|
|
132
|
-
return d.loaded =
|
|
133
|
-
},
|
|
134
|
-
function
|
|
135
|
-
|
|
214
|
+
return d.loaded = u, d;
|
|
215
|
+
}, sr = Se ? Ue : R;
|
|
216
|
+
function Pe(r, e) {
|
|
217
|
+
sr(() => Q(r, e), [r, e]);
|
|
136
218
|
}
|
|
137
|
-
const
|
|
138
|
-
function
|
|
219
|
+
const ur = parseInt($e.split(".")[0], 10), cr = ur >= 19;
|
|
220
|
+
function X({
|
|
139
221
|
href: r,
|
|
140
222
|
fragmentKey: e
|
|
141
223
|
}) {
|
|
142
|
-
return
|
|
224
|
+
return cr ? /* @__PURE__ */ l(
|
|
143
225
|
"link",
|
|
144
226
|
{
|
|
145
227
|
rel: "stylesheet",
|
|
@@ -147,50 +229,50 @@ function oe({
|
|
|
147
229
|
precedence: "default",
|
|
148
230
|
"data-fragment-key": e
|
|
149
231
|
}
|
|
150
|
-
) : (
|
|
232
|
+
) : (Pe(r, e), null);
|
|
151
233
|
}
|
|
152
|
-
function
|
|
234
|
+
function ar(r) {
|
|
153
235
|
}
|
|
154
|
-
const
|
|
236
|
+
const be = Object.freeze({}), z = I(be);
|
|
155
237
|
z.displayName = "HostPropertiesContext";
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
function
|
|
238
|
+
const Z = {}, G = I(null);
|
|
239
|
+
G.displayName = "ProjectPropertiesContext";
|
|
240
|
+
const Ae = Object.freeze({}), ee = I(Ae);
|
|
241
|
+
ee.displayName = "SourceTransportsContext";
|
|
242
|
+
const re = I("live");
|
|
243
|
+
re.displayName = "SourceNetworkContext";
|
|
244
|
+
function ae(r) {
|
|
163
245
|
const e = r instanceof Error ? r : new Error(String(r));
|
|
164
|
-
if (!(e instanceof
|
|
246
|
+
if (!(e instanceof ve))
|
|
165
247
|
return { kind: "failed", error: e };
|
|
166
248
|
const { code: t } = e;
|
|
167
249
|
return t === "NO_ACTIVE_VARIANT" ? { kind: "no-variant", code: t, error: e } : t === "AREA_NOT_FOUND" || t === "NO_PUBLISHED_SNAPSHOT" || t === "NESTED_SNAPSHOT_MISSING" ? { kind: "misconfigured", code: t, error: e } : { kind: "failed", code: t, error: e };
|
|
168
250
|
}
|
|
169
|
-
function
|
|
251
|
+
function Ce(r, e, t) {
|
|
170
252
|
return typeof r == "function" ? r(e, t) : r ?? null;
|
|
171
253
|
}
|
|
172
|
-
const
|
|
254
|
+
const ir = () => {
|
|
173
255
|
};
|
|
174
|
-
function
|
|
256
|
+
function ie(r) {
|
|
175
257
|
return r instanceof Error ? r : new Error(String(r));
|
|
176
258
|
}
|
|
177
|
-
class
|
|
259
|
+
class Re extends Ve {
|
|
178
260
|
constructor() {
|
|
179
261
|
super(...arguments), this.state = { hasError: !1, error: null };
|
|
180
262
|
}
|
|
181
263
|
static getDerivedStateFromError(e) {
|
|
182
|
-
return { hasError: !0, error:
|
|
264
|
+
return { hasError: !0, error: ie(e) };
|
|
183
265
|
}
|
|
184
266
|
componentDidCatch(e, t) {
|
|
185
|
-
var s,
|
|
186
|
-
const n =
|
|
187
|
-
process.env.NODE_ENV !== "production" && console.error("[fragments] Area error:", n, t.componentStack), (
|
|
267
|
+
var s, u;
|
|
268
|
+
const n = ie(e);
|
|
269
|
+
process.env.NODE_ENV !== "production" && console.error("[fragments] Area error:", n, t.componentStack), (u = (s = this.props).onError) == null || u.call(s, n);
|
|
188
270
|
}
|
|
189
271
|
render() {
|
|
190
272
|
if (this.state.hasError) {
|
|
191
273
|
const e = { kind: "failed", error: this.state.error ?? new Error("Unknown Area error") };
|
|
192
274
|
try {
|
|
193
|
-
return
|
|
275
|
+
return Ce(this.props.empty, e, this.props.retry ?? ir);
|
|
194
276
|
} catch {
|
|
195
277
|
return null;
|
|
196
278
|
}
|
|
@@ -198,36 +280,36 @@ class pe extends Me {
|
|
|
198
280
|
return this.props.children;
|
|
199
281
|
}
|
|
200
282
|
}
|
|
201
|
-
function
|
|
283
|
+
function lr(r, e) {
|
|
202
284
|
let t;
|
|
203
285
|
for (const [n, s] of Object.entries(e))
|
|
204
286
|
s != null && (t ?? (t = { ...r }), t[n] = s);
|
|
205
287
|
return t ?? r;
|
|
206
288
|
}
|
|
207
|
-
function
|
|
289
|
+
function dr(r, e) {
|
|
208
290
|
const t = Object.keys(r);
|
|
209
291
|
return t.length !== Object.keys(e).length ? !1 : t.every((n) => Object.prototype.hasOwnProperty.call(e, n) && Object.is(r[n], e[n]));
|
|
210
292
|
}
|
|
211
|
-
const
|
|
212
|
-
function
|
|
293
|
+
const Te = Object.freeze({});
|
|
294
|
+
function Oe(r, e, t) {
|
|
213
295
|
let n;
|
|
214
|
-
for (const [s,
|
|
215
|
-
const o = t[
|
|
296
|
+
for (const [s, u] of Object.entries(e)) {
|
|
297
|
+
const o = t[u];
|
|
216
298
|
o != null && (n ?? (n = { ...r }), n[s] = o);
|
|
217
299
|
}
|
|
218
300
|
return n ?? r;
|
|
219
301
|
}
|
|
220
|
-
function
|
|
302
|
+
function Ie(r, e, t) {
|
|
221
303
|
if (!r) return {};
|
|
222
304
|
const n = {};
|
|
223
305
|
for (const s of Object.keys(r))
|
|
224
|
-
n[s] =
|
|
306
|
+
n[s] = fr(r[s], e, t);
|
|
225
307
|
return n;
|
|
226
308
|
}
|
|
227
|
-
function
|
|
228
|
-
return Array.isArray(r) ? r.map((n, s) => n === null ? null :
|
|
309
|
+
function fr(r, e, t) {
|
|
310
|
+
return Array.isArray(r) ? r.map((n, s) => n === null ? null : le(n, e, t, s)) : le(r, e, t);
|
|
229
311
|
}
|
|
230
|
-
function
|
|
312
|
+
function le(r, e, t, n) {
|
|
231
313
|
let s;
|
|
232
314
|
try {
|
|
233
315
|
s = e(r.fragmentId);
|
|
@@ -236,58 +318,58 @@ function ue(r, e, t, n) {
|
|
|
236
318
|
throw o;
|
|
237
319
|
return console.warn(`[FragmentRenderer] Slot fragment ${r.fragmentId} failed to load — rendering empty hole`, o), null;
|
|
238
320
|
}
|
|
239
|
-
const
|
|
240
|
-
return
|
|
321
|
+
const u = Ie(r.slots, e, t);
|
|
322
|
+
return ze(s, { key: n, ...Oe(r.props, r.projectBindings ?? Te, t), ...u });
|
|
241
323
|
}
|
|
242
|
-
const
|
|
324
|
+
const _e = ({
|
|
243
325
|
fragmentId: r,
|
|
244
326
|
props: e,
|
|
245
327
|
globalCssUrl: t = null,
|
|
246
|
-
projectProperties: n =
|
|
328
|
+
projectProperties: n = Z,
|
|
247
329
|
fragments: s = [r],
|
|
248
|
-
slots:
|
|
249
|
-
sources: o =
|
|
330
|
+
slots: u,
|
|
331
|
+
sources: o = Ae,
|
|
250
332
|
sourceNetwork: m = "live"
|
|
251
333
|
}) => {
|
|
252
|
-
const
|
|
334
|
+
const c = xe(r), a = w(D), d = w(z);
|
|
253
335
|
if (!a)
|
|
254
336
|
throw new Error("[FragmentRendererInner] No ModulesMapProvider in tree");
|
|
255
|
-
const
|
|
256
|
-
() =>
|
|
337
|
+
const g = Ie(u, a.read, d), S = L(
|
|
338
|
+
() => lr(n, d),
|
|
257
339
|
[n, d]
|
|
258
|
-
), f = { ...e ?? {}, ...
|
|
259
|
-
return /* @__PURE__ */
|
|
340
|
+
), f = { ...e ?? {}, ...g }, C = s.length > 0 ? s.map(Ke).join(" ") : void 0;
|
|
341
|
+
return /* @__PURE__ */ De(He, { children: [
|
|
260
342
|
t != null && /* @__PURE__ */ l(
|
|
261
|
-
|
|
343
|
+
X,
|
|
262
344
|
{
|
|
263
345
|
href: t,
|
|
264
|
-
fragmentKey:
|
|
346
|
+
fragmentKey: Ye
|
|
265
347
|
}
|
|
266
348
|
),
|
|
267
|
-
s.map((
|
|
268
|
-
const p =
|
|
349
|
+
s.map((h) => {
|
|
350
|
+
const p = Je(h);
|
|
269
351
|
return p ? /* @__PURE__ */ l(
|
|
270
|
-
|
|
352
|
+
X,
|
|
271
353
|
{
|
|
272
354
|
href: p,
|
|
273
|
-
fragmentKey:
|
|
355
|
+
fragmentKey: We(h)
|
|
274
356
|
},
|
|
275
|
-
|
|
357
|
+
h
|
|
276
358
|
) : null;
|
|
277
359
|
}),
|
|
278
|
-
/* @__PURE__ */ l(
|
|
360
|
+
/* @__PURE__ */ l(re.Provider, { value: m, children: /* @__PURE__ */ l(ee.Provider, { value: o, children: /* @__PURE__ */ l(G.Provider, { value: S, children: /* @__PURE__ */ l(q.Provider, { value: null, children: /* @__PURE__ */ l(
|
|
279
361
|
"div",
|
|
280
362
|
{
|
|
281
|
-
className:
|
|
363
|
+
className: C,
|
|
282
364
|
style: { display: "contents" },
|
|
283
|
-
children: /* @__PURE__ */ l(
|
|
365
|
+
children: /* @__PURE__ */ l(c, { ...f })
|
|
284
366
|
}
|
|
285
367
|
) }) }) }) })
|
|
286
368
|
] });
|
|
287
|
-
},
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
function
|
|
369
|
+
}, mr = ({ onError: r, ...e }) => /* @__PURE__ */ l(he, { fallback: null, children: /* @__PURE__ */ l(Re, { onError: r, children: /* @__PURE__ */ l(_e, { ...e }) }) }), K = I(null);
|
|
370
|
+
K.displayName = "AreaExposureContext";
|
|
371
|
+
const gr = 1e3, hr = Array.from({ length: 101 }, (r, e) => e / 100);
|
|
372
|
+
function vr({
|
|
291
373
|
visibleArea: r,
|
|
292
374
|
totalArea: e,
|
|
293
375
|
visibleHeight: t,
|
|
@@ -295,60 +377,60 @@ function lr({
|
|
|
295
377
|
}) {
|
|
296
378
|
if (r <= 0)
|
|
297
379
|
return !1;
|
|
298
|
-
const s = e > 0 && r >= 0.5 * e,
|
|
299
|
-
return s ||
|
|
380
|
+
const s = e > 0 && r >= 0.5 * e, u = n > 0 && t >= 0.5 * n;
|
|
381
|
+
return s || u;
|
|
300
382
|
}
|
|
301
|
-
function
|
|
383
|
+
function de() {
|
|
302
384
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (r) => {
|
|
303
385
|
const e = Math.random() * 16 | 0;
|
|
304
386
|
return (r === "x" ? e : e & 3 | 8).toString(16);
|
|
305
387
|
});
|
|
306
388
|
}
|
|
307
|
-
function
|
|
389
|
+
function fe(r) {
|
|
308
390
|
const e = r.getBoundingClientRect();
|
|
309
391
|
return e.width > 0 && e.height > 0;
|
|
310
392
|
}
|
|
311
|
-
function
|
|
393
|
+
function Er(r) {
|
|
312
394
|
const e = [];
|
|
313
395
|
function t(n, s) {
|
|
314
|
-
var
|
|
396
|
+
var u;
|
|
315
397
|
for (const o of Array.from(n.children)) {
|
|
316
398
|
let m = "";
|
|
317
399
|
try {
|
|
318
400
|
m = window.getComputedStyle(o).display;
|
|
319
401
|
} catch {
|
|
320
|
-
m = ((
|
|
402
|
+
m = ((u = o.style) == null ? void 0 : u.display) || "";
|
|
321
403
|
}
|
|
322
404
|
if (m === "contents")
|
|
323
405
|
t(o, s);
|
|
324
|
-
else if (m === "none" ||
|
|
406
|
+
else if (m === "none" || fe(o))
|
|
325
407
|
s.push(o);
|
|
326
408
|
else {
|
|
327
|
-
const
|
|
328
|
-
t(o,
|
|
409
|
+
const c = [];
|
|
410
|
+
t(o, c), c.some(fe) ? s.push(...c) : s.push(o);
|
|
329
411
|
}
|
|
330
412
|
}
|
|
331
413
|
}
|
|
332
414
|
return t(r, e), e;
|
|
333
415
|
}
|
|
334
|
-
const
|
|
416
|
+
const yr = ({
|
|
335
417
|
experiment: r,
|
|
336
418
|
emit: e,
|
|
337
419
|
children: t
|
|
338
420
|
}) => {
|
|
339
|
-
const [n, s] =
|
|
421
|
+
const [n, s] = j(de), u = A(!1), o = A(null), m = A(/* @__PURE__ */ new Set()), c = A(null), a = A(r);
|
|
340
422
|
a.current = r;
|
|
341
423
|
const d = A(e);
|
|
342
424
|
d.current = e;
|
|
343
|
-
const
|
|
344
|
-
|
|
425
|
+
const g = A(n);
|
|
426
|
+
g.current = n;
|
|
345
427
|
const S = B(() => {
|
|
346
|
-
|
|
428
|
+
u.current || (u.current = !0, o.current && (clearTimeout(o.current), o.current = null), d.current({
|
|
347
429
|
type: "impression",
|
|
348
430
|
experiment: a.current,
|
|
349
|
-
viewId:
|
|
431
|
+
viewId: g.current
|
|
350
432
|
}));
|
|
351
|
-
}, []), f =
|
|
433
|
+
}, []), f = L(
|
|
352
434
|
() => ({
|
|
353
435
|
experiment: r,
|
|
354
436
|
viewId: n,
|
|
@@ -361,183 +443,188 @@ const fr = ({
|
|
|
361
443
|
return R(() => {
|
|
362
444
|
if (typeof window > "u" || typeof IntersectionObserver > "u")
|
|
363
445
|
return;
|
|
364
|
-
const
|
|
365
|
-
if (!
|
|
366
|
-
let
|
|
446
|
+
const C = c.current;
|
|
447
|
+
if (!C) return;
|
|
448
|
+
let h = [];
|
|
367
449
|
const p = /* @__PURE__ */ new Map(), i = () => !(typeof document > "u" || "visibilityState" in document && document.visibilityState === "hidden" || "prerendering" in document && document.prerendering), y = () => {
|
|
368
|
-
if (
|
|
369
|
-
let
|
|
370
|
-
for (const
|
|
371
|
-
const x = p.get(
|
|
372
|
-
x && (
|
|
450
|
+
if (u.current || h.length === 0) return;
|
|
451
|
+
let b = 0, E = 0, M = !1, N = 1 / 0, k = -1 / 0;
|
|
452
|
+
for (const Y of h) {
|
|
453
|
+
const x = p.get(Y);
|
|
454
|
+
x && (b += x.interArea, E += x.boundArea, x.interArea > 0 && x.interBottom > x.interTop && (M = !0, x.interTop < N && (N = x.interTop), x.interBottom > k && (k = x.interBottom)));
|
|
373
455
|
}
|
|
374
|
-
const U = M ? Math.max(0,
|
|
375
|
-
i() &&
|
|
376
|
-
visibleArea:
|
|
456
|
+
const U = M ? Math.max(0, k - N) : 0, $ = typeof window < "u" ? window.innerHeight : 0;
|
|
457
|
+
i() && vr({
|
|
458
|
+
visibleArea: b,
|
|
377
459
|
totalArea: E,
|
|
378
460
|
visibleHeight: U,
|
|
379
461
|
viewportHeight: $
|
|
380
462
|
}) ? o.current || (o.current = setTimeout(() => {
|
|
381
463
|
o.current = null, S();
|
|
382
|
-
},
|
|
383
|
-
},
|
|
384
|
-
(
|
|
385
|
-
var E, M,
|
|
386
|
-
for (const O of
|
|
387
|
-
const
|
|
464
|
+
}, gr)) : o.current && (clearTimeout(o.current), o.current = null);
|
|
465
|
+
}, v = new IntersectionObserver(
|
|
466
|
+
(b) => {
|
|
467
|
+
var E, M, N, k, U, $;
|
|
468
|
+
for (const O of b) {
|
|
469
|
+
const Y = ((E = O.boundingClientRect) == null ? void 0 : E.width) ?? 0, x = ((M = O.boundingClientRect) == null ? void 0 : M.height) ?? 0, Ne = ((N = O.intersectionRect) == null ? void 0 : N.width) ?? 0, ke = ((k = O.intersectionRect) == null ? void 0 : k.height) ?? 0, se = Y * x, Me = Ne * ke, je = ((U = O.intersectionRect) == null ? void 0 : U.top) ?? 0, Le = (($ = O.intersectionRect) == null ? void 0 : $.bottom) ?? 0;
|
|
388
470
|
p.set(O.target, {
|
|
389
|
-
interArea:
|
|
390
|
-
boundArea:
|
|
391
|
-
interTop:
|
|
392
|
-
interBottom:
|
|
471
|
+
interArea: se > 0 ? Me : 0,
|
|
472
|
+
boundArea: se,
|
|
473
|
+
interTop: je,
|
|
474
|
+
interBottom: Le
|
|
393
475
|
});
|
|
394
476
|
}
|
|
395
|
-
|
|
477
|
+
u.current || y();
|
|
396
478
|
},
|
|
397
|
-
{ threshold:
|
|
398
|
-
),
|
|
399
|
-
if (
|
|
400
|
-
const
|
|
401
|
-
for (const E of
|
|
402
|
-
|
|
403
|
-
for (const E of
|
|
404
|
-
|
|
405
|
-
|
|
479
|
+
{ threshold: hr }
|
|
480
|
+
), T = () => {
|
|
481
|
+
if (u.current || !c.current) return;
|
|
482
|
+
const b = Er(c.current);
|
|
483
|
+
for (const E of h)
|
|
484
|
+
b.includes(E) || (v.unobserve(E), p.delete(E));
|
|
485
|
+
for (const E of b)
|
|
486
|
+
h.includes(E) || v.observe(E);
|
|
487
|
+
h = b;
|
|
406
488
|
};
|
|
407
|
-
|
|
408
|
-
let
|
|
409
|
-
typeof MutationObserver < "u" && (
|
|
410
|
-
|
|
411
|
-
}),
|
|
412
|
-
const
|
|
489
|
+
T();
|
|
490
|
+
let P = null;
|
|
491
|
+
typeof MutationObserver < "u" && (P = new MutationObserver(() => {
|
|
492
|
+
u.current || T();
|
|
493
|
+
}), P.observe(C, { childList: !0, subtree: !0 }));
|
|
494
|
+
const F = () => {
|
|
413
495
|
typeof document < "u" && document.visibilityState === "hidden" ? o.current && (clearTimeout(o.current), o.current = null) : y();
|
|
414
496
|
}, H = () => {
|
|
415
497
|
y();
|
|
416
|
-
},
|
|
498
|
+
}, te = () => {
|
|
417
499
|
o.current && (clearTimeout(o.current), o.current = null);
|
|
418
|
-
},
|
|
500
|
+
}, ne = () => {
|
|
419
501
|
y();
|
|
420
|
-
},
|
|
421
|
-
if (
|
|
422
|
-
o.current && (clearTimeout(o.current), o.current = null),
|
|
423
|
-
const E =
|
|
424
|
-
|
|
502
|
+
}, oe = (b) => {
|
|
503
|
+
if (b.persisted) {
|
|
504
|
+
o.current && (clearTimeout(o.current), o.current = null), u.current = !1;
|
|
505
|
+
const E = de();
|
|
506
|
+
g.current = E, s(E), y();
|
|
425
507
|
}
|
|
426
508
|
};
|
|
427
|
-
return typeof document < "u" && (document.addEventListener("visibilitychange",
|
|
428
|
-
o.current && (clearTimeout(o.current), o.current = null),
|
|
509
|
+
return typeof document < "u" && (document.addEventListener("visibilitychange", F), document.addEventListener("prerenderingchange", H)), typeof window < "u" && (window.addEventListener("pagehide", te), window.addEventListener("resize", ne), window.addEventListener("pageshow", oe)), () => {
|
|
510
|
+
o.current && (clearTimeout(o.current), o.current = null), v.disconnect(), P && P.disconnect(), typeof document < "u" && (document.removeEventListener("visibilitychange", F), document.removeEventListener("prerenderingchange", H)), typeof window < "u" && (window.removeEventListener("pagehide", te), window.removeEventListener("resize", ne), window.removeEventListener("pageshow", oe));
|
|
429
511
|
};
|
|
430
|
-
}, [r, e]), /* @__PURE__ */ l(
|
|
431
|
-
},
|
|
432
|
-
const n =
|
|
512
|
+
}, [r, e]), /* @__PURE__ */ l(K.Provider, { value: f, children: /* @__PURE__ */ l("div", { ref: c, style: { display: "contents" }, children: t }) });
|
|
513
|
+
}, pr = ({ areaCode: r, options: e, retry: t }) => {
|
|
514
|
+
const n = we(r, {
|
|
433
515
|
suspense: !1,
|
|
434
516
|
ssr: !1,
|
|
435
517
|
pause: e == null ? void 0 : e.pause,
|
|
436
518
|
timeout: e == null ? void 0 : e.timeout
|
|
437
|
-
}), s = w(z),
|
|
519
|
+
}), s = w(z), u = w(_), o = A(null);
|
|
438
520
|
if (R(() => {
|
|
439
|
-
var
|
|
521
|
+
var P;
|
|
440
522
|
if (n.status !== "not-found" || !n.error) return;
|
|
441
|
-
const
|
|
523
|
+
const v = ae(n.error), T = JSON.stringify([
|
|
442
524
|
r,
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
525
|
+
v.kind,
|
|
526
|
+
v.code,
|
|
527
|
+
v.error.message
|
|
446
528
|
]);
|
|
447
|
-
o.current !==
|
|
448
|
-
`[fragments] Area resolution ${
|
|
449
|
-
|
|
529
|
+
o.current !== T && (o.current = T, (P = e == null ? void 0 : e.onError) == null || P.call(e, v.error), process.env.NODE_ENV !== "production" && v.kind !== "no-variant" && console.error(
|
|
530
|
+
`[fragments] Area resolution ${v.kind}: areaCode=${r}, code=${v.code ?? "none"}`,
|
|
531
|
+
v.error
|
|
450
532
|
));
|
|
451
533
|
}, [r, e == null ? void 0 : e.onError, n.error, n.status]), (e == null ? void 0 : e.pause) === !0)
|
|
452
534
|
return null;
|
|
453
535
|
if (n.status === "idle")
|
|
454
536
|
return (e == null ? void 0 : e.fallback) ?? null;
|
|
455
537
|
if (n.status === "not-found")
|
|
456
|
-
return
|
|
538
|
+
return Ce(
|
|
457
539
|
e == null ? void 0 : e.empty,
|
|
458
|
-
|
|
540
|
+
ae(n.error),
|
|
459
541
|
t
|
|
460
542
|
);
|
|
461
543
|
if (n.status === "loading" || !n.data)
|
|
462
544
|
return (e == null ? void 0 : e.fallback) ?? null;
|
|
463
545
|
const {
|
|
464
546
|
rootFragmentId: m,
|
|
465
|
-
props:
|
|
547
|
+
props: c,
|
|
466
548
|
projectProperties: a,
|
|
467
549
|
globalCssUrl: d,
|
|
468
|
-
fragments:
|
|
550
|
+
fragments: g,
|
|
469
551
|
slots: S,
|
|
470
552
|
sources: f,
|
|
471
|
-
projectBindings:
|
|
472
|
-
} = n.data,
|
|
473
|
-
|
|
474
|
-
|
|
553
|
+
projectBindings: C
|
|
554
|
+
} = n.data, h = Oe(
|
|
555
|
+
c,
|
|
556
|
+
C ?? Te,
|
|
475
557
|
s
|
|
476
|
-
), p = typeof (e == null ? void 0 : e.props) == "function" ? e.props(
|
|
477
|
-
|
|
558
|
+
), p = typeof (e == null ? void 0 : e.props) == "function" ? e.props(h) : e != null && e.props ? { ...h, ...e.props } : h, i = n.data.experiment, y = /* @__PURE__ */ l(
|
|
559
|
+
_e,
|
|
478
560
|
{
|
|
479
561
|
fragmentId: m,
|
|
480
562
|
props: p,
|
|
481
563
|
globalCssUrl: d,
|
|
482
564
|
projectProperties: a,
|
|
483
|
-
fragments:
|
|
565
|
+
fragments: g,
|
|
484
566
|
slots: S,
|
|
485
567
|
sources: f
|
|
486
568
|
}
|
|
487
569
|
);
|
|
488
|
-
return /* @__PURE__ */ l(
|
|
489
|
-
|
|
570
|
+
return /* @__PURE__ */ l(he, { fallback: (e == null ? void 0 : e.fallback) ?? null, children: i && (u != null && u.$events) ? /* @__PURE__ */ l(
|
|
571
|
+
yr,
|
|
490
572
|
{
|
|
491
573
|
experiment: i,
|
|
492
|
-
emit:
|
|
574
|
+
emit: u.$events.emit,
|
|
493
575
|
children: y
|
|
494
576
|
},
|
|
495
577
|
`${i.label}:${i.variantId}`
|
|
496
578
|
) : y });
|
|
497
|
-
},
|
|
498
|
-
const t = w(
|
|
579
|
+
}, xr = ({ areaCode: r, options: e }) => {
|
|
580
|
+
const t = w(_), [n, s] = j(0), u = t == null ? void 0 : t.$area;
|
|
499
581
|
R(() => {
|
|
500
582
|
(e == null ? void 0 : e.ssr) !== !0 || process.env.NODE_ENV === "production" || console.error(
|
|
501
583
|
"[fragments] Area option `ssr` is reserved: server resolution has been removed from the runtime; existing `ssr: false` calls continue to work unchanged."
|
|
502
584
|
);
|
|
503
585
|
}, [e == null ? void 0 : e.ssr]);
|
|
504
586
|
const o = B(() => {
|
|
505
|
-
|
|
587
|
+
u != null && u.resolve && (u.resolve(r).catch(() => {
|
|
506
588
|
}), s((m) => m + 1));
|
|
507
|
-
}, [
|
|
589
|
+
}, [u, r]);
|
|
508
590
|
return (
|
|
509
591
|
// A retry remounts the boundary and AreaInner: a repeated failure is a new
|
|
510
592
|
// telemetry event, so AreaInner intentionally calls options.onError again.
|
|
511
593
|
/* @__PURE__ */ l(
|
|
512
|
-
|
|
594
|
+
Re,
|
|
513
595
|
{
|
|
514
596
|
onError: e == null ? void 0 : e.onError,
|
|
515
597
|
empty: e == null ? void 0 : e.empty,
|
|
516
598
|
retry: o,
|
|
517
|
-
children: /* @__PURE__ */ l(
|
|
599
|
+
children: /* @__PURE__ */ l(pr, { areaCode: r, options: e, retry: o })
|
|
518
600
|
},
|
|
519
601
|
n
|
|
520
602
|
)
|
|
521
603
|
);
|
|
522
604
|
};
|
|
523
|
-
function
|
|
524
|
-
const e = r ??
|
|
525
|
-
|
|
605
|
+
function wr() {
|
|
606
|
+
const r = globalThis, e = r.__FRAGMENTS_DEPS__ ?? (r.__FRAGMENTS_DEPS__ = {});
|
|
607
|
+
e.react = ge, e["react/jsx-runtime"] = Be, e["@fragmentsx/runtime-react"] = tr;
|
|
608
|
+
}
|
|
609
|
+
function Sr(r) {
|
|
610
|
+
const e = r ?? be, t = A(e);
|
|
611
|
+
return dr(t.current, e) || (t.current = e), t.current;
|
|
526
612
|
}
|
|
527
|
-
function
|
|
528
|
-
|
|
613
|
+
function Pr({ client: r, children: e, properties: t }) {
|
|
614
|
+
wr();
|
|
615
|
+
const n = L(
|
|
529
616
|
() => ({
|
|
530
|
-
read: (
|
|
617
|
+
read: (u) => r.$fragments.read(u)
|
|
531
618
|
}),
|
|
532
619
|
[r]
|
|
533
|
-
), s =
|
|
534
|
-
return /* @__PURE__ */ l(
|
|
620
|
+
), s = Sr(t);
|
|
621
|
+
return /* @__PURE__ */ l(ye, { value: r, children: /* @__PURE__ */ l(pe, { value: n, children: /* @__PURE__ */ l(z.Provider, { value: s, children: e }) }) });
|
|
535
622
|
}
|
|
536
|
-
function
|
|
537
|
-
return (w(
|
|
623
|
+
function br(r) {
|
|
624
|
+
return (w(G) ?? Z)[r];
|
|
538
625
|
}
|
|
539
|
-
function
|
|
540
|
-
const e = w(
|
|
626
|
+
function Ar(r) {
|
|
627
|
+
const e = w(K);
|
|
541
628
|
return B(() => {
|
|
542
629
|
e && (e.reachedGoals.has(r) || (e.reachedGoals.add(r), e.ensureImpression(), e.emit({
|
|
543
630
|
type: "goal",
|
|
@@ -547,60 +634,60 @@ function Rr(r) {
|
|
|
547
634
|
})));
|
|
548
635
|
}, [e, r]);
|
|
549
636
|
}
|
|
550
|
-
function
|
|
551
|
-
const [, t] =
|
|
637
|
+
function Cr(r, e) {
|
|
638
|
+
const [, t] = Ge((u) => u + 1, 0), n = e(), s = A(n);
|
|
552
639
|
return s.current = n, R(() => {
|
|
553
|
-
const
|
|
554
|
-
return Object.is(s.current, e()) || t(),
|
|
640
|
+
const u = r(t);
|
|
641
|
+
return Object.is(s.current, e()) || t(), u;
|
|
555
642
|
}, [r, e]), n;
|
|
556
643
|
}
|
|
557
|
-
const
|
|
558
|
-
function
|
|
559
|
-
var
|
|
560
|
-
const t =
|
|
561
|
-
() =>
|
|
562
|
-
[
|
|
563
|
-
), [y,
|
|
644
|
+
const me = ge.useSyncExternalStore, Rr = me || ((r, e) => Cr(r, e)), Fe = "offline", Tr = () => Promise.reject(new Error(Fe));
|
|
645
|
+
function Or(r, e) {
|
|
646
|
+
var T, P;
|
|
647
|
+
const t = nr(), [n] = j(Ee), s = (t == null ? void 0 : t.sourceCache) ?? n, u = (T = t == null ? void 0 : t.sourceFetchers) == null ? void 0 : T[r], o = (P = t == null ? void 0 : t.sourceBaseUrls) == null ? void 0 : P[r], m = u ? "host-fetch" : "network", c = t == null ? void 0 : t.env, a = ue({ source: r, target: e.target, params: e.params }), d = L(() => ({ source: r, target: e.target, params: e.params }), [a]), g = B((F) => s.subscribe(d, F), [s, d]), S = B(() => s.get(d), [s, d]), f = Rr(g, S, S), C = w(re), h = w(ee), p = Xe(r, e.target), i = L(
|
|
648
|
+
() => C === Fe ? null : qe(h[p], d.params, o),
|
|
649
|
+
[C, h, p, d, o]
|
|
650
|
+
), [y, v] = j(null);
|
|
564
651
|
return R(() => {
|
|
565
|
-
(f == null ? void 0 : f.status) === "ready" && y !== null &&
|
|
652
|
+
(f == null ? void 0 : f.status) === "ready" && y !== null && v(null);
|
|
566
653
|
}, [f, y]), R(() => {
|
|
567
654
|
i && !i.ok && f === void 0 && console.warn(`[useSource] ${p}: ${i.reason}`);
|
|
568
655
|
}, [p, i == null ? void 0 : i.ok, i && !i.ok ? i.reason : void 0, f === void 0]), R(() => {
|
|
569
656
|
if (i && !i.ok || (f == null ? void 0 : f.status) === "ready" || y === a) return;
|
|
570
|
-
|
|
571
|
-
const
|
|
572
|
-
s.load(d,
|
|
573
|
-
}, [s, d, a, f, y, i,
|
|
657
|
+
v(a);
|
|
658
|
+
const F = i && i.ok ? () => Qe({ url: i.url, init: i.init }, { fetcher: u, timeout: c == null ? void 0 : c.timeout }).then((H) => (c != null && c.debug && console.info(`[useSource] loaded ${ue(d)} origin=${m}`), H)) : Tr;
|
|
659
|
+
s.load(d, F, m);
|
|
660
|
+
}, [s, d, a, f, y, i, u, m, c == null ? void 0 : c.timeout, c == null ? void 0 : c.debug]), (f == null ? void 0 : f.status) === "ready" ? { data: f.data ?? void 0, loading: !1 } : (f == null ? void 0 : f.status) === "pending" ? { data: void 0, loading: !0 } : i && !i.ok ? { data: void 0, loading: !1 } : { data: void 0, loading: y !== a };
|
|
574
661
|
}
|
|
575
|
-
const
|
|
576
|
-
function
|
|
577
|
-
return
|
|
662
|
+
const Ir = Or;
|
|
663
|
+
function _r(r) {
|
|
664
|
+
return Ze({ ...r, inject: Q });
|
|
578
665
|
}
|
|
579
666
|
export {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
667
|
+
W as AREA_UNRESOLVED,
|
|
668
|
+
xr as Area,
|
|
669
|
+
K as AreaExposureContext,
|
|
670
|
+
mr as FragmentRenderer,
|
|
671
|
+
X as FragmentStylesheet,
|
|
672
|
+
Lr as FragmentsApiVersionError,
|
|
673
|
+
Br as FragmentsAreaError,
|
|
674
|
+
_ as FragmentsClientContext,
|
|
675
|
+
ye as FragmentsClientProvider,
|
|
676
|
+
Dr as FragmentsLoadError,
|
|
677
|
+
Pr as FragmentsProvider,
|
|
678
|
+
q as InstanceIdContext,
|
|
679
|
+
D as ModulesMapContext,
|
|
680
|
+
pe as ModulesMapProvider,
|
|
681
|
+
G as ProjectPropertiesContext,
|
|
682
|
+
_r as createBrowserClient,
|
|
683
|
+
Hr as createSourceCache,
|
|
684
|
+
Z as defaultProjectProperties,
|
|
685
|
+
Q as injectStylesheet,
|
|
686
|
+
we as useArea,
|
|
687
|
+
ar as useCssChunk,
|
|
688
|
+
xe as useFragmentComponent,
|
|
689
|
+
Pe as useFragmentStylesheet,
|
|
690
|
+
Ar as useGoal,
|
|
691
|
+
br as useProjectProperty,
|
|
692
|
+
Ir as useSource
|
|
606
693
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("react/jsx-runtime"),require("react"),require("@fragmentsx/fragments-client")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@fragmentsx/fragments-client"],l):(i=typeof globalThis<"u"?globalThis:i||self,l(i.FragmentsRuntimeReact={},i.jsxRuntime,i.React,i.fragmentsClient))})(this,function(i,l,o,E){"use strict";function Pe(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const Ce=Pe(o),N=o.createContext(null);N.displayName="FragmentsClientContext";function Z(r){return l.jsx(N.Provider,{value:r.value,children:r.children})}function Ae(){return o.useContext(N)}const z=o.createContext(null);z.displayName="InstanceIdContext";const M=o.createContext(null);M.displayName="ModulesMapContext";function R({value:r,children:e}){return l.jsx(M.Provider,{value:r,children:e})}function ee(r){const e=o.useContext(M);if(!e)throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");return e.read(r)}const re=typeof window<"u",K=Object.freeze({rootFragmentId:0,variantId:null,experiment:null,props:{},projectProperties:{},projectBindings:{},globalCssUrl:null,fragments:[],slots:{},sources:{}});function G(r){const e=r.$area;if(!(e!=null&&e.read))throw new Error("[useArea] $area plugin not mounted");return e}function te(r,e){const t=o.useContext(N);if(!t)throw new Error("[useArea] No FragmentsClientProvider in tree");const n=(e==null?void 0:e.suspense)??!0,u=(e==null?void 0:e.pause)===!0||!re&&(e==null?void 0:e.ssr)===!1,c=(e==null?void 0:e.timeout)!=null?{timeout:e.timeout}:void 0,[,s]=o.useState(0);if(o.useEffect(()=>{if(n||u)return;const a=G(t);let d=!0;return Promise.resolve(a.resolve(r,c)).catch(()=>{}).finally(()=>{d&&s(m=>m+1)}),()=>{d=!1}},[r,n,e==null?void 0:e.pause,e==null?void 0:e.timeout,e==null?void 0:e.ssr]),n){if(u)return K;const a=G(t);if(a.has(r)||Promise.resolve(a.resolve(r,c)).catch(()=>{}),!re)try{return a.read(r)}catch(d){if(d!=null&&typeof d.then=="function")throw d;return process.env.NODE_ENV!=="production"&&console.error(`[useArea] Area ${r} remained unresolved on the server because its cache reached a terminal state`,d),K}return a.read(r)}if(u)return{status:"idle",data:null,error:null};const g=G(t);if(g.has(r))try{return{status:"ready",data:g.read(r),error:null}}catch(a){return{status:"not-found",data:null,error:a instanceof Error?a:new Error(String(a))}}return Promise.resolve(g.resolve(r,c)).catch(()=>{}),{status:"loading",data:null,error:null}}const ne=typeof window<"u",Oe=3e3,L=new Map,Y=(r,e)=>{if(!ne){const v=()=>{};return v.loaded=Promise.resolve(),v}const t=L.get(e);if(t){t.refCount+=1;const v=()=>{t.refCount-=1,t.refCount===0&&(t.clearReadyTimer(),t.linkEl.remove(),L.delete(e))};return v.loaded=t.loaded,v}const n=document.createElement("link");n.rel="stylesheet",n.href=r,n.setAttribute("data-fragment-key",e);let u;const c=new Promise(v=>{u=v}),s=()=>{a(),u()},g=setTimeout(s,Oe),a=()=>clearTimeout(g);n.addEventListener("load",s),n.addEventListener("error",s),document.head.appendChild(n);const d={refCount:1,linkEl:n,loaded:c,clearReadyTimer:a};L.set(e,d);const m=()=>{d.refCount-=1,d.refCount===0&&(d.clearReadyTimer(),d.linkEl.remove(),L.delete(e))};return m.loaded=c,m},Te=ne?o.useLayoutEffect:o.useEffect;function oe(r,e){Te(()=>Y(r,e),[r,e])}const Ie=parseInt(o.version.split(".")[0],10)>=19;function q({href:r,fragmentKey:e}){return Ie?l.jsx("link",{rel:"stylesheet",href:r,precedence:"default","data-fragment-key":e}):(oe(r,e),null)}function Ne(r){}const se=Object.freeze({}),B=o.createContext(se);B.displayName="HostPropertiesContext";const J={},D=o.createContext(null);D.displayName="ProjectPropertiesContext";const ue=Object.freeze({}),W=o.createContext(ue);W.displayName="SourceTransportsContext";const X=o.createContext("live");X.displayName="SourceNetworkContext";function ce(r){const e=r instanceof Error?r:new Error(String(r));if(!(e instanceof E.FragmentsAreaError))return{kind:"failed",error:e};const{code:t}=e;return t==="NO_ACTIVE_VARIANT"?{kind:"no-variant",code:t,error:e}:t==="AREA_NOT_FOUND"||t==="NO_PUBLISHED_SNAPSHOT"||t==="NESTED_SNAPSHOT_MISSING"?{kind:"misconfigured",code:t,error:e}:{kind:"failed",code:t,error:e}}function ae(r,e,t){return typeof r=="function"?r(e,t):r??null}const ke=()=>{};function ie(r){return r instanceof Error?r:new Error(String(r))}class le extends o.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:ie(e)}}componentDidCatch(e,t){var u,c;const n=ie(e);process.env.NODE_ENV!=="production"&&console.error("[fragments] Area error:",n,t.componentStack),(c=(u=this.props).onError)==null||c.call(u,n)}render(){if(this.state.hasError){const e={kind:"failed",error:this.state.error??new Error("Unknown Area error")};try{return ae(this.props.empty,e,this.props.retry??ke)}catch{return null}}return this.props.children}}function Fe(r,e){let t;for(const[n,u]of Object.entries(e))u!=null&&(t??(t={...r}),t[n]=u);return t??r}function je(r,e){const t=Object.keys(r);return t.length!==Object.keys(e).length?!1:t.every(n=>Object.prototype.hasOwnProperty.call(e,n)&&Object.is(r[n],e[n]))}const de=Object.freeze({});function fe(r,e,t){let n;for(const[u,c]of Object.entries(e)){const s=t[c];s!=null&&(n??(n={...r}),n[u]=s)}return n??r}function me(r,e,t){if(!r)return{};const n={};for(const u of Object.keys(r))n[u]=Me(r[u],e,t);return n}function Me(r,e,t){return Array.isArray(r)?r.map((n,u)=>n===null?null:he(n,e,t,u)):he(r,e,t)}function he(r,e,t,n){let u;try{u=e(r.fragmentId)}catch(s){if(s!=null&&typeof s.then=="function")throw s;return console.warn(`[FragmentRenderer] Slot fragment ${r.fragmentId} failed to load — rendering empty hole`,s),null}const c=me(r.slots,e,t);return o.createElement(u,{key:n,...fe(r.props,r.projectBindings??de,t),...c})}const ge=({fragmentId:r,props:e,globalCssUrl:t=null,projectProperties:n=J,fragments:u=[r],slots:c,sources:s=ue,sourceNetwork:g="live"})=>{const a=ee(r),d=o.useContext(M),m=o.useContext(B);if(!d)throw new Error("[FragmentRendererInner] No ModulesMapProvider in tree");const v=me(c,d.read,m),P=o.useMemo(()=>Fe(n,m),[n,m]),h={...e??{},...v},O=u.length>0?u.map(E.toScopeClassName).join(" "):void 0;return l.jsxs(l.Fragment,{children:[t!=null&&l.jsx(q,{href:t,fragmentKey:E.AREA_GLOBAL_CSS_KEY}),u.map(y=>{const w=E.resolveStylesHref(y);return w?l.jsx(q,{href:w,fragmentKey:E.fragmentCssKey(y)},y):null}),l.jsx(X.Provider,{value:g,children:l.jsx(W.Provider,{value:s,children:l.jsx(D.Provider,{value:P,children:l.jsx(z.Provider,{value:null,children:l.jsx("div",{className:O,style:{display:"contents"},children:l.jsx(a,{...h})})})})})})]})},_e=({onError:r,...e})=>l.jsx(o.Suspense,{fallback:null,children:l.jsx(le,{onError:r,children:l.jsx(ge,{...e})})}),H=o.createContext(null);H.displayName="AreaExposureContext";const Le=1e3,Be=Array.from({length:101},(r,e)=>e/100);function De({visibleArea:r,totalArea:e,visibleHeight:t,viewportHeight:n}){if(r<=0)return!1;const u=e>0&&r>=.5*e,c=n>0&&t>=.5*n;return u||c}function ve(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{const e=Math.random()*16|0;return(r==="x"?e:e&3|8).toString(16)})}function Ee(r){const e=r.getBoundingClientRect();return e.width>0&&e.height>0}function He(r){const e=[];function t(n,u){var c;for(const s of Array.from(n.children)){let g="";try{g=window.getComputedStyle(s).display}catch{g=((c=s.style)==null?void 0:c.display)||""}if(g==="contents")t(s,u);else if(g==="none"||Ee(s))u.push(s);else{const a=[];t(s,a),a.some(Ee)?u.push(...a):u.push(s)}}}return t(r,e),e}const Ue=({experiment:r,emit:e,children:t})=>{const[n,u]=o.useState(ve),c=o.useRef(!1),s=o.useRef(null),g=o.useRef(new Set),a=o.useRef(null),d=o.useRef(r);d.current=r;const m=o.useRef(e);m.current=e;const v=o.useRef(n);v.current=n;const P=o.useCallback(()=>{c.current||(c.current=!0,s.current&&(clearTimeout(s.current),s.current=null),m.current({type:"impression",experiment:d.current,viewId:v.current}))},[]),h=o.useMemo(()=>({experiment:r,viewId:n,emit:e,reachedGoals:g.current,ensureImpression:P}),[r,n,e,P]);return o.useEffect(()=>{if(typeof window>"u"||typeof IntersectionObserver>"u")return;const O=a.current;if(!O)return;let y=[];const w=new Map,f=()=>!(typeof document>"u"||"visibilityState"in document&&document.visibilityState==="hidden"||"prerendering"in document&&document.prerendering),x=()=>{if(c.current||y.length===0)return;let A=0,p=0,_=!1,F=1/0,j=-1/0;for(const Q of y){const b=w.get(Q);b&&(A+=b.interArea,p+=b.boundArea,b.interArea>0&&b.interBottom>b.interTop&&(_=!0,b.interTop<F&&(F=b.interTop),b.interBottom>j&&(j=b.interBottom)))}const $=_?Math.max(0,j-F):0,V=typeof window<"u"?window.innerHeight:0;f()&&De({visibleArea:A,totalArea:p,visibleHeight:$,viewportHeight:V})?s.current||(s.current=setTimeout(()=>{s.current=null,P()},Le)):s.current&&(clearTimeout(s.current),s.current=null)},S=new IntersectionObserver(A=>{var p,_,F,j,$,V;for(const I of A){const Q=((p=I.boundingClientRect)==null?void 0:p.width)??0,b=((_=I.boundingClientRect)==null?void 0:_.height)??0,Re=((F=I.intersectionRect)==null?void 0:F.width)??0,er=((j=I.intersectionRect)==null?void 0:j.height)??0,be=Q*b,rr=Re*er,tr=(($=I.intersectionRect)==null?void 0:$.top)??0,nr=((V=I.intersectionRect)==null?void 0:V.bottom)??0;w.set(I.target,{interArea:be>0?rr:0,boundArea:be,interTop:tr,interBottom:nr})}c.current||x()},{threshold:Be}),T=()=>{if(c.current||!a.current)return;const A=He(a.current);for(const p of y)A.includes(p)||(S.unobserve(p),w.delete(p));for(const p of A)y.includes(p)||S.observe(p);y=A};T();let C=null;typeof MutationObserver<"u"&&(C=new MutationObserver(()=>{c.current||T()}),C.observe(O,{childList:!0,subtree:!0}));const k=()=>{typeof document<"u"&&document.visibilityState==="hidden"?s.current&&(clearTimeout(s.current),s.current=null):x()},U=()=>{x()},pe=()=>{s.current&&(clearTimeout(s.current),s.current=null)},xe=()=>{x()},we=A=>{if(A.persisted){s.current&&(clearTimeout(s.current),s.current=null),c.current=!1;const p=ve();v.current=p,u(p),x()}};return typeof document<"u"&&(document.addEventListener("visibilitychange",k),document.addEventListener("prerenderingchange",U)),typeof window<"u"&&(window.addEventListener("pagehide",pe),window.addEventListener("resize",xe),window.addEventListener("pageshow",we)),()=>{s.current&&(clearTimeout(s.current),s.current=null),S.disconnect(),C&&C.disconnect(),typeof document<"u"&&(document.removeEventListener("visibilitychange",k),document.removeEventListener("prerenderingchange",U)),typeof window<"u"&&(window.removeEventListener("pagehide",pe),window.removeEventListener("resize",xe),window.removeEventListener("pageshow",we))}},[r,e]),l.jsx(H.Provider,{value:h,children:l.jsx("div",{ref:a,style:{display:"contents"},children:t})})},$e=({areaCode:r,options:e,retry:t})=>{const n=te(r,{suspense:!1,ssr:!1,pause:e==null?void 0:e.pause,timeout:e==null?void 0:e.timeout}),u=o.useContext(B),c=o.useContext(N),s=o.useRef(null);if(o.useEffect(()=>{var C;if(n.status!=="not-found"||!n.error)return;const S=ce(n.error),T=JSON.stringify([r,S.kind,S.code,S.error.message]);s.current!==T&&(s.current=T,(C=e==null?void 0:e.onError)==null||C.call(e,S.error),process.env.NODE_ENV!=="production"&&S.kind!=="no-variant"&&console.error(`[fragments] Area resolution ${S.kind}: areaCode=${r}, code=${S.code??"none"}`,S.error))},[r,e==null?void 0:e.onError,n.error,n.status]),(e==null?void 0:e.pause)===!0)return null;if(n.status==="idle")return(e==null?void 0:e.fallback)??null;if(n.status==="not-found")return ae(e==null?void 0:e.empty,ce(n.error),t);if(n.status==="loading"||!n.data)return(e==null?void 0:e.fallback)??null;const{rootFragmentId:g,props:a,projectProperties:d,globalCssUrl:m,fragments:v,slots:P,sources:h,projectBindings:O}=n.data,y=fe(a,O??de,u),w=typeof(e==null?void 0:e.props)=="function"?e.props(y):e!=null&&e.props?{...y,...e.props}:y,f=n.data.experiment,x=l.jsx(ge,{fragmentId:g,props:w,globalCssUrl:m,projectProperties:d,fragments:v,slots:P,sources:h});return l.jsx(o.Suspense,{fallback:(e==null?void 0:e.fallback)??null,children:f&&(c!=null&&c.$events)?l.jsx(Ue,{experiment:f,emit:c.$events.emit,children:x},`${f.label}:${f.variantId}`):x})},Ve=({areaCode:r,options:e})=>{const t=o.useContext(N),[n,u]=o.useState(0),c=t==null?void 0:t.$area;o.useEffect(()=>{(e==null?void 0:e.ssr)!==!0||process.env.NODE_ENV==="production"||console.error("[fragments] Area option `ssr` is reserved: server resolution has been removed from the runtime; existing `ssr: false` calls continue to work unchanged.")},[e==null?void 0:e.ssr]);const s=o.useCallback(()=>{c!=null&&c.resolve&&(c.resolve(r).catch(()=>{}),u(g=>g+1))},[c,r]);return l.jsx(le,{onError:e==null?void 0:e.onError,empty:e==null?void 0:e.empty,retry:s,children:l.jsx($e,{areaCode:r,options:e,retry:s})},n)};function ze(r){const e=r??se,t=o.useRef(e);return je(t.current,e)||(t.current=e),t.current}function Ke({client:r,children:e,properties:t}){const n=o.useMemo(()=>({read:c=>r.$fragments.read(c)}),[r]),u=ze(t);return l.jsx(Z,{value:r,children:l.jsx(R,{value:n,children:l.jsx(B.Provider,{value:u,children:e})})})}function Ge(r){return(o.useContext(D)??J)[r]}function Ye(r){const e=o.useContext(H);return o.useCallback(()=>{e&&(e.reachedGoals.has(r)||(e.reachedGoals.add(r),e.ensureImpression(),e.emit({type:"goal",experiment:e.experiment,viewId:e.viewId,goalKey:r})))},[e,r])}function qe(r,e){const[,t]=o.useReducer(c=>c+1,0),n=e(),u=o.useRef(n);return u.current=n,o.useEffect(()=>{const c=r(t);return Object.is(u.current,e())||t(),c},[r,e]),n}const ye=Ce.useSyncExternalStore,Je=ye||((r,e)=>qe(r,e)),Se="offline",We=()=>Promise.reject(new Error(Se));function Xe(r,e){var T,C;const t=Ae(),[n]=o.useState(E.createSourceCache),u=(t==null?void 0:t.sourceCache)??n,c=(T=t==null?void 0:t.sourceFetchers)==null?void 0:T[r],s=(C=t==null?void 0:t.sourceBaseUrls)==null?void 0:C[r],g=c?"host-fetch":"network",a=t==null?void 0:t.env,d=E.sourceCallKey({source:r,target:e.target,params:e.params}),m=o.useMemo(()=>({source:r,target:e.target,params:e.params}),[d]),v=o.useCallback(k=>u.subscribe(m,k),[u,m]),P=o.useCallback(()=>u.get(m),[u,m]),h=Je(v,P,P),O=o.useContext(X),y=o.useContext(W),w=E.sourceTransportKey(r,e.target),f=o.useMemo(()=>O===Se?null:E.resolveSourceRequest(y[w],m.params,s),[O,y,w,m,s]),[x,S]=o.useState(null);return o.useEffect(()=>{(h==null?void 0:h.status)==="ready"&&x!==null&&S(null)},[h,x]),o.useEffect(()=>{f&&!f.ok&&h===void 0&&console.warn(`[useSource] ${w}: ${f.reason}`)},[w,f==null?void 0:f.ok,f&&!f.ok?f.reason:void 0,h===void 0]),o.useEffect(()=>{if(f&&!f.ok||(h==null?void 0:h.status)==="ready"||x===d)return;S(d);const k=f&&f.ok?()=>E.runSourceFetch({url:f.url,init:f.init},{fetcher:c,timeout:a==null?void 0:a.timeout}).then(U=>(a!=null&&a.debug&&console.info(`[useSource] loaded ${E.sourceCallKey(m)} origin=${g}`),U)):We;u.load(m,k,g)},[u,m,d,h,x,f,c,g,a==null?void 0:a.timeout,a==null?void 0:a.debug]),(h==null?void 0:h.status)==="ready"?{data:h.data??void 0,loading:!1}:(h==null?void 0:h.status)==="pending"?{data:void 0,loading:!0}:f&&!f.ok?{data:void 0,loading:!1}:{data:void 0,loading:x!==d}}const Qe=Xe;function Ze(r){return E.createFragmentsClient({...r,inject:Y})}Object.defineProperty(i,"FragmentsApiVersionError",{enumerable:!0,get:()=>E.FragmentsApiVersionError}),Object.defineProperty(i,"FragmentsAreaError",{enumerable:!0,get:()=>E.FragmentsAreaError}),Object.defineProperty(i,"FragmentsLoadError",{enumerable:!0,get:()=>E.FragmentsLoadError}),Object.defineProperty(i,"createSourceCache",{enumerable:!0,get:()=>E.createSourceCache}),i.AREA_UNRESOLVED=K,i.Area=Ve,i.AreaExposureContext=H,i.FragmentRenderer=_e,i.FragmentStylesheet=q,i.FragmentsClientContext=N,i.FragmentsClientProvider=Z,i.FragmentsProvider=Ke,i.InstanceIdContext=z,i.ModulesMapContext=M,i.ModulesMapProvider=R,i.ProjectPropertiesContext=D,i.createBrowserClient=Ze,i.defaultProjectProperties=J,i.injectStylesheet=Y,i.useArea=te,i.useCssChunk=Ne,i.useFragmentComponent=ee,i.useFragmentStylesheet=oe,i.useGoal=Ye,i.useProjectProperty=Ge,i.useSource=Qe,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(i,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("react/jsx-runtime"),require("react"),require("@fragmentsx/fragments-client")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@fragmentsx/fragments-client"],l):(i=typeof globalThis<"u"?globalThis:i||self,l(i.FragmentsRuntimeReact={},i.jsxRuntime,i.React,i.fragmentsClient))})(this,function(i,l,o,E){"use strict";"use client";function ne(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const Ne=ne(l),oe=ne(o),ke=Object.freeze(Object.defineProperty({__proto__:null,get AREA_UNRESOLVED(){return H},get Area(){return Pe},get AreaExposureContext(){return L},get FragmentRenderer(){return pe},get FragmentStylesheet(){return $},get FragmentsApiVersionError(){return E.FragmentsApiVersionError},get FragmentsAreaError(){return E.FragmentsAreaError},get FragmentsClientContext(){return T},get FragmentsClientProvider(){return J},get FragmentsLoadError(){return E.FragmentsLoadError},get FragmentsProvider(){return be},get InstanceIdContext(){return D},get ModulesMapContext(){return j},get ModulesMapProvider(){return W},get ProjectPropertiesContext(){return k},get createBrowserClient(){return Fe},get createSourceCache(){return E.createSourceCache},get defaultProjectProperties(){return G},get injectStylesheet(){return V},get useArea(){return Z},get useCssChunk(){return ce},get useFragmentComponent(){return X},get useFragmentStylesheet(){return R},get useGoal(){return Ce},get useProjectProperty(){return we},get useSource(){return Te}},Symbol.toStringTag,{value:"Module"})),T=o.createContext(null);T.displayName="FragmentsClientContext";function J(r){return l.jsx(T.Provider,{value:r.value,children:r.children})}function Le(){return o.useContext(T)}const D=o.createContext(null);D.displayName="InstanceIdContext";const j=o.createContext(null);j.displayName="ModulesMapContext";function W({value:r,children:e}){return l.jsx(j.Provider,{value:r,children:e})}function X(r){const e=o.useContext(j);if(!e)throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");return e.read(r)}const se=typeof window<"u",H=Object.freeze({rootFragmentId:0,variantId:null,experiment:null,props:{},projectProperties:{},projectBindings:{},globalCssUrl:null,fragments:[],slots:{},sources:{}});function Q(r){const e=r.$area;if(!(e!=null&&e.read))throw new Error("[useArea] $area plugin not mounted");return e}function Z(r,e){const t=o.useContext(T);if(!t)throw new Error("[useArea] No FragmentsClientProvider in tree");const n=(e==null?void 0:e.suspense)??!0,u=(e==null?void 0:e.pause)===!0||!se&&(e==null?void 0:e.ssr)===!1,c=(e==null?void 0:e.timeout)!=null?{timeout:e.timeout}:void 0,[,s]=o.useState(0);if(o.useEffect(()=>{if(n||u)return;const a=Q(t);let d=!0;return Promise.resolve(a.resolve(r,c)).catch(()=>{}).finally(()=>{d&&s(m=>m+1)}),()=>{d=!1}},[r,n,e==null?void 0:e.pause,e==null?void 0:e.timeout,e==null?void 0:e.ssr]),n){if(u)return H;const a=Q(t);if(a.has(r)||Promise.resolve(a.resolve(r,c)).catch(()=>{}),!se)try{return a.read(r)}catch(d){if(d!=null&&typeof d.then=="function")throw d;return process.env.NODE_ENV!=="production"&&console.error(`[useArea] Area ${r} remained unresolved on the server because its cache reached a terminal state`,d),H}return a.read(r)}if(u)return{status:"idle",data:null,error:null};const h=Q(t);if(h.has(r))try{return{status:"ready",data:h.read(r),error:null}}catch(a){return{status:"not-found",data:null,error:a instanceof Error?a:new Error(String(a))}}return Promise.resolve(h.resolve(r,c)).catch(()=>{}),{status:"loading",data:null,error:null}}const ue=typeof window<"u",Be=3e3,U=new Map,V=(r,e)=>{if(!ue){const v=()=>{};return v.loaded=Promise.resolve(),v}const t=U.get(e);if(t){t.refCount+=1;const v=()=>{t.refCount-=1,t.refCount===0&&(t.clearReadyTimer(),t.linkEl.remove(),U.delete(e))};return v.loaded=t.loaded,v}const n=document.createElement("link");n.rel="stylesheet",n.href=r,n.setAttribute("data-fragment-key",e);let u;const c=new Promise(v=>{u=v}),s=()=>{a(),u()},h=setTimeout(s,Be),a=()=>clearTimeout(h);n.addEventListener("load",s),n.addEventListener("error",s),document.head.appendChild(n);const d={refCount:1,linkEl:n,loaded:c,clearReadyTimer:a};U.set(e,d);const m=()=>{d.refCount-=1,d.refCount===0&&(d.clearReadyTimer(),d.linkEl.remove(),U.delete(e))};return m.loaded=c,m},De=ue?o.useLayoutEffect:o.useEffect;function R(r,e){De(()=>V(r,e),[r,e])}const He=parseInt(o.version.split(".")[0],10)>=19;function $({href:r,fragmentKey:e}){return He?l.jsx("link",{rel:"stylesheet",href:r,precedence:"default","data-fragment-key":e}):(R(r,e),null)}function ce(r){}const ae=Object.freeze({}),z=o.createContext(ae);z.displayName="HostPropertiesContext";const G={},k=o.createContext(null);k.displayName="ProjectPropertiesContext";const ie=Object.freeze({}),ee=o.createContext(ie);ee.displayName="SourceTransportsContext";const re=o.createContext("live");re.displayName="SourceNetworkContext";function le(r){const e=r instanceof Error?r:new Error(String(r));if(!(e instanceof E.FragmentsAreaError))return{kind:"failed",error:e};const{code:t}=e;return t==="NO_ACTIVE_VARIANT"?{kind:"no-variant",code:t,error:e}:t==="AREA_NOT_FOUND"||t==="NO_PUBLISHED_SNAPSHOT"||t==="NESTED_SNAPSHOT_MISSING"?{kind:"misconfigured",code:t,error:e}:{kind:"failed",code:t,error:e}}function de(r,e,t){return typeof r=="function"?r(e,t):r??null}const Ue=()=>{};function fe(r){return r instanceof Error?r:new Error(String(r))}class me extends o.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:fe(e)}}componentDidCatch(e,t){var u,c;const n=fe(e);process.env.NODE_ENV!=="production"&&console.error("[fragments] Area error:",n,t.componentStack),(c=(u=this.props).onError)==null||c.call(u,n)}render(){if(this.state.hasError){const e={kind:"failed",error:this.state.error??new Error("Unknown Area error")};try{return de(this.props.empty,e,this.props.retry??Ue)}catch{return null}}return this.props.children}}function Ve(r,e){let t;for(const[n,u]of Object.entries(e))u!=null&&(t??(t={...r}),t[n]=u);return t??r}function $e(r,e){const t=Object.keys(r);return t.length!==Object.keys(e).length?!1:t.every(n=>Object.prototype.hasOwnProperty.call(e,n)&&Object.is(r[n],e[n]))}const ge=Object.freeze({});function he(r,e,t){let n;for(const[u,c]of Object.entries(e)){const s=t[c];s!=null&&(n??(n={...r}),n[u]=s)}return n??r}function Ee(r,e,t){if(!r)return{};const n={};for(const u of Object.keys(r))n[u]=ze(r[u],e,t);return n}function ze(r,e,t){return Array.isArray(r)?r.map((n,u)=>n===null?null:ve(n,e,t,u)):ve(r,e,t)}function ve(r,e,t,n){let u;try{u=e(r.fragmentId)}catch(s){if(s!=null&&typeof s.then=="function")throw s;return console.warn(`[FragmentRenderer] Slot fragment ${r.fragmentId} failed to load — rendering empty hole`,s),null}const c=Ee(r.slots,e,t);return o.createElement(u,{key:n,...he(r.props,r.projectBindings??ge,t),...c})}const ye=({fragmentId:r,props:e,globalCssUrl:t=null,projectProperties:n=G,fragments:u=[r],slots:c,sources:s=ie,sourceNetwork:h="live"})=>{const a=X(r),d=o.useContext(j),m=o.useContext(z);if(!d)throw new Error("[FragmentRendererInner] No ModulesMapProvider in tree");const v=Ee(c,d.read,m),w=o.useMemo(()=>Ve(n,m),[n,m]),g={...e??{},...v},O=u.length>0?u.map(E.toScopeClassName).join(" "):void 0;return l.jsxs(l.Fragment,{children:[t!=null&&l.jsx($,{href:t,fragmentKey:E.AREA_GLOBAL_CSS_KEY}),u.map(y=>{const P=E.resolveStylesHref(y);return P?l.jsx($,{href:P,fragmentKey:E.fragmentCssKey(y)},y):null}),l.jsx(re.Provider,{value:h,children:l.jsx(ee.Provider,{value:s,children:l.jsx(k.Provider,{value:w,children:l.jsx(D.Provider,{value:null,children:l.jsx("div",{className:O,style:{display:"contents"},children:l.jsx(a,{...g})})})})})})]})},pe=({onError:r,...e})=>l.jsx(o.Suspense,{fallback:null,children:l.jsx(me,{onError:r,children:l.jsx(ye,{...e})})}),L=o.createContext(null);L.displayName="AreaExposureContext";const Ge=1e3,Ke=Array.from({length:101},(r,e)=>e/100);function Ye({visibleArea:r,totalArea:e,visibleHeight:t,viewportHeight:n}){if(r<=0)return!1;const u=e>0&&r>=.5*e,c=n>0&&t>=.5*n;return u||c}function Se(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{const e=Math.random()*16|0;return(r==="x"?e:e&3|8).toString(16)})}function xe(r){const e=r.getBoundingClientRect();return e.width>0&&e.height>0}function qe(r){const e=[];function t(n,u){var c;for(const s of Array.from(n.children)){let h="";try{h=window.getComputedStyle(s).display}catch{h=((c=s.style)==null?void 0:c.display)||""}if(h==="contents")t(s,u);else if(h==="none"||xe(s))u.push(s);else{const a=[];t(s,a),a.some(xe)?u.push(...a):u.push(s)}}}return t(r,e),e}const Je=({experiment:r,emit:e,children:t})=>{const[n,u]=o.useState(Se),c=o.useRef(!1),s=o.useRef(null),h=o.useRef(new Set),a=o.useRef(null),d=o.useRef(r);d.current=r;const m=o.useRef(e);m.current=e;const v=o.useRef(n);v.current=n;const w=o.useCallback(()=>{c.current||(c.current=!0,s.current&&(clearTimeout(s.current),s.current=null),m.current({type:"impression",experiment:d.current,viewId:v.current}))},[]),g=o.useMemo(()=>({experiment:r,viewId:n,emit:e,reachedGoals:h.current,ensureImpression:w}),[r,n,e,w]);return o.useEffect(()=>{if(typeof window>"u"||typeof IntersectionObserver>"u")return;const O=a.current;if(!O)return;let y=[];const P=new Map,f=()=>!(typeof document>"u"||"visibilityState"in document&&document.visibilityState==="hidden"||"prerendering"in document&&document.prerendering),x=()=>{if(c.current||y.length===0)return;let A=0,S=0,B=!1,M=1/0,N=-1/0;for(const te of y){const b=P.get(te);b&&(A+=b.interArea,S+=b.boundArea,b.interArea>0&&b.interBottom>b.interTop&&(B=!0,b.interTop<M&&(M=b.interTop),b.interBottom>N&&(N=b.interBottom)))}const Y=B?Math.max(0,N-M):0,q=typeof window<"u"?window.innerHeight:0;f()&&Ye({visibleArea:A,totalArea:S,visibleHeight:Y,viewportHeight:q})?s.current||(s.current=setTimeout(()=>{s.current=null,w()},Ge)):s.current&&(clearTimeout(s.current),s.current=null)},p=new IntersectionObserver(A=>{var S,B,M,N,Y,q;for(const _ of A){const te=((S=_.boundingClientRect)==null?void 0:S.width)??0,b=((B=_.boundingClientRect)==null?void 0:B.height)??0,tr=((M=_.intersectionRect)==null?void 0:M.width)??0,nr=((N=_.intersectionRect)==null?void 0:N.height)??0,Me=te*b,or=tr*nr,sr=((Y=_.intersectionRect)==null?void 0:Y.top)??0,ur=((q=_.intersectionRect)==null?void 0:q.bottom)??0;P.set(_.target,{interArea:Me>0?or:0,boundArea:Me,interTop:sr,interBottom:ur})}c.current||x()},{threshold:Ke}),F=()=>{if(c.current||!a.current)return;const A=qe(a.current);for(const S of y)A.includes(S)||(p.unobserve(S),P.delete(S));for(const S of A)y.includes(S)||p.observe(S);y=A};F();let C=null;typeof MutationObserver<"u"&&(C=new MutationObserver(()=>{c.current||F()}),C.observe(O,{childList:!0,subtree:!0}));const I=()=>{typeof document<"u"&&document.visibilityState==="hidden"?s.current&&(clearTimeout(s.current),s.current=null):x()},K=()=>{x()},_e=()=>{s.current&&(clearTimeout(s.current),s.current=null)},je=()=>{x()},Ie=A=>{if(A.persisted){s.current&&(clearTimeout(s.current),s.current=null),c.current=!1;const S=Se();v.current=S,u(S),x()}};return typeof document<"u"&&(document.addEventListener("visibilitychange",I),document.addEventListener("prerenderingchange",K)),typeof window<"u"&&(window.addEventListener("pagehide",_e),window.addEventListener("resize",je),window.addEventListener("pageshow",Ie)),()=>{s.current&&(clearTimeout(s.current),s.current=null),p.disconnect(),C&&C.disconnect(),typeof document<"u"&&(document.removeEventListener("visibilitychange",I),document.removeEventListener("prerenderingchange",K)),typeof window<"u"&&(window.removeEventListener("pagehide",_e),window.removeEventListener("resize",je),window.removeEventListener("pageshow",Ie))}},[r,e]),l.jsx(L.Provider,{value:g,children:l.jsx("div",{ref:a,style:{display:"contents"},children:t})})},We=({areaCode:r,options:e,retry:t})=>{const n=Z(r,{suspense:!1,ssr:!1,pause:e==null?void 0:e.pause,timeout:e==null?void 0:e.timeout}),u=o.useContext(z),c=o.useContext(T),s=o.useRef(null);if(o.useEffect(()=>{var C;if(n.status!=="not-found"||!n.error)return;const p=le(n.error),F=JSON.stringify([r,p.kind,p.code,p.error.message]);s.current!==F&&(s.current=F,(C=e==null?void 0:e.onError)==null||C.call(e,p.error),process.env.NODE_ENV!=="production"&&p.kind!=="no-variant"&&console.error(`[fragments] Area resolution ${p.kind}: areaCode=${r}, code=${p.code??"none"}`,p.error))},[r,e==null?void 0:e.onError,n.error,n.status]),(e==null?void 0:e.pause)===!0)return null;if(n.status==="idle")return(e==null?void 0:e.fallback)??null;if(n.status==="not-found")return de(e==null?void 0:e.empty,le(n.error),t);if(n.status==="loading"||!n.data)return(e==null?void 0:e.fallback)??null;const{rootFragmentId:h,props:a,projectProperties:d,globalCssUrl:m,fragments:v,slots:w,sources:g,projectBindings:O}=n.data,y=he(a,O??ge,u),P=typeof(e==null?void 0:e.props)=="function"?e.props(y):e!=null&&e.props?{...y,...e.props}:y,f=n.data.experiment,x=l.jsx(ye,{fragmentId:h,props:P,globalCssUrl:m,projectProperties:d,fragments:v,slots:w,sources:g});return l.jsx(o.Suspense,{fallback:(e==null?void 0:e.fallback)??null,children:f&&(c!=null&&c.$events)?l.jsx(Je,{experiment:f,emit:c.$events.emit,children:x},`${f.label}:${f.variantId}`):x})},Pe=({areaCode:r,options:e})=>{const t=o.useContext(T),[n,u]=o.useState(0),c=t==null?void 0:t.$area;o.useEffect(()=>{(e==null?void 0:e.ssr)!==!0||process.env.NODE_ENV==="production"||console.error("[fragments] Area option `ssr` is reserved: server resolution has been removed from the runtime; existing `ssr: false` calls continue to work unchanged.")},[e==null?void 0:e.ssr]);const s=o.useCallback(()=>{c!=null&&c.resolve&&(c.resolve(r).catch(()=>{}),u(h=>h+1))},[c,r]);return l.jsx(me,{onError:e==null?void 0:e.onError,empty:e==null?void 0:e.empty,retry:s,children:l.jsx(We,{areaCode:r,options:e,retry:s})},n)};function Xe(){const r=globalThis,e=r.__FRAGMENTS_DEPS__??(r.__FRAGMENTS_DEPS__={});e.react=oe,e["react/jsx-runtime"]=Ne,e["@fragmentsx/runtime-react"]=ke}function Qe(r){const e=r??ae,t=o.useRef(e);return $e(t.current,e)||(t.current=e),t.current}function be({client:r,children:e,properties:t}){Xe();const n=o.useMemo(()=>({read:c=>r.$fragments.read(c)}),[r]),u=Qe(t);return l.jsx(J,{value:r,children:l.jsx(W,{value:n,children:l.jsx(z.Provider,{value:u,children:e})})})}function we(r){return(o.useContext(k)??G)[r]}function Ce(r){const e=o.useContext(L);return o.useCallback(()=>{e&&(e.reachedGoals.has(r)||(e.reachedGoals.add(r),e.ensureImpression(),e.emit({type:"goal",experiment:e.experiment,viewId:e.viewId,goalKey:r})))},[e,r])}function Ze(r,e){const[,t]=o.useReducer(c=>c+1,0),n=e(),u=o.useRef(n);return u.current=n,o.useEffect(()=>{const c=r(t);return Object.is(u.current,e())||t(),c},[r,e]),n}const Ae=oe.useSyncExternalStore,Re=Ae||((r,e)=>Ze(r,e)),Oe="offline",er=()=>Promise.reject(new Error(Oe));function rr(r,e){var F,C;const t=Le(),[n]=o.useState(E.createSourceCache),u=(t==null?void 0:t.sourceCache)??n,c=(F=t==null?void 0:t.sourceFetchers)==null?void 0:F[r],s=(C=t==null?void 0:t.sourceBaseUrls)==null?void 0:C[r],h=c?"host-fetch":"network",a=t==null?void 0:t.env,d=E.sourceCallKey({source:r,target:e.target,params:e.params}),m=o.useMemo(()=>({source:r,target:e.target,params:e.params}),[d]),v=o.useCallback(I=>u.subscribe(m,I),[u,m]),w=o.useCallback(()=>u.get(m),[u,m]),g=Re(v,w,w),O=o.useContext(re),y=o.useContext(ee),P=E.sourceTransportKey(r,e.target),f=o.useMemo(()=>O===Oe?null:E.resolveSourceRequest(y[P],m.params,s),[O,y,P,m,s]),[x,p]=o.useState(null);return o.useEffect(()=>{(g==null?void 0:g.status)==="ready"&&x!==null&&p(null)},[g,x]),o.useEffect(()=>{f&&!f.ok&&g===void 0&&console.warn(`[useSource] ${P}: ${f.reason}`)},[P,f==null?void 0:f.ok,f&&!f.ok?f.reason:void 0,g===void 0]),o.useEffect(()=>{if(f&&!f.ok||(g==null?void 0:g.status)==="ready"||x===d)return;p(d);const I=f&&f.ok?()=>E.runSourceFetch({url:f.url,init:f.init},{fetcher:c,timeout:a==null?void 0:a.timeout}).then(K=>(a!=null&&a.debug&&console.info(`[useSource] loaded ${E.sourceCallKey(m)} origin=${h}`),K)):er;u.load(m,I,h)},[u,m,d,g,x,f,c,h,a==null?void 0:a.timeout,a==null?void 0:a.debug]),(g==null?void 0:g.status)==="ready"?{data:g.data??void 0,loading:!1}:(g==null?void 0:g.status)==="pending"?{data:void 0,loading:!0}:f&&!f.ok?{data:void 0,loading:!1}:{data:void 0,loading:x!==d}}const Te=rr;function Fe(r){return E.createFragmentsClient({...r,inject:V})}Object.defineProperty(i,"FragmentsApiVersionError",{enumerable:!0,get:()=>E.FragmentsApiVersionError}),Object.defineProperty(i,"FragmentsAreaError",{enumerable:!0,get:()=>E.FragmentsAreaError}),Object.defineProperty(i,"FragmentsLoadError",{enumerable:!0,get:()=>E.FragmentsLoadError}),Object.defineProperty(i,"createSourceCache",{enumerable:!0,get:()=>E.createSourceCache}),i.AREA_UNRESOLVED=H,i.Area=Pe,i.AreaExposureContext=L,i.FragmentRenderer=pe,i.FragmentStylesheet=$,i.FragmentsClientContext=T,i.FragmentsClientProvider=J,i.FragmentsProvider=be,i.InstanceIdContext=D,i.ModulesMapContext=j,i.ModulesMapProvider=W,i.ProjectPropertiesContext=k,i.createBrowserClient=Fe,i.defaultProjectProperties=G,i.injectStylesheet=V,i.useArea=Z,i.useCssChunk=ce,i.useFragmentComponent=X,i.useFragmentStylesheet=R,i.useGoal=Ce,i.useProjectProperty=we,i.useSource=Te,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fragmentsx/runtime-react",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.2.0-dev-
|
|
4
|
+
"version": "0.2.0-dev-20261025103802",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@graph-state/core": "^0.13.3",
|
|
35
|
-
"@fragmentsx/fragments-client": "0.2.0-dev-
|
|
35
|
+
"@fragmentsx/fragments-client": "0.2.0-dev-20261025103802"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@testing-library/jest-dom": "^6.6.3",
|