@leftium/gg 0.0.51 → 0.0.53

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.
@@ -1,5 +1,6 @@
1
1
  import { BROWSER } from 'esm-env';
2
2
  import { shouldLoadEruda, loadEruda } from './loader.js';
3
+ import { enableGgRuntime } from '../gg.js';
3
4
  let initialized = false;
4
5
  /**
5
6
  * Initialize the gg Eruda plugin
@@ -62,16 +63,11 @@ function setupGestureDetection(options) {
62
63
  // Reset timer on each tap
63
64
  if (tapTimer)
64
65
  clearTimeout(tapTimer);
65
- // If 5 taps detected, load Eruda
66
+ // If 5 taps detected, enable gg logging and load Eruda
66
67
  if (tapCount >= 5) {
67
- console.log('[gg] 5 taps detected, loading Eruda...');
68
- // Persist the decision
69
- try {
70
- localStorage.setItem('gg-enabled', 'true');
71
- }
72
- catch {
73
- // localStorage might not be available
74
- }
68
+ console.log('[gg] 5 taps detected, enabling gg logging and loading Eruda (session-only). For persistent logging across app restarts, run: localStorage.setItem("gg-enabled", "true")');
69
+ // Enable gg runtime for this session (flips ggConfig.enabled in memory only)
70
+ enableGgRuntime();
75
71
  loadEruda(options);
76
72
  resetTaps();
77
73
  return;
package/dist/gg.d.ts CHANGED
@@ -91,6 +91,20 @@ export declare class GgChain<T> {
91
91
  /** Flush the log immediately and return the passthrough value. */
92
92
  get v(): T;
93
93
  }
94
+ /**
95
+ * Enable gg logging at runtime (e.g., after 5-tap gesture in production).
96
+ * Flips the internal enabled flag so subsequent gg() calls start capturing.
97
+ * This is session-only — does not persist to localStorage, so the next
98
+ * page load / app launch starts with gg disabled again.
99
+ *
100
+ * To enable gg across app restarts (e.g., in a prod Tauri app), run this
101
+ * in the Eruda console instead:
102
+ * localStorage.setItem("gg-enabled", "true")
103
+ * Clear with: localStorage.removeItem("gg-enabled") or gg.clearPersist()
104
+ *
105
+ * @internal Used by the Eruda gesture handler — not part of the public API.
106
+ */
107
+ export declare function enableGgRuntime(): void;
94
108
  /**
95
109
  * Chainable wrapper returned by gg.time(). Only supports .ns() for setting
96
110
  * the namespace for the entire timer group (inherited by timeLog/timeEnd).
package/dist/gg.js CHANGED
@@ -1,5 +1,5 @@
1
- import debugFactory, { debugReady } from './debug/index.js';
2
1
  import { BROWSER, DEV } from 'esm-env';
2
+ import debugFactory, { debugReady } from './debug/index.js';
3
3
  import { toWordTuple } from './words.js';
4
4
  const _ggCallSitesPlugin = typeof __GG_TAG_PLUGIN__ !== 'undefined' ? __GG_TAG_PLUGIN__ : false;
5
5
  /**
@@ -11,7 +11,7 @@ function createGgDebugger(namespace) {
11
11
  // Store the original formatArgs
12
12
  const originalFormatArgs = dbg.formatArgs;
13
13
  // Override formatArgs to add padding to the namespace display
14
- dbg.formatArgs = function (args) {
14
+ dbg.formatArgs = (args) => {
15
15
  // Call original formatArgs first
16
16
  if (originalFormatArgs) {
17
17
  originalFormatArgs.call(dbg, args);
@@ -232,7 +232,7 @@ export function gg(...args) {
232
232
  * @example
233
233
  * <OpenInEditorLink gg={gg.here()} />
234
234
  */
235
- gg.here = function () {
235
+ gg.here = () => {
236
236
  if (!ggConfig.enabled) {
237
237
  return { fileName: '', functionName: '', url: '' };
238
238
  }
@@ -448,14 +448,15 @@ function ggLog(options, ...args) {
448
448
  // on CapturedEntry for the Eruda UI to display on hover)
449
449
  const logArgs = args.length === 0 ? ['(no args)'] : [...args];
450
450
  // Add level prefix emoji for info/warn/error
451
- if (level === 'info') {
452
- logArgs[0] = `ℹ️ ${logArgs[0]}`;
453
- }
454
- else if (level === 'warn') {
455
- logArgs[0] = `⚠️ ${logArgs[0]}`;
456
- }
457
- else if (level === 'error') {
458
- logArgs[0] = `⛔ ${logArgs[0]}`;
451
+ const levelEmoji = level === 'info' ? 'ℹ️' : level === 'warn' ? '⚠️' : level === 'error' ? '⛔' : '';
452
+ if (levelEmoji) {
453
+ if (typeof logArgs[0] === 'string') {
454
+ logArgs[0] = `${levelEmoji} ${logArgs[0]}`;
455
+ }
456
+ else {
457
+ // Don't coerce objects to string via template literal — prepend emoji as separate arg
458
+ logArgs.unshift(levelEmoji);
459
+ }
459
460
  }
460
461
  // Compute diff independently of the debug library's enabled state.
461
462
  // ggLogFunction.diff only updates when the debugger is enabled (i.e. localStorage.debug
@@ -508,7 +509,7 @@ function ggLog(options, ...args) {
508
509
  *
509
510
  * Returns a GgChain for chaining modifiers (.ns(), .warn(), etc.)
510
511
  */
511
- gg._ns = function (options, ...args) {
512
+ gg._ns = (options, ...args) => {
512
513
  const disabled = !ggConfig.enabled;
513
514
  return new GgChain(args[0], args, options, disabled);
514
515
  };
@@ -517,7 +518,7 @@ gg._ns = function (options, ...args) {
517
518
  *
518
519
  * Called by the ggCallSitesPlugin when it rewrites gg.here() calls.
519
520
  */
520
- gg._here = function (options) {
521
+ gg._here = (options) => {
521
522
  if (!ggConfig.enabled) {
522
523
  return { fileName: '', functionName: '', url: '' };
523
524
  }
@@ -540,9 +541,7 @@ gg._here = function (options) {
540
541
  * In <script> blocks: gg._ns({ns:'...', file:'...', line:1, col:1}, args)
541
542
  * In template markup: gg._ns(gg._o('...','...',1,1), args)
542
543
  */
543
- gg._o = function (ns, file, line, col, src) {
544
- return { ns, file, line, col, src };
545
- };
544
+ gg._o = (ns, file, line, col, src) => ({ ns, file, line, col, src });
546
545
  gg.disable = isCloudflareWorker() ? () => '' : () => debugFactory.disable();
547
546
  gg.enable = isCloudflareWorker() ? () => { } : (ns) => debugFactory.enable(ns);
548
547
  /**
@@ -560,6 +559,22 @@ gg.clearPersist = () => {
560
559
  }
561
560
  }
562
561
  };
562
+ /**
563
+ * Enable gg logging at runtime (e.g., after 5-tap gesture in production).
564
+ * Flips the internal enabled flag so subsequent gg() calls start capturing.
565
+ * This is session-only — does not persist to localStorage, so the next
566
+ * page load / app launch starts with gg disabled again.
567
+ *
568
+ * To enable gg across app restarts (e.g., in a prod Tauri app), run this
569
+ * in the Eruda console instead:
570
+ * localStorage.setItem("gg-enabled", "true")
571
+ * Clear with: localStorage.removeItem("gg-enabled") or gg.clearPersist()
572
+ *
573
+ * @internal Used by the Eruda gesture handler — not part of the public API.
574
+ */
575
+ export function enableGgRuntime() {
576
+ ggConfig.enabled = true;
577
+ }
563
578
  // ── Console-like methods ───────────────────────────────────────────────
564
579
  // Each public method (gg.warn, gg.error, etc.) has a corresponding internal
565
580
  // method (gg._warn, gg._error, etc.) that accepts call-site metadata from
@@ -633,7 +648,7 @@ gg.time = function (label = 'default') {
633
648
  return new GgTimerChain(label, options);
634
649
  };
635
650
  /** gg._time() - Internal: time with call-site metadata from Vite plugin. */
636
- gg._time = function (options, label = 'default') {
651
+ gg._time = (options, label = 'default') => {
637
652
  if (ggConfig.enabled) {
638
653
  timers.set(label, { start: performance.now(), options });
639
654
  }
@@ -665,7 +680,7 @@ gg.timeLog = function (label = 'default', ...args) {
665
680
  ggLog({ ...timer.options, ns }, `${label}: ${formatElapsed(elapsed)}`, ...args);
666
681
  };
667
682
  /** gg._timeLog() - Internal: timeLog with call-site metadata from Vite plugin. */
668
- gg._timeLog = function (options, label = 'default', ...args) {
683
+ gg._timeLog = (options, label = 'default', ...args) => {
669
684
  if (!ggConfig.enabled)
670
685
  return;
671
686
  const timer = timers.get(label);
@@ -702,7 +717,7 @@ gg.timeEnd = function (label = 'default') {
702
717
  ggLog({ ...timer.options, ns }, `${label}: ${formatElapsed(elapsed)}`);
703
718
  };
704
719
  /** gg._timeEnd() - Internal: timeEnd with call-site metadata from Vite plugin. */
705
- gg._timeEnd = function (options, label = 'default') {
720
+ gg._timeEnd = (options, label = 'default') => {
706
721
  if (!ggConfig.enabled)
707
722
  return;
708
723
  const timer = timers.get(label);
@@ -871,7 +886,7 @@ const STYLE_CODES = {
871
886
  * Internal helper to create chainable color function with method chaining
872
887
  */
873
888
  function createColorFunction(fgCode = '', bgCode = '', styleCode = '') {
874
- const tagFn = function (strings, ...values) {
889
+ const tagFn = (strings, ...values) => {
875
890
  const text = strings.reduce((acc, str, i) => acc + str + (values[i] !== undefined ? String(values[i]) : ''), '');
876
891
  return fgCode + bgCode + styleCode + text + '\x1b[0m';
877
892
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leftium/gg",
3
- "version": "0.0.51",
3
+ "version": "0.0.53",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Leftium/gg.git"