@cntrl-site/sdk-nextjs 1.9.14-6 → 1.9.15
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/lib/ItemGeometry/GenericGeometryController.js +2 -15
- package/lib/ItemGeometry/RichTextGeometryController.js +0 -26
- package/lib/components/items/RichTextItem/RichTextItem.js +1 -2
- package/package.json +1 -1
- package/src/ItemGeometry/GenericGeometryController.ts +3 -15
- package/src/ItemGeometry/RichTextGeometryController.ts +0 -30
- package/src/components/items/RichTextItem/RichTextItem.tsx +1 -2
|
@@ -32,25 +32,12 @@ class GenericGeometryController {
|
|
|
32
32
|
this.angle = angle;
|
|
33
33
|
}
|
|
34
34
|
setOptions(options) {
|
|
35
|
-
// no options
|
|
36
35
|
}
|
|
37
36
|
getAngle() {
|
|
38
|
-
return
|
|
37
|
+
return 0;
|
|
39
38
|
}
|
|
40
39
|
getScale() {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
getParentAngle() {
|
|
44
|
-
if (!this.registry || !this.parentId)
|
|
45
|
-
return 0;
|
|
46
|
-
const parentController = this.registry.getControllerById(this.parentId);
|
|
47
|
-
return parentController.getAngle();
|
|
48
|
-
}
|
|
49
|
-
getParentScale() {
|
|
50
|
-
if (!this.registry || !this.parentId)
|
|
51
|
-
return 1;
|
|
52
|
-
const parentController = this.registry.getControllerById(this.parentId);
|
|
53
|
-
return parentController.getScale();
|
|
40
|
+
return 1;
|
|
54
41
|
}
|
|
55
42
|
}
|
|
56
43
|
exports.GenericGeometryController = GenericGeometryController;
|
|
@@ -95,32 +95,6 @@ class RichTextGeometryController {
|
|
|
95
95
|
const content = new sdk_1.Rect(boundary.left + left, boundary.top + top, right - left, bottom - top);
|
|
96
96
|
return content;
|
|
97
97
|
}
|
|
98
|
-
getBaselines() {
|
|
99
|
-
const boundary = this.getBoundary();
|
|
100
|
-
const contentBoundary = this.getContentBoundary();
|
|
101
|
-
const offsetY = contentBoundary.top - boundary.top;
|
|
102
|
-
const baselines = [];
|
|
103
|
-
(0, domDfs_1.domDfs)(Array.from(this.container.children), (el) => {
|
|
104
|
-
var _a, _b;
|
|
105
|
-
if (el.children.length !== 0)
|
|
106
|
-
return;
|
|
107
|
-
const rects = el.getClientRects();
|
|
108
|
-
const styles = window.getComputedStyle(el);
|
|
109
|
-
const isTextCentered = styles.textAlign === 'center';
|
|
110
|
-
const ls = RichTextGeometryController.parseCssValue(styles.letterSpacing);
|
|
111
|
-
const metrics = (0, sdk_1.measureFont)(this.getFontStr(styles), (_b = (_a = el.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '');
|
|
112
|
-
const { baseline, fontBoxHeight, rightMargin } = metrics;
|
|
113
|
-
for (let i = 0; i <= rects.length - 1; i += 1) {
|
|
114
|
-
const rect = rects[i];
|
|
115
|
-
const halfLead = (rect.height - fontBoxHeight) / 2;
|
|
116
|
-
baselines.push({
|
|
117
|
-
xEnd: isTextCentered ? boundary.width : rect.right - rightMargin - ls - boundary.left,
|
|
118
|
-
y: rect.top + halfLead + baseline - boundary.top - offsetY
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
return baselines;
|
|
123
|
-
}
|
|
124
98
|
getFontStr(styles) {
|
|
125
99
|
const fontSize = (0, CSSNumeric_1.parseCSSNumber)(styles.fontSize);
|
|
126
100
|
const lineHeight = (0, CSSNumeric_1.parseCSSNumber)(styles.lineHeight);
|
|
@@ -27,12 +27,11 @@ const RichTextItem = ({ item, sectionId, onResize, interactionCtrl, onVisibility
|
|
|
27
27
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
28
28
|
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
29
29
|
const { blur: itemBlur, wordSpacing: itemWordSpacing, letterSpacing: itemLetterSpacing, color: itemColor, fontSize, lineHeight, xSizing } = (0, useRichTextItemValues_1.useRichTextItemValues)(item, sectionId);
|
|
30
|
-
const geometryOptions = (0, react_1.useMemo)(() => ({ xSizing }), [xSizing]);
|
|
31
30
|
const layoutValues = [item.area, item.layoutParams];
|
|
32
31
|
const exemplary = (0, useExemplary_1.useExemplary)();
|
|
33
32
|
const { layoutId } = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
34
33
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
35
|
-
const geometry = (0, useItemGeometry_1.useItemGeometry)(item.id, ref, RichTextGeometryController_1.RichTextGeometryController,
|
|
34
|
+
const geometry = (0, useItemGeometry_1.useItemGeometry)(item.id, ref, RichTextGeometryController_1.RichTextGeometryController, { xSizing });
|
|
36
35
|
geometry === null || geometry === void 0 ? void 0 : geometry.setAngle(itemAngle);
|
|
37
36
|
const stateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color']);
|
|
38
37
|
const stateStyles = (_a = stateParams === null || stateParams === void 0 ? void 0 : stateParams.styles) !== null && _a !== void 0 ? _a : {};
|
package/package.json
CHANGED
|
@@ -46,26 +46,14 @@ export class GenericGeometryController implements ItemGeometryController {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
setOptions(options?: unknown) {
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
getAngle(): number {
|
|
53
|
-
return
|
|
53
|
+
return 0;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
getScale() {
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private getParentAngle() {
|
|
61
|
-
if (!this.registry || !this.parentId) return 0;
|
|
62
|
-
const parentController = this.registry.getControllerById(this.parentId);
|
|
63
|
-
return parentController.getAngle();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
getParentScale(): number {
|
|
67
|
-
if (!this.registry || !this.parentId) return 1;
|
|
68
|
-
const parentController = this.registry.getControllerById(this.parentId);
|
|
69
|
-
return parentController.getScale();
|
|
57
|
+
return 1;
|
|
70
58
|
}
|
|
71
59
|
}
|
|
@@ -12,11 +12,6 @@ interface RichTextGeometryOptions {
|
|
|
12
12
|
xSizing: SizingType;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
interface Baseline {
|
|
16
|
-
y: number;
|
|
17
|
-
xEnd: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
15
|
type GeomtryRegistry = {
|
|
21
16
|
getControllerById: (itemId: string) => ItemGeometryController;
|
|
22
17
|
};
|
|
@@ -130,31 +125,6 @@ export class RichTextGeometryController implements ItemGeometryController {
|
|
|
130
125
|
return content;
|
|
131
126
|
}
|
|
132
127
|
|
|
133
|
-
private getBaselines(): Baseline[] {
|
|
134
|
-
const boundary = this.getBoundary();
|
|
135
|
-
const contentBoundary = this.getContentBoundary();
|
|
136
|
-
const offsetY = contentBoundary.top - boundary.top;
|
|
137
|
-
const baselines: Baseline[] = [];
|
|
138
|
-
domDfs(Array.from(this.container.children), (el) => {
|
|
139
|
-
if (el.children.length !== 0) return;
|
|
140
|
-
const rects = el.getClientRects();
|
|
141
|
-
const styles = window.getComputedStyle(el);
|
|
142
|
-
const isTextCentered = styles.textAlign === 'center';
|
|
143
|
-
const ls = RichTextGeometryController.parseCssValue(styles.letterSpacing);
|
|
144
|
-
const metrics = measureFont(this.getFontStr(styles), el.textContent?.trim() ?? '');
|
|
145
|
-
const { baseline, fontBoxHeight, rightMargin } = metrics;
|
|
146
|
-
for (let i = 0; i <= rects.length - 1; i += 1) {
|
|
147
|
-
const rect = rects[i];
|
|
148
|
-
const halfLead = (rect.height - fontBoxHeight) / 2;
|
|
149
|
-
baselines.push({
|
|
150
|
-
xEnd: isTextCentered ? boundary.width : rect.right - rightMargin - ls - boundary.left,
|
|
151
|
-
y: rect.top + halfLead + baseline - boundary.top - offsetY
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
return baselines;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
128
|
private getFontStr(styles: CSSStyleDeclaration) {
|
|
159
129
|
const fontSize = parseCSSNumber(styles.fontSize);
|
|
160
130
|
const lineHeight = parseCSSNumber(styles.lineHeight);
|
|
@@ -29,12 +29,11 @@ export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, on
|
|
|
29
29
|
lineHeight,
|
|
30
30
|
xSizing
|
|
31
31
|
} = useRichTextItemValues(item, sectionId);
|
|
32
|
-
const geometryOptions = useMemo(() => ({ xSizing }), [xSizing]);
|
|
33
32
|
const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
|
|
34
33
|
const exemplary = useExemplary();
|
|
35
34
|
const { layoutId } = useCurrentLayout();
|
|
36
35
|
useRegisterResize(ref, onResize);
|
|
37
|
-
const geometry = useItemGeometry(item.id, ref, RichTextGeometryController,
|
|
36
|
+
const geometry = useItemGeometry(item.id, ref, RichTextGeometryController, { xSizing });
|
|
38
37
|
geometry?.setAngle(itemAngle!);
|
|
39
38
|
const stateParams = interactionCtrl?.getState<number | string>(['angle', 'blur', 'letterSpacing', 'wordSpacing', 'color']);
|
|
40
39
|
const stateStyles = stateParams?.styles ?? {};
|