@flexiformal/ftml-react 0.0.3 → 0.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexiformal/ftml-react",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/FlexiFormal/ftml-ts#readme",
6
6
  "bugs": {
@@ -15,8 +15,8 @@
15
15
  "types": "./dist/index.d.ts",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
19
- "default": "./dist/index.js"
18
+ "types": "./dist/index.d.mts",
19
+ "default": "./dist/index.mjs"
20
20
  }
21
21
  },
22
22
  "files": [
@@ -50,7 +50,7 @@
50
50
  "vitest": "^3.0.7"
51
51
  },
52
52
  "dependencies": {
53
- "@flexiformal/ftml": "0.0.3",
53
+ "@flexiformal/ftml": "0.0.4",
54
54
  "react": "^19.0.0",
55
55
  "react-dom": "^19.0.0"
56
56
  }
package/dist/index.d.ts DELETED
@@ -1,55 +0,0 @@
1
- import * as Base from '@flexiformal/ftml';
2
- export { Base as FTML };
3
- import { ReactNode } from 'react';
4
-
5
- declare const initialize: typeof Base.initialize;
6
- declare function getCurrentUri(): Base.FTML.NarrativeUri | undefined;
7
- interface FtmlConfig {
8
- allowHovers?: boolean;
9
- allowFullscreen?: boolean;
10
- allowFormalInfo?: boolean;
11
- allowNotationChanges?: boolean;
12
- chooseHighlightStyle?: boolean;
13
- showContent?: boolean;
14
- pdfLink?: boolean;
15
- highlightStyle?: Base.FTML.HighlightStyle;
16
- toc?: Base.FTML.TocSource;
17
- autoexpandLimit?: Base.FTML.LogicalLevel;
18
- tocProgress?: Base.FTML.TocProgress[];
19
- sectionWrap?: (uri: Base.FTML.DocumentElementUri, lvl: Base.FTML.SectionLevel) => ((ch: ReactNode) => ReactNode) | undefined;
20
- paragraphWrap?: (uri: Base.FTML.DocumentElementUri, kind: Base.FTML.ParagraphKind) => ((ch: ReactNode) => ReactNode) | undefined;
21
- slideWrap?: (uri: Base.FTML.DocumentElementUri) => ((ch: ReactNode) => ReactNode) | undefined;
22
- problemWrap?: (uri: Base.FTML.DocumentElementUri, subProblem: boolean) => ((ch: ReactNode) => ReactNode) | undefined;
23
- onSectionTitle?: (uri: Base.FTML.DocumentElementUri, lvl: Base.FTML.SectionLevel) => ReactNode | undefined;
24
- problemStates?: Base.FTML.ProblemStates;
25
- onProblemResponse?: (r: Base.FTML.ProblemResponse) => void;
26
- }
27
- interface FTMLSetupArgs extends FtmlConfig {
28
- children: ReactNode;
29
- }
30
- /**
31
- * Sets up Leptos' reactive system
32
- */
33
- declare const FTMLSetup: React.FC<FTMLSetupArgs>;
34
- /**
35
- * See {@link FTMLConfig} and {@link FTML.DocumentOptions}
36
- */
37
- interface FTMLDocumentArgs extends FtmlConfig {
38
- document: Base.FTML.DocumentOptions;
39
- }
40
- /**
41
- * render an FTML document
42
- */
43
- declare const FTMLDocument: React.FC<FTMLDocumentArgs>;
44
- /**
45
- * See {@link FTMLConfig} and {@link Base.FTML.FragmentOptions}
46
- */
47
- interface FTMLFragmentArgs extends FtmlConfig {
48
- fragment: Base.FTML.FragmentOptions;
49
- }
50
- /**
51
- * render an FTML fragment
52
- */
53
- declare const FTMLFragment: React.FC<FTMLFragmentArgs>;
54
-
55
- export { FTMLDocument, type FTMLDocumentArgs, FTMLFragment, type FTMLFragmentArgs, FTMLSetup, type FTMLSetupArgs, type FtmlConfig, getCurrentUri, initialize };
package/dist/index.js DELETED
@@ -1,301 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.tsx
31
- var index_exports = {};
32
- __export(index_exports, {
33
- FTML: () => FTML2,
34
- FTMLDocument: () => FTMLDocument,
35
- FTMLFragment: () => FTMLFragment,
36
- FTMLSetup: () => FTMLSetup,
37
- getCurrentUri: () => getCurrentUri,
38
- initialize: () => initialize2
39
- });
40
- module.exports = __toCommonJS(index_exports);
41
- var Base = __toESM(require("@flexiformal/ftml"));
42
- var FTML2 = __toESM(require("@flexiformal/ftml"));
43
- var import_react2 = require("react");
44
-
45
- // src/leptos.tsx
46
- var import_react = require("react");
47
- var import_react_dom = require("react-dom");
48
- var import_jsx_runtime = require("react/jsx-runtime");
49
- var ReactLeptosContext = (0, import_react.createContext)(
50
- void 0
51
- );
52
- function toConfig(config, addTunnel) {
53
- let cfg = {
54
- allowHovers: config.allowHovers,
55
- allowFullscreen: config.allowFullscreen,
56
- allowFormalInfo: config.allowFormalInfo,
57
- allowNotationChanges: config.allowNotationChanges,
58
- chooseHighlightStyle: config.chooseHighlightStyle,
59
- showContent: config.showContent,
60
- pdfLink: config.pdfLink,
61
- toc: config.toc,
62
- tocProgress: config.tocProgress,
63
- autoexpandLimit: config.autoexpandLimit,
64
- onProblemResponse: config.onProblemResponse,
65
- problemStates: config.problemStates
66
- };
67
- const ost = config.onSectionTitle;
68
- if (ost) {
69
- cfg.onSectionTitle = (u, lvl) => {
70
- return (e, ctx) => {
71
- addTunnel(e, ost(u, lvl), ctx);
72
- };
73
- };
74
- }
75
- const sect = config.sectionWrap;
76
- if (sect) {
77
- cfg.sectionWrap = (u, lvl) => {
78
- return (e, ctx) => {
79
- const r = sect(u, lvl);
80
- if (r) {
81
- addTunnel(e, r(elemToReact(e, ctx)), ctx);
82
- }
83
- };
84
- };
85
- }
86
- const para = config.paragraphWrap;
87
- if (para) {
88
- cfg.paragraphWrap = (u, knd) => {
89
- return (e, ctx) => {
90
- const r = para(u, knd);
91
- if (r) {
92
- addTunnel(e, r(elemToReact(e, ctx)), ctx);
93
- }
94
- };
95
- };
96
- }
97
- const slide = config.slideWrap;
98
- if (slide) {
99
- cfg.slideWrap = (u) => {
100
- return (e, ctx) => {
101
- const r = slide(u);
102
- if (r) {
103
- addTunnel(e, r(elemToReact(e, ctx)), ctx);
104
- }
105
- };
106
- };
107
- }
108
- const problem = config.problemWrap;
109
- if (problem) {
110
- cfg.problemWrap = (u, sub) => {
111
- return (e, ctx) => {
112
- const r = problem(u, sub);
113
- if (r) {
114
- addTunnel(e, r(elemToReact(e, ctx)), ctx);
115
- }
116
- };
117
- };
118
- }
119
- return cfg;
120
- }
121
- function elemToReact(elem, ctx) {
122
- const chs = Array.from(elem.childNodes);
123
- chs.forEach((c) => elem.removeChild(c));
124
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ElemToReact, { elems: chs, ctx });
125
- }
126
- var ElemToReact = ({ elems, ctx }) => {
127
- const ref = (0, import_react.useRef)(null);
128
- const done = (0, import_react.useRef)(false);
129
- (0, import_react.useEffect)(() => {
130
- if (ref.current && !done.current) {
131
- done.current = true;
132
- ref.current.replaceChildren(...elems);
133
- }
134
- }, []);
135
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReactLeptosContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, style: { display: "contents" } }) });
136
- };
137
- function useLeptosTunnel() {
138
- const [tunnel, setTunnel] = (0, import_react.useState)(void 0);
139
- const addTunnel = (element, node, context) => {
140
- const id = Math.random().toString(36).slice(2);
141
- setTunnel({ element, node, id, context });
142
- return id;
143
- };
144
- const removeTunnel = () => {
145
- setTunnel(void 0);
146
- };
147
- const TunnelRenderer = () => tunnel ? (0, import_react_dom.createPortal)(
148
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReactLeptosContext.Provider, { value: tunnel.context, children: tunnel.node }),
149
- tunnel.element,
150
- tunnel.id
151
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
152
- (0, import_react.useEffect)(() => {
153
- return () => {
154
- if (tunnel) {
155
- }
156
- };
157
- });
158
- return {
159
- addTunnel,
160
- removeTunnel,
161
- TunnelRenderer
162
- };
163
- }
164
- function useLeptosTunnels() {
165
- const [tunnels, setTunnels] = (0, import_react.useState)([]);
166
- const addTunnel = (element, node, context) => {
167
- const id = Math.random().toString(36).slice(2);
168
- setTunnels((prev) => [...prev, { element, node, id, context }]);
169
- return id;
170
- };
171
- const removeTunnel = (id) => {
172
- setTunnels(
173
- (prev) => prev.filter((tunnel) => {
174
- if (tunnel.id === id) {
175
- }
176
- return tunnel.id !== id;
177
- })
178
- );
179
- };
180
- const TunnelRenderer = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: tunnels.map(
181
- (tunnel) => (0, import_react_dom.createPortal)(
182
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReactLeptosContext.Provider, { value: tunnel.context, children: tunnel.node }),
183
- tunnel.element,
184
- tunnel.id
185
- )
186
- ) });
187
- (0, import_react.useEffect)(() => {
188
- return () => {
189
- tunnels.forEach((tunnel) => {
190
- });
191
- };
192
- });
193
- return {
194
- addTunnel,
195
- removeTunnel,
196
- TunnelRenderer
197
- };
198
- }
199
-
200
- // src/index.tsx
201
- var import_jsx_runtime2 = require("react/jsx-runtime");
202
- var initialize2 = Base.initialize;
203
- function getCurrentUri() {
204
- const context = (0, import_react2.useContext)(ReactLeptosContext);
205
- if (context) {
206
- return Base.FTML.get_current_uri(context);
207
- }
208
- }
209
- var FTMLSetup = (args) => {
210
- const mountRef = (0, import_react2.useRef)(null);
211
- const main = useLeptosTunnel();
212
- const { addTunnel, TunnelRenderer } = useLeptosTunnels();
213
- const context = (0, import_react2.useContext)(ReactLeptosContext);
214
- (0, import_react2.useEffect)(() => {
215
- if (!mountRef.current) return;
216
- if (context) {
217
- const handle = Base.FTML.apply_config(
218
- toConfig(args, addTunnel),
219
- mountRef.current,
220
- context
221
- );
222
- return () => {
223
- handle.unmount();
224
- };
225
- } else {
226
- const handle = Base.ftmlSetup(
227
- mountRef.current,
228
- (e, o) => {
229
- main.addTunnel(
230
- e,
231
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
232
- args.children,
233
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TunnelRenderer, {})
234
- ] }),
235
- o
236
- );
237
- },
238
- toConfig(args, addTunnel)
239
- );
240
- return () => {
241
- handle.unmount();
242
- };
243
- }
244
- }, []);
245
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
246
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: mountRef, style: { display: "contents" } }),
247
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(main.TunnelRenderer, {})
248
- ] });
249
- };
250
- var FTMLDocument = (args) => {
251
- const mountRef = (0, import_react2.useRef)(null);
252
- const { addTunnel, TunnelRenderer } = useLeptosTunnels();
253
- const context = (0, import_react2.useContext)(ReactLeptosContext);
254
- (0, import_react2.useEffect)(() => {
255
- if (mountRef.current === null) return;
256
- const handle = Base.ftmlDocument(
257
- mountRef.current,
258
- args.document,
259
- context,
260
- toConfig(args, addTunnel)
261
- );
262
- return () => {
263
- handle.unmount();
264
- };
265
- }, []);
266
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { textAlign: "start" }, children: [
267
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: mountRef }),
268
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TunnelRenderer, {})
269
- ] });
270
- };
271
- var FTMLFragment = (args) => {
272
- const mountRef = (0, import_react2.useRef)(null);
273
- const { addTunnel, TunnelRenderer } = useLeptosTunnels();
274
- const context = (0, import_react2.useContext)(ReactLeptosContext);
275
- (0, import_react2.useEffect)(() => {
276
- if (!mountRef.current) return;
277
- const handle = Base.ftmlFragment(
278
- mountRef.current,
279
- args.fragment,
280
- context,
281
- toConfig(args, addTunnel)
282
- );
283
- return () => {
284
- handle.unmount();
285
- };
286
- }, []);
287
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { textAlign: "start" }, children: [
288
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: mountRef }),
289
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TunnelRenderer, {})
290
- ] });
291
- };
292
- // Annotate the CommonJS export names for ESM import in node:
293
- 0 && (module.exports = {
294
- FTML,
295
- FTMLDocument,
296
- FTMLFragment,
297
- FTMLSetup,
298
- getCurrentUri,
299
- initialize
300
- });
301
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.tsx","../src/leptos.tsx"],"sourcesContent":["import * as Base from \"@flexiformal/ftml\";\nexport * as FTML from \"@flexiformal/ftml\";\nimport { ReactNode, useContext, useEffect, useRef } from \"react\";\nimport {\n useLeptosTunnel,\n useLeptosTunnels,\n ReactLeptosContext,\n toConfig,\n} from \"./leptos\";\n\nexport const initialize = Base.initialize;\n\nexport function getCurrentUri(): Base.FTML.NarrativeUri | undefined {\n const context = useContext(ReactLeptosContext);\n if (context) {\n return Base.FTML.get_current_uri(context);\n }\n}\n\nexport interface FtmlConfig {\n allowHovers?: boolean;\n allowFullscreen?: boolean;\n allowFormalInfo?: boolean;\n allowNotationChanges?: boolean;\n chooseHighlightStyle?: boolean;\n showContent?: boolean;\n pdfLink?: boolean;\n highlightStyle?: Base.FTML.HighlightStyle;\n toc?: Base.FTML.TocSource;\n autoexpandLimit?: Base.FTML.LogicalLevel;\n tocProgress?: Base.FTML.TocProgress[];\n sectionWrap?: (\n uri: Base.FTML.DocumentElementUri,\n lvl: Base.FTML.SectionLevel,\n ) => ((ch: ReactNode) => ReactNode) | undefined;\n paragraphWrap?: (\n uri: Base.FTML.DocumentElementUri,\n kind: Base.FTML.ParagraphKind,\n ) => ((ch: ReactNode) => ReactNode) | undefined;\n slideWrap?: (\n uri: Base.FTML.DocumentElementUri,\n ) => ((ch: ReactNode) => ReactNode) | undefined;\n problemWrap?: (\n uri: Base.FTML.DocumentElementUri,\n subProblem: boolean,\n ) => ((ch: ReactNode) => ReactNode) | undefined;\n onSectionTitle?: (\n uri: Base.FTML.DocumentElementUri,\n lvl: Base.FTML.SectionLevel,\n ) => ReactNode | undefined;\n problemStates?: Base.FTML.ProblemStates;\n onProblemResponse?: (r: Base.FTML.ProblemResponse) => void;\n}\n\nexport interface FTMLSetupArgs extends FtmlConfig {\n children: ReactNode;\n}\n\n/**\n * Sets up Leptos' reactive system\n */\nexport const FTMLSetup: React.FC<FTMLSetupArgs> = (args) => {\n const mountRef = useRef<HTMLDivElement>(null);\n const main = useLeptosTunnel();\n const { addTunnel, TunnelRenderer } = useLeptosTunnels();\n const context = useContext(ReactLeptosContext);\n\n useEffect(() => {\n if (!mountRef.current) return;\n if (context) {\n const handle = Base.FTML.apply_config(\n toConfig(args, addTunnel),\n mountRef.current,\n context,\n );\n return () => {\n handle.unmount();\n };\n } else {\n const handle = Base.ftmlSetup(\n mountRef.current,\n (e, o) => {\n main.addTunnel(\n e,\n <>\n {args.children}\n <TunnelRenderer />\n </>,\n o,\n );\n },\n toConfig(args, addTunnel),\n );\n return () => {\n handle.unmount();\n };\n }\n }, []);\n\n return (\n <>\n <div ref={mountRef} style={{ display: \"contents\" }} />\n <main.TunnelRenderer />\n </>\n );\n};\n\n/**\n * See {@link FTMLConfig} and {@link FTML.DocumentOptions}\n */\nexport interface FTMLDocumentArgs extends FtmlConfig {\n document: Base.FTML.DocumentOptions;\n}\n\n/**\n * render an FTML document\n */\nexport const FTMLDocument: React.FC<FTMLDocumentArgs> = (args) => {\n const mountRef = useRef<HTMLDivElement>(null);\n const { addTunnel, TunnelRenderer } = useLeptosTunnels();\n const context = useContext(ReactLeptosContext);\n\n useEffect(() => {\n if (mountRef.current === null) return;\n const handle = Base.ftmlDocument(\n mountRef.current,\n args.document,\n context,\n toConfig(args, addTunnel),\n );\n return () => {\n handle.unmount();\n };\n }, []);\n return (\n <div style={{ textAlign: \"start\" }}>\n <div ref={mountRef} />\n <TunnelRenderer />\n </div>\n );\n};\n\n/**\n * See {@link FTMLConfig} and {@link Base.FTML.FragmentOptions}\n */\nexport interface FTMLFragmentArgs extends FtmlConfig {\n fragment: Base.FTML.FragmentOptions;\n}\n\n/**\n * render an FTML fragment\n */\nexport const FTMLFragment: React.FC<FTMLFragmentArgs> = (args) => {\n const mountRef = useRef<HTMLDivElement>(null);\n const { addTunnel, TunnelRenderer } = useLeptosTunnels();\n const context = useContext(ReactLeptosContext);\n\n useEffect(() => {\n if (!mountRef.current) return;\n const handle = Base.ftmlFragment(\n mountRef.current,\n args.fragment,\n context,\n toConfig(args, addTunnel),\n );\n return () => {\n handle.unmount();\n };\n }, []);\n return (\n <div style={{ textAlign: \"start\" }}>\n <div ref={mountRef} />\n <TunnelRenderer />\n </div>\n );\n};\n","import { createContext, ReactNode, useEffect, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { FTML } from \"@flexiformal/ftml\";\nimport { FtmlConfig } from \".\";\n\ntype LeptosContext = FTML.LeptosContext;\n\nexport const ReactLeptosContext = createContext<LeptosContext | undefined>(\n undefined,\n);\ninterface Tunnel {\n element: Element;\n node: ReactNode;\n context: LeptosContext;\n id: string; // for React keys\n}\n\nexport function toConfig(\n config: FtmlConfig,\n addTunnel: (\n element: Element,\n node: ReactNode,\n context: FTML.LeptosContext,\n ) => string,\n): FTML.FtmlConfig {\n let cfg: FTML.FtmlConfig = {\n allowHovers: config.allowHovers,\n allowFullscreen: config.allowFullscreen,\n allowFormalInfo: config.allowFormalInfo,\n allowNotationChanges: config.allowNotationChanges,\n chooseHighlightStyle: config.chooseHighlightStyle,\n showContent: config.showContent,\n pdfLink: config.pdfLink,\n toc: config.toc,\n tocProgress: config.tocProgress,\n autoexpandLimit: config.autoexpandLimit,\n onProblemResponse: config.onProblemResponse,\n problemStates: config.problemStates,\n };\n const ost = config.onSectionTitle;\n if (ost) {\n cfg.onSectionTitle = (u, lvl) => {\n return (e, ctx) => {\n addTunnel(e, ost(u, lvl), ctx);\n };\n };\n }\n const sect = config.sectionWrap;\n if (sect) {\n cfg.sectionWrap = (u, lvl) => {\n return (e, ctx) => {\n const r = sect(u, lvl);\n if (r) {\n addTunnel(e, r(elemToReact(e, ctx)), ctx);\n }\n };\n };\n }\n const para = config.paragraphWrap;\n if (para) {\n cfg.paragraphWrap = (u, knd) => {\n return (e, ctx) => {\n const r = para(u, knd);\n if (r) {\n addTunnel(e, r(elemToReact(e, ctx)), ctx);\n }\n };\n };\n }\n const slide = config.slideWrap;\n if (slide) {\n cfg.slideWrap = (u) => {\n return (e, ctx) => {\n const r = slide(u);\n if (r) {\n addTunnel(e, r(elemToReact(e, ctx)), ctx);\n }\n };\n };\n }\n const problem = config.problemWrap;\n if (problem) {\n cfg.problemWrap = (u, sub) => {\n return (e, ctx) => {\n const r = problem(u, sub);\n if (r) {\n addTunnel(e, r(elemToReact(e, ctx)), ctx);\n }\n };\n };\n }\n return cfg;\n}\n\nexport function elemToReact(\n elem: HTMLDivElement,\n ctx: FTML.LeptosContext,\n): ReactNode {\n const chs = Array.from(elem.childNodes);\n chs.forEach((c) => elem.removeChild(c));\n return <ElemToReact elems={chs} ctx={ctx} />;\n}\n\nconst ElemToReact: React.FC<{\n elems: ChildNode[];\n ctx: FTML.LeptosContext;\n}> = ({ elems, ctx }) => {\n const ref = useRef<HTMLDivElement>(null);\n const done = useRef<boolean>(false);\n useEffect(() => {\n if (ref.current && !done.current) {\n done.current = true;\n ref.current.replaceChildren(...elems);\n }\n }, []);\n return (\n <ReactLeptosContext.Provider value={ctx}>\n <div ref={ref} style={{ display: \"contents\" }} />\n </ReactLeptosContext.Provider>\n );\n};\n\nexport function useLeptosTunnel() {\n const [tunnel, setTunnel] = useState<Tunnel | undefined>(undefined);\n\n const addTunnel = (\n element: Element,\n node: ReactNode,\n context: LeptosContext,\n ) => {\n const id = Math.random().toString(36).slice(2);\n setTunnel({ element, node, id, context });\n return id; // Return id for later removal\n };\n\n const removeTunnel = () => {\n setTunnel(undefined);\n };\n\n const TunnelRenderer = () =>\n tunnel ? (\n createPortal(\n <ReactLeptosContext.Provider value={tunnel.context}>\n {tunnel.node}\n </ReactLeptosContext.Provider>,\n tunnel.element,\n tunnel.id,\n )\n ) : (\n <></>\n );\n\n useEffect(() => {\n return () => {\n if (tunnel) {\n //try{tunnel.context.cleanup();} catch (e){console.log(\"Error cleaning up leptos context:\",e)}\n }\n };\n });\n\n return {\n addTunnel,\n removeTunnel,\n TunnelRenderer,\n };\n}\n\nexport function useLeptosTunnels() {\n const [tunnels, setTunnels] = useState<Tunnel[]>([]);\n\n const addTunnel = (\n element: Element,\n node: ReactNode,\n context: LeptosContext,\n ) => {\n const id = Math.random().toString(36).slice(2);\n setTunnels((prev) => [...prev, { element, node, id, context }]);\n return id; // Return id for later removal\n };\n\n const removeTunnel = (id: string) => {\n setTunnels((prev) =>\n prev.filter((tunnel) => {\n if (tunnel.id === id) {\n //try{tunnel.context.cleanup();} catch (e){console.log(\"Error cleaning up leptos context:\",e)}\n }\n return tunnel.id !== id;\n }),\n );\n };\n\n const TunnelRenderer = () => (\n <>\n {tunnels.map((tunnel) =>\n createPortal(\n <ReactLeptosContext.Provider value={tunnel.context}>\n {tunnel.node}\n </ReactLeptosContext.Provider>,\n tunnel.element,\n tunnel.id,\n ),\n )}\n </>\n );\n\n useEffect(() => {\n return () => {\n tunnels.forEach((tunnel) => {\n //try{tunnel.context.cleanup();} catch (e){console.log(\"Error cleaning up leptos context:\",e)}\n });\n };\n });\n\n return {\n addTunnel,\n removeTunnel,\n TunnelRenderer,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,cAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,oBAAAC;AAAA;AAAA;AAAA,WAAsB;AACtB,IAAAD,QAAsB;AACtB,IAAAE,gBAAyD;;;ACFzD,mBAAsE;AACtE,uBAA6B;AAmGlB;AA7FJ,IAAM,yBAAqB;AAAA,EAC9B;AACJ;AAQO,SAAS,SACZ,QACA,WAKe;AACf,MAAI,MAAuB;AAAA,IACvB,aAAa,OAAO;AAAA,IACpB,iBAAiB,OAAO;AAAA,IACxB,iBAAiB,OAAO;AAAA,IACxB,sBAAsB,OAAO;AAAA,IAC7B,sBAAsB,OAAO;AAAA,IAC7B,aAAa,OAAO;AAAA,IACpB,SAAS,OAAO;AAAA,IAChB,KAAK,OAAO;AAAA,IACZ,aAAa,OAAO;AAAA,IACpB,iBAAiB,OAAO;AAAA,IACxB,mBAAmB,OAAO;AAAA,IAC1B,eAAe,OAAO;AAAA,EAC1B;AACA,QAAM,MAAM,OAAO;AACnB,MAAI,KAAK;AACL,QAAI,iBAAiB,CAAC,GAAG,QAAQ;AAC7B,aAAO,CAAC,GAAG,QAAQ;AACf,kBAAU,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG;AAAA,MACjC;AAAA,IACJ;AAAA,EACJ;AACA,QAAM,OAAO,OAAO;AACpB,MA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