@fragmentsx/runtime-react 0.2.0-dev-20260831061037 → 0.2.0-dev-20260901074721

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.d.ts CHANGED
@@ -169,9 +169,10 @@ declare interface FragmentStylesheetProps {
169
169
  *
170
170
  * @param href - CDN URL стилевого файла
171
171
  * @param key - уникальный ключ для dedup (например `chunk:201` или `fragment:42:abc`)
172
- * @returns cleanup callback — при refCount = 0 удаляет `<link>` из head
172
+ * @returns handle — вызываемый cleanup (при refCount = 0 удаляет `<link>` из
173
+ * head) с дополнительным свойством `loaded: Promise<void>`
173
174
  */
174
- export declare const injectStylesheet: (href: string, key: string) => (() => void);
175
+ export declare const injectStylesheet: (href: string, key: string) => StylesheetHandle;
175
176
 
176
177
  export declare const InstanceIdContext: Context<string | null>;
177
178
 
@@ -226,6 +227,40 @@ export declare interface ReachGoalInfo {
226
227
  campaignId?: number;
227
228
  }
228
229
 
230
+ /**
231
+ * Ref-counted `<link rel="stylesheet">` injector для compiled fragment CSS delivery (Req #11).
232
+ *
233
+ * **Single source of truth для ref-count dedup**: $cssChunks (client-core) делегирует
234
+ * DOM injection сюда через factory parameter (BLOCKER-4 architectural decision).
235
+ * Module-level registry гарантирует что за один bundle-scope один key = один <link>.
236
+ *
237
+ * Использование:
238
+ * ```ts
239
+ * const handle = injectStylesheet('https://cdn.example.com/chunk.css', 'chunk:201');
240
+ * await handle.loaded; // готовность CSS (load / error / таймаут — quick-260831-etq)
241
+ * // ... позже при unmount:
242
+ * handle();
243
+ * ```
244
+ *
245
+ * Ref-count semantics:
246
+ * - Первый вызов с key → создаёт `<link>`, refCount = 1
247
+ * - Повторный вызов с тем же key → refCount++, новый `<link>` НЕ создаётся
248
+ * - Cleanup → refCount--; при refCount = 0 → `<link>` удаляется из head
249
+ *
250
+ * Канал готовности (quick-260831-etq, D-5/D-6): возвращаемый handle несёт
251
+ * `loaded: Promise<void>`, который резолвится по `load`, по `error` (сбой
252
+ * трактуется как «готово» — показать без стилей лучше, чем зависнуть) или по
253
+ * истечении `STYLESHEET_READY_TIMEOUT_MS`, если ни одно событие не пришло
254
+ * (недоступный/молчащий CDN). Промис никогда не отвергается.
255
+ *
256
+ * SSR safety: в Node (isBrowser === false) возвращает свежий noop-handle с уже
257
+ * разрешённым `loaded` — общий экспорт `noop` не мутируется.
258
+ */
259
+ /** Канал готовности CSS у ref-counted injectStylesheet handle. */
260
+ declare type StylesheetHandle = (() => void) & {
261
+ loaded: Promise<void>;
262
+ };
263
+
229
264
  /** Suspense-режим (по умолчанию либо явный `suspense: true`) — прежний throw-протокол. */
230
265
  export declare function useArea(areaCode: string, options?: UseAreaOptions & {
231
266
  suspense?: true;
@@ -259,6 +294,14 @@ export declare interface UseAreaOptions {
259
294
  */
260
295
  export declare interface UseAreaResult {
261
296
  rootFragmentId: number;
297
+ /**
298
+ * Quick 260831-dor (INT-10): id выбранного варианта — вход для атрибуции
299
+ * на стороне площадки-потребителя (префикс партнёрской ссылки трекера).
300
+ * `$area` уже нормализует отсутствие поля у backend'а в `null` (не `0` —
301
+ * `0` неотличим от настоящего id и молча испортил бы атрибуцию), поэтому
302
+ * поле обязательное и nullable, а не опциональное.
303
+ */
304
+ variantId: number | null;
262
305
  /**
263
306
  * Phase 73, B-02/B-06: значения props корневого артефакта, разрешённые сервером
264
307
  * (`resolveVariantProps`) — привязки `$ref` сюда не доезжают, только готовые значения.
package/dist/index.es.js CHANGED
@@ -1,32 +1,32 @@
1
- import { jsx as u, jsxs as N, Fragment as k } from "react/jsx-runtime";
2
- import { createContext as m, useContext as f, useMemo as C, useState as I, useEffect as P, useLayoutEffect as R, version as b, Component as p, Suspense as y } from "react";
3
- import { createFragmentsClient as _ } from "@fragmentsx/fragments-client";
4
- import { FragmentsApiVersionError as le, FragmentsAreaError as se, FragmentsLoadError as ae } from "@fragmentsx/fragments-client";
5
- const o = m(
1
+ import { jsx as l, jsxs as j, Fragment as I } from "react/jsx-runtime";
2
+ import { createContext as v, useContext as f, useMemo as P, useState as L, useEffect as F, useLayoutEffect as N, version as k, Component as b, Suspense as A } from "react";
3
+ import { AREA_GLOBAL_CSS_KEY as p, fragmentCssKey as O, fragmentFontsKey as U, createFragmentsClient as B } from "@fragmentsx/fragments-client";
4
+ import { FragmentsApiVersionError as oe, FragmentsAreaError as ie, FragmentsLoadError as fe } from "@fragmentsx/fragments-client";
5
+ const m = v(
6
6
  null
7
7
  );
8
- o.displayName = "FragmentsClientContext";
9
- function U(r) {
10
- return /* @__PURE__ */ u(o.Provider, { value: r.value, children: r.children });
8
+ m.displayName = "FragmentsClientContext";
9
+ function D(r) {
10
+ return /* @__PURE__ */ l(m.Provider, { value: r.value, children: r.children });
11
11
  }
12
- function L() {
13
- return f(o);
12
+ function K() {
13
+ return f(m);
14
14
  }
15
- const F = m(null);
16
- F.displayName = "InstanceIdContext";
17
- const v = m(
15
+ const S = v(null);
16
+ S.displayName = "InstanceIdContext";
17
+ const g = v(
18
18
  null
19
19
  );
20
- v.displayName = "ModulesMapContext";
21
- function O({
20
+ g.displayName = "ModulesMapContext";
21
+ function V({
22
22
  value: r,
23
23
  children: e
24
24
  }) {
25
- return /* @__PURE__ */ u(v.Provider, { value: r, children: e });
25
+ return /* @__PURE__ */ l(g.Provider, { value: r, children: e });
26
26
  }
27
- function W() {
28
- const r = f(o);
29
- return C(
27
+ function re() {
28
+ const r = f(m);
29
+ return P(
30
30
  () => ({
31
31
  reachGoal: (e) => {
32
32
  var n, t;
@@ -36,36 +36,39 @@ function W() {
36
36
  [r]
37
37
  );
38
38
  }
39
- function B(r) {
40
- const e = f(v);
39
+ function G(r) {
40
+ const e = f(g);
41
41
  if (!e)
42
42
  throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");
43
43
  return e.read(r);
44
44
  }
45
- const D = typeof window < "u", x = Object.freeze({
45
+ const Y = typeof window < "u", x = Object.freeze({
46
46
  rootFragmentId: 0,
47
+ variantId: null,
47
48
  props: {},
48
49
  projectProperties: {},
49
50
  globalCssUrl: null
50
51
  });
51
- function V(r, e) {
52
- const n = f(o);
52
+ function $(r, e) {
53
+ const n = f(m);
53
54
  if (!n)
54
55
  throw new Error("[useArea] No FragmentsClientProvider in tree");
55
56
  const t = n.$area;
56
57
  if (!(t != null && t.read))
57
58
  throw new Error("[useArea] $area plugin not mounted");
58
- const l = (e == null ? void 0 : e.suspense) ?? !0, d = (e == null ? void 0 : e.pause) === !0 || !D && (e == null ? void 0 : e.ssr) === !1, s = (e == null ? void 0 : e.timeout) != null ? { timeout: e.timeout } : void 0, [, a] = I(0);
59
- if (P(() => {
60
- if (l || d) return;
59
+ const s = (e == null ? void 0 : e.suspense) ?? !0, d = (e == null ? void 0 : e.pause) === !0 || !Y && (e == null ? void 0 : e.ssr) === !1, a = (e == null ? void 0 : e.timeout) != null ? { timeout: e.timeout } : void 0, [, u] = L(0);
60
+ if (F(() => {
61
+ if (s || d) return;
61
62
  let c = !0;
62
- return t.resolve(r, s).finally(() => {
63
- c && a((h) => h + 1);
63
+ return Promise.resolve(t.resolve(r, a)).catch(() => {
64
+ }).finally(() => {
65
+ c && u((o) => o + 1);
64
66
  }), () => {
65
67
  c = !1;
66
68
  };
67
- }, [r, l, e == null ? void 0 : e.pause, e == null ? void 0 : e.timeout, e == null ? void 0 : e.ssr]), l)
68
- return d ? x : (t.has(r) || t.resolve(r, s), t.read(r));
69
+ }, [r, s, e == null ? void 0 : e.pause, e == null ? void 0 : e.timeout, e == null ? void 0 : e.ssr]), s)
70
+ return d ? x : (t.has(r) || Promise.resolve(t.resolve(r, a)).catch(() => {
71
+ }), t.read(r));
69
72
  if (d)
70
73
  return { status: "idle", data: null, error: null };
71
74
  if (t.has(r))
@@ -78,30 +81,45 @@ function V(r, e) {
78
81
  error: c instanceof Error ? c : new Error(String(c))
79
82
  };
80
83
  }
81
- return t.resolve(r, s), { status: "loading", data: null, error: null };
84
+ return Promise.resolve(t.resolve(r, a)).catch(() => {
85
+ }), { status: "loading", data: null, error: null };
82
86
  }
83
- const w = typeof window < "u", $ = () => {
84
- }, i = /* @__PURE__ */ new Map(), A = (r, e) => {
85
- if (!w)
86
- return $;
87
- const n = i.get(e);
88
- if (n)
89
- return n.refCount += 1, () => {
90
- n.refCount -= 1, n.refCount === 0 && (n.linkEl.remove(), i.delete(e));
87
+ const w = typeof window < "u", z = 3e3, h = /* @__PURE__ */ new Map(), M = (r, e) => {
88
+ if (!w) {
89
+ const i = () => {
91
90
  };
91
+ return i.loaded = Promise.resolve(), i;
92
+ }
93
+ const n = h.get(e);
94
+ if (n) {
95
+ n.refCount += 1;
96
+ const i = () => {
97
+ n.refCount -= 1, n.refCount === 0 && (n.clearReadyTimer(), n.linkEl.remove(), h.delete(e));
98
+ };
99
+ return i.loaded = n.loaded, i;
100
+ }
92
101
  const t = document.createElement("link");
93
- t.rel = "stylesheet", t.href = r, t.setAttribute("data-fragment-key", e), document.head.appendChild(t);
94
- const l = { refCount: 1, linkEl: t };
95
- return i.set(e, l), () => {
96
- l.refCount -= 1, l.refCount === 0 && (l.linkEl.remove(), i.delete(e));
102
+ t.rel = "stylesheet", t.href = r, t.setAttribute("data-fragment-key", e);
103
+ let s;
104
+ const d = new Promise((i) => {
105
+ s = i;
106
+ }), a = () => {
107
+ c(), s();
108
+ }, u = setTimeout(a, z), c = () => clearTimeout(u);
109
+ t.addEventListener("load", a), t.addEventListener("error", a), document.head.appendChild(t);
110
+ const o = { refCount: 1, linkEl: t, loaded: d, clearReadyTimer: c };
111
+ h.set(e, o);
112
+ const y = () => {
113
+ o.refCount -= 1, o.refCount === 0 && (o.clearReadyTimer(), o.linkEl.remove(), h.delete(e));
97
114
  };
98
- }, T = w ? R : P;
99
- function G(r, e) {
100
- T(() => A(r, e), [r, e]);
115
+ return y.loaded = d, y;
116
+ }, H = w ? N : F;
117
+ function J(r, e) {
118
+ H(() => M(r, e), [r, e]);
101
119
  }
102
- const K = parseInt(b.split(".")[0], 10), z = K >= 19;
103
- function g({ href: r, fragmentKey: e }) {
104
- return z ? /* @__PURE__ */ u(
120
+ const q = parseInt(k.split(".")[0], 10), Q = q >= 19;
121
+ function E({ href: r, fragmentKey: e }) {
122
+ return Q ? /* @__PURE__ */ l(
105
123
  "link",
106
124
  {
107
125
  rel: "stylesheet",
@@ -109,13 +127,13 @@ function g({ href: r, fragmentKey: e }) {
109
127
  precedence: "default",
110
128
  "data-fragment-key": e
111
129
  }
112
- ) : (G(r, e), null);
130
+ ) : (J(r, e), null);
113
131
  }
114
- function X(r) {
132
+ function te(r) {
115
133
  }
116
- const M = {}, E = m(null);
117
- E.displayName = "ProjectPropertiesContext";
118
- class S extends p {
134
+ const R = {}, C = v(null);
135
+ C.displayName = "ProjectPropertiesContext";
136
+ class T extends b {
119
137
  constructor() {
120
138
  super(...arguments), this.state = { hasError: !1 };
121
139
  }
@@ -123,108 +141,108 @@ class S extends p {
123
141
  return { hasError: !0 };
124
142
  }
125
143
  componentDidCatch(e, n) {
126
- var t, l;
127
- process.env.NODE_ENV !== "production" && console.error("[fragments] Area error:", e, n.componentStack), (l = (t = this.props).onError) == null || l.call(t, e);
144
+ var t, s;
145
+ process.env.NODE_ENV !== "production" && console.error("[fragments] Area error:", e, n.componentStack), (s = (t = this.props).onError) == null || s.call(t, e);
128
146
  }
129
147
  render() {
130
148
  return this.state.hasError ? null : this.props.children;
131
149
  }
132
150
  }
133
- const j = ({
151
+ const _ = ({
134
152
  fragmentId: r,
135
153
  props: e,
136
154
  globalCssUrl: n = null,
137
- projectProperties: t = M
155
+ projectProperties: t = R
138
156
  }) => {
139
- const l = B(r), s = L().$fragments, a = s == null ? void 0 : s.getRef(r), c = s == null ? void 0 : s.getScopeClass(r), h = e ?? {};
140
- return /* @__PURE__ */ N(k, { children: [
141
- n != null && /* @__PURE__ */ u(
142
- g,
157
+ const s = G(r), a = K().$fragments, u = a == null ? void 0 : a.getRef(r), c = a == null ? void 0 : a.getScopeClass(r), o = e ?? {};
158
+ return /* @__PURE__ */ j(I, { children: [
159
+ n != null && /* @__PURE__ */ l(
160
+ E,
143
161
  {
144
162
  href: n,
145
- fragmentKey: "global"
163
+ fragmentKey: p
146
164
  }
147
165
  ),
148
- a && /* @__PURE__ */ u(
149
- g,
166
+ u && /* @__PURE__ */ l(
167
+ E,
150
168
  {
151
- href: a.cssUrl,
152
- fragmentKey: `fragment:${r}:css`
169
+ href: u.cssUrl,
170
+ fragmentKey: O(r)
153
171
  }
154
172
  ),
155
- (a == null ? void 0 : a.fontsUrl) != null && /* @__PURE__ */ u(
156
- g,
173
+ (u == null ? void 0 : u.fontsUrl) != null && /* @__PURE__ */ l(
174
+ E,
157
175
  {
158
- href: a.fontsUrl,
159
- fragmentKey: `fragment:${r}:fonts`
176
+ href: u.fontsUrl,
177
+ fragmentKey: U(r)
160
178
  }
161
179
  ),
162
- /* @__PURE__ */ u(E.Provider, { value: t, children: /* @__PURE__ */ u(F.Provider, { value: null, children: /* @__PURE__ */ u(
180
+ /* @__PURE__ */ l(C.Provider, { value: t, children: /* @__PURE__ */ l(S.Provider, { value: null, children: /* @__PURE__ */ l(
163
181
  "div",
164
182
  {
165
183
  className: c,
166
184
  style: { display: "contents" },
167
- children: /* @__PURE__ */ u(l, { ...h })
185
+ children: /* @__PURE__ */ l(s, { ...o })
168
186
  }
169
187
  ) }) })
170
188
  ] });
171
- }, Y = ({ onError: r, ...e }) => /* @__PURE__ */ u(y, { fallback: null, children: /* @__PURE__ */ u(S, { onError: r, children: /* @__PURE__ */ u(j, { ...e }) }) }), J = ({ areaCode: r, options: e }) => {
189
+ }, ne = ({ onError: r, ...e }) => /* @__PURE__ */ l(A, { fallback: null, children: /* @__PURE__ */ l(T, { onError: r, children: /* @__PURE__ */ l(_, { ...e }) }) }), W = ({ areaCode: r, options: e }) => {
172
190
  if ((e == null ? void 0 : e.pause) === !0)
173
191
  return null;
174
- const n = V(r, {
192
+ const n = $(r, {
175
193
  timeout: e == null ? void 0 : e.timeout,
176
194
  ssr: e == null ? void 0 : e.ssr
177
195
  });
178
196
  if (n === x)
179
197
  return null;
180
- const { rootFragmentId: t, props: l, projectProperties: d, globalCssUrl: s } = n, a = typeof (e == null ? void 0 : e.props) == "function" ? e.props(l) : e != null && e.props ? { ...l, ...e.props } : l;
181
- return /* @__PURE__ */ u(
182
- j,
198
+ const { rootFragmentId: t, props: s, projectProperties: d, globalCssUrl: a } = n, u = typeof (e == null ? void 0 : e.props) == "function" ? e.props(s) : e != null && e.props ? { ...s, ...e.props } : s;
199
+ return /* @__PURE__ */ l(
200
+ _,
183
201
  {
184
202
  fragmentId: t,
185
- props: a,
186
- globalCssUrl: s,
203
+ props: u,
204
+ globalCssUrl: a,
187
205
  projectProperties: d
188
206
  }
189
207
  );
190
- }, Z = ({ areaCode: r, options: e }) => /* @__PURE__ */ u(y, { fallback: (e == null ? void 0 : e.fallback) ?? null, children: /* @__PURE__ */ u(S, { onError: e == null ? void 0 : e.onError, children: /* @__PURE__ */ u(J, { areaCode: r, options: e }) }) });
191
- function ee({ client: r, children: e }) {
192
- const n = C(
208
+ }, le = ({ areaCode: r, options: e }) => /* @__PURE__ */ l(A, { fallback: (e == null ? void 0 : e.fallback) ?? null, children: /* @__PURE__ */ l(T, { onError: e == null ? void 0 : e.onError, children: /* @__PURE__ */ l(W, { areaCode: r, options: e }) }) });
209
+ function ae({ client: r, children: e }) {
210
+ const n = P(
193
211
  () => ({
194
212
  read: (t) => r.$fragments.read(t)
195
213
  }),
196
214
  [r]
197
215
  );
198
- return /* @__PURE__ */ u(U, { value: r, children: /* @__PURE__ */ u(O, { value: n, children: e }) });
216
+ return /* @__PURE__ */ l(D, { value: r, children: /* @__PURE__ */ l(V, { value: n, children: e }) });
199
217
  }
200
- function re(r) {
201
- return (f(E) ?? M)[r];
218
+ function se(r) {
219
+ return (f(C) ?? R)[r];
202
220
  }
203
- function te(r) {
204
- return _({ ...r, inject: A });
221
+ function ue(r) {
222
+ return B({ ...r, inject: M });
205
223
  }
206
224
  export {
207
225
  x as AREA_UNRESOLVED,
208
- Z as Area,
209
- Y as FragmentRenderer,
210
- g as FragmentStylesheet,
211
- le as FragmentsApiVersionError,
212
- se as FragmentsAreaError,
213
- o as FragmentsClientContext,
214
- U as FragmentsClientProvider,
215
- ae as FragmentsLoadError,
216
- ee as FragmentsProvider,
217
- F as InstanceIdContext,
218
- v as ModulesMapContext,
219
- O as ModulesMapProvider,
220
- E as ProjectPropertiesContext,
221
- te as createBrowserClient,
222
- M as defaultProjectProperties,
223
- A as injectStylesheet,
224
- V as useArea,
225
- X as useCssChunk,
226
- B as useFragmentComponent,
227
- W as useFragmentMetrics,
228
- G as useFragmentStylesheet,
229
- re as useProjectProperty
226
+ le as Area,
227
+ ne as FragmentRenderer,
228
+ E as FragmentStylesheet,
229
+ oe as FragmentsApiVersionError,
230
+ ie as FragmentsAreaError,
231
+ m as FragmentsClientContext,
232
+ D as FragmentsClientProvider,
233
+ fe as FragmentsLoadError,
234
+ ae as FragmentsProvider,
235
+ S as InstanceIdContext,
236
+ g as ModulesMapContext,
237
+ V as ModulesMapProvider,
238
+ C as ProjectPropertiesContext,
239
+ ue as createBrowserClient,
240
+ R as defaultProjectProperties,
241
+ M as injectStylesheet,
242
+ $ as useArea,
243
+ te as useCssChunk,
244
+ G as useFragmentComponent,
245
+ re as useFragmentMetrics,
246
+ J as useFragmentStylesheet,
247
+ se as useProjectProperty
230
248
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(t,u){typeof exports=="object"&&typeof module<"u"?u(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"],u):(t=typeof globalThis<"u"?globalThis:t||self,u(t.FragmentsRuntimeReact={},t.jsxRuntime,t.React,t.fragmentsClient))})(this,function(t,u,s,m){"use strict";const o=s.createContext(null);o.displayName="FragmentsClientContext";function j(r){return u.jsx(o.Provider,{value:r.value,children:r.children})}function k(){return s.useContext(o)}const P=s.createContext(null);P.displayName="InstanceIdContext";const g=s.createContext(null);g.displayName="ModulesMapContext";function M({value:r,children:e}){return u.jsx(g.Provider,{value:r,children:e})}function x(){const r=s.useContext(o);return s.useMemo(()=>({reachGoal:e=>{var l,n;(n=(l=r==null?void 0:r.$metrics)==null?void 0:l.reachGoal)==null||n.call(l,e)}}),[r])}function S(r){const e=s.useContext(g);if(!e)throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");return e.read(r)}const _=typeof window<"u",v=Object.freeze({rootFragmentId:0,props:{},projectProperties:{},globalCssUrl:null});function w(r,e){const l=s.useContext(o);if(!l)throw new Error("[useArea] No FragmentsClientProvider in tree");const n=l.$area;if(!(n!=null&&n.read))throw new Error("[useArea] $area plugin not mounted");const a=(e==null?void 0:e.suspense)??!0,i=(e==null?void 0:e.pause)===!0||!_&&(e==null?void 0:e.ssr)===!1,c=(e==null?void 0:e.timeout)!=null?{timeout:e.timeout}:void 0,[,d]=s.useState(0);if(s.useEffect(()=>{if(a||i)return;let f=!0;return n.resolve(r,c).finally(()=>{f&&d(A=>A+1)}),()=>{f=!1}},[r,a,e==null?void 0:e.pause,e==null?void 0:e.timeout,e==null?void 0:e.ssr]),a)return i?v:(n.has(r)||n.resolve(r,c),n.read(r));if(i)return{status:"idle",data:null,error:null};if(n.has(r))try{return{status:"ready",data:n.read(r),error:null}}catch(f){return{status:"not-found",data:null,error:f instanceof Error?f:new Error(String(f))}}return n.resolve(r,c),{status:"loading",data:null,error:null}}const b=typeof window<"u",L=()=>{},h=new Map,F=(r,e)=>{if(!b)return L;const l=h.get(e);if(l)return l.refCount+=1,()=>{l.refCount-=1,l.refCount===0&&(l.linkEl.remove(),h.delete(e))};const n=document.createElement("link");n.rel="stylesheet",n.href=r,n.setAttribute("data-fragment-key",e),document.head.appendChild(n);const a={refCount:1,linkEl:n};return h.set(e,a),()=>{a.refCount-=1,a.refCount===0&&(a.linkEl.remove(),h.delete(e))}},T=b?s.useLayoutEffect:s.useEffect;function I(r,e){T(()=>F(r,e),[r,e])}const U=parseInt(s.version.split(".")[0],10)>=19;function C({href:r,fragmentKey:e}){return U?u.jsx("link",{rel:"stylesheet",href:r,precedence:"default","data-fragment-key":e}):(I(r,e),null)}function V(r){}const y={},E=s.createContext(null);E.displayName="ProjectPropertiesContext";class N extends s.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,l){var n,a;process.env.NODE_ENV!=="production"&&console.error("[fragments] Area error:",e,l.componentStack),(a=(n=this.props).onError)==null||a.call(n,e)}render(){return this.state.hasError?null:this.props.children}}const O=({fragmentId:r,props:e,globalCssUrl:l=null,projectProperties:n=y})=>{const a=S(r),c=k().$fragments,d=c==null?void 0:c.getRef(r),f=c==null?void 0:c.getScopeClass(r),A=e??{};return u.jsxs(u.Fragment,{children:[l!=null&&u.jsx(C,{href:l,fragmentKey:"global"}),d&&u.jsx(C,{href:d.cssUrl,fragmentKey:`fragment:${r}:css`}),(d==null?void 0:d.fontsUrl)!=null&&u.jsx(C,{href:d.fontsUrl,fragmentKey:`fragment:${r}:fonts`}),u.jsx(E.Provider,{value:n,children:u.jsx(P.Provider,{value:null,children:u.jsx("div",{className:f,style:{display:"contents"},children:u.jsx(a,{...A})})})})]})},B=({onError:r,...e})=>u.jsx(s.Suspense,{fallback:null,children:u.jsx(N,{onError:r,children:u.jsx(O,{...e})})}),D=({areaCode:r,options:e})=>{if((e==null?void 0:e.pause)===!0)return null;const l=w(r,{timeout:e==null?void 0:e.timeout,ssr:e==null?void 0:e.ssr});if(l===v)return null;const{rootFragmentId:n,props:a,projectProperties:i,globalCssUrl:c}=l,d=typeof(e==null?void 0:e.props)=="function"?e.props(a):e!=null&&e.props?{...a,...e.props}:a;return u.jsx(O,{fragmentId:n,props:d,globalCssUrl:c,projectProperties:i})},$=({areaCode:r,options:e})=>u.jsx(s.Suspense,{fallback:(e==null?void 0:e.fallback)??null,children:u.jsx(N,{onError:e==null?void 0:e.onError,children:u.jsx(D,{areaCode:r,options:e})})});function q({client:r,children:e}){const l=s.useMemo(()=>({read:n=>r.$fragments.read(n)}),[r]);return u.jsx(j,{value:r,children:u.jsx(M,{value:l,children:e})})}function G(r){return(s.useContext(E)??y)[r]}function J(r){return m.createFragmentsClient({...r,inject:F})}Object.defineProperty(t,"FragmentsApiVersionError",{enumerable:!0,get:()=>m.FragmentsApiVersionError}),Object.defineProperty(t,"FragmentsAreaError",{enumerable:!0,get:()=>m.FragmentsAreaError}),Object.defineProperty(t,"FragmentsLoadError",{enumerable:!0,get:()=>m.FragmentsLoadError}),t.AREA_UNRESOLVED=v,t.Area=$,t.FragmentRenderer=B,t.FragmentStylesheet=C,t.FragmentsClientContext=o,t.FragmentsClientProvider=j,t.FragmentsProvider=q,t.InstanceIdContext=P,t.ModulesMapContext=g,t.ModulesMapProvider=M,t.ProjectPropertiesContext=E,t.createBrowserClient=J,t.defaultProjectProperties=y,t.injectStylesheet=F,t.useArea=w,t.useCssChunk=V,t.useFragmentComponent=S,t.useFragmentMetrics=x,t.useFragmentStylesheet=I,t.useProjectProperty=G,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ (function(t,s){typeof exports=="object"&&typeof module<"u"?s(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"],s):(t=typeof globalThis<"u"?globalThis:t||self,s(t.FragmentsRuntimeReact={},t.jsxRuntime,t.React,t.fragmentsClient))})(this,function(t,s,u,m){"use strict";const g=u.createContext(null);g.displayName="FragmentsClientContext";function M(r){return s.jsx(g.Provider,{value:r.value,children:r.children})}function N(){return u.useContext(g)}const y=u.createContext(null);y.displayName="InstanceIdContext";const E=u.createContext(null);E.displayName="ModulesMapContext";function j({value:r,children:e}){return s.jsx(E.Provider,{value:r,children:e})}function k(){const r=u.useContext(g);return u.useMemo(()=>({reachGoal:e=>{var l,n;(n=(l=r==null?void 0:r.$metrics)==null?void 0:l.reachGoal)==null||n.call(l,e)}}),[r])}function w(r){const e=u.useContext(E);if(!e)throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");return e.read(r)}const x=typeof window<"u",F=Object.freeze({rootFragmentId:0,variantId:null,props:{},projectProperties:{},globalCssUrl:null});function T(r,e){const l=u.useContext(g);if(!l)throw new Error("[useArea] No FragmentsClientProvider in tree");const n=l.$area;if(!(n!=null&&n.read))throw new Error("[useArea] $area plugin not mounted");const c=(e==null?void 0:e.suspense)??!0,i=(e==null?void 0:e.pause)===!0||!x&&(e==null?void 0:e.ssr)===!1,a=(e==null?void 0:e.timeout)!=null?{timeout:e.timeout}:void 0,[,d]=u.useState(0);if(u.useEffect(()=>{if(c||i)return;let o=!0;return Promise.resolve(n.resolve(r,a)).catch(()=>{}).finally(()=>{o&&d(f=>f+1)}),()=>{o=!1}},[r,c,e==null?void 0:e.pause,e==null?void 0:e.timeout,e==null?void 0:e.ssr]),c)return i?F:(n.has(r)||Promise.resolve(n.resolve(r,a)).catch(()=>{}),n.read(r));if(i)return{status:"idle",data:null,error:null};if(n.has(r))try{return{status:"ready",data:n.read(r),error:null}}catch(o){return{status:"not-found",data:null,error:o instanceof Error?o:new Error(String(o))}}return Promise.resolve(n.resolve(r,a)).catch(()=>{}),{status:"loading",data:null,error:null}}const _=typeof window<"u",U=3e3,v=new Map,A=(r,e)=>{if(!_){const h=()=>{};return h.loaded=Promise.resolve(),h}const l=v.get(e);if(l){l.refCount+=1;const h=()=>{l.refCount-=1,l.refCount===0&&(l.clearReadyTimer(),l.linkEl.remove(),v.delete(e))};return h.loaded=l.loaded,h}const n=document.createElement("link");n.rel="stylesheet",n.href=r,n.setAttribute("data-fragment-key",e);let c;const i=new Promise(h=>{c=h}),a=()=>{o(),c()},d=setTimeout(a,U),o=()=>clearTimeout(d);n.addEventListener("load",a),n.addEventListener("error",a),document.head.appendChild(n);const f={refCount:1,linkEl:n,loaded:i,clearReadyTimer:o};v.set(e,f);const O=()=>{f.refCount-=1,f.refCount===0&&(f.clearReadyTimer(),f.linkEl.remove(),v.delete(e))};return O.loaded=i,O},B=_?u.useLayoutEffect:u.useEffect;function b(r,e){B(()=>A(r,e),[r,e])}const D=parseInt(u.version.split(".")[0],10)>=19;function C({href:r,fragmentKey:e}){return D?s.jsx("link",{rel:"stylesheet",href:r,precedence:"default","data-fragment-key":e}):(b(r,e),null)}function V(r){}const S={},P=u.createContext(null);P.displayName="ProjectPropertiesContext";class I extends u.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,l){var n,c;process.env.NODE_ENV!=="production"&&console.error("[fragments] Area error:",e,l.componentStack),(c=(n=this.props).onError)==null||c.call(n,e)}render(){return this.state.hasError?null:this.props.children}}const L=({fragmentId:r,props:e,globalCssUrl:l=null,projectProperties:n=S})=>{const c=w(r),a=N().$fragments,d=a==null?void 0:a.getRef(r),o=a==null?void 0:a.getScopeClass(r),f=e??{};return s.jsxs(s.Fragment,{children:[l!=null&&s.jsx(C,{href:l,fragmentKey:m.AREA_GLOBAL_CSS_KEY}),d&&s.jsx(C,{href:d.cssUrl,fragmentKey:m.fragmentCssKey(r)}),(d==null?void 0:d.fontsUrl)!=null&&s.jsx(C,{href:d.fontsUrl,fragmentKey:m.fragmentFontsKey(r)}),s.jsx(P.Provider,{value:n,children:s.jsx(y.Provider,{value:null,children:s.jsx("div",{className:o,style:{display:"contents"},children:s.jsx(c,{...f})})})})]})},K=({onError:r,...e})=>s.jsx(u.Suspense,{fallback:null,children:s.jsx(I,{onError:r,children:s.jsx(L,{...e})})}),q=({areaCode:r,options:e})=>{if((e==null?void 0:e.pause)===!0)return null;const l=T(r,{timeout:e==null?void 0:e.timeout,ssr:e==null?void 0:e.ssr});if(l===F)return null;const{rootFragmentId:n,props:c,projectProperties:i,globalCssUrl:a}=l,d=typeof(e==null?void 0:e.props)=="function"?e.props(c):e!=null&&e.props?{...c,...e.props}:c;return s.jsx(L,{fragmentId:n,props:d,globalCssUrl:a,projectProperties:i})},G=({areaCode:r,options:e})=>s.jsx(u.Suspense,{fallback:(e==null?void 0:e.fallback)??null,children:s.jsx(I,{onError:e==null?void 0:e.onError,children:s.jsx(q,{areaCode:r,options:e})})});function R({client:r,children:e}){const l=u.useMemo(()=>({read:n=>r.$fragments.read(n)}),[r]);return s.jsx(M,{value:r,children:s.jsx(j,{value:l,children:e})})}function Y(r){return(u.useContext(P)??S)[r]}function J(r){return m.createFragmentsClient({...r,inject:A})}Object.defineProperty(t,"FragmentsApiVersionError",{enumerable:!0,get:()=>m.FragmentsApiVersionError}),Object.defineProperty(t,"FragmentsAreaError",{enumerable:!0,get:()=>m.FragmentsAreaError}),Object.defineProperty(t,"FragmentsLoadError",{enumerable:!0,get:()=>m.FragmentsLoadError}),t.AREA_UNRESOLVED=F,t.Area=G,t.FragmentRenderer=K,t.FragmentStylesheet=C,t.FragmentsClientContext=g,t.FragmentsClientProvider=M,t.FragmentsProvider=R,t.InstanceIdContext=y,t.ModulesMapContext=E,t.ModulesMapProvider=j,t.ProjectPropertiesContext=P,t.createBrowserClient=J,t.defaultProjectProperties=S,t.injectStylesheet=A,t.useArea=T,t.useCssChunk=V,t.useFragmentComponent=w,t.useFragmentMetrics=k,t.useFragmentStylesheet=b,t.useProjectProperty=Y,Object.defineProperty(t,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-20260831061037",
4
+ "version": "0.2.0-dev-20260901074721",
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-20260831061037"
35
+ "@fragmentsx/fragments-client": "0.2.0-dev-20260901074721"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@testing-library/jest-dom": "^6.6.3",