@djangocfg/nextjs 2.1.626 → 2.1.628

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
@@ -304,6 +304,16 @@ function MyComponent() {
304
304
  }
305
305
  ```
306
306
 
307
+ #### Shared locale cookie (several hosts, one family)
308
+
309
+ `NEXT_LOCALE` is written by the **proxy** (`createProxy` → `shareLocaleCookie`) and by `useChangeLocale` in the browser, never during render. Server components read the locale from the URL segment, so the cookie cannot change what SSR renders; it only decides where a bare `/` redirects. With `Domain=<registrable domain>` every host of the family sends the same value; the host-only twin is expired so it cannot shadow it. Override the domain guess with `NEXT_PUBLIC_COOKIE_DOMAIN`.
310
+
311
+ What it costs, and the rules that keep SSR intact:
312
+ - A response that sets a cookie is not cached by a CDN by default. The proxy sets it only when next-intl wrote one (a bare-path visit or a switch), not on every page view; keep it that way and do not add `Set-Cookie` to static pages.
313
+ - Never read `NEXT_LOCALE` in a server component (`cookies()` makes the route dynamic). Take `locale` from `params`.
314
+ - SEO sites (one language per host, indexed) keep `localeCookie: false`; sharing applies only to app families behind a login.
315
+ - If this ever causes trouble, the fallback is no cookie at all: the locale lives in the URL, and the family switcher links to the sibling host with the same locale prefix.
316
+
307
317
  #### Locale Switcher
308
318
 
309
319
  Smart wrapper around `@djangocfg/layouts` LocaleSwitcher with automatic next-intl hooks:
@@ -0,0 +1,11 @@
1
+ export { A as AppIconGlyph, a as AppIconOptions, b as AppIconShape, I as IconNode, c as appIconElement, d as appIconGradient, o as oklchToHex } from '../element-DhDVWCha.mjs';
2
+ import 'react';
3
+
4
+ /** The manifest's `icons` for an app that serves `createAppIcon` at `app/icon.tsx`. Pass it to `createManifest({ icons })`. */
5
+ declare const appIconPaths: {
6
+ readonly logo192: "/icon/192";
7
+ readonly logo384: "/icon/384";
8
+ readonly logo512: "/icon/512";
9
+ };
10
+
11
+ export { appIconPaths };
@@ -0,0 +1,66 @@
1
+ // src/app-icon/element.ts
2
+ import { createElement } from "react";
3
+ function oklchToHex(l, c, h) {
4
+ const a = c * Math.cos(h * Math.PI / 180);
5
+ const b = c * Math.sin(h * Math.PI / 180);
6
+ const l_ = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;
7
+ const m_ = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;
8
+ const s_ = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;
9
+ const lin = [
10
+ 4.0767416621 * l_ - 3.3077115913 * m_ + 0.2309699292 * s_,
11
+ -1.2684380046 * l_ + 2.6097574011 * m_ - 0.3413193965 * s_,
12
+ -0.0041960863 * l_ - 0.7034186147 * m_ + 1.707614701 * s_
13
+ ];
14
+ const hex = lin.map((v) => {
15
+ const g = v <= 31308e-7 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055;
16
+ return Math.round(Math.min(1, Math.max(0, g)) * 255).toString(16).padStart(2, "0");
17
+ });
18
+ return `#${hex.join("")}`;
19
+ }
20
+ function appIconGradient(hue) {
21
+ return `linear-gradient(150deg, ${oklchToHex(0.66, 0.17, hue)}, ${oklchToHex(0.47, 0.18, hue + 22)})`;
22
+ }
23
+ function nodesOf(glyph) {
24
+ if (Array.isArray(glyph)) return glyph;
25
+ const node = glyph.__iconData?.node;
26
+ if (!node) throw new Error("app-icon: glyph is not a lucide icon module (expected `import * as x from 'lucide-react/icons/<name>'`)");
27
+ return node;
28
+ }
29
+ function appIconElement({ glyph, hue, size, shape = "rounded" }) {
30
+ const square = shape === "square";
31
+ const side = Math.round(size * (square ? 0.46 : 0.58));
32
+ const glyphSvg = createElement(
33
+ "svg",
34
+ { width: side, height: side, viewBox: "0 0 24 24", fill: "none", stroke: "#ffffff", strokeWidth: 2.1, strokeLinecap: "round", strokeLinejoin: "round" },
35
+ ...nodesOf(glyph).map(([tag, { key, ...attrs }]) => createElement(tag, { key, ...attrs }))
36
+ );
37
+ return createElement(
38
+ "div",
39
+ {
40
+ style: {
41
+ width: size,
42
+ height: size,
43
+ display: "flex",
44
+ alignItems: "center",
45
+ justifyContent: "center",
46
+ backgroundImage: appIconGradient(hue),
47
+ borderRadius: square ? 0 : Math.round(size * 0.225)
48
+ }
49
+ },
50
+ glyphSvg
51
+ );
52
+ }
53
+
54
+ // src/app-icon/paths.ts
55
+ var appIconPaths = {
56
+ logo192: "/icon/192",
57
+ logo384: "/icon/384",
58
+ logo512: "/icon/512"
59
+ };
60
+ export {
61
+ appIconElement,
62
+ appIconGradient,
63
+ appIconPaths,
64
+ oklchToHex
65
+ };
66
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/app-icon/element.ts","../../src/app-icon/paths.ts"],"sourcesContent":["/**\n * App icon: ONE definition of the picture an app shows in a tab, on a home screen and as a PWA icon.\n *\n * House style: a full-bleed tile in the product's hue (a two-stop gradient), a white lucide glyph in the inner ~46-58%,\n * and NO border near the edge. The OS cuts its own corner (iOS ~22%, Android a mask); anything drawn at the edge never\n * matches that curve.\n *\n * Pure: plain host elements only (`next/og` renders nothing else) and no `next/og` import, so a client bundle can use\n * the same gradient for an in-app tile. The route factory lives in `./next`.\n */\n\nimport { createElement, type ReactElement } from 'react';\n\n/** What lucide stores for an icon: `[tag, attrs][]`; `attrs.key` is React's key. */\nexport type IconNode = [tag: string, attrs: Record<string, string>][];\n\n/**\n * A glyph is a lucide icon MODULE, `import * as workflow from 'lucide-react/icons/workflow'` (a lucide component is a\n * client component and `next/og` cannot render it, so its drawing data is read from the module), or the node list itself.\n */\nexport type AppIconGlyph = object | IconNode;\n\nexport type AppIconShape = 'rounded' | 'square';\n\nexport interface AppIconOptions {\n glyph: AppIconGlyph;\n /** OKLCH hue, 0-360. The switcher tile should use `appIconGradient(hue)` so both agree. */\n hue: number;\n /** Side in px. */\n size: number;\n /** `rounded`: transparent corners (browser tab). `square`: full-bleed for iOS and maskable PWA icons. @default 'rounded' */\n shape?: AppIconShape;\n}\n\n/** OKLCH to sRGB hex. `next/og` does not parse `oklch()`; CSS does, and the two must show the same colour. */\nexport function oklchToHex(l: number, c: number, h: number): string {\n const a = c * Math.cos((h * Math.PI) / 180);\n const b = c * Math.sin((h * Math.PI) / 180);\n const l_ = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;\n const m_ = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;\n const s_ = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;\n const lin = [\n 4.0767416621 * l_ - 3.3077115913 * m_ + 0.2309699292 * s_,\n -1.2684380046 * l_ + 2.6097574011 * m_ - 0.3413193965 * s_,\n -0.0041960863 * l_ - 0.7034186147 * m_ + 1.707614701 * s_,\n ];\n const hex = lin.map((v) => {\n const g = v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055;\n return Math.round(Math.min(1, Math.max(0, g)) * 255).toString(16).padStart(2, '0');\n });\n return `#${hex.join('')}`;\n}\n\n/** The gradient behind a glyph, two hex stops from one hue. */\nexport function appIconGradient(hue: number): string {\n return `linear-gradient(150deg, ${oklchToHex(0.66, 0.17, hue)}, ${oklchToHex(0.47, 0.18, hue + 22)})`;\n}\n\nfunction nodesOf(glyph: AppIconGlyph): IconNode {\n if (Array.isArray(glyph)) return glyph as IconNode;\n const node = (glyph as { __iconData?: { node?: IconNode } }).__iconData?.node;\n if (!node) throw new Error(\"app-icon: glyph is not a lucide icon module (expected `import * as x from 'lucide-react/icons/<name>'`)\");\n return node;\n}\n\n/** The picture as plain JSX, for `new ImageResponse(...)`. */\nexport function appIconElement({ glyph, hue, size, shape = 'rounded' }: AppIconOptions): ReactElement {\n const square = shape === 'square';\n // A square icon is cropped by the OS: keep the glyph inside the maskable safe zone (the inner 60%).\n const side = Math.round(size * (square ? 0.46 : 0.58));\n const glyphSvg = createElement(\n 'svg',\n { width: side, height: side, viewBox: '0 0 24 24', fill: 'none', stroke: '#ffffff', strokeWidth: 2.1, strokeLinecap: 'round', strokeLinejoin: 'round' },\n ...nodesOf(glyph).map(([tag, { key, ...attrs }]) => createElement(tag, { key, ...attrs })),\n );\n return createElement(\n 'div',\n {\n style: {\n width: size,\n height: size,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n backgroundImage: appIconGradient(hue),\n borderRadius: square ? 0 : Math.round(size * 0.225),\n },\n },\n glyphSvg,\n );\n}\n","/** The manifest's `icons` for an app that serves `createAppIcon` at `app/icon.tsx`. Pass it to `createManifest({ icons })`. */\nexport const appIconPaths = {\n logo192: '/icon/192',\n logo384: '/icon/384',\n logo512: '/icon/512',\n} as const;\n"],"mappings":";AAWA,SAAS,qBAAwC;AAwB1C,SAAS,WAAW,GAAW,GAAW,GAAmB;AAClE,QAAM,IAAI,IAAI,KAAK,IAAK,IAAI,KAAK,KAAM,GAAG;AAC1C,QAAM,IAAI,IAAI,KAAK,IAAK,IAAI,KAAK,KAAM,GAAG;AAC1C,QAAM,MAAM,IAAI,eAAe,IAAI,eAAe,MAAM;AACxD,QAAM,MAAM,IAAI,eAAe,IAAI,eAAe,MAAM;AACxD,QAAM,MAAM,IAAI,eAAe,IAAI,cAAc,MAAM;AACvD,QAAM,MAAM;AAAA,IACV,eAAe,KAAK,eAAe,KAAK,eAAe;AAAA,IACvD,gBAAgB,KAAK,eAAe,KAAK,eAAe;AAAA,IACxD,gBAAgB,KAAK,eAAe,KAAK,cAAc;AAAA,EACzD;AACA,QAAM,MAAM,IAAI,IAAI,CAAC,MAAM;AACzB,UAAM,IAAI,KAAK,WAAY,QAAQ,IAAI,QAAQ,MAAM,IAAI,OAAO;AAChE,WAAO,KAAK,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAAA,EACnF,CAAC;AACD,SAAO,IAAI,IAAI,KAAK,EAAE,CAAC;AACzB;AAGO,SAAS,gBAAgB,KAAqB;AACnD,SAAO,2BAA2B,WAAW,MAAM,MAAM,GAAG,CAAC,KAAK,WAAW,MAAM,MAAM,MAAM,EAAE,CAAC;AACpG;AAEA,SAAS,QAAQ,OAA+B;AAC9C,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO;AACjC,QAAM,OAAQ,MAA+C,YAAY;AACzE,MAAI,CAAC,KAAM,OAAM,IAAI,MAAM,yGAAyG;AACpI,SAAO;AACT;AAGO,SAAS,eAAe,EAAE,OAAO,KAAK,MAAM,QAAQ,UAAU,GAAiC;AACpG,QAAM,SAAS,UAAU;AAEzB,QAAM,OAAO,KAAK,MAAM,QAAQ,SAAS,OAAO,KAAK;AACrD,QAAM,WAAW;AAAA,IACf;AAAA,IACA,EAAE,OAAO,MAAM,QAAQ,MAAM,SAAS,aAAa,MAAM,QAAQ,QAAQ,WAAW,aAAa,KAAK,eAAe,SAAS,gBAAgB,QAAQ;AAAA,IACtJ,GAAG,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,cAAc,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;AAAA,EAC3F;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,iBAAiB,gBAAgB,GAAG;AAAA,QACpC,cAAc,SAAS,IAAI,KAAK,MAAM,OAAO,KAAK;AAAA,MACpD;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;;;ACzFO,IAAM,eAAe;AAAA,EAC1B,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;","names":[]}
@@ -0,0 +1,51 @@
1
+ import { ImageResponse } from 'next/og';
2
+ import { AppIconGlyph } from './index.mjs';
3
+ import 'react';
4
+
5
+ /**
6
+ * Route handlers for Next's icon file conventions, from one glyph and one hue.
7
+ *
8
+ * // app/icon.tsx
9
+ * import * as workflow from 'lucide-react/icons/workflow';
10
+ * import { createAppIcon } from '@djangocfg/nextjs/app-icon/next';
11
+ * const icon = createAppIcon({ glyph: workflow, hue: 55 });
12
+ * export const generateImageMetadata = icon.generateImageMetadata;
13
+ * export default icon.icon;
14
+ *
15
+ * // app/apple-icon.tsx
16
+ * export const size = { width: 180, height: 180 };
17
+ * export const contentType = 'image/png';
18
+ * export default icon.appleIcon; // same createAppIcon call, or call it again
19
+ *
20
+ * Served at `/icon/tab` (64, rounded), `/icon/192`, `/icon/384`, `/icon/512` (square) and `/apple-icon` (180, square).
21
+ */
22
+
23
+ declare const appIconSizes: {
24
+ readonly tab: 64;
25
+ readonly '192': 192;
26
+ readonly '384': 384;
27
+ readonly '512': 512;
28
+ };
29
+ declare const appleIconSize: {
30
+ readonly width: 180;
31
+ readonly height: 180;
32
+ };
33
+ declare function createAppIcon({ glyph, hue }: {
34
+ glyph: AppIconGlyph;
35
+ hue: number;
36
+ }): {
37
+ generateImageMetadata(): {
38
+ id: string;
39
+ size: {
40
+ width: 64 | 192 | 384 | 512;
41
+ height: 64 | 192 | 384 | 512;
42
+ };
43
+ contentType: string;
44
+ }[];
45
+ icon({ id }: {
46
+ id: Promise<string | number>;
47
+ }): Promise<ImageResponse>;
48
+ appleIcon(): ImageResponse;
49
+ };
50
+
51
+ export { appIconSizes, appleIconSize, createAppIcon };
@@ -0,0 +1,87 @@
1
+ // src/app-icon/next.ts
2
+ import { ImageResponse } from "next/og";
3
+
4
+ // src/app-icon/element.ts
5
+ import { createElement } from "react";
6
+ function oklchToHex(l, c, h) {
7
+ const a = c * Math.cos(h * Math.PI / 180);
8
+ const b = c * Math.sin(h * Math.PI / 180);
9
+ const l_ = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;
10
+ const m_ = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;
11
+ const s_ = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;
12
+ const lin = [
13
+ 4.0767416621 * l_ - 3.3077115913 * m_ + 0.2309699292 * s_,
14
+ -1.2684380046 * l_ + 2.6097574011 * m_ - 0.3413193965 * s_,
15
+ -0.0041960863 * l_ - 0.7034186147 * m_ + 1.707614701 * s_
16
+ ];
17
+ const hex = lin.map((v) => {
18
+ const g = v <= 31308e-7 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055;
19
+ return Math.round(Math.min(1, Math.max(0, g)) * 255).toString(16).padStart(2, "0");
20
+ });
21
+ return `#${hex.join("")}`;
22
+ }
23
+ function appIconGradient(hue) {
24
+ return `linear-gradient(150deg, ${oklchToHex(0.66, 0.17, hue)}, ${oklchToHex(0.47, 0.18, hue + 22)})`;
25
+ }
26
+ function nodesOf(glyph) {
27
+ if (Array.isArray(glyph)) return glyph;
28
+ const node = glyph.__iconData?.node;
29
+ if (!node) throw new Error("app-icon: glyph is not a lucide icon module (expected `import * as x from 'lucide-react/icons/<name>'`)");
30
+ return node;
31
+ }
32
+ function appIconElement({ glyph, hue, size, shape = "rounded" }) {
33
+ const square = shape === "square";
34
+ const side = Math.round(size * (square ? 0.46 : 0.58));
35
+ const glyphSvg = createElement(
36
+ "svg",
37
+ { width: side, height: side, viewBox: "0 0 24 24", fill: "none", stroke: "#ffffff", strokeWidth: 2.1, strokeLinecap: "round", strokeLinejoin: "round" },
38
+ ...nodesOf(glyph).map(([tag, { key, ...attrs }]) => createElement(tag, { key, ...attrs }))
39
+ );
40
+ return createElement(
41
+ "div",
42
+ {
43
+ style: {
44
+ width: size,
45
+ height: size,
46
+ display: "flex",
47
+ alignItems: "center",
48
+ justifyContent: "center",
49
+ backgroundImage: appIconGradient(hue),
50
+ borderRadius: square ? 0 : Math.round(size * 0.225)
51
+ }
52
+ },
53
+ glyphSvg
54
+ );
55
+ }
56
+
57
+ // src/app-icon/next.ts
58
+ var appIconSizes = { tab: 64, "192": 192, "384": 384, "512": 512 };
59
+ var appleIconSize = { width: 180, height: 180 };
60
+ function createAppIcon({ glyph, hue }) {
61
+ return {
62
+ generateImageMetadata() {
63
+ return Object.entries(appIconSizes).map(([id, side]) => ({
64
+ id,
65
+ size: { width: side, height: side },
66
+ contentType: "image/png"
67
+ }));
68
+ },
69
+ async icon({ id }) {
70
+ const key = String(await id);
71
+ const side = appIconSizes[key] ?? appIconSizes.tab;
72
+ return new ImageResponse(appIconElement({ glyph, hue, size: side, shape: key === "tab" ? "rounded" : "square" }), {
73
+ width: side,
74
+ height: side
75
+ });
76
+ },
77
+ appleIcon() {
78
+ return new ImageResponse(appIconElement({ glyph, hue, size: appleIconSize.width, shape: "square" }), appleIconSize);
79
+ }
80
+ };
81
+ }
82
+ export {
83
+ appIconSizes,
84
+ appleIconSize,
85
+ createAppIcon
86
+ };
87
+ //# sourceMappingURL=next.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/app-icon/next.ts","../../src/app-icon/element.ts"],"sourcesContent":["/**\n * Route handlers for Next's icon file conventions, from one glyph and one hue.\n *\n * // app/icon.tsx\n * import * as workflow from 'lucide-react/icons/workflow';\n * import { createAppIcon } from '@djangocfg/nextjs/app-icon/next';\n * const icon = createAppIcon({ glyph: workflow, hue: 55 });\n * export const generateImageMetadata = icon.generateImageMetadata;\n * export default icon.icon;\n *\n * // app/apple-icon.tsx\n * export const size = { width: 180, height: 180 };\n * export const contentType = 'image/png';\n * export default icon.appleIcon; // same createAppIcon call, or call it again\n *\n * Served at `/icon/tab` (64, rounded), `/icon/192`, `/icon/384`, `/icon/512` (square) and `/apple-icon` (180, square).\n */\n\nimport { ImageResponse } from 'next/og';\n\nimport { appIconElement, type AppIconGlyph } from './element';\n\nexport const appIconSizes = { tab: 64, '192': 192, '384': 384, '512': 512 } as const;\nexport const appleIconSize = { width: 180, height: 180 } as const;\n\nexport function createAppIcon({ glyph, hue }: { glyph: AppIconGlyph; hue: number }) {\n return {\n generateImageMetadata() {\n return Object.entries(appIconSizes).map(([id, side]) => ({\n id,\n size: { width: side, height: side },\n contentType: 'image/png',\n }));\n },\n async icon({ id }: { id: Promise<string | number> }) {\n const key = String(await id) as keyof typeof appIconSizes;\n const side = appIconSizes[key] ?? appIconSizes.tab;\n return new ImageResponse(appIconElement({ glyph, hue, size: side, shape: key === 'tab' ? 'rounded' : 'square' }), {\n width: side,\n height: side,\n });\n },\n appleIcon() {\n return new ImageResponse(appIconElement({ glyph, hue, size: appleIconSize.width, shape: 'square' }), appleIconSize);\n },\n };\n}\n","/**\n * App icon: ONE definition of the picture an app shows in a tab, on a home screen and as a PWA icon.\n *\n * House style: a full-bleed tile in the product's hue (a two-stop gradient), a white lucide glyph in the inner ~46-58%,\n * and NO border near the edge. The OS cuts its own corner (iOS ~22%, Android a mask); anything drawn at the edge never\n * matches that curve.\n *\n * Pure: plain host elements only (`next/og` renders nothing else) and no `next/og` import, so a client bundle can use\n * the same gradient for an in-app tile. The route factory lives in `./next`.\n */\n\nimport { createElement, type ReactElement } from 'react';\n\n/** What lucide stores for an icon: `[tag, attrs][]`; `attrs.key` is React's key. */\nexport type IconNode = [tag: string, attrs: Record<string, string>][];\n\n/**\n * A glyph is a lucide icon MODULE, `import * as workflow from 'lucide-react/icons/workflow'` (a lucide component is a\n * client component and `next/og` cannot render it, so its drawing data is read from the module), or the node list itself.\n */\nexport type AppIconGlyph = object | IconNode;\n\nexport type AppIconShape = 'rounded' | 'square';\n\nexport interface AppIconOptions {\n glyph: AppIconGlyph;\n /** OKLCH hue, 0-360. The switcher tile should use `appIconGradient(hue)` so both agree. */\n hue: number;\n /** Side in px. */\n size: number;\n /** `rounded`: transparent corners (browser tab). `square`: full-bleed for iOS and maskable PWA icons. @default 'rounded' */\n shape?: AppIconShape;\n}\n\n/** OKLCH to sRGB hex. `next/og` does not parse `oklch()`; CSS does, and the two must show the same colour. */\nexport function oklchToHex(l: number, c: number, h: number): string {\n const a = c * Math.cos((h * Math.PI) / 180);\n const b = c * Math.sin((h * Math.PI) / 180);\n const l_ = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;\n const m_ = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;\n const s_ = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;\n const lin = [\n 4.0767416621 * l_ - 3.3077115913 * m_ + 0.2309699292 * s_,\n -1.2684380046 * l_ + 2.6097574011 * m_ - 0.3413193965 * s_,\n -0.0041960863 * l_ - 0.7034186147 * m_ + 1.707614701 * s_,\n ];\n const hex = lin.map((v) => {\n const g = v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055;\n return Math.round(Math.min(1, Math.max(0, g)) * 255).toString(16).padStart(2, '0');\n });\n return `#${hex.join('')}`;\n}\n\n/** The gradient behind a glyph, two hex stops from one hue. */\nexport function appIconGradient(hue: number): string {\n return `linear-gradient(150deg, ${oklchToHex(0.66, 0.17, hue)}, ${oklchToHex(0.47, 0.18, hue + 22)})`;\n}\n\nfunction nodesOf(glyph: AppIconGlyph): IconNode {\n if (Array.isArray(glyph)) return glyph as IconNode;\n const node = (glyph as { __iconData?: { node?: IconNode } }).__iconData?.node;\n if (!node) throw new Error(\"app-icon: glyph is not a lucide icon module (expected `import * as x from 'lucide-react/icons/<name>'`)\");\n return node;\n}\n\n/** The picture as plain JSX, for `new ImageResponse(...)`. */\nexport function appIconElement({ glyph, hue, size, shape = 'rounded' }: AppIconOptions): ReactElement {\n const square = shape === 'square';\n // A square icon is cropped by the OS: keep the glyph inside the maskable safe zone (the inner 60%).\n const side = Math.round(size * (square ? 0.46 : 0.58));\n const glyphSvg = createElement(\n 'svg',\n { width: side, height: side, viewBox: '0 0 24 24', fill: 'none', stroke: '#ffffff', strokeWidth: 2.1, strokeLinecap: 'round', strokeLinejoin: 'round' },\n ...nodesOf(glyph).map(([tag, { key, ...attrs }]) => createElement(tag, { key, ...attrs })),\n );\n return createElement(\n 'div',\n {\n style: {\n width: size,\n height: size,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n backgroundImage: appIconGradient(hue),\n borderRadius: square ? 0 : Math.round(size * 0.225),\n },\n },\n glyphSvg,\n );\n}\n"],"mappings":";AAkBA,SAAS,qBAAqB;;;ACP9B,SAAS,qBAAwC;AAwB1C,SAAS,W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YAAY;AACV,aAAO,IAAI,cAAc,eAAe,EAAE,OAAO,KAAK,MAAM,cAAc,OAAO,OAAO,SAAS,CAAC,GAAG,aAAa;AAAA,IACpH;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,39 @@
1
+ import { ReactElement } from 'react';
2
+
3
+ /**
4
+ * App icon: ONE definition of the picture an app shows in a tab, on a home screen and as a PWA icon.
5
+ *
6
+ * House style: a full-bleed tile in the product's hue (a two-stop gradient), a white lucide glyph in the inner ~46-58%,
7
+ * and NO border near the edge. The OS cuts its own corner (iOS ~22%, Android a mask); anything drawn at the edge never
8
+ * matches that curve.
9
+ *
10
+ * Pure: plain host elements only (`next/og` renders nothing else) and no `next/og` import, so a client bundle can use
11
+ * the same gradient for an in-app tile. The route factory lives in `./next`.
12
+ */
13
+
14
+ /** What lucide stores for an icon: `[tag, attrs][]`; `attrs.key` is React's key. */
15
+ type IconNode = [tag: string, attrs: Record<string, string>][];
16
+ /**
17
+ * A glyph is a lucide icon MODULE, `import * as workflow from 'lucide-react/icons/workflow'` (a lucide component is a
18
+ * client component and `next/og` cannot render it, so its drawing data is read from the module), or the node list itself.
19
+ */
20
+ type AppIconGlyph = object | IconNode;
21
+ type AppIconShape = 'rounded' | 'square';
22
+ interface AppIconOptions {
23
+ glyph: AppIconGlyph;
24
+ /** OKLCH hue, 0-360. The switcher tile should use `appIconGradient(hue)` so both agree. */
25
+ hue: number;
26
+ /** Side in px. */
27
+ size: number;
28
+ /** `rounded`: transparent corners (browser tab). `square`: full-bleed for iOS and maskable PWA icons. @default 'rounded' */
29
+ shape?: AppIconShape;
30
+ }
31
+ /** OKLCH to sRGB hex. `next/og` does not parse `oklch()`; CSS does, and the two must show the same colour. */
32
+ declare function oklchToHex(l: number, c: number, h: number): string;
33
+ /** The gradient behind a glyph, two hex stops from one hue. */
34
+ declare function appIconGradient(hue: number): string;
35
+ /** The picture as plain JSX, for `new ImageResponse(...)`. */
36
+ declare function appIconElement({ glyph, hue, size, shape }: AppIconOptions): ReactElement;
37
+
38
+ export { appIconElement as c, appIconGradient as d, oklchToHex as o };
39
+ export type { AppIconGlyph as A, IconNode as I, AppIconOptions as a, AppIconShape as b };
@@ -95,6 +95,49 @@ function NextIntlProvider({
95
95
  );
96
96
  }
97
97
 
98
+ // src/i18n/shared-locale.ts
99
+ var LOCALE_COOKIE = "NEXT_LOCALE";
100
+ var LOCALE_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
101
+ var TWO_LABEL_SUFFIXES = /* @__PURE__ */ new Set([
102
+ "co.uk",
103
+ "org.uk",
104
+ "ac.uk",
105
+ "com.au",
106
+ "net.au",
107
+ "co.nz",
108
+ "co.jp",
109
+ "co.kr",
110
+ "or.kr",
111
+ "com.br",
112
+ "com.tr",
113
+ "com.cn",
114
+ "com.mx",
115
+ "co.in",
116
+ "co.za",
117
+ "com.sg",
118
+ "com.hk",
119
+ "com.tw",
120
+ "com.ar",
121
+ "com.ua",
122
+ "co.il"
123
+ ]);
124
+ function sharedCookieDomain(hostname, override) {
125
+ const forced = override?.trim().replace(/^\./, "");
126
+ if (forced) return forced;
127
+ const host = hostname.split(":")[0].toLowerCase();
128
+ if (!host || /^\d+(\.\d+){3}$/.test(host) || host.includes(":")) return null;
129
+ const labels = host.split(".");
130
+ if (labels.length < 2) return null;
131
+ const keep = TWO_LABEL_SUFFIXES.has(labels.slice(-2).join(".")) ? 3 : 2;
132
+ return labels.slice(-keep).join(".");
133
+ }
134
+ function localeCookieHeader(locale, domain, secure) {
135
+ return `${LOCALE_COOKIE}=${encodeURIComponent(locale)}; Path=/; Max-Age=${LOCALE_COOKIE_MAX_AGE}; SameSite=Lax${domain ? `; Domain=${domain}` : ""}${secure ? "; Secure" : ""}`;
136
+ }
137
+ function expireHostOnlyLocaleCookie(secure) {
138
+ return `${LOCALE_COOKIE}=; Path=/; Max-Age=0; SameSite=Lax${secure ? "; Secure" : ""}`;
139
+ }
140
+
98
141
  // src/i18n/client.ts
99
142
  function useTranslations(namespace) {
100
143
  return useNextIntlTranslations(namespace);
@@ -128,9 +171,10 @@ function useDefaultLocale() {
128
171
  function useChangeLocale() {
129
172
  const pathname = usePathname();
130
173
  return (locale) => {
131
- const date = /* @__PURE__ */ new Date();
132
- date.setFullYear(date.getFullYear() + 1);
133
- document.cookie = `NEXT_LOCALE=${locale}; expires=${date.toUTCString()}; path=/`;
174
+ const secure = window.location.protocol === "https:";
175
+ const domain = sharedCookieDomain(window.location.hostname, process.env.NEXT_PUBLIC_COOKIE_DOMAIN);
176
+ document.cookie = localeCookieHeader(locale, domain, secure);
177
+ if (domain) document.cookie = expireHostOnlyLocaleCookie(secure);
134
178
  window.location.href = `/${locale}${pathname}`;
135
179
  };
136
180
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/i18n/client.ts","../../src/i18n/navigation.ts","../../src/i18n/routing.ts","../../src/i18n/provider.tsx"],"sourcesContent":["/**\n * Client-side i18n Hooks\n *\n * For use in Client Components ('use client')\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useTranslations, useLocale } from '@djangocfg/nextjs/i18n/client';\n *\n * export function MyComponent() {\n * const t = useTranslations('HomePage');\n * const locale = useLocale();\n *\n * return <h1>{t('title')}</h1>;\n * }\n * ```\n */\n\n'use client';\n\nimport {\n useFormatter, useLocale as useNextIntlLocale, useMessages, useNow, useTimeZone,\n useTranslations as useNextIntlTranslations\n} from 'next-intl';\n\nimport { usePathname } from './navigation';\nimport { I18nProvider, NextIntlProvider, useDeclaredLocales } from './provider';\nimport { routing } from './routing';\n\n// Re-export providers\nexport { I18nProvider, NextIntlProvider };\n\nimport type { LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Core Client Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Get translations in Client Components\n *\n * @example\n * ```tsx\n * const t = useTranslations('HomePage');\n * return <h1>{t('title')}</h1>;\n *\n * // With interpolation\n * return <p>{t('greeting', { name: 'John' })}</p>;\n * ```\n */\nexport function useTranslations<Namespace extends string = never>(\n namespace?: Namespace\n) {\n return useNextIntlTranslations(namespace);\n}\n\n/**\n * Get current locale in Client Components\n */\nexport function useLocale(): LocaleCode {\n return useNextIntlLocale() as LocaleCode;\n}\n\n/**\n * Get all messages\n * Useful for passing to child providers\n */\nexport { useMessages };\n\n/**\n * Get current time\n */\nexport { useNow };\n\n/**\n * Get timezone\n */\nexport { useTimeZone };\n\n/**\n * Get formatter for dates, numbers, etc.\n */\nexport { useFormatter };\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Convenience Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Shorthand for useTranslations\n * Alias for compatibility with @djangocfg/i18n\n */\nexport const useT = useTranslations;\n\n/**\n * Get namespaced translations\n *\n * @example\n * ```tsx\n * const pt = useNamespacedTranslations('payments');\n * return <span>{pt('balance.available')}</span>;\n * ```\n */\nexport function useNamespacedTranslations(namespace: string) {\n return useNextIntlTranslations(namespace);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Formatting Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Format a date according to locale\n *\n * @example\n * ```tsx\n * const formatDate = useDateFormatter();\n * return <span>{formatDate(new Date())}</span>;\n * ```\n */\nexport function useDateFormatter() {\n const formatter = useFormatter();\n return (date: Date | number, options?: Parameters<typeof formatter.dateTime>[1]) =>\n formatter.dateTime(date, options);\n}\n\n/**\n * Format a number according to locale\n *\n * @example\n * ```tsx\n * const formatNumber = useNumberFormatter();\n * return <span>{formatNumber(1234.56)}</span>;\n * ```\n */\nexport function useNumberFormatter() {\n const formatter = useFormatter();\n return (number: number, options?: Parameters<typeof formatter.number>[1]) =>\n formatter.number(number, options);\n}\n\n/**\n * Format relative time\n *\n * @example\n * ```tsx\n * const formatRelative = useRelativeTimeFormatter();\n * return <span>{formatRelative(new Date())}</span>;\n * ```\n */\nexport function useRelativeTimeFormatter() {\n const formatter = useFormatter();\n return (date: Date | number, options?: Parameters<typeof formatter.relativeTime>[1]) =>\n formatter.relativeTime(date, options);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Switching Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Locales the app declared on `I18nProvider`; the built-in routing list only\n * when it declared none.\n *\n * @example\n * ```tsx\n * const locales = useLocales();\n * // ['en', 'ru', 'ko']\n * ```\n */\nexport function useLocales(): LocaleCode[] {\n const declared = useDeclaredLocales();\n return declared ?? (routing.locales as LocaleCode[]);\n}\n\n/**\n * Get default locale from routing config\n */\nexport function useDefaultLocale(): LocaleCode {\n return routing.defaultLocale as LocaleCode;\n}\n\n/**\n * Hook to change current locale\n *\n * @example\n * ```tsx\n * const changeLocale = useChangeLocale();\n *\n * <button onClick={() => changeLocale('ru')}>\n * Switch to Russian\n * </button>\n * ```\n */\nexport function useChangeLocale() {\n const pathname = usePathname();\n\n return (locale: LocaleCode) => {\n // Set NEXT_LOCALE cookie so middleware remembers the choice\n const date = new Date();\n date.setFullYear(date.getFullYear() + 1);\n document.cookie = `NEXT_LOCALE=${locale}; expires=${date.toUTCString()}; path=/`;\n\n // Hard navigation to force full page reload with new locale\n // (ensures server components re-render with updated translations)\n window.location.href = `/${locale}${pathname}`;\n };\n}\n\n/**\n * Combined hook for locale switching\n * Returns current locale, available locales, and change function\n *\n * @example\n * ```tsx\n * const { locale, locales, changeLocale } = useLocaleSwitcher();\n *\n * <select value={locale} onChange={(e) => changeLocale(e.target.value)}>\n * {locales.map(l => <option key={l} value={l}>{l}</option>)}\n * </select>\n * ```\n */\nexport function useLocaleSwitcher() {\n const locale = useLocale();\n const locales = useLocales();\n const changeLocale = useChangeLocale();\n\n return { locale, locales, changeLocale };\n}\n","/**\n * i18n Navigation Utilities\n *\n * Provides locale-aware navigation components and functions\n *\n * @example\n * ```ts\n * // In your app's i18n/navigation.ts\n * import { createNavigation } from '@djangocfg/nextjs/i18n';\n * import { routing } from './routing';\n *\n * export const { Link, redirect, usePathname, useRouter } = createNavigation(routing);\n * ```\n *\n * @example\n * ```tsx\n * // Using in components\n * import { Link, usePathname } from '@/i18n/navigation';\n *\n * function Nav() {\n * const pathname = usePathname();\n * return <Link href=\"/about\">About</Link>;\n * }\n * ```\n */\n\nimport { createNavigation as createNextIntlNavigation } from 'next-intl/navigation';\n\nimport { createRouting, routing } from './routing';\n\nimport type { I18nConfig } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Navigation Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create navigation utilities with custom routing\n *\n * Returns locale-aware versions of:\n * - Link: Locale-prefixed links\n * - redirect: Server-side redirect with locale\n * - usePathname: Current pathname without locale prefix\n * - useRouter: Router with locale-aware navigation\n * - getPathname: Get pathname for a route\n */\nexport function createNavigation(routingConfig?: ReturnType<typeof createRouting>) {\n const config = routingConfig ?? routing;\n return createNextIntlNavigation(config);\n}\n\n/**\n * Create navigation from config options\n */\nexport function createNavigationFromConfig(config: Partial<I18nConfig>) {\n const routingConfig = createRouting(config);\n return createNextIntlNavigation(routingConfig);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Navigation (using default routing)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Default navigation utilities\n * Use these directly or create custom ones with createNavigation()\n */\nexport const {\n Link,\n redirect,\n usePathname,\n useRouter,\n getPathname,\n} = createNavigation();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Types\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Props for locale-aware Link component\n */\nexport interface LinkProps {\n /** Target href */\n href: string;\n /** Target locale (optional, defaults to current) */\n locale?: string;\n /** Children */\n children?: React.ReactNode;\n /** Additional props passed to Next.js Link */\n [key: string]: unknown;\n}\n","/**\n * i18n Routing Configuration\n *\n * Creates routing configuration for next-intl\n * Used by proxy and navigation components\n */\n\nimport { defineRouting } from 'next-intl/routing';\n\nimport type { I18nConfig, LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Configuration\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport const DEFAULT_LOCALES: LocaleCode[] = ['en', 'ru', 'ko', 'ja', 'de', 'fr', 'zh', 'it', 'es', 'nl', 'ar', 'tr', 'pt-BR', 'pl', 'sv', 'no', 'da'];\nexport const DEFAULT_LOCALE: LocaleCode = 'en';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Routing Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create routing configuration for next-intl\n *\n * @example\n * ```ts\n * // i18n/routing.ts\n * import { createRouting } from '@djangocfg/nextjs/i18n';\n *\n * export const routing = createRouting({\n * locales: ['en', 'ru', 'ko'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport function createRouting(config?: Partial<I18nConfig>) {\n const locales = config?.locales ?? DEFAULT_LOCALES;\n const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;\n const localePrefix = config?.localePrefix ?? 'as-needed';\n\n return defineRouting({\n locales,\n defaultLocale,\n localePrefix,\n });\n}\n\n/**\n * Default routing configuration\n * Can be overridden by app-specific configuration\n */\nexport const routing = createRouting();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Utilities\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Check if a locale is supported\n */\nexport function isValidLocale(\n locale: string,\n supportedLocales: readonly string[] = DEFAULT_LOCALES\n): locale is LocaleCode {\n return supportedLocales.includes(locale as LocaleCode);\n}\n\n/**\n * Get locale from params (handles async params in Next.js 15+)\n */\nexport async function getLocaleFromParams(\n params: Promise<{ locale: string }> | { locale: string }\n): Promise<LocaleCode> {\n const resolved = await params;\n return resolved.locale as LocaleCode;\n}\n\n/**\n * Generate static params for all locales\n * Use in generateStaticParams for locale pages\n */\nexport function generateLocaleParams(locales: readonly string[] = DEFAULT_LOCALES) {\n return locales.map((locale) => ({ locale }));\n}\n","/**\n * i18n Provider for Next.js App Router\n *\n * Bridges next-intl with @djangocfg/i18n\n * Provides translations to both Server and Client components\n *\n * @example\n * ```tsx\n * // app/[locale]/layout.tsx\n * import { I18nProvider } from '@djangocfg/nextjs/i18n';\n * import { getMessages, getLocale } from '@djangocfg/nextjs/i18n/server';\n *\n * export default async function LocaleLayout({ children, params }) {\n * const locale = await getLocale(params);\n * const messages = await getMessages();\n *\n * return (\n * <I18nProvider locale={locale} messages={messages}>\n * {children}\n * </I18nProvider>\n * );\n * }\n * ```\n */\n\n'use client';\n\nimport { createContext, useContext } from 'react';\nimport { NextIntlClientProvider } from 'next-intl';\nimport { I18nProvider as DjangoCfgI18nProvider } from '@djangocfg/i18n';\nimport type { I18nProviderProps, LocaleCode } from './types';\n\nconst DeclaredLocalesContext = createContext<LocaleCode[] | null>(null);\n\n/** Locales the app passed to its provider, or null when it passed none. */\nexport const useDeclaredLocales = (): LocaleCode[] | null => useContext(DeclaredLocalesContext);\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Provider Component\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Unified i18n Provider\n *\n * Wraps both NextIntlClientProvider and @djangocfg/i18n's I18nProvider\n * This ensures both next-intl hooks and @djangocfg/i18n hooks work correctly\n */\nexport function I18nProvider({\n locale,\n messages,\n locales,\n timeZone = 'UTC',\n now,\n children,\n}: I18nProviderProps) {\n return (\n <NextIntlClientProvider\n locale={locale}\n messages={messages}\n timeZone={timeZone}\n now={now}\n >\n <DjangoCfgI18nProvider\n locale={locale as LocaleCode}\n translations={messages}\n >\n <DeclaredLocalesContext.Provider value={locales ?? null}>\n {children}\n </DeclaredLocalesContext.Provider>\n </DjangoCfgI18nProvider>\n </NextIntlClientProvider>\n );\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Lightweight Provider (next-intl only)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Next-intl only provider (without @djangocfg/i18n context)\n * Use if you only need next-intl hooks\n */\nexport function NextIntlProvider({\n locale,\n messages,\n locales,\n timeZone = 'UTC',\n now,\n children,\n}: I18nProviderProps) {\n return (\n <NextIntlClientProvider\n locale={locale}\n messages={messages}\n timeZone={timeZone}\n now={now}\n >\n <DeclaredLocalesContext.Provider value={locales ?? null}>\n {children}\n </DeclaredLocalesContext.Provider>\n </NextIntlClientProvider>\n );\n}\n"],"mappings":";;;AAsBA;AAAA,EACI;AAAA,EAAc,aAAa;AAAA,EAAmB;AAAA,EAAa;AAAA,EAAQ;AAAA,EACnE,mBAAmB;AAAA,OAChB;;;ACCP,SAAS,oBAAoB,gCAAgC;;;ACnB7D,SAAS,qBAAqB;AAQvB,IAAM,kBAAgC,CAAC,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,SAAS,MAAM,MAAM,MAAM,IAAI;AAC9I,IAAM,iBAA6B;AAoBnC,SAAS,cAAc,QAA8B;AAC1D,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,QAAM,eAAe,QAAQ,gBAAgB;AAE7C,SAAO,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAMO,IAAM,UAAU,cAAc;;;ADN9B,SAAS,iBAAiB,eAAkD;AACjF,QAAM,SAAS,iBAAiB;AAChC,SAAO,yBAAyB,MAAM;AACxC;AAkBO,IAAM;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI,iBAAiB;;;AE9CrB,SAAS,eAAe,kBAAkB;AAC1C,SAAS,8BAA8B;AACvC,SAAS,gBAAgB,6BAA6B;AAqC9C;AAlCR,IAAM,yBAAyB,cAAmC,IAAI;AAG/D,IAAM,qBAAqB,MAA2B,WAAW,sBAAsB;AAYvF,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AACF,GAAsB;AACpB,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,U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,SAAS,OAAO,IAAI,MAAM,GAAG,QAAQ;AAAA,EAC9C;AACF;AAeO,SAAS,oBAAoB;AAClC,QAAM,SAAS,UAAU;AACzB,QAAM,UAAU,WAAW;AAC3B,QAAM,eAAe,gBAAgB;AAErC,SAAO,EAAE,QAAQ,SAAS,aAAa;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../src/i18n/client.ts","../../src/i18n/navigation.ts","../../src/i18n/routing.ts","../../src/i18n/provider.tsx","../../src/i18n/shared-locale.ts"],"sourcesContent":["/**\n * Client-side i18n Hooks\n *\n * For use in Client Components ('use client')\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useTranslations, useLocale } from '@djangocfg/nextjs/i18n/client';\n *\n * export function MyComponent() {\n * const t = useTranslations('HomePage');\n * const locale = useLocale();\n *\n * return <h1>{t('title')}</h1>;\n * }\n * ```\n */\n\n'use client';\n\nimport {\n useFormatter, useLocale as useNextIntlLocale, useMessages, useNow, useTimeZone,\n useTranslations as useNextIntlTranslations\n} from 'next-intl';\n\nimport { usePathname } from './navigation';\nimport { I18nProvider, NextIntlProvider, useDeclaredLocales } from './provider';\nimport { routing } from './routing';\nimport { expireHostOnlyLocaleCookie, localeCookieHeader, sharedCookieDomain } from './shared-locale';\n\n// Re-export providers\nexport { I18nProvider, NextIntlProvider };\n\nimport type { LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Core Client Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Get translations in Client Components\n *\n * @example\n * ```tsx\n * const t = useTranslations('HomePage');\n * return <h1>{t('title')}</h1>;\n *\n * // With interpolation\n * return <p>{t('greeting', { name: 'John' })}</p>;\n * ```\n */\nexport function useTranslations<Namespace extends string = never>(\n namespace?: Namespace\n) {\n return useNextIntlTranslations(namespace);\n}\n\n/**\n * Get current locale in Client Components\n */\nexport function useLocale(): LocaleCode {\n return useNextIntlLocale() as LocaleCode;\n}\n\n/**\n * Get all messages\n * Useful for passing to child providers\n */\nexport { useMessages };\n\n/**\n * Get current time\n */\nexport { useNow };\n\n/**\n * Get timezone\n */\nexport { useTimeZone };\n\n/**\n * Get formatter for dates, numbers, etc.\n */\nexport { useFormatter };\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Convenience Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Shorthand for useTranslations\n * Alias for compatibility with @djangocfg/i18n\n */\nexport const useT = useTranslations;\n\n/**\n * Get namespaced translations\n *\n * @example\n * ```tsx\n * const pt = useNamespacedTranslations('payments');\n * return <span>{pt('balance.available')}</span>;\n * ```\n */\nexport function useNamespacedTranslations(namespace: string) {\n return useNextIntlTranslations(namespace);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Formatting Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Format a date according to locale\n *\n * @example\n * ```tsx\n * const formatDate = useDateFormatter();\n * return <span>{formatDate(new Date())}</span>;\n * ```\n */\nexport function useDateFormatter() {\n const formatter = useFormatter();\n return (date: Date | number, options?: Parameters<typeof formatter.dateTime>[1]) =>\n formatter.dateTime(date, options);\n}\n\n/**\n * Format a number according to locale\n *\n * @example\n * ```tsx\n * const formatNumber = useNumberFormatter();\n * return <span>{formatNumber(1234.56)}</span>;\n * ```\n */\nexport function useNumberFormatter() {\n const formatter = useFormatter();\n return (number: number, options?: Parameters<typeof formatter.number>[1]) =>\n formatter.number(number, options);\n}\n\n/**\n * Format relative time\n *\n * @example\n * ```tsx\n * const formatRelative = useRelativeTimeFormatter();\n * return <span>{formatRelative(new Date())}</span>;\n * ```\n */\nexport function useRelativeTimeFormatter() {\n const formatter = useFormatter();\n return (date: Date | number, options?: Parameters<typeof formatter.relativeTime>[1]) =>\n formatter.relativeTime(date, options);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Switching Hooks\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Locales the app declared on `I18nProvider`; the built-in routing list only\n * when it declared none.\n *\n * @example\n * ```tsx\n * const locales = useLocales();\n * // ['en', 'ru', 'ko']\n * ```\n */\nexport function useLocales(): LocaleCode[] {\n const declared = useDeclaredLocales();\n return declared ?? (routing.locales as LocaleCode[]);\n}\n\n/**\n * Get default locale from routing config\n */\nexport function useDefaultLocale(): LocaleCode {\n return routing.defaultLocale as LocaleCode;\n}\n\n/**\n * Hook to change current locale\n *\n * @example\n * ```tsx\n * const changeLocale = useChangeLocale();\n *\n * <button onClick={() => changeLocale('ru')}>\n * Switch to Russian\n * </button>\n * ```\n */\nexport function useChangeLocale() {\n const pathname = usePathname();\n\n return (locale: LocaleCode) => {\n // Set NEXT_LOCALE so middleware remembers the choice, on the registrable domain so every host of the family\n // reads it (see ./shared-locale); the host-only twin is expired so it cannot shadow the shared one.\n const secure = window.location.protocol === 'https:';\n const domain = sharedCookieDomain(window.location.hostname, process.env.NEXT_PUBLIC_COOKIE_DOMAIN);\n document.cookie = localeCookieHeader(locale, domain, secure);\n if (domain) document.cookie = expireHostOnlyLocaleCookie(secure);\n\n // Hard navigation to force full page reload with new locale\n // (ensures server components re-render with updated translations)\n window.location.href = `/${locale}${pathname}`;\n };\n}\n\n/**\n * Combined hook for locale switching\n * Returns current locale, available locales, and change function\n *\n * @example\n * ```tsx\n * const { locale, locales, changeLocale } = useLocaleSwitcher();\n *\n * <select value={locale} onChange={(e) => changeLocale(e.target.value)}>\n * {locales.map(l => <option key={l} value={l}>{l}</option>)}\n * </select>\n * ```\n */\nexport function useLocaleSwitcher() {\n const locale = useLocale();\n const locales = useLocales();\n const changeLocale = useChangeLocale();\n\n return { locale, locales, changeLocale };\n}\n","/**\n * i18n Navigation Utilities\n *\n * Provides locale-aware navigation components and functions\n *\n * @example\n * ```ts\n * // In your app's i18n/navigation.ts\n * import { createNavigation } from '@djangocfg/nextjs/i18n';\n * import { routing } from './routing';\n *\n * export const { Link, redirect, usePathname, useRouter } = createNavigation(routing);\n * ```\n *\n * @example\n * ```tsx\n * // Using in components\n * import { Link, usePathname } from '@/i18n/navigation';\n *\n * function Nav() {\n * const pathname = usePathname();\n * return <Link href=\"/about\">About</Link>;\n * }\n * ```\n */\n\nimport { createNavigation as createNextIntlNavigation } from 'next-intl/navigation';\n\nimport { createRouting, routing } from './routing';\n\nimport type { I18nConfig } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Navigation Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create navigation utilities with custom routing\n *\n * Returns locale-aware versions of:\n * - Link: Locale-prefixed links\n * - redirect: Server-side redirect with locale\n * - usePathname: Current pathname without locale prefix\n * - useRouter: Router with locale-aware navigation\n * - getPathname: Get pathname for a route\n */\nexport function createNavigation(routingConfig?: ReturnType<typeof createRouting>) {\n const config = routingConfig ?? routing;\n return createNextIntlNavigation(config);\n}\n\n/**\n * Create navigation from config options\n */\nexport function createNavigationFromConfig(config: Partial<I18nConfig>) {\n const routingConfig = createRouting(config);\n return createNextIntlNavigation(routingConfig);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Navigation (using default routing)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Default navigation utilities\n * Use these directly or create custom ones with createNavigation()\n */\nexport const {\n Link,\n redirect,\n usePathname,\n useRouter,\n getPathname,\n} = createNavigation();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Types\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Props for locale-aware Link component\n */\nexport interface LinkProps {\n /** Target href */\n href: string;\n /** Target locale (optional, defaults to current) */\n locale?: string;\n /** Children */\n children?: React.ReactNode;\n /** Additional props passed to Next.js Link */\n [key: string]: unknown;\n}\n","/**\n * i18n Routing Configuration\n *\n * Creates routing configuration for next-intl\n * Used by proxy and navigation components\n */\n\nimport { defineRouting } from 'next-intl/routing';\n\nimport type { I18nConfig, LocaleCode } from './types';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Default Configuration\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport const DEFAULT_LOCALES: LocaleCode[] = ['en', 'ru', 'ko', 'ja', 'de', 'fr', 'zh', 'it', 'es', 'nl', 'ar', 'tr', 'pt-BR', 'pl', 'sv', 'no', 'da'];\nexport const DEFAULT_LOCALE: LocaleCode = 'en';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Routing Factory\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Create routing configuration for next-intl\n *\n * @example\n * ```ts\n * // i18n/routing.ts\n * import { createRouting } from '@djangocfg/nextjs/i18n';\n *\n * export const routing = createRouting({\n * locales: ['en', 'ru', 'ko'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport function createRouting(config?: Partial<I18nConfig>) {\n const locales = config?.locales ?? DEFAULT_LOCALES;\n const defaultLocale = config?.defaultLocale ?? DEFAULT_LOCALE;\n const localePrefix = config?.localePrefix ?? 'as-needed';\n\n return defineRouting({\n locales,\n defaultLocale,\n localePrefix,\n });\n}\n\n/**\n * Default routing configuration\n * Can be overridden by app-specific configuration\n */\nexport const routing = createRouting();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Locale Utilities\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Check if a locale is supported\n */\nexport function isValidLocale(\n locale: string,\n supportedLocales: readonly string[] = DEFAULT_LOCALES\n): locale is LocaleCode {\n return supportedLocales.includes(locale as LocaleCode);\n}\n\n/**\n * Get locale from params (handles async params in Next.js 15+)\n */\nexport async function getLocaleFromParams(\n params: Promise<{ locale: string }> | { locale: string }\n): Promise<LocaleCode> {\n const resolved = await params;\n return resolved.locale as LocaleCode;\n}\n\n/**\n * Generate static params for all locales\n * Use in generateStaticParams for locale pages\n */\nexport function generateLocaleParams(locales: readonly string[] = DEFAULT_LOCALES) {\n return locales.map((locale) => ({ locale }));\n}\n","/**\n * i18n Provider for Next.js App Router\n *\n * Bridges next-intl with @djangocfg/i18n\n * Provides translations to both Server and Client components\n *\n * @example\n * ```tsx\n * // app/[locale]/layout.tsx\n * import { I18nProvider } from '@djangocfg/nextjs/i18n';\n * import { getMessages, getLocale } from '@djangocfg/nextjs/i18n/server';\n *\n * export default async function LocaleLayout({ children, params }) {\n * const locale = await getLocale(params);\n * const messages = await getMessages();\n *\n * return (\n * <I18nProvider locale={locale} messages={messages}>\n * {children}\n * </I18nProvider>\n * );\n * }\n * ```\n */\n\n'use client';\n\nimport { createContext, useContext } from 'react';\nimport { NextIntlClientProvider } from 'next-intl';\nimport { I18nProvider as DjangoCfgI18nProvider } from '@djangocfg/i18n';\nimport type { I18nProviderProps, LocaleCode } from './types';\n\nconst DeclaredLocalesContext = createContext<LocaleCode[] | null>(null);\n\n/** Locales the app passed to its provider, or null when it passed none. */\nexport const useDeclaredLocales = (): LocaleCode[] | null => useContext(DeclaredLocalesContext);\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Provider Component\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Unified i18n Provider\n *\n * Wraps both NextIntlClientProvider and @djangocfg/i18n's I18nProvider\n * This ensures both next-intl hooks and @djangocfg/i18n hooks work correctly\n */\nexport function I18nProvider({\n locale,\n messages,\n locales,\n timeZone = 'UTC',\n now,\n children,\n}: I18nProviderProps) {\n return (\n <NextIntlClientProvider\n locale={locale}\n messages={messages}\n timeZone={timeZone}\n now={now}\n >\n <DjangoCfgI18nProvider\n locale={locale as LocaleCode}\n translations={messages}\n >\n <DeclaredLocalesContext.Provider value={locales ?? null}>\n {children}\n </DeclaredLocalesContext.Provider>\n </DjangoCfgI18nProvider>\n </NextIntlClientProvider>\n );\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Lightweight Provider (next-intl only)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Next-intl only provider (without @djangocfg/i18n context)\n * Use if you only need next-intl hooks\n */\nexport function NextIntlProvider({\n locale,\n messages,\n locales,\n timeZone = 'UTC',\n now,\n children,\n}: I18nProviderProps) {\n return (\n <NextIntlClientProvider\n locale={locale}\n messages={messages}\n timeZone={timeZone}\n now={now}\n >\n <DeclaredLocalesContext.Provider value={locales ?? null}>\n {children}\n </DeclaredLocalesContext.Provider>\n </NextIntlClientProvider>\n );\n}\n","/**\n * One locale across every host of one product family.\n *\n * `NEXT_LOCALE` is written host-only by default, so a reader who picked Russian on `hub.example.com` meets English on\n * `team.example.com`. The session tokens already live on the registrable domain (`@djangocfg/api` `createStorage`,\n * `cookieDomain: 'auto'`); the locale follows the same rule: the cookie gets `Domain=` the registrable domain, and the\n * host-only twin is expired so it cannot shadow the shared one.\n *\n * Pure and framework-free, so the proxy (server) and `useChangeLocale` (browser) agree on the domain.\n */\n\nexport const LOCALE_COOKIE = 'NEXT_LOCALE';\nexport const LOCALE_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;\n\n// Second-level public suffixes whose registrable domain has three labels. Not the whole Public Suffix List: the common\n// ones; anything else sets NEXT_PUBLIC_COOKIE_DOMAIN.\nconst TWO_LABEL_SUFFIXES = new Set([\n 'co.uk', 'org.uk', 'ac.uk', 'com.au', 'net.au', 'co.nz', 'co.jp', 'co.kr', 'or.kr', 'com.br', 'com.tr', 'com.cn', 'com.mx',\n 'co.in', 'co.za', 'com.sg', 'com.hk', 'com.tw', 'com.ar', 'com.ua', 'co.il',\n]);\n\n/**\n * The domain a cookie must carry to be sent to every subdomain, or `null` for a host that cannot share (an IP, a bare\n * label such as `localhost`, or an apex with no subdomain in use: a host-only cookie already covers it).\n * `override` (`NEXT_PUBLIC_COOKIE_DOMAIN`) wins when set.\n */\nexport function sharedCookieDomain(hostname: string, override?: string | null): string | null {\n const forced = override?.trim().replace(/^\\./, '');\n if (forced) return forced;\n const host = hostname.split(':')[0]!.toLowerCase();\n if (!host || /^\\d+(\\.\\d+){3}$/.test(host) || host.includes(':')) return null;\n const labels = host.split('.');\n if (labels.length < 2) return null;\n const keep = TWO_LABEL_SUFFIXES.has(labels.slice(-2).join('.')) ? 3 : 2;\n return labels.slice(-keep).join('.');\n}\n\n/** The `Set-Cookie` value that writes the shared locale cookie. */\nexport function localeCookieHeader(locale: string, domain: string | null, secure: boolean): string {\n return `${LOCALE_COOKIE}=${encodeURIComponent(locale)}; Path=/; Max-Age=${LOCALE_COOKIE_MAX_AGE}; SameSite=Lax${domain ? `; Domain=${domain}` : ''}${secure ? '; Secure' : ''}`;\n}\n\n/** Expires the host-only twin of the cookie (a cookie is identified by name and Domain). */\nexport function expireHostOnlyLocaleCookie(secure: boolean): string {\n return `${LOCALE_COOKIE}=; Path=/; Max-Age=0; SameSite=Lax${secure ? '; Secure' : ''}`;\n}\n"],"mappings":";;;AAsBA;AAAA,EACI;AAAA,EAAc,aAAa;AAAA,EAAmB;AAAA,EAAa;AAAA,EAAQ;AAAA,EACnE,mBAAmB;AAAA,OAChB;;;ACCP,SAAS,oBAAoB,gCAAgC;;;ACnB7D,SAAS,qBAAqB;AAQvB,IAAM,kBAAgC,CAAC,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,SAAS,MAAM,MAAM,MAAM,IAAI;AAC9I,IAAM,iBAA6B;AAoBnC,SAAS,cAAc,QAA8B;AAC1D,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,QAAM,eAAe,QAAQ,gBAAgB;AAE7C,SAAO,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAMO,IAAM,UAAU,cAAc;;;ADN9B,SAAS,iBAAiB,eAAkD;AACjF,QAAM,SAAS,iBAAiB;AAChC,SAAO,yBAAyB,MAAM;AACxC;AAkBO,IAAM;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI,iBAAiB;;;AE9CrB,SAAS,eAAe,kBAAkB;AAC1C,SAAS,8BAA8B;AACvC,SAAS,gBAAgB,6BAA6B;AAqC9C;AAlCR,IAAM,yBAAyB,cAAmC,IAAI;AAG/D,IAAM,qBAAqB,MAA2B,WAAW,sBAAsB;AAYvF,SAAS,aAAa;AAAA,EAC3B;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S,UAAU,QAAQ,IAAI,yBAAyB;AACjG,aAAS,SAAS,mBAAmB,QAAQ,QAAQ,MAAM;AAC3D,QAAI,OAAQ,UAAS,SAAS,2BAA2B,MAAM;AAI/D,WAAO,SAAS,OAAO,IAAI,MAAM,GAAG,QAAQ;AAAA,EAC9C;AACF;AAeO,SAAS,oBAAoB;AAClC,QAAM,SAAS,UAAU;AACzB,QAAM,UAAU,WAAW;AAC3B,QAAM,eAAe,gBAAgB;AAErC,SAAO,EAAE,QAAQ,SAAS,aAAa;AACzC;","names":[]}
@@ -54,6 +54,49 @@ import { jsx } from "react/jsx-runtime";
54
54
  var DeclaredLocalesContext = createContext(null);
55
55
  var useDeclaredLocales = () => useContext(DeclaredLocalesContext);
56
56
 
57
+ // src/i18n/shared-locale.ts
58
+ var LOCALE_COOKIE = "NEXT_LOCALE";
59
+ var LOCALE_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
60
+ var TWO_LABEL_SUFFIXES = /* @__PURE__ */ new Set([
61
+ "co.uk",
62
+ "org.uk",
63
+ "ac.uk",
64
+ "com.au",
65
+ "net.au",
66
+ "co.nz",
67
+ "co.jp",
68
+ "co.kr",
69
+ "or.kr",
70
+ "com.br",
71
+ "com.tr",
72
+ "com.cn",
73
+ "com.mx",
74
+ "co.in",
75
+ "co.za",
76
+ "com.sg",
77
+ "com.hk",
78
+ "com.tw",
79
+ "com.ar",
80
+ "com.ua",
81
+ "co.il"
82
+ ]);
83
+ function sharedCookieDomain(hostname, override) {
84
+ const forced = override?.trim().replace(/^\./, "");
85
+ if (forced) return forced;
86
+ const host = hostname.split(":")[0].toLowerCase();
87
+ if (!host || /^\d+(\.\d+){3}$/.test(host) || host.includes(":")) return null;
88
+ const labels = host.split(".");
89
+ if (labels.length < 2) return null;
90
+ const keep = TWO_LABEL_SUFFIXES.has(labels.slice(-2).join(".")) ? 3 : 2;
91
+ return labels.slice(-keep).join(".");
92
+ }
93
+ function localeCookieHeader(locale, domain, secure) {
94
+ return `${LOCALE_COOKIE}=${encodeURIComponent(locale)}; Path=/; Max-Age=${LOCALE_COOKIE_MAX_AGE}; SameSite=Lax${domain ? `; Domain=${domain}` : ""}${secure ? "; Secure" : ""}`;
95
+ }
96
+ function expireHostOnlyLocaleCookie(secure) {
97
+ return `${LOCALE_COOKIE}=; Path=/; Max-Age=0; SameSite=Lax${secure ? "; Secure" : ""}`;
98
+ }
99
+
57
100
  // src/i18n/client.ts
58
101
  function useLocale() {
59
102
  return useNextIntlLocale();
@@ -65,9 +108,10 @@ function useLocales() {
65
108
  function useChangeLocale() {
66
109
  const pathname = usePathname();
67
110
  return (locale) => {
68
- const date = /* @__PURE__ */ new Date();
69
- date.setFullYear(date.getFullYear() + 1);
70
- document.cookie = `NEXT_LOCALE=${locale}; expires=${date.toUTCString()}; path=/`;
111
+ const secure = window.location.protocol === "https:";
112
+ const domain = sharedCookieDomain(window.location.hostname, process.env.NEXT_PUBLIC_COOKIE_DOMAIN);
113
+ document.cookie = localeCookieHeader(locale, domain, secure);
114
+ if (domain) document.cookie = expireHostOnlyLocaleCookie(secure);
71
115
  window.location.href = `/${locale}${pathname}`;
72
116
  };
73
117
  }