@djangocfg/ui-core 2.1.232 → 2.1.234
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 +6 -0
- package/package.json +4 -4
- package/src/components/index.ts +0 -2
- package/src/lib/env.ts +10 -0
- package/src/lib/index.ts +1 -1
- package/src/lib/logger/logger.ts +1 -3
- package/src/components/og-image.tsx +0 -50
- package/src/lib/og-image.ts +0 -151
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/ui-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.234",
|
|
4
4
|
"description": "Pure React UI component library without Next.js dependencies - for Electron, Vite, CRA apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui-components",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"playground": "playground dev"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
|
-
"@djangocfg/i18n": "^2.1.
|
|
84
|
+
"@djangocfg/i18n": "^2.1.234",
|
|
85
85
|
"consola": "^3.4.2",
|
|
86
86
|
"lucide-react": "^0.545.0",
|
|
87
87
|
"moment": "^2.30.1",
|
|
@@ -143,9 +143,9 @@
|
|
|
143
143
|
"vaul": "1.1.2"
|
|
144
144
|
},
|
|
145
145
|
"devDependencies": {
|
|
146
|
-
"@djangocfg/i18n": "^2.1.
|
|
146
|
+
"@djangocfg/i18n": "^2.1.234",
|
|
147
147
|
"@djangocfg/playground": "workspace:*",
|
|
148
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
148
|
+
"@djangocfg/typescript-config": "^2.1.234",
|
|
149
149
|
"@types/node": "^24.7.2",
|
|
150
150
|
"@types/react": "^19.1.0",
|
|
151
151
|
"@types/react-dom": "^19.1.0",
|
package/src/components/index.ts
CHANGED
|
@@ -104,8 +104,6 @@ export { CopyButton, CopyField } from './copy';
|
|
|
104
104
|
export type { CopyButtonProps, CopyFieldProps } from './copy';
|
|
105
105
|
export { DownloadButton } from './button-download';
|
|
106
106
|
export type { DownloadButtonProps } from './button-download';
|
|
107
|
-
export { OgImage } from './og-image';
|
|
108
|
-
export type { OgImageProps } from './og-image';
|
|
109
107
|
|
|
110
108
|
// Additional Components
|
|
111
109
|
export { Toaster } from './sonner';
|
package/src/lib/env.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment constants — shared across all @djangocfg packages.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const nodeEnv = process.env.NODE_ENV || 'development';
|
|
6
|
+
export const isDev = nodeEnv === 'development';
|
|
7
|
+
export const isProd = nodeEnv === 'production';
|
|
8
|
+
export const isTest = nodeEnv === 'test';
|
|
9
|
+
export const isBrowser = typeof window !== 'undefined';
|
|
10
|
+
export const isServer = typeof window === 'undefined';
|
package/src/lib/index.ts
CHANGED
package/src/lib/logger/logger.ts
CHANGED
|
@@ -14,9 +14,7 @@ import { useLogStore } from './logStore';
|
|
|
14
14
|
|
|
15
15
|
import type { Logger, LogLevel, MediaLogger } from './types';
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
const isDev = process.env.NODE_ENV !== 'production';
|
|
19
|
-
const isBrowser = typeof window !== 'undefined';
|
|
17
|
+
import { isDev, isBrowser } from '../env';
|
|
20
18
|
|
|
21
19
|
// Create base consola instance
|
|
22
20
|
const baseConsola = consola.create({
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
generateOgImageUrl, type GenerateOgImageUrlOptions, type OgImageUrlParams
|
|
7
|
-
} from '../lib/og-image';
|
|
8
|
-
import { cn } from '../lib/utils';
|
|
9
|
-
|
|
10
|
-
export interface OgImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
|
|
11
|
-
/** OG Image parameters */
|
|
12
|
-
params: OgImageUrlParams
|
|
13
|
-
/** Generation options (baseUrl, useBase64) */
|
|
14
|
-
options?: GenerateOgImageUrlOptions
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* OgImage Component
|
|
19
|
-
*
|
|
20
|
-
* Renders an image using the OG Image API with auto-generated URL.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```tsx
|
|
24
|
-
* <OgImage
|
|
25
|
-
* params={{ title: 'My Page', description: 'Description' }}
|
|
26
|
-
* className="rounded-lg"
|
|
27
|
-
* />
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const OgImage = React.forwardRef<HTMLImageElement, OgImageProps>(
|
|
31
|
-
({ params, options, className, alt, ...props }, ref) => {
|
|
32
|
-
const src = React.useMemo(
|
|
33
|
-
() => generateOgImageUrl(params, options),
|
|
34
|
-
[params, options]
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<img
|
|
39
|
-
ref={ref}
|
|
40
|
-
src={src}
|
|
41
|
-
alt={alt || params.title}
|
|
42
|
-
className={cn('w-full', className)}
|
|
43
|
-
{...props}
|
|
44
|
-
/>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
)
|
|
48
|
-
OgImage.displayName = 'OgImage'
|
|
49
|
-
|
|
50
|
-
export { OgImage }
|
package/src/lib/og-image.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OG Image URL Generation Utilities
|
|
3
|
-
*
|
|
4
|
-
* Client-side utilities for generating OG image URLs.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/** Default OG Image API base URL */
|
|
8
|
-
const DEFAULT_OG_IMAGE_BASE_URL = 'https://djangocfg.com/api/og';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Encode string to base64 with Unicode support
|
|
12
|
-
* Works in both browser and Node.js environments
|
|
13
|
-
*/
|
|
14
|
-
function encodeBase64(str: string): string {
|
|
15
|
-
// Node.js environment
|
|
16
|
-
if (typeof Buffer !== 'undefined') {
|
|
17
|
-
return Buffer.from(str, 'utf-8').toString('base64');
|
|
18
|
-
}
|
|
19
|
-
// Browser environment - handle Unicode via UTF-8 encoding
|
|
20
|
-
const utf8Bytes = new TextEncoder().encode(str);
|
|
21
|
-
const binaryString = Array.from(utf8Bytes, byte => String.fromCharCode(byte)).join('');
|
|
22
|
-
return btoa(binaryString);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* OG Image URL parameters
|
|
27
|
-
*/
|
|
28
|
-
export interface OgImageUrlParams {
|
|
29
|
-
/** Page title */
|
|
30
|
-
title: string;
|
|
31
|
-
/** Page description (optional) */
|
|
32
|
-
description?: string;
|
|
33
|
-
/** Site name (optional) */
|
|
34
|
-
siteName?: string;
|
|
35
|
-
/** Logo URL (optional) */
|
|
36
|
-
logo?: string;
|
|
37
|
-
/** Background type: 'gradient' or 'solid' */
|
|
38
|
-
backgroundType?: 'gradient' | 'solid';
|
|
39
|
-
/** Gradient start color (hex) */
|
|
40
|
-
gradientStart?: string;
|
|
41
|
-
/** Gradient end color (hex) */
|
|
42
|
-
gradientEnd?: string;
|
|
43
|
-
/** Background color (for solid type) */
|
|
44
|
-
backgroundColor?: string;
|
|
45
|
-
/** Title font size (px) */
|
|
46
|
-
titleSize?: number;
|
|
47
|
-
/** Title font weight */
|
|
48
|
-
titleWeight?: number;
|
|
49
|
-
/** Title text color */
|
|
50
|
-
titleColor?: string;
|
|
51
|
-
/** Description font size (px) */
|
|
52
|
-
descriptionSize?: number;
|
|
53
|
-
/** Description text color */
|
|
54
|
-
descriptionColor?: string;
|
|
55
|
-
/** Site name font size (px) */
|
|
56
|
-
siteNameSize?: number;
|
|
57
|
-
/** Site name text color */
|
|
58
|
-
siteNameColor?: string;
|
|
59
|
-
/** Padding (px) */
|
|
60
|
-
padding?: number;
|
|
61
|
-
/** Logo size (px) */
|
|
62
|
-
logoSize?: number;
|
|
63
|
-
/** Show logo flag */
|
|
64
|
-
showLogo?: boolean;
|
|
65
|
-
/** Show site name flag */
|
|
66
|
-
showSiteName?: boolean;
|
|
67
|
-
/** Additional custom parameters */
|
|
68
|
-
[key: string]: string | number | boolean | undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Options for generating OG image URL
|
|
73
|
-
*/
|
|
74
|
-
export interface GenerateOgImageUrlOptions {
|
|
75
|
-
/**
|
|
76
|
-
* Base URL of the OG image API route
|
|
77
|
-
* @default 'https://djangocfg.com/api/og'
|
|
78
|
-
*/
|
|
79
|
-
baseUrl?: string;
|
|
80
|
-
/**
|
|
81
|
-
* If true, encode params as base64 for safer URLs
|
|
82
|
-
* @default true
|
|
83
|
-
*/
|
|
84
|
-
useBase64?: boolean;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Generate OG image URL with query parameters or base64 encoding
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* // Using default baseUrl (https://djangocfg.com/api/og)
|
|
93
|
-
* const url = generateOgImageUrl({ title: 'My Page Title' });
|
|
94
|
-
*
|
|
95
|
-
* // With custom baseUrl
|
|
96
|
-
* const url = generateOgImageUrl({ title: 'My Page' }, { baseUrl: '/api/og' });
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export function generateOgImageUrl(
|
|
100
|
-
params: OgImageUrlParams,
|
|
101
|
-
options: GenerateOgImageUrlOptions = {}
|
|
102
|
-
): string {
|
|
103
|
-
const { baseUrl = DEFAULT_OG_IMAGE_BASE_URL, useBase64 = true } = options;
|
|
104
|
-
|
|
105
|
-
if (useBase64) {
|
|
106
|
-
const cleanParams: Record<string, string | number | boolean> = {};
|
|
107
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
108
|
-
if (value !== undefined && value !== null && value !== '') {
|
|
109
|
-
cleanParams[key] = value;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const jsonString = JSON.stringify(cleanParams);
|
|
114
|
-
const base64Data = encodeBase64(jsonString);
|
|
115
|
-
return `${baseUrl}/${base64Data}`;
|
|
116
|
-
} else {
|
|
117
|
-
const searchParams = new URLSearchParams();
|
|
118
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
119
|
-
if (value !== undefined && value !== null && value !== '') {
|
|
120
|
-
searchParams.append(key, String(value));
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
const query = searchParams.toString();
|
|
124
|
-
return query ? `${baseUrl}?${query}` : baseUrl;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Get absolute OG image URL from relative path
|
|
130
|
-
*/
|
|
131
|
-
export function getAbsoluteOgImageUrl(relativePath: string, siteUrl: string): string {
|
|
132
|
-
// If path is already an absolute URL, return as-is
|
|
133
|
-
if (relativePath.startsWith('http://') || relativePath.startsWith('https://')) {
|
|
134
|
-
return relativePath;
|
|
135
|
-
}
|
|
136
|
-
const cleanSiteUrl = siteUrl.replace(/\/$/, '');
|
|
137
|
-
const cleanPath = relativePath.startsWith('/') ? relativePath : `/${relativePath}`;
|
|
138
|
-
return `${cleanSiteUrl}${cleanPath}`;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Create OG image URL builder with preset configuration
|
|
143
|
-
*/
|
|
144
|
-
export function createOgImageUrlBuilder(
|
|
145
|
-
defaults: Partial<OgImageUrlParams> = {},
|
|
146
|
-
options: GenerateOgImageUrlOptions = {}
|
|
147
|
-
) {
|
|
148
|
-
return (params: OgImageUrlParams): string => {
|
|
149
|
-
return generateOgImageUrl({ ...defaults, ...params }, options);
|
|
150
|
-
};
|
|
151
|
-
}
|