@leftium/gg 0.0.21 → 0.0.24

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 CHANGED
@@ -29,11 +29,13 @@ _Coming soon..._
29
29
  This library includes a **patched version** of the [`debug`](https://www.npmjs.com/package/debug) package. The patch reformats the output to display time diffs **before** the namespace for better readability:
30
30
 
31
31
  **Standard debug output:**
32
+
32
33
  ```
33
34
  gg:routes/+page.svelte +123ms
34
35
  ```
35
36
 
36
37
  **Patched output (this library):**
38
+
37
39
  ```
38
40
  +123ms gg:routes/+page.svelte
39
41
  ```
@@ -1 +1,3 @@
1
+ // @ts-nocheck
2
+ // Auto-generated bundled debug library - type checking disabled
1
3
  import e from"tty";import t from"util";function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function n(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var s,o,i,c,a,u={exports:{}},l={exports:{}};function f(){if(o)return s;o=1;var e=1e3,t=60*e,r=60*t,n=24*r,i=7*n,c=365.25*n;function a(e,t,r,n){var s=t>=1.5*r;return Math.round(e/r)+" "+n+(s?"s":"")}return s=function(s,o){o=o||{};var u=typeof s;if("string"===u&&s.length>0)return function(s){if((s=String(s)).length>100)return;var o=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(!o)return;var a=parseFloat(o[1]);switch((o[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return a*c;case"weeks":case"week":case"w":return a*i;case"days":case"day":case"d":return a*n;case"hours":case"hour":case"hrs":case"hr":case"h":return a*r;case"minutes":case"minute":case"mins":case"min":case"m":return a*t;case"seconds":case"second":case"secs":case"sec":case"s":return a*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}(s);if("number"===u&&isFinite(s))return o.long?function(s){var o=Math.abs(s);if(o>=n)return a(s,o,n,"day");if(o>=r)return a(s,o,r,"hour");if(o>=t)return a(s,o,t,"minute");if(o>=e)return a(s,o,e,"second");return s+" ms"}(s):function(s){var o=Math.abs(s);if(o>=n)return Math.round(s/n)+"d";if(o>=r)return Math.round(s/r)+"h";if(o>=t)return Math.round(s/t)+"m";if(o>=e)return Math.round(s/e)+"s";return s+"ms"}(s);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(s))}}function p(){if(c)return i;return c=1,i=function(e){function t(e){let n,s,o,i=null;function c(...e){if(!c.enabled)return;const r=c,s=Number(new Date),o=s-(n||s);r.diff=o,r.prev=n,r.curr=s,n=s,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(n,s)=>{if("%%"===n)return"%";i++;const o=t.formatters[s];if("function"==typeof o){const t=e[i];n=o.call(r,t),e.splice(i,1),i--}return n}),t.formatArgs.call(r,e);(r.log||t.log).apply(r,e)}return c.namespace=e,c.useColors=t.useColors(),c.color=t.selectColor(e),c.extend=r,c.destroy=t.destroy,Object.defineProperty(c,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(s!==t.namespaces&&(s=t.namespaces,o=t.enabled(e)),o),set:e=>{i=e}}),"function"==typeof t.init&&t.init(c),c}function r(e,r){const n=t(this.namespace+(void 0===r?":":r)+e);return n.log=this.log,n}function n(e,t){let r=0,n=0,s=-1,o=0;for(;r<e.length;)if(n<t.length&&(t[n]===e[r]||"*"===t[n]))"*"===t[n]?(s=n,o=r,n++):(r++,n++);else{if(-1===s)return!1;n=s+1,o++,r=o}for(;n<t.length&&"*"===t[n];)n++;return n===t.length}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of r)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(const r of t.skips)if(n(e,r))return!1;for(const r of t.names)if(n(e,r))return!0;return!1},t.humanize=f(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(r=>{t[r]=e[r]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let r=0;for(let t=0;t<e.length;t++)r=(r<<5)-r+e.charCodeAt(t),r|=0;return t.colors[Math.abs(r)%t.colors.length]},t.enable(t.load()),t},i}var d={exports:{}};const C=(()=>{if(!("navigator"in globalThis))return 0;if(globalThis.navigator.userAgentData){const e=navigator.userAgentData.brands.find(({brand:e})=>"Chromium"===e);if(e?.version>93)return 3}return/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)?1:0})(),m=0!==C&&{level:C,hasBasic:!0,has256:C>=2,has16m:C>=3},g={stdout:m,stderr:m};var h,F,y=n(Object.freeze({__proto__:null,default:g}));function b(){return h||(h=1,function(r,n){const s=e,o=t;n.init=function(e){e.inspectOpts={};const t=Object.keys(n.inspectOpts);for(let r=0;r<t.length;r++)e.inspectOpts[t[r]]=n.inspectOpts[t[r]]},n.log=function(...e){return process.stderr.write(o.formatWithOptions(n.inspectOpts,...e)+"\n")},n.formatArgs=function(e){const{namespace:t,useColors:s}=this;if(s){const n=this.color,s="[3"+(n<8?n:"8;5;"+n),o=`${s};1m${("+"+r.exports.humanize(this.diff)).padStart(6)} ${t} `;e[0]=o+e[0].split("\n").join("\n"+o),e.push(s+"")}else e[0]=function(){if(n.inspectOpts.hideDate)return"";return(new Date).toISOString()+" "}()+t+" "+e[0]},n.save=function(e){e?process.env.DEBUG=e:delete process.env.DEBUG},n.load=function(){return process.env.DEBUG},n.useColors=function(){return"colors"in n.inspectOpts?Boolean(n.inspectOpts.colors):s.isatty(process.stderr.fd)},n.destroy=o.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."),n.colors=[6,2,3,4,5,1];try{const e=y;e&&(e.stderr||e).level>=2&&(n.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch(e){}n.inspectOpts=Object.keys(process.env).filter(e=>/^debug_/i.test(e)).reduce((e,t)=>{const r=t.substring(6).toLowerCase().replace(/_([a-z])/g,(e,t)=>t.toUpperCase());let n=process.env[t];return n=!!/^(yes|on|true|enabled)$/i.test(n)||!/^(no|off|false|disabled)$/i.test(n)&&("null"===n?null:Number(n)),e[r]=n,e},{}),r.exports=p()(n);const{formatters:i}=r.exports;i.o=function(e){return this.inspectOpts.colors=this.useColors,o.inspect(e,this.inspectOpts).split("\n").map(e=>e.trim()).join(" ")},i.O=function(e){return this.inspectOpts.colors=this.useColors,o.inspect(e,this.inspectOpts)}}(d,d.exports)),d.exports}var v=(F||(F=1,"undefined"==typeof process||"renderer"===process.type||!0===process.browser||process.__nwjs?u.exports=(a||(a=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+`${("+"+e.exports.humanize(this.diff)).padStart(6)} ${this.namespace}`+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" "),!this.useColors)return;const r="color: "+this.color;t.splice(1,0,r,"color: inherit");let n=0,s=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(n++,"%c"===e&&(s=n))}),t.splice(s,0,r)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=p()(t);const{formatters:r}=e.exports;r.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(l,l.exports)),l.exports):u.exports=b()),u.exports),w=r(v);export{w as default};
@@ -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,95 @@
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
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
+ eruda.add(ggPlugin);
89
+ // Make GG tab the default selected tab
90
+ eruda.show('GG');
91
+ }
92
+ catch (error) {
93
+ console.error('[gg] Failed to load Eruda:', error);
94
+ }
95
+ }
@@ -0,0 +1,29 @@
1
+ import type { GgErudaOptions, CapturedEntry } from './types.js';
2
+ /**
3
+ * Licia jQuery-like wrapper used by Eruda
4
+ */
5
+ interface LiciaElement {
6
+ html(content: string): void;
7
+ show(): void;
8
+ hide(): void;
9
+ find(selector: string): LiciaElement;
10
+ on(event: string, handler: (e: Event) => void): void;
11
+ get(index: number): HTMLElement | undefined;
12
+ length: number;
13
+ }
14
+ /**
15
+ * Creates the gg Eruda plugin
16
+ *
17
+ * Uses Eruda's plugin API where $el is a jQuery-like (licia) wrapper.
18
+ * Methods: $el.html(), $el.show(), $el.hide(), $el.find(), $el.on()
19
+ */
20
+ export declare function createGgPlugin(options: GgErudaOptions, gg: {
21
+ _onLog?: ((entry: CapturedEntry) => void) | null;
22
+ }): {
23
+ name: string;
24
+ init($container: LiciaElement): void;
25
+ show(): void;
26
+ hide(): void;
27
+ destroy(): void;
28
+ };
29
+ export {};