@webiny/website-builder-sdk 6.4.11 → 6.6.0-alpha.1
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/ContentSdk.d.ts +13 -0
- package/ContentSdk.js +25 -0
- package/ContentSdk.js.map +1 -1
- package/ElementFactory.js +3 -1
- package/ElementFactory.js.map +1 -1
- package/asset/deliveryUrl.d.ts +41 -0
- package/asset/deliveryUrl.js +34 -0
- package/asset/deliveryUrl.js.map +1 -0
- package/asset/deliveryUrl.test.d.ts +1 -0
- package/asset/deliveryUrl.test.js +127 -0
- package/asset/deliveryUrl.test.js.map +1 -0
- package/asset/geometry.d.ts +7 -0
- package/asset/geometry.js +10 -0
- package/asset/geometry.js.map +1 -0
- package/asset/imageSrcSet.d.ts +63 -0
- package/asset/imageSrcSet.js +98 -0
- package/asset/imageSrcSet.js.map +1 -0
- package/asset/imageSrcSet.test.d.ts +1 -0
- package/asset/imageSrcSet.test.js +103 -0
- package/asset/imageSrcSet.test.js.map +1 -0
- package/asset/index.d.ts +5 -0
- package/asset/index.js +5 -0
- package/asset/normalize.d.ts +24 -0
- package/asset/normalize.js +102 -0
- package/asset/normalize.js.map +1 -0
- package/asset/normalize.test.d.ts +1 -0
- package/asset/normalize.test.js +256 -0
- package/asset/normalize.test.js.map +1 -0
- package/asset/types.d.ts +2 -0
- package/asset/types.js +0 -0
- package/createComponent.d.ts +5 -0
- package/createComponent.js +32 -0
- package/createComponent.js.map +1 -0
- package/dataProviders/ApiClient.d.ts +3 -1
- package/dataProviders/ApiClient.js +4 -2
- package/dataProviders/ApiClient.js.map +1 -1
- package/dataProviders/DefaultDataProvider.d.ts +4 -0
- package/dataProviders/DefaultDataProvider.js +35 -0
- package/dataProviders/DefaultDataProvider.js.map +1 -1
- package/dataProviders/GET_EXPERIMENT_PAUSED.d.ts +1 -0
- package/dataProviders/GET_EXPERIMENT_PAUSED.js +17 -0
- package/dataProviders/GET_EXPERIMENT_PAUSED.js.map +1 -0
- package/dataProviders/GET_PAGE_EXPERIMENT.d.ts +1 -0
- package/dataProviders/GET_PAGE_EXPERIMENT.js +32 -0
- package/dataProviders/GET_PAGE_EXPERIMENT.js.map +1 -0
- package/dataProviders/GET_VARIANT_CONTENT.d.ts +1 -0
- package/dataProviders/GET_VARIANT_CONTENT.js +24 -0
- package/dataProviders/GET_VARIANT_CONTENT.js.map +1 -0
- package/dataProviders/NullDataProvider.d.ts +4 -0
- package/dataProviders/NullDataProvider.js +9 -0
- package/dataProviders/NullDataProvider.js.map +1 -1
- package/experiments/PostHogAnalyticsProvider.d.ts +31 -0
- package/experiments/PostHogAnalyticsProvider.js +28 -0
- package/experiments/PostHogAnalyticsProvider.js.map +1 -0
- package/experiments/analyticsProvider.d.ts +4 -0
- package/experiments/analyticsProvider.js +11 -0
- package/experiments/analyticsProvider.js.map +1 -0
- package/experiments/bucketing.d.ts +27 -0
- package/experiments/bucketing.js +91 -0
- package/experiments/bucketing.js.map +1 -0
- package/experiments/bucketing.test.d.ts +1 -0
- package/experiments/bucketing.test.js +183 -0
- package/experiments/bucketing.test.js.map +1 -0
- package/experiments/index.d.ts +5 -0
- package/experiments/index.js +5 -0
- package/experiments/render.d.ts +79 -0
- package/experiments/render.js +149 -0
- package/experiments/render.js.map +1 -0
- package/experiments/types.d.ts +108 -0
- package/experiments/types.js +4 -0
- package/experiments/types.js.map +1 -0
- package/image/geometry.d.ts +54 -0
- package/image/geometry.js +112 -0
- package/image/geometry.js.map +1 -0
- package/image/geometry.test.d.ts +1 -0
- package/image/geometry.test.js +190 -0
- package/image/geometry.test.js.map +1 -0
- package/image/index.d.ts +3 -0
- package/image/index.js +3 -0
- package/image/presets.d.ts +6 -0
- package/image/presets.js +20 -0
- package/image/presets.js.map +1 -0
- package/image/types.d.ts +10 -0
- package/image/types.js +0 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/package.json +7 -6
- package/types.d.ts +5 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const clamp = (value, min = 0, max = 1)=>{
|
|
2
|
+
if (Number.isNaN(value)) return min;
|
|
3
|
+
return Math.min(max, Math.max(min, value));
|
|
4
|
+
};
|
|
5
|
+
const round = (n)=>Math.round(1000 * n) / 1000;
|
|
6
|
+
const DEFAULT_CROP = {
|
|
7
|
+
top: 0,
|
|
8
|
+
left: 0,
|
|
9
|
+
bottom: 0,
|
|
10
|
+
right: 0
|
|
11
|
+
};
|
|
12
|
+
const DEFAULT_FOCAL_POINT = {
|
|
13
|
+
x: 0.5,
|
|
14
|
+
y: 0.5
|
|
15
|
+
};
|
|
16
|
+
function resolveAssetImage(override, assetDefault) {
|
|
17
|
+
return {
|
|
18
|
+
crop: override?.crop ?? assetDefault?.crop,
|
|
19
|
+
focalPoint: override?.focalPoint ?? assetDefault?.focalPoint,
|
|
20
|
+
alt: override?.alt ?? assetDefault?.alt,
|
|
21
|
+
caption: override?.caption ?? assetDefault?.caption
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function getCropRect(crop) {
|
|
25
|
+
const top = clamp(crop?.top ?? DEFAULT_CROP.top);
|
|
26
|
+
const left = clamp(crop?.left ?? DEFAULT_CROP.left);
|
|
27
|
+
const bottom = clamp(crop?.bottom ?? DEFAULT_CROP.bottom);
|
|
28
|
+
const right = clamp(crop?.right ?? DEFAULT_CROP.right);
|
|
29
|
+
const width = Math.max(0, 1 - left - right);
|
|
30
|
+
const height = Math.max(0, 1 - top - bottom);
|
|
31
|
+
return {
|
|
32
|
+
x: left,
|
|
33
|
+
y: top,
|
|
34
|
+
width,
|
|
35
|
+
height
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const resolveAspectRatio = (aspectRatio)=>{
|
|
39
|
+
if ("number" == typeof aspectRatio) return aspectRatio > 0 ? aspectRatio : 1;
|
|
40
|
+
const { width, height } = aspectRatio;
|
|
41
|
+
return width > 0 && height > 0 ? width / height : 1;
|
|
42
|
+
};
|
|
43
|
+
const getFocalCenter = (fp)=>({
|
|
44
|
+
x: clamp(fp?.x ?? DEFAULT_FOCAL_POINT.x),
|
|
45
|
+
y: clamp(fp?.y ?? DEFAULT_FOCAL_POINT.y)
|
|
46
|
+
});
|
|
47
|
+
function getVisibleRect(image, aspectRatio) {
|
|
48
|
+
const cropRect = getCropRect(image.crop);
|
|
49
|
+
if (void 0 === aspectRatio || cropRect.width <= 0 || cropRect.height <= 0) return cropRect;
|
|
50
|
+
const iw = (image.width ?? 0) > 0 ? image.width : 1;
|
|
51
|
+
const ih = (image.height ?? 0) > 0 ? image.height : 1;
|
|
52
|
+
const targetAR = resolveAspectRatio(aspectRatio);
|
|
53
|
+
const cropWpx = cropRect.width * iw;
|
|
54
|
+
const cropHpx = cropRect.height * ih;
|
|
55
|
+
const cropAR = cropWpx / cropHpx;
|
|
56
|
+
let finalWpx;
|
|
57
|
+
let finalHpx;
|
|
58
|
+
if (targetAR > cropAR) {
|
|
59
|
+
finalWpx = cropWpx;
|
|
60
|
+
finalHpx = cropWpx / targetAR;
|
|
61
|
+
} else {
|
|
62
|
+
finalHpx = cropHpx;
|
|
63
|
+
finalWpx = cropHpx * targetAR;
|
|
64
|
+
}
|
|
65
|
+
const finalW = finalWpx / iw;
|
|
66
|
+
const finalH = finalHpx / ih;
|
|
67
|
+
const center = getFocalCenter(image.focalPoint);
|
|
68
|
+
const maxX = cropRect.x + cropRect.width - finalW;
|
|
69
|
+
const maxY = cropRect.y + cropRect.height - finalH;
|
|
70
|
+
const x = clamp(center.x - finalW / 2, cropRect.x, Math.max(cropRect.x, maxX));
|
|
71
|
+
const y = clamp(center.y - finalH / 2, cropRect.y, Math.max(cropRect.y, maxY));
|
|
72
|
+
return {
|
|
73
|
+
x,
|
|
74
|
+
y,
|
|
75
|
+
width: finalW,
|
|
76
|
+
height: finalH
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function getImageRenderData(image, aspectRatio) {
|
|
80
|
+
const rect = getVisibleRect(image, aspectRatio);
|
|
81
|
+
const center = getFocalCenter(image.focalPoint);
|
|
82
|
+
const safeW = rect.width > 0 ? rect.width : 1;
|
|
83
|
+
const safeH = rect.height > 0 ? rect.height : 1;
|
|
84
|
+
const iw = image.width || 1;
|
|
85
|
+
const ih = image.height || 1;
|
|
86
|
+
const boxAspectRatio = void 0 !== aspectRatio ? resolveAspectRatio(aspectRatio) : rect.width * iw / (rect.height * ih);
|
|
87
|
+
return {
|
|
88
|
+
rect,
|
|
89
|
+
objectPosition: `${round(100 * center.x)}% ${round(100 * center.y)}%`,
|
|
90
|
+
container: {
|
|
91
|
+
position: "relative",
|
|
92
|
+
width: "100%",
|
|
93
|
+
aspectRatio: `${round(boxAspectRatio)}`,
|
|
94
|
+
overflow: "hidden"
|
|
95
|
+
},
|
|
96
|
+
image: {
|
|
97
|
+
position: "absolute",
|
|
98
|
+
width: `${round(100 / safeW)}%`,
|
|
99
|
+
height: `${round(100 / safeH)}%`,
|
|
100
|
+
left: `${round(100 * -(rect.x / safeW))}%`,
|
|
101
|
+
top: `${round(100 * -(rect.y / safeH))}%`,
|
|
102
|
+
maxWidth: "none",
|
|
103
|
+
objectFit: "cover",
|
|
104
|
+
objectPosition: `${round(100 * center.x)}% ${round(100 * center.y)}%`
|
|
105
|
+
},
|
|
106
|
+
intrinsicWidth: iw,
|
|
107
|
+
intrinsicHeight: ih
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export { getCropRect, getImageRenderData, getVisibleRect, resolveAssetImage };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image/geometry.js","sources":["../../src/image/geometry.ts"],"sourcesContent":["/**\n * Pure geometry core for crop + focal point rendering.\n *\n * This module is the single source of truth shared by:\n * - the Admin editor previews (square / 4:3 / 16:9),\n * - the Next.js render helper (`getImageProps` / `<Image>`),\n * - and any future URL-transform loader (`?rect=…`).\n *\n * Keeping the math here guarantees that what an editor previews is exactly what\n * a visitor sees. Everything is framework-agnostic and side-effect free.\n */\nimport type { AssetCrop, AssetFocalPoint, AssetImage } from \"@webiny/sdk\";\nimport type { AspectRatioInput } from \"./types.js\";\n\n/** A rectangle in normalized (0..1) coordinates of the original image. */\nexport interface NormalizedRect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * CSS needed to render an image cropped to a target aspect ratio while honoring\n * both the crop rectangle and the focal point — without any server-side processing.\n *\n * `objectPosition` is the simpler, focal-point-only path (apply to an `object-fit:\n * cover` image). `container` + `image` is the accurate path that also honors the\n * crop rectangle via an overflow-clipped wrapper.\n */\nexport interface ImageRenderData {\n rect: NormalizedRect;\n objectPosition: string;\n container: {\n position: \"relative\";\n width: \"100%\";\n aspectRatio: string;\n overflow: \"hidden\";\n };\n image: {\n position: \"absolute\";\n width: string;\n height: string;\n left: string;\n top: string;\n maxWidth: \"none\";\n objectFit: \"cover\";\n objectPosition: string;\n };\n intrinsicWidth: number;\n intrinsicHeight: number;\n}\n\nconst clamp = (value: number, min = 0, max = 1): number => {\n if (Number.isNaN(value)) {\n return min;\n }\n return Math.min(max, Math.max(min, value));\n};\n\nconst round = (n: number): number => Math.round(n * 1000) / 1000;\n\nconst DEFAULT_CROP: AssetCrop = { top: 0, left: 0, bottom: 0, right: 0 };\nconst DEFAULT_FOCAL_POINT: AssetFocalPoint = { x: 0.5, y: 0.5 };\n\nexport function resolveAssetImage(\n override?: AssetImage | null,\n assetDefault?: AssetImage | null\n): AssetImage {\n return {\n crop: override?.crop ?? assetDefault?.crop,\n focalPoint: override?.focalPoint ?? assetDefault?.focalPoint,\n alt: override?.alt ?? assetDefault?.alt,\n caption: override?.caption ?? assetDefault?.caption\n };\n}\n\nexport function getCropRect(crop?: AssetCrop | null): NormalizedRect {\n const top = clamp(crop?.top ?? DEFAULT_CROP.top);\n const left = clamp(crop?.left ?? DEFAULT_CROP.left);\n const bottom = clamp(crop?.bottom ?? DEFAULT_CROP.bottom);\n const right = clamp(crop?.right ?? DEFAULT_CROP.right);\n\n const width = Math.max(0, 1 - left - right);\n const height = Math.max(0, 1 - top - bottom);\n\n return { x: left, y: top, width, height };\n}\n\nconst resolveAspectRatio = (aspectRatio: AspectRatioInput): number => {\n if (typeof aspectRatio === \"number\") {\n return aspectRatio > 0 ? aspectRatio : 1;\n }\n const { width, height } = aspectRatio;\n return width > 0 && height > 0 ? width / height : 1;\n};\n\nconst getFocalCenter = (fp?: AssetFocalPoint | null): { x: number; y: number } => ({\n x: clamp(fp?.x ?? DEFAULT_FOCAL_POINT.x),\n y: clamp(fp?.y ?? DEFAULT_FOCAL_POINT.y)\n});\n\nexport function getVisibleRect(image: AssetImage, aspectRatio?: AspectRatioInput): NormalizedRect {\n const cropRect = getCropRect(image.crop);\n\n if (aspectRatio === undefined || cropRect.width <= 0 || cropRect.height <= 0) {\n return cropRect;\n }\n\n const iw = (image.width ?? 0) > 0 ? image.width! : 1;\n const ih = (image.height ?? 0) > 0 ? image.height! : 1;\n const targetAR = resolveAspectRatio(aspectRatio);\n\n const cropWpx = cropRect.width * iw;\n const cropHpx = cropRect.height * ih;\n const cropAR = cropWpx / cropHpx;\n\n let finalWpx: number;\n let finalHpx: number;\n if (targetAR > cropAR) {\n finalWpx = cropWpx;\n finalHpx = cropWpx / targetAR;\n } else {\n finalHpx = cropHpx;\n finalWpx = cropHpx * targetAR;\n }\n\n const finalW = finalWpx / iw;\n const finalH = finalHpx / ih;\n\n const center = getFocalCenter(image.focalPoint);\n const maxX = cropRect.x + cropRect.width - finalW;\n const maxY = cropRect.y + cropRect.height - finalH;\n const x = clamp(center.x - finalW / 2, cropRect.x, Math.max(cropRect.x, maxX));\n const y = clamp(center.y - finalH / 2, cropRect.y, Math.max(cropRect.y, maxY));\n\n return { x, y, width: finalW, height: finalH };\n}\n\nexport function getImageRenderData(\n image: AssetImage,\n aspectRatio?: AspectRatioInput\n): ImageRenderData {\n const rect = getVisibleRect(image, aspectRatio);\n const center = getFocalCenter(image.focalPoint);\n\n const safeW = rect.width > 0 ? rect.width : 1;\n const safeH = rect.height > 0 ? rect.height : 1;\n\n const iw = image.width || 1;\n const ih = image.height || 1;\n\n const boxAspectRatio =\n aspectRatio !== undefined\n ? resolveAspectRatio(aspectRatio)\n : (rect.width * iw) / (rect.height * ih);\n\n return {\n rect,\n objectPosition: `${round(center.x * 100)}% ${round(center.y * 100)}%`,\n container: {\n position: \"relative\",\n width: \"100%\",\n aspectRatio: `${round(boxAspectRatio)}`,\n overflow: \"hidden\"\n },\n image: {\n position: \"absolute\",\n width: `${round(100 / safeW)}%`,\n height: `${round(100 / safeH)}%`,\n left: `${round(-(rect.x / safeW) * 100)}%`,\n top: `${round(-(rect.y / safeH) * 100)}%`,\n maxWidth: \"none\",\n objectFit: \"cover\",\n objectPosition: `${round(center.x * 100)}% ${round(center.y * 100)}%`\n },\n intrinsicWidth: iw,\n intrinsicHeight: ih\n };\n}\n"],"names":["clamp","value","min","max","Number","Math","round","n","DEFAULT_CROP","DEFAULT_FOCAL_POINT","resolveAssetImage","override","assetDefault","getCropRect","crop","top","left","bottom","right","width","height","resolveAspectRatio","aspectRatio","getFocalCenter","fp","getVisibleRect","image","cropRect","undefined","iw","ih","targetAR","cropWpx","cropHpx","cropAR","finalWpx","finalHpx","finalW","finalH","center","maxX","maxY","x","y","getImageRenderData","rect","safeW","safeH","boxAspectRatio"],"mappings":"AAqDA,MAAMA,QAAQ,CAACC,OAAeC,MAAM,CAAC,EAAEC,MAAM,CAAC;IAC1C,IAAIC,OAAO,KAAK,CAACH,QACb,OAAOC;IAEX,OAAOG,KAAK,GAAG,CAACF,KAAKE,KAAK,GAAG,CAACH,KAAKD;AACvC;AAEA,MAAMK,QAAQ,CAACC,IAAsBF,KAAK,KAAK,CAACE,AAAI,OAAJA,KAAY;AAE5D,MAAMC,eAA0B;IAAE,KAAK;IAAG,MAAM;IAAG,QAAQ;IAAG,OAAO;AAAE;AACvE,MAAMC,sBAAuC;IAAE,GAAG;IAAK,GAAG;AAAI;AAEvD,SAASC,kBACZC,QAA4B,EAC5B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,cACMD,mBAAmBC,eAClBuB,KAAK,KAAK,GAAGhB,KAAOgB,CAAAA,KAAK,MAAM,GAAGf,EAAC;IAE9C,OAAO;QACHe;QACA,gBAAgB,GAAGvC,MAAMiC,AAAW,MAAXA,OAAO,CAAC,EAAQ,EAAE,EAAEjC,MAAMiC,AAAW,MAAXA,OAAO,CAAC,EAAQ,CAAC,CAAC;QACrE,WAAW;YACP,UAAU;YACV,OAAO;YACP,aAAa,GAAGjC,MAAM0C,iBAAiB;YACvC,UAAU;QACd;QACA,OAAO;YACH,UAAU;YACV,OAAO,GAAG1C,MAAM,MAAMwC,OAAO,CAAC,CAAC;YAC/B,QAAQ,GAAGxC,MAAM,MAAMyC,OAAO,CAAC,CAAC;YAChC,MAAM,GAAGzC,MAAM,AAAoB,MAApB,CAAEuC,CAAAA,KAAK,CAAC,GAAGC,KAAI,GAAU,CAAC,CAAC;YAC1C,KAAK,GAAGxC,MAAM,AAAoB,MAApB,CAAEuC,CAAAA,KAAK,CAAC,GAAGE,KAAI,GAAU,CAAC,CAAC;YACzC,UAAU;YACV,WAAW;YACX,gBAAgB,GAAGzC,MAAMiC,AAAW,MAAXA,OAAO,CAAC,EAAQ,EAAE,EAAEjC,MAAMiC,AAAW,MAAXA,OAAO,CAAC,EAAQ,CAAC,CAAC;QACzE;QACA,gBAAgBV;QAChB,iBAAiBC;IACrB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { getCropRect, getImageRenderData, getVisibleRect, resolveAssetImage } from "./geometry.js";
|
|
3
|
+
const geometry_test_image = (overrides)=>({
|
|
4
|
+
width: 1000,
|
|
5
|
+
height: 1000,
|
|
6
|
+
...overrides
|
|
7
|
+
});
|
|
8
|
+
describe("resolveAssetImage", ()=>{
|
|
9
|
+
it("prefers the override per property, falling back to the asset default", ()=>{
|
|
10
|
+
const assetDefault = {
|
|
11
|
+
crop: {
|
|
12
|
+
top: 0.1,
|
|
13
|
+
left: 0.1,
|
|
14
|
+
bottom: 0.1,
|
|
15
|
+
right: 0.1
|
|
16
|
+
},
|
|
17
|
+
focalPoint: {
|
|
18
|
+
x: 0.2,
|
|
19
|
+
y: 0.2
|
|
20
|
+
},
|
|
21
|
+
alt: "default alt",
|
|
22
|
+
caption: "default caption"
|
|
23
|
+
};
|
|
24
|
+
const override = {
|
|
25
|
+
focalPoint: {
|
|
26
|
+
x: 0.8,
|
|
27
|
+
y: 0.8
|
|
28
|
+
},
|
|
29
|
+
alt: "override alt"
|
|
30
|
+
};
|
|
31
|
+
const result = resolveAssetImage(override, assetDefault);
|
|
32
|
+
expect(result.crop).toEqual(assetDefault.crop);
|
|
33
|
+
expect(result.caption).toBe("default caption");
|
|
34
|
+
expect(result.focalPoint).toEqual(override.focalPoint);
|
|
35
|
+
expect(result.alt).toBe("override alt");
|
|
36
|
+
});
|
|
37
|
+
it("handles null/undefined inputs", ()=>{
|
|
38
|
+
expect(resolveAssetImage(null, null)).toEqual({
|
|
39
|
+
crop: void 0,
|
|
40
|
+
focalPoint: void 0,
|
|
41
|
+
alt: void 0,
|
|
42
|
+
caption: void 0
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe("getCropRect", ()=>{
|
|
47
|
+
it("returns the full image when no crop is set", ()=>{
|
|
48
|
+
expect(getCropRect()).toEqual({
|
|
49
|
+
x: 0,
|
|
50
|
+
y: 0,
|
|
51
|
+
width: 1,
|
|
52
|
+
height: 1
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
it("converts edge insets into a rectangle", ()=>{
|
|
56
|
+
const rect = getCropRect({
|
|
57
|
+
top: 0.1,
|
|
58
|
+
left: 0.2,
|
|
59
|
+
bottom: 0.3,
|
|
60
|
+
right: 0.05
|
|
61
|
+
});
|
|
62
|
+
expect(rect.x).toBeCloseTo(0.2, 10);
|
|
63
|
+
expect(rect.y).toBeCloseTo(0.1, 10);
|
|
64
|
+
expect(rect.width).toBeCloseTo(0.75, 10);
|
|
65
|
+
expect(rect.height).toBeCloseTo(0.6, 10);
|
|
66
|
+
});
|
|
67
|
+
it("does not produce negative dimensions when insets overlap", ()=>{
|
|
68
|
+
const rect = getCropRect({
|
|
69
|
+
top: 0.7,
|
|
70
|
+
left: 0.7,
|
|
71
|
+
bottom: 0.7,
|
|
72
|
+
right: 0.7
|
|
73
|
+
});
|
|
74
|
+
expect(rect.width).toBe(0);
|
|
75
|
+
expect(rect.height).toBe(0);
|
|
76
|
+
});
|
|
77
|
+
it("clamps out-of-range values", ()=>{
|
|
78
|
+
const rect = getCropRect({
|
|
79
|
+
top: -1,
|
|
80
|
+
left: 2,
|
|
81
|
+
bottom: 0,
|
|
82
|
+
right: 0
|
|
83
|
+
});
|
|
84
|
+
expect(rect.x).toBe(1);
|
|
85
|
+
expect(rect.y).toBe(0);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe("getVisibleRect", ()=>{
|
|
89
|
+
it("returns the crop rect when no aspect ratio is requested", ()=>{
|
|
90
|
+
const rect = getVisibleRect(geometry_test_image({
|
|
91
|
+
crop: {
|
|
92
|
+
top: 0.1,
|
|
93
|
+
left: 0.1,
|
|
94
|
+
bottom: 0.1,
|
|
95
|
+
right: 0.1
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
expect(rect).toEqual({
|
|
99
|
+
x: 0.1,
|
|
100
|
+
y: 0.1,
|
|
101
|
+
width: 0.8,
|
|
102
|
+
height: 0.8
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
it("fits a 16:9 rect inside a square image, centered by default", ()=>{
|
|
106
|
+
const rect = getVisibleRect(geometry_test_image(), 16 / 9);
|
|
107
|
+
expect(rect.width).toBeCloseTo(1, 5);
|
|
108
|
+
expect(rect.height).toBeCloseTo(0.5625, 5);
|
|
109
|
+
expect(rect.y).toBeCloseTo(0.21875, 5);
|
|
110
|
+
expect(rect.x).toBeCloseTo(0, 5);
|
|
111
|
+
});
|
|
112
|
+
it("shifts the visible rect toward the focal point and clamps to bounds", ()=>{
|
|
113
|
+
const rect = getVisibleRect(geometry_test_image({
|
|
114
|
+
focalPoint: {
|
|
115
|
+
x: 0.5,
|
|
116
|
+
y: 0.05
|
|
117
|
+
}
|
|
118
|
+
}), 16 / 9);
|
|
119
|
+
expect(rect.y).toBeCloseTo(0, 5);
|
|
120
|
+
});
|
|
121
|
+
it("keeps the visible rect within the crop rectangle", ()=>{
|
|
122
|
+
const rect = getVisibleRect(geometry_test_image({
|
|
123
|
+
crop: {
|
|
124
|
+
top: 0.25,
|
|
125
|
+
left: 0,
|
|
126
|
+
bottom: 0.25,
|
|
127
|
+
right: 0
|
|
128
|
+
},
|
|
129
|
+
focalPoint: {
|
|
130
|
+
x: 0.5,
|
|
131
|
+
y: 0.9
|
|
132
|
+
}
|
|
133
|
+
}), 1);
|
|
134
|
+
expect(rect.y).toBeGreaterThanOrEqual(0.25 - 1e-9);
|
|
135
|
+
expect(rect.y + rect.height).toBeLessThanOrEqual(0.75 + 1e-9);
|
|
136
|
+
});
|
|
137
|
+
it("accepts an explicit width/height aspect ratio", ()=>{
|
|
138
|
+
const byObject = getVisibleRect(geometry_test_image(), {
|
|
139
|
+
width: 16,
|
|
140
|
+
height: 9
|
|
141
|
+
});
|
|
142
|
+
const byNumber = getVisibleRect(geometry_test_image(), 16 / 9);
|
|
143
|
+
expect(byObject).toEqual(byNumber);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe("getImageRenderData", ()=>{
|
|
147
|
+
it("derives objectPosition from the focal point", ()=>{
|
|
148
|
+
const data = getImageRenderData(geometry_test_image({
|
|
149
|
+
focalPoint: {
|
|
150
|
+
x: 0.25,
|
|
151
|
+
y: 0.75
|
|
152
|
+
}
|
|
153
|
+
}), 1);
|
|
154
|
+
expect(data.objectPosition).toBe("25% 75%");
|
|
155
|
+
});
|
|
156
|
+
it("produces an overflow-hidden container with the requested aspect ratio", ()=>{
|
|
157
|
+
const data = getImageRenderData(geometry_test_image(), 16 / 9);
|
|
158
|
+
expect(data.container.overflow).toBe("hidden");
|
|
159
|
+
expect(data.container.aspectRatio).toBe(`${Math.round(16 / 9 * 1000) / 1000}`);
|
|
160
|
+
});
|
|
161
|
+
it("scales and offsets the image so the visible rect fills the container", ()=>{
|
|
162
|
+
const data = getImageRenderData(geometry_test_image(), 16 / 9);
|
|
163
|
+
expect(data.image.width).toBe("100%");
|
|
164
|
+
expect(data.image.height).toBe(`${Math.round(100 / 0.5625 * 1000) / 1000}%`);
|
|
165
|
+
expect(parseFloat(data.image.left)).toBe(0);
|
|
166
|
+
expect(parseFloat(data.image.top)).toBeLessThan(0);
|
|
167
|
+
});
|
|
168
|
+
it("stays finite for a degenerate (collapsed) crop", ()=>{
|
|
169
|
+
const data = getImageRenderData(geometry_test_image({
|
|
170
|
+
crop: {
|
|
171
|
+
top: 0.7,
|
|
172
|
+
left: 0.7,
|
|
173
|
+
bottom: 0.7,
|
|
174
|
+
right: 0.7
|
|
175
|
+
}
|
|
176
|
+
}), 1);
|
|
177
|
+
expect(Number.isFinite(parseFloat(data.image.width))).toBe(true);
|
|
178
|
+
expect(Number.isFinite(parseFloat(data.image.height))).toBe(true);
|
|
179
|
+
});
|
|
180
|
+
it("passes through intrinsic dimensions", ()=>{
|
|
181
|
+
const data = getImageRenderData(geometry_test_image({
|
|
182
|
+
width: 1920,
|
|
183
|
+
height: 1080
|
|
184
|
+
}), 16 / 9);
|
|
185
|
+
expect(data.intrinsicWidth).toBe(1920);
|
|
186
|
+
expect(data.intrinsicHeight).toBe(1080);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
//# sourceMappingURL=geometry.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image/geometry.test.js","sources":["../../src/image/geometry.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { getCropRect, getImageRenderData, getVisibleRect, resolveAssetImage } from \"./geometry.js\";\nimport type { AssetImage } from \"@webiny/sdk\";\n\nconst image = (overrides?: Partial<AssetImage>): AssetImage => ({\n width: 1000,\n height: 1000,\n ...overrides\n});\n\ndescribe(\"resolveAssetImage\", () => {\n it(\"prefers the override per property, falling back to the asset default\", () => {\n const assetDefault: AssetImage = {\n crop: { top: 0.1, left: 0.1, bottom: 0.1, right: 0.1 },\n focalPoint: { x: 0.2, y: 0.2 },\n alt: \"default alt\",\n caption: \"default caption\"\n };\n const override: AssetImage = {\n focalPoint: { x: 0.8, y: 0.8 },\n alt: \"override alt\"\n };\n\n const result = resolveAssetImage(override, assetDefault);\n\n expect(result.crop).toEqual(assetDefault.crop);\n expect(result.caption).toBe(\"default caption\");\n expect(result.focalPoint).toEqual(override.focalPoint);\n expect(result.alt).toBe(\"override alt\");\n });\n\n it(\"handles null/undefined inputs\", () => {\n expect(resolveAssetImage(null, null)).toEqual({\n crop: undefined,\n focalPoint: undefined,\n alt: undefined,\n caption: undefined\n });\n });\n});\n\ndescribe(\"getCropRect\", () => {\n it(\"returns the full image when no crop is set\", () => {\n expect(getCropRect()).toEqual({ x: 0, y: 0, width: 1, height: 1 });\n });\n\n it(\"converts edge insets into a rectangle\", () => {\n const rect = getCropRect({ top: 0.1, left: 0.2, bottom: 0.3, right: 0.05 });\n expect(rect.x).toBeCloseTo(0.2, 10);\n expect(rect.y).toBeCloseTo(0.1, 10);\n expect(rect.width).toBeCloseTo(0.75, 10);\n expect(rect.height).toBeCloseTo(0.6, 10);\n });\n\n it(\"does not produce negative dimensions when insets overlap\", () => {\n const rect = getCropRect({ top: 0.7, left: 0.7, bottom: 0.7, right: 0.7 });\n expect(rect.width).toBe(0);\n expect(rect.height).toBe(0);\n });\n\n it(\"clamps out-of-range values\", () => {\n const rect = getCropRect({ top: -1, left: 2, bottom: 0, right: 0 });\n expect(rect.x).toBe(1);\n expect(rect.y).toBe(0);\n });\n});\n\ndescribe(\"getVisibleRect\", () => {\n it(\"returns the crop rect when no aspect ratio is requested\", () => {\n const rect = getVisibleRect(\n image({ crop: { top: 0.1, left: 0.1, bottom: 0.1, right: 0.1 } })\n );\n expect(rect).toEqual({ x: 0.1, y: 0.1, width: 0.8, height: 0.8 });\n });\n\n it(\"fits a 16:9 rect inside a square image, centered by default\", () => {\n const rect = getVisibleRect(image(), 16 / 9);\n expect(rect.width).toBeCloseTo(1, 5);\n expect(rect.height).toBeCloseTo(0.5625, 5);\n expect(rect.y).toBeCloseTo((1 - 0.5625) / 2, 5);\n expect(rect.x).toBeCloseTo(0, 5);\n });\n\n it(\"shifts the visible rect toward the focal point and clamps to bounds\", () => {\n const rect = getVisibleRect(image({ focalPoint: { x: 0.5, y: 0.05 } }), 16 / 9);\n expect(rect.y).toBeCloseTo(0, 5);\n });\n\n it(\"keeps the visible rect within the crop rectangle\", () => {\n const rect = getVisibleRect(\n image({\n crop: { top: 0.25, left: 0, bottom: 0.25, right: 0 },\n focalPoint: { x: 0.5, y: 0.9 }\n }),\n 1\n );\n expect(rect.y).toBeGreaterThanOrEqual(0.25 - 1e-9);\n expect(rect.y + rect.height).toBeLessThanOrEqual(0.75 + 1e-9);\n });\n\n it(\"accepts an explicit width/height aspect ratio\", () => {\n const byObject = getVisibleRect(image(), { width: 16, height: 9 });\n const byNumber = getVisibleRect(image(), 16 / 9);\n expect(byObject).toEqual(byNumber);\n });\n});\n\ndescribe(\"getImageRenderData\", () => {\n it(\"derives objectPosition from the focal point\", () => {\n const data = getImageRenderData(image({ focalPoint: { x: 0.25, y: 0.75 } }), 1);\n expect(data.objectPosition).toBe(\"25% 75%\");\n });\n\n it(\"produces an overflow-hidden container with the requested aspect ratio\", () => {\n const data = getImageRenderData(image(), 16 / 9);\n expect(data.container.overflow).toBe(\"hidden\");\n expect(data.container.aspectRatio).toBe(`${Math.round((16 / 9) * 1000) / 1000}`);\n });\n\n it(\"scales and offsets the image so the visible rect fills the container\", () => {\n const data = getImageRenderData(image(), 16 / 9);\n expect(data.image.width).toBe(\"100%\");\n expect(data.image.height).toBe(`${Math.round((100 / 0.5625) * 1000) / 1000}%`);\n expect(parseFloat(data.image.left)).toBe(0);\n expect(parseFloat(data.image.top)).toBeLessThan(0);\n });\n\n it(\"stays finite for a degenerate (collapsed) crop\", () => {\n const data = getImageRenderData(\n image({ crop: { top: 0.7, left: 0.7, bottom: 0.7, right: 0.7 } }),\n 1\n );\n expect(Number.isFinite(parseFloat(data.image.width))).toBe(true);\n expect(Number.isFinite(parseFloat(data.image.height))).toBe(true);\n });\n\n it(\"passes through intrinsic dimensions\", () => {\n const data = getImageRenderData(image({ width: 1920, height: 1080 }), 16 / 9);\n expect(data.intrinsicWidth).toBe(1920);\n expect(data.intrinsicHeight).toBe(1080);\n });\n});\n"],"names":["image","overrides","describe","it","assetDefault","override","result","resolveAssetImage","expect","undefined","getCropRect","rect","getVisibleRect","byObject","byNumber","data","getImageRenderData","Math","parseFloat","Number"],"mappings":";;AAIA,MAAMA,sBAAQ,CAACC,YAAiD;QAC5D,OAAO;QACP,QAAQ;QACR,GAAGA,SAAS;IAChB;AAEAC,SAAS,qBAAqB;IAC1BC,GAAG,wEAAwE;QACvE,MAAMC,eAA2B;YAC7B,MAAM;gBAAE,KAAK;gBAAK,MAAM;gBAAK,QAAQ;gBAAK,OAAO;YAAI;YACrD,YAAY;gBAAE,GAAG;gBAAK,GAAG;YAAI;YAC7B,KAAK;YACL,SAAS;QACb;QACA,MAAMC,WAAuB;YACzB,YAAY;gBAAE,GAAG;gBAAK,GAAG;YAAI;YAC7B,KAAK;QACT;QAEA,MAAMC,SAASC,kBAAkBF,UAAUD;QAE3CI,OAAOF,OAAO,IAAI,EAAE,OAAO,CAACF,aAAa,IAAI;QAC7CI,OAAOF,OAAO,OAAO,EAAE,IAAI,CAAC;QAC5BE,OAAOF,OAAO,UAAU,EAAE,OAAO,CAACD,SAAS,UAAU;QACrDG,OAAOF,OAAO,GAAG,EAAE,IAAI,CAAC;IAC5B;IAEAH,GAAG,iCAAiC;QAChCK,OAAOD,k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C,QAAQ,EAAE,IAAI,CAAC;QACrCP,OAAOO,KAAK,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,GAAGE,KAAK,KAAK,CAAE,KAAK,IAAK,QAAQ,MAAM;IACnF;IAEAd,GAAG,wEAAwE;QACvE,MAAMY,OAAOC,mBAAmBhB,uBAAS,KAAK;QAC9CQ,OAAOO,KAAK,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;QAC9BP,OAAOO,KAAK,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,GAAGE,KAAK,KAAK,CAAE,MAAM,SAAU,QAAQ,KAAK,CAAC,CAAC;QAC7ET,OAAOU,WAAWH,KAAK,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QACzCP,OAAOU,WAAWH,KAAK,KAAK,CAAC,GAAG,GAAG,YAAY,CAAC;IACpD;IAEAZ,GAAG,kDAAkD;QACjD,MAAMY,OAAOC,mBACThB,oBAAM;YAAE,MAAM;gBAAE,KAAK;gBAAK,MAAM;gBAAK,QAAQ;gBAAK,OAAO;YAAI;QAAE,IAC/D;QAEJQ,OAAOW,OAAO,QAAQ,CAACD,WAAWH,KAAK,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC;QAC3DP,OAAOW,OAAO,QAAQ,CAACD,WAAWH,KAAK,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC;IAChE;IAEAZ,GAAG,uCAAuC;QACtC,MAAMY,OAAOC,mBAAmBhB,oBAAM;YAAE,OAAO;YAAM,QAAQ;QAAK,IAAI,KAAK;QAC3EQ,OAAOO,KAAK,cAAc,EAAE,IAAI,CAAC;QACjCP,OAAOO,KAAK,eAAe,EAAE,IAAI,CAAC;IACtC;AACJ"}
|
package/image/index.d.ts
ADDED
package/image/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AspectRatioPreset } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Default aspect ratios shown in the image editor's preview strip.
|
|
4
|
+
* A later phase will let a field lock to one of these (or a custom ratio).
|
|
5
|
+
*/
|
|
6
|
+
export declare const ASPECT_RATIO_PRESETS: AspectRatioPreset[];
|
package/image/presets.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const ASPECT_RATIO_PRESETS = [
|
|
2
|
+
{
|
|
3
|
+
id: "square",
|
|
4
|
+
label: "Square",
|
|
5
|
+
ratio: 1
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
id: "4:3",
|
|
9
|
+
label: "4:3",
|
|
10
|
+
ratio: 4 / 3
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: "16:9",
|
|
14
|
+
label: "16:9",
|
|
15
|
+
ratio: 16 / 9
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
export { ASPECT_RATIO_PRESETS };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image/presets.js","sources":["../../src/image/presets.ts"],"sourcesContent":["import type { AspectRatioPreset } from \"./types.js\";\n\n/**\n * Default aspect ratios shown in the image editor's preview strip.\n * A later phase will let a field lock to one of these (or a custom ratio).\n */\nexport const ASPECT_RATIO_PRESETS: AspectRatioPreset[] = [\n { id: \"square\", label: \"Square\", ratio: 1 },\n { id: \"4:3\", label: \"4:3\", ratio: 4 / 3 },\n { id: \"16:9\", label: \"16:9\", ratio: 16 / 9 }\n];\n"],"names":["ASPECT_RATIO_PRESETS"],"mappings":"AAMO,MAAMA,uBAA4C;IACrD;QAAE,IAAI;QAAU,OAAO;QAAU,OAAO;IAAE;IAC1C;QAAE,IAAI;QAAO,OAAO;QAAO,OAAO,IAAI;IAAE;IACxC;QAAE,IAAI;QAAQ,OAAO;QAAQ,OAAO,KAAK;IAAE;CAC9C"}
|
package/image/types.d.ts
ADDED
package/image/types.js
ADDED
|
File without changes
|
package/index.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export * from "./DocumentStore.js";
|
|
|
8
8
|
export * from "./Logger.js";
|
|
9
9
|
export * from "./FunctionConverter.js";
|
|
10
10
|
export * from "./createInput.js";
|
|
11
|
+
export * from "./createComponent.js";
|
|
12
|
+
export * from "./image/index.js";
|
|
13
|
+
export * from "./asset/index.js";
|
|
11
14
|
export * from "./MouseTracker.js";
|
|
12
15
|
export * from "./ViewportManager.js";
|
|
13
16
|
export * from "./messenger/Messenger.js";
|
|
@@ -21,6 +24,7 @@ export * from "./createElement.js";
|
|
|
21
24
|
export * from "./registerComponentGroup.js";
|
|
22
25
|
export * from "./jsonPatch.js";
|
|
23
26
|
export * from "./headersProvider.js";
|
|
27
|
+
export * from "./experiments/index.js";
|
|
24
28
|
export * from "./ComponentManifestToAstConverter.js";
|
|
25
29
|
export * from "./findMatchingAstNode.js";
|
|
26
30
|
export * from "./InheritanceProcessor.js";
|
package/index.js
CHANGED
|
@@ -8,6 +8,9 @@ export * from "./DocumentStore.js";
|
|
|
8
8
|
export * from "./Logger.js";
|
|
9
9
|
export * from "./FunctionConverter.js";
|
|
10
10
|
export * from "./createInput.js";
|
|
11
|
+
export * from "./createComponent.js";
|
|
12
|
+
export * from "./image/index.js";
|
|
13
|
+
export * from "./asset/index.js";
|
|
11
14
|
export * from "./MouseTracker.js";
|
|
12
15
|
export * from "./ViewportManager.js";
|
|
13
16
|
export * from "./messenger/Messenger.js";
|
|
@@ -20,6 +23,7 @@ export * from "./createElement.js";
|
|
|
20
23
|
export * from "./registerComponentGroup.js";
|
|
21
24
|
export * from "./jsonPatch.js";
|
|
22
25
|
export * from "./headersProvider.js";
|
|
26
|
+
export * from "./experiments/index.js";
|
|
23
27
|
export * from "./ComponentManifestToAstConverter.js";
|
|
24
28
|
export * from "./findMatchingAstNode.js";
|
|
25
29
|
export * from "./InheritanceProcessor.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/website-builder-sdk",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"author": "Pavel Denisjuk",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@webiny/sdk": "6.6.0-alpha.1",
|
|
15
16
|
"csstype": "3.2.3",
|
|
16
17
|
"deep-equal": "2.2.3",
|
|
17
18
|
"deepmerge": "4.3.1",
|
|
@@ -20,8 +21,8 @@
|
|
|
20
21
|
"is-hotkey": "0.2.0",
|
|
21
22
|
"lodash": "4.18.1",
|
|
22
23
|
"matcher": "6.0.0",
|
|
23
|
-
"mobx": "
|
|
24
|
-
"nanoid": "
|
|
24
|
+
"mobx": "7.0.3",
|
|
25
|
+
"nanoid": "6.0.1",
|
|
25
26
|
"nanoid-dictionary": "5.0.0",
|
|
26
27
|
"pino": "10.3.1",
|
|
27
28
|
"pino-pretty": "13.1.3"
|
|
@@ -29,9 +30,9 @@
|
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/deep-equal": "1.0.4",
|
|
31
32
|
"@types/is-hotkey": "0.1.10",
|
|
32
|
-
"@webiny/build-tools": "6.
|
|
33
|
-
"typescript": "
|
|
34
|
-
"vitest": "4.1.
|
|
33
|
+
"@webiny/build-tools": "6.6.0-alpha.1",
|
|
34
|
+
"typescript": "7.0.2",
|
|
35
|
+
"vitest": "4.1.11"
|
|
35
36
|
},
|
|
36
37
|
"publishConfig": {
|
|
37
38
|
"access": "public"
|
package/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { BindingsApi } from "./BindingsApi.js";
|
|
|
3
3
|
import type { ShorthandCssProperties } from "./types/ShorthandCssProperties.js";
|
|
4
4
|
import type { InputFactory } from "./createInput.js";
|
|
5
5
|
import type { Breakpoint } from "./types/WebsiteBuilderTheme.js";
|
|
6
|
+
import type { ActiveExperiment, VariantContent } from "./experiments/types.js";
|
|
6
7
|
export type { WebsiteBuilderTheme, Breakpoint } from "./types/WebsiteBuilderTheme.js";
|
|
7
8
|
type CSSProperties = CSS.Properties<string | number>;
|
|
8
9
|
export type ElementMap = Record<string, DocumentElement>;
|
|
@@ -198,6 +199,7 @@ export type ComponentManifest = {
|
|
|
198
199
|
hideFromToolbar?: boolean;
|
|
199
200
|
hideStyleSettings?: string[];
|
|
200
201
|
autoApplyStyles?: boolean;
|
|
202
|
+
applyDefaultStyles?: boolean;
|
|
201
203
|
tags: string[];
|
|
202
204
|
constraints?: ComponentConstraint[];
|
|
203
205
|
descendantConstraints?: ComponentConstraint[];
|
|
@@ -373,6 +375,9 @@ export interface IDataProvider {
|
|
|
373
375
|
getPageByPath(path: string, options?: GetPageOptions): Promise<PublicPage | null>;
|
|
374
376
|
getPageById(id: string, options?: GetPageOptions): Promise<PublicPage | null>;
|
|
375
377
|
listPages(options?: ListPagesOptions): Promise<ListPagesResult>;
|
|
378
|
+
getPageExperiment(path: string): Promise<ActiveExperiment | null>;
|
|
379
|
+
getVariantContent(variantId: string): Promise<VariantContent | null>;
|
|
380
|
+
getExperimentPaused(experimentId: string): Promise<boolean>;
|
|
376
381
|
}
|
|
377
382
|
export interface IEnvironment {
|
|
378
383
|
isClient(): boolean;
|