@easy-web/core 1.3.3 → 1.5.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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +9 -9
  3. package/src/components/Header.astro +205 -205
  4. package/src/components/HeaderCentered.astro +230 -230
  5. package/src/components/HeaderFlyout.astro +370 -370
  6. package/src/components/HeaderHideOnScroll.astro +234 -234
  7. package/src/components/LanguageSwitch.astro +82 -82
  8. package/src/components/NotFound.astro +115 -115
  9. package/src/components/PageShell.astro +82 -82
  10. package/src/components/SeoHead.astro +106 -106
  11. package/src/components/StructuredData.astro +1 -1
  12. package/src/components/ThemeToggle.astro +84 -84
  13. package/src/components/UniversalMedia.astro +106 -106
  14. package/src/components/__tests__/StructuredData.test.ts +1 -1
  15. package/src/components/__tests__/UniversalMedia.test.ts +65 -65
  16. package/src/contracts/__tests__/jsonld.test.ts +1 -1
  17. package/src/contracts/index.ts +1 -1
  18. package/src/contracts/jsonld.ts +1 -1
  19. package/src/i18n/__tests__/factory.test.ts +54 -54
  20. package/src/i18n/__tests__/localized-paths.test.ts +258 -258
  21. package/src/i18n/__tests__/routing-multi-locale.test.ts +89 -89
  22. package/src/i18n/__tests__/seo.test.ts +140 -140
  23. package/src/i18n/factory.ts +66 -66
  24. package/src/i18n/index.ts +5 -5
  25. package/src/i18n/localized-paths.ts +181 -181
  26. package/src/i18n/seo.ts +131 -131
  27. package/src/markdown/__tests__/__fixtures__/abs-src-assets.md +1 -1
  28. package/src/markdown/__tests__/__fixtures__/external-url.md +1 -1
  29. package/src/markdown/__tests__/__fixtures__/public-slash.md +1 -1
  30. package/src/markdown/__tests__/__fixtures__/rel-double-dot.md +1 -1
  31. package/src/markdown/__tests__/index.test.ts +60 -60
  32. package/src/markdown/index.ts +1 -1
  33. package/src/markdown/plugin.ts +42 -42
  34. package/src/schemas/__tests__/notFound.test.ts +32 -32
  35. package/src/schemas/notFound.ts +33 -33
  36. package/src/seo/__tests__/crawl-policy.test.ts +50 -50
  37. package/src/seo/__tests__/integration.test.ts +195 -195
  38. package/src/seo/__tests__/no-index-resolution.test.ts +53 -53
  39. package/src/seo/__tests__/robots-txt.test.ts +66 -66
  40. package/src/seo/__tests__/sitemap-options.test.ts +400 -400
  41. package/src/seo/crawl-policy.ts +36 -36
  42. package/src/seo/index.ts +254 -254
  43. package/src/seo/routes/robots-txt.ts +36 -36
@@ -1,84 +1,84 @@
1
- ---
2
- /**
3
- * ThemeToggle – switches between light and dark themes using @easy-web/theme-core.
4
- * Pure Astro component with inline vanilla JS. No framework dependency.
5
- */
6
- import type { ThemeToggleProps } from '../contracts/props.js';
7
- import { resolveLabels } from './labels.js';
8
-
9
- export type Props = ThemeToggleProps;
10
-
11
- const { lang = 'en', labels: labelOverrides } = Astro.props;
12
- const labels = resolveLabels(lang, labelOverrides);
13
- const { label = labels.toggleColorTheme } = Astro.props;
14
- ---
15
-
16
- <button
17
- type="button"
18
- class="ew-theme-toggle"
19
- aria-label={label}
20
- title={label}
21
- >
22
- <svg class="ew-theme-toggle__icon ew-theme-toggle__icon--sun" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
23
- <circle cx="12" cy="12" r="5"></circle>
24
- <line x1="12" y1="1" x2="12" y2="3"></line>
25
- <line x1="12" y1="21" x2="12" y2="23"></line>
26
- <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
27
- <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
28
- <line x1="1" y1="12" x2="3" y2="12"></line>
29
- <line x1="21" y1="12" x2="23" y2="12"></line>
30
- <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
31
- <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
32
- </svg>
33
- <svg class="ew-theme-toggle__icon ew-theme-toggle__icon--moon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
34
- <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
35
- </svg>
36
- </button>
37
-
38
- <style>
39
- .ew-theme-toggle {
40
- display: inline-flex;
41
- align-items: center;
42
- justify-content: center;
43
- box-sizing: border-box;
44
- /* Shared header-control height. Icon-only → same value for width for a square button. */
45
- width: 2.25rem;
46
- height: 2.25rem;
47
- background: transparent;
48
- border: 1px solid var(--ew-border);
49
- border-radius: var(--ew-radius-md);
50
- color: var(--ew-on-surface);
51
- cursor: pointer;
52
- padding: 0;
53
- }
54
- .ew-theme-toggle:hover {
55
- background: var(--ew-surface-muted);
56
- }
57
- .ew-theme-toggle:focus-visible {
58
- outline: 2px solid var(--ew-primary);
59
- outline-offset: 2px;
60
- }
61
-
62
- /* Default: show sun, hide moon (light mode) */
63
- .ew-theme-toggle__icon--moon { display: none; }
64
- .ew-theme-toggle__icon--sun { display: block; }
65
-
66
- :global([data-theme="dark"]) .ew-theme-toggle__icon--sun { display: none; }
67
- :global([data-theme="dark"]) .ew-theme-toggle__icon--moon { display: block; }
68
-
69
- @media (prefers-color-scheme: dark) {
70
- :global(:root:not([data-theme="light"])) .ew-theme-toggle__icon--sun { display: none; }
71
- :global(:root:not([data-theme="light"])) .ew-theme-toggle__icon--moon { display: block; }
72
- }
73
- </style>
74
-
75
- <script>
76
- import { applyTheme, getPreferredTheme } from '../theme/index.js';
77
-
78
- const btn = document.querySelector('.ew-theme-toggle') as HTMLButtonElement | null;
79
- btn?.addEventListener('click', () => {
80
- const current = getPreferredTheme();
81
- const next = current === 'dark' ? 'light' : 'dark';
82
- applyTheme(next);
83
- });
84
- </script>
1
+ ---
2
+ /**
3
+ * ThemeToggle – switches between light and dark themes using @easy-web/theme-core.
4
+ * Pure Astro component with inline vanilla JS. No framework dependency.
5
+ */
6
+ import type { ThemeToggleProps } from '../contracts/props.js';
7
+ import { resolveLabels } from './labels.js';
8
+
9
+ export type Props = ThemeToggleProps;
10
+
11
+ const { lang = 'en', labels: labelOverrides } = Astro.props;
12
+ const labels = resolveLabels(lang, labelOverrides);
13
+ const { label = labels.toggleColorTheme } = Astro.props;
14
+ ---
15
+
16
+ <button
17
+ type="button"
18
+ class="ew-theme-toggle"
19
+ aria-label={label}
20
+ title={label}
21
+ >
22
+ <svg class="ew-theme-toggle__icon ew-theme-toggle__icon--sun" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
23
+ <circle cx="12" cy="12" r="5"></circle>
24
+ <line x1="12" y1="1" x2="12" y2="3"></line>
25
+ <line x1="12" y1="21" x2="12" y2="23"></line>
26
+ <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
27
+ <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
28
+ <line x1="1" y1="12" x2="3" y2="12"></line>
29
+ <line x1="21" y1="12" x2="23" y2="12"></line>
30
+ <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
31
+ <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
32
+ </svg>
33
+ <svg class="ew-theme-toggle__icon ew-theme-toggle__icon--moon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
34
+ <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
35
+ </svg>
36
+ </button>
37
+
38
+ <style>
39
+ .ew-theme-toggle {
40
+ display: inline-flex;
41
+ align-items: center;
42
+ justify-content: center;
43
+ box-sizing: border-box;
44
+ /* Shared header-control height. Icon-only → same value for width for a square button. */
45
+ width: 2.25rem;
46
+ height: 2.25rem;
47
+ background: transparent;
48
+ border: 1px solid var(--ew-border);
49
+ border-radius: var(--ew-radius-md);
50
+ color: var(--ew-on-surface);
51
+ cursor: pointer;
52
+ padding: 0;
53
+ }
54
+ .ew-theme-toggle:hover {
55
+ background: var(--ew-surface-muted);
56
+ }
57
+ .ew-theme-toggle:focus-visible {
58
+ outline: 2px solid var(--ew-primary);
59
+ outline-offset: 2px;
60
+ }
61
+
62
+ /* Default: show sun, hide moon (light mode) */
63
+ .ew-theme-toggle__icon--moon { display: none; }
64
+ .ew-theme-toggle__icon--sun { display: block; }
65
+
66
+ :global([data-theme="dark"]) .ew-theme-toggle__icon--sun { display: none; }
67
+ :global([data-theme="dark"]) .ew-theme-toggle__icon--moon { display: block; }
68
+
69
+ @media (prefers-color-scheme: dark) {
70
+ :global(:root:not([data-theme="light"])) .ew-theme-toggle__icon--sun { display: none; }
71
+ :global(:root:not([data-theme="light"])) .ew-theme-toggle__icon--moon { display: block; }
72
+ }
73
+ </style>
74
+
75
+ <script>
76
+ import { applyTheme, getPreferredTheme } from '../theme/index.js';
77
+
78
+ const btn = document.querySelector('.ew-theme-toggle') as HTMLButtonElement | null;
79
+ btn?.addEventListener('click', () => {
80
+ const current = getPreferredTheme();
81
+ const next = current === 'dark' ? 'light' : 'dark';
82
+ applyTheme(next);
83
+ });
84
+ </script>
@@ -1,106 +1,106 @@
1
- ---
2
- /**
3
- * UniversalMedia — renders an image from any source type.
4
- *
5
- * @deprecated Use `Media` (`@easy-web/core/components/Media.astro`) with an
6
- * `Image` or `DecorativeImage` contract instead. Existing call sites keep
7
- * rendering exactly as before.
8
- *
9
- * @remarks
10
- * Supported image formats: JPEG, PNG, WebP, AVIF, SVG, GIF.
11
- * Unsupported formats (upload rejected at CMS level): HEIC, JXL.
12
- *
13
- * 4-case dispatch:
14
- * 1. ImageMetadata object → <Image> (Astro-optimised, with srcset)
15
- * 2. "/src/assets/..." string → glob lookup via `images` prop → <Image> (fallback to fallbackSrc)
16
- * 3. External URL ("http..." or "https...") → <Image inferSize>
17
- * 4. Everything else (public-folder path "/foo/bar.png") → plain <img>
18
- */
19
- import { Image } from 'astro:assets';
20
- import type { ImageMetadata } from 'astro';
21
-
22
- interface Props {
23
- /** The image source: an Astro ImageMetadata object or a URL/path string. */
24
- src: ImageMetadata | string;
25
- /** Alt text for the image (required). */
26
- alt: string;
27
- /**
28
- * Consumer-supplied glob result mapping paths to lazy image loaders.
29
- * Consumer generates this via Vite's glob-import helper (see Astro/Vite docs)
30
- * matching `/src/assets/**` with `{ import: 'default' }` so entries yield
31
- * `() => Promise<{ default: ImageMetadata }>`.
32
- * The component does NOT resolve the glob itself.
33
- */
34
- images: Record<string, () => Promise<{ default: ImageMetadata }>>;
35
- /** Fallback image path to use when a /src/assets/... glob lookup misses. Defaults to empty (renders nothing gracefully). */
36
- fallbackSrc?: string;
37
- /** Fallback alt text used when fallbackSrc is rendered. Defaults to alt. */
38
- fallbackAlt?: string;
39
- width?: number;
40
- height?: number;
41
- class?: string;
42
- decoding?: 'async' | 'auto' | 'sync';
43
- }
44
-
45
- const {
46
- src,
47
- alt,
48
- images,
49
- fallbackSrc,
50
- fallbackAlt,
51
- width = 800,
52
- height = 600,
53
- class: cssClass = '',
54
- decoding = 'async',
55
- } = Astro.props;
56
-
57
- // Case 1: already a resolved ImageMetadata object
58
- const isImageMetadata = typeof src !== 'string';
59
-
60
- // Normalise string to check against known patterns
61
- const srcStr = isImageMetadata ? '' : (src as string);
62
-
63
- // Case 2: /src/assets/... path — must be resolved via consumer-supplied glob
64
- const isInternalSrcAssets = srcStr.startsWith('/src/assets/');
65
-
66
- // Case 3: external URL
67
- const isExternalUrl = srcStr.startsWith('http://') || srcStr.startsWith('https://');
68
-
69
- // Resolve ImageMetadata for cases 1 & 2
70
- let resolvedSrc: ImageMetadata | null = null;
71
- let resolvedAlt = alt;
72
-
73
- if (isImageMetadata) {
74
- resolvedSrc = src as ImageMetadata;
75
- } else if (isInternalSrcAssets) {
76
- const loader = images[srcStr];
77
- if (typeof loader === 'function') {
78
- const mod = await loader();
79
- resolvedSrc = mod.default ?? (mod as unknown as ImageMetadata);
80
- }
81
- if (!resolvedSrc && fallbackSrc) {
82
- const fallbackLoader = images[fallbackSrc];
83
- if (typeof fallbackLoader === 'function') {
84
- const mod = await fallbackLoader();
85
- resolvedSrc = mod.default ?? (mod as unknown as ImageMetadata);
86
- resolvedAlt = fallbackAlt ?? alt;
87
- } else {
88
- console.warn(
89
- `UniversalMedia: "${srcStr}" not found in glob, and fallbackSrc "${fallbackSrc}" is also missing. Rendering as plain <img>.`
90
- );
91
- }
92
- }
93
- }
94
- ---
95
-
96
- {isImageMetadata || isInternalSrcAssets ? (
97
- resolvedSrc ? (
98
- <Image class={cssClass} src={resolvedSrc} alt={resolvedAlt} width={width} height={height} decoding={decoding} />
99
- ) : (
100
- <img class={cssClass} src={srcStr} alt={alt} width={width} height={height} decoding={decoding} />
101
- )
102
- ) : isExternalUrl ? (
103
- <Image class={cssClass} src={srcStr} alt={alt} inferSize decoding={decoding} />
104
- ) : (
105
- <img class={cssClass} src={srcStr} alt={alt} width={width} height={height} decoding={decoding} />
106
- )}
1
+ ---
2
+ /**
3
+ * UniversalMedia — renders an image from any source type.
4
+ *
5
+ * @deprecated Use `Media` (`@easy-web/core/components/Media.astro`) with an
6
+ * `Image` or `DecorativeImage` contract instead. Existing call sites keep
7
+ * rendering exactly as before.
8
+ *
9
+ * @remarks
10
+ * Supported image formats: JPEG, PNG, WebP, AVIF, SVG, GIF.
11
+ * Unsupported formats (upload rejected at CMS level): HEIC, JXL.
12
+ *
13
+ * 4-case dispatch:
14
+ * 1. ImageMetadata object → <Image> (Astro-optimised, with srcset)
15
+ * 2. "/src/assets/..." string → glob lookup via `images` prop → <Image> (fallback to fallbackSrc)
16
+ * 3. External URL ("http..." or "https...") → <Image inferSize>
17
+ * 4. Everything else (public-folder path "/foo/bar.png") → plain <img>
18
+ */
19
+ import { Image } from 'astro:assets';
20
+ import type { ImageMetadata } from 'astro';
21
+
22
+ interface Props {
23
+ /** The image source: an Astro ImageMetadata object or a URL/path string. */
24
+ src: ImageMetadata | string;
25
+ /** Alt text for the image (required). */
26
+ alt: string;
27
+ /**
28
+ * Consumer-supplied glob result mapping paths to lazy image loaders.
29
+ * Consumer generates this via Vite's glob-import helper (see Astro/Vite docs)
30
+ * matching `/src/assets/**` with `{ import: 'default' }` so entries yield
31
+ * `() => Promise<{ default: ImageMetadata }>`.
32
+ * The component does NOT resolve the glob itself.
33
+ */
34
+ images: Record<string, () => Promise<{ default: ImageMetadata }>>;
35
+ /** Fallback image path to use when a /src/assets/... glob lookup misses. Defaults to empty (renders nothing gracefully). */
36
+ fallbackSrc?: string;
37
+ /** Fallback alt text used when fallbackSrc is rendered. Defaults to alt. */
38
+ fallbackAlt?: string;
39
+ width?: number;
40
+ height?: number;
41
+ class?: string;
42
+ decoding?: 'async' | 'auto' | 'sync';
43
+ }
44
+
45
+ const {
46
+ src,
47
+ alt,
48
+ images,
49
+ fallbackSrc,
50
+ fallbackAlt,
51
+ width = 800,
52
+ height = 600,
53
+ class: cssClass = '',
54
+ decoding = 'async',
55
+ } = Astro.props;
56
+
57
+ // Case 1: already a resolved ImageMetadata object
58
+ const isImageMetadata = typeof src !== 'string';
59
+
60
+ // Normalise string to check against known patterns
61
+ const srcStr = isImageMetadata ? '' : (src as string);
62
+
63
+ // Case 2: /src/assets/... path — must be resolved via consumer-supplied glob
64
+ const isInternalSrcAssets = srcStr.startsWith('/src/assets/');
65
+
66
+ // Case 3: external URL
67
+ const isExternalUrl = srcStr.startsWith('http://') || srcStr.startsWith('https://');
68
+
69
+ // Resolve ImageMetadata for cases 1 & 2
70
+ let resolvedSrc: ImageMetadata | null = null;
71
+ let resolvedAlt = alt;
72
+
73
+ if (isImageMetadata) {
74
+ resolvedSrc = src as ImageMetadata;
75
+ } else if (isInternalSrcAssets) {
76
+ const loader = images[srcStr];
77
+ if (typeof loader === 'function') {
78
+ const mod = await loader();
79
+ resolvedSrc = mod.default ?? (mod as unknown as ImageMetadata);
80
+ }
81
+ if (!resolvedSrc && fallbackSrc) {
82
+ const fallbackLoader = images[fallbackSrc];
83
+ if (typeof fallbackLoader === 'function') {
84
+ const mod = await fallbackLoader();
85
+ resolvedSrc = mod.default ?? (mod as unknown as ImageMetadata);
86
+ resolvedAlt = fallbackAlt ?? alt;
87
+ } else {
88
+ console.warn(
89
+ `UniversalMedia: "${srcStr}" not found in glob, and fallbackSrc "${fallbackSrc}" is also missing. Rendering as plain <img>.`
90
+ );
91
+ }
92
+ }
93
+ }
94
+ ---
95
+
96
+ {isImageMetadata || isInternalSrcAssets ? (
97
+ resolvedSrc ? (
98
+ <Image class={cssClass} src={resolvedSrc} alt={resolvedAlt} width={width} height={height} decoding={decoding} />
99
+ ) : (
100
+ <img class={cssClass} src={srcStr} alt={alt} width={width} height={height} decoding={decoding} />
101
+ )
102
+ ) : isExternalUrl ? (
103
+ <Image class={cssClass} src={srcStr} alt={alt} inferSize decoding={decoding} />
104
+ ) : (
105
+ <img class={cssClass} src={srcStr} alt={alt} width={width} height={height} decoding={decoding} />
106
+ )}
@@ -42,4 +42,4 @@ describe('SeoHead structuredData', () => {
42
42
  expect(html).toContain('application/ld+json');
43
43
  expect(html).toContain('{"@type":"WebPage"}');
44
44
  });
45
- });
45
+ });
@@ -1,65 +1,65 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type { ImageMetadata } from 'astro';
3
-
4
- /**
5
- * Mirrors the dispatch logic inside UniversalMedia.astro.
6
- * Tests the categorisation, not the Astro rendering (which requires a full Astro setup).
7
- *
8
- * The component branches on 4 cases:
9
- * 1. ImageMetadata object → <Image> (Astro-optimised)
10
- * 2. "/src/assets/..." string → glob lookup → <Image> (with fallback path)
11
- * 3. "http(s)://..." string → <Image inferSize>
12
- * 4. Everything else (public path) → plain <img>
13
- */
14
- type DispatchCase = 'image-metadata' | 'internal-src-assets' | 'external-url' | 'public-path';
15
-
16
- function classifySource(src: ImageMetadata | string): DispatchCase {
17
- if (typeof src !== 'string') return 'image-metadata';
18
- if (src.startsWith('/src/assets/')) return 'internal-src-assets';
19
- if (src.startsWith('http://') || src.startsWith('https://')) return 'external-url';
20
- return 'public-path';
21
- }
22
-
23
- // Minimal ImageMetadata stub for test case 1
24
- const mockImageMetadata: ImageMetadata = {
25
- src: '/src/assets/images/test.png',
26
- width: 100,
27
- height: 100,
28
- format: 'png',
29
- };
30
-
31
- describe('<UniversalMedia> dispatch logic', () => {
32
- it('case 1: ImageMetadata object → image-metadata', () => {
33
- expect(classifySource(mockImageMetadata)).toBe('image-metadata');
34
- });
35
-
36
- it('case 2: /src/assets/ string → internal-src-assets (glob lookup path)', () => {
37
- expect(classifySource('/src/assets/images/photo.jpg')).toBe('internal-src-assets');
38
- });
39
-
40
- it('case 3: https:// URL → external-url (inferSize path)', () => {
41
- expect(classifySource('https://example.com/photo.jpg')).toBe('external-url');
42
- });
43
-
44
- it('case 4: public path /foo/bar.png → public-path (plain img)', () => {
45
- expect(classifySource('/uploads/photo.jpg')).toBe('public-path');
46
- });
47
-
48
- it('case 5: glob miss + fallbackSrc → fallback branch applies when resolvedSrc is null', () => {
49
- // Simulate glob miss: empty images map for a /src/assets/ URL
50
- const images: Record<string, () => Promise<{ default: ImageMetadata }>> = {};
51
- const src = '/src/assets/images/missing.png';
52
- const fallbackSrc = '/src/assets/images/default.png';
53
-
54
- const dispatch = classifySource(src);
55
- expect(dispatch).toBe('internal-src-assets');
56
-
57
- // Verify fallback key lookup works
58
- const hasMainImage = src in images;
59
- const hasFallback = fallbackSrc in images;
60
- expect(hasMainImage).toBe(false); // glob miss
61
- expect(hasFallback).toBe(false); // fallback also missing → plain img fallback
62
-
63
- // The component would render plain <img> when both are missing (documented in UniversalMedia)
64
- });
65
- });
1
+ import { describe, it, expect } from 'vitest';
2
+ import type { ImageMetadata } from 'astro';
3
+
4
+ /**
5
+ * Mirrors the dispatch logic inside UniversalMedia.astro.
6
+ * Tests the categorisation, not the Astro rendering (which requires a full Astro setup).
7
+ *
8
+ * The component branches on 4 cases:
9
+ * 1. ImageMetadata object → <Image> (Astro-optimised)
10
+ * 2. "/src/assets/..." string → glob lookup → <Image> (with fallback path)
11
+ * 3. "http(s)://..." string → <Image inferSize>
12
+ * 4. Everything else (public path) → plain <img>
13
+ */
14
+ type DispatchCase = 'image-metadata' | 'internal-src-assets' | 'external-url' | 'public-path';
15
+
16
+ function classifySource(src: ImageMetadata | string): DispatchCase {
17
+ if (typeof src !== 'string') return 'image-metadata';
18
+ if (src.startsWith('/src/assets/')) return 'internal-src-assets';
19
+ if (src.startsWith('http://') || src.startsWith('https://')) return 'external-url';
20
+ return 'public-path';
21
+ }
22
+
23
+ // Minimal ImageMetadata stub for test case 1
24
+ const mockImageMetadata: ImageMetadata = {
25
+ src: '/src/assets/images/test.png',
26
+ width: 100,
27
+ height: 100,
28
+ format: 'png',
29
+ };
30
+
31
+ describe('<UniversalMedia> dispatch logic', () => {
32
+ it('case 1: ImageMetadata object → image-metadata', () => {
33
+ expect(classifySource(mockImageMetadata)).toBe('image-metadata');
34
+ });
35
+
36
+ it('case 2: /src/assets/ string → internal-src-assets (glob lookup path)', () => {
37
+ expect(classifySource('/src/assets/images/photo.jpg')).toBe('internal-src-assets');
38
+ });
39
+
40
+ it('case 3: https:// URL → external-url (inferSize path)', () => {
41
+ expect(classifySource('https://example.com/photo.jpg')).toBe('external-url');
42
+ });
43
+
44
+ it('case 4: public path /foo/bar.png → public-path (plain img)', () => {
45
+ expect(classifySource('/uploads/photo.jpg')).toBe('public-path');
46
+ });
47
+
48
+ it('case 5: glob miss + fallbackSrc → fallback branch applies when resolvedSrc is null', () => {
49
+ // Simulate glob miss: empty images map for a /src/assets/ URL
50
+ const images: Record<string, () => Promise<{ default: ImageMetadata }>> = {};
51
+ const src = '/src/assets/images/missing.png';
52
+ const fallbackSrc = '/src/assets/images/default.png';
53
+
54
+ const dispatch = classifySource(src);
55
+ expect(dispatch).toBe('internal-src-assets');
56
+
57
+ // Verify fallback key lookup works
58
+ const hasMainImage = src in images;
59
+ const hasFallback = fallbackSrc in images;
60
+ expect(hasMainImage).toBe(false); // glob miss
61
+ expect(hasFallback).toBe(false); // fallback also missing → plain img fallback
62
+
63
+ // The component would render plain <img> when both are missing (documented in UniversalMedia)
64
+ });
65
+ });
@@ -142,4 +142,4 @@ describe('jsonLd.product', () => {
142
142
  image: 'https://example.com/rk.jpg',
143
143
  });
144
144
  });
145
- });
145
+ });
@@ -3,4 +3,4 @@ export * from './implements.js';
3
3
  export * from './props.js';
4
4
  export * from './publish.js';
5
5
  export * from './types.js';
6
- export * from './jsonld.js';
6
+ export * from './jsonld.js';
@@ -157,4 +157,4 @@ export const jsonLd = {
157
157
  url: absolute(ctx.url, ctx.siteUrl),
158
158
  });
159
159
  },
160
- };
160
+ };
@@ -1,54 +1,54 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { createI18n } from '../factory.js';
3
-
4
- const i18n = createI18n({ locales: ['de', 'en'] as const, defaultLocale: 'de', baseUrl: 'https://dev.ismaili.de' });
5
-
6
- describe('createI18n', () => {
7
- it('returns object with expected function keys', () => {
8
- expect(typeof i18n.localizedHref).toBe('function');
9
- expect(typeof i18n.getLocaleFromPath).toBe('function');
10
- expect(typeof i18n.getAlternateLinks).toBe('function');
11
- expect(typeof i18n.getCanonicalUrl).toBe('function');
12
- });
13
- it('returns object with format sub-object', () => {
14
- expect(typeof i18n.format).toBe('object');
15
- expect(typeof i18n.format.date).toBe('function');
16
- expect(typeof i18n.format.number).toBe('function');
17
- expect(typeof i18n.format.currency).toBe('function');
18
- expect(typeof i18n.format.relativeTime).toBe('function');
19
- expect(typeof i18n.format.list).toBe('function');
20
- });
21
- it('exposes locales and defaultLocale', () => {
22
- expect(i18n.locales).toEqual(['de', 'en']);
23
- expect(i18n.defaultLocale).toBe('de');
24
- });
25
- it('localizedHref produces correct output for non-default', () => {
26
- expect(i18n.localizedHref('/about', 'en')).toBe('/en/about');
27
- });
28
- it('localizedHref produces correct output for default', () => {
29
- expect(i18n.localizedHref('/about', 'de')).toBe('/about');
30
- });
31
- it('getAlternateLinks returns 3 entries for 2 locales', () => {
32
- expect(i18n.getAlternateLinks('/about')).toHaveLength(3);
33
- });
34
- it('getCanonicalUrl for default locale', () => {
35
- expect(i18n.getCanonicalUrl('/about', 'de')).toBe('https://dev.ismaili.de/about/');
36
- });
37
- it('getCanonicalUrl for non-default locale', () => {
38
- expect(i18n.getCanonicalUrl('/about', 'en')).toBe('https://dev.ismaili.de/en/about/');
39
- });
40
- it('format.number works', () => {
41
- expect(i18n.format.number('de', 1234.5)).toBe('1.234,5');
42
- });
43
- it('format.currency returns formatted string with symbol', () => {
44
- const result = i18n.format.currency('de', 9.99, 'EUR');
45
- expect(result).toContain('9');
46
- expect(result).toContain('€');
47
- });
48
- it('getLocaleFromPath detects en', () => {
49
- expect(i18n.getLocaleFromPath('/en/about')).toBe('en');
50
- });
51
- it('getLocaleFromPath falls back to default', () => {
52
- expect(i18n.getLocaleFromPath('/kontakt')).toBe('de');
53
- });
54
- });
1
+ import { describe, it, expect } from 'vitest';
2
+ import { createI18n } from '../factory.js';
3
+
4
+ const i18n = createI18n({ locales: ['de', 'en'] as const, defaultLocale: 'de', baseUrl: 'https://dev.ismaili.de' });
5
+
6
+ describe('createI18n', () => {
7
+ it('returns object with expected function keys', () => {
8
+ expect(typeof i18n.localizedHref).toBe('function');
9
+ expect(typeof i18n.getLocaleFromPath).toBe('function');
10
+ expect(typeof i18n.getAlternateLinks).toBe('function');
11
+ expect(typeof i18n.getCanonicalUrl).toBe('function');
12
+ });
13
+ it('returns object with format sub-object', () => {
14
+ expect(typeof i18n.format).toBe('object');
15
+ expect(typeof i18n.format.date).toBe('function');
16
+ expect(typeof i18n.format.number).toBe('function');
17
+ expect(typeof i18n.format.currency).toBe('function');
18
+ expect(typeof i18n.format.relativeTime).toBe('function');
19
+ expect(typeof i18n.format.list).toBe('function');
20
+ });
21
+ it('exposes locales and defaultLocale', () => {
22
+ expect(i18n.locales).toEqual(['de', 'en']);
23
+ expect(i18n.defaultLocale).toBe('de');
24
+ });
25
+ it('localizedHref produces correct output for non-default', () => {
26
+ expect(i18n.localizedHref('/about', 'en')).toBe('/en/about');
27
+ });
28
+ it('localizedHref produces correct output for default', () => {
29
+ expect(i18n.localizedHref('/about', 'de')).toBe('/about');
30
+ });
31
+ it('getAlternateLinks returns 3 entries for 2 locales', () => {
32
+ expect(i18n.getAlternateLinks('/about')).toHaveLength(3);
33
+ });
34
+ it('getCanonicalUrl for default locale', () => {
35
+ expect(i18n.getCanonicalUrl('/about', 'de')).toBe('https://dev.ismaili.de/about/');
36
+ });
37
+ it('getCanonicalUrl for non-default locale', () => {
38
+ expect(i18n.getCanonicalUrl('/about', 'en')).toBe('https://dev.ismaili.de/en/about/');
39
+ });
40
+ it('format.number works', () => {
41
+ expect(i18n.format.number('de', 1234.5)).toBe('1.234,5');
42
+ });
43
+ it('format.currency returns formatted string with symbol', () => {
44
+ const result = i18n.format.currency('de', 9.99, 'EUR');
45
+ expect(result).toContain('9');
46
+ expect(result).toContain('€');
47
+ });
48
+ it('getLocaleFromPath detects en', () => {
49
+ expect(i18n.getLocaleFromPath('/en/about')).toBe('en');
50
+ });
51
+ it('getLocaleFromPath falls back to default', () => {
52
+ expect(i18n.getLocaleFromPath('/kontakt')).toBe('de');
53
+ });
54
+ });