react-state-basis 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -41,11 +41,13 @@ __export(index_exports, {
41
41
  Suspense: () => Suspense2,
42
42
  __testEngine__: () => __testEngine__,
43
43
  __test__: () => __test__,
44
+ basis: () => basis,
44
45
  beginEffectTracking: () => beginEffectTracking,
45
46
  cloneElement: () => cloneElement2,
46
47
  config: () => config,
47
48
  configureBasis: () => configureBasis,
48
49
  createContext: () => createContext2,
50
+ createElement: () => createElement2,
49
51
  createPortal: () => createPortal,
50
52
  createRef: () => createRef2,
51
53
  currentTickBatch: () => currentTickBatch,
@@ -77,8 +79,8 @@ __export(index_exports, {
77
79
  useMemo: () => useMemo,
78
80
  useOptimistic: () => useOptimistic2,
79
81
  useReducer: () => useReducer,
80
- useRef: () => useRef,
81
- useState: () => useState,
82
+ useRef: () => useRef2,
83
+ useState: () => useState2,
82
84
  useSyncExternalStore: () => useSyncExternalStore,
83
85
  useTransition: () => useTransition,
84
86
  version: () => version2
@@ -307,96 +309,118 @@ var LOOP_WINDOW_MS = 500;
307
309
  var ANALYSIS_INTERVAL = 5;
308
310
 
309
311
  // src/engine.ts
310
- var config = {
311
- debug: false
312
+ var GLOBAL_KEY = "__BASIS_ENGINE_INSTANCE__";
313
+ var getGlobalInstance = () => {
314
+ const g = typeof window !== "undefined" ? window : global;
315
+ if (!g[GLOBAL_KEY]) {
316
+ g[GLOBAL_KEY] = {
317
+ config: { debug: false },
318
+ history: /* @__PURE__ */ new Map(),
319
+ currentTickBatch: /* @__PURE__ */ new Set(),
320
+ redundantLabels: /* @__PURE__ */ new Set(),
321
+ booted: false,
322
+ updateLog: [],
323
+ tick: 0,
324
+ isBatching: false,
325
+ currentEffectSource: null
326
+ };
327
+ }
328
+ return g[GLOBAL_KEY];
312
329
  };
313
- var booted = false;
330
+ var instance = getGlobalInstance();
331
+ var config = instance.config;
332
+ var history = instance.history;
333
+ var currentTickBatch = instance.currentTickBatch;
334
+ var redundantLabels = instance.redundantLabels;
314
335
  var configureBasis = (newConfig) => {
315
- config = { ...config, ...newConfig };
316
- if (config.debug && !booted) {
336
+ Object.assign(instance.config, newConfig);
337
+ if (instance.config.debug && !instance.booted) {
317
338
  displayBootLog(WINDOW_SIZE);
318
- booted = true;
339
+ instance.booted = true;
319
340
  }
320
341
  };
321
- var history = /* @__PURE__ */ new Map();
322
- var currentTickBatch = /* @__PURE__ */ new Set();
323
- var updateLog = [];
324
- var currentEffectSource = null;
325
- var tick = 0;
326
- var isBatching = false;
327
342
  var analyzeBasis = () => {
328
- if (!config.debug) return;
329
- const entries = Array.from(history.entries());
343
+ if (!instance.config.debug) {
344
+ instance.redundantLabels.clear();
345
+ return;
346
+ }
347
+ const entries = Array.from(instance.history.entries());
330
348
  if (entries.length < 2) return;
349
+ const newRedundant = /* @__PURE__ */ new Set();
331
350
  entries.forEach(([labelA, vecA], i) => {
332
351
  entries.slice(i + 1).forEach(([labelB, vecB]) => {
333
352
  const sim = calculateCosineSimilarity(vecA, vecB);
334
353
  if (sim > SIMILARITY_THRESHOLD) {
335
- displayRedundancyAlert(labelA, labelB, sim, history.size);
354
+ newRedundant.add(labelA);
355
+ newRedundant.add(labelB);
356
+ displayRedundancyAlert(labelA, labelB, sim, instance.history.size);
336
357
  }
337
358
  });
338
359
  });
339
- };
340
- var printBasisHealthReport = (threshold = 0.5) => {
341
- if (!config.debug) {
342
- console.warn("[Basis] Cannot generate report. Debug mode is OFF.");
343
- return;
344
- }
345
- displayHealthReport(history, calculateCosineSimilarity, threshold);
346
- };
347
- var beginEffectTracking = (label) => {
348
- currentEffectSource = label;
349
- };
350
- var endEffectTracking = () => {
351
- currentEffectSource = null;
352
- };
353
- var registerVariable = (label) => {
354
- if (!config.debug) return;
355
- if (!history.has(label)) {
356
- history.set(label, new Array(WINDOW_SIZE).fill(0));
357
- }
358
- };
359
- var unregisterVariable = (label) => {
360
- history.delete(label);
360
+ instance.redundantLabels.clear();
361
+ newRedundant.forEach((label) => instance.redundantLabels.add(label));
361
362
  };
362
363
  var recordUpdate = (label) => {
363
- if (!config.debug) return true;
364
+ if (!instance.config.debug) return true;
364
365
  const now = Date.now();
365
- updateLog.push({ label, ts: now });
366
- updateLog = updateLog.filter((e) => now - e.ts < LOOP_WINDOW_MS);
367
- if (updateLog.filter((e) => e.label === label).length > LOOP_THRESHOLD) {
366
+ instance.updateLog.push({ label, ts: now });
367
+ instance.updateLog = instance.updateLog.filter((e) => now - e.ts < LOOP_WINDOW_MS);
368
+ if (instance.updateLog.filter((e) => e.label === label).length > LOOP_THRESHOLD) {
368
369
  displayInfiniteLoop(label);
369
370
  return false;
370
371
  }
371
- if (currentEffectSource && currentEffectSource !== label) {
372
- displayCausalHint(label, currentEffectSource);
372
+ if (instance.currentEffectSource && instance.currentEffectSource !== label) {
373
+ displayCausalHint(label, instance.currentEffectSource);
373
374
  }
374
- currentTickBatch.add(label);
375
- if (!isBatching) {
376
- isBatching = true;
375
+ instance.currentTickBatch.add(label);
376
+ if (!instance.isBatching) {
377
+ instance.isBatching = true;
377
378
  setTimeout(() => {
378
- tick++;
379
- history.forEach((vec, l) => {
379
+ instance.tick++;
380
+ instance.history.forEach((vec, l) => {
380
381
  vec.shift();
381
- vec.push(currentTickBatch.has(l) ? 1 : 0);
382
+ vec.push(instance.currentTickBatch.has(l) ? 1 : 0);
382
383
  });
383
- currentTickBatch.clear();
384
- isBatching = false;
385
- if (tick % ANALYSIS_INTERVAL === 0) {
384
+ instance.currentTickBatch.clear();
385
+ instance.isBatching = false;
386
+ if (instance.tick % ANALYSIS_INTERVAL === 0) {
386
387
  analyzeBasis();
387
388
  }
388
389
  }, 20);
389
390
  }
390
391
  return true;
391
392
  };
393
+ var beginEffectTracking = (label) => {
394
+ if (instance.config.debug) instance.currentEffectSource = label;
395
+ };
396
+ var endEffectTracking = () => {
397
+ instance.currentEffectSource = null;
398
+ };
399
+ var registerVariable = (label) => {
400
+ if (!instance.config.debug) return;
401
+ if (!instance.history.has(label)) {
402
+ instance.history.set(label, new Array(WINDOW_SIZE).fill(0));
403
+ }
404
+ };
405
+ var unregisterVariable = (label) => {
406
+ instance.history.delete(label);
407
+ };
408
+ var printBasisHealthReport = (threshold = 0.5) => {
409
+ if (!instance.config.debug) {
410
+ console.warn("[Basis] Cannot generate report. Debug mode is OFF.");
411
+ return;
412
+ }
413
+ displayHealthReport(instance.history, calculateCosineSimilarity, threshold);
414
+ };
392
415
  if (typeof window !== "undefined") {
393
416
  window.printBasisReport = printBasisHealthReport;
394
417
  }
395
418
  var __testEngine__ = {
396
- config,
419
+ instance,
420
+ config: instance.config,
421
+ history: instance.history,
422
+ currentTickBatch: instance.currentTickBatch,
397
423
  configureBasis,
398
- history,
399
- currentTickBatch,
400
424
  registerVariable,
401
425
  recordUpdate,
402
426
  printBasisHealthReport,
@@ -405,85 +429,223 @@ var __testEngine__ = {
405
429
  };
406
430
 
407
431
  // src/context.tsx
432
+ var import_react2 = require("react");
433
+
434
+ // src/ui/BasisHUD.tsx
408
435
  var import_react = require("react");
436
+
437
+ // src/ui/config.ts
438
+ var HUD_DIMENSIONS = {
439
+ WINDOW_SIZE,
440
+ ROW_HEIGHT: 16,
441
+ COL_WIDTH: 5,
442
+ LABEL_WIDTH: 100,
443
+ PADDING: 10,
444
+ RADIUS: 1.5
445
+ };
446
+ var HUD_THEME = {
447
+ bg: "rgba(15, 23, 42, 0.95)",
448
+ border: "#334155",
449
+ header: "#8b5cf6",
450
+ text: "#f1f5f9",
451
+ textDim: "#94a3b8",
452
+ success: "#10b981",
453
+ error: "#ef4444",
454
+ grid: "#1e293b"
455
+ };
456
+ var getHUDContainerStyle = (isExpanded) => ({
457
+ position: "fixed",
458
+ bottom: "20px",
459
+ right: "20px",
460
+ backgroundColor: HUD_THEME.bg,
461
+ border: `1px solid ${HUD_THEME.border}`,
462
+ borderRadius: "12px",
463
+ backdropFilter: "blur(8px)",
464
+ boxShadow: "0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3)",
465
+ zIndex: 999999,
466
+ overflow: "hidden",
467
+ width: isExpanded ? "380px" : "130px",
468
+ transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
469
+ cursor: "pointer",
470
+ userSelect: "none",
471
+ WebkitUserSelect: "none"
472
+ });
473
+
474
+ // src/ui/BasisHUD.tsx
409
475
  var import_jsx_runtime = require("react/jsx-runtime");
410
- var BasisContext = (0, import_react.createContext)({ debug: false });
476
+ var BasisHUD = () => {
477
+ const [isExpanded, setIsExpanded] = (0, import_react.useState)(false);
478
+ const canvasRef = (0, import_react.useRef)(null);
479
+ (0, import_react.useEffect)(() => {
480
+ if (!isExpanded) return;
481
+ let animationFrame;
482
+ const draw = () => {
483
+ const canvas = canvasRef.current;
484
+ if (!canvas) return;
485
+ const ctx = canvas.getContext("2d");
486
+ if (!ctx) return;
487
+ const entries = Array.from(history.entries());
488
+ const dpr = window.devicePixelRatio || 1;
489
+ const rawWidth = HUD_DIMENSIONS.WINDOW_SIZE * HUD_DIMENSIONS.COL_WIDTH + HUD_DIMENSIONS.LABEL_WIDTH + HUD_DIMENSIONS.PADDING * 2;
490
+ const rawHeight = Math.max(entries.length * HUD_DIMENSIONS.ROW_HEIGHT + HUD_DIMENSIONS.PADDING * 2, 60);
491
+ updateCanvasSize(canvas, rawWidth, rawHeight, dpr);
492
+ ctx.save();
493
+ ctx.scale(dpr, dpr);
494
+ ctx.clearRect(0, 0, rawWidth, rawHeight);
495
+ if (entries.length === 0) {
496
+ renderEmptyState(ctx);
497
+ } else {
498
+ renderMatrix(ctx, entries);
499
+ }
500
+ ctx.restore();
501
+ animationFrame = requestAnimationFrame(draw);
502
+ };
503
+ draw();
504
+ return () => cancelAnimationFrame(animationFrame);
505
+ }, [isExpanded]);
506
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: getHUDContainerStyle(isExpanded), onClick: () => setIsExpanded(!isExpanded), children: [
507
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HUDHeader, { isExpanded }),
508
+ isExpanded && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "10px 14px 15px 14px" }, children: [
509
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("canvas", { ref: canvasRef, style: { display: "block" } }),
510
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HUDFooter, {})
511
+ ] })
512
+ ] });
513
+ };
514
+ function updateCanvasSize(canvas, w, h, dpr) {
515
+ const targetW = Math.floor(w * dpr);
516
+ const targetH = Math.floor(h * dpr);
517
+ if (canvas.width !== targetW || canvas.height !== targetH) {
518
+ canvas.width = targetW;
519
+ canvas.height = targetH;
520
+ canvas.style.width = `${w}px`;
521
+ canvas.style.height = `${h}px`;
522
+ }
523
+ }
524
+ function renderEmptyState(ctx) {
525
+ ctx.fillStyle = HUD_THEME.textDim;
526
+ ctx.font = "11px Inter, sans-serif";
527
+ ctx.fillText("Waiting for state transitions...", HUD_DIMENSIONS.PADDING, 30);
528
+ }
529
+ function renderMatrix(ctx, entries) {
530
+ entries.forEach(([label, vector], rowIndex) => {
531
+ const y = rowIndex * HUD_DIMENSIONS.ROW_HEIGHT + HUD_DIMENSIONS.PADDING;
532
+ const stateName = label.split(" -> ")[1] || label;
533
+ const isRedundant = redundantLabels.has(label);
534
+ vector.forEach((bit, colIndex) => {
535
+ const x = colIndex * HUD_DIMENSIONS.COL_WIDTH + HUD_DIMENSIONS.PADDING;
536
+ ctx.fillStyle = bit === 1 ? isRedundant ? HUD_THEME.error : HUD_THEME.success : HUD_THEME.grid;
537
+ const w = HUD_DIMENSIONS.COL_WIDTH - 1.5;
538
+ const h = HUD_DIMENSIONS.ROW_HEIGHT - 4;
539
+ if (ctx.roundRect) {
540
+ ctx.beginPath();
541
+ ctx.roundRect(x, y, w, h, HUD_DIMENSIONS.RADIUS);
542
+ ctx.fill();
543
+ } else {
544
+ ctx.fillRect(x, y, w, h);
545
+ }
546
+ });
547
+ const textX = HUD_DIMENSIONS.WINDOW_SIZE * HUD_DIMENSIONS.COL_WIDTH + HUD_DIMENSIONS.PADDING + 10;
548
+ ctx.fillStyle = isRedundant ? HUD_THEME.error : HUD_THEME.text;
549
+ ctx.font = `${isRedundant ? "600" : "400"} 11px Inter, Menlo, monospace`;
550
+ const cleanName = isRedundant ? `! ${stateName}` : stateName;
551
+ const truncatedName = cleanName.length > 18 ? cleanName.substring(0, 16) + ".." : cleanName;
552
+ ctx.fillText(truncatedName, textX, y + 9);
553
+ });
554
+ }
555
+ var HUDHeader = ({ isExpanded }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
556
+ padding: "10px 14px",
557
+ backgroundColor: isExpanded ? HUD_THEME.header : "transparent",
558
+ color: isExpanded ? "white" : HUD_THEME.header,
559
+ fontWeight: 600,
560
+ fontSize: "11px",
561
+ letterSpacing: "0.05em",
562
+ display: "flex",
563
+ justifyContent: "space-between",
564
+ alignItems: "center",
565
+ transition: "background 0.3s"
566
+ }, children: [
567
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: isExpanded ? "STATE BASIS MATRIX" : "\u{1F4D0} BASIS ACTIVE" }),
568
+ isExpanded && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { opacity: 0.8, fontSize: "9px" }, children: "R50" })
569
+ ] });
570
+ var HUDFooter = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
571
+ marginTop: "12px",
572
+ paddingTop: "8px",
573
+ borderTop: `1px solid ${HUD_THEME.grid}`,
574
+ color: HUD_THEME.textDim,
575
+ fontSize: "9px",
576
+ display: "flex",
577
+ justifyContent: "space-between"
578
+ }, children: [
579
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "LINEAR DEPENDENCY AUDIT" }),
580
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "THRESHOLD 0.88" })
581
+ ] });
582
+
583
+ // src/context.tsx
584
+ var import_jsx_runtime2 = require("react/jsx-runtime");
585
+ var BasisContext = (0, import_react2.createContext)({ debug: false });
411
586
  var isWeb2 = typeof window !== "undefined" && typeof window.document !== "undefined";
412
587
  var BasisProvider = ({ children, debug = true }) => {
413
- (0, import_react.useLayoutEffect)(() => {
588
+ (0, import_react2.useLayoutEffect)(() => {
414
589
  configureBasis({ debug });
415
590
  if (isWeb2) {
416
591
  window._basis_debug = debug;
417
592
  }
418
593
  }, [debug]);
419
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(BasisContext.Provider, { value: { debug }, children: [
594
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(BasisContext.Provider, { value: { debug }, children: [
420
595
  children,
421
- debug && isWeb2 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
422
- position: "fixed",
423
- bottom: 10,
424
- right: 10,
425
- background: "black",
426
- color: "#0f0",
427
- padding: "5px 10px",
428
- fontSize: "10px",
429
- fontFamily: "monospace",
430
- border: "1px solid #0f0",
431
- zIndex: 99999,
432
- borderRadius: "4px",
433
- pointerEvents: "none"
434
- }, children: "BASIS_ENGINE: ACTIVE" })
596
+ debug && isWeb2 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BasisHUD, {})
435
597
  ] });
436
598
  };
437
- var useBasisConfig = () => (0, import_react.useContext)(BasisContext);
599
+ var useBasisConfig = () => (0, import_react2.useContext)(BasisContext);
438
600
 
439
601
  // src/hooks.ts
440
- var React2 = __toESM(require("react"));
441
- var import_react2 = require("react");
442
- function useState(initialState, label) {
443
- const [val, setVal] = (0, import_react2.useState)(initialState);
602
+ var React3 = __toESM(require("react"));
603
+ var import_react3 = require("react");
604
+ function useState2(initialState, label) {
605
+ const [val, setVal] = (0, import_react3.useState)(initialState);
444
606
  const effectiveLabel = label || "anonymous_state";
445
- (0, import_react2.useEffect)(() => {
607
+ (0, import_react3.useEffect)(() => {
446
608
  registerVariable(effectiveLabel);
447
609
  return () => unregisterVariable(effectiveLabel);
448
610
  }, [effectiveLabel]);
449
- const setter = (0, import_react2.useCallback)((newValue) => {
611
+ const setter = (0, import_react3.useCallback)((newValue) => {
450
612
  if (recordUpdate(effectiveLabel)) setVal(newValue);
451
613
  }, [effectiveLabel, setVal]);
452
614
  return [val, setter];
453
615
  }
454
- function useRef(initialValue, _label) {
455
- return (0, import_react2.useRef)(initialValue);
616
+ function useRef2(initialValue, _label) {
617
+ return (0, import_react3.useRef)(initialValue);
456
618
  }
457
619
  function useReducer(reducer, initialArg, init, label) {
458
620
  const effectiveLabel = typeof init === "string" ? init : label || "anonymous_reducer";
459
621
  const reactInit = typeof init === "function" ? init : void 0;
460
- const [state, dispatch] = (0, import_react2.useReducer)(reducer, initialArg, reactInit);
461
- (0, import_react2.useEffect)(() => {
622
+ const [state, dispatch] = (0, import_react3.useReducer)(reducer, initialArg, reactInit);
623
+ (0, import_react3.useEffect)(() => {
462
624
  registerVariable(effectiveLabel);
463
625
  return () => unregisterVariable(effectiveLabel);
464
626
  }, [effectiveLabel]);
465
- const basisDispatch = (0, import_react2.useCallback)((action) => {
627
+ const basisDispatch = (0, import_react3.useCallback)((action) => {
466
628
  if (recordUpdate(effectiveLabel)) dispatch(action);
467
629
  }, [effectiveLabel, dispatch]);
468
630
  return [state, basisDispatch];
469
631
  }
470
632
  function useMemo(factory, deps, label) {
471
633
  const effectiveLabel = label || "anonymous_projection";
472
- (0, import_react2.useEffect)(() => {
634
+ (0, import_react3.useEffect)(() => {
473
635
  if (config.debug) console.log(`%c [Basis] Valid Projection: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
474
636
  }, [effectiveLabel]);
475
- return (0, import_react2.useMemo)(factory, deps || []);
637
+ return (0, import_react3.useMemo)(factory, deps || []);
476
638
  }
477
639
  function useCallback(callback, deps, label) {
478
640
  const effectiveLabel = label || "anonymous_callback";
479
- (0, import_react2.useEffect)(() => {
641
+ (0, import_react3.useEffect)(() => {
480
642
  if (config.debug) console.log(`%c [Basis] Stable Callback: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
481
643
  }, [effectiveLabel]);
482
- return (0, import_react2.useCallback)(callback, deps);
644
+ return (0, import_react3.useCallback)(callback, deps);
483
645
  }
484
646
  function useEffect2(effect, deps, label) {
485
647
  const effectiveLabel = label || "anonymous_effect";
486
- (0, import_react2.useEffect)(() => {
648
+ (0, import_react3.useEffect)(() => {
487
649
  beginEffectTracking(effectiveLabel);
488
650
  const cleanup = effect();
489
651
  endEffectTracking();
@@ -492,7 +654,7 @@ function useEffect2(effect, deps, label) {
492
654
  }
493
655
  function useLayoutEffect2(effect, deps, label) {
494
656
  const effectiveLabel = label || "anonymous_layout_effect";
495
- (0, import_react2.useLayoutEffect)(() => {
657
+ (0, import_react3.useLayoutEffect)(() => {
496
658
  beginEffectTracking(effectiveLabel);
497
659
  const cleanup = effect();
498
660
  endEffectTracking();
@@ -500,7 +662,7 @@ function useLayoutEffect2(effect, deps, label) {
500
662
  }, deps);
501
663
  }
502
664
  function useTransition(_label) {
503
- const [isPending, startTransition3] = (0, import_react2.useTransition)();
665
+ const [isPending, startTransition3] = (0, import_react3.useTransition)();
504
666
  const effectiveLabel = _label || "anonymous_transition";
505
667
  const basisStartTransition = (callback) => {
506
668
  if (config.debug) console.log(`%c [Basis] Transition Started: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
@@ -512,34 +674,34 @@ function useDeferredValue(value, initialValueOrLabel, label) {
512
674
  const isLabelAsSecondArg = typeof initialValueOrLabel === "string" && label === void 0;
513
675
  const actualInitialValue = isLabelAsSecondArg ? void 0 : initialValueOrLabel;
514
676
  const effectiveLabel = isLabelAsSecondArg ? initialValueOrLabel : label || "anonymous_deferred";
515
- const deferredValue = (0, import_react2.useDeferredValue)(value, actualInitialValue);
516
- (0, import_react2.useEffect)(() => {
677
+ const deferredValue = (0, import_react3.useDeferredValue)(value, actualInitialValue);
678
+ (0, import_react3.useEffect)(() => {
517
679
  if (config.debug && value !== deferredValue) console.log(`%c [Basis] Value Deferred: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
518
680
  }, [value, deferredValue, effectiveLabel]);
519
681
  return deferredValue;
520
682
  }
521
683
  function createContext2(defaultValue, label) {
522
- const context = (0, import_react2.createContext)(defaultValue);
684
+ const context = (0, import_react3.createContext)(defaultValue);
523
685
  if (label) context._basis_label = label;
524
686
  return context;
525
687
  }
526
- var useContext2 = import_react2.useContext;
527
- var useId2 = (label) => React2.useId();
528
- var useDebugValue2 = React2.useDebugValue;
529
- var useImperativeHandle2 = React2.useImperativeHandle;
530
- var useInsertionEffect2 = React2.useInsertionEffect;
531
- var useSyncExternalStore = import_react2.useSyncExternalStore;
688
+ var useContext2 = import_react3.useContext;
689
+ var useId2 = (label) => React3.useId();
690
+ var useDebugValue2 = React3.useDebugValue;
691
+ var useImperativeHandle2 = React3.useImperativeHandle;
692
+ var useInsertionEffect2 = React3.useInsertionEffect;
693
+ var useSyncExternalStore = import_react3.useSyncExternalStore;
532
694
  function use(usable) {
533
- return (0, import_react2.use)(usable);
695
+ return (0, import_react3.use)(usable);
534
696
  }
535
697
  function useOptimistic2(passthrough, reducer, label) {
536
698
  const effectiveLabel = label || "anonymous_optimistic";
537
- (0, import_react2.useEffect)(() => {
699
+ (0, import_react3.useEffect)(() => {
538
700
  registerVariable(effectiveLabel);
539
701
  return () => unregisterVariable(effectiveLabel);
540
702
  }, [effectiveLabel]);
541
- const [state, reactAddOptimistic] = React2.useOptimistic(passthrough, reducer);
542
- const addOptimistic = (0, import_react2.useCallback)((payload) => {
703
+ const [state, reactAddOptimistic] = React3.useOptimistic(passthrough, reducer);
704
+ const addOptimistic = (0, import_react3.useCallback)((payload) => {
543
705
  if (recordUpdate(effectiveLabel)) {
544
706
  reactAddOptimistic(payload);
545
707
  }
@@ -550,16 +712,16 @@ function useActionState2(action, initialState, permalink, label) {
550
712
  const isLabelAsThirdArg = typeof permalink === "string" && label === void 0;
551
713
  const actualPermalink = isLabelAsThirdArg ? void 0 : permalink;
552
714
  const effectiveLabel = isLabelAsThirdArg ? permalink : label || "anonymous_action_state";
553
- const [state, reactDispatch, isPending] = React2.useActionState(
715
+ const [state, reactDispatch, isPending] = React3.useActionState(
554
716
  action,
555
717
  initialState,
556
718
  actualPermalink
557
719
  );
558
- (0, import_react2.useEffect)(() => {
720
+ (0, import_react3.useEffect)(() => {
559
721
  registerVariable(effectiveLabel);
560
722
  return () => unregisterVariable(effectiveLabel);
561
723
  }, [effectiveLabel]);
562
- const basisDispatch = (0, import_react2.useCallback)((payload) => {
724
+ const basisDispatch = (0, import_react3.useCallback)((payload) => {
563
725
  if (recordUpdate(effectiveLabel)) {
564
726
  reactDispatch(payload);
565
727
  }
@@ -568,6 +730,30 @@ function useActionState2(action, initialState, permalink, label) {
568
730
  }
569
731
  var __test__ = { registerVariable, unregisterVariable, recordUpdate, beginEffectTracking, endEffectTracking, history, currentTickBatch };
570
732
 
733
+ // src/vite-plugin.ts
734
+ function basis() {
735
+ return {
736
+ name: "vite-plugin-react-state-basis",
737
+ enforce: "pre",
738
+ resolveId(source, importer) {
739
+ if (source === "react" || source === "react-dom" || source === "react-dom/client") {
740
+ const isLibraryCore = importer && ((importer.includes("react-state-basis/src") || importer.includes("react-state-basis/dist")) && !importer.includes("react-state-basis/example"));
741
+ const isYalc = importer && importer.includes(".yalc");
742
+ if (isLibraryCore || isYalc) {
743
+ return null;
744
+ }
745
+ const mapping = {
746
+ "react": "react-state-basis",
747
+ "react-dom": "react-state-basis",
748
+ "react-dom/client": "react-state-basis/client"
749
+ };
750
+ return this.resolve(mapping[source], importer, { skipSelf: true });
751
+ }
752
+ return null;
753
+ }
754
+ };
755
+ }
756
+
571
757
  // src/index.ts
572
758
  var Children2 = ReactNamespace.Children;
573
759
  var Component2 = ReactNamespace.Component;
@@ -577,6 +763,7 @@ var PureComponent2 = ReactNamespace.PureComponent;
577
763
  var StrictMode2 = ReactNamespace.StrictMode;
578
764
  var Suspense2 = ReactNamespace.Suspense;
579
765
  var cloneElement2 = ReactNamespace.cloneElement;
766
+ var createElement2 = ReactNamespace.createElement;
580
767
  var createRef2 = ReactNamespace.createRef;
581
768
  var forwardRef2 = ReactNamespace.forwardRef;
582
769
  var isValidElement2 = ReactNamespace.isValidElement;
@@ -601,11 +788,13 @@ var index_default = ReactNamespace;
601
788
  Suspense,
602
789
  __testEngine__,
603
790
  __test__,
791
+ basis,
604
792
  beginEffectTracking,
605
793
  cloneElement,
606
794
  config,
607
795
  configureBasis,
608
796
  createContext,
797
+ createElement,
609
798
  createPortal,
610
799
  createRef,
611
800
  currentTickBatch,