@omnitron-dev/lumen-ui 0.0.0-stage → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -2
  3. package/dist/blocks/backlinks.d.ts +7 -0
  4. package/dist/blocks/backlinks.d.ts.map +1 -0
  5. package/dist/blocks/code-block.d.ts +9 -0
  6. package/dist/blocks/code-block.d.ts.map +1 -0
  7. package/dist/blocks/component-example.d.ts +16 -0
  8. package/dist/blocks/component-example.d.ts.map +1 -0
  9. package/dist/blocks/hover-reference-card.d.ts +11 -0
  10. package/dist/blocks/hover-reference-card.d.ts.map +1 -0
  11. package/dist/blocks/index.d.ts +7 -0
  12. package/dist/blocks/index.d.ts.map +1 -0
  13. package/dist/blocks/index.js +4 -0
  14. package/dist/blocks/index.js.map +1 -0
  15. package/dist/blocks/page-agent-actions.d.ts +7 -0
  16. package/dist/blocks/page-agent-actions.d.ts.map +1 -0
  17. package/dist/blocks/theorem-block.d.ts +15 -0
  18. package/dist/blocks/theorem-block.d.ts.map +1 -0
  19. package/dist/chunk-AQ5PPDEV.js +590 -0
  20. package/dist/chunk-AQ5PPDEV.js.map +1 -0
  21. package/dist/chunk-HCY4QR4M.js +197 -0
  22. package/dist/chunk-HCY4QR4M.js.map +1 -0
  23. package/dist/chunk-HLB7FMNG.js +536 -0
  24. package/dist/chunk-HLB7FMNG.js.map +1 -0
  25. package/dist/chunk-L2KGVOK3.js +21 -0
  26. package/dist/chunk-L2KGVOK3.js.map +1 -0
  27. package/dist/chunk-XUGEOYWY.js +117 -0
  28. package/dist/chunk-XUGEOYWY.js.map +1 -0
  29. package/dist/chunk-ZWYLETDL.js +363 -0
  30. package/dist/chunk-ZWYLETDL.js.map +1 -0
  31. package/dist/hydration/context.d.ts +17 -0
  32. package/dist/hydration/context.d.ts.map +1 -0
  33. package/dist/hydration/document-tabs.d.ts +4 -0
  34. package/dist/hydration/document-tabs.d.ts.map +1 -0
  35. package/dist/hydration/host.d.ts +13 -0
  36. package/dist/hydration/host.d.ts.map +1 -0
  37. package/dist/hydration/index.d.ts +5 -0
  38. package/dist/hydration/index.d.ts.map +1 -0
  39. package/dist/hydration/index.js +5 -0
  40. package/dist/hydration/index.js.map +1 -0
  41. package/dist/hydration/shell.d.ts +19 -0
  42. package/dist/hydration/shell.d.ts.map +1 -0
  43. package/dist/hydration/triggers.d.ts +25 -0
  44. package/dist/hydration/triggers.d.ts.map +1 -0
  45. package/dist/index.d.ts +10 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +9 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/interactive/api-explorer.d.ts +34 -0
  50. package/dist/interactive/api-explorer.d.ts.map +1 -0
  51. package/dist/interactive/index.d.ts +5 -0
  52. package/dist/interactive/index.d.ts.map +1 -0
  53. package/dist/interactive/index.js +5 -0
  54. package/dist/interactive/index.js.map +1 -0
  55. package/dist/interactive/mermaid-diagram.d.ts +7 -0
  56. package/dist/interactive/mermaid-diagram.d.ts.map +1 -0
  57. package/dist/interactive/playground-execution.d.ts +14 -0
  58. package/dist/interactive/playground-execution.d.ts.map +1 -0
  59. package/dist/interactive/playground-worker.d.ts +2 -0
  60. package/dist/interactive/playground-worker.d.ts.map +1 -0
  61. package/dist/interactive/playground.d.ts +32 -0
  62. package/dist/interactive/playground.d.ts.map +1 -0
  63. package/dist/navigation/doc-layout.d.ts +9 -0
  64. package/dist/navigation/doc-layout.d.ts.map +1 -0
  65. package/dist/navigation/footer.d.ts +30 -0
  66. package/dist/navigation/footer.d.ts.map +1 -0
  67. package/dist/navigation/index.d.ts +6 -0
  68. package/dist/navigation/index.d.ts.map +1 -0
  69. package/dist/navigation/index.js +4 -0
  70. package/dist/navigation/index.js.map +1 -0
  71. package/dist/navigation/navbar.d.ts +30 -0
  72. package/dist/navigation/navbar.d.ts.map +1 -0
  73. package/dist/navigation/pagination.d.ts +19 -0
  74. package/dist/navigation/pagination.d.ts.map +1 -0
  75. package/dist/navigation/section-nav.d.ts +18 -0
  76. package/dist/navigation/section-nav.d.ts.map +1 -0
  77. package/dist/playground-worker.js +15 -0
  78. package/dist/playground-worker.js.map +1 -0
  79. package/dist/search/index.d.ts +4 -0
  80. package/dist/search/index.d.ts.map +1 -0
  81. package/dist/search/index.js +4 -0
  82. package/dist/search/index.js.map +1 -0
  83. package/dist/search/netron-adapter.d.ts +25 -0
  84. package/dist/search/netron-adapter.d.ts.map +1 -0
  85. package/dist/search/pagefind-adapter.d.ts +20 -0
  86. package/dist/search/pagefind-adapter.d.ts.map +1 -0
  87. package/dist/search/search-dialog.d.ts +40 -0
  88. package/dist/search/search-dialog.d.ts.map +1 -0
  89. package/package.json +83 -3
@@ -0,0 +1,590 @@
1
+ import { LumenContext } from './chunk-L2KGVOK3.js';
2
+ import { parseHydrationTrigger, serializeIslandProps, parseIslandProps } from '@omnitron-dev/lumen-ast/islands';
3
+ import React3, { useState, useRef, useEffect, useMemo, useCallback, useId, useLayoutEffect } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { PrismProvider } from '@omnitron-dev/prism/core';
6
+ import { ErrorBoundary } from '@omnitron-dev/prism/components/error-boundary';
7
+ import { Tabs } from '@omnitron-dev/prism/components/tabs';
8
+ import { jsx, jsxs } from 'react/jsx-runtime';
9
+
10
+ function setupTrigger(element, trigger, onTrigger, options) {
11
+ switch (parseHydrationTrigger(trigger)) {
12
+ case "load":
13
+ return setupLoadTrigger(onTrigger);
14
+ case "visible":
15
+ return setupVisibleTrigger(element, onTrigger, options);
16
+ case "interaction":
17
+ return setupInteractionTrigger(element, onTrigger);
18
+ case "idle":
19
+ return setupIdleTrigger(onTrigger, options);
20
+ default:
21
+ return setupEventTrigger(element, trigger.slice(2).toLowerCase(), onTrigger);
22
+ }
23
+ }
24
+ function setupLoadTrigger(onTrigger) {
25
+ if (typeof window === "undefined") return () => {
26
+ };
27
+ if (document.readyState === "complete" || document.readyState === "interactive") {
28
+ const handle = requestAnimationFrame(() => onTrigger());
29
+ return () => cancelAnimationFrame(handle);
30
+ }
31
+ const handler = () => onTrigger();
32
+ window.addEventListener("DOMContentLoaded", handler, { once: true });
33
+ return () => window.removeEventListener("DOMContentLoaded", handler);
34
+ }
35
+ function setupVisibleTrigger(element, onTrigger, options) {
36
+ if (typeof window === "undefined") return () => {
37
+ };
38
+ if (typeof IntersectionObserver === "undefined") {
39
+ onTrigger();
40
+ return () => {
41
+ };
42
+ }
43
+ let observer = new IntersectionObserver(
44
+ (entries) => {
45
+ for (const entry of entries) {
46
+ if (entry.isIntersecting) {
47
+ if (observer) {
48
+ observer.disconnect();
49
+ observer = null;
50
+ }
51
+ onTrigger();
52
+ break;
53
+ }
54
+ }
55
+ },
56
+ {
57
+ rootMargin: options?.rootMargin ?? "200px",
58
+ threshold: options?.threshold ?? 0.1
59
+ }
60
+ );
61
+ observer.observe(element);
62
+ return () => {
63
+ if (observer) {
64
+ observer.disconnect();
65
+ observer = null;
66
+ }
67
+ };
68
+ }
69
+ var INTERACTION_EVENTS = ["pointerenter", "focusin", "click", "touchstart", "keydown"];
70
+ function setupInteractionTrigger(element, onTrigger) {
71
+ if (typeof window === "undefined") return () => {
72
+ };
73
+ let fired = false;
74
+ const handler = () => {
75
+ if (fired) return;
76
+ fired = true;
77
+ cleanup();
78
+ onTrigger();
79
+ };
80
+ const cleanup = () => {
81
+ for (const evt of INTERACTION_EVENTS) {
82
+ element.removeEventListener(evt, handler);
83
+ }
84
+ };
85
+ for (const evt of INTERACTION_EVENTS) {
86
+ element.addEventListener(evt, handler, { once: true, passive: true });
87
+ }
88
+ return cleanup;
89
+ }
90
+ function setupIdleTrigger(onTrigger, options) {
91
+ if (typeof window === "undefined") return () => {
92
+ };
93
+ if ("requestIdleCallback" in window && typeof window.requestIdleCallback === "function") {
94
+ const handle = window.requestIdleCallback(() => onTrigger(), { timeout: options?.timeout ?? 2e3 });
95
+ return () => window.cancelIdleCallback(handle);
96
+ }
97
+ const timer = setTimeout(() => onTrigger(), 200);
98
+ return () => clearTimeout(timer);
99
+ }
100
+ function setupEventTrigger(element, eventName, onTrigger) {
101
+ if (typeof window === "undefined") return () => {
102
+ };
103
+ const handler = () => onTrigger();
104
+ element.addEventListener(eventName, handler, { once: true, passive: true });
105
+ return () => element.removeEventListener(eventName, handler);
106
+ }
107
+ function PortalIslandHost({
108
+ islandId,
109
+ component,
110
+ hydrate = "idle",
111
+ props = {},
112
+ children,
113
+ className = "lumen-portal-island",
114
+ style
115
+ }) {
116
+ return React3.createElement(
117
+ "div",
118
+ {
119
+ className,
120
+ "data-lumen-island": islandId,
121
+ ...component ? { "data-component": component } : {},
122
+ "data-hydrate": parseHydrationTrigger(hydrate),
123
+ "data-props": serializeIslandProps(props),
124
+ style
125
+ },
126
+ children
127
+ );
128
+ }
129
+ var syncEvent = "lumen:document-tab-change";
130
+ function fragmentTarget(doc) {
131
+ const hash = doc.defaultView?.location.hash;
132
+ if (!hash) return null;
133
+ try {
134
+ return doc.getElementById(decodeURIComponent(hash.slice(1)));
135
+ } catch {
136
+ return null;
137
+ }
138
+ }
139
+ function DocumentTabs() {
140
+ const strip = useRef(null);
141
+ const instance = useId();
142
+ const [panels, setPanels] = useState([]);
143
+ const [selected, setSelected] = useState(0);
144
+ const group = strip.current?.closest(".lumen-tabs");
145
+ const syncKey = group?.dataset.syncKey;
146
+ useLayoutEffect(() => {
147
+ const container = strip.current?.closest(".lumen-tabs");
148
+ if (!container) return;
149
+ const sections = Array.from(container.querySelectorAll(":scope > .lumen-tab-item"));
150
+ const items = [];
151
+ for (const section of sections) {
152
+ const heading = section.querySelector(":scope > .lumen-tab-label");
153
+ if (!heading) return;
154
+ items.push({ section, heading, value: section.dataset.value ?? heading.textContent ?? "" });
155
+ }
156
+ const doc = container.ownerDocument;
157
+ const anchor = fragmentTarget(doc);
158
+ const peer = container.dataset.syncKey && Array.from(doc.querySelectorAll(".lumen-tabs[data-active-value]")).find((item) => item !== container && item.dataset.syncKey === container.dataset.syncKey);
159
+ const anchored = items.findIndex((item) => anchor && item.section.contains(anchor));
160
+ const anchorPanel = anchor?.closest(".lumen-tab-item");
161
+ const anchorGroup = anchorPanel?.parentElement;
162
+ const anchorValue = container.dataset.syncKey && anchorGroup?.dataset.syncKey === container.dataset.syncKey ? anchorPanel?.dataset.value : void 0;
163
+ const synced = items.findIndex((item) => item.value === (anchorValue ?? (peer && peer.dataset.activeValue)));
164
+ setSelected(anchored >= 0 ? anchored : Math.max(0, synced));
165
+ setPanels(items);
166
+ }, []);
167
+ useLayoutEffect(() => {
168
+ const tabs = strip.current?.querySelectorAll('[role="tab"]');
169
+ if (!group || !panels.length || tabs?.length !== panels.length) return void 0;
170
+ panels.forEach(({ section, heading }, index) => {
171
+ const tab = tabs[index];
172
+ section.id = `${instance}-panel-${index}`;
173
+ section.setAttribute("role", "tabpanel");
174
+ section.setAttribute("aria-labelledby", tab.id);
175
+ section.tabIndex = 0;
176
+ tab.setAttribute("aria-controls", section.id);
177
+ heading.hidden = true;
178
+ section.hidden = index !== selected;
179
+ });
180
+ group.dataset.activeValue = panels[selected].value;
181
+ return () => {
182
+ delete group.dataset.activeValue;
183
+ for (const { section, heading } of panels) {
184
+ section.hidden = false;
185
+ heading.hidden = false;
186
+ for (const attribute of ["id", "role", "aria-labelledby", "tabindex"]) section.removeAttribute(attribute);
187
+ }
188
+ };
189
+ }, [group, instance, panels, selected]);
190
+ useEffect(() => {
191
+ if (!group || !panels.length) return void 0;
192
+ const doc = group.ownerDocument;
193
+ const onSync = (event) => {
194
+ const choice = event.detail;
195
+ if (!choice || choice.key !== syncKey) return;
196
+ const index = panels.findIndex((item) => item.value === choice.value);
197
+ if (index >= 0) setSelected(index);
198
+ };
199
+ const onHashChange = () => {
200
+ const anchor = fragmentTarget(doc);
201
+ const index = panels.findIndex((item) => anchor && item.section.contains(anchor));
202
+ if (index >= 0) {
203
+ setSelected(index);
204
+ if (syncKey) doc.dispatchEvent(new CustomEvent(syncEvent, { detail: { key: syncKey, value: panels[index].value } }));
205
+ }
206
+ };
207
+ if (syncKey) doc.addEventListener(syncEvent, onSync);
208
+ doc.defaultView?.addEventListener("hashchange", onHashChange);
209
+ return () => {
210
+ if (syncKey) doc.removeEventListener(syncEvent, onSync);
211
+ doc.defaultView?.removeEventListener("hashchange", onHashChange);
212
+ };
213
+ }, [group, panels, syncKey]);
214
+ function select(value) {
215
+ const index = Number(value);
216
+ setSelected(index);
217
+ if (syncKey) group?.ownerDocument.dispatchEvent(new CustomEvent(syncEvent, { detail: { key: syncKey, value: panels[index].value } }));
218
+ }
219
+ return /* @__PURE__ */ jsx("div", { ref: strip, children: panels.length > 0 && /* @__PURE__ */ jsx(
220
+ Tabs,
221
+ {
222
+ "aria-label": group?.dataset.label || panels.map((item) => item.heading.textContent).join(" / "),
223
+ tabs: panels.map((item, index) => ({ label: item.heading.textContent ?? item.value, value: String(index) })),
224
+ value: String(selected),
225
+ onChange: select,
226
+ selectionFollowsFocus: true,
227
+ variant: "scrollable",
228
+ scrollButtons: "auto"
229
+ }
230
+ ) });
231
+ }
232
+ var ISLAND_SELECTOR = ".lumen-portal-island, [data-lumen-island], [data-widget]";
233
+ var globalElementInstanceCounter = 0;
234
+ var elementInstanceKeys = /* @__PURE__ */ new WeakMap();
235
+ var syntheticElementIds = /* @__PURE__ */ new WeakMap();
236
+ function getOrCreateInstanceKey(el) {
237
+ let key = elementInstanceKeys.get(el);
238
+ if (!key) {
239
+ globalElementInstanceCounter += 1;
240
+ key = `lumen-island-inst-${globalElementInstanceCounter}`;
241
+ elementInstanceKeys.set(el, key);
242
+ }
243
+ return key;
244
+ }
245
+ function resolveElementIslandIdentity(el) {
246
+ const explicitIslandId = el.getAttribute("data-lumen-island") ?? "";
247
+ const dataComponent = el.getAttribute("data-component") ?? "";
248
+ const dataWidget = el.getAttribute("data-widget") ?? "";
249
+ let islandId = explicitIslandId;
250
+ if (!islandId) {
251
+ let synthetic = syntheticElementIds.get(el);
252
+ if (!synthetic) {
253
+ const base = dataWidget || dataComponent || "island";
254
+ globalElementInstanceCounter += 1;
255
+ synthetic = `${base}-${globalElementInstanceCounter}`;
256
+ syntheticElementIds.set(el, synthetic);
257
+ }
258
+ islandId = synthetic;
259
+ el.setAttribute("data-lumen-island", islandId);
260
+ }
261
+ const componentName = dataComponent || dataWidget || islandId;
262
+ return { islandId, componentName };
263
+ }
264
+ function discoverIsland(element, previous) {
265
+ const { islandId, componentName } = resolveElementIslandIdentity(element);
266
+ const rawProps = element.getAttribute("data-props");
267
+ const rawTrigger = element.getAttribute("data-hydrate");
268
+ if (previous?.islandId === islandId && previous.componentName === componentName && previous.rawProps === rawProps && previous.rawTrigger === rawTrigger) return previous;
269
+ const item = { instanceKey: getOrCreateInstanceKey(element), islandId, componentName, element, rawProps, rawTrigger };
270
+ try {
271
+ return { ...item, props: rawProps === null ? {} : parseIslandProps(rawProps), trigger: parseHydrationTrigger(rawTrigger ?? "idle") };
272
+ } catch (error) {
273
+ const metadataError = error instanceof Error ? error : new Error("Invalid island metadata");
274
+ console.error(`[LumenHydration] Invalid metadata for island "${islandId}":`, metadataError);
275
+ return { ...item, metadataError };
276
+ }
277
+ }
278
+ function PortalIslandManager({
279
+ registry,
280
+ onActiveIslandsChange,
281
+ hydrateHandlerRef,
282
+ pendingHydrateIdsRef
283
+ }) {
284
+ const [, setRenderVersion] = useState(0);
285
+ const [discovered, setDiscovered] = useState([]);
286
+ const cleanupsRef = useRef(/* @__PURE__ */ new Map());
287
+ const activeElementsRef = useRef(/* @__PURE__ */ new Set());
288
+ const clearedSsrElementsRef = useRef(/* @__PURE__ */ new WeakSet());
289
+ const discoveredListRef = useRef([]);
290
+ const registryRef = useRef(registry);
291
+ const onActiveIslandsChangeRef = useRef(onActiveIslandsChange);
292
+ registryRef.current = registry;
293
+ onActiveIslandsChangeRef.current = onActiveIslandsChange;
294
+ useEffect(() => {
295
+ if (typeof document === "undefined") {
296
+ return void 0;
297
+ }
298
+ const cleanups = cleanupsRef.current;
299
+ const activeElements = activeElementsRef.current;
300
+ const notifyActiveIds = () => {
301
+ const nextIds = /* @__PURE__ */ new Set();
302
+ for (const item of discoveredListRef.current) {
303
+ if (item.element.isConnected && activeElements.has(item.element)) {
304
+ nextIds.add(item.islandId);
305
+ }
306
+ }
307
+ onActiveIslandsChangeRef.current?.(nextIds);
308
+ };
309
+ const clearStaticFallbackIfReady = (el, componentName) => {
310
+ if (clearedSsrElementsRef.current.has(el)) {
311
+ return;
312
+ }
313
+ if (registryRef.current[componentName]) {
314
+ clearedSsrElementsRef.current.add(el);
315
+ el.replaceChildren();
316
+ }
317
+ };
318
+ const activateElement = (el) => {
319
+ if (!el.isConnected) return;
320
+ let item = discoveredListRef.current.find((candidate) => candidate.element === el);
321
+ const identity = resolveElementIslandIdentity(el);
322
+ const triggerChanged = item?.rawTrigger !== el.getAttribute("data-hydrate");
323
+ if (!item || item.rawProps !== el.getAttribute("data-props") || triggerChanged || item.islandId !== identity.islandId || item.componentName !== identity.componentName) {
324
+ scanAndAttach();
325
+ if (triggerChanged) return;
326
+ item = discoveredListRef.current.find((candidate) => candidate.element === el);
327
+ }
328
+ if (!item || item.metadataError) return;
329
+ const cleanup = cleanups.get(el);
330
+ if (cleanup) {
331
+ cleanup();
332
+ cleanups.delete(el);
333
+ }
334
+ if (activeElements.has(el)) {
335
+ return;
336
+ }
337
+ activeElements.add(el);
338
+ clearStaticFallbackIfReady(el, item.componentName);
339
+ notifyActiveIds();
340
+ setRenderVersion((v) => v + 1);
341
+ };
342
+ const scanAndAttach = () => {
343
+ if (typeof document === "undefined") return;
344
+ const nodeList = document.querySelectorAll(ISLAND_SELECTOR);
345
+ const connectedElements = /* @__PURE__ */ new Set();
346
+ nodeList.forEach((el) => {
347
+ if (el.isConnected) {
348
+ connectedElements.add(el);
349
+ }
350
+ });
351
+ let activePruned = false;
352
+ cleanups.forEach((cleanup, el) => {
353
+ if (!connectedElements.has(el) || !el.isConnected) {
354
+ cleanup();
355
+ cleanups.delete(el);
356
+ }
357
+ });
358
+ activeElements.forEach((el) => {
359
+ if (!connectedElements.has(el) || !el.isConnected) {
360
+ activeElements.delete(el);
361
+ activePruned = true;
362
+ }
363
+ });
364
+ const prevList = discoveredListRef.current;
365
+ const previousByElement = new Map(prevList.map((item) => [item.element, item]));
366
+ const nextList = [...connectedElements].map((el) => discoverIsland(el, previousByElement.get(el)));
367
+ const pendingElementsToActivate = [];
368
+ const listChanged = prevList.length !== nextList.length || nextList.some((item, index) => item !== prevList[index]);
369
+ discoveredListRef.current = nextList;
370
+ for (const item of nextList) {
371
+ const { element: el, islandId, componentName } = item;
372
+ const previous = previousByElement.get(el);
373
+ if (item.metadataError || previous?.rawTrigger !== item.rawTrigger) {
374
+ cleanups.get(el)?.();
375
+ cleanups.delete(el);
376
+ }
377
+ if (item.metadataError) {
378
+ el.setAttribute("data-lumen-error", "metadata");
379
+ if (activeElements.delete(el)) activePruned = true;
380
+ continue;
381
+ }
382
+ el.removeAttribute("data-lumen-error");
383
+ if (pendingHydrateIdsRef?.current && (pendingHydrateIdsRef.current.has(islandId) || pendingHydrateIdsRef.current.has(componentName))) {
384
+ pendingHydrateIdsRef.current.delete(islandId);
385
+ pendingHydrateIdsRef.current.delete(componentName);
386
+ pendingElementsToActivate.push(el);
387
+ continue;
388
+ }
389
+ if (activeElements.has(el) || cleanups.has(el)) {
390
+ continue;
391
+ }
392
+ const cleanup = setupTrigger(el, item.trigger, () => {
393
+ activateElement(el);
394
+ });
395
+ if (activeElements.has(el)) cleanup();
396
+ else cleanups.set(el, cleanup);
397
+ }
398
+ for (const el of pendingElementsToActivate) {
399
+ activateElement(el);
400
+ }
401
+ if (activePruned || listChanged) {
402
+ notifyActiveIds();
403
+ }
404
+ if (listChanged || activePruned || pendingElementsToActivate.length > 0) {
405
+ setDiscovered(nextList);
406
+ }
407
+ };
408
+ const hydrateById = (targetId) => {
409
+ if (!targetId) return;
410
+ scanAndAttach();
411
+ let matched = false;
412
+ for (const item of discoveredListRef.current) {
413
+ if (!item.metadataError && item.element.isConnected && (item.islandId === targetId || item.componentName === targetId)) {
414
+ matched = true;
415
+ activateElement(item.element);
416
+ }
417
+ }
418
+ if (!matched && pendingHydrateIdsRef?.current) {
419
+ pendingHydrateIdsRef.current.add(targetId);
420
+ }
421
+ };
422
+ if (hydrateHandlerRef) {
423
+ hydrateHandlerRef.current = hydrateById;
424
+ }
425
+ scanAndAttach();
426
+ let mutationObserver = null;
427
+ if (typeof MutationObserver !== "undefined") {
428
+ mutationObserver = new MutationObserver(() => {
429
+ scanAndAttach();
430
+ });
431
+ mutationObserver.observe(document.body, {
432
+ childList: true,
433
+ subtree: true,
434
+ attributes: true,
435
+ attributeFilter: ["data-props", "data-hydrate", "data-component", "data-widget", "data-lumen-island"]
436
+ });
437
+ }
438
+ return () => {
439
+ if (hydrateHandlerRef) {
440
+ hydrateHandlerRef.current = null;
441
+ }
442
+ mutationObserver?.disconnect();
443
+ cleanups.forEach((cleanup) => cleanup());
444
+ cleanups.clear();
445
+ activeElements.clear();
446
+ };
447
+ }, [hydrateHandlerRef, pendingHydrateIdsRef]);
448
+ if (typeof window === "undefined" || discovered.length === 0) {
449
+ return null;
450
+ }
451
+ const portals = [];
452
+ for (const item of discovered) {
453
+ if (item.element.isConnected && item.metadataError) {
454
+ if (!clearedSsrElementsRef.current.has(item.element)) {
455
+ clearedSsrElementsRef.current.add(item.element);
456
+ item.element.replaceChildren();
457
+ }
458
+ portals.push(createPortal(/* @__PURE__ */ jsx("p", { className: "lumen-island-error", role: "alert", children: "Unable to load this component: invalid island metadata." }), item.element, item.instanceKey));
459
+ continue;
460
+ }
461
+ if (item.element.isConnected && activeElementsRef.current.has(item.element)) {
462
+ const Component = registry[item.componentName];
463
+ if (Component) {
464
+ if (!clearedSsrElementsRef.current.has(item.element)) {
465
+ clearedSsrElementsRef.current.add(item.element);
466
+ item.element.replaceChildren();
467
+ }
468
+ portals.push(createPortal(
469
+ /* @__PURE__ */ jsx(
470
+ ErrorBoundary,
471
+ {
472
+ resetKeys: [Component, item.islandId, item.rawProps],
473
+ fallback: ({ error }) => /* @__PURE__ */ jsxs("p", { className: "lumen-island-error", role: "alert", children: [
474
+ item.componentName,
475
+ " could not render. ",
476
+ error.message
477
+ ] }),
478
+ children: React3.createElement(Component, item.props)
479
+ }
480
+ ),
481
+ item.element,
482
+ item.instanceKey
483
+ ));
484
+ }
485
+ }
486
+ }
487
+ return portals.length > 0 ? React3.createElement(React3.Fragment, null, ...portals) : null;
488
+ }
489
+ function LumenShellProvider({
490
+ children,
491
+ theme = "dark",
492
+ locale = "en",
493
+ currentPath = "/",
494
+ islands = {}
495
+ }) {
496
+ const [dynamicIslands, setDynamicIslands] = useState({});
497
+ const [activeIslands, setActiveIslands] = useState(() => /* @__PURE__ */ new Set());
498
+ const mergedIslands = useMemo(() => ({ LumenDocumentTabs: DocumentTabs, ...islands, ...dynamicIslands }), [islands, dynamicIslands]);
499
+ const latestRegistryRef = useRef(mergedIslands);
500
+ latestRegistryRef.current = mergedIslands;
501
+ const hydrateHandlerRef = useRef(null);
502
+ const pendingHydrateIdsRef = useRef(/* @__PURE__ */ new Set());
503
+ const registerIsland = useCallback((name, component) => {
504
+ if (!name || !component) return;
505
+ latestRegistryRef.current = { ...latestRegistryRef.current, [name]: component };
506
+ setDynamicIslands((prev) => {
507
+ if (prev[name] === component) return prev;
508
+ return { ...prev, [name]: component };
509
+ });
510
+ }, []);
511
+ const getIsland = useCallback((name) => latestRegistryRef.current[name], []);
512
+ const hydrateIsland = useCallback((islandId) => {
513
+ if (!islandId) return;
514
+ if (hydrateHandlerRef.current) {
515
+ hydrateHandlerRef.current(islandId);
516
+ } else {
517
+ pendingHydrateIdsRef.current.add(islandId);
518
+ }
519
+ }, []);
520
+ const handleActiveIslandsChange = useCallback((nextIds) => {
521
+ setActiveIslands((prev) => {
522
+ if (prev.size === nextIds.size && Array.from(prev).every((id) => nextIds.has(id))) {
523
+ return prev;
524
+ }
525
+ return new Set(nextIds);
526
+ });
527
+ }, []);
528
+ const contextValue = useMemo(
529
+ () => ({
530
+ theme,
531
+ locale,
532
+ currentPath,
533
+ islands: mergedIslands,
534
+ registerIsland,
535
+ getIsland,
536
+ activeIslands,
537
+ hydrateIsland
538
+ }),
539
+ [theme, locale, currentPath, mergedIslands, registerIsland, getIsland, activeIslands, hydrateIsland]
540
+ );
541
+ const shellDiv = React3.createElement(
542
+ "div",
543
+ { className: "lumen-shell", "data-theme": theme, "data-locale": locale },
544
+ children,
545
+ React3.createElement(PortalIslandManager, {
546
+ registry: mergedIslands,
547
+ onActiveIslandsChange: handleActiveIslandsChange,
548
+ hydrateHandlerRef,
549
+ pendingHydrateIdsRef
550
+ })
551
+ );
552
+ return React3.createElement(LumenContext.Provider, { value: contextValue }, shellDiv);
553
+ }
554
+ function LumenShell({
555
+ children,
556
+ theme = "dark",
557
+ locale = "en",
558
+ currentPath = "/",
559
+ islands = {},
560
+ disablePrismProvider = false
561
+ }) {
562
+ const resolvedMode = theme === "light" ? "light" : "dark";
563
+ const providerElement = React3.createElement(LumenShellProvider, {
564
+ theme,
565
+ locale,
566
+ currentPath,
567
+ islands,
568
+ children
569
+ });
570
+ if (disablePrismProvider) {
571
+ return providerElement;
572
+ }
573
+ return /* @__PURE__ */ jsx(
574
+ PrismProvider,
575
+ {
576
+ disableCssBaseline: true,
577
+ mode: resolvedMode,
578
+ config: {
579
+ theme: {
580
+ mode: resolvedMode
581
+ }
582
+ },
583
+ children: providerElement
584
+ }
585
+ );
586
+ }
587
+
588
+ export { LumenShell, PortalIslandHost, PortalIslandManager, setupEventTrigger, setupIdleTrigger, setupInteractionTrigger, setupLoadTrigger, setupTrigger, setupVisibleTrigger };
589
+ //# sourceMappingURL=chunk-AQ5PPDEV.js.map
590
+ //# sourceMappingURL=chunk-AQ5PPDEV.js.map