@eldrajs/theme-nuxt 0.0.0 → 0.2.0

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 (45) hide show
  1. package/CHANGELOG.md +255 -0
  2. package/LICENSE +21 -0
  3. package/README.md +323 -1
  4. package/dist/module.cjs +5 -0
  5. package/dist/module.d.mts +56 -0
  6. package/dist/module.d.ts +56 -0
  7. package/dist/module.json +12 -0
  8. package/dist/module.mjs +320 -0
  9. package/dist/runtime/catalog.d.ts +119 -0
  10. package/dist/runtime/catalog.js +226 -0
  11. package/dist/runtime/commerce.d.ts +68 -0
  12. package/dist/runtime/commerce.js +40 -0
  13. package/dist/runtime/composables/useEldraPage.d.ts +17 -0
  14. package/dist/runtime/composables/useEldraPage.js +229 -0
  15. package/dist/runtime/designTokens.d.ts +59 -0
  16. package/dist/runtime/designTokens.js +55 -0
  17. package/dist/runtime/drafts.d.ts +3 -0
  18. package/dist/runtime/drafts.js +89 -0
  19. package/dist/runtime/links.d.ts +32 -0
  20. package/dist/runtime/links.js +132 -0
  21. package/dist/runtime/locale.d.ts +21 -0
  22. package/dist/runtime/locale.js +9 -0
  23. package/dist/runtime/localeState.d.ts +52 -0
  24. package/dist/runtime/localeState.js +48 -0
  25. package/dist/runtime/locales.d.ts +186 -0
  26. package/dist/runtime/locales.js +109 -0
  27. package/dist/runtime/messages.d.ts +59 -0
  28. package/dist/runtime/messages.js +66 -0
  29. package/dist/runtime/origins.d.ts +18 -0
  30. package/dist/runtime/origins.js +28 -0
  31. package/dist/runtime/plugin.d.ts +3 -0
  32. package/dist/runtime/plugin.js +83 -0
  33. package/dist/runtime/resolveRoute.d.ts +81 -0
  34. package/dist/runtime/resolveRoute.js +166 -0
  35. package/dist/runtime/routePath.d.ts +31 -0
  36. package/dist/runtime/routePath.js +7 -0
  37. package/dist/runtime/siteIconAssets.d.ts +19 -0
  38. package/dist/runtime/siteIconAssets.js +29 -0
  39. package/dist/runtime/siteIcons.d.ts +74 -0
  40. package/dist/runtime/siteIcons.js +96 -0
  41. package/dist/runtime/staticRoutes.d.ts +14 -0
  42. package/dist/runtime/staticRoutes.js +26 -0
  43. package/dist/types.d.mts +7 -0
  44. package/dist/types.d.ts +7 -0
  45. package/package.json +60 -2
@@ -0,0 +1,19 @@
1
+ import type { ResolvedSiteIcons } from './siteIcons.js';
2
+ /** One file the build writes into the static output. */
3
+ export interface GeneratedIconFile {
4
+ /** Path relative to the site root. */
5
+ name: string;
6
+ data: Buffer;
7
+ }
8
+ export interface SiteIconOutput {
9
+ /** Only `site.webmanifest`: every image is linked straight from the media CDN. */
10
+ files: GeneratedIconFile[];
11
+ link: Record<string, string>[];
12
+ meta: Record<string, string>[];
13
+ }
14
+ /**
15
+ * The web manifest and head tags for a resolved site icon setting. Pure and in-memory — no image
16
+ * is fetched or processed here: the media worker renders every size (always PNG), Core builds the
17
+ * URLs, and this only points at them. The manifest is same-origin JSON (a browser requires it).
18
+ */
19
+ export declare function buildSiteIconOutput(setting: Pick<ResolvedSiteIcons, 'icons' | 'backgroundColor' | 'themeColor' | 'shortName' | 'name'>, baseURL?: string): SiteIconOutput;
@@ -0,0 +1,29 @@
1
+ export function buildSiteIconOutput(setting, baseURL = "/") {
2
+ const base = baseURL.endsWith("/") ? baseURL : `${baseURL}/`;
3
+ const { icons } = setting;
4
+ const name = setting.name ?? setting.shortName;
5
+ const manifest = {
6
+ ...name === null ? {} : { name },
7
+ ...setting.shortName === null ? {} : { short_name: setting.shortName },
8
+ icons: [
9
+ { src: icons.icon192, sizes: "192x192", type: "image/png" },
10
+ { src: icons.icon512, sizes: "512x512", type: "image/png" },
11
+ { src: icons.maskable512, sizes: "512x512", type: "image/png", purpose: "maskable" }
12
+ ],
13
+ ...setting.themeColor === null ? {} : { theme_color: setting.themeColor },
14
+ background_color: setting.backgroundColor,
15
+ display: "standalone",
16
+ start_url: base
17
+ };
18
+ return {
19
+ files: [
20
+ { name: "site.webmanifest", data: Buffer.from(JSON.stringify(manifest, null, 2) + "\n") }
21
+ ],
22
+ link: [
23
+ { rel: "icon", type: "image/png", sizes: "32x32", href: icons.favicon32 },
24
+ { rel: "apple-touch-icon", href: icons.appleTouch180 },
25
+ { rel: "manifest", href: `${base}site.webmanifest` }
26
+ ],
27
+ meta: setting.themeColor === null ? [] : [{ name: "theme-color", content: setting.themeColor }]
28
+ };
29
+ }
@@ -0,0 +1,74 @@
1
+ import type { EldraClient } from '@eldrajs/sdk';
2
+ /**
3
+ * The site's icon setting exactly as `GET /site/v1/site-icons` answers it (and Studio's
4
+ * `PUT /sites/{siteId}/site-icons` stores it). `iconUrl: null` means "no icons set": the theme's
5
+ * own `public/` files and head tags stay. The colour and short-name defaults (the theme's primary
6
+ * token, the site name) are resolved by the **build** — `resolveSiteIcons` below — never by Core.
7
+ */
8
+ export interface SiteIconsSetting {
9
+ revision: number;
10
+ /** The media-library asset URL (`{media}/public/{orgId}/assets/{assetId}`), or `null` when no icon is set. */
11
+ iconUrl: string | null;
12
+ /** `#rrggbb`. Paints the iOS icon and the maskable Android icon, which cannot be transparent. */
13
+ backgroundColor: string;
14
+ /** `#rrggbb`, or `null` for the theme's primary design token. */
15
+ themeColor: string | null;
16
+ /** 1–12 characters, or `null` for the site name. */
17
+ shortName: string | null;
18
+ /**
19
+ * The rendered variants, built by Core (the only place that knows the media worker's icon
20
+ * suffixes) — `null` exactly when `iconUrl` is `null`. The build links to these, never renders.
21
+ */
22
+ icons: SiteIconUrls | null;
23
+ }
24
+ /** Absolute media URLs of the icon variants the media worker renders (always `image/png`). */
25
+ export interface SiteIconUrls {
26
+ favicon32: string;
27
+ appleTouch180: string;
28
+ icon192: string;
29
+ icon512: string;
30
+ maskable512: string;
31
+ }
32
+ /**
33
+ * The slice of an `@eldrajs/sdk` client this read needs — a whole `EldraClient` satisfies it. The
34
+ * same narrow shape, for the same reasons, as `DesignTokensReader`: `GET /site/v1/site-icons` is a
35
+ * site-module read with no typed `features.*` method, so the client's generic `request` carries it.
36
+ */
37
+ export interface SiteIconsReader {
38
+ request: EldraClient['request'];
39
+ }
40
+ /** The one line a build prints when it could not read the platform's site icons. */
41
+ export declare const SITE_ICONS_WARNING = "[eldra] could not read the platform\u2019s site icons \u2014 keeping the theme\u2019s own icon files";
42
+ /** How long the build waits for the answer; see `READ_TIMEOUT_MS` in `./designTokens.ts`. */
43
+ export declare const READ_TIMEOUT_MS = 10000;
44
+ /** Android's launcher shows at most about this many characters of `short_name`. */
45
+ export declare const SHORT_NAME_MAX = 12;
46
+ /**
47
+ * The platform's site-icon setting, or `null`.
48
+ *
49
+ * Fail-soft exactly like `readDesignTokens`: no client, an unreachable gateway, a timeout and a
50
+ * response that is not the documented shape all end in `null` and **one** warning, so a theme keeps
51
+ * deploying with the icon files it ships. A well-formed answer with `iconUrl: null` is **not** a
52
+ * failure — it is the normal "nothing set" state — and warns nothing.
53
+ */
54
+ export declare function readSiteIcons(reader: SiteIconsReader | null, warn?: (message: string) => void): Promise<SiteIconsSetting | null>;
55
+ /** The values the generated files and tags are made from, defaults filled in. */
56
+ export interface ResolvedSiteIcons {
57
+ iconUrl: string;
58
+ icons: SiteIconUrls;
59
+ backgroundColor: string;
60
+ /** `null` when neither the setting nor the theme gives one — the meta tag is then omitted. */
61
+ themeColor: string | null;
62
+ /** `null` when neither the setting nor a site name gives one. */
63
+ shortName: string | null;
64
+ name: string | null;
65
+ }
66
+ /**
67
+ * Fills in the defaults Core deliberately does not store: the theme colour falls back to the
68
+ * theme's primary design token, the short name to the site name (cut to Android's limit). `null`
69
+ * when no icon is set, which is the signal to leave the theme's own files alone.
70
+ */
71
+ export declare function resolveSiteIcons(setting: SiteIconsSetting | null, defaults: {
72
+ siteName?: string | null;
73
+ primaryToken?: string | null;
74
+ }): ResolvedSiteIcons | null;
@@ -0,0 +1,96 @@
1
+ const ICON_URL_KEYS = ["favicon32", "appleTouch180", "icon192", "icon512", "maskable512"];
2
+ export const SITE_ICONS_WARNING = "[eldra] could not read the platform\u2019s site icons \u2014 keeping the theme\u2019s own icon files";
3
+ export const READ_TIMEOUT_MS = 1e4;
4
+ export const SHORT_NAME_MAX = 12;
5
+ const HEX_COLOR = /^#[0-9a-f]{6}$/i;
6
+ export async function readSiteIcons(reader, warn = console.warn) {
7
+ const read = reader === null ? { setting: null, cause: null } : await readOrNull(reader);
8
+ if (read.setting === null) {
9
+ warn(read.cause === null ? SITE_ICONS_WARNING : `${SITE_ICONS_WARNING} (${read.cause})`);
10
+ return null;
11
+ }
12
+ return read.setting;
13
+ }
14
+ async function readOrNull(reader) {
15
+ const controller = new AbortController();
16
+ const timer = setTimeout(
17
+ () => controller.abort(new Error(`timed out after ${READ_TIMEOUT_MS}ms`)),
18
+ READ_TIMEOUT_MS
19
+ );
20
+ try {
21
+ const response = await reader.request({
22
+ path: "/site/v1/site-icons",
23
+ signal: controller.signal
24
+ });
25
+ const setting = toSiteIconsSetting(response);
26
+ return {
27
+ setting,
28
+ cause: setting === null ? "the platform published an unusable response" : null
29
+ };
30
+ } catch (error) {
31
+ return { setting: null, cause: error instanceof Error ? error.message : String(error) };
32
+ } finally {
33
+ clearTimeout(timer);
34
+ }
35
+ }
36
+ function toSiteIconsSetting(value) {
37
+ if (typeof value !== "object" || value === null) return null;
38
+ const record = value;
39
+ if (typeof record.revision !== "number" || !Number.isFinite(record.revision)) return null;
40
+ const { iconUrl, backgroundColor, themeColor, shortName } = record;
41
+ if (iconUrl !== null && typeof iconUrl !== "string") return null;
42
+ if (typeof backgroundColor !== "string" || !HEX_COLOR.test(backgroundColor)) return null;
43
+ if (themeColor !== null && (typeof themeColor !== "string" || !HEX_COLOR.test(themeColor))) {
44
+ return null;
45
+ }
46
+ if (shortName !== null && typeof shortName !== "string") return null;
47
+ const icons = toSiteIconUrls(record.icons);
48
+ if (icons === void 0) return null;
49
+ if ((iconUrl === null || iconUrl === "") !== (icons === null)) return null;
50
+ return {
51
+ revision: record.revision,
52
+ iconUrl: iconUrl === "" ? null : iconUrl,
53
+ backgroundColor: backgroundColor.toLowerCase(),
54
+ themeColor: themeColor === null ? null : themeColor.toLowerCase(),
55
+ shortName: shortName === null ? null : truncateRunes(shortName.trim(), SHORT_NAME_MAX) || null,
56
+ icons
57
+ };
58
+ }
59
+ function toSiteIconUrls(value) {
60
+ if (value === null) return null;
61
+ if (typeof value !== "object") return void 0;
62
+ const record = value;
63
+ const urls = {};
64
+ for (const key of ICON_URL_KEYS) {
65
+ const url = record[key];
66
+ if (typeof url !== "string" || !isAbsoluteHttpUrl(url)) return void 0;
67
+ urls[key] = url;
68
+ }
69
+ return urls;
70
+ }
71
+ function isAbsoluteHttpUrl(value) {
72
+ try {
73
+ const { protocol, hostname } = new URL(value);
74
+ if (protocol === "https:") return true;
75
+ return protocol === "http:" && (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]");
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
80
+ export function resolveSiteIcons(setting, defaults) {
81
+ if (setting === null || setting.iconUrl === null || setting.icons === null) return null;
82
+ const siteName = defaults.siteName?.trim() || null;
83
+ const primary = defaults.primaryToken ?? null;
84
+ const name = siteName ?? setting.shortName;
85
+ return {
86
+ iconUrl: setting.iconUrl,
87
+ icons: setting.icons,
88
+ backgroundColor: setting.backgroundColor,
89
+ themeColor: setting.themeColor ?? (primary !== null && HEX_COLOR.test(primary) ? primary : null),
90
+ shortName: setting.shortName ?? (siteName === null ? null : truncateRunes(siteName, 12)),
91
+ name
92
+ };
93
+ }
94
+ function truncateRunes(value, max) {
95
+ return Array.from(value).slice(0, max).join("").trim();
96
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The prerendered route set once it is known, **without waiting** — `null` until the manifest has
3
+ * been read, and `null` forever on a build that has no usable one.
4
+ *
5
+ * This is the accessor a synchronous decision uses (`useEldraPage`'s `getCachedData`, which Nuxt
6
+ * calls with no chance to await). `prime()` from a plugin and Nuxt's own payload plugin both put
7
+ * the answer here long before the first client navigation; anything that still finds it missing
8
+ * falls through to the asynchronous `prerenderedRoutes()`.
9
+ */
10
+ export declare function knownPrerenderedRoutes(): ReadonlySet<string> | null;
11
+ /** The prerendered route set, reading the manifest at most once per page load. */
12
+ export declare function prerenderedRoutes(): Promise<ReadonlySet<string> | null>;
13
+ /** Start the one manifest read now, so the first navigation has its answer synchronously. */
14
+ export declare function primePrerenderedRoutes(): void;
@@ -0,0 +1,26 @@
1
+ import { getAppManifest } from "nuxt/app";
2
+ import { canonicalRoutePath } from "./routePath.js";
3
+ let known = null;
4
+ let lookup = null;
5
+ export function knownPrerenderedRoutes() {
6
+ return known;
7
+ }
8
+ export function prerenderedRoutes() {
9
+ lookup ??= readManifest();
10
+ return lookup;
11
+ }
12
+ export function primePrerenderedRoutes() {
13
+ void prerenderedRoutes();
14
+ }
15
+ async function readManifest() {
16
+ if (!import.meta.client || import.meta.dev) return null;
17
+ try {
18
+ const manifest = await getAppManifest();
19
+ const routes = manifest.prerendered;
20
+ if (!Array.isArray(routes) || routes.length === 0) return null;
21
+ known = new Set(routes.map(canonicalRoutePath));
22
+ return known;
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.js'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.js'
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module'
package/package.json CHANGED
@@ -1,11 +1,69 @@
1
1
  {
2
2
  "name": "@eldrajs/theme-nuxt",
3
- "version": "0.0.0",
4
- "description": "Placeholder that reserved the name for trusted publishing. Install a real version.",
3
+ "version": "0.2.0",
4
+ "description": "Nuxt module for Eldra themes: wires @eldrajs/vite-plugin-theme, the gateway client, draft overlays and the Studio preview bridge into a Nuxt 4 site.",
5
+ "keywords": [
6
+ "cms",
7
+ "eldra",
8
+ "headless",
9
+ "nuxt",
10
+ "nuxt-module",
11
+ "theme"
12
+ ],
13
+ "homepage": "https://github.com/eldra-is/headless-kit/tree/main/packages/theme-nuxt#readme",
14
+ "bugs": "https://github.com/eldra-is/headless-kit/issues",
5
15
  "license": "MIT",
6
16
  "repository": {
7
17
  "type": "git",
8
18
  "url": "git+https://github.com/eldra-is/headless-kit.git",
9
19
  "directory": "packages/theme-nuxt"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "CHANGELOG.md",
24
+ "LICENSE"
25
+ ],
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/types.d.mts",
30
+ "import": "./dist/module.mjs"
31
+ },
32
+ "./commerce": {
33
+ "types": "./dist/runtime/commerce.d.ts",
34
+ "import": "./dist/runtime/commerce.js"
35
+ },
36
+ "./locales": {
37
+ "types": "./dist/runtime/locales.d.ts",
38
+ "import": "./dist/runtime/locales.js"
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "provenance": true
45
+ },
46
+ "dependencies": {
47
+ "@nuxt/kit": "^4.0.0",
48
+ "defu": "^6.1.4",
49
+ "@eldrajs/sdk": "^0.2.9",
50
+ "@eldrajs/theme-core": "^0.2.0",
51
+ "@eldrajs/theme-vue": "^0.2.0",
52
+ "@eldrajs/vite-plugin-theme": "^0.2.0"
53
+ },
54
+ "devDependencies": {
55
+ "@nuxt/module-builder": "^0.8.4",
56
+ "@nuxt/schema": "^4.0.0",
57
+ "@playwright/test": "1.62.1",
58
+ "execa": "^9.5.2",
59
+ "nuxt": "^4.0.0"
60
+ },
61
+ "engines": {
62
+ "node": ">=20"
63
+ },
64
+ "scripts": {
65
+ "build": "nuxt-module-build build",
66
+ "typecheck": "tsc -p tsconfig.json",
67
+ "test": "vitest run"
10
68
  }
11
69
  }