@webiny/website-builder-sdk 0.0.0-unstable.eb196ccd2f → 0.0.0-unstable.eb81deee7e
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/BindingsApi.js +29 -36
- package/BindingsApi.js.map +1 -1
- package/BindingsProcessor.js +34 -43
- package/BindingsProcessor.js.map +1 -1
- package/BindingsProcessor.test.js +82 -77
- package/BindingsProcessor.test.js.map +1 -1
- package/BindingsResolver.d.ts +5 -2
- package/BindingsResolver.js +99 -122
- package/BindingsResolver.js.map +1 -1
- package/BindingsResolver.test.js +399 -362
- package/BindingsResolver.test.js.map +1 -1
- package/ComponentInputTraverser.js +32 -49
- package/ComponentInputTraverser.js.map +1 -1
- package/ComponentManifestToAstConverter.js +20 -21
- package/ComponentManifestToAstConverter.js.map +1 -1
- package/ComponentRegistry.d.ts +9 -0
- package/ComponentRegistry.js +38 -22
- package/ComponentRegistry.js.map +1 -1
- package/ComponentResolver.d.ts +3 -2
- package/ComponentResolver.js +39 -29
- package/ComponentResolver.js.map +1 -1
- package/ComponentResolver.test.d.ts +1 -0
- package/ComponentResolver.test.js +81 -0
- package/ComponentResolver.test.js.map +1 -0
- package/ConstraintEvaluator.d.ts +36 -0
- package/ConstraintEvaluator.js +288 -0
- package/ConstraintEvaluator.js.map +1 -0
- package/ConstraintEvaluator.test.d.ts +1 -0
- package/ConstraintEvaluator.test.js +1634 -0
- package/ConstraintEvaluator.test.js.map +1 -0
- package/ContentSdk.d.ts +17 -3
- package/ContentSdk.js +113 -90
- package/ContentSdk.js.map +1 -1
- package/DocumentStore.d.ts +1 -1
- package/DocumentStore.js +47 -59
- package/DocumentStore.js.map +1 -1
- package/DocumentStoreManager.js +17 -16
- package/DocumentStoreManager.js.map +1 -1
- package/EditingSdk.d.ts +2 -2
- package/EditingSdk.js +92 -124
- package/EditingSdk.js.map +1 -1
- package/ElementFactory.d.ts +2 -3
- package/ElementFactory.js +164 -163
- package/ElementFactory.js.map +1 -1
- package/ElementFactory.objectListDefaults.test.d.ts +1 -0
- package/ElementFactory.objectListDefaults.test.js +423 -0
- package/ElementFactory.objectListDefaults.test.js.map +1 -0
- package/ElementFactory.test.d.ts +1 -0
- package/ElementFactory.test.js +353 -0
- package/ElementFactory.test.js.map +1 -0
- package/Environment.js +18 -19
- package/Environment.js.map +1 -1
- package/FunctionConverter.js +8 -7
- package/FunctionConverter.js.map +1 -1
- package/HashObject.js +11 -12
- package/HashObject.js.map +1 -1
- package/HotkeyManager.js +41 -48
- package/HotkeyManager.js.map +1 -1
- package/IBindingsUpdater.js +0 -3
- package/IRedirects.js +0 -3
- package/InheritanceProcessor.d.ts +2 -2
- package/InheritanceProcessor.js +99 -139
- package/InheritanceProcessor.js.map +1 -1
- package/InheritanceProcessor.test.js +178 -178
- package/InheritanceProcessor.test.js.map +1 -1
- package/InheritedValueResolver.d.ts +18 -1
- package/InheritedValueResolver.js +18 -20
- package/InheritedValueResolver.js.map +1 -1
- package/InputBindingsProcessor.d.ts +23 -2
- package/InputBindingsProcessor.js +200 -289
- package/InputBindingsProcessor.js.map +1 -1
- package/InputBindingsProcessorTokens.test.d.ts +1 -0
- package/InputBindingsProcessorTokens.test.js +400 -0
- package/InputBindingsProcessorTokens.test.js.map +1 -0
- package/InputsBindingsProcessor.test.js +334 -313
- package/InputsBindingsProcessor.test.js.map +1 -1
- package/InputsUpdater.d.ts +1 -1
- package/InputsUpdater.js +23 -26
- package/InputsUpdater.js.map +1 -1
- package/LiveSdk.d.ts +2 -2
- package/LiveSdk.js +12 -13
- package/LiveSdk.js.map +1 -1
- package/Logger.d.ts +2 -1
- package/Logger.js +9 -8
- package/Logger.js.map +1 -1
- package/MouseTracker.js +77 -83
- package/MouseTracker.js.map +1 -1
- package/NullSdk.d.ts +4 -3
- package/NullSdk.js +22 -14
- package/NullSdk.js.map +1 -1
- package/PreviewDocument.d.ts +1 -0
- package/PreviewDocument.js +30 -30
- package/PreviewDocument.js.map +1 -1
- package/PreviewSdk.d.ts +4 -3
- package/PreviewSdk.js +19 -17
- package/PreviewSdk.js.map +1 -1
- package/PreviewViewport.d.ts +0 -1
- package/PreviewViewport.js +50 -82
- package/PreviewViewport.js.map +1 -1
- package/README.md +10 -2
- package/ResizeObserver.js +24 -31
- package/ResizeObserver.js.map +1 -1
- package/StylesBindingsProcessor.d.ts +12 -2
- package/StylesBindingsProcessor.js +62 -79
- package/StylesBindingsProcessor.js.map +1 -1
- package/StylesUpdater.d.ts +1 -1
- package/StylesUpdater.js +20 -25
- package/StylesUpdater.js.map +1 -1
- package/Theme.js +30 -32
- package/Theme.js.map +1 -1
- package/ViewportManager.d.ts +2 -0
- package/ViewportManager.js +89 -97
- package/ViewportManager.js.map +1 -1
- package/assertBindingShapes.d.ts +31 -0
- package/assertBindingShapes.js +64 -0
- package/assertBindingShapes.js.map +1 -0
- package/assertBindingShapes.test.d.ts +1 -0
- package/assertBindingShapes.test.js +131 -0
- package/assertBindingShapes.test.js.map +1 -0
- 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 +106 -0
- package/asset/normalize.js.map +1 -0
- package/asset/normalize.test.d.ts +1 -0
- package/asset/normalize.test.js +263 -0
- package/asset/normalize.test.js.map +1 -0
- package/asset/types.d.ts +2 -0
- package/asset/types.js +0 -0
- package/constants.d.ts +1 -0
- package/constants.js +7 -5
- package/constants.js.map +1 -1
- package/contentEntry/ContentEntryBindingsResolver.d.ts +30 -0
- package/contentEntry/ContentEntryBindingsResolver.js +45 -0
- package/contentEntry/ContentEntryBindingsResolver.js.map +1 -0
- package/contentEntry/ContentEntryCache.d.ts +46 -0
- package/contentEntry/ContentEntryCache.js +50 -0
- package/contentEntry/ContentEntryCache.js.map +1 -0
- package/contentEntry/resolveContentEntry.d.ts +74 -0
- package/contentEntry/resolveContentEntry.js +53 -0
- package/contentEntry/resolveContentEntry.js.map +1 -0
- package/contentEntry/resolveContentEntry.test.d.ts +1 -0
- package/contentEntry/resolveContentEntry.test.js +213 -0
- package/contentEntry/resolveContentEntry.test.js.map +1 -0
- package/createComponent.d.ts +5 -0
- package/createComponent.js +32 -0
- package/createComponent.js.map +1 -0
- package/createElement.js +5 -6
- package/createElement.js.map +1 -1
- package/createInput.d.ts +132 -16
- package/createInput.js +92 -111
- package/createInput.js.map +1 -1
- package/createTheme.js +2 -3
- package/createTheme.js.map +1 -1
- package/dataProviders/ApiClient.d.ts +10 -5
- package/dataProviders/ApiClient.js +40 -49
- package/dataProviders/ApiClient.js.map +1 -1
- package/dataProviders/DefaultDataProvider.d.ts +7 -3
- package/dataProviders/DefaultDataProvider.js +91 -45
- 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_BY_ID.d.ts +1 -1
- package/dataProviders/GET_PAGE_BY_ID.js +4 -1
- package/dataProviders/GET_PAGE_BY_ID.js.map +1 -1
- package/dataProviders/GET_PAGE_BY_PATH.d.ts +1 -1
- package/dataProviders/GET_PAGE_BY_PATH.js +4 -1
- package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -1
- 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/LIST_PUBLISHED_PAGES.d.ts +1 -1
- package/dataProviders/LIST_PUBLISHED_PAGES.js +17 -5
- package/dataProviders/LIST_PUBLISHED_PAGES.js.map +1 -1
- package/dataProviders/NullDataProvider.d.ts +16 -4
- package/dataProviders/NullDataProvider.js +30 -13
- package/dataProviders/NullDataProvider.js.map +1 -1
- package/dataProviders/RedirectsProvider.js +24 -27
- package/dataProviders/RedirectsProvider.js.map +1 -1
- package/defaultBreakpoints.js +43 -22
- package/defaultBreakpoints.js.map +1 -1
- package/documentOperations/$addElementReferenceToParent.d.ts +1 -1
- package/documentOperations/$addElementReferenceToParent.js +30 -26
- package/documentOperations/$addElementReferenceToParent.js.map +1 -1
- package/documentOperations/AddElement.js +8 -7
- package/documentOperations/AddElement.js.map +1 -1
- package/documentOperations/AddToParent.d.ts +2 -2
- package/documentOperations/AddToParent.js +14 -13
- package/documentOperations/AddToParent.js.map +1 -1
- package/documentOperations/IDocumentOperation.js +0 -3
- package/documentOperations/RemoveElement.js +10 -7
- package/documentOperations/RemoveElement.js.map +1 -1
- package/documentOperations/SetGlobalInputBinding.js +23 -22
- package/documentOperations/SetGlobalInputBinding.js.map +1 -1
- package/documentOperations/SetGlobalStyleBinding.js +23 -23
- package/documentOperations/SetGlobalStyleBinding.js.map +1 -1
- package/documentOperations/SetInputBindingOverride.js +30 -29
- package/documentOperations/SetInputBindingOverride.js.map +1 -1
- package/documentOperations/SetStyleBindingOverride.js +30 -31
- package/documentOperations/SetStyleBindingOverride.js.map +1 -1
- package/documentOperations/index.js +9 -8
- package/documentOperations/index.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/findMatchingAstNode.js +11 -13
- package/findMatchingAstNode.js.map +1 -1
- package/generateElementId.d.ts +1 -1
- package/generateElementId.js +2 -2
- package/generateElementId.js.map +1 -1
- package/headersProvider.js +4 -3
- package/headersProvider.js.map +1 -1
- 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 +12 -1
- package/index.js +11 -3
- package/jsonPatch.d.ts +1 -1
- package/jsonPatch.js +5 -9
- package/jsonPatch.js.map +1 -1
- package/messages.js +12 -11
- package/messages.js.map +1 -1
- package/messenger/MessageOrigin.js +12 -11
- package/messenger/MessageOrigin.js.map +1 -1
- package/messenger/Messenger.js +59 -70
- package/messenger/Messenger.js.map +1 -1
- package/messenger/index.js +0 -2
- package/package.json +19 -22
- package/registerComponentGroup.js +5 -6
- package/registerComponentGroup.js.map +1 -1
- package/tokenBinding.d.ts +26 -0
- package/tokenBinding.js +15 -0
- package/tokenBinding.js.map +1 -0
- package/tokenBinding.test.d.ts +1 -0
- package/tokenBinding.test.js +165 -0
- package/tokenBinding.test.js.map +1 -0
- package/types/ShorthandCssProperties.js +0 -3
- package/types/WebsiteBuilderTheme.d.ts +54 -45
- package/types/WebsiteBuilderTheme.js +0 -3
- package/types.d.ts +294 -13
- package/types.js +0 -3
- package/IBindingsUpdater.js.map +0 -1
- package/IRedirects.js.map +0 -1
- package/documentOperations/IDocumentOperation.js.map +0 -1
- package/index.js.map +0 -1
- package/lexical/createDefaultLexicalTheme.d.ts +0 -2
- package/lexical/createDefaultLexicalTheme.js +0 -84
- package/lexical/createDefaultLexicalTheme.js.map +0 -1
- package/lexical/createLexicalTheme.d.ts +0 -2
- package/lexical/createLexicalTheme.js +0 -7
- package/lexical/createLexicalTheme.js.map +0 -1
- package/lexical/deepMerge.d.ts +0 -1
- package/lexical/deepMerge.js +0 -23
- package/lexical/deepMerge.js.map +0 -1
- package/messenger/index.js.map +0 -1
- package/types/LexicalEditorTheme.d.ts +0 -2
- package/types/LexicalEditorTheme.js +0 -3
- package/types/LexicalEditorTheme.js.map +0 -1
- package/types/ShorthandCssProperties.js.map +0 -1
- package/types/WebsiteBuilderTheme.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -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":"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"}
|
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,11 +8,17 @@ 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 "./contentEntry/resolveContentEntry.js";
|
|
12
|
+
export * from "./contentEntry/ContentEntryCache.js";
|
|
13
|
+
export * from "./contentEntry/ContentEntryBindingsResolver.js";
|
|
14
|
+
export * from "./createComponent.js";
|
|
15
|
+
export * from "./image/index.js";
|
|
16
|
+
export * from "./asset/index.js";
|
|
11
17
|
export * from "./MouseTracker.js";
|
|
12
18
|
export * from "./ViewportManager.js";
|
|
13
19
|
export * from "./messenger/Messenger.js";
|
|
14
20
|
export * from "./messenger/MessageOrigin.js";
|
|
15
|
-
export * from "./types.js";
|
|
21
|
+
export type * from "./types.js";
|
|
16
22
|
export * from "./DocumentStoreManager.js";
|
|
17
23
|
export * from "./BindingsProcessor.js";
|
|
18
24
|
export * from "./ResizeObserver.js";
|
|
@@ -21,10 +27,15 @@ export * from "./createElement.js";
|
|
|
21
27
|
export * from "./registerComponentGroup.js";
|
|
22
28
|
export * from "./jsonPatch.js";
|
|
23
29
|
export * from "./headersProvider.js";
|
|
30
|
+
export * from "./experiments/index.js";
|
|
24
31
|
export * from "./ComponentManifestToAstConverter.js";
|
|
25
32
|
export * from "./findMatchingAstNode.js";
|
|
26
33
|
export * from "./InheritanceProcessor.js";
|
|
27
34
|
export * from "./InputBindingsProcessor.js";
|
|
28
35
|
export * from "./StylesBindingsProcessor.js";
|
|
36
|
+
export * from "./tokenBinding.js";
|
|
29
37
|
export * from "./ElementFactory.js";
|
|
38
|
+
export * from "./ConstraintEvaluator.js";
|
|
39
|
+
export * from "./generateElementId.js";
|
|
30
40
|
export { StyleSettings } from "./constants.js";
|
|
41
|
+
export * from "./assertBindingShapes.js";
|
package/index.js
CHANGED
|
@@ -8,11 +8,16 @@ 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 "./contentEntry/resolveContentEntry.js";
|
|
12
|
+
export * from "./contentEntry/ContentEntryCache.js";
|
|
13
|
+
export * from "./contentEntry/ContentEntryBindingsResolver.js";
|
|
14
|
+
export * from "./createComponent.js";
|
|
15
|
+
export * from "./image/index.js";
|
|
16
|
+
export * from "./asset/index.js";
|
|
11
17
|
export * from "./MouseTracker.js";
|
|
12
18
|
export * from "./ViewportManager.js";
|
|
13
19
|
export * from "./messenger/Messenger.js";
|
|
14
20
|
export * from "./messenger/MessageOrigin.js";
|
|
15
|
-
export * from "./types.js";
|
|
16
21
|
export * from "./DocumentStoreManager.js";
|
|
17
22
|
export * from "./BindingsProcessor.js";
|
|
18
23
|
export * from "./ResizeObserver.js";
|
|
@@ -21,12 +26,15 @@ export * from "./createElement.js";
|
|
|
21
26
|
export * from "./registerComponentGroup.js";
|
|
22
27
|
export * from "./jsonPatch.js";
|
|
23
28
|
export * from "./headersProvider.js";
|
|
29
|
+
export * from "./experiments/index.js";
|
|
24
30
|
export * from "./ComponentManifestToAstConverter.js";
|
|
25
31
|
export * from "./findMatchingAstNode.js";
|
|
26
32
|
export * from "./InheritanceProcessor.js";
|
|
27
33
|
export * from "./InputBindingsProcessor.js";
|
|
28
34
|
export * from "./StylesBindingsProcessor.js";
|
|
35
|
+
export * from "./tokenBinding.js";
|
|
29
36
|
export * from "./ElementFactory.js";
|
|
37
|
+
export * from "./ConstraintEvaluator.js";
|
|
38
|
+
export * from "./generateElementId.js";
|
|
39
|
+
export * from "./assertBindingShapes.js";
|
|
30
40
|
export { StyleSettings } from "./constants.js";
|
|
31
|
-
|
|
32
|
-
//# sourceMappingURL=index.js.map
|
package/jsonPatch.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { Operation, Validator, PatchResult } from "fast-json-patch";
|
|
|
2
2
|
export type { Operation as JsonPatchOperation, PatchResult as JsonPatchResult };
|
|
3
3
|
export declare const jsonPatch: {
|
|
4
4
|
compare: (tree1: object | any[], tree2: object | any[], invertible?: boolean) => Operation[];
|
|
5
|
-
applyPatch: <T>(document: T, patch: Operation[], validateOperation?: boolean | Validator<T
|
|
5
|
+
applyPatch: <T>(document: T, patch: Operation[], validateOperation?: boolean | Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean) => PatchResult<T>;
|
|
6
6
|
};
|
package/jsonPatch.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return fjp.compare(tree1, tree2, invertible);
|
|
6
|
-
},
|
|
7
|
-
applyPatch: (document, patch, validateOperation, mutateDocument, banPrototypeModifications) => {
|
|
8
|
-
return fjp.applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications);
|
|
9
|
-
}
|
|
1
|
+
import * as __rspack_external_fast_json_patch_index_mjs_25f05694 from "fast-json-patch/index.mjs";
|
|
2
|
+
const jsonPatch = {
|
|
3
|
+
compare: (tree1, tree2, invertible)=>__rspack_external_fast_json_patch_index_mjs_25f05694.compare(tree1, tree2, invertible),
|
|
4
|
+
applyPatch: (document, patch, validateOperation, mutateDocument, banPrototypeModifications)=>__rspack_external_fast_json_patch_index_mjs_25f05694.applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications)
|
|
10
5
|
};
|
|
6
|
+
export { jsonPatch };
|
|
11
7
|
|
|
12
8
|
//# sourceMappingURL=jsonPatch.js.map
|
package/jsonPatch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"jsonPatch.js","sources":["../src/jsonPatch.ts"],"sourcesContent":["import type { Operation, Validator, PatchResult } from \"fast-json-patch\";\n// @ts-expect-error We need this hack.\nimport * as fjp from \"fast-json-patch/index.mjs\";\n\nexport type { Operation as JsonPatchOperation, PatchResult as JsonPatchResult };\n\nexport const jsonPatch = {\n compare: (tree1: object | any[], tree2: object | any[], invertible?: boolean): Operation[] => {\n return fjp.compare(tree1, tree2, invertible);\n },\n applyPatch: <T>(\n document: T,\n patch: Operation[],\n validateOperation?: boolean | Validator<T>,\n mutateDocument?: boolean,\n banPrototypeModifications?: boolean\n ): PatchResult<T> => {\n return fjp.applyPatch(\n document,\n patch,\n validateOperation,\n mutateDocument,\n banPrototypeModifications\n );\n }\n};\n"],"names":["jsonPatch","tree1","tree2","invertible","fjp","document","patch","validateOperation","mutateDocument","banPrototypeModifications"],"mappings":";AAMO,MAAMA,YAAY;IACrB,SAAS,CAACC,OAAuBC,OAAuBC,aAC7CC,qDAAAA,OAAW,CAACH,OAAOC,OAAOC;IAErC,YAAY,CACRE,UACAC,OACAC,mBACAC,gBACAC,4BAEOL,qDAAAA,UAAc,CACjBC,UACAC,OACAC,mBACAC,gBACAC;AAGZ"}
|
package/messages.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
const DOCUMENT_SET = "document.set";
|
|
2
|
+
const DOCUMENT_PATCH = "document.patch";
|
|
3
|
+
const PREVIEW_COMPONENT_REGISTER = "preview.component.register";
|
|
4
|
+
const PREVIEW_READY = "preview.ready";
|
|
5
|
+
const PREVIEW_COMPONENTGROUP_REGISTER = "preview.componentGroup.register";
|
|
6
|
+
const PREVIEW_VIEWPORT_CHANGE_START = "preview.viewport.change.start";
|
|
7
|
+
const PREVIEW_VIEWPORT_CHANGE_END = "preview.viewport.change.end";
|
|
8
|
+
const PREVIEW_ELEMENT_POSITIONS = "preview.element.positions";
|
|
9
|
+
const PREVIEW_ELEMENT_CLICK = "preview.element.click";
|
|
10
|
+
const PREVIEW_ELEMENT_ENTER = "preview.element.enter";
|
|
11
|
+
const PREVIEW_ELEMENT_LEAVE = "preview.element.leave";
|
|
12
|
+
export { DOCUMENT_PATCH, DOCUMENT_SET, PREVIEW_COMPONENTGROUP_REGISTER, PREVIEW_COMPONENT_REGISTER, PREVIEW_ELEMENT_CLICK, PREVIEW_ELEMENT_ENTER, PREVIEW_ELEMENT_LEAVE, PREVIEW_ELEMENT_POSITIONS, PREVIEW_READY, PREVIEW_VIEWPORT_CHANGE_END, PREVIEW_VIEWPORT_CHANGE_START };
|
|
12
13
|
|
|
13
14
|
//# sourceMappingURL=messages.js.map
|
package/messages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"messages.js","sources":["../src/messages.ts"],"sourcesContent":["export const DOCUMENT_SET = \"document.set\";\nexport const DOCUMENT_PATCH = \"document.patch\";\nexport const PREVIEW_COMPONENT_REGISTER = \"preview.component.register\";\nexport const PREVIEW_READY = \"preview.ready\";\nexport const PREVIEW_COMPONENTGROUP_REGISTER = \"preview.componentGroup.register\";\nexport const PREVIEW_VIEWPORT_CHANGE_START = \"preview.viewport.change.start\";\nexport const PREVIEW_VIEWPORT_CHANGE_END = \"preview.viewport.change.end\";\nexport const PREVIEW_ELEMENT_POSITIONS = \"preview.element.positions\";\nexport const PREVIEW_ELEMENT_CLICK = \"preview.element.click\";\nexport const PREVIEW_ELEMENT_ENTER = \"preview.element.enter\";\nexport const PREVIEW_ELEMENT_LEAVE = \"preview.element.leave\";\n"],"names":["DOCUMENT_SET","DOCUMENT_PATCH","PREVIEW_COMPONENT_REGISTER","PREVIEW_READY","PREVIEW_COMPONENTGROUP_REGISTER","PREVIEW_VIEWPORT_CHANGE_START","PREVIEW_VIEWPORT_CHANGE_END","PREVIEW_ELEMENT_POSITIONS","PREVIEW_ELEMENT_CLICK","PREVIEW_ELEMENT_ENTER","PREVIEW_ELEMENT_LEAVE"],"mappings":"AAAO,MAAMA,eAAe;AACrB,MAAMC,iBAAiB;AACvB,MAAMC,6BAA6B;AACnC,MAAMC,gBAAgB;AACtB,MAAMC,kCAAkC;AACxC,MAAMC,gCAAgC;AACtC,MAAMC,8BAA8B;AACpC,MAAMC,4BAA4B;AAClC,MAAMC,wBAAwB;AAC9B,MAAMC,wBAAwB;AAC9B,MAAMC,wBAAwB"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
class MessageOrigin {
|
|
2
|
+
constructor(getWindow, origin){
|
|
3
|
+
this.getWindow = getWindow;
|
|
4
|
+
this.origin = origin;
|
|
5
|
+
}
|
|
6
|
+
matches(event) {
|
|
7
|
+
return event.origin === this.origin;
|
|
8
|
+
}
|
|
9
|
+
get window() {
|
|
10
|
+
return this.getWindow();
|
|
11
|
+
}
|
|
12
12
|
}
|
|
13
|
+
export { MessageOrigin };
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=MessageOrigin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"messenger/MessageOrigin.js","sources":["../../src/messenger/MessageOrigin.ts"],"sourcesContent":["export class MessageOrigin {\n private readonly getWindow: () => Window;\n public readonly origin: string;\n\n constructor(getWindow: () => Window, origin: string) {\n this.getWindow = getWindow;\n this.origin = origin;\n }\n\n matches(event: MessageEvent): boolean {\n return event.origin === this.origin;\n }\n\n get window() {\n return this.getWindow();\n }\n}\n"],"names":["MessageOrigin","getWindow","origin","event"],"mappings":"AAAO,MAAMA;IAIT,YAAYC,SAAuB,EAAEC,MAAc,CAAE;QACjD,IAAI,CAAC,SAAS,GAAGD;QACjB,IAAI,CAAC,MAAM,GAAGC;IAClB;IAEA,QAAQC,KAAmB,EAAW;QAClC,OAAOA,MAAM,MAAM,KAAK,IAAI,CAAC,MAAM;IACvC;IAEA,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,SAAS;IACzB;AACJ"}
|
package/messenger/Messenger.js
CHANGED
|
@@ -1,80 +1,69 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isMatch } from "matcher";
|
|
2
2
|
import { logger } from "../Logger.js";
|
|
3
|
-
const ignored = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} = event.data || {};
|
|
21
|
-
if (!this.target.matches(event)) {
|
|
22
|
-
return;
|
|
3
|
+
const ignored = [
|
|
4
|
+
"preview.mouse.move",
|
|
5
|
+
"preview.component.register",
|
|
6
|
+
"preview.scroll",
|
|
7
|
+
"preview.viewport",
|
|
8
|
+
"preview.viewport.change.start",
|
|
9
|
+
"preview.viewport.change.end"
|
|
10
|
+
];
|
|
11
|
+
class Messenger {
|
|
12
|
+
constructor(source, target, pattern){
|
|
13
|
+
this.source = source;
|
|
14
|
+
this.target = target;
|
|
15
|
+
this.listeners = new Map();
|
|
16
|
+
this.pattern = pattern;
|
|
17
|
+
this.prefixGlob = pattern.replace(/\*+$/, "");
|
|
18
|
+
this.handleMessage = this.handleMessage.bind(this);
|
|
19
|
+
this.source.window.addEventListener("message", this.handleMessage);
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
handleMessage(event) {
|
|
22
|
+
const { type, payload } = event.data || {};
|
|
23
|
+
if (!this.target.matches(event)) return;
|
|
24
|
+
if (!type || !isMatch(type, this.pattern)) return;
|
|
25
|
+
const logicalType = this.stripPrefix(type);
|
|
26
|
+
if (!this.isIgnored(logicalType)) logger.debug({
|
|
27
|
+
type,
|
|
28
|
+
payload
|
|
29
|
+
}, `${this.getTime()} --> [${this.source.origin}][${logicalType}]`);
|
|
30
|
+
const handlers = this.listeners.get(logicalType);
|
|
31
|
+
if (handlers) handlers.forEach((fn)=>fn(payload, logicalType));
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
logger.debug(`${this.getTime()} --> [${this.source.origin}][${logicalType}]`, {
|
|
30
|
-
type,
|
|
31
|
-
payload
|
|
32
|
-
});
|
|
33
|
+
stripPrefix(fullType) {
|
|
34
|
+
return fullType.startsWith(this.prefixGlob) ? fullType.slice(this.prefixGlob.length) : fullType;
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
handlers.forEach(fn => fn(payload, logicalType));
|
|
36
|
+
isIgnored(logicalType) {
|
|
37
|
+
return ignored.includes(logicalType);
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
on(logicalType, handler) {
|
|
46
|
-
if (!this.listeners.has(logicalType)) {
|
|
47
|
-
this.listeners.set(logicalType, new Set());
|
|
39
|
+
on(logicalType, handler) {
|
|
40
|
+
if (!this.listeners.has(logicalType)) this.listeners.set(logicalType, new Set());
|
|
41
|
+
this.listeners.get(logicalType).add(handler);
|
|
42
|
+
return ()=>{
|
|
43
|
+
const listeners = this.listeners.get(logicalType);
|
|
44
|
+
if (listeners) listeners.delete(handler);
|
|
45
|
+
};
|
|
48
46
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
send(logicalType, payload) {
|
|
48
|
+
const fullType = this.prefixGlob + logicalType;
|
|
49
|
+
if (!this.isIgnored(logicalType)) logger.debug({
|
|
50
|
+
type: fullType,
|
|
51
|
+
payload
|
|
52
|
+
}, `${this.getTime()} <-- [${this.source.origin}][${logicalType}]`);
|
|
53
|
+
this.target.window.postMessage({
|
|
54
|
+
type: fullType,
|
|
55
|
+
payload
|
|
56
|
+
}, this.target.origin);
|
|
57
|
+
}
|
|
58
|
+
dispose() {
|
|
59
|
+
this.source.window.removeEventListener("message", this.handleMessage);
|
|
60
|
+
this.listeners.clear();
|
|
61
|
+
}
|
|
62
|
+
getTime() {
|
|
63
|
+
const date = new Date();
|
|
64
|
+
return `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}.${date.getMilliseconds()}`;
|
|
64
65
|
}
|
|
65
|
-
this.target.window.postMessage({
|
|
66
|
-
type: fullType,
|
|
67
|
-
payload
|
|
68
|
-
}, this.target.origin);
|
|
69
|
-
}
|
|
70
|
-
dispose() {
|
|
71
|
-
this.source.window.removeEventListener("message", this.handleMessage);
|
|
72
|
-
this.listeners.clear();
|
|
73
|
-
}
|
|
74
|
-
getTime() {
|
|
75
|
-
const date = new Date();
|
|
76
|
-
return `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}.${date.getMilliseconds()}`;
|
|
77
|
-
}
|
|
78
66
|
}
|
|
67
|
+
export { Messenger };
|
|
79
68
|
|
|
80
69
|
//# sourceMappingURL=Messenger.js.map
|