@ogxjs/core 0.1.1 → 0.2.0-alpha.1

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.
Files changed (62) hide show
  1. package/dist/builder.d.ts +5 -0
  2. package/dist/builder.d.ts.map +1 -1
  3. package/dist/builder.js +11 -1
  4. package/dist/cache/hash.d.ts +66 -0
  5. package/dist/cache/hash.d.ts.map +1 -0
  6. package/dist/cache/hash.js +161 -0
  7. package/dist/cache/index.d.ts +10 -0
  8. package/dist/cache/index.d.ts.map +1 -0
  9. package/dist/cache/index.js +12 -0
  10. package/dist/cache/lru.d.ts +122 -0
  11. package/dist/cache/lru.d.ts.map +1 -0
  12. package/dist/cache/lru.js +269 -0
  13. package/dist/cache/snapshot.d.ts +116 -0
  14. package/dist/cache/snapshot.d.ts.map +1 -0
  15. package/dist/cache/snapshot.js +204 -0
  16. package/dist/cache.d.ts +2 -2
  17. package/dist/cache.js +2 -2
  18. package/dist/css.d.ts +19 -6
  19. package/dist/css.d.ts.map +1 -1
  20. package/dist/index.d.ts +18 -4
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +41 -10
  23. package/dist/ogx.js +2 -2
  24. package/dist/perf/index.d.ts +8 -0
  25. package/dist/perf/index.d.ts.map +1 -0
  26. package/dist/perf/index.js +7 -0
  27. package/dist/perf/timing.d.ts +160 -0
  28. package/dist/perf/timing.d.ts.map +1 -0
  29. package/dist/perf/timing.js +305 -0
  30. package/dist/presets/blog.js +1 -1
  31. package/dist/presets/docs.d.ts +2 -0
  32. package/dist/presets/docs.d.ts.map +1 -1
  33. package/dist/presets/docs.js +26 -23
  34. package/dist/presets/minimal.d.ts +2 -0
  35. package/dist/presets/minimal.d.ts.map +1 -1
  36. package/dist/presets/minimal.js +8 -16
  37. package/dist/presets/social.d.ts +2 -0
  38. package/dist/presets/social.d.ts.map +1 -1
  39. package/dist/presets/social.js +28 -18
  40. package/dist/render-png.d.ts.map +1 -1
  41. package/dist/render-png.js +9 -1
  42. package/dist/render-svg.d.ts.map +1 -1
  43. package/dist/render-svg.js +11 -1
  44. package/dist/tailwind/class-cache.d.ts +141 -0
  45. package/dist/tailwind/class-cache.d.ts.map +1 -0
  46. package/dist/tailwind/class-cache.js +212 -0
  47. package/dist/tailwind/index.d.ts +14 -1
  48. package/dist/tailwind/index.d.ts.map +1 -1
  49. package/dist/tailwind/index.js +15 -1
  50. package/dist/tailwind/lookup-tables.d.ts +30 -0
  51. package/dist/tailwind/lookup-tables.d.ts.map +1 -0
  52. package/dist/tailwind/lookup-tables.js +427 -0
  53. package/dist/tailwind/parser-v2.d.ts +54 -0
  54. package/dist/tailwind/parser-v2.d.ts.map +1 -0
  55. package/dist/tailwind/parser-v2.js +250 -0
  56. package/dist/tailwind/parser.d.ts +1 -0
  57. package/dist/tailwind/parser.d.ts.map +1 -1
  58. package/dist/tailwind/parser.js +1 -0
  59. package/dist/tailwind/prefix-handlers.d.ts +68 -0
  60. package/dist/tailwind/prefix-handlers.d.ts.map +1 -0
  61. package/dist/tailwind/prefix-handlers.js +931 -0
  62. package/package.json +17 -2
package/dist/index.d.ts CHANGED
@@ -1,17 +1,31 @@
1
- export { absolute, badge, card, div, fluent, footer, grid, h, h1, h2, header, img, imgFromUrl, main, p, row, spacer, span, stack, svgFromContent, validateImageUrl, } from "./builder";
2
- export { snapshotCache } from "./cache";
1
+ /**
2
+ * @ogxjs/core - High-performance OG Image Generator
3
+ *
4
+ * @description
5
+ * Generate beautiful Open Graph images using Tailwind CSS classes.
6
+ * Built for Node.js, Bun, and Deno.
7
+ *
8
+ * @version 0.2.0 "Turbo"
9
+ * @see https://ogx-three.vercel.app
10
+ */
11
+ export { absolute, badge, card, div, fluent, footer, grid, h, h1, h2, header, img, imgFromUrl, main, p, row, spacer, span, stack, svgFromContent, unsafe_img, validateImageUrl, } from "./builder";
12
+ export type { LRUCacheOptions, LRUCacheStats, SnapshotCacheOptions, SnapshotCacheStats, } from "./cache/index";
13
+ export { configureSnapshotCache, fastHash, fnv1a, getSnapshotCache, hashObject, LRUCache, snapshotCache, } from "./cache/index";
3
14
  export type { CSSProperties } from "./css";
4
15
  export { fontRegistry } from "./font-registry";
5
16
  export { createFont, loadFont, loadFontFromUrl, loadInterFont, loadInterFromUrl, } from "./fonts";
6
17
  export { ogx, ogxToSVG } from "./ogx";
18
+ export type { TimingAggregate, TimingEntry, TimingReport } from "./perf";
19
+ export { benchmark, benchmarkSync, quickTime, quickTimeSync, Timer, timing, } from "./perf";
7
20
  export type { BlogPresetProps, DocsPresetProps, MinimalPresetProps, SocialPresetProps, } from "./presets";
8
21
  export { blogPreset, docsPreset, minimalPreset, presets, socialPreset, } from "./presets";
9
22
  export { render } from "./render-png";
10
23
  export { renderToSVG } from "./render-svg";
11
- export { parseTailwind } from "./tailwind";
24
+ export type { CacheStats, GradientState, ParseContext } from "./tailwind";
25
+ export { clearAllCaches, getCacheStats, isStaticClass, parseTailwind, parseTailwindBatch, STATIC_CLASSES, } from "./tailwind";
12
26
  export type { Platform } from "./targets";
13
27
  export { getPlatformDimensions } from "./targets";
14
- export type { FontConfig, OGXBaseConfig, OGXChildren, OGXConfig, OGXElement, OGXElementProps, Preset, PresetName, PresetProps, RenderOptions, } from "./types";
28
+ export type { FontConfig, OGXBaseConfig, OGXChildren, OGXConfig, OGXElement, OGXElementProps, Preset, PresetName, PresetProps, RenderOptions, ThemeConfig, } from "./types";
15
29
  export { loadAsset, toDataUri } from "./utils/assets";
16
30
  export type { FitTextOptions } from "./utils/text";
17
31
  export { calculateFittingFontSize } from "./utils/text";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,GAAG,EACH,MAAM,EACN,MAAM,EACN,IAAI,EACJ,CAAC,EACD,EAAE,EACF,EAAE,EACF,MAAM,EACN,GAAG,EACH,UAAU,EACV,IAAI,EACJ,CAAC,EACD,GAA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,YAAY,CAAC;AAI1E,OAAO,EACN,cAAc,EACd,aAAa,EACb,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,cAAc,GACd,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAI1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EACX,UAAU,EACV,aAAa,EACb,WAAW,EACX,SAAS,EACT,UAAU,EACV,eAAe,EACf,MAAM,EACN,UAAU,EACV,WAAW,EACX,aAAa,EACb,WAAW,GACX,MAAM,SAAS,CAAC;AAKjB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,19 +1,50 @@
1
- // @ogxjs/core - Main exports
2
- // Builder - Element construction
3
- export { absolute, badge, card, div, fluent, footer, grid, h, h1, h2, header, img, imgFromUrl, main, p, row, spacer, span, stack, svgFromContent, validateImageUrl, } from "./builder";
4
- // Utilities
5
- export { snapshotCache } from "./cache";
6
- // Fonts - Loading and registration
1
+ /**
2
+ * @ogxjs/core - High-performance OG Image Generator
3
+ *
4
+ * @description
5
+ * Generate beautiful Open Graph images using Tailwind CSS classes.
6
+ * Built for Node.js, Bun, and Deno.
7
+ *
8
+ * @version 0.2.0 "Turbo"
9
+ * @see https://ogx-three.vercel.app
10
+ */
11
+ // ═══════════════════════════════════════════════════════════════════════════
12
+ // BUILDER - Element construction
13
+ // ═══════════════════════════════════════════════════════════════════════════
14
+ export { absolute, badge, card, div, fluent, footer, grid, h, h1, h2, header, img, imgFromUrl, main, p, row, spacer, span, stack, svgFromContent, unsafe_img, validateImageUrl, } from "./builder";
15
+ // ═══════════════════════════════════════════════════════════════════════════
16
+ // CACHE - v2 with LRU + Fast Hash
17
+ // ═══════════════════════════════════════════════════════════════════════════
18
+ export { configureSnapshotCache, fastHash, fnv1a, getSnapshotCache, hashObject, LRUCache, snapshotCache, } from "./cache/index";
19
+ // ═══════════════════════════════════════════════════════════════════════════
20
+ // FONTS - Loading and registration
21
+ // ═══════════════════════════════════════════════════════════════════════════
7
22
  export { fontRegistry } from "./font-registry";
8
23
  export { createFont, loadFont, loadFontFromUrl, loadInterFont, loadInterFromUrl, } from "./fonts";
9
- // Rendering - SVG and PNG generation
24
+ // ═══════════════════════════════════════════════════════════════════════════
25
+ // RENDERING - SVG and PNG generation
26
+ // ═══════════════════════════════════════════════════════════════════════════
10
27
  export { ogx, ogxToSVG } from "./ogx";
11
- // Presets - Ready-to-use templates
28
+ // ═══════════════════════════════════════════════════════════════════════════
29
+ // PERFORMANCE - Timing API
30
+ // ═══════════════════════════════════════════════════════════════════════════
31
+ export { benchmark, benchmarkSync, quickTime, quickTimeSync, Timer, timing, } from "./perf";
32
+ // ═══════════════════════════════════════════════════════════════════════════
33
+ // PRESETS - Ready-to-use templates
34
+ // ═══════════════════════════════════════════════════════════════════════════
12
35
  export { blogPreset, docsPreset, minimalPreset, presets, socialPreset, } from "./presets";
13
36
  export { render } from "./render-png";
14
37
  export { renderToSVG } from "./render-svg";
15
- export { parseTailwind } from "./tailwind";
16
- // Platform - Target dimensions
38
+ // ═══════════════════════════════════════════════════════════════════════════
39
+ // TAILWIND - Parser v2 with O(1) lookups
40
+ // ═══════════════════════════════════════════════════════════════════════════
41
+ export { clearAllCaches, getCacheStats, isStaticClass, parseTailwind, parseTailwindBatch, STATIC_CLASSES, } from "./tailwind";
42
+ // ═══════════════════════════════════════════════════════════════════════════
43
+ // PLATFORM - Target dimensions
44
+ // ═══════════════════════════════════════════════════════════════════════════
17
45
  export { getPlatformDimensions } from "./targets";
46
+ // ═══════════════════════════════════════════════════════════════════════════
47
+ // UTILITIES
48
+ // ═══════════════════════════════════════════════════════════════════════════
18
49
  export { loadAsset, toDataUri } from "./utils/assets";
19
50
  export { calculateFittingFontSize } from "./utils/text";
package/dist/ogx.js CHANGED
@@ -25,7 +25,7 @@ export async function ogx(config) {
25
25
  if (!presetFn) {
26
26
  throw new Error(`Unknown preset: ${preset}`);
27
27
  }
28
- const element = presetFn({ ...props, slots });
28
+ const element = presetFn({ ...props, slots, colorScheme });
29
29
  // Resolve fonts (Registry > Explicit > Default Inter)
30
30
  let resolvedFonts = fonts ?? [];
31
31
  if (resolvedFonts.length === 0) {
@@ -74,7 +74,7 @@ export async function ogxToSVG(config) {
74
74
  if (!presetFn) {
75
75
  throw new Error(`Unknown preset: ${preset}`);
76
76
  }
77
- const element = presetFn({ ...props, slots });
77
+ const element = presetFn({ ...props, slots, colorScheme });
78
78
  // Resolve fonts
79
79
  let resolvedFonts = fonts ?? [];
80
80
  if (resolvedFonts.length === 0) {
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @ogxjs/core - Performance Module
3
+ * Timing and profiling utilities
4
+ *
5
+ * @version 0.2.0 "Turbo"
6
+ */
7
+ export { benchmark, benchmarkSync, quickTime, quickTimeSync, Timer, type TimingAggregate, type TimingEntry, type TimingReport, timing, } from "./timing";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/perf/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACN,SAAS,EACT,aAAa,EACb,SAAS,EACT,aAAa,EACb,KAAK,EACL,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,MAAM,GACN,MAAM,UAAU,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @ogxjs/core - Performance Module
3
+ * Timing and profiling utilities
4
+ *
5
+ * @version 0.2.0 "Turbo"
6
+ */
7
+ export { benchmark, benchmarkSync, quickTime, quickTimeSync, Timer, timing, } from "./timing";
@@ -0,0 +1,160 @@
1
+ /**
2
+ * @ogxjs/core - Performance Timing API
3
+ * Profiling and performance measurement tools
4
+ *
5
+ * @description
6
+ * Provides timing utilities for measuring OGX performance:
7
+ * - Timer API for manual measurements
8
+ * - Automatic instrumentation for render pipeline
9
+ * - Report generation with statistics
10
+ *
11
+ * @version 0.2.0 "Turbo"
12
+ */
13
+ export interface TimingEntry {
14
+ label: string;
15
+ startTime: number;
16
+ endTime?: number;
17
+ duration?: number;
18
+ }
19
+ export interface TimingReport {
20
+ entries: TimingEntry[];
21
+ totals: Record<string, TimingAggregate>;
22
+ summary: {
23
+ totalDuration: number;
24
+ entryCount: number;
25
+ averageDuration: number;
26
+ };
27
+ }
28
+ export interface TimingAggregate {
29
+ count: number;
30
+ totalMs: number;
31
+ minMs: number;
32
+ maxMs: number;
33
+ avgMs: number;
34
+ }
35
+ /**
36
+ * Performance timer for measuring code execution
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const timer = new Timer();
41
+ *
42
+ * timer.start("render");
43
+ * await render(element);
44
+ * timer.end("render");
45
+ *
46
+ * timer.start("png-conversion");
47
+ * const png = convertToPng(svg);
48
+ * timer.end("png-conversion");
49
+ *
50
+ * console.log(timer.getReport());
51
+ * // { entries: [...], totals: {...}, summary: {...} }
52
+ * ```
53
+ */
54
+ export declare class Timer {
55
+ private entries;
56
+ private active;
57
+ private enabled;
58
+ constructor(enabled?: boolean);
59
+ /**
60
+ * Start a timing measurement
61
+ */
62
+ start(label: string): void;
63
+ /**
64
+ * End a timing measurement
65
+ * @returns Duration in milliseconds
66
+ */
67
+ end(label: string): number;
68
+ /**
69
+ * Measure an async operation
70
+ */
71
+ measure<T>(label: string, fn: () => Promise<T>): Promise<T>;
72
+ /**
73
+ * Measure a sync operation
74
+ */
75
+ measureSync<T>(label: string, fn: () => T): T;
76
+ /**
77
+ * Get timing report
78
+ */
79
+ getReport(): TimingReport;
80
+ /**
81
+ * Get formatted report string
82
+ */
83
+ getFormattedReport(): string;
84
+ /**
85
+ * Clear all entries
86
+ */
87
+ clear(): void;
88
+ /**
89
+ * Enable/disable timing
90
+ */
91
+ setEnabled(enabled: boolean): void;
92
+ /**
93
+ * Check if timing is enabled
94
+ */
95
+ isEnabled(): boolean;
96
+ }
97
+ /**
98
+ * Global timing API
99
+ */
100
+ export declare const timing: {
101
+ /**
102
+ * Start a timing measurement
103
+ */
104
+ start(label: string): void;
105
+ /**
106
+ * End a timing measurement
107
+ */
108
+ end(label: string): number;
109
+ /**
110
+ * Measure an async operation
111
+ */
112
+ measure<T>(label: string, fn: () => Promise<T>): Promise<T>;
113
+ /**
114
+ * Measure a sync operation
115
+ */
116
+ measureSync<T>(label: string, fn: () => T): T;
117
+ /**
118
+ * Get timing report
119
+ */
120
+ getReport(): TimingReport;
121
+ /**
122
+ * Get formatted report string
123
+ */
124
+ getFormattedReport(): string;
125
+ /**
126
+ * Clear all timing entries
127
+ */
128
+ clear(): void;
129
+ /**
130
+ * Enable timing (useful for debugging in production)
131
+ */
132
+ enable(): void;
133
+ /**
134
+ * Disable timing
135
+ */
136
+ disable(): void;
137
+ /**
138
+ * Check if timing is enabled
139
+ */
140
+ isEnabled(): boolean;
141
+ };
142
+ /**
143
+ * Quick one-off timing for a function
144
+ * Returns [result, durationMs]
145
+ */
146
+ export declare function quickTime<T>(fn: () => Promise<T>): Promise<[T, number]>;
147
+ /**
148
+ * Quick one-off timing for a sync function
149
+ */
150
+ export declare function quickTimeSync<T>(fn: () => T): [T, number];
151
+ /**
152
+ * Benchmark a function multiple times
153
+ * Returns statistics
154
+ */
155
+ export declare function benchmark(fn: () => Promise<void>, iterations?: number): Promise<TimingAggregate>;
156
+ /**
157
+ * Benchmark a sync function
158
+ */
159
+ export declare function benchmarkSync(fn: () => void, iterations?: number): TimingAggregate;
160
+ //# sourceMappingURL=timing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../src/perf/timing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAA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G;IACH,SAAS,IAAI,OAAO;CAGpB;AAUD;;GAEG;AACH,eAAO,MAAM,MAAM;IAClB;;OAEG;iBACU,MAAM,GAAG,IAAI;IAI1B;;OAEG;eACQ,MAAM,GAAG,MAAM;IAI1B;;OAEG;YACK,CAAC,SAAS,MAAM,MAAM,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAI3D;;OAEG;gBACS,CAAC,SAAS,MAAM,MAAM,MAAM,CAAC,GAAG,CAAC;IAI7C;;OAEG;iBACU,YAAY;IAIzB;;OAEG;0BACmB,MAAM;IAI5B;;OAEG;aACM,IAAI;IAIb;;OAEG;cACO,IAAI;IAId;;OAEG;eACQ,IAAI;IAIf;;OAEG;iBACU,OAAO;CAGpB,CAAC;AAIF;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAK7E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAKzD;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC9B,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACvB,UAAU,SAAM,GACd,OAAO,CAAC,eAAe,CAAC,CAkB1B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC5B,EAAE,EAAE,MAAM,IAAI,EACd,UAAU,SAAM,GACd,eAAe,CAkBjB"}
@@ -0,0 +1,305 @@
1
+ /**
2
+ * @ogxjs/core - Performance Timing API
3
+ * Profiling and performance measurement tools
4
+ *
5
+ * @description
6
+ * Provides timing utilities for measuring OGX performance:
7
+ * - Timer API for manual measurements
8
+ * - Automatic instrumentation for render pipeline
9
+ * - Report generation with statistics
10
+ *
11
+ * @version 0.2.0 "Turbo"
12
+ */
13
+ // TIMING CLASS
14
+ /**
15
+ * Performance timer for measuring code execution
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const timer = new Timer();
20
+ *
21
+ * timer.start("render");
22
+ * await render(element);
23
+ * timer.end("render");
24
+ *
25
+ * timer.start("png-conversion");
26
+ * const png = convertToPng(svg);
27
+ * timer.end("png-conversion");
28
+ *
29
+ * console.log(timer.getReport());
30
+ * // { entries: [...], totals: {...}, summary: {...} }
31
+ * ```
32
+ */
33
+ export class Timer {
34
+ entries = [];
35
+ active = new Map();
36
+ enabled;
37
+ constructor(enabled = true) {
38
+ this.enabled = enabled;
39
+ }
40
+ /**
41
+ * Start a timing measurement
42
+ */
43
+ start(label) {
44
+ if (!this.enabled)
45
+ return;
46
+ const entry = {
47
+ label,
48
+ startTime: performance.now(),
49
+ };
50
+ this.active.set(label, entry);
51
+ }
52
+ /**
53
+ * End a timing measurement
54
+ * @returns Duration in milliseconds
55
+ */
56
+ end(label) {
57
+ if (!this.enabled)
58
+ return 0;
59
+ const entry = this.active.get(label);
60
+ if (!entry) {
61
+ console.warn(`Timer: No active timer for "${label}"`);
62
+ return 0;
63
+ }
64
+ entry.endTime = performance.now();
65
+ entry.duration = entry.endTime - entry.startTime;
66
+ this.entries.push(entry);
67
+ this.active.delete(label);
68
+ return entry.duration;
69
+ }
70
+ /**
71
+ * Measure an async operation
72
+ */
73
+ async measure(label, fn) {
74
+ this.start(label);
75
+ try {
76
+ return await fn();
77
+ }
78
+ finally {
79
+ this.end(label);
80
+ }
81
+ }
82
+ /**
83
+ * Measure a sync operation
84
+ */
85
+ measureSync(label, fn) {
86
+ this.start(label);
87
+ try {
88
+ return fn();
89
+ }
90
+ finally {
91
+ this.end(label);
92
+ }
93
+ }
94
+ /**
95
+ * Get timing report
96
+ */
97
+ getReport() {
98
+ // Aggregate by label
99
+ const totals = {};
100
+ for (const entry of this.entries) {
101
+ if (entry.duration === undefined)
102
+ continue;
103
+ if (!totals[entry.label]) {
104
+ totals[entry.label] = {
105
+ count: 0,
106
+ totalMs: 0,
107
+ minMs: Infinity,
108
+ maxMs: -Infinity,
109
+ avgMs: 0,
110
+ };
111
+ }
112
+ const agg = totals[entry.label];
113
+ agg.count++;
114
+ agg.totalMs += entry.duration;
115
+ agg.minMs = Math.min(agg.minMs, entry.duration);
116
+ agg.maxMs = Math.max(agg.maxMs, entry.duration);
117
+ }
118
+ // Calculate averages
119
+ for (const label of Object.keys(totals)) {
120
+ const agg = totals[label];
121
+ agg.avgMs = agg.totalMs / agg.count;
122
+ }
123
+ // Calculate summary
124
+ const totalDuration = this.entries.reduce((sum, e) => sum + (e.duration ?? 0), 0);
125
+ const entryCount = this.entries.filter((e) => e.duration !== undefined).length;
126
+ return {
127
+ entries: [...this.entries],
128
+ totals,
129
+ summary: {
130
+ totalDuration,
131
+ entryCount,
132
+ averageDuration: entryCount > 0 ? totalDuration / entryCount : 0,
133
+ },
134
+ };
135
+ }
136
+ /**
137
+ * Get formatted report string
138
+ */
139
+ getFormattedReport() {
140
+ const report = this.getReport();
141
+ const lines = [
142
+ "┌─────────────────────────────────────────────────────┐",
143
+ "│ OGX Performance Report │",
144
+ "├─────────────────────────────────────────────────────┤",
145
+ ];
146
+ // Totals by label
147
+ for (const [label, agg] of Object.entries(report.totals)) {
148
+ lines.push(`│ ${label.padEnd(20)} │ ${agg.avgMs.toFixed(2).padStart(8)}ms avg │`);
149
+ lines.push(`│ ${"".padEnd(20)} │ ${agg.count.toString().padStart(8)} calls │`);
150
+ }
151
+ lines.push("├─────────────────────────────────────────────────────┤");
152
+ lines.push(`│ Total: ${report.summary.totalDuration.toFixed(2)}ms (${report.summary.entryCount} entries) │`);
153
+ lines.push("└─────────────────────────────────────────────────────┘");
154
+ return lines.join("\n");
155
+ }
156
+ /**
157
+ * Clear all entries
158
+ */
159
+ clear() {
160
+ this.entries = [];
161
+ this.active.clear();
162
+ }
163
+ /**
164
+ * Enable/disable timing
165
+ */
166
+ setEnabled(enabled) {
167
+ this.enabled = enabled;
168
+ }
169
+ /**
170
+ * Check if timing is enabled
171
+ */
172
+ isEnabled() {
173
+ return this.enabled;
174
+ }
175
+ }
176
+ // GLOBAL TIMER
177
+ /**
178
+ * Global timer instance for OGX operations
179
+ * Disabled by default in production
180
+ */
181
+ const globalTimer = new Timer(process.env.NODE_ENV !== "production");
182
+ /**
183
+ * Global timing API
184
+ */
185
+ export const timing = {
186
+ /**
187
+ * Start a timing measurement
188
+ */
189
+ start(label) {
190
+ globalTimer.start(label);
191
+ },
192
+ /**
193
+ * End a timing measurement
194
+ */
195
+ end(label) {
196
+ return globalTimer.end(label);
197
+ },
198
+ /**
199
+ * Measure an async operation
200
+ */
201
+ measure(label, fn) {
202
+ return globalTimer.measure(label, fn);
203
+ },
204
+ /**
205
+ * Measure a sync operation
206
+ */
207
+ measureSync(label, fn) {
208
+ return globalTimer.measureSync(label, fn);
209
+ },
210
+ /**
211
+ * Get timing report
212
+ */
213
+ getReport() {
214
+ return globalTimer.getReport();
215
+ },
216
+ /**
217
+ * Get formatted report string
218
+ */
219
+ getFormattedReport() {
220
+ return globalTimer.getFormattedReport();
221
+ },
222
+ /**
223
+ * Clear all timing entries
224
+ */
225
+ clear() {
226
+ globalTimer.clear();
227
+ },
228
+ /**
229
+ * Enable timing (useful for debugging in production)
230
+ */
231
+ enable() {
232
+ globalTimer.setEnabled(true);
233
+ },
234
+ /**
235
+ * Disable timing
236
+ */
237
+ disable() {
238
+ globalTimer.setEnabled(false);
239
+ },
240
+ /**
241
+ * Check if timing is enabled
242
+ */
243
+ isEnabled() {
244
+ return globalTimer.isEnabled();
245
+ },
246
+ };
247
+ // QUICK TIMING UTILITIES
248
+ /**
249
+ * Quick one-off timing for a function
250
+ * Returns [result, durationMs]
251
+ */
252
+ export async function quickTime(fn) {
253
+ const start = performance.now();
254
+ const result = await fn();
255
+ const duration = performance.now() - start;
256
+ return [result, duration];
257
+ }
258
+ /**
259
+ * Quick one-off timing for a sync function
260
+ */
261
+ export function quickTimeSync(fn) {
262
+ const start = performance.now();
263
+ const result = fn();
264
+ const duration = performance.now() - start;
265
+ return [result, duration];
266
+ }
267
+ /**
268
+ * Benchmark a function multiple times
269
+ * Returns statistics
270
+ */
271
+ export async function benchmark(fn, iterations = 100) {
272
+ const durations = [];
273
+ for (let i = 0; i < iterations; i++) {
274
+ const start = performance.now();
275
+ await fn();
276
+ durations.push(performance.now() - start);
277
+ }
278
+ const totalMs = durations.reduce((sum, d) => sum + d, 0);
279
+ return {
280
+ count: iterations,
281
+ totalMs,
282
+ minMs: Math.min(...durations),
283
+ maxMs: Math.max(...durations),
284
+ avgMs: totalMs / iterations,
285
+ };
286
+ }
287
+ /**
288
+ * Benchmark a sync function
289
+ */
290
+ export function benchmarkSync(fn, iterations = 100) {
291
+ const durations = [];
292
+ for (let i = 0; i < iterations; i++) {
293
+ const start = performance.now();
294
+ fn();
295
+ durations.push(performance.now() - start);
296
+ }
297
+ const totalMs = durations.reduce((sum, d) => sum + d, 0);
298
+ return {
299
+ count: iterations,
300
+ totalMs,
301
+ minMs: Math.min(...durations),
302
+ maxMs: Math.max(...durations),
303
+ avgMs: totalMs / iterations,
304
+ };
305
+ }
@@ -60,7 +60,7 @@ export const blogPreset = (props) => {
60
60
  span([
61
61
  "text-lg",
62
62
  "font-medium",
63
- isDark ? "text-zinc-400" : "text-zinc-500",
63
+ isDark ? "text-zinc-400" : "text-zinc-600",
64
64
  ], [date, readingTime].filter(Boolean).join(" · ")),
65
65
  ]),
66
66
  ]),
@@ -15,6 +15,8 @@ export interface DocsPresetProps {
15
15
  header?: OGXElement;
16
16
  footer?: OGXElement;
17
17
  };
18
+ /** Details Image */
19
+ detailsOG?: boolean;
18
20
  }
19
21
  /**
20
22
  * Docs preset - ideal for documentation sites
@@ -1 +1 @@
1
- {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/presets/docs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,WAAW,eAAe;IAC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