@djangocfg/nextjs 2.1.30 → 2.1.31

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.
@@ -0,0 +1,195 @@
1
+ /**
2
+ * PWA Manifest Metadata Utilities
3
+ *
4
+ * Helper functions for creating Next.js metadata for PWA manifest
5
+ */
6
+
7
+ import type { Metadata, MetadataRoute } from 'next';
8
+
9
+ export interface ManifestConfig {
10
+ name: string;
11
+ shortName?: string;
12
+ description?: string;
13
+ themeColor?: string;
14
+ backgroundColor?: string;
15
+ display?: 'standalone' | 'fullscreen' | 'minimal-ui' | 'browser';
16
+ orientation?: 'portrait' | 'landscape' | 'any';
17
+ startUrl?: string;
18
+ scope?: string;
19
+ lang?: string;
20
+ dir?: 'ltr' | 'rtl' | 'auto';
21
+ icons?: {
22
+ src: string;
23
+ sizes: string;
24
+ type?: string;
25
+ purpose?: string;
26
+ }[];
27
+ }
28
+
29
+ /**
30
+ * Icon paths configuration
31
+ */
32
+ export interface IconPaths {
33
+ logo192?: string;
34
+ logo384?: string;
35
+ logo512?: string;
36
+ }
37
+
38
+ /**
39
+ * Create manifest metadata for Next.js app
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * export const metadata: Metadata = {
44
+ * ...createManifestMetadata({
45
+ * name: 'My App',
46
+ * shortName: 'App',
47
+ * description: 'My awesome app',
48
+ * }),
49
+ * };
50
+ * ```
51
+ */
52
+ export function createManifestMetadata(config: ManifestConfig): Metadata {
53
+ return {
54
+ manifest: '/manifest.json',
55
+ themeColor: config.themeColor || '#000000',
56
+ appleWebApp: {
57
+ capable: true,
58
+ statusBarStyle: 'default',
59
+ title: config.shortName || config.name,
60
+ },
61
+ applicationName: config.name,
62
+ formatDetection: {
63
+ telephone: false,
64
+ },
65
+ viewport: {
66
+ width: 'device-width',
67
+ initialScale: 1,
68
+ maximumScale: 1,
69
+ },
70
+ };
71
+ }
72
+
73
+ /**
74
+ * Create Next.js manifest function
75
+ *
76
+ * Use this in your app/manifest.ts file
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * // app/manifest.ts
81
+ * import { createManifest } from '@djangocfg/nextjs/config';
82
+ * import { settings } from '@core/settings';
83
+ *
84
+ * export default createManifest({
85
+ * name: settings.app.name,
86
+ * description: settings.app.description,
87
+ * icons: {
88
+ * logo192: settings.app.icons.logo192,
89
+ * logo384: settings.app.icons.logo384,
90
+ * logo512: settings.app.icons.logo512,
91
+ * },
92
+ * });
93
+ * ```
94
+ */
95
+ export function createManifest(config: {
96
+ name: string;
97
+ shortName?: string;
98
+ description?: string;
99
+ themeColor?: string;
100
+ backgroundColor?: string;
101
+ display?: 'standalone' | 'fullscreen' | 'minimal-ui' | 'browser';
102
+ orientation?: 'portrait' | 'landscape' | 'any';
103
+ startUrl?: string;
104
+ scope?: string;
105
+ lang?: string;
106
+ dir?: 'ltr' | 'rtl' | 'auto';
107
+ icons?: IconPaths | ManifestConfig['icons'];
108
+ }): () => MetadataRoute.Manifest {
109
+ return () => {
110
+ // Convert IconPaths to manifest icons format
111
+ let manifestIcons: MetadataRoute.Manifest['icons'];
112
+
113
+ if (Array.isArray(config.icons)) {
114
+ // Already in manifest format
115
+ manifestIcons = config.icons as MetadataRoute.Manifest['icons'];
116
+ } else if (config.icons) {
117
+ // Convert IconPaths to manifest icons
118
+ const { logo192, logo384, logo512 } = config.icons as IconPaths;
119
+ manifestIcons = [
120
+ ...(logo192
121
+ ? [
122
+ {
123
+ src: logo192,
124
+ sizes: '192x192',
125
+ type: 'image/png',
126
+ purpose: 'maskable' as const,
127
+ },
128
+ ]
129
+ : []),
130
+ ...(logo384
131
+ ? [
132
+ {
133
+ src: logo384,
134
+ sizes: '384x384',
135
+ type: 'image/png',
136
+ },
137
+ ]
138
+ : []),
139
+ ...(logo512
140
+ ? [
141
+ {
142
+ src: logo512,
143
+ sizes: '512x512',
144
+ type: 'image/png',
145
+ },
146
+ ]
147
+ : []),
148
+ ];
149
+ } else {
150
+ // Default icons
151
+ manifestIcons = [
152
+ {
153
+ src: '/static/logos/192x192.png',
154
+ sizes: '192x192',
155
+ type: 'image/png',
156
+ purpose: 'maskable' as const,
157
+ },
158
+ {
159
+ src: '/static/logos/384x384.png',
160
+ sizes: '384x384',
161
+ type: 'image/png',
162
+ },
163
+ {
164
+ src: '/static/logos/512x512.png',
165
+ sizes: '512x512',
166
+ type: 'image/png',
167
+ },
168
+ ];
169
+ }
170
+
171
+ return {
172
+ name: config.name,
173
+ short_name: config.shortName || config.name,
174
+ description: config.description || config.name,
175
+ start_url: config.startUrl || '/',
176
+ scope: config.scope || '/',
177
+ display: config.display || 'standalone',
178
+ orientation: config.orientation || 'portrait',
179
+ background_color: config.backgroundColor || '#000000',
180
+ theme_color: config.themeColor || '#ffffff',
181
+ lang: config.lang || 'en',
182
+ dir: config.dir || 'ltr',
183
+ icons: manifestIcons,
184
+ };
185
+ };
186
+ }
187
+
188
+ /**
189
+ * Generate manifest.json content (legacy)
190
+ *
191
+ * @deprecated Use createManifest() instead
192
+ */
193
+ export function generateManifest(config: ManifestConfig): Record<string, any> {
194
+ return createManifest(config)();
195
+ }