@almadar/ui 4.44.0 → 4.45.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/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { clsx } from 'clsx';
2
2
  import { twMerge } from 'tailwind-merge';
3
- import { createLogger } from '@almadar/logger';
3
+ import { createLogger, isLogLevelEnabled } from '@almadar/logger';
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -100,75 +100,89 @@ var apiClient = {
100
100
  return handleResponse(response);
101
101
  }
102
102
  };
103
-
104
- // lib/debug.ts
105
- var DEBUG_ENABLED = typeof window !== "undefined" && (localStorage.getItem("debug") === "true" || process.env.NODE_ENV === "development");
103
+ var NAMESPACE = "almadar:ui:debug";
104
+ var log = createLogger(NAMESPACE);
105
+ var inputLog = createLogger("almadar:ui:debug:input");
106
+ var collisionLog = createLogger("almadar:ui:debug:collision");
107
+ var physicsLog = createLogger("almadar:ui:debug:physics");
108
+ var gameStateLog = createLogger("almadar:ui:debug:game-state");
109
+ function gateEnabled(level, ns = NAMESPACE) {
110
+ return isLogLevelEnabled(level, ns);
111
+ }
106
112
  function isDebugEnabled() {
107
- if (DEBUG_ENABLED) return true;
108
- return typeof window !== "undefined" && window.__ALMADAR_DEBUG_VERIFY__ === true;
113
+ return gateEnabled("DEBUG");
109
114
  }
110
115
  function debug(...args) {
111
- if (isDebugEnabled()) {
112
- console.log("[DEBUG]", ...args);
116
+ if (!gateEnabled("DEBUG")) return;
117
+ const [first, ...rest] = args;
118
+ const message = typeof first === "string" ? first : "<debug>";
119
+ if (rest.length === 0 && typeof first === "string") {
120
+ log.debug(message);
121
+ } else {
122
+ log.debug(message, { args: rest.length > 0 ? formatArgs(rest) : formatArgs([first]) });
113
123
  }
114
124
  }
115
125
  function debugGroup(label) {
116
- if (isDebugEnabled()) {
117
- console.group(`[DEBUG] ${label}`);
118
- }
126
+ if (gateEnabled("DEBUG")) console.group(`[${NAMESPACE}] ${label}`);
119
127
  }
120
128
  function debugGroupEnd() {
121
- if (isDebugEnabled()) {
122
- console.groupEnd();
123
- }
129
+ if (gateEnabled("DEBUG")) console.groupEnd();
124
130
  }
125
131
  function debugWarn(...args) {
126
- if (isDebugEnabled()) {
127
- console.warn("[DEBUG]", ...args);
128
- }
132
+ if (!gateEnabled("WARN")) return;
133
+ const [first, ...rest] = args;
134
+ const message = typeof first === "string" ? first : "<warn>";
135
+ log.warn(message, rest.length > 0 ? { args: formatArgs(rest) } : void 0);
129
136
  }
130
137
  function debugError(...args) {
131
- if (isDebugEnabled()) {
132
- console.error("[DEBUG]", ...args);
133
- }
138
+ if (!gateEnabled("ERROR")) return;
139
+ const [first, ...rest] = args;
140
+ const message = typeof first === "string" ? first : "<error>";
141
+ log.error(message, rest.length > 0 ? { args: formatArgs(rest) } : void 0);
134
142
  }
135
143
  function debugTable(data) {
136
- if (isDebugEnabled()) {
137
- console.table(data);
138
- }
144
+ if (gateEnabled("DEBUG")) console.table(data);
139
145
  }
140
146
  function debugTime(label) {
141
- if (isDebugEnabled()) {
142
- console.time(`[DEBUG] ${label}`);
143
- }
147
+ if (gateEnabled("DEBUG")) console.time(`[${NAMESPACE}] ${label}`);
144
148
  }
145
149
  function debugTimeEnd(label) {
146
- if (isDebugEnabled()) {
147
- console.timeEnd(`[DEBUG] ${label}`);
148
- }
150
+ if (gateEnabled("DEBUG")) console.timeEnd(`[${NAMESPACE}] ${label}`);
149
151
  }
150
152
  function debugInput(inputType, data) {
151
- if (isDebugEnabled()) {
152
- console.log(`[DEBUG:INPUT] ${inputType}:`, data);
153
- }
153
+ inputLog.debug(inputType, { data: formatArgs([data]) });
154
154
  }
155
155
  function debugCollision(entityA, entityB, details) {
156
- if (isDebugEnabled()) {
157
- console.log(
158
- `[DEBUG:COLLISION] ${entityA.type || entityA.id} <-> ${entityB.type || entityB.id}`,
159
- details ?? ""
160
- );
161
- }
156
+ collisionLog.debug("collision", () => ({
157
+ a: entityA.type ?? entityA.id ?? null,
158
+ b: entityB.type ?? entityB.id ?? null,
159
+ details: details === void 0 ? null : formatArgs([details])
160
+ }));
162
161
  }
163
162
  function debugPhysics(entityId, physics) {
164
- if (isDebugEnabled()) {
165
- console.log(`[DEBUG:PHYSICS] ${entityId}:`, physics);
166
- }
163
+ physicsLog.debug("physics", { entityId, data: formatArgs([physics]) });
167
164
  }
168
165
  function debugGameState(stateName, value) {
169
- if (isDebugEnabled()) {
170
- console.log(`[DEBUG:GAME_STATE] ${stateName}:`, value);
166
+ gameStateLog.debug(stateName, { value: formatArgs([value]) });
167
+ }
168
+ function formatArgs(values) {
169
+ if (values.length === 1) return toLogMetaValue(values[0]);
170
+ return values.map(toLogMetaValue);
171
+ }
172
+ function toLogMetaValue(v) {
173
+ if (v === null || v === void 0) return v;
174
+ if (v instanceof Error) return v;
175
+ const t = typeof v;
176
+ if (t === "string" || t === "number" || t === "boolean") return v;
177
+ if (Array.isArray(v)) return v.map(toLogMetaValue);
178
+ if (t === "object") {
179
+ const out = {};
180
+ for (const [k, val] of Object.entries(v)) {
181
+ out[k] = toLogMetaValue(val);
182
+ }
183
+ return out;
171
184
  }
185
+ return String(v);
172
186
  }
173
187
 
174
188
  // lib/debugUtils.ts
@@ -429,7 +443,7 @@ function clearTraits() {
429
443
  traits.clear();
430
444
  notifyListeners4();
431
445
  }
432
- var log = createLogger("almadar:bridge");
446
+ var log2 = createLogger("almadar:bridge");
433
447
  var MAX_TRANSITIONS = 500;
434
448
  function getState() {
435
449
  if (typeof window !== "undefined") {
@@ -480,7 +494,7 @@ function recordTransition(trace) {
480
494
  ...trace,
481
495
  id: `t-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
482
496
  };
483
- log.info("transition:recorded", { trait: trace.traitName, from: trace.from, to: trace.to, event: trace.event, effectCount: trace.effects.length });
497
+ log2.debug("transition:recorded", { trait: trace.traitName, from: trace.from, to: trace.to, event: trace.event, effectCount: trace.effects.length });
484
498
  getState().transitions.push(entry);
485
499
  if (getState().transitions.length > MAX_TRANSITIONS) {
486
500
  getState().transitions.shift();
@@ -597,7 +611,7 @@ function getTraitSnapshots() {
597
611
  try {
598
612
  snapshots.push(getter());
599
613
  } catch (err) {
600
- log.error("traitSnapshot getter failed", { trait: traitName, err: String(err) });
614
+ log2.error("traitSnapshot getter failed", { trait: traitName, err: String(err) });
601
615
  }
602
616
  }
603
617
  return snapshots;
@@ -645,12 +659,12 @@ function waitForTransition(event, timeoutMs = 1e4) {
645
659
  }
646
660
  function bindEventBus(eventBus) {
647
661
  if (typeof window === "undefined") return;
648
- log.info("bindEventBus", { hasOnAny: !!eventBus.onAny });
662
+ log2.info("bindEventBus", { hasOnAny: !!eventBus.onAny });
649
663
  exposeOnWindow();
650
664
  if (window.__orbitalVerification) {
651
665
  window.__orbitalVerification.sendEvent = (event, payload, traitScope) => {
652
666
  const prefixed = event.startsWith("UI:") ? event : traitScope ? `UI:${traitScope}.${event}` : `UI:${event}`;
653
- log.debug("sendEvent", { event: prefixed, traitScope, payloadKeys: payload ? Object.keys(payload) : [] });
667
+ log2.debug("sendEvent", { event: prefixed, traitScope, payloadKeys: payload ? Object.keys(payload) : [] });
654
668
  eventBus.emit(prefixed, payload);
655
669
  };
656
670
  const eventLog = [];
@@ -2540,7 +2540,7 @@ var fallbackEventBus = {
2540
2540
  try {
2541
2541
  handler(event);
2542
2542
  } catch (error) {
2543
- console.error(`[EventBus] Error in listener for '${type}':`, error);
2543
+ log.error("Error in listener", { type, error: error instanceof Error ? error : String(error) });
2544
2544
  }
2545
2545
  });
2546
2546
  }
@@ -2548,7 +2548,7 @@ var fallbackEventBus = {
2548
2548
  try {
2549
2549
  handler(event);
2550
2550
  } catch (error) {
2551
- console.error(`[EventBus] Error in onAny listener for '${type}':`, error);
2551
+ log.error("Error in onAny listener", { type, error: error instanceof Error ? error : String(error) });
2552
2552
  }
2553
2553
  });
2554
2554
  },
@@ -2516,7 +2516,7 @@ var fallbackEventBus = {
2516
2516
  try {
2517
2517
  handler(event);
2518
2518
  } catch (error) {
2519
- console.error(`[EventBus] Error in listener for '${type}':`, error);
2519
+ log.error("Error in listener", { type, error: error instanceof Error ? error : String(error) });
2520
2520
  }
2521
2521
  });
2522
2522
  }
@@ -2524,7 +2524,7 @@ var fallbackEventBus = {
2524
2524
  try {
2525
2525
  handler(event);
2526
2526
  } catch (error) {
2527
- console.error(`[EventBus] Error in onAny listener for '${type}':`, error);
2527
+ log.error("Error in onAny listener", { type, error: error instanceof Error ? error : String(error) });
2528
2528
  }
2529
2529
  });
2530
2530
  },
@@ -26,8 +26,12 @@ export interface EventBusContextTypeExtended extends EventBusContextType {
26
26
  export declare const EventBusContext: React.Context<EventBusContextTypeExtended | null>;
27
27
  interface EventBusProviderProps {
28
28
  children: ReactNode;
29
- /** Enable debug logging in development */
29
+ /**
30
+ * @deprecated No-op. Logging is now gated by `@almadar/logger` —
31
+ * use `setLogLevel('DEBUG')` or `setNamespaceLevel('almadar:eventbus', 'DEBUG')`
32
+ * from `@almadar/logger` to control verbosity. Kept for API compatibility.
33
+ */
30
34
  debug?: boolean;
31
35
  }
32
- export declare function EventBusProvider({ children, debug }: EventBusProviderProps): import("react/jsx-runtime").JSX.Element;
36
+ export declare function EventBusProvider({ children }: EventBusProviderProps): import("react/jsx-runtime").JSX.Element;
33
37
  export type { EventBusContextType };