hadars 0.1.17 → 0.1.19

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.
@@ -0,0 +1,911 @@
1
+ import {
2
+ FRAGMENT_TYPE,
3
+ Fragment,
4
+ REACT19_ELEMENT,
5
+ SLIM_ELEMENT,
6
+ SUSPENSE_TYPE,
7
+ createElement,
8
+ jsx
9
+ } from "../chunk-OS3V4CPN.js";
10
+
11
+ // src/slim-react/renderContext.ts
12
+ var GLOBAL_KEY = "__slimReactRenderState";
13
+ var EMPTY = { id: 0, overflow: "", bits: 0 };
14
+ function s() {
15
+ const g = globalThis;
16
+ if (!g[GLOBAL_KEY]) {
17
+ g[GLOBAL_KEY] = { currentTreeContext: { ...EMPTY }, localIdCounter: 0, idPrefix: "" };
18
+ }
19
+ return g[GLOBAL_KEY];
20
+ }
21
+ function resetRenderState() {
22
+ const st = s();
23
+ st.currentTreeContext = { ...EMPTY };
24
+ st.localIdCounter = 0;
25
+ }
26
+ function pushTreeContext(totalChildren, index) {
27
+ const st = s();
28
+ const saved = { ...st.currentTreeContext };
29
+ const pendingBits = 32 - Math.clz32(totalChildren);
30
+ const slot = index + 1;
31
+ const totalBits = st.currentTreeContext.bits + pendingBits;
32
+ if (totalBits <= 30) {
33
+ st.currentTreeContext = {
34
+ id: st.currentTreeContext.id << pendingBits | slot,
35
+ overflow: st.currentTreeContext.overflow,
36
+ bits: totalBits
37
+ };
38
+ } else {
39
+ let newOverflow = st.currentTreeContext.overflow;
40
+ if (st.currentTreeContext.bits > 0)
41
+ newOverflow += st.currentTreeContext.id.toString(32);
42
+ st.currentTreeContext = { id: 1 << pendingBits | slot, overflow: newOverflow, bits: pendingBits };
43
+ }
44
+ return saved;
45
+ }
46
+ function popTreeContext(saved) {
47
+ s().currentTreeContext = saved;
48
+ }
49
+ function pushComponentScope() {
50
+ const st = s();
51
+ const saved = st.localIdCounter;
52
+ st.localIdCounter = 0;
53
+ return saved;
54
+ }
55
+ function popComponentScope(saved) {
56
+ s().localIdCounter = saved;
57
+ }
58
+ function snapshotContext() {
59
+ const st = s();
60
+ return { tree: { ...st.currentTreeContext }, localId: st.localIdCounter };
61
+ }
62
+ function restoreContext(snap) {
63
+ const st = s();
64
+ st.currentTreeContext = { ...snap.tree };
65
+ st.localIdCounter = snap.localId;
66
+ }
67
+ function getTreeId() {
68
+ const { id, overflow, bits } = s().currentTreeContext;
69
+ return bits > 0 ? overflow + id.toString(32) : overflow;
70
+ }
71
+ function makeId() {
72
+ const st = s();
73
+ const treeId = getTreeId();
74
+ const n = st.localIdCounter++;
75
+ let id = ":" + st.idPrefix + "R";
76
+ if (treeId.length > 0)
77
+ id += treeId;
78
+ id += ":";
79
+ if (n > 0)
80
+ id += "H" + n.toString(32) + ":";
81
+ return id;
82
+ }
83
+
84
+ // src/slim-react/hooks.ts
85
+ function useState(initialState) {
86
+ const value = typeof initialState === "function" ? initialState() : initialState;
87
+ return [value, () => {
88
+ }];
89
+ }
90
+ function useReducer(_reducer, initialState) {
91
+ return [initialState, () => {
92
+ }];
93
+ }
94
+ function useEffect(_effect, _deps) {
95
+ }
96
+ function useLayoutEffect(_effect, _deps) {
97
+ }
98
+ function useInsertionEffect(_effect, _deps) {
99
+ }
100
+ function useRef(initialValue) {
101
+ return { current: initialValue };
102
+ }
103
+ function useMemo(factory, _deps) {
104
+ return factory();
105
+ }
106
+ function useCallback(callback, _deps) {
107
+ return callback;
108
+ }
109
+ function useId() {
110
+ return makeId();
111
+ }
112
+ function useDebugValue(_value, _format) {
113
+ }
114
+ function useImperativeHandle(_ref, _createHandle, _deps) {
115
+ }
116
+ function useSyncExternalStore(_subscribe, getSnapshot, getServerSnapshot) {
117
+ return (getServerSnapshot || getSnapshot)();
118
+ }
119
+ function useTransition() {
120
+ return [false, (cb) => cb()];
121
+ }
122
+ function useDeferredValue(value) {
123
+ return value;
124
+ }
125
+ function useOptimistic(passthrough) {
126
+ return [passthrough, () => {
127
+ }];
128
+ }
129
+ function useFormStatus() {
130
+ return { pending: false, data: null, method: null, action: null };
131
+ }
132
+ function useActionState(_action, initialState, _permalink) {
133
+ return [initialState, () => {
134
+ }, false];
135
+ }
136
+ function use(usable) {
137
+ if (typeof usable === "object" && usable !== null && "_currentValue" in usable) {
138
+ return usable._currentValue;
139
+ }
140
+ const promise = usable;
141
+ if (promise.status === "fulfilled")
142
+ return promise.value;
143
+ if (promise.status === "rejected")
144
+ throw promise.reason;
145
+ throw promise;
146
+ }
147
+ function startTransition(callback) {
148
+ callback();
149
+ }
150
+
151
+ // src/slim-react/context.ts
152
+ function createContext(defaultValue) {
153
+ const context = {
154
+ _currentValue: defaultValue,
155
+ Provider: null,
156
+ Consumer: null
157
+ };
158
+ const Provider = function ContextProvider({
159
+ children
160
+ }) {
161
+ return children ?? null;
162
+ };
163
+ Provider._context = context;
164
+ context.Provider = Provider;
165
+ context.Consumer = ({ children }) => {
166
+ return children(
167
+ context._currentValue
168
+ );
169
+ };
170
+ return context;
171
+ }
172
+
173
+ // src/slim-react/render.ts
174
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
175
+ "area",
176
+ "base",
177
+ "br",
178
+ "col",
179
+ "embed",
180
+ "hr",
181
+ "img",
182
+ "input",
183
+ "link",
184
+ "meta",
185
+ "param",
186
+ "source",
187
+ "track",
188
+ "wbr"
189
+ ]);
190
+ function escapeHtml(str) {
191
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&#x27;");
192
+ }
193
+ function escapeAttr(str) {
194
+ return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
195
+ }
196
+ function styleObjectToString(style) {
197
+ return Object.entries(style).map(([key, value]) => {
198
+ const cssKey = key.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
199
+ return `${cssKey}:${value}`;
200
+ }).join(";");
201
+ }
202
+ var SVG_ATTR_MAP = {
203
+ // Presentation / geometry
204
+ accentHeight: "accent-height",
205
+ alignmentBaseline: "alignment-baseline",
206
+ arabicForm: "arabic-form",
207
+ baselineShift: "baseline-shift",
208
+ capHeight: "cap-height",
209
+ clipPath: "clip-path",
210
+ clipRule: "clip-rule",
211
+ colorInterpolation: "color-interpolation",
212
+ colorInterpolationFilters: "color-interpolation-filters",
213
+ colorProfile: "color-profile",
214
+ dominantBaseline: "dominant-baseline",
215
+ enableBackground: "enable-background",
216
+ fillOpacity: "fill-opacity",
217
+ fillRule: "fill-rule",
218
+ floodColor: "flood-color",
219
+ floodOpacity: "flood-opacity",
220
+ fontFamily: "font-family",
221
+ fontSize: "font-size",
222
+ fontSizeAdjust: "font-size-adjust",
223
+ fontStretch: "font-stretch",
224
+ fontStyle: "font-style",
225
+ fontVariant: "font-variant",
226
+ fontWeight: "font-weight",
227
+ glyphName: "glyph-name",
228
+ glyphOrientationHorizontal: "glyph-orientation-horizontal",
229
+ glyphOrientationVertical: "glyph-orientation-vertical",
230
+ horizAdvX: "horiz-adv-x",
231
+ horizOriginX: "horiz-origin-x",
232
+ imageRendering: "image-rendering",
233
+ letterSpacing: "letter-spacing",
234
+ lightingColor: "lighting-color",
235
+ markerEnd: "marker-end",
236
+ markerMid: "marker-mid",
237
+ markerStart: "marker-start",
238
+ overlinePosition: "overline-position",
239
+ overlineThickness: "overline-thickness",
240
+ paintOrder: "paint-order",
241
+ panose1: "panose-1",
242
+ pointerEvents: "pointer-events",
243
+ renderingIntent: "rendering-intent",
244
+ shapeRendering: "shape-rendering",
245
+ stopColor: "stop-color",
246
+ stopOpacity: "stop-opacity",
247
+ strikethroughPosition: "strikethrough-position",
248
+ strikethroughThickness: "strikethrough-thickness",
249
+ strokeDasharray: "stroke-dasharray",
250
+ strokeDashoffset: "stroke-dashoffset",
251
+ strokeLinecap: "stroke-linecap",
252
+ strokeLinejoin: "stroke-linejoin",
253
+ strokeMiterlimit: "stroke-miterlimit",
254
+ strokeOpacity: "stroke-opacity",
255
+ strokeWidth: "stroke-width",
256
+ textAnchor: "text-anchor",
257
+ textDecoration: "text-decoration",
258
+ textRendering: "text-rendering",
259
+ underlinePosition: "underline-position",
260
+ underlineThickness: "underline-thickness",
261
+ unicodeBidi: "unicode-bidi",
262
+ unicodeRange: "unicode-range",
263
+ unitsPerEm: "units-per-em",
264
+ vAlphabetic: "v-alphabetic",
265
+ vHanging: "v-hanging",
266
+ vIdeographic: "v-ideographic",
267
+ vMathematical: "v-mathematical",
268
+ vertAdvY: "vert-adv-y",
269
+ vertOriginX: "vert-origin-x",
270
+ vertOriginY: "vert-origin-y",
271
+ wordSpacing: "word-spacing",
272
+ writingMode: "writing-mode",
273
+ xHeight: "x-height",
274
+ // Namespace-prefixed
275
+ xlinkActuate: "xlink:actuate",
276
+ xlinkArcrole: "xlink:arcrole",
277
+ xlinkHref: "xlink:href",
278
+ xlinkRole: "xlink:role",
279
+ xlinkShow: "xlink:show",
280
+ xlinkTitle: "xlink:title",
281
+ xlinkType: "xlink:type",
282
+ xmlBase: "xml:base",
283
+ xmlLang: "xml:lang",
284
+ xmlSpace: "xml:space",
285
+ xmlns: "xmlns",
286
+ xmlnsXlink: "xmlns:xlink",
287
+ // Filter / lighting
288
+ baseFrequency: "baseFrequency",
289
+ colorInterpolation_filters: "color-interpolation-filters",
290
+ diffuseConstant: "diffuseConstant",
291
+ edgeMode: "edgeMode",
292
+ filterUnits: "filterUnits",
293
+ gradientTransform: "gradientTransform",
294
+ gradientUnits: "gradientUnits",
295
+ kernelMatrix: "kernelMatrix",
296
+ kernelUnitLength: "kernelUnitLength",
297
+ lengthAdjust: "lengthAdjust",
298
+ limitingConeAngle: "limitingConeAngle",
299
+ markerHeight: "markerHeight",
300
+ markerWidth: "markerWidth",
301
+ maskContentUnits: "maskContentUnits",
302
+ maskUnits: "maskUnits",
303
+ numOctaves: "numOctaves",
304
+ pathLength: "pathLength",
305
+ patternContentUnits: "patternContentUnits",
306
+ patternTransform: "patternTransform",
307
+ patternUnits: "patternUnits",
308
+ pointsAtX: "pointsAtX",
309
+ pointsAtY: "pointsAtY",
310
+ pointsAtZ: "pointsAtZ",
311
+ preserveAspectRatio: "preserveAspectRatio",
312
+ primitiveUnits: "primitiveUnits",
313
+ refX: "refX",
314
+ refY: "refY",
315
+ repeatCount: "repeatCount",
316
+ repeatDur: "repeatDur",
317
+ specularConstant: "specularConstant",
318
+ specularExponent: "specularExponent",
319
+ spreadMethod: "spreadMethod",
320
+ startOffset: "startOffset",
321
+ stdDeviation: "stdDeviation",
322
+ stitchTiles: "stitchTiles",
323
+ surfaceScale: "surfaceScale",
324
+ systemLanguage: "systemLanguage",
325
+ tableValues: "tableValues",
326
+ targetX: "targetX",
327
+ targetY: "targetY",
328
+ textLength: "textLength",
329
+ viewBox: "viewBox",
330
+ xChannelSelector: "xChannelSelector",
331
+ yChannelSelector: "yChannelSelector"
332
+ };
333
+ function renderAttributes(props, isSvg) {
334
+ let attrs = "";
335
+ for (const [key, value] of Object.entries(props)) {
336
+ if (key === "children" || key === "key" || key === "ref" || key === "dangerouslySetInnerHTML" || key === "suppressHydrationWarning" || key === "suppressContentEditableWarning")
337
+ continue;
338
+ if (key.startsWith("on") && key.length > 2 && key[2] === key[2].toUpperCase())
339
+ continue;
340
+ let attrName;
341
+ if (isSvg && key in SVG_ATTR_MAP) {
342
+ attrName = SVG_ATTR_MAP[key];
343
+ } else {
344
+ attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key;
345
+ }
346
+ if (value === false || value == null) {
347
+ if (value === false && (attrName.startsWith("aria-") || attrName.startsWith("data-"))) {
348
+ attrs += ` ${attrName}="false"`;
349
+ }
350
+ continue;
351
+ }
352
+ if (value === true) {
353
+ attrs += ` ${attrName}=""`;
354
+ continue;
355
+ }
356
+ if (key === "style" && typeof value === "object") {
357
+ attrs += ` style="${escapeAttr(styleObjectToString(value))}"`;
358
+ continue;
359
+ }
360
+ attrs += ` ${attrName}="${escapeAttr(String(value))}"`;
361
+ }
362
+ return attrs;
363
+ }
364
+ var BufferWriter = class {
365
+ chunks = [];
366
+ lastWasText = false;
367
+ write(chunk) {
368
+ this.chunks.push(chunk);
369
+ this.lastWasText = false;
370
+ }
371
+ text(s2) {
372
+ this.chunks.push(s2);
373
+ this.lastWasText = true;
374
+ }
375
+ flush(target) {
376
+ for (const c of this.chunks)
377
+ target.write(c);
378
+ target.lastWasText = this.lastWasText;
379
+ }
380
+ };
381
+ function renderNode(node, writer, isSvg = false) {
382
+ if (node == null || typeof node === "boolean")
383
+ return;
384
+ if (typeof node === "string") {
385
+ writer.text(escapeHtml(node));
386
+ return;
387
+ }
388
+ if (typeof node === "number") {
389
+ writer.text(String(node));
390
+ return;
391
+ }
392
+ if (Array.isArray(node)) {
393
+ return renderChildArray(node, writer, isSvg);
394
+ }
395
+ if (typeof node === "object" && node !== null && Symbol.iterator in node && !("$$typeof" in node)) {
396
+ return renderChildArray(
397
+ Array.from(node),
398
+ writer,
399
+ isSvg
400
+ );
401
+ }
402
+ if (typeof node === "object" && node !== null && "$$typeof" in node) {
403
+ const elType = node["$$typeof"];
404
+ if (elType !== SLIM_ELEMENT && elType !== REACT19_ELEMENT)
405
+ return;
406
+ const element = node;
407
+ const { type, props } = element;
408
+ if (type === FRAGMENT_TYPE) {
409
+ return renderChildren(props.children, writer, isSvg);
410
+ }
411
+ if (type === SUSPENSE_TYPE) {
412
+ return renderSuspense(props, writer, isSvg);
413
+ }
414
+ if (typeof type === "function") {
415
+ return renderComponent(type, props, writer, isSvg);
416
+ }
417
+ if (typeof type === "object" && type !== null) {
418
+ return renderComponent(type, props, writer, isSvg);
419
+ }
420
+ if (typeof type === "string") {
421
+ return renderHostElement(type, props, writer, isSvg);
422
+ }
423
+ }
424
+ }
425
+ function markSelectedOptionsMulti(children, selectedValues) {
426
+ if (children == null || typeof children === "boolean")
427
+ return children;
428
+ if (typeof children === "string" || typeof children === "number")
429
+ return children;
430
+ if (Array.isArray(children)) {
431
+ return children.map((c) => markSelectedOptionsMulti(c, selectedValues));
432
+ }
433
+ if (typeof children === "object" && "$$typeof" in children) {
434
+ const elType = children["$$typeof"];
435
+ if (elType !== SLIM_ELEMENT && elType !== REACT19_ELEMENT)
436
+ return children;
437
+ const el = children;
438
+ if (el.type === "option") {
439
+ const optValue = el.props.value !== void 0 ? el.props.value : el.props.children;
440
+ const isSelected = selectedValues.has(String(optValue));
441
+ return { ...el, props: { ...el.props, selected: isSelected || void 0 } };
442
+ }
443
+ if (el.type === "optgroup" || el.type === FRAGMENT_TYPE) {
444
+ const newChildren = markSelectedOptionsMulti(el.props.children, selectedValues);
445
+ return { ...el, props: { ...el.props, children: newChildren } };
446
+ }
447
+ }
448
+ return children;
449
+ }
450
+ function renderHostElement(tag, props, writer, isSvg) {
451
+ const enteringSvg = tag === "svg";
452
+ const childSvg = isSvg || enteringSvg;
453
+ if (tag === "textarea") {
454
+ const textContent = props.value ?? props.defaultValue ?? props.children ?? "";
455
+ const filteredProps = {};
456
+ for (const k of Object.keys(props)) {
457
+ if (k !== "value" && k !== "defaultValue" && k !== "children")
458
+ filteredProps[k] = props[k];
459
+ }
460
+ writer.write(`<textarea${renderAttributes(filteredProps, false)}>`);
461
+ writer.text(escapeHtml(String(textContent)));
462
+ writer.write("</textarea>");
463
+ return;
464
+ }
465
+ if (tag === "select") {
466
+ const selectedValue = props.value ?? props.defaultValue;
467
+ const filteredProps = {};
468
+ for (const k of Object.keys(props)) {
469
+ if (k !== "value" && k !== "defaultValue")
470
+ filteredProps[k] = props[k];
471
+ }
472
+ writer.write(`<select${renderAttributes(filteredProps, false)}>`);
473
+ const selectedSet = selectedValue == null ? null : Array.isArray(selectedValue) ? new Set(selectedValue.map(String)) : /* @__PURE__ */ new Set([String(selectedValue)]);
474
+ const patchedChildren = selectedSet != null ? markSelectedOptionsMulti(props.children, selectedSet) : props.children;
475
+ const inner2 = renderChildren(patchedChildren, writer, false);
476
+ if (inner2 && typeof inner2.then === "function") {
477
+ return inner2.then(() => {
478
+ writer.write("</select>");
479
+ });
480
+ }
481
+ writer.write("</select>");
482
+ return;
483
+ }
484
+ writer.write(`<${tag}${renderAttributes(props, childSvg)}`);
485
+ if (VOID_ELEMENTS.has(tag)) {
486
+ writer.write("/>");
487
+ return;
488
+ }
489
+ writer.write(">");
490
+ const childContext = tag === "foreignObject" ? false : childSvg;
491
+ let inner = void 0;
492
+ if (props.dangerouslySetInnerHTML) {
493
+ writer.write(props.dangerouslySetInnerHTML.__html);
494
+ } else {
495
+ inner = renderChildren(props.children, writer, childContext);
496
+ }
497
+ if (inner && typeof inner.then === "function") {
498
+ return inner.then(() => {
499
+ writer.write(`</${tag}>`);
500
+ });
501
+ }
502
+ writer.write(`</${tag}>`);
503
+ }
504
+ var REACT_MEMO = Symbol.for("react.memo");
505
+ var REACT_FORWARD_REF = Symbol.for("react.forward_ref");
506
+ var REACT_PROVIDER = Symbol.for("react.provider");
507
+ var REACT_CONTEXT = Symbol.for("react.context");
508
+ var REACT_CONSUMER = Symbol.for("react.consumer");
509
+ var REACT_LAZY = Symbol.for("react.lazy");
510
+ function renderComponent(type, props, writer, isSvg) {
511
+ const typeOf = type?.$$typeof;
512
+ if (typeOf === REACT_MEMO) {
513
+ return renderNode(
514
+ { $$typeof: SLIM_ELEMENT, type: type.type, props, key: null },
515
+ writer,
516
+ isSvg
517
+ );
518
+ }
519
+ if (typeOf === REACT_FORWARD_REF) {
520
+ return renderComponent(type.render, props, writer, isSvg);
521
+ }
522
+ if (typeOf === REACT_LAZY) {
523
+ const resolved = type._init(type._payload);
524
+ const LazyComp = resolved?.default ?? resolved;
525
+ return renderComponent(LazyComp, props, writer, isSvg);
526
+ }
527
+ if (typeOf === REACT_CONSUMER) {
528
+ const ctx2 = type._context;
529
+ const value = ctx2?._currentValue;
530
+ const result2 = typeof props.children === "function" ? props.children(value) : null;
531
+ const savedScope2 = pushComponentScope();
532
+ const finish2 = () => popComponentScope(savedScope2);
533
+ const r2 = renderNode(result2, writer, isSvg);
534
+ if (r2 && typeof r2.then === "function") {
535
+ return r2.then(finish2);
536
+ }
537
+ finish2();
538
+ return;
539
+ }
540
+ const isProvider = "_context" in type || typeOf === REACT_PROVIDER || typeOf === REACT_CONTEXT && "value" in props;
541
+ let prevCtxValue;
542
+ let ctx;
543
+ if (isProvider) {
544
+ ctx = type._context ?? type;
545
+ prevCtxValue = ctx._currentValue;
546
+ ctx._currentValue = props.value;
547
+ }
548
+ const savedScope = pushComponentScope();
549
+ if (isProvider && typeof type !== "function") {
550
+ const finish2 = () => {
551
+ popComponentScope(savedScope);
552
+ ctx._currentValue = prevCtxValue;
553
+ };
554
+ const r2 = renderChildren(props.children, writer, isSvg);
555
+ if (r2 && typeof r2.then === "function") {
556
+ return r2.then(finish2);
557
+ }
558
+ finish2();
559
+ return;
560
+ }
561
+ let result;
562
+ try {
563
+ if (type.prototype && typeof type.prototype.render === "function") {
564
+ const instance = new type(props);
565
+ if (typeof type.getDerivedStateFromProps === "function") {
566
+ const derived = type.getDerivedStateFromProps(props, instance.state ?? {});
567
+ if (derived != null)
568
+ instance.state = { ...instance.state ?? {}, ...derived };
569
+ }
570
+ result = instance.render();
571
+ } else {
572
+ result = type(props);
573
+ }
574
+ } catch (e) {
575
+ popComponentScope(savedScope);
576
+ if (isProvider)
577
+ ctx._currentValue = prevCtxValue;
578
+ throw e;
579
+ }
580
+ const finish = () => {
581
+ popComponentScope(savedScope);
582
+ if (isProvider)
583
+ ctx._currentValue = prevCtxValue;
584
+ };
585
+ if (result instanceof Promise) {
586
+ return result.then((resolved) => {
587
+ const r2 = renderNode(resolved, writer, isSvg);
588
+ if (r2 && typeof r2.then === "function") {
589
+ return r2.then(finish);
590
+ }
591
+ finish();
592
+ });
593
+ }
594
+ const r = renderNode(result, writer, isSvg);
595
+ if (r && typeof r.then === "function") {
596
+ return r.then(finish);
597
+ }
598
+ finish();
599
+ }
600
+ function isTextLike(node) {
601
+ return typeof node === "string" || typeof node === "number";
602
+ }
603
+ function renderChildArray(children, writer, isSvg) {
604
+ const totalChildren = children.length;
605
+ for (let i = 0; i < totalChildren; i++) {
606
+ if (isTextLike(children[i]) && writer.lastWasText) {
607
+ writer.write("<!-- -->");
608
+ }
609
+ const savedTree = pushTreeContext(totalChildren, i);
610
+ const r = renderNode(children[i], writer, isSvg);
611
+ if (r && typeof r.then === "function") {
612
+ return r.then(() => {
613
+ popTreeContext(savedTree);
614
+ return renderChildArrayFrom(children, i + 1, writer, isSvg);
615
+ });
616
+ }
617
+ popTreeContext(savedTree);
618
+ }
619
+ }
620
+ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
621
+ const totalChildren = children.length;
622
+ for (let i = startIndex; i < totalChildren; i++) {
623
+ if (isTextLike(children[i]) && writer.lastWasText) {
624
+ writer.write("<!-- -->");
625
+ }
626
+ const savedTree = pushTreeContext(totalChildren, i);
627
+ const r = renderNode(children[i], writer, isSvg);
628
+ if (r && typeof r.then === "function") {
629
+ return r.then(() => {
630
+ popTreeContext(savedTree);
631
+ return renderChildArrayFrom(children, i + 1, writer, isSvg);
632
+ });
633
+ }
634
+ popTreeContext(savedTree);
635
+ }
636
+ }
637
+ function renderChildren(children, writer, isSvg = false) {
638
+ if (children == null)
639
+ return;
640
+ if (Array.isArray(children)) {
641
+ return renderChildArray(children, writer, isSvg);
642
+ }
643
+ return renderNode(children, writer, isSvg);
644
+ }
645
+ var MAX_SUSPENSE_RETRIES = 25;
646
+ async function renderSuspense(props, writer, isSvg = false) {
647
+ const { children, fallback } = props;
648
+ let attempts = 0;
649
+ const snap = snapshotContext();
650
+ while (attempts < MAX_SUSPENSE_RETRIES) {
651
+ restoreContext(snap);
652
+ try {
653
+ const buffer = new BufferWriter();
654
+ const r = renderNode(children, buffer, isSvg);
655
+ if (r && typeof r.then === "function") {
656
+ await r;
657
+ }
658
+ writer.write("<!--$-->");
659
+ buffer.flush(writer);
660
+ writer.write("<!--/$-->");
661
+ return;
662
+ } catch (error) {
663
+ if (error && typeof error.then === "function") {
664
+ await error;
665
+ attempts++;
666
+ } else {
667
+ throw error;
668
+ }
669
+ }
670
+ }
671
+ restoreContext(snap);
672
+ writer.write("<!--$?-->");
673
+ if (fallback) {
674
+ const r = renderNode(fallback, writer, isSvg);
675
+ if (r && typeof r.then === "function")
676
+ await r;
677
+ }
678
+ writer.write("<!--/$-->");
679
+ }
680
+ function renderToStream(element) {
681
+ const encoder = new TextEncoder();
682
+ return new ReadableStream({
683
+ async start(controller) {
684
+ resetRenderState();
685
+ const writer = {
686
+ lastWasText: false,
687
+ write(chunk) {
688
+ controller.enqueue(encoder.encode(chunk));
689
+ this.lastWasText = false;
690
+ },
691
+ text(s2) {
692
+ controller.enqueue(encoder.encode(s2));
693
+ this.lastWasText = true;
694
+ }
695
+ };
696
+ try {
697
+ const r = renderNode(element, writer);
698
+ if (r && typeof r.then === "function")
699
+ await r;
700
+ controller.close();
701
+ } catch (error) {
702
+ controller.error(error);
703
+ }
704
+ }
705
+ });
706
+ }
707
+ async function renderToString(element) {
708
+ for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
709
+ resetRenderState();
710
+ const chunks = [];
711
+ const writer = {
712
+ lastWasText: false,
713
+ write(c) {
714
+ chunks.push(c);
715
+ this.lastWasText = false;
716
+ },
717
+ text(s2) {
718
+ chunks.push(s2);
719
+ this.lastWasText = true;
720
+ }
721
+ };
722
+ try {
723
+ const r = renderNode(element, writer);
724
+ if (r && typeof r.then === "function")
725
+ await r;
726
+ return chunks.join("");
727
+ } catch (error) {
728
+ if (error && typeof error.then === "function") {
729
+ await error;
730
+ continue;
731
+ }
732
+ throw error;
733
+ }
734
+ }
735
+ throw new Error("[slim-react] renderToString exceeded maximum retries");
736
+ }
737
+
738
+ // src/slim-react/index.ts
739
+ function useContext(context) {
740
+ return context._currentValue;
741
+ }
742
+ var Suspense = SUSPENSE_TYPE;
743
+ function isValidElement(obj) {
744
+ return typeof obj === "object" && obj !== null && obj.$$typeof === SLIM_ELEMENT;
745
+ }
746
+ function cloneElement(element, overrideProps, ...children) {
747
+ return {
748
+ $$typeof: SLIM_ELEMENT,
749
+ type: element.type,
750
+ props: {
751
+ ...element.props,
752
+ ...overrideProps,
753
+ ...children.length === 1 ? { children: children[0] } : children.length > 1 ? { children } : {}
754
+ },
755
+ key: overrideProps?.key ?? element.key
756
+ };
757
+ }
758
+ function forwardRef(render) {
759
+ const component = (props) => render(props, props.ref ?? null);
760
+ component.displayName = render.displayName || render.name || "ForwardRef";
761
+ return component;
762
+ }
763
+ function memo(component) {
764
+ return component;
765
+ }
766
+ function lazy(factory) {
767
+ let resolved = null;
768
+ let promise = null;
769
+ return function LazyComponent(props) {
770
+ if (resolved)
771
+ return resolved(props);
772
+ if (!promise) {
773
+ promise = factory().then((mod) => {
774
+ resolved = mod.default;
775
+ });
776
+ }
777
+ throw promise;
778
+ };
779
+ }
780
+ function toFlatArray(children) {
781
+ if (children == null || typeof children === "boolean")
782
+ return [];
783
+ if (Array.isArray(children))
784
+ return children.flatMap(toFlatArray);
785
+ return [children];
786
+ }
787
+ var Children = {
788
+ map(children, fn) {
789
+ return toFlatArray(children).map((child, i) => fn(child, i));
790
+ },
791
+ forEach(children, fn) {
792
+ toFlatArray(children).forEach((child, i) => fn(child, i));
793
+ },
794
+ count(children) {
795
+ return toFlatArray(children).length;
796
+ },
797
+ only(children) {
798
+ const arr = toFlatArray(children);
799
+ if (arr.length !== 1)
800
+ throw new Error("Children.only expected one child");
801
+ return arr[0];
802
+ },
803
+ toArray: toFlatArray
804
+ };
805
+ var Component = class {
806
+ props;
807
+ state;
808
+ context;
809
+ constructor(props) {
810
+ this.props = props;
811
+ this.state = {};
812
+ }
813
+ setState(_partial) {
814
+ }
815
+ forceUpdate() {
816
+ }
817
+ render() {
818
+ return null;
819
+ }
820
+ };
821
+ var PureComponent = class extends Component {
822
+ };
823
+ var React = {
824
+ // Hooks
825
+ useState,
826
+ useReducer,
827
+ useEffect,
828
+ useLayoutEffect,
829
+ useInsertionEffect,
830
+ useRef,
831
+ useMemo,
832
+ useCallback,
833
+ useId,
834
+ useDebugValue,
835
+ useImperativeHandle,
836
+ useSyncExternalStore,
837
+ useTransition,
838
+ useDeferredValue,
839
+ useOptimistic,
840
+ useFormStatus,
841
+ useActionState,
842
+ use,
843
+ startTransition,
844
+ // Context
845
+ createContext,
846
+ useContext,
847
+ // Elements
848
+ createElement,
849
+ cloneElement,
850
+ isValidElement,
851
+ forwardRef,
852
+ memo,
853
+ lazy,
854
+ Fragment,
855
+ Suspense,
856
+ // Compat
857
+ Children,
858
+ Component,
859
+ PureComponent,
860
+ // Rendering
861
+ renderToStream,
862
+ renderToString,
863
+ renderToReadableStream: renderToStream,
864
+ // Version stub
865
+ version: "19.0.0-slim"
866
+ };
867
+ var slim_react_default = React;
868
+ export {
869
+ Children,
870
+ Component,
871
+ FRAGMENT_TYPE,
872
+ Fragment,
873
+ PureComponent,
874
+ SLIM_ELEMENT,
875
+ SUSPENSE_TYPE,
876
+ Suspense,
877
+ cloneElement,
878
+ createContext,
879
+ createElement,
880
+ slim_react_default as default,
881
+ forwardRef,
882
+ isValidElement,
883
+ jsx,
884
+ jsx as jsxDEV,
885
+ jsx as jsxs,
886
+ lazy,
887
+ memo,
888
+ renderToStream as renderToReadableStream,
889
+ renderToStream,
890
+ renderToString,
891
+ startTransition,
892
+ use,
893
+ useActionState,
894
+ useCallback,
895
+ useContext,
896
+ useDebugValue,
897
+ useDeferredValue,
898
+ useEffect,
899
+ useFormStatus,
900
+ useId,
901
+ useImperativeHandle,
902
+ useInsertionEffect,
903
+ useLayoutEffect,
904
+ useMemo,
905
+ useOptimistic,
906
+ useReducer,
907
+ useRef,
908
+ useState,
909
+ useSyncExternalStore,
910
+ useTransition
911
+ };