react-state-basis 0.3.1 → 0.3.3
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/chunk-I5ZFRXQP.mjs +18 -0
- package/dist/chunk-I5ZFRXQP.mjs.map +1 -0
- package/dist/index.d.mts +13 -97
- package/dist/index.d.ts +13 -97
- package/dist/index.js +173 -276
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +179 -242
- package/dist/index.mjs.map +1 -1
- package/dist/plugin.js +51 -29
- package/dist/production.d.mts +19 -16
- package/dist/production.d.ts +19 -16
- package/dist/production.js +25 -12
- package/dist/production.js.map +1 -1
- package/dist/production.mjs +20 -12
- package/dist/production.mjs.map +1 -1
- package/dist/vite-plugin.js +5 -15
- package/dist/vite-plugin.js.map +1 -1
- package/dist/vite-plugin.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-GEHMQPV4.mjs +0 -28
- package/dist/chunk-GEHMQPV4.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -31,64 +31,33 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
BasisProvider: () => BasisProvider,
|
|
34
|
-
Children: () => Children2,
|
|
35
|
-
Component: () => Component2,
|
|
36
|
-
Fragment: () => Fragment2,
|
|
37
|
-
Profiler: () => Profiler2,
|
|
38
|
-
PureComponent: () => PureComponent2,
|
|
39
|
-
React: () => ReactNamespace,
|
|
40
|
-
StrictMode: () => StrictMode2,
|
|
41
|
-
Suspense: () => Suspense2,
|
|
42
|
-
__testEngine__: () => __testEngine__,
|
|
43
|
-
__test__: () => __test__,
|
|
44
34
|
basis: () => basis,
|
|
45
|
-
beginEffectTracking: () => beginEffectTracking,
|
|
46
|
-
cloneElement: () => cloneElement2,
|
|
47
|
-
config: () => config,
|
|
48
35
|
configureBasis: () => configureBasis,
|
|
49
|
-
createContext: () => createContext2,
|
|
50
|
-
createElement: () => createElement2,
|
|
51
|
-
createPortal: () => createPortal,
|
|
52
|
-
createRef: () => createRef2,
|
|
53
|
-
currentTickBatch: () => currentTickBatch,
|
|
54
|
-
default: () => index_default,
|
|
55
|
-
endEffectTracking: () => endEffectTracking,
|
|
56
|
-
flushSync: () => flushSync,
|
|
57
|
-
forwardRef: () => forwardRef2,
|
|
58
|
-
history: () => history,
|
|
59
|
-
isValidElement: () => isValidElement2,
|
|
60
|
-
lazy: () => lazy2,
|
|
61
|
-
memo: () => memo2,
|
|
62
36
|
printBasisHealthReport: () => printBasisHealthReport,
|
|
63
|
-
recordUpdate: () => recordUpdate,
|
|
64
|
-
registerVariable: () => registerVariable,
|
|
65
|
-
startTransition: () => startTransition2,
|
|
66
|
-
unregisterVariable: () => unregisterVariable,
|
|
67
|
-
unstable_batchedUpdates: () => unstable_batchedUpdates,
|
|
68
37
|
use: () => use,
|
|
69
38
|
useActionState: () => useActionState2,
|
|
70
39
|
useBasisConfig: () => useBasisConfig,
|
|
71
40
|
useCallback: () => useCallback,
|
|
72
|
-
useContext: () => useContext2,
|
|
73
41
|
useDebugValue: () => useDebugValue2,
|
|
74
42
|
useDeferredValue: () => useDeferredValue,
|
|
75
|
-
useEffect: () =>
|
|
43
|
+
useEffect: () => useEffect,
|
|
76
44
|
useId: () => useId2,
|
|
77
45
|
useImperativeHandle: () => useImperativeHandle2,
|
|
78
46
|
useInsertionEffect: () => useInsertionEffect2,
|
|
79
|
-
useLayoutEffect: () =>
|
|
47
|
+
useLayoutEffect: () => useLayoutEffect,
|
|
80
48
|
useMemo: () => useMemo,
|
|
81
49
|
useOptimistic: () => useOptimistic2,
|
|
82
50
|
useReducer: () => useReducer,
|
|
83
|
-
useRef: () =>
|
|
84
|
-
useState: () =>
|
|
51
|
+
useRef: () => useRef,
|
|
52
|
+
useState: () => useState,
|
|
85
53
|
useSyncExternalStore: () => useSyncExternalStore,
|
|
86
|
-
useTransition: () => useTransition
|
|
87
|
-
version: () => version2
|
|
54
|
+
useTransition: () => useTransition
|
|
88
55
|
});
|
|
89
56
|
module.exports = __toCommonJS(index_exports);
|
|
90
|
-
|
|
91
|
-
|
|
57
|
+
|
|
58
|
+
// src/hooks.ts
|
|
59
|
+
var React = __toESM(require("react"));
|
|
60
|
+
var import_react = require("react");
|
|
92
61
|
|
|
93
62
|
// src/core/logger.ts
|
|
94
63
|
var isWeb = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
@@ -113,7 +82,8 @@ var STYLES = {
|
|
|
113
82
|
border-radius: 0 3px 3px 0;
|
|
114
83
|
`,
|
|
115
84
|
dim: "color: #e84393; font-weight: bold;",
|
|
116
|
-
bold: "font-weight: bold;"
|
|
85
|
+
bold: "font-weight: bold;",
|
|
86
|
+
subText: "color: #636e72; font-size: 11px;"
|
|
117
87
|
};
|
|
118
88
|
var parseLabel = (label) => {
|
|
119
89
|
const parts = label.split(" -> ");
|
|
@@ -131,7 +101,7 @@ var logBasis = (message, ...styles) => {
|
|
|
131
101
|
};
|
|
132
102
|
var displayBootLog = (windowSize) => {
|
|
133
103
|
logBasis(
|
|
134
|
-
`%cBasis%cAuditor%c
|
|
104
|
+
`%cBasis%cAuditor%c Structural Relationship Check | Window: ${windowSize} ticks`,
|
|
135
105
|
STYLES.basis,
|
|
136
106
|
STYLES.version,
|
|
137
107
|
"color: #636e72; font-style: italic; margin-left: 8px;"
|
|
@@ -142,19 +112,21 @@ var displayRedundancyAlert = (labelA, labelB, sim, totalDimensions) => {
|
|
|
142
112
|
const infoB = parseLabel(labelB);
|
|
143
113
|
const isCrossFile = infoA.file !== infoB.file;
|
|
144
114
|
if (isWeb) {
|
|
145
|
-
console.group(`%c \u{1F4D0} BASIS |
|
|
115
|
+
console.group(`%c \u{1F4D0} BASIS | REDUNDANT STATE PATTERN `, STYLES.headerRed);
|
|
146
116
|
console.log(`%c\u{1F4CD} Location: %c${isCrossFile ? `${infoA.file} & ${infoB.file}` : infoA.file}`, STYLES.bold, STYLES.location);
|
|
147
117
|
console.log(
|
|
148
|
-
`%
|
|
118
|
+
`%cObservation:%c Variables %c${infoA.name}%c and %c${infoB.name}%c are Synchronized.
|
|
119
|
+
%cThis means one variable is likely redundant and can be deleted to simplify the component.`,
|
|
149
120
|
STYLES.bold,
|
|
150
121
|
"",
|
|
151
122
|
STYLES.label,
|
|
152
123
|
"",
|
|
153
124
|
STYLES.label,
|
|
154
|
-
""
|
|
125
|
+
"",
|
|
126
|
+
STYLES.subText
|
|
155
127
|
);
|
|
156
128
|
console.log(
|
|
157
|
-
`%cHow to fix:%c
|
|
129
|
+
`%cHow to fix:%c Refactor %c${infoB.name}%c as a Computed Value (Projection):
|
|
158
130
|
%c// \u{1F6E0}\uFE0F Basis Fix: Remove useState, use useMemo
|
|
159
131
|
const ${infoB.name} = useMemo(() => deriveFrom(${infoA.name}), [${infoA.name}]);%c`,
|
|
160
132
|
"color: #00b894; font-weight: bold;",
|
|
@@ -164,16 +136,16 @@ const ${infoB.name} = useMemo(() => deriveFrom(${infoA.name}), [${infoA.name}]);
|
|
|
164
136
|
STYLES.codeBlock,
|
|
165
137
|
""
|
|
166
138
|
);
|
|
167
|
-
console.groupCollapsed(`%c \u{1F52C} Proof Details `, "color: #636e72; font-size: 10px; cursor: pointer;");
|
|
139
|
+
console.groupCollapsed(`%c \u{1F52C} Proof Details (Mathematical Basis) `, "color: #636e72; font-size: 10px; cursor: pointer;");
|
|
168
140
|
console.table({
|
|
169
141
|
"Similarity": `${(sim * 100).toFixed(2)}%`,
|
|
170
|
-
"
|
|
171
|
-
"Rank": totalDimensions - 1
|
|
142
|
+
"Condition": "Collinear Vectors (Dimension Collapse)",
|
|
143
|
+
"Rank Impact": `-1 (Rank: ${totalDimensions - 1})`
|
|
172
144
|
});
|
|
173
145
|
console.groupEnd();
|
|
174
146
|
console.groupEnd();
|
|
175
147
|
} else {
|
|
176
|
-
console.log(`[BASIS] REDUNDANCY
|
|
148
|
+
console.log(`[BASIS] REDUNDANCY: ${infoA.name} <-> ${infoB.name} (Synchronized Updates)`);
|
|
177
149
|
console.log(`Location: ${isCrossFile ? `${infoA.file} & ${infoB.file}` : infoA.file}`);
|
|
178
150
|
}
|
|
179
151
|
};
|
|
@@ -183,7 +155,7 @@ var displayCausalHint = (targetLabel, sourceLabel) => {
|
|
|
183
155
|
const isCrossFile = target.file !== source.file;
|
|
184
156
|
const locationPath = isCrossFile ? `${source.file} \u2794 ${target.file}` : target.file;
|
|
185
157
|
if (isWeb) {
|
|
186
|
-
console.groupCollapsed(`%c \u{1F4A1} BASIS |
|
|
158
|
+
console.groupCollapsed(`%c \u{1F4A1} BASIS | SYNC LEAK (Double Render Cycle) `, STYLES.headerBlue);
|
|
187
159
|
console.log(`%c\u{1F4CD} Location: %c${locationPath}`, STYLES.bold, STYLES.location);
|
|
188
160
|
console.log(
|
|
189
161
|
`%cSequence:%c %c${source.name}%c \u2794 Effect \u2794 %c${target.name}%c`,
|
|
@@ -195,7 +167,8 @@ var displayCausalHint = (targetLabel, sourceLabel) => {
|
|
|
195
167
|
""
|
|
196
168
|
);
|
|
197
169
|
console.log(
|
|
198
|
-
`%cObservation:%c Variable %c${target.name}%c is being manually synchronized
|
|
170
|
+
`%cObservation:%c Variable %c${target.name}%c is being manually synchronized from its source.
|
|
171
|
+
This creates a %cDouble Render Cycle%c (Performance Cost). Consider using useMemo or lifting state.`,
|
|
199
172
|
STYLES.bold,
|
|
200
173
|
"",
|
|
201
174
|
STYLES.label,
|
|
@@ -205,7 +178,7 @@ var displayCausalHint = (targetLabel, sourceLabel) => {
|
|
|
205
178
|
);
|
|
206
179
|
console.groupEnd();
|
|
207
180
|
} else {
|
|
208
|
-
console.log(`[BASIS]
|
|
181
|
+
console.log(`[BASIS] SYNC LEAK: ${source.name} \u2794 ${target.name} (Double Render)`);
|
|
209
182
|
}
|
|
210
183
|
};
|
|
211
184
|
var displayInfiniteLoop = (label) => {
|
|
@@ -214,13 +187,13 @@ var displayInfiniteLoop = (label) => {
|
|
|
214
187
|
console.group(`%c \u{1F6D1} BASIS CRITICAL | CIRCUIT BREAKER `, STYLES.headerRed);
|
|
215
188
|
console.error(
|
|
216
189
|
`Infinite oscillation detected on: %c${info.name}%c
|
|
217
|
-
Execution halted to prevent browser thread lock.`,
|
|
190
|
+
Execution halted to prevent browser thread lock. Check for circular useEffect dependencies.`,
|
|
218
191
|
"color: white; background: #d63031; padding: 2px 4px; border-radius: 3px;",
|
|
219
192
|
""
|
|
220
193
|
);
|
|
221
194
|
console.groupEnd();
|
|
222
195
|
} else {
|
|
223
|
-
console.log(`[BASIS CRITICAL]
|
|
196
|
+
console.log(`[BASIS CRITICAL] CIRCUIT BREAKER: ${info.name}. Execution halted.`);
|
|
224
197
|
}
|
|
225
198
|
};
|
|
226
199
|
var displayHealthReport = (history2, similarityFn, threshold) => {
|
|
@@ -249,23 +222,24 @@ var displayHealthReport = (history2, similarityFn, threshold) => {
|
|
|
249
222
|
}
|
|
250
223
|
});
|
|
251
224
|
const systemRank = independentCount + clusters.length;
|
|
252
|
-
const
|
|
225
|
+
const healthScore = systemRank / totalVars * 100;
|
|
253
226
|
if (isWeb) {
|
|
254
|
-
console.group(`%c \u{1F4CA} BASIS |
|
|
227
|
+
console.group(`%c \u{1F4CA} BASIS | ARCHITECTURAL HEALTH REPORT `, STYLES.headerGreen);
|
|
255
228
|
console.log(
|
|
256
|
-
`%
|
|
229
|
+
`%cArchitectural Health Score: %c${healthScore.toFixed(1)}% %c(State Distribution: ${systemRank}/${totalVars})`,
|
|
257
230
|
STYLES.bold,
|
|
258
|
-
`color: ${
|
|
231
|
+
`color: ${healthScore > 85 ? "#00b894" : "#d63031"}; font-size: 16px; font-weight: bold;`,
|
|
259
232
|
"color: #636e72; font-style: italic;"
|
|
260
233
|
);
|
|
261
234
|
if (clusters.length > 0) {
|
|
262
|
-
console.log(`%cDetected ${clusters.length}
|
|
235
|
+
console.log(`%cDetected ${clusters.length} Synchronized Update Clusters:`, "font-weight: bold; color: #e17055; margin-top: 10px;");
|
|
263
236
|
clusters.forEach((cluster, idx) => {
|
|
264
237
|
const names = cluster.map((l) => parseLabel(l).name).join(" \u27F7 ");
|
|
265
238
|
console.log(` %c${idx + 1}%c ${names}`, "background: #e17055; color: white; border-radius: 50%; padding: 0 5px;", "font-family: monospace;");
|
|
266
239
|
});
|
|
240
|
+
console.log("%c\u{1F4A1} Action: Variables in a cluster move together. Try refactoring them into a single state object or use useMemo for derived values.", STYLES.subText);
|
|
267
241
|
} else {
|
|
268
|
-
console.log("%c\u2728 All state variables
|
|
242
|
+
console.log("%c\u2728 All state variables have optimal distribution. Your Basis is healthy.", "color: #00b894; font-weight: bold; margin-top: 10px;");
|
|
269
243
|
}
|
|
270
244
|
if (totalVars > 0 && totalVars < 15) {
|
|
271
245
|
console.groupCollapsed("%cView Full Correlation Matrix", "color: #636e72; font-size: 11px;");
|
|
@@ -284,10 +258,7 @@ var displayHealthReport = (history2, similarityFn, threshold) => {
|
|
|
284
258
|
}
|
|
285
259
|
console.groupEnd();
|
|
286
260
|
} else {
|
|
287
|
-
console.log(`[BASIS HEALTH]
|
|
288
|
-
if (clusters.length > 0) {
|
|
289
|
-
console.log(`Redundancy Clusters: ${clusters.length}`);
|
|
290
|
-
}
|
|
261
|
+
console.log(`[BASIS HEALTH] Score: ${healthScore.toFixed(1)}% (State Distribution: ${systemRank}/${totalVars})`);
|
|
291
262
|
}
|
|
292
263
|
};
|
|
293
264
|
|
|
@@ -429,11 +400,134 @@ var __testEngine__ = {
|
|
|
429
400
|
endEffectTracking
|
|
430
401
|
};
|
|
431
402
|
|
|
403
|
+
// src/hooks.ts
|
|
404
|
+
function useState(initialState, label) {
|
|
405
|
+
const [val, setVal] = (0, import_react.useState)(initialState);
|
|
406
|
+
const effectiveLabel = label || "anonymous_state";
|
|
407
|
+
(0, import_react.useEffect)(() => {
|
|
408
|
+
registerVariable(effectiveLabel);
|
|
409
|
+
return () => unregisterVariable(effectiveLabel);
|
|
410
|
+
}, [effectiveLabel]);
|
|
411
|
+
const setter = (0, import_react.useCallback)((newValue) => {
|
|
412
|
+
if (recordUpdate(effectiveLabel)) setVal(newValue);
|
|
413
|
+
}, [effectiveLabel, setVal]);
|
|
414
|
+
return [val, setter];
|
|
415
|
+
}
|
|
416
|
+
function useRef(initialValue, _label) {
|
|
417
|
+
return (0, import_react.useRef)(initialValue);
|
|
418
|
+
}
|
|
419
|
+
function useReducer(reducer, initialArg, init, label) {
|
|
420
|
+
const effectiveLabel = typeof init === "string" ? init : label || "anonymous_reducer";
|
|
421
|
+
const reactInit = typeof init === "function" ? init : void 0;
|
|
422
|
+
const [state, dispatch] = (0, import_react.useReducer)(reducer, initialArg, reactInit);
|
|
423
|
+
(0, import_react.useEffect)(() => {
|
|
424
|
+
registerVariable(effectiveLabel);
|
|
425
|
+
return () => unregisterVariable(effectiveLabel);
|
|
426
|
+
}, [effectiveLabel]);
|
|
427
|
+
const basisDispatch = (0, import_react.useCallback)((action) => {
|
|
428
|
+
if (recordUpdate(effectiveLabel)) dispatch(action);
|
|
429
|
+
}, [effectiveLabel, dispatch]);
|
|
430
|
+
return [state, basisDispatch];
|
|
431
|
+
}
|
|
432
|
+
function useMemo(factory, deps, label) {
|
|
433
|
+
const effectiveLabel = label || "anonymous_projection";
|
|
434
|
+
(0, import_react.useEffect)(() => {
|
|
435
|
+
if (config.debug) console.log(`%c [Basis] Valid Projection: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
|
|
436
|
+
}, [effectiveLabel]);
|
|
437
|
+
return (0, import_react.useMemo)(factory, deps || []);
|
|
438
|
+
}
|
|
439
|
+
function useCallback(callback, deps, label) {
|
|
440
|
+
const effectiveLabel = label || "anonymous_callback";
|
|
441
|
+
(0, import_react.useEffect)(() => {
|
|
442
|
+
if (config.debug) console.log(`%c [Basis] Stable Callback: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
|
|
443
|
+
}, [effectiveLabel]);
|
|
444
|
+
return (0, import_react.useCallback)(callback, deps);
|
|
445
|
+
}
|
|
446
|
+
function useEffect(effect, deps, label) {
|
|
447
|
+
const effectiveLabel = label || "anonymous_effect";
|
|
448
|
+
(0, import_react.useEffect)(() => {
|
|
449
|
+
beginEffectTracking(effectiveLabel);
|
|
450
|
+
const cleanup = effect();
|
|
451
|
+
endEffectTracking();
|
|
452
|
+
return cleanup;
|
|
453
|
+
}, deps);
|
|
454
|
+
}
|
|
455
|
+
function useLayoutEffect(effect, deps, label) {
|
|
456
|
+
const effectiveLabel = label || "anonymous_layout_effect";
|
|
457
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
458
|
+
beginEffectTracking(effectiveLabel);
|
|
459
|
+
const cleanup = effect();
|
|
460
|
+
endEffectTracking();
|
|
461
|
+
return cleanup;
|
|
462
|
+
}, deps);
|
|
463
|
+
}
|
|
464
|
+
function useTransition(_label) {
|
|
465
|
+
const [isPending, startTransition] = (0, import_react.useTransition)();
|
|
466
|
+
const effectiveLabel = _label || "anonymous_transition";
|
|
467
|
+
const basisStartTransition = (callback) => {
|
|
468
|
+
if (config.debug) console.log(`%c [Basis] Transition Started: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
|
|
469
|
+
startTransition(callback);
|
|
470
|
+
};
|
|
471
|
+
return [isPending, basisStartTransition];
|
|
472
|
+
}
|
|
473
|
+
function useDeferredValue(value, initialValueOrLabel, label) {
|
|
474
|
+
const isLabelAsSecondArg = typeof initialValueOrLabel === "string" && label === void 0;
|
|
475
|
+
const actualInitialValue = isLabelAsSecondArg ? void 0 : initialValueOrLabel;
|
|
476
|
+
const effectiveLabel = isLabelAsSecondArg ? initialValueOrLabel : label || "anonymous_deferred";
|
|
477
|
+
const deferredValue = (0, import_react.useDeferredValue)(value, actualInitialValue);
|
|
478
|
+
(0, import_react.useEffect)(() => {
|
|
479
|
+
if (config.debug && value !== deferredValue) console.log(`%c [Basis] Value Deferred: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
|
|
480
|
+
}, [value, deferredValue, effectiveLabel]);
|
|
481
|
+
return deferredValue;
|
|
482
|
+
}
|
|
483
|
+
var useId2 = (label) => React.useId();
|
|
484
|
+
var useDebugValue2 = React.useDebugValue;
|
|
485
|
+
var useImperativeHandle2 = React.useImperativeHandle;
|
|
486
|
+
var useInsertionEffect2 = React.useInsertionEffect;
|
|
487
|
+
var useSyncExternalStore = import_react.useSyncExternalStore;
|
|
488
|
+
function use(usable) {
|
|
489
|
+
return (0, import_react.use)(usable);
|
|
490
|
+
}
|
|
491
|
+
function useOptimistic2(passthrough, reducer, label) {
|
|
492
|
+
const effectiveLabel = label || "anonymous_optimistic";
|
|
493
|
+
(0, import_react.useEffect)(() => {
|
|
494
|
+
registerVariable(effectiveLabel);
|
|
495
|
+
return () => unregisterVariable(effectiveLabel);
|
|
496
|
+
}, [effectiveLabel]);
|
|
497
|
+
const [state, reactAddOptimistic] = React.useOptimistic(passthrough, reducer);
|
|
498
|
+
const addOptimistic = (0, import_react.useCallback)((payload) => {
|
|
499
|
+
if (recordUpdate(effectiveLabel)) {
|
|
500
|
+
reactAddOptimistic(payload);
|
|
501
|
+
}
|
|
502
|
+
}, [effectiveLabel, reactAddOptimistic]);
|
|
503
|
+
return [state, addOptimistic];
|
|
504
|
+
}
|
|
505
|
+
function useActionState2(action, initialState, permalink, label) {
|
|
506
|
+
const isLabelAsThirdArg = typeof permalink === "string" && label === void 0;
|
|
507
|
+
const actualPermalink = isLabelAsThirdArg ? void 0 : permalink;
|
|
508
|
+
const effectiveLabel = isLabelAsThirdArg ? permalink : label || "anonymous_action_state";
|
|
509
|
+
const [state, reactDispatch, isPending] = React.useActionState(
|
|
510
|
+
action,
|
|
511
|
+
initialState,
|
|
512
|
+
actualPermalink
|
|
513
|
+
);
|
|
514
|
+
(0, import_react.useEffect)(() => {
|
|
515
|
+
registerVariable(effectiveLabel);
|
|
516
|
+
return () => unregisterVariable(effectiveLabel);
|
|
517
|
+
}, [effectiveLabel]);
|
|
518
|
+
const basisDispatch = (0, import_react.useCallback)((payload) => {
|
|
519
|
+
if (recordUpdate(effectiveLabel)) {
|
|
520
|
+
reactDispatch(payload);
|
|
521
|
+
}
|
|
522
|
+
}, [effectiveLabel, reactDispatch]);
|
|
523
|
+
return [state, basisDispatch, isPending];
|
|
524
|
+
}
|
|
525
|
+
|
|
432
526
|
// src/context.tsx
|
|
433
|
-
var
|
|
527
|
+
var import_react3 = require("react");
|
|
434
528
|
|
|
435
529
|
// src/ui/BasisHUD.tsx
|
|
436
|
-
var
|
|
530
|
+
var import_react2 = require("react");
|
|
437
531
|
|
|
438
532
|
// src/ui/config.ts
|
|
439
533
|
var HUD_DIMENSIONS = {
|
|
@@ -475,9 +569,9 @@ var getHUDContainerStyle = (isExpanded) => ({
|
|
|
475
569
|
// src/ui/BasisHUD.tsx
|
|
476
570
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
477
571
|
var BasisHUD = () => {
|
|
478
|
-
const [isExpanded, setIsExpanded] = (0,
|
|
479
|
-
const canvasRef = (0,
|
|
480
|
-
(0,
|
|
572
|
+
const [isExpanded, setIsExpanded] = (0, import_react2.useState)(false);
|
|
573
|
+
const canvasRef = (0, import_react2.useRef)(null);
|
|
574
|
+
(0, import_react2.useEffect)(() => {
|
|
481
575
|
if (!isExpanded) return;
|
|
482
576
|
let animationFrame;
|
|
483
577
|
const draw = () => {
|
|
@@ -583,10 +677,10 @@ var HUDFooter = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { styl
|
|
|
583
677
|
|
|
584
678
|
// src/context.tsx
|
|
585
679
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
586
|
-
var BasisContext = (0,
|
|
680
|
+
var BasisContext = (0, import_react3.createContext)({ debug: false });
|
|
587
681
|
var isWeb2 = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
588
682
|
var BasisProvider = ({ children, debug = true }) => {
|
|
589
|
-
(0,
|
|
683
|
+
(0, import_react3.useLayoutEffect)(() => {
|
|
590
684
|
configureBasis({ debug });
|
|
591
685
|
if (isWeb2) {
|
|
592
686
|
window._basis_debug = debug;
|
|
@@ -597,227 +691,31 @@ var BasisProvider = ({ children, debug = true }) => {
|
|
|
597
691
|
debug && isWeb2 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BasisHUD, {})
|
|
598
692
|
] });
|
|
599
693
|
};
|
|
600
|
-
var useBasisConfig = () => (0,
|
|
601
|
-
|
|
602
|
-
// src/hooks.ts
|
|
603
|
-
var React3 = __toESM(require("react"));
|
|
604
|
-
var import_react3 = require("react");
|
|
605
|
-
function useState2(initialState, label) {
|
|
606
|
-
const [val, setVal] = (0, import_react3.useState)(initialState);
|
|
607
|
-
const effectiveLabel = label || "anonymous_state";
|
|
608
|
-
(0, import_react3.useEffect)(() => {
|
|
609
|
-
registerVariable(effectiveLabel);
|
|
610
|
-
return () => unregisterVariable(effectiveLabel);
|
|
611
|
-
}, [effectiveLabel]);
|
|
612
|
-
const setter = (0, import_react3.useCallback)((newValue) => {
|
|
613
|
-
if (recordUpdate(effectiveLabel)) setVal(newValue);
|
|
614
|
-
}, [effectiveLabel, setVal]);
|
|
615
|
-
return [val, setter];
|
|
616
|
-
}
|
|
617
|
-
function useRef2(initialValue, _label) {
|
|
618
|
-
return (0, import_react3.useRef)(initialValue);
|
|
619
|
-
}
|
|
620
|
-
function useReducer(reducer, initialArg, init, label) {
|
|
621
|
-
const effectiveLabel = typeof init === "string" ? init : label || "anonymous_reducer";
|
|
622
|
-
const reactInit = typeof init === "function" ? init : void 0;
|
|
623
|
-
const [state, dispatch] = (0, import_react3.useReducer)(reducer, initialArg, reactInit);
|
|
624
|
-
(0, import_react3.useEffect)(() => {
|
|
625
|
-
registerVariable(effectiveLabel);
|
|
626
|
-
return () => unregisterVariable(effectiveLabel);
|
|
627
|
-
}, [effectiveLabel]);
|
|
628
|
-
const basisDispatch = (0, import_react3.useCallback)((action) => {
|
|
629
|
-
if (recordUpdate(effectiveLabel)) dispatch(action);
|
|
630
|
-
}, [effectiveLabel, dispatch]);
|
|
631
|
-
return [state, basisDispatch];
|
|
632
|
-
}
|
|
633
|
-
function useMemo(factory, deps, label) {
|
|
634
|
-
const effectiveLabel = label || "anonymous_projection";
|
|
635
|
-
(0, import_react3.useEffect)(() => {
|
|
636
|
-
if (config.debug) console.log(`%c [Basis] Valid Projection: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
|
|
637
|
-
}, [effectiveLabel]);
|
|
638
|
-
return (0, import_react3.useMemo)(factory, deps || []);
|
|
639
|
-
}
|
|
640
|
-
function useCallback(callback, deps, label) {
|
|
641
|
-
const effectiveLabel = label || "anonymous_callback";
|
|
642
|
-
(0, import_react3.useEffect)(() => {
|
|
643
|
-
if (config.debug) console.log(`%c [Basis] Stable Callback: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
|
|
644
|
-
}, [effectiveLabel]);
|
|
645
|
-
return (0, import_react3.useCallback)(callback, deps);
|
|
646
|
-
}
|
|
647
|
-
function useEffect2(effect, deps, label) {
|
|
648
|
-
const effectiveLabel = label || "anonymous_effect";
|
|
649
|
-
(0, import_react3.useEffect)(() => {
|
|
650
|
-
beginEffectTracking(effectiveLabel);
|
|
651
|
-
const cleanup = effect();
|
|
652
|
-
endEffectTracking();
|
|
653
|
-
return cleanup;
|
|
654
|
-
}, deps);
|
|
655
|
-
}
|
|
656
|
-
function useLayoutEffect2(effect, deps, label) {
|
|
657
|
-
const effectiveLabel = label || "anonymous_layout_effect";
|
|
658
|
-
(0, import_react3.useLayoutEffect)(() => {
|
|
659
|
-
beginEffectTracking(effectiveLabel);
|
|
660
|
-
const cleanup = effect();
|
|
661
|
-
endEffectTracking();
|
|
662
|
-
return cleanup;
|
|
663
|
-
}, deps);
|
|
664
|
-
}
|
|
665
|
-
function useTransition(_label) {
|
|
666
|
-
const [isPending, startTransition3] = (0, import_react3.useTransition)();
|
|
667
|
-
const effectiveLabel = _label || "anonymous_transition";
|
|
668
|
-
const basisStartTransition = (callback) => {
|
|
669
|
-
if (config.debug) console.log(`%c [Basis] Transition Started: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
|
|
670
|
-
startTransition3(callback);
|
|
671
|
-
};
|
|
672
|
-
return [isPending, basisStartTransition];
|
|
673
|
-
}
|
|
674
|
-
function useDeferredValue(value, initialValueOrLabel, label) {
|
|
675
|
-
const isLabelAsSecondArg = typeof initialValueOrLabel === "string" && label === void 0;
|
|
676
|
-
const actualInitialValue = isLabelAsSecondArg ? void 0 : initialValueOrLabel;
|
|
677
|
-
const effectiveLabel = isLabelAsSecondArg ? initialValueOrLabel : label || "anonymous_deferred";
|
|
678
|
-
const deferredValue = (0, import_react3.useDeferredValue)(value, actualInitialValue);
|
|
679
|
-
(0, import_react3.useEffect)(() => {
|
|
680
|
-
if (config.debug && value !== deferredValue) console.log(`%c [Basis] Value Deferred: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
|
|
681
|
-
}, [value, deferredValue, effectiveLabel]);
|
|
682
|
-
return deferredValue;
|
|
683
|
-
}
|
|
684
|
-
function createContext2(defaultValue, label) {
|
|
685
|
-
const context = (0, import_react3.createContext)(defaultValue);
|
|
686
|
-
if (label) context._basis_label = label;
|
|
687
|
-
return context;
|
|
688
|
-
}
|
|
689
|
-
var useContext2 = import_react3.useContext;
|
|
690
|
-
var useId2 = (label) => React3.useId();
|
|
691
|
-
var useDebugValue2 = React3.useDebugValue;
|
|
692
|
-
var useImperativeHandle2 = React3.useImperativeHandle;
|
|
693
|
-
var useInsertionEffect2 = React3.useInsertionEffect;
|
|
694
|
-
var useSyncExternalStore = import_react3.useSyncExternalStore;
|
|
695
|
-
function use(usable) {
|
|
696
|
-
return (0, import_react3.use)(usable);
|
|
697
|
-
}
|
|
698
|
-
function useOptimistic2(passthrough, reducer, label) {
|
|
699
|
-
const effectiveLabel = label || "anonymous_optimistic";
|
|
700
|
-
(0, import_react3.useEffect)(() => {
|
|
701
|
-
registerVariable(effectiveLabel);
|
|
702
|
-
return () => unregisterVariable(effectiveLabel);
|
|
703
|
-
}, [effectiveLabel]);
|
|
704
|
-
const [state, reactAddOptimistic] = React3.useOptimistic(passthrough, reducer);
|
|
705
|
-
const addOptimistic = (0, import_react3.useCallback)((payload) => {
|
|
706
|
-
if (recordUpdate(effectiveLabel)) {
|
|
707
|
-
reactAddOptimistic(payload);
|
|
708
|
-
}
|
|
709
|
-
}, [effectiveLabel, reactAddOptimistic]);
|
|
710
|
-
return [state, addOptimistic];
|
|
711
|
-
}
|
|
712
|
-
function useActionState2(action, initialState, permalink, label) {
|
|
713
|
-
const isLabelAsThirdArg = typeof permalink === "string" && label === void 0;
|
|
714
|
-
const actualPermalink = isLabelAsThirdArg ? void 0 : permalink;
|
|
715
|
-
const effectiveLabel = isLabelAsThirdArg ? permalink : label || "anonymous_action_state";
|
|
716
|
-
const [state, reactDispatch, isPending] = React3.useActionState(
|
|
717
|
-
action,
|
|
718
|
-
initialState,
|
|
719
|
-
actualPermalink
|
|
720
|
-
);
|
|
721
|
-
(0, import_react3.useEffect)(() => {
|
|
722
|
-
registerVariable(effectiveLabel);
|
|
723
|
-
return () => unregisterVariable(effectiveLabel);
|
|
724
|
-
}, [effectiveLabel]);
|
|
725
|
-
const basisDispatch = (0, import_react3.useCallback)((payload) => {
|
|
726
|
-
if (recordUpdate(effectiveLabel)) {
|
|
727
|
-
reactDispatch(payload);
|
|
728
|
-
}
|
|
729
|
-
}, [effectiveLabel, reactDispatch]);
|
|
730
|
-
return [state, basisDispatch, isPending];
|
|
731
|
-
}
|
|
732
|
-
var __test__ = { registerVariable, unregisterVariable, recordUpdate, beginEffectTracking, endEffectTracking, history, currentTickBatch };
|
|
694
|
+
var useBasisConfig = () => (0, import_react3.useContext)(BasisContext);
|
|
733
695
|
|
|
734
696
|
// src/vite-plugin.ts
|
|
735
697
|
function basis() {
|
|
736
698
|
return {
|
|
737
699
|
name: "vite-plugin-react-state-basis",
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
const isYalc = importer && importer.includes(".yalc");
|
|
743
|
-
if (isLibraryCore || isYalc) {
|
|
744
|
-
return null;
|
|
700
|
+
config() {
|
|
701
|
+
return {
|
|
702
|
+
optimizeDeps: {
|
|
703
|
+
exclude: ["react-state-basis"]
|
|
745
704
|
}
|
|
746
|
-
|
|
747
|
-
"react": "react-state-basis",
|
|
748
|
-
"react-dom": "react-state-basis",
|
|
749
|
-
"react-dom/client": "react-state-basis/client"
|
|
750
|
-
};
|
|
751
|
-
return this.resolve(mapping[source], importer, { skipSelf: true });
|
|
752
|
-
}
|
|
753
|
-
return null;
|
|
705
|
+
};
|
|
754
706
|
}
|
|
755
707
|
};
|
|
756
708
|
}
|
|
757
|
-
|
|
758
|
-
// src/index.ts
|
|
759
|
-
var Children2 = ReactNamespace.Children;
|
|
760
|
-
var Component2 = ReactNamespace.Component;
|
|
761
|
-
var Fragment2 = ReactNamespace.Fragment;
|
|
762
|
-
var Profiler2 = ReactNamespace.Profiler;
|
|
763
|
-
var PureComponent2 = ReactNamespace.PureComponent;
|
|
764
|
-
var StrictMode2 = ReactNamespace.StrictMode;
|
|
765
|
-
var Suspense2 = ReactNamespace.Suspense;
|
|
766
|
-
var cloneElement2 = ReactNamespace.cloneElement;
|
|
767
|
-
var createElement2 = ReactNamespace.createElement;
|
|
768
|
-
var createRef2 = ReactNamespace.createRef;
|
|
769
|
-
var forwardRef2 = ReactNamespace.forwardRef;
|
|
770
|
-
var isValidElement2 = ReactNamespace.isValidElement;
|
|
771
|
-
var lazy2 = ReactNamespace.lazy;
|
|
772
|
-
var memo2 = ReactNamespace.memo;
|
|
773
|
-
var startTransition2 = ReactNamespace.startTransition;
|
|
774
|
-
var version2 = ReactNamespace.version;
|
|
775
|
-
var RD = ReactDOMNamespace;
|
|
776
|
-
var createPortal = RD.createPortal;
|
|
777
|
-
var flushSync = RD.flushSync;
|
|
778
|
-
var unstable_batchedUpdates = RD.unstable_batchedUpdates;
|
|
779
|
-
var index_default = ReactNamespace;
|
|
780
709
|
// Annotate the CommonJS export names for ESM import in node:
|
|
781
710
|
0 && (module.exports = {
|
|
782
711
|
BasisProvider,
|
|
783
|
-
Children,
|
|
784
|
-
Component,
|
|
785
|
-
Fragment,
|
|
786
|
-
Profiler,
|
|
787
|
-
PureComponent,
|
|
788
|
-
React,
|
|
789
|
-
StrictMode,
|
|
790
|
-
Suspense,
|
|
791
|
-
__testEngine__,
|
|
792
|
-
__test__,
|
|
793
712
|
basis,
|
|
794
|
-
beginEffectTracking,
|
|
795
|
-
cloneElement,
|
|
796
|
-
config,
|
|
797
713
|
configureBasis,
|
|
798
|
-
createContext,
|
|
799
|
-
createElement,
|
|
800
|
-
createPortal,
|
|
801
|
-
createRef,
|
|
802
|
-
currentTickBatch,
|
|
803
|
-
endEffectTracking,
|
|
804
|
-
flushSync,
|
|
805
|
-
forwardRef,
|
|
806
|
-
history,
|
|
807
|
-
isValidElement,
|
|
808
|
-
lazy,
|
|
809
|
-
memo,
|
|
810
714
|
printBasisHealthReport,
|
|
811
|
-
recordUpdate,
|
|
812
|
-
registerVariable,
|
|
813
|
-
startTransition,
|
|
814
|
-
unregisterVariable,
|
|
815
|
-
unstable_batchedUpdates,
|
|
816
715
|
use,
|
|
817
716
|
useActionState,
|
|
818
717
|
useBasisConfig,
|
|
819
718
|
useCallback,
|
|
820
|
-
useContext,
|
|
821
719
|
useDebugValue,
|
|
822
720
|
useDeferredValue,
|
|
823
721
|
useEffect,
|
|
@@ -831,7 +729,6 @@ var index_default = ReactNamespace;
|
|
|
831
729
|
useRef,
|
|
832
730
|
useState,
|
|
833
731
|
useSyncExternalStore,
|
|
834
|
-
useTransition
|
|
835
|
-
version
|
|
732
|
+
useTransition
|
|
836
733
|
});
|
|
837
734
|
//# sourceMappingURL=index.js.map
|