@wocart/theme 2.2.0 → 3.0.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.
- package/CHANGELOG.md +24 -0
- package/README.md +24 -1077
- package/dist/image-service.d.ts +16 -19
- package/dist/image-service.js +20 -23
- package/dist/manifest.d.ts +2 -2
- package/dist/manifest.js +2 -2
- package/dist/patterns.d.ts +1 -1
- package/dist/patterns.js +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
package/dist/image-service.d.ts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An Astro image service for Wocart storefronts: every `<Image>` and
|
|
3
|
-
* `getImage()` of a
|
|
4
|
-
* on
|
|
3
|
+
* `getImage()` of a store image is resized by the store's own media delivery
|
|
4
|
+
* — ImageKit or Cloudflare — so a storefront on any host gets the same URLs
|
|
5
|
+
* and no second image bill. Any other image (another host, a file imported
|
|
6
|
+
* into the theme) is served as it is, and so is every image of a `direct`
|
|
7
|
+
* delivery, which does not resize.
|
|
5
8
|
*
|
|
6
|
-
* The
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* imported into the theme — is served as it is. Without a media domain (local
|
|
10
|
-
* development, a store without one) every image passes through unchanged.
|
|
11
|
-
*
|
|
12
|
-
* The domain is read per call, not at build: one theme build serves every
|
|
13
|
-
* store. Bind it once, in the theme, to wherever the store's media domain
|
|
14
|
-
* lives:
|
|
9
|
+
* The delivery is the store config's `media`, read per image, not at build:
|
|
10
|
+
* one theme build serves every store. Bind it once, in the theme, to where
|
|
11
|
+
* the theme keeps the store's config:
|
|
15
12
|
*
|
|
16
13
|
* ```ts
|
|
17
14
|
* // src/image-service.ts
|
|
18
|
-
* import { MEDIA_DOMAIN } from "astro:env/server";
|
|
19
15
|
* import { mediaImageService } from "@wocart/theme/image-service";
|
|
20
|
-
*
|
|
16
|
+
* import { storeMedia } from "./store-media";
|
|
17
|
+
* export default mediaImageService(storeMedia);
|
|
21
18
|
* ```
|
|
22
19
|
*
|
|
23
20
|
* ```js
|
|
@@ -27,13 +24,13 @@
|
|
|
27
24
|
* ```
|
|
28
25
|
*/
|
|
29
26
|
import type { ExternalImageService, ImageTransform } from "astro";
|
|
30
|
-
import { type MediaImageParams } from "@wocart/storefront";
|
|
31
|
-
/** The
|
|
27
|
+
import { type MediaDelivery, type MediaImageParams } from "@wocart/storefront";
|
|
28
|
+
/** The resizing options an Astro image transform asks for. */
|
|
32
29
|
export declare function mediaImageParams(options: ImageTransform): MediaImageParams;
|
|
33
30
|
/**
|
|
34
|
-
* The image service, bound to the store's media
|
|
31
|
+
* The image service, bound to the store's media delivery.
|
|
35
32
|
*
|
|
36
|
-
* @param
|
|
37
|
-
* store's
|
|
33
|
+
* @param delivery - Read on every image (e.g. `() => config.media`): the
|
|
34
|
+
* store's `MediaDelivery`, or `null` / `undefined` to pass every image through.
|
|
38
35
|
*/
|
|
39
|
-
export declare function mediaImageService(
|
|
36
|
+
export declare function mediaImageService(delivery: () => MediaDelivery | null | undefined | Promise<MediaDelivery | null | undefined>): ExternalImageService;
|
package/dist/image-service.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An Astro image service for Wocart storefronts: every `<Image>` and
|
|
3
|
-
* `getImage()` of a
|
|
4
|
-
* on
|
|
3
|
+
* `getImage()` of a store image is resized by the store's own media delivery
|
|
4
|
+
* — ImageKit or Cloudflare — so a storefront on any host gets the same URLs
|
|
5
|
+
* and no second image bill. Any other image (another host, a file imported
|
|
6
|
+
* into the theme) is served as it is, and so is every image of a `direct`
|
|
7
|
+
* delivery, which does not resize.
|
|
5
8
|
*
|
|
6
|
-
* The
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* imported into the theme — is served as it is. Without a media domain (local
|
|
10
|
-
* development, a store without one) every image passes through unchanged.
|
|
11
|
-
*
|
|
12
|
-
* The domain is read per call, not at build: one theme build serves every
|
|
13
|
-
* store. Bind it once, in the theme, to wherever the store's media domain
|
|
14
|
-
* lives:
|
|
9
|
+
* The delivery is the store config's `media`, read per image, not at build:
|
|
10
|
+
* one theme build serves every store. Bind it once, in the theme, to where
|
|
11
|
+
* the theme keeps the store's config:
|
|
15
12
|
*
|
|
16
13
|
* ```ts
|
|
17
14
|
* // src/image-service.ts
|
|
18
|
-
* import { MEDIA_DOMAIN } from "astro:env/server";
|
|
19
15
|
* import { mediaImageService } from "@wocart/theme/image-service";
|
|
20
|
-
*
|
|
16
|
+
* import { storeMedia } from "./store-media";
|
|
17
|
+
* export default mediaImageService(storeMedia);
|
|
21
18
|
* ```
|
|
22
19
|
*
|
|
23
20
|
* ```js
|
|
@@ -28,8 +25,8 @@
|
|
|
28
25
|
*/
|
|
29
26
|
import { baseService } from "astro/assets";
|
|
30
27
|
import { mediaImageUrl } from "@wocart/storefront";
|
|
31
|
-
/** Astro's `fit` (CSS object-fit) in
|
|
32
|
-
const
|
|
28
|
+
/** Astro's `fit` (CSS object-fit) in the words `mediaImageUrl` takes; a value it also knows passes as it is. */
|
|
29
|
+
const FIT = {
|
|
33
30
|
cover: "cover",
|
|
34
31
|
contain: "contain",
|
|
35
32
|
fill: "squeeze",
|
|
@@ -38,7 +35,7 @@ const CLOUDFLARE_FIT = {
|
|
|
38
35
|
pad: "pad",
|
|
39
36
|
squeeze: "squeeze",
|
|
40
37
|
};
|
|
41
|
-
/** The
|
|
38
|
+
/** The resizing options an Astro image transform asks for. */
|
|
42
39
|
export function mediaImageParams(options) {
|
|
43
40
|
const params = {};
|
|
44
41
|
if (options.width)
|
|
@@ -49,25 +46,25 @@ export function mediaImageParams(options) {
|
|
|
49
46
|
params.format = options.format;
|
|
50
47
|
if (typeof options.quality === "number")
|
|
51
48
|
params.quality = options.quality;
|
|
52
|
-
const fit = options.fit ?
|
|
49
|
+
const fit = options.fit ? FIT[options.fit] : undefined;
|
|
53
50
|
if (fit)
|
|
54
51
|
params.fit = fit;
|
|
55
52
|
return params;
|
|
56
53
|
}
|
|
57
54
|
/**
|
|
58
|
-
* The image service, bound to the store's media
|
|
55
|
+
* The image service, bound to the store's media delivery.
|
|
59
56
|
*
|
|
60
|
-
* @param
|
|
61
|
-
* store's
|
|
57
|
+
* @param delivery - Read on every image (e.g. `() => config.media`): the
|
|
58
|
+
* store's `MediaDelivery`, or `null` / `undefined` to pass every image through.
|
|
62
59
|
*/
|
|
63
|
-
export function mediaImageService(
|
|
60
|
+
export function mediaImageService(delivery) {
|
|
64
61
|
return {
|
|
65
62
|
...baseService,
|
|
66
|
-
getURL(options) {
|
|
63
|
+
async getURL(options) {
|
|
67
64
|
const src = options.src;
|
|
68
65
|
if (typeof src !== "string")
|
|
69
66
|
return src.src;
|
|
70
|
-
return mediaImageUrl(src, mediaImageParams(options),
|
|
67
|
+
return mediaImageUrl(src, mediaImageParams(options), await delivery()) ?? src;
|
|
71
68
|
},
|
|
72
69
|
};
|
|
73
70
|
}
|
package/dist/manifest.d.ts
CHANGED
|
@@ -21,8 +21,8 @@ export declare const THEME_MANIFEST_PATH = "/wocart-theme.json";
|
|
|
21
21
|
/** Derive the data-only manifest from a theme. `component` and `load` are dropped. */
|
|
22
22
|
export declare function themeManifest(theme: ThemeDefinition): ThemeManifest;
|
|
23
23
|
/**
|
|
24
|
-
* The manifest's structural shape. Unknown keys are stripped
|
|
25
|
-
*
|
|
24
|
+
* The manifest's structural shape. Unknown keys are stripped, so a manifest
|
|
25
|
+
* from a newer theme still reads; absent `fields`/`slots` normalize to `[]`.
|
|
26
26
|
* Rules that span fields are not here — `validateThemeManifest` applies them.
|
|
27
27
|
*/
|
|
28
28
|
export declare const ThemeManifestSchema: z.ZodObject<{
|
package/dist/manifest.js
CHANGED
|
@@ -214,8 +214,8 @@ const ComponentSpecSchema = z.object({
|
|
|
214
214
|
.default([]),
|
|
215
215
|
});
|
|
216
216
|
/**
|
|
217
|
-
* The manifest's structural shape. Unknown keys are stripped
|
|
218
|
-
*
|
|
217
|
+
* The manifest's structural shape. Unknown keys are stripped, so a manifest
|
|
218
|
+
* from a newer theme still reads; absent `fields`/`slots` normalize to `[]`.
|
|
219
219
|
* Rules that span fields are not here — `validateThemeManifest` applies them.
|
|
220
220
|
*/
|
|
221
221
|
export const ThemeManifestSchema = z.object({
|
package/dist/patterns.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const TYPE_KEY_PATTERN: RegExp;
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const SURFACE_KEY_PATTERN: RegExp;
|
|
19
19
|
/** The platform page types a surface can render (`SurfacePageType`), mirrored from the storefront's page types. */
|
|
20
|
-
export declare const PAGE_TYPES: readonly ["home", "catalog", "category", "collection", "product", "page", "landing", "checkout", "thankYou"];
|
|
20
|
+
export declare const PAGE_TYPES: readonly ["home", "catalog", "category", "collection", "product", "page", "landing", "checkout", "thankYou", "trackOrder"];
|
|
21
21
|
/** A `color` field's value: a hex color, `#rgb` or `#rrggbb`. */
|
|
22
22
|
export declare const COLOR_PATTERN: RegExp;
|
|
23
23
|
/**
|
package/dist/patterns.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -749,7 +749,7 @@ export interface AreaSpec {
|
|
|
749
749
|
* The storefront's page types — what a URL means, with the paths the platform
|
|
750
750
|
* owns. The same names as `StorefrontPageType` in `@wocart/storefront`.
|
|
751
751
|
*/
|
|
752
|
-
export type SurfacePageType = "home" | "catalog" | "category" | "collection" | "product" | "page" | "landing" | "checkout" | "thankYou";
|
|
752
|
+
export type SurfacePageType = "home" | "catalog" | "category" | "collection" | "product" | "page" | "landing" | "checkout" | "thankYou" | "trackOrder";
|
|
753
753
|
/**
|
|
754
754
|
* One component as data: a `ComponentDefinition` minus its runtime-only
|
|
755
755
|
* implementation. `component` (the live component reference) and `load` (the
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wocart/theme",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "The Wocart theme contract: code-owned component definitions, JSON page documents, validation and resolution, and a reference Astro renderer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wocart",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"zod": "^4.4.3"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
|
-
"@wocart/storefront": "^
|
|
85
|
+
"@wocart/storefront": "^2.0.0",
|
|
86
86
|
"astro": "^7.0.0"
|
|
87
87
|
},
|
|
88
88
|
"peerDependenciesMeta": {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
94
|
"@types/node": "^26.2.0",
|
|
95
|
-
"@wocart/storefront": "^
|
|
95
|
+
"@wocart/storefront": "^2.0.0",
|
|
96
96
|
"astro": "^7.3.2",
|
|
97
97
|
"fast-check": "^4.6.0",
|
|
98
98
|
"happy-dom": "^20.11.6",
|