react-state-basis 0.1.3 → 0.2.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/README.md +31 -20
- package/dist/index.d.mts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +207 -113
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -111
- package/dist/index.mjs.map +1 -1
- package/dist/plugin.js +23 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -149,7 +149,19 @@ Replace your standard React hook imports with `react-state-basis`. This allows t
|
|
|
149
149
|
// import { useState, useEffect } from 'react';
|
|
150
150
|
|
|
151
151
|
// ✅ To this:
|
|
152
|
-
import {
|
|
152
|
+
import {
|
|
153
|
+
useState,
|
|
154
|
+
useEffect,
|
|
155
|
+
useMemo,
|
|
156
|
+
useCallback,
|
|
157
|
+
useContext,
|
|
158
|
+
useRef,
|
|
159
|
+
useLayoutEffect,
|
|
160
|
+
useId,
|
|
161
|
+
useSyncExternalStore,
|
|
162
|
+
useDeferredValue,
|
|
163
|
+
useTransition
|
|
164
|
+
} from 'react-state-basis';
|
|
153
165
|
|
|
154
166
|
function MyComponent() {
|
|
155
167
|
const [data, setData] = useState([]); // Automatically vectorized and tracked
|
|
@@ -447,30 +459,29 @@ Think of it as an architectural smoke detector-not a fire marshal.
|
|
|
447
459
|
|
|
448
460
|
---
|
|
449
461
|
|
|
450
|
-
## 🗺️ Roadmap
|
|
462
|
+
## 🗺️ Roadmap: The Path to Architectural Rigor
|
|
451
463
|
|
|
452
|
-
|
|
464
|
+
React-State-Basis is evolving from a runtime auditor to a complete development infrastructure. Here is the planned trajectory:
|
|
453
465
|
|
|
454
|
-
###
|
|
455
|
-
|
|
456
|
-
*
|
|
457
|
-
*
|
|
466
|
+
### **v0.2.0 - Full Hook Parity (Upcoming)**
|
|
467
|
+
The goal is to make Basis a complete drop-in replacement for the standard React API.
|
|
468
|
+
* **Complete API Coverage:** Adding support for `useRef`, `useCallback`, `useLayoutEffect`, `useTransition`, `useDeferredValue`
|
|
469
|
+
* **Babel Enhancements:** Automated labeling for the entire hook suite to ensure zero-manual-config diagnostics.
|
|
470
|
+
* **Signature Robustness:** Smart disambiguation between dependency arrays and manual labels.
|
|
458
471
|
|
|
459
|
-
###
|
|
460
|
-
|
|
461
|
-
*
|
|
462
|
-
*
|
|
472
|
+
### **v0.3.0 - Modernity & Production Strategy**
|
|
473
|
+
Aligning with the future of React and ensuring zero production cost.
|
|
474
|
+
* **React 19 Support:** Integration of `use()`, `useOptimistic()`, and `useActionState()` into the vector space model.
|
|
475
|
+
* **Zero-Overhead Production:** Implementing **Conditional Exports**. When in production mode, Basis will pass through raw React hooks with zero logic, ensuring no performance penalty.
|
|
463
476
|
|
|
464
|
-
###
|
|
465
|
-
|
|
466
|
-
*
|
|
467
|
-
*
|
|
477
|
+
### **v0.4.0 - Developer Ecosystem & Visuals**
|
|
478
|
+
Tools for better ergonomics and high-level insights.
|
|
479
|
+
* **CLI Utilities (`rsb-init`, `rsb-clean`):** Automated codemods to instantly inject or remove Basis from large codebases. No more manual search-and-replace.
|
|
480
|
+
* **State-Space Visualizer:** A 2D topology map showing "Redundancy Clusters." Visualize your state vectors as physical nodes to identify where the architecture is collapsing.
|
|
468
481
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
* **Test-Health Reporting:** Integration with Vitest/Jest to automatically fail builds if a "Dimension Collapse" or "Infinite Loop" is detected during automated test runs.
|
|
473
|
-
* **Architectural KPI tracking:** Monitoring your **System Efficiency Score** over time as the codebase grows.
|
|
482
|
+
### **v1.0.0 - Formal Verification**
|
|
483
|
+
* **Architectural Gatekeeping:** CI/CD integration to fail builds on infinite loops or critical dimension collapses.
|
|
484
|
+
* **KPI Tracking:** Long-term monitoring of your application’s **System Efficiency Score**.
|
|
474
485
|
|
|
475
486
|
---
|
|
476
487
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import react__default, { Dispatch, SetStateAction, DependencyList, EffectCallback, Reducer, Context, ReactNode } from 'react';
|
|
2
3
|
export { CSSProperties, Context, DependencyList, Dispatch, EffectCallback, FC, PropsWithChildren, ReactElement, ReactNode, Reducer, SetStateAction } from 'react';
|
|
3
4
|
|
|
4
5
|
declare const history: Map<string, number[]>;
|
|
@@ -24,7 +25,17 @@ declare function useMemo<T>(factory: () => T, depsOrLabel?: DependencyList | str
|
|
|
24
25
|
declare function useEffect(effect: EffectCallback, depsOrLabel?: DependencyList | string, label?: string): void;
|
|
25
26
|
declare function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I & S, init?: any, label?: string): [S, Dispatch<A>];
|
|
26
27
|
declare function createContext<T>(defaultValue: T, label?: string): Context<T>;
|
|
28
|
+
declare function useCallback<T extends (...args: any[]) => any>(callback: T, depsOrLabel?: DependencyList | string, label?: string): T;
|
|
29
|
+
declare function useRef<T>(initialValue: T, _label?: string): react.RefObject<T>;
|
|
30
|
+
declare function useLayoutEffect(effect: EffectCallback, depsOrLabel?: DependencyList | string, label?: string): void;
|
|
27
31
|
declare function useContext<T>(context: Context<T>): T;
|
|
32
|
+
declare function useId(_label?: string): string;
|
|
33
|
+
declare function useDebugValue<T>(value: T, formatter?: (value: T) => any, _label?: string): void;
|
|
34
|
+
declare function useImperativeHandle<T, R extends T>(ref: React.Ref<T> | undefined, init: () => R, deps?: DependencyList, _label?: string): void;
|
|
35
|
+
declare function useInsertionEffect(effect: EffectCallback, deps?: DependencyList, _label?: string): void;
|
|
36
|
+
declare function useTransition(_label?: string): [boolean, (callback: () => void) => void];
|
|
37
|
+
declare function useDeferredValue<T>(value: T, initialValueOrLabel?: T | string, label?: string): T;
|
|
38
|
+
declare function useSyncExternalStore<Snapshot>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => Snapshot, getServerSnapshot?: () => Snapshot, _label?: string): Snapshot;
|
|
28
39
|
declare const __test__: {
|
|
29
40
|
registerVariable: (label: string) => void;
|
|
30
41
|
unregisterVariable: (label: string) => void;
|
|
@@ -39,9 +50,9 @@ interface BasisProviderProps {
|
|
|
39
50
|
children: ReactNode;
|
|
40
51
|
debug?: boolean;
|
|
41
52
|
}
|
|
42
|
-
declare const BasisProvider:
|
|
53
|
+
declare const BasisProvider: react__default.FC<BasisProviderProps>;
|
|
43
54
|
declare const useBasisConfig: () => {
|
|
44
55
|
debug: boolean;
|
|
45
56
|
};
|
|
46
57
|
|
|
47
|
-
export { BasisProvider, __testEngine__, __test__, beginEffectTracking, createContext, currentTickBatch, endEffectTracking, history, printBasisHealthReport, recordUpdate, registerVariable, unregisterVariable, useBasisConfig, useContext, useEffect, useMemo, useReducer, useState };
|
|
58
|
+
export { BasisProvider, __testEngine__, __test__, beginEffectTracking, createContext, currentTickBatch, endEffectTracking, history, printBasisHealthReport, recordUpdate, registerVariable, unregisterVariable, useBasisConfig, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import react__default, { Dispatch, SetStateAction, DependencyList, EffectCallback, Reducer, Context, ReactNode } from 'react';
|
|
2
3
|
export { CSSProperties, Context, DependencyList, Dispatch, EffectCallback, FC, PropsWithChildren, ReactElement, ReactNode, Reducer, SetStateAction } from 'react';
|
|
3
4
|
|
|
4
5
|
declare const history: Map<string, number[]>;
|
|
@@ -24,7 +25,17 @@ declare function useMemo<T>(factory: () => T, depsOrLabel?: DependencyList | str
|
|
|
24
25
|
declare function useEffect(effect: EffectCallback, depsOrLabel?: DependencyList | string, label?: string): void;
|
|
25
26
|
declare function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I & S, init?: any, label?: string): [S, Dispatch<A>];
|
|
26
27
|
declare function createContext<T>(defaultValue: T, label?: string): Context<T>;
|
|
28
|
+
declare function useCallback<T extends (...args: any[]) => any>(callback: T, depsOrLabel?: DependencyList | string, label?: string): T;
|
|
29
|
+
declare function useRef<T>(initialValue: T, _label?: string): react.RefObject<T>;
|
|
30
|
+
declare function useLayoutEffect(effect: EffectCallback, depsOrLabel?: DependencyList | string, label?: string): void;
|
|
27
31
|
declare function useContext<T>(context: Context<T>): T;
|
|
32
|
+
declare function useId(_label?: string): string;
|
|
33
|
+
declare function useDebugValue<T>(value: T, formatter?: (value: T) => any, _label?: string): void;
|
|
34
|
+
declare function useImperativeHandle<T, R extends T>(ref: React.Ref<T> | undefined, init: () => R, deps?: DependencyList, _label?: string): void;
|
|
35
|
+
declare function useInsertionEffect(effect: EffectCallback, deps?: DependencyList, _label?: string): void;
|
|
36
|
+
declare function useTransition(_label?: string): [boolean, (callback: () => void) => void];
|
|
37
|
+
declare function useDeferredValue<T>(value: T, initialValueOrLabel?: T | string, label?: string): T;
|
|
38
|
+
declare function useSyncExternalStore<Snapshot>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => Snapshot, getServerSnapshot?: () => Snapshot, _label?: string): Snapshot;
|
|
28
39
|
declare const __test__: {
|
|
29
40
|
registerVariable: (label: string) => void;
|
|
30
41
|
unregisterVariable: (label: string) => void;
|
|
@@ -39,9 +50,9 @@ interface BasisProviderProps {
|
|
|
39
50
|
children: ReactNode;
|
|
40
51
|
debug?: boolean;
|
|
41
52
|
}
|
|
42
|
-
declare const BasisProvider:
|
|
53
|
+
declare const BasisProvider: react__default.FC<BasisProviderProps>;
|
|
43
54
|
declare const useBasisConfig: () => {
|
|
44
55
|
debug: boolean;
|
|
45
56
|
};
|
|
46
57
|
|
|
47
|
-
export { BasisProvider, __testEngine__, __test__, beginEffectTracking, createContext, currentTickBatch, endEffectTracking, history, printBasisHealthReport, recordUpdate, registerVariable, unregisterVariable, useBasisConfig, useContext, useEffect, useMemo, useReducer, useState };
|
|
58
|
+
export { BasisProvider, __testEngine__, __test__, beginEffectTracking, createContext, currentTickBatch, endEffectTracking, history, printBasisHealthReport, recordUpdate, registerVariable, unregisterVariable, useBasisConfig, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
package/dist/index.js
CHANGED
|
@@ -33,28 +33,35 @@ __export(index_exports, {
|
|
|
33
33
|
registerVariable: () => registerVariable,
|
|
34
34
|
unregisterVariable: () => unregisterVariable,
|
|
35
35
|
useBasisConfig: () => useBasisConfig,
|
|
36
|
+
useCallback: () => useCallback,
|
|
36
37
|
useContext: () => useContext,
|
|
38
|
+
useDebugValue: () => useDebugValue,
|
|
39
|
+
useDeferredValue: () => useDeferredValue,
|
|
37
40
|
useEffect: () => useEffect,
|
|
41
|
+
useId: () => useId,
|
|
42
|
+
useImperativeHandle: () => useImperativeHandle,
|
|
43
|
+
useInsertionEffect: () => useInsertionEffect,
|
|
44
|
+
useLayoutEffect: () => useLayoutEffect,
|
|
38
45
|
useMemo: () => useMemo,
|
|
39
46
|
useReducer: () => useReducer,
|
|
40
|
-
|
|
47
|
+
useRef: () => useRef,
|
|
48
|
+
useState: () => useState,
|
|
49
|
+
useSyncExternalStore: () => useSyncExternalStore,
|
|
50
|
+
useTransition: () => useTransition
|
|
41
51
|
});
|
|
42
52
|
module.exports = __toCommonJS(index_exports);
|
|
43
53
|
|
|
44
54
|
// src/core/logger.ts
|
|
55
|
+
var isWeb = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
45
56
|
var STYLES = {
|
|
46
|
-
// Brand Colors
|
|
47
57
|
basis: "background: #6c5ce7; color: white; font-weight: bold; padding: 2px 6px; border-radius: 3px;",
|
|
48
58
|
version: "background: #a29bfe; color: #2d3436; padding: 2px 6px; border-radius: 3px; margin-left: -4px;",
|
|
49
|
-
// Headers
|
|
50
59
|
headerRed: "background: #d63031; color: white; font-weight: bold; padding: 4px 8px; border-radius: 4px;",
|
|
51
60
|
headerBlue: "background: #0984e3; color: white; font-weight: bold; padding: 4px 8px; border-radius: 4px;",
|
|
52
61
|
headerGreen: "background: #00b894; color: white; font-weight: bold; padding: 4px 8px; border-radius: 4px;",
|
|
53
|
-
// Elements
|
|
54
62
|
label: "background: #dfe6e9; color: #2d3436; padding: 0 4px; border-radius: 3px; font-family: monospace; font-weight: bold; border: 1px solid #b2bec3;",
|
|
55
63
|
location: "color: #0984e3; font-family: monospace; font-weight: bold;",
|
|
56
64
|
math: "color: #636e72; font-style: italic; font-family: serif;",
|
|
57
|
-
// Code Block
|
|
58
65
|
codeBlock: `
|
|
59
66
|
background: #1e1e1e;
|
|
60
67
|
color: #9cdcfe;
|
|
@@ -66,7 +73,6 @@ var STYLES = {
|
|
|
66
73
|
line-height: 1.4;
|
|
67
74
|
border-radius: 0 3px 3px 0;
|
|
68
75
|
`,
|
|
69
|
-
// Highlights
|
|
70
76
|
dim: "color: #e84393; font-weight: bold;",
|
|
71
77
|
bold: "font-weight: bold;"
|
|
72
78
|
};
|
|
@@ -77,9 +83,16 @@ var parseLabel = (label) => {
|
|
|
77
83
|
name: parts[1] || label
|
|
78
84
|
};
|
|
79
85
|
};
|
|
86
|
+
var logBasis = (message, ...styles) => {
|
|
87
|
+
if (isWeb) {
|
|
88
|
+
console.log(message, ...styles);
|
|
89
|
+
} else {
|
|
90
|
+
console.log(message.replace(/%c/g, ""));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
80
93
|
var displayBootLog = (windowSize) => {
|
|
81
|
-
|
|
82
|
-
`%cBasis%cAuditor v0.1.
|
|
94
|
+
logBasis(
|
|
95
|
+
`%cBasis%cAuditor v0.1.4%c Monitoring State Space | Window: ${windowSize} ticks`,
|
|
83
96
|
STYLES.basis,
|
|
84
97
|
STYLES.version,
|
|
85
98
|
"color: #636e72; font-style: italic; margin-left: 8px;"
|
|
@@ -89,87 +102,87 @@ var displayRedundancyAlert = (labelA, labelB, sim, totalDimensions) => {
|
|
|
89
102
|
const infoA = parseLabel(labelA);
|
|
90
103
|
const infoB = parseLabel(labelB);
|
|
91
104
|
const isCrossFile = infoA.file !== infoB.file;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
if (isWeb) {
|
|
106
|
+
console.group(`%c \u{1F4D0} BASIS | DIMENSION COLLAPSE DETECTED `, STYLES.headerRed);
|
|
107
|
+
console.log(`%c\u{1F4CD} Location: %c${isCrossFile ? `${infoA.file} & ${infoB.file}` : infoA.file}`, STYLES.bold, STYLES.location);
|
|
108
|
+
console.log(
|
|
109
|
+
`%cAnalysis:%c Vectors %c${infoA.name}%c and %c${infoB.name}%c are collinear (redundant).`,
|
|
110
|
+
STYLES.bold,
|
|
111
|
+
"",
|
|
112
|
+
STYLES.label,
|
|
113
|
+
"",
|
|
114
|
+
STYLES.label,
|
|
115
|
+
""
|
|
116
|
+
);
|
|
117
|
+
console.log(
|
|
118
|
+
`%cHow to fix:%c Project %c${infoB.name}%c as a derived value:
|
|
105
119
|
%c// \u{1F6E0}\uFE0F Basis Fix: Remove useState, use useMemo
|
|
106
120
|
const ${infoB.name} = useMemo(() => deriveFrom(${infoA.name}), [${infoA.name}]);%c`,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
"color: #00b894; font-weight: bold;",
|
|
122
|
+
"",
|
|
123
|
+
"color: #e84393; font-weight: bold;",
|
|
124
|
+
"",
|
|
125
|
+
STYLES.codeBlock,
|
|
126
|
+
""
|
|
127
|
+
);
|
|
128
|
+
console.groupCollapsed(`%c \u{1F52C} Proof Details `, "color: #636e72; font-size: 10px; cursor: pointer;");
|
|
129
|
+
console.table({
|
|
130
|
+
"Similarity": `${(sim * 100).toFixed(2)}%`,
|
|
131
|
+
"Linear Dependency": "TRUE",
|
|
132
|
+
"Rank": totalDimensions - 1
|
|
133
|
+
});
|
|
134
|
+
console.groupEnd();
|
|
135
|
+
console.groupEnd();
|
|
136
|
+
} else {
|
|
137
|
+
console.log(`[BASIS] REDUNDANCY DETECTED: ${infoA.name} <-> ${infoB.name} (${(sim * 100).toFixed(0)}% similarity)`);
|
|
138
|
+
console.log(`Location: ${isCrossFile ? `${infoA.file} & ${infoB.file}` : infoA.file}`);
|
|
139
|
+
}
|
|
122
140
|
};
|
|
123
141
|
var displayCausalHint = (targetLabel, sourceLabel) => {
|
|
124
142
|
const target = parseLabel(targetLabel);
|
|
125
143
|
const source = parseLabel(sourceLabel);
|
|
126
144
|
const isCrossFile = target.file !== source.file;
|
|
127
145
|
const locationPath = isCrossFile ? `${source.file} \u2794 ${target.file}` : target.file;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
This creates a %c"Double Render Cycle"%c.`,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
"",
|
|
154
|
-
"color: #0984e3; font-weight: bold;",
|
|
155
|
-
"",
|
|
156
|
-
"color: #e84393; font-weight: bold;",
|
|
157
|
-
"",
|
|
158
|
-
STYLES.codeBlock,
|
|
159
|
-
""
|
|
160
|
-
);
|
|
161
|
-
console.groupEnd();
|
|
146
|
+
if (isWeb) {
|
|
147
|
+
console.groupCollapsed(`%c \u{1F4A1} BASIS | CAUSALITY (Sequential Update) `, STYLES.headerBlue);
|
|
148
|
+
console.log(`%c\u{1F4CD} Location: %c${locationPath}`, STYLES.bold, STYLES.location);
|
|
149
|
+
console.log(
|
|
150
|
+
`%cSequence:%c %c${source.name}%c \u2794 Effect \u2794 %c${target.name}%c`,
|
|
151
|
+
STYLES.bold,
|
|
152
|
+
"",
|
|
153
|
+
STYLES.label,
|
|
154
|
+
"",
|
|
155
|
+
STYLES.label,
|
|
156
|
+
""
|
|
157
|
+
);
|
|
158
|
+
console.log(
|
|
159
|
+
`%cObservation:%c Variable %c${target.name}%c is being manually synchronized. This creates a %c"Double Render Cycle"%c.`,
|
|
160
|
+
STYLES.bold,
|
|
161
|
+
"",
|
|
162
|
+
STYLES.label,
|
|
163
|
+
"",
|
|
164
|
+
"color: #d63031; font-weight: bold;",
|
|
165
|
+
""
|
|
166
|
+
);
|
|
167
|
+
console.groupEnd();
|
|
168
|
+
} else {
|
|
169
|
+
console.log(`[BASIS] CAUSALITY: ${source.name} \u2794 ${target.name} (Double Render Cycle)`);
|
|
170
|
+
}
|
|
162
171
|
};
|
|
163
172
|
var displayInfiniteLoop = (label) => {
|
|
164
173
|
const info = parseLabel(label);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
if (isWeb) {
|
|
175
|
+
console.group(`%c \u{1F6D1} BASIS CRITICAL | CIRCUIT BREAKER `, STYLES.headerRed);
|
|
176
|
+
console.error(
|
|
177
|
+
`Infinite oscillation detected on: %c${info.name}%c
|
|
178
|
+
Execution halted to prevent browser thread lock.`,
|
|
179
|
+
"color: white; background: #d63031; padding: 2px 4px; border-radius: 3px;",
|
|
180
|
+
""
|
|
181
|
+
);
|
|
182
|
+
console.groupEnd();
|
|
183
|
+
} else {
|
|
184
|
+
console.log(`[BASIS CRITICAL] INFINITE LOOP ON: ${info.name}. Execution halted.`);
|
|
185
|
+
}
|
|
173
186
|
};
|
|
174
187
|
var displayHealthReport = (history2, similarityFn, threshold) => {
|
|
175
188
|
const entries = Array.from(history2.entries());
|
|
@@ -198,40 +211,45 @@ var displayHealthReport = (history2, similarityFn, threshold) => {
|
|
|
198
211
|
});
|
|
199
212
|
const systemRank = independentCount + clusters.length;
|
|
200
213
|
const efficiency = systemRank / totalVars * 100;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
} else {
|
|
215
|
-
console.log("%c\u2728 All state variables are linearly independent. Your Basis is optimal.", "color: #00b894; font-weight: bold; margin-top: 10px;");
|
|
216
|
-
}
|
|
217
|
-
if (totalVars > 0 && totalVars < 15) {
|
|
218
|
-
console.groupCollapsed("%cView Full Correlation Matrix", "color: #636e72; font-size: 11px;");
|
|
219
|
-
const matrix = {};
|
|
220
|
-
entries.forEach(([labelA]) => {
|
|
221
|
-
const nameA = parseLabel(labelA).name;
|
|
222
|
-
matrix[nameA] = {};
|
|
223
|
-
entries.forEach(([labelB]) => {
|
|
224
|
-
const nameB = parseLabel(labelB).name;
|
|
225
|
-
const sim = similarityFn(history2.get(labelA), history2.get(labelB));
|
|
226
|
-
matrix[nameA][nameB] = sim > threshold ? `\u274C ${(sim * 100).toFixed(0)}%` : `\u2705`;
|
|
214
|
+
if (isWeb) {
|
|
215
|
+
console.group(`%c \u{1F4CA} BASIS | SYSTEM HEALTH REPORT `, STYLES.headerGreen);
|
|
216
|
+
console.log(
|
|
217
|
+
`%cBasis Efficiency: %c${efficiency.toFixed(1)}% %c(Rank: ${systemRank}/${totalVars})`,
|
|
218
|
+
STYLES.bold,
|
|
219
|
+
`color: ${efficiency > 85 ? "#00b894" : "#d63031"}; font-size: 16px; font-weight: bold;`,
|
|
220
|
+
"color: #636e72; font-style: italic;"
|
|
221
|
+
);
|
|
222
|
+
if (clusters.length > 0) {
|
|
223
|
+
console.log(`%cDetected ${clusters.length} Redundancy Clusters:`, "font-weight: bold; color: #e17055; margin-top: 10px;");
|
|
224
|
+
clusters.forEach((cluster, idx) => {
|
|
225
|
+
const names = cluster.map((l) => parseLabel(l).name).join(" \u27F7 ");
|
|
226
|
+
console.log(` %c${idx + 1}%c ${names}`, "background: #e17055; color: white; border-radius: 50%; padding: 0 5px;", "font-family: monospace;");
|
|
227
227
|
});
|
|
228
|
-
}
|
|
229
|
-
|
|
228
|
+
} else {
|
|
229
|
+
console.log("%c\u2728 All state variables are linearly independent. Your Basis is optimal.", "color: #00b894; font-weight: bold; margin-top: 10px;");
|
|
230
|
+
}
|
|
231
|
+
if (totalVars > 0 && totalVars < 15) {
|
|
232
|
+
console.groupCollapsed("%cView Full Correlation Matrix", "color: #636e72; font-size: 11px;");
|
|
233
|
+
const matrix = {};
|
|
234
|
+
entries.forEach(([labelA]) => {
|
|
235
|
+
const nameA = parseLabel(labelA).name;
|
|
236
|
+
matrix[nameA] = {};
|
|
237
|
+
entries.forEach(([labelB]) => {
|
|
238
|
+
const nameB = parseLabel(labelB).name;
|
|
239
|
+
const sim = similarityFn(history2.get(labelA), history2.get(labelB));
|
|
240
|
+
matrix[nameA][nameB] = sim > threshold ? `\u274C ${(sim * 100).toFixed(0)}%` : `\u2705`;
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
console.table(matrix);
|
|
244
|
+
console.groupEnd();
|
|
245
|
+
}
|
|
230
246
|
console.groupEnd();
|
|
231
247
|
} else {
|
|
232
|
-
console.log(
|
|
248
|
+
console.log(`[BASIS HEALTH] Efficiency: ${efficiency.toFixed(1)}% (Rank: ${systemRank}/${totalVars})`);
|
|
249
|
+
if (clusters.length > 0) {
|
|
250
|
+
console.log(`Redundancy Clusters: ${clusters.length}`);
|
|
251
|
+
}
|
|
233
252
|
}
|
|
234
|
-
console.groupEnd();
|
|
235
253
|
};
|
|
236
254
|
|
|
237
255
|
// src/core/math.ts
|
|
@@ -340,7 +358,7 @@ function useState(initialValue, label) {
|
|
|
340
358
|
registerVariable(effectiveLabel);
|
|
341
359
|
return () => unregisterVariable(effectiveLabel);
|
|
342
360
|
}, [effectiveLabel]);
|
|
343
|
-
const setter =
|
|
361
|
+
const setter = useCallback((newValue) => {
|
|
344
362
|
if (recordUpdate(effectiveLabel)) {
|
|
345
363
|
setVal(newValue);
|
|
346
364
|
}
|
|
@@ -377,7 +395,7 @@ function useReducer(reducer, initialArg, init, label) {
|
|
|
377
395
|
registerVariable(effectiveLabel);
|
|
378
396
|
return () => unregisterVariable(effectiveLabel);
|
|
379
397
|
}, [effectiveLabel]);
|
|
380
|
-
const basisDispatch =
|
|
398
|
+
const basisDispatch = useCallback((action) => {
|
|
381
399
|
if (recordUpdate(effectiveLabel)) {
|
|
382
400
|
dispatch(action);
|
|
383
401
|
}
|
|
@@ -391,9 +409,74 @@ function createContext(defaultValue, label) {
|
|
|
391
409
|
}
|
|
392
410
|
return context;
|
|
393
411
|
}
|
|
412
|
+
function useCallback(callback, depsOrLabel, label) {
|
|
413
|
+
const isLabelAsSecondArg = typeof depsOrLabel === "string";
|
|
414
|
+
const actualDeps = isLabelAsSecondArg ? void 0 : depsOrLabel;
|
|
415
|
+
const effectiveLabel = isLabelAsSecondArg ? depsOrLabel : label || "anonymous_callback";
|
|
416
|
+
(0, import_react.useEffect)(() => {
|
|
417
|
+
if (window._basis_debug !== false) {
|
|
418
|
+
console.log(`%c [Basis] Stable Callback: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
|
|
419
|
+
}
|
|
420
|
+
}, [effectiveLabel]);
|
|
421
|
+
return (0, import_react.useCallback)(callback, actualDeps || []);
|
|
422
|
+
}
|
|
423
|
+
function useRef(initialValue, _label) {
|
|
424
|
+
return (0, import_react.useRef)(initialValue);
|
|
425
|
+
}
|
|
426
|
+
function useLayoutEffect(effect, depsOrLabel, label) {
|
|
427
|
+
const isLabelAsSecondArg = typeof depsOrLabel === "string";
|
|
428
|
+
const actualDeps = isLabelAsSecondArg ? void 0 : depsOrLabel;
|
|
429
|
+
const effectiveLabel = isLabelAsSecondArg ? depsOrLabel : label || "anonymous_layout_effect";
|
|
430
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
431
|
+
beginEffectTracking(effectiveLabel);
|
|
432
|
+
const cleanup = effect();
|
|
433
|
+
endEffectTracking();
|
|
434
|
+
return cleanup;
|
|
435
|
+
}, actualDeps);
|
|
436
|
+
}
|
|
394
437
|
function useContext(context) {
|
|
395
438
|
return (0, import_react.useContext)(context);
|
|
396
439
|
}
|
|
440
|
+
function useId(_label) {
|
|
441
|
+
return (0, import_react.useId)();
|
|
442
|
+
}
|
|
443
|
+
function useDebugValue(value, formatter, _label) {
|
|
444
|
+
return (0, import_react.useDebugValue)(value, formatter);
|
|
445
|
+
}
|
|
446
|
+
function useImperativeHandle(ref, init, deps, _label) {
|
|
447
|
+
return (0, import_react.useImperativeHandle)(ref, init, deps);
|
|
448
|
+
}
|
|
449
|
+
function useInsertionEffect(effect, deps, _label) {
|
|
450
|
+
return (0, import_react.useInsertionEffect)(effect, deps);
|
|
451
|
+
}
|
|
452
|
+
function useTransition(_label) {
|
|
453
|
+
const [isPending, startTransition] = (0, import_react.useTransition)();
|
|
454
|
+
const effectiveLabel = _label || "anonymous_transition";
|
|
455
|
+
const basisStartTransition = (callback) => {
|
|
456
|
+
if (window._basis_debug !== false) {
|
|
457
|
+
console.log(`%c [Basis] Transition Started: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
|
|
458
|
+
}
|
|
459
|
+
startTransition(() => {
|
|
460
|
+
callback();
|
|
461
|
+
});
|
|
462
|
+
};
|
|
463
|
+
return [isPending, basisStartTransition];
|
|
464
|
+
}
|
|
465
|
+
function useDeferredValue(value, initialValueOrLabel, label) {
|
|
466
|
+
const isLabelAsSecondArg = typeof initialValueOrLabel === "string" && label === void 0;
|
|
467
|
+
const actualInitialValue = isLabelAsSecondArg ? void 0 : initialValueOrLabel;
|
|
468
|
+
const effectiveLabel = isLabelAsSecondArg ? initialValueOrLabel : label || "anonymous_deferred";
|
|
469
|
+
const deferredValue = (0, import_react.useDeferredValue)(value, actualInitialValue);
|
|
470
|
+
(0, import_react.useEffect)(() => {
|
|
471
|
+
if (window._basis_debug !== false && value !== deferredValue) {
|
|
472
|
+
console.log(`%c [Basis] Value Deferred: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
|
|
473
|
+
}
|
|
474
|
+
}, [value, deferredValue, effectiveLabel]);
|
|
475
|
+
return deferredValue;
|
|
476
|
+
}
|
|
477
|
+
function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot, _label) {
|
|
478
|
+
return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getServerSnapshot);
|
|
479
|
+
}
|
|
397
480
|
var __test__ = {
|
|
398
481
|
registerVariable,
|
|
399
482
|
unregisterVariable,
|
|
@@ -408,13 +491,14 @@ var __test__ = {
|
|
|
408
491
|
var import_react2 = require("react");
|
|
409
492
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
410
493
|
var BasisContext = (0, import_react2.createContext)({ debug: false });
|
|
494
|
+
var isWeb2 = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
411
495
|
var BasisProvider = ({ children, debug = true }) => {
|
|
412
|
-
if (
|
|
496
|
+
if (isWeb2) {
|
|
413
497
|
window._basis_debug = debug;
|
|
414
498
|
}
|
|
415
499
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(BasisContext.Provider, { value: { debug }, children: [
|
|
416
500
|
children,
|
|
417
|
-
debug && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
501
|
+
debug && isWeb2 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
418
502
|
position: "fixed",
|
|
419
503
|
bottom: 10,
|
|
420
504
|
right: 10,
|
|
@@ -446,10 +530,20 @@ var useBasisConfig = () => (0, import_react2.useContext)(BasisContext);
|
|
|
446
530
|
registerVariable,
|
|
447
531
|
unregisterVariable,
|
|
448
532
|
useBasisConfig,
|
|
533
|
+
useCallback,
|
|
449
534
|
useContext,
|
|
535
|
+
useDebugValue,
|
|
536
|
+
useDeferredValue,
|
|
450
537
|
useEffect,
|
|
538
|
+
useId,
|
|
539
|
+
useImperativeHandle,
|
|
540
|
+
useInsertionEffect,
|
|
541
|
+
useLayoutEffect,
|
|
451
542
|
useMemo,
|
|
452
543
|
useReducer,
|
|
453
|
-
|
|
544
|
+
useRef,
|
|
545
|
+
useState,
|
|
546
|
+
useSyncExternalStore,
|
|
547
|
+
useTransition
|
|
454
548
|
});
|
|
455
549
|
//# sourceMappingURL=index.js.map
|