@gradial/aci 0.1.29 → 0.1.30

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.
Binary file
@@ -1,3 +1,3 @@
1
- export { type Image, type ImageFallback, type ImageSource, type ImageAttrs, ImageSchema, imageAttrs, primaryImageSource, } from '../types/image.js';
1
+ export { type Image, type ImageSource, type ImageAttrs, ImageSchema, imageAttrs, primaryImageSource, } from '../types/image.js';
2
2
  export { type Video, type VideoSource, VideoSchema, VideoSourceSchema, } from '../types/video.js';
3
3
  export { type Asset, AssetSchema, isImage, isVideo, isAsset, } from '../types/media.js';
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export type { Registry, RegistryEntry, AnyComponent } from './registry.js';
5
5
  export { blockRef, blockRefArray } from './types/block-ref.js';
6
6
  export type { BlockRef, BlockRefEntry, BlockRefMeta, BlockRefUnion } from './types/block-ref.js';
7
7
  export type { ComponentContract, ComponentContractID, ComponentContractValidator, ComponentRegistry, ComponentValidationContext, ComponentValidationIssue, InferComponentProps, } from './types/component.js';
8
- export { ImageSchema, imageAttrs, primaryImageSource, type Image, type ImageFallback, type ImageSource, type ImageAttrs, type ImageSlotContract, type SlotOutput, } from './types/image.js';
8
+ export { ImageSchema, imageAttrs, primaryImageSource, type Image, type ImageSource, type ImageAttrs, type ImageSlotContract, type SlotOutput, } from './types/image.js';
9
9
  export { LinkSchema, type Link, type LinkTarget, type LinkResolverContext, resolveLink, resolveHref, assertSafeHref, normalizeLinkRel, } from './types/link.js';
10
10
  export { HeadingSchema, InlineContentSchema, RichTextValueSchema, type Heading, type InlineContent, type RichTextValue, } from './types/rich-text.js';
11
11
  export type { Config, RouteConfig, ExternalDependency, DAMConfig, } from './types/config.js';
@@ -12,10 +12,9 @@ export function Image({ image, value, ...attrs }) {
12
12
  assetId: '',
13
13
  versionId: '',
14
14
  alt: '',
15
- fallback: { src: '', width: 0, height: 0 },
16
15
  sources: [],
17
16
  };
18
- if (!resolved.fallback.src) {
17
+ if (!resolved.sources[0]?.src) {
19
18
  return createElement('img', {
20
19
  src: '',
21
20
  alt: resolved.alt,
@@ -1,17 +1,13 @@
1
1
  import { z } from 'zod';
2
- export interface ImageFallback {
3
- /** Derivative URL for the base <img>. */
2
+ export interface ImageSource {
3
+ /** Primary derivative URL for this rendition candidate. */
4
4
  src: string;
5
5
  /** Intrinsic width in pixels (0 when the format carries none, e.g. SVG). */
6
- width: number;
6
+ width?: number;
7
7
  /** Intrinsic height in pixels (0 when the format carries none). */
8
- height: number;
9
- /** MIME type hint, e.g. image/webp. */
10
- type?: string;
11
- }
12
- export interface ImageSource {
13
- /** srcset value — a single URL or a width-descriptor candidate list. */
14
- srcset: string;
8
+ height?: number;
9
+ /** Optional width-descriptor rendition candidates. */
10
+ srcset?: string;
15
11
  /** sizes attribute from the slot contract. */
16
12
  sizes?: string;
17
13
  /** Media query scoping this source (art direction). */
@@ -28,8 +24,6 @@ export interface Image {
28
24
  versionId: string;
29
25
  /** Accessible description of the image content. */
30
26
  alt: string;
31
- /** Base <img> rendition. */
32
- fallback: ImageFallback;
33
27
  /** <source> candidates produced for the asset slot. */
34
28
  sources: ImageSource[];
35
29
  }
@@ -43,14 +37,11 @@ export interface SlotOutput {
43
37
  widths: number[];
44
38
  media?: string;
45
39
  }
46
- export declare const ImageFallbackSchema: z.ZodObject<{
47
- src: z.ZodString;
48
- width: z.ZodNumber;
49
- height: z.ZodNumber;
50
- type: z.ZodOptional<z.ZodString>;
51
- }, z.core.$strip>;
52
40
  export declare const ImageSourceSchema: z.ZodObject<{
53
- srcset: z.ZodString;
41
+ src: z.ZodString;
42
+ srcset: z.ZodOptional<z.ZodString>;
43
+ width: z.ZodOptional<z.ZodNumber>;
44
+ height: z.ZodOptional<z.ZodNumber>;
54
45
  sizes: z.ZodOptional<z.ZodString>;
55
46
  media: z.ZodOptional<z.ZodString>;
56
47
  type: z.ZodString;
@@ -60,14 +51,11 @@ export declare const ImageSchema: z.ZodObject<{
60
51
  assetId: z.ZodString;
61
52
  versionId: z.ZodString;
62
53
  alt: z.ZodString;
63
- fallback: z.ZodObject<{
64
- src: z.ZodString;
65
- width: z.ZodNumber;
66
- height: z.ZodNumber;
67
- type: z.ZodOptional<z.ZodString>;
68
- }, z.core.$strip>;
69
54
  sources: z.ZodArray<z.ZodObject<{
70
- srcset: z.ZodString;
55
+ src: z.ZodString;
56
+ srcset: z.ZodOptional<z.ZodString>;
57
+ width: z.ZodOptional<z.ZodNumber>;
58
+ height: z.ZodOptional<z.ZodNumber>;
71
59
  sizes: z.ZodOptional<z.ZodString>;
72
60
  media: z.ZodOptional<z.ZodString>;
73
61
  type: z.ZodString;
@@ -75,9 +63,9 @@ export declare const ImageSchema: z.ZodObject<{
75
63
  }, z.core.$strip>;
76
64
  export type ImageAttrs = Record<string, unknown>;
77
65
  /**
78
- * The primary rendition of an image — its fallback (base <img>) entry.
66
+ * The primary rendition of an image — its first source entry.
79
67
  */
80
- export declare function primaryImageSource(image: Image): ImageFallback;
68
+ export declare function primaryImageSource(image: Image): ImageSource;
81
69
  /**
82
70
  * Computes the full set of <img> attributes for an Image.
83
71
  *
@@ -2,14 +2,11 @@ import { z } from 'zod';
2
2
  // ---------------------------------------------------------------------------
3
3
  // Zod schema
4
4
  // ---------------------------------------------------------------------------
5
- export const ImageFallbackSchema = z.object({
6
- src: z.string().min(1),
7
- width: z.number().int().nonnegative(),
8
- height: z.number().int().nonnegative(),
9
- type: z.string().min(1).optional(),
10
- });
11
5
  export const ImageSourceSchema = z.object({
12
- srcset: z.string().min(1),
6
+ src: z.string().min(1),
7
+ srcset: z.string().min(1).optional(),
8
+ width: z.number().int().nonnegative().optional(),
9
+ height: z.number().int().nonnegative().optional(),
13
10
  sizes: z.string().min(1).optional(),
14
11
  media: z.string().min(1).optional(),
15
12
  type: z.string().min(1),
@@ -19,14 +16,13 @@ export const ImageSchema = z.object({
19
16
  assetId: z.string().min(1),
20
17
  versionId: z.string().min(1),
21
18
  alt: z.string(),
22
- fallback: ImageFallbackSchema,
23
19
  sources: z.array(ImageSourceSchema).min(1),
24
20
  });
25
21
  /**
26
- * The primary rendition of an image — its fallback (base <img>) entry.
22
+ * The primary rendition of an image — its first source entry.
27
23
  */
28
24
  export function primaryImageSource(image) {
29
- return image.fallback;
25
+ return image.sources[0];
30
26
  }
31
27
  /**
32
28
  * Computes the full set of <img> attributes for an Image.
@@ -38,12 +34,13 @@ export function primaryImageSource(image) {
38
34
  * first unscoped source only.
39
35
  */
40
36
  export function imageAttrs(image, overrides = {}) {
41
- const unscoped = image.sources.find((s) => !s.media);
37
+ const primary = image.sources[0];
38
+ const unscoped = image.sources.find((s) => !s.media) ?? primary;
42
39
  return {
43
- src: image.fallback.src,
40
+ src: primary.src,
44
41
  alt: image.alt,
45
- width: image.fallback.width > 0 ? image.fallback.width : undefined,
46
- height: image.fallback.height > 0 ? image.fallback.height : undefined,
42
+ width: primary.width && primary.width > 0 ? primary.width : undefined,
43
+ height: primary.height && primary.height > 0 ? primary.height : undefined,
47
44
  srcSet: unscoped?.srcset || undefined,
48
45
  sizes: unscoped?.sizes || undefined,
49
46
  loading: 'lazy',
@@ -9,14 +9,11 @@ export declare const AssetSchema: z.ZodUnion<readonly [z.ZodObject<{
9
9
  assetId: z.ZodString;
10
10
  versionId: z.ZodString;
11
11
  alt: z.ZodString;
12
- fallback: z.ZodObject<{
13
- src: z.ZodString;
14
- width: z.ZodNumber;
15
- height: z.ZodNumber;
16
- type: z.ZodOptional<z.ZodString>;
17
- }, z.core.$strip>;
18
12
  sources: z.ZodArray<z.ZodObject<{
19
- srcset: z.ZodString;
13
+ src: z.ZodString;
14
+ srcset: z.ZodOptional<z.ZodString>;
15
+ width: z.ZodOptional<z.ZodNumber>;
16
+ height: z.ZodOptional<z.ZodNumber>;
20
17
  sizes: z.ZodOptional<z.ZodString>;
21
18
  media: z.ZodOptional<z.ZodString>;
22
19
  type: z.ZodString;
@@ -35,14 +32,11 @@ export declare const AssetSchema: z.ZodUnion<readonly [z.ZodObject<{
35
32
  assetId: z.ZodString;
36
33
  versionId: z.ZodString;
37
34
  alt: z.ZodString;
38
- fallback: z.ZodObject<{
39
- src: z.ZodString;
40
- width: z.ZodNumber;
41
- height: z.ZodNumber;
42
- type: z.ZodOptional<z.ZodString>;
43
- }, z.core.$strip>;
44
35
  sources: z.ZodArray<z.ZodObject<{
45
- srcset: z.ZodString;
36
+ src: z.ZodString;
37
+ srcset: z.ZodOptional<z.ZodString>;
38
+ width: z.ZodOptional<z.ZodNumber>;
39
+ height: z.ZodOptional<z.ZodNumber>;
46
40
  sizes: z.ZodOptional<z.ZodString>;
47
41
  media: z.ZodOptional<z.ZodString>;
48
42
  type: z.ZodString;
@@ -52,14 +52,11 @@ export declare const VideoSchema: z.ZodObject<{
52
52
  assetId: z.ZodString;
53
53
  versionId: z.ZodString;
54
54
  alt: z.ZodString;
55
- fallback: z.ZodObject<{
56
- src: z.ZodString;
57
- width: z.ZodNumber;
58
- height: z.ZodNumber;
59
- type: z.ZodOptional<z.ZodString>;
60
- }, z.core.$strip>;
61
55
  sources: z.ZodArray<z.ZodObject<{
62
- srcset: z.ZodString;
56
+ src: z.ZodString;
57
+ srcset: z.ZodOptional<z.ZodString>;
58
+ width: z.ZodOptional<z.ZodNumber>;
59
+ height: z.ZodOptional<z.ZodNumber>;
63
60
  sizes: z.ZodOptional<z.ZodString>;
64
61
  media: z.ZodOptional<z.ZodString>;
65
62
  type: z.ZodString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradial/aci",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -85,13 +85,6 @@
85
85
  "default": "./dist/astro/index.js"
86
86
  }
87
87
  },
88
- "scripts": {
89
- "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
90
- "build:cli": "cd ../.. && ./scripts/build-cli.sh",
91
- "generate-starters": "cd ../.. && tsx scripts/generate-starters.ts",
92
- "compile-registry": "tsx src/cli/compile-registry.mjs",
93
- "prepack": "npm run generate-starters && npm run build && npm run build:cli"
94
- },
95
88
  "dependencies": {
96
89
  "markdown-it": "^14.1.0",
97
90
  "sanitize-html": "^2.13.1",
@@ -127,5 +120,11 @@
127
120
  "tsx": "^4.20.0",
128
121
  "typescript": "^5.9.3",
129
122
  "zod": "^4.0.0"
123
+ },
124
+ "scripts": {
125
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
126
+ "build:cli": "cd ../.. && ./scripts/build-cli.sh",
127
+ "generate-starters": "cd ../.. && tsx scripts/generate-starters.ts",
128
+ "compile-registry": "tsx src/cli/compile-registry.mjs"
130
129
  }
131
- }
130
+ }
File without changes
@@ -1,27 +1,21 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  // ---------------------------------------------------------------------------
4
- // Image fallback + source variants
4
+ // Image source variants
5
5
  //
6
- // The fallback is the base <img> rendition (largest derivative); each source
7
- // entry is one <source> element candidate with a ready-made srcset scoped by
8
- // the optional media/sizes of the slot output that produced it.
6
+ // Each source provides a primary src and may include a ready-made srcset
7
+ // scoped by the optional media/sizes of the slot output that produced it.
9
8
  // ---------------------------------------------------------------------------
10
9
 
11
- export interface ImageFallback {
12
- /** Derivative URL for the base <img>. */
10
+ export interface ImageSource {
11
+ /** Primary derivative URL for this rendition candidate. */
13
12
  src: string;
14
13
  /** Intrinsic width in pixels (0 when the format carries none, e.g. SVG). */
15
- width: number;
14
+ width?: number;
16
15
  /** Intrinsic height in pixels (0 when the format carries none). */
17
- height: number;
18
- /** MIME type hint, e.g. image/webp. */
19
- type?: string;
20
- }
21
-
22
- export interface ImageSource {
23
- /** srcset value — a single URL or a width-descriptor candidate list. */
24
- srcset: string;
16
+ height?: number;
17
+ /** Optional width-descriptor rendition candidates. */
18
+ srcset?: string;
25
19
  /** sizes attribute from the slot contract. */
26
20
  sizes?: string;
27
21
  /** Media query scoping this source (art direction). */
@@ -47,8 +41,6 @@ export interface Image {
47
41
  versionId: string;
48
42
  /** Accessible description of the image content. */
49
43
  alt: string;
50
- /** Base <img> rendition. */
51
- fallback: ImageFallback;
52
44
  /** <source> candidates produced for the asset slot. */
53
45
  sources: ImageSource[];
54
46
  }
@@ -73,15 +65,11 @@ export interface SlotOutput {
73
65
  // Zod schema
74
66
  // ---------------------------------------------------------------------------
75
67
 
76
- export const ImageFallbackSchema = z.object({
77
- src: z.string().min(1),
78
- width: z.number().int().nonnegative(),
79
- height: z.number().int().nonnegative(),
80
- type: z.string().min(1).optional(),
81
- });
82
-
83
68
  export const ImageSourceSchema = z.object({
84
- srcset: z.string().min(1),
69
+ src: z.string().min(1),
70
+ srcset: z.string().min(1).optional(),
71
+ width: z.number().int().nonnegative().optional(),
72
+ height: z.number().int().nonnegative().optional(),
85
73
  sizes: z.string().min(1).optional(),
86
74
  media: z.string().min(1).optional(),
87
75
  type: z.string().min(1),
@@ -92,7 +80,6 @@ export const ImageSchema = z.object({
92
80
  assetId: z.string().min(1),
93
81
  versionId: z.string().min(1),
94
82
  alt: z.string(),
95
- fallback: ImageFallbackSchema,
96
83
  sources: z.array(ImageSourceSchema).min(1),
97
84
  });
98
85
 
@@ -103,10 +90,10 @@ export const ImageSchema = z.object({
103
90
  export type ImageAttrs = Record<string, unknown>;
104
91
 
105
92
  /**
106
- * The primary rendition of an image — its fallback (base <img>) entry.
93
+ * The primary rendition of an image — its first source entry.
107
94
  */
108
- export function primaryImageSource(image: Image): ImageFallback {
109
- return image.fallback;
95
+ export function primaryImageSource(image: Image): ImageSource {
96
+ return image.sources[0];
110
97
  }
111
98
 
112
99
  /**
@@ -119,13 +106,14 @@ export function primaryImageSource(image: Image): ImageFallback {
119
106
  * first unscoped source only.
120
107
  */
121
108
  export function imageAttrs(image: Image, overrides: ImageAttrs = {}): ImageAttrs {
122
- const unscoped = image.sources.find((s) => !s.media);
109
+ const primary = image.sources[0];
110
+ const unscoped = image.sources.find((s) => !s.media) ?? primary;
123
111
 
124
112
  return {
125
- src: image.fallback.src,
113
+ src: primary.src,
126
114
  alt: image.alt,
127
- width: image.fallback.width > 0 ? image.fallback.width : undefined,
128
- height: image.fallback.height > 0 ? image.fallback.height : undefined,
115
+ width: primary.width && primary.width > 0 ? primary.width : undefined,
116
+ height: primary.height && primary.height > 0 ? primary.height : undefined,
129
117
  srcSet: unscoped?.srcset || undefined,
130
118
  sizes: unscoped?.sizes || undefined,
131
119
  loading: 'lazy',
@@ -27,9 +27,8 @@ export const sectionStoryFixtures: SectionStoryFixture[] = [
27
27
  assetId: 'fixture_seattle',
28
28
  versionId: 'v0001',
29
29
  alt: 'Seattle skyline at dusk',
30
- fallback: { src: '/assets/seattle.avif', width: 1920, height: 1280, type: 'image/avif' },
31
30
  sources: [
32
- { srcset: '/assets/seattle.avif', sizes: '100vw', type: 'image/avif' }
31
+ { src: '/assets/seattle.avif', width: 1920, height: 1280, sizes: '100vw', type: 'image/avif' }
33
32
  ]
34
33
  }
35
34
  }