@leftium/gg 0.0.20 → 0.0.23
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/eruda/buffer.d.ts +26 -0
- package/dist/eruda/buffer.js +40 -0
- package/dist/eruda/index.d.ts +24 -0
- package/dist/eruda/index.js +82 -0
- package/dist/eruda/loader.d.ts +9 -0
- package/dist/eruda/loader.js +94 -0
- package/dist/eruda/plugin.d.ts +14 -0
- package/dist/eruda/plugin.js +625 -0
- package/dist/eruda/types.d.ts +52 -0
- package/dist/eruda/types.js +1 -0
- package/dist/gg.d.ts +15 -0
- package/dist/gg.js +104 -5
- package/package.json +26 -19
- package/dist/debug/ms/index.d.ts +0 -2
- package/dist/debug/ms/index.js +0 -162
- package/dist/debug/ms/package.json +0 -38
- package/dist/debug/package.json +0 -64
- package/dist/debug/src/browser.d.ts +0 -93
- package/dist/debug/src/browser.js +0 -272
- package/dist/debug/src/common.d.ts +0 -28
- package/dist/debug/src/common.js +0 -292
- package/dist/debug/src/index.d.ts +0 -104
- package/dist/debug/src/index.js +0 -10
- package/dist/debug/src/node.d.ts +0 -95
- package/dist/debug/src/node.js +0 -263
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CapturedEntry } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Ring buffer for captured log entries
|
|
4
|
+
*/
|
|
5
|
+
export declare class LogBuffer {
|
|
6
|
+
private entries;
|
|
7
|
+
private maxSize;
|
|
8
|
+
constructor(maxSize?: number);
|
|
9
|
+
/**
|
|
10
|
+
* Add an entry to the buffer
|
|
11
|
+
* If buffer is full, oldest entry is removed
|
|
12
|
+
*/
|
|
13
|
+
push(entry: CapturedEntry): void;
|
|
14
|
+
/**
|
|
15
|
+
* Get all entries (optionally filtered)
|
|
16
|
+
*/
|
|
17
|
+
getEntries(filter?: (entry: CapturedEntry) => boolean): CapturedEntry[];
|
|
18
|
+
/**
|
|
19
|
+
* Clear all entries
|
|
20
|
+
*/
|
|
21
|
+
clear(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get entry count
|
|
24
|
+
*/
|
|
25
|
+
get size(): number;
|
|
26
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ring buffer for captured log entries
|
|
3
|
+
*/
|
|
4
|
+
export class LogBuffer {
|
|
5
|
+
entries = [];
|
|
6
|
+
maxSize;
|
|
7
|
+
constructor(maxSize = 2000) {
|
|
8
|
+
this.maxSize = maxSize;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Add an entry to the buffer
|
|
12
|
+
* If buffer is full, oldest entry is removed
|
|
13
|
+
*/
|
|
14
|
+
push(entry) {
|
|
15
|
+
this.entries.push(entry);
|
|
16
|
+
if (this.entries.length > this.maxSize) {
|
|
17
|
+
this.entries.shift(); // Remove oldest
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get all entries (optionally filtered)
|
|
22
|
+
*/
|
|
23
|
+
getEntries(filter) {
|
|
24
|
+
if (!filter)
|
|
25
|
+
return [...this.entries];
|
|
26
|
+
return this.entries.filter(filter);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Clear all entries
|
|
30
|
+
*/
|
|
31
|
+
clear() {
|
|
32
|
+
this.entries = [];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get entry count
|
|
36
|
+
*/
|
|
37
|
+
get size() {
|
|
38
|
+
return this.entries.length;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { GgErudaOptions } from './types.js';
|
|
2
|
+
export type { GgErudaOptions, CapturedEntry, ErudaPlugin } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Initialize the gg Eruda plugin
|
|
5
|
+
*
|
|
6
|
+
* In development, loads Eruda eagerly.
|
|
7
|
+
* In production, loads only when triggers fire.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { initGgEruda } from '@leftium/gg/eruda';
|
|
12
|
+
*
|
|
13
|
+
* // Simple usage - works in dev, respects ?gg in prod
|
|
14
|
+
* initGgEruda();
|
|
15
|
+
*
|
|
16
|
+
* // Custom triggers
|
|
17
|
+
* initGgEruda({
|
|
18
|
+
* prod: 'url-param', // Only ?gg trigger, no gesture
|
|
19
|
+
* maxEntries: 5000,
|
|
20
|
+
* autoEnable: true
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function initGgEruda(options?: GgErudaOptions): void;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { BROWSER } from 'esm-env';
|
|
2
|
+
import { shouldLoadEruda, loadEruda } from './loader.js';
|
|
3
|
+
let initialized = false;
|
|
4
|
+
/**
|
|
5
|
+
* Initialize the gg Eruda plugin
|
|
6
|
+
*
|
|
7
|
+
* In development, loads Eruda eagerly.
|
|
8
|
+
* In production, loads only when triggers fire.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { initGgEruda } from '@leftium/gg/eruda';
|
|
13
|
+
*
|
|
14
|
+
* // Simple usage - works in dev, respects ?gg in prod
|
|
15
|
+
* initGgEruda();
|
|
16
|
+
*
|
|
17
|
+
* // Custom triggers
|
|
18
|
+
* initGgEruda({
|
|
19
|
+
* prod: 'url-param', // Only ?gg trigger, no gesture
|
|
20
|
+
* maxEntries: 5000,
|
|
21
|
+
* autoEnable: true
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function initGgEruda(options = {}) {
|
|
26
|
+
// Only run in browser
|
|
27
|
+
if (!BROWSER)
|
|
28
|
+
return;
|
|
29
|
+
// Prevent double initialization
|
|
30
|
+
if (initialized) {
|
|
31
|
+
console.warn('[gg] initGgEruda() called multiple times. Ignoring subsequent calls.');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
initialized = true;
|
|
35
|
+
// Check if we should load Eruda
|
|
36
|
+
if (!shouldLoadEruda(options)) {
|
|
37
|
+
// In production without triggers, set up gesture detection if enabled
|
|
38
|
+
const prodTriggers = options.prod ?? ['url-param', 'gesture'];
|
|
39
|
+
const triggerArray = Array.isArray(prodTriggers) ? prodTriggers : [prodTriggers];
|
|
40
|
+
if (triggerArray.includes('gesture')) {
|
|
41
|
+
setupGestureDetection(options);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// Load Eruda
|
|
46
|
+
loadEruda(options);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Set up 5-tap gesture detection for production
|
|
50
|
+
*/
|
|
51
|
+
function setupGestureDetection(options) {
|
|
52
|
+
let tapCount = 0;
|
|
53
|
+
let tapTimer = null;
|
|
54
|
+
const resetTaps = () => {
|
|
55
|
+
tapCount = 0;
|
|
56
|
+
if (tapTimer)
|
|
57
|
+
clearTimeout(tapTimer);
|
|
58
|
+
tapTimer = null;
|
|
59
|
+
};
|
|
60
|
+
document.addEventListener('click', () => {
|
|
61
|
+
tapCount++;
|
|
62
|
+
// Reset timer on each tap
|
|
63
|
+
if (tapTimer)
|
|
64
|
+
clearTimeout(tapTimer);
|
|
65
|
+
// If 5 taps detected, load Eruda
|
|
66
|
+
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
|
+
}
|
|
75
|
+
loadEruda(options);
|
|
76
|
+
resetTaps();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// Reset after 1 second of no taps
|
|
80
|
+
tapTimer = setTimeout(resetTaps, 1000);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GgErudaOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if Eruda should be loaded based on environment and triggers
|
|
4
|
+
*/
|
|
5
|
+
export declare function shouldLoadEruda(options: GgErudaOptions): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Dynamically imports and initializes Eruda
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadEruda(options: GgErudaOptions): Promise<void>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { BROWSER, DEV } from 'esm-env';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if any production trigger is active
|
|
4
|
+
*/
|
|
5
|
+
function checkProdTriggers(triggers) {
|
|
6
|
+
if (!BROWSER)
|
|
7
|
+
return false;
|
|
8
|
+
if (triggers === false)
|
|
9
|
+
return false;
|
|
10
|
+
const triggerArray = Array.isArray(triggers) ? triggers : [triggers];
|
|
11
|
+
for (const trigger of triggerArray) {
|
|
12
|
+
if (trigger === 'url-param') {
|
|
13
|
+
try {
|
|
14
|
+
const params = new URLSearchParams(window.location.search);
|
|
15
|
+
if (params.has('gg')) {
|
|
16
|
+
// Persist the decision
|
|
17
|
+
localStorage.setItem('gg-enabled', 'true');
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// URLSearchParams might not be available
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (trigger === 'localStorage') {
|
|
26
|
+
try {
|
|
27
|
+
if (localStorage.getItem('gg-enabled') === 'true') {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// localStorage might not be available
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (trigger === 'gesture') {
|
|
36
|
+
// TODO: Implement 5-tap gesture detection
|
|
37
|
+
// For now, fall through
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Determines if Eruda should be loaded based on environment and triggers
|
|
44
|
+
*/
|
|
45
|
+
export function shouldLoadEruda(options) {
|
|
46
|
+
if (!BROWSER)
|
|
47
|
+
return false;
|
|
48
|
+
// Development - always load
|
|
49
|
+
if (DEV)
|
|
50
|
+
return true;
|
|
51
|
+
// Production - check triggers
|
|
52
|
+
const prodTriggers = options.prod ?? ['url-param', 'gesture'];
|
|
53
|
+
return checkProdTriggers(prodTriggers);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Dynamically imports and initializes Eruda
|
|
57
|
+
*/
|
|
58
|
+
export async function loadEruda(options) {
|
|
59
|
+
if (!BROWSER)
|
|
60
|
+
return;
|
|
61
|
+
try {
|
|
62
|
+
// Dynamic import of Eruda
|
|
63
|
+
const erudaModule = await import('eruda');
|
|
64
|
+
const eruda = erudaModule.default;
|
|
65
|
+
// Initialize Eruda
|
|
66
|
+
eruda.init({
|
|
67
|
+
...options.erudaOptions,
|
|
68
|
+
// Ensure tool is always visible in case user customizes
|
|
69
|
+
tool: ['console', 'elements', 'network', 'resources', 'info', 'snippets', 'sources']
|
|
70
|
+
});
|
|
71
|
+
// Auto-enable localStorage.debug if requested and unset
|
|
72
|
+
if (options.autoEnable !== false) {
|
|
73
|
+
try {
|
|
74
|
+
if (!localStorage.getItem('debug')) {
|
|
75
|
+
localStorage.setItem('debug', 'gg:*');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// localStorage might not be available
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Register gg plugin
|
|
83
|
+
// Import gg and pass it to the plugin directly
|
|
84
|
+
const { gg } = await import('../gg.js');
|
|
85
|
+
const { createGgPlugin } = await import('./plugin.js');
|
|
86
|
+
const ggPlugin = createGgPlugin(options, gg);
|
|
87
|
+
eruda.add(ggPlugin);
|
|
88
|
+
// Make GG tab the default selected tab
|
|
89
|
+
eruda.show('GG');
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.error('[gg] Failed to load Eruda:', error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GgErudaOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the gg Eruda plugin
|
|
4
|
+
*
|
|
5
|
+
* Uses Eruda's plugin API where $el is a jQuery-like (licia) wrapper.
|
|
6
|
+
* Methods: $el.html(), $el.show(), $el.hide(), $el.find(), $el.on()
|
|
7
|
+
*/
|
|
8
|
+
export declare function createGgPlugin(options: GgErudaOptions, gg: any): {
|
|
9
|
+
name: string;
|
|
10
|
+
init($container: any): void;
|
|
11
|
+
show(): void;
|
|
12
|
+
hide(): void;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
};
|