hadars 0.1.35 → 0.1.37

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