km-card-layout-component-miniprogram 0.1.8 → 0.1.9
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/example/pages/home/index.js +107 -16
- package/miniprogram_dist/components/card-layout/elements/custom-element/index.js +27 -0
- package/miniprogram_dist/components/card-layout/elements/custom-element/index.json +3 -0
- package/miniprogram_dist/components/card-layout/elements/custom-element/index.wxml +5 -0
- package/miniprogram_dist/components/card-layout/elements/custom-element/index.wxss +14 -0
- package/miniprogram_dist/components/card-layout/elements/icon-element/index.js +39 -0
- package/miniprogram_dist/components/card-layout/elements/icon-element/index.json +3 -0
- package/miniprogram_dist/components/card-layout/elements/icon-element/index.wxml +5 -0
- package/miniprogram_dist/components/card-layout/elements/icon-element/index.wxss +37 -0
- package/miniprogram_dist/components/card-layout/elements/image-element/index.js +31 -0
- package/miniprogram_dist/components/card-layout/elements/image-element/index.json +3 -0
- package/miniprogram_dist/components/card-layout/elements/image-element/index.wxml +8 -0
- package/miniprogram_dist/components/card-layout/elements/image-element/index.wxss +10 -0
- package/miniprogram_dist/components/card-layout/elements/text-element/index.js +47 -0
- package/miniprogram_dist/components/card-layout/elements/text-element/index.json +3 -0
- package/miniprogram_dist/components/card-layout/elements/text-element/index.wxml +29 -0
- package/miniprogram_dist/components/card-layout/elements/text-element/index.wxss +59 -0
- package/miniprogram_dist/components/card-layout/index.js +19 -36
- package/miniprogram_dist/components/card-layout/index.json +7 -1
- package/miniprogram_dist/components/card-layout/index.wxml +15 -63
- package/miniprogram_dist/components/card-layout/index.wxss +0 -65
- package/miniprogram_dist/utils/card-schema.js +12 -3
- package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +4 -0
- package/miniprogram_dist/vendor/km-card-layout-core/index.js +37 -6
- package/miniprogram_dist/vendor/km-card-layout-core/interface/index.js +1 -1
- package/miniprogram_dist/vendor/km-card-layout-core/ops/changeBackground.js +8 -1
- package/miniprogram_dist/vendor/km-card-layout-core/render/helpers.js +133 -0
- package/miniprogram_dist/vendor/km-card-layout-core/render/tool.js +16 -0
- package/package.json +1 -1
- package/script/sync-core.js +3 -0
- package/src/components/card-layout/elements/custom-element/index.json +3 -0
- package/src/components/card-layout/elements/custom-element/index.ts +30 -0
- package/src/components/card-layout/elements/custom-element/index.wxml +5 -0
- package/src/components/card-layout/elements/custom-element/index.wxss +14 -0
- package/src/components/card-layout/elements/icon-element/index.json +3 -0
- package/src/components/card-layout/elements/icon-element/index.ts +42 -0
- package/src/components/card-layout/elements/icon-element/index.wxml +5 -0
- package/src/components/card-layout/elements/icon-element/index.wxss +37 -0
- package/src/components/card-layout/elements/image-element/index.json +3 -0
- package/src/components/card-layout/elements/image-element/index.ts +35 -0
- package/src/components/card-layout/elements/image-element/index.wxml +8 -0
- package/src/components/card-layout/elements/image-element/index.wxss +10 -0
- package/src/components/card-layout/elements/text-element/index.json +3 -0
- package/src/components/card-layout/elements/text-element/index.ts +52 -0
- package/src/components/card-layout/elements/text-element/index.wxml +29 -0
- package/src/components/card-layout/elements/text-element/index.wxss +59 -0
- package/src/components/card-layout/index.json +7 -1
- package/src/components/card-layout/index.ts +36 -45
- package/src/components/card-layout/index.wxml +15 -63
- package/src/components/card-layout/index.wxss +0 -65
- package/src/utils/card-schema.ts +11 -4
- package/src/vendor/km-card-layout-core/bindings.ts +3 -0
- package/src/vendor/km-card-layout-core/data.ts +2 -1
- package/src/vendor/km-card-layout-core/index.ts +37 -5
- package/src/vendor/km-card-layout-core/interface/context.ts +6 -0
- package/src/vendor/km-card-layout-core/interface/data/payload.ts +1 -0
- package/src/vendor/km-card-layout-core/interface/index.ts +2 -2
- package/src/vendor/km-card-layout-core/ops/changeBackground.ts +14 -4
- package/src/vendor/km-card-layout-core/render/helpers.ts +144 -0
- package/src/vendor/km-card-layout-core/render/tool.ts +21 -0
- package/src/vendor/km-card-layout-core/types.d.ts +71 -12
- package/src/vendor/km-card-layout-core/utils.ts +4 -0
- package/miniprogram_dist/vendor/km-card-layout-core/render/builder.js +0 -210
- package/src/vendor/km-card-layout-core/interface/render.ts +0 -53
- package/src/vendor/km-card-layout-core/render/builder.ts +0 -288
- /package/miniprogram_dist/vendor/km-card-layout-core/interface/{render.js → context.js} +0 -0
|
@@ -102,10 +102,9 @@ export const applySpecialStyle = (
|
|
|
102
102
|
const specialStyle = resolveSpecialStyle(el, background);
|
|
103
103
|
const baseStyle = { ...(el.style || {}) };
|
|
104
104
|
const isCustom = el.type === 'custom';
|
|
105
|
-
const hasExplicit =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
: baseStyle.color !== undefined && baseStyle.color !== null;
|
|
105
|
+
const hasExplicit = isCustom
|
|
106
|
+
? Boolean(baseStyle.backgroundColor || baseStyle.background)
|
|
107
|
+
: baseStyle.color !== undefined && baseStyle.color !== null;
|
|
109
108
|
|
|
110
109
|
const overrideExisting = options.overrideExisting === true;
|
|
111
110
|
const hasSpecial = Object.keys(specialStyle).length > 0;
|
|
@@ -167,3 +166,14 @@ export const updateElementsStyle = (
|
|
|
167
166
|
),
|
|
168
167
|
};
|
|
169
168
|
};
|
|
169
|
+
|
|
170
|
+
export const setElementVisible = (
|
|
171
|
+
layout: CardLayoutSchema[],
|
|
172
|
+
key: string,
|
|
173
|
+
visible: boolean
|
|
174
|
+
): CardLayoutSchema[] => {
|
|
175
|
+
return layout.map(la => ({
|
|
176
|
+
...la,
|
|
177
|
+
children: la.children.map(el => (el.key === key ? { ...el, visible } : el)),
|
|
178
|
+
}));
|
|
179
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { addUnit } from '../helpers';
|
|
2
|
+
import { getAbsLayout } from '../layout';
|
|
3
|
+
import type {
|
|
4
|
+
CardElement,
|
|
5
|
+
CardLayoutSchema,
|
|
6
|
+
IconElement,
|
|
7
|
+
ImageElement,
|
|
8
|
+
LayoutPanelElement,
|
|
9
|
+
TextElement,
|
|
10
|
+
} from '../interface';
|
|
11
|
+
|
|
12
|
+
export const buildWrapperStyle = (el: CardElement, unit: 'px' | 'rpx' = 'px') => {
|
|
13
|
+
const abs = getAbsLayout(el);
|
|
14
|
+
if (!abs) return {};
|
|
15
|
+
return {
|
|
16
|
+
position: 'absolute',
|
|
17
|
+
left: addUnit(abs.x, unit),
|
|
18
|
+
top: addUnit(abs.y, unit),
|
|
19
|
+
width: addUnit(abs.width, unit),
|
|
20
|
+
height: addUnit(abs.height, unit),
|
|
21
|
+
zIndex: abs.zIndex,
|
|
22
|
+
boxSizing: 'border-box',
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const buildCardStyle = (layout: CardLayoutSchema, unit: 'px' | 'rpx' = 'px') => ({
|
|
27
|
+
width: addUnit(layout.width, unit),
|
|
28
|
+
height: addUnit(layout.height, unit),
|
|
29
|
+
color: layout.fontColor,
|
|
30
|
+
borderRadius:
|
|
31
|
+
layout.borderRadius !== undefined
|
|
32
|
+
? addUnit(layout.borderRadius, unit)
|
|
33
|
+
: undefined,
|
|
34
|
+
padding:
|
|
35
|
+
layout.padding !== undefined ? addUnit(layout.padding, unit) : undefined,
|
|
36
|
+
position: 'relative',
|
|
37
|
+
overflow: 'hidden',
|
|
38
|
+
boxSizing: 'border-box',
|
|
39
|
+
backgroundColor: 'transparent',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const buildBackgroundStyle = (layout: CardLayoutSchema, unit: 'px' | 'rpx' = 'px') => ({
|
|
43
|
+
zIndex: layout.backgroundZIndex,
|
|
44
|
+
borderRadius:
|
|
45
|
+
layout.borderRadius !== undefined
|
|
46
|
+
? addUnit(layout.borderRadius, unit)
|
|
47
|
+
: undefined,
|
|
48
|
+
width: '100%',
|
|
49
|
+
height: '100%',
|
|
50
|
+
position: 'absolute',
|
|
51
|
+
left: 0,
|
|
52
|
+
top: 0,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const buildBaseContentStyle = (el: CardElement) => ({
|
|
56
|
+
...(el.style || {}),
|
|
57
|
+
boxSizing: 'border-box',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const buildPanelContentStyle = (el: LayoutPanelElement, unit: 'px' | 'rpx' = 'px') => ({
|
|
61
|
+
position: 'relative',
|
|
62
|
+
width: '100%',
|
|
63
|
+
height: '100%',
|
|
64
|
+
display: 'block',
|
|
65
|
+
boxSizing: 'border-box',
|
|
66
|
+
...(el.style || {}),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const buildTextContentStyle = (el: TextElement, unit: 'px' | 'rpx' = 'px') => {
|
|
70
|
+
const textAlign =
|
|
71
|
+
(el.style?.textAlign as string | undefined) || el.align || undefined;
|
|
72
|
+
const style: Record<string, any> = {
|
|
73
|
+
...(el.style || {}),
|
|
74
|
+
fontSize: addUnit(el.style?.fontSize, unit),
|
|
75
|
+
whiteSpace: 'pre-wrap',
|
|
76
|
+
wordBreak: 'break-word',
|
|
77
|
+
lineHeight:
|
|
78
|
+
el.style?.lineHeight !== undefined && el.style?.lineHeight !== null
|
|
79
|
+
? addUnit(el.style.lineHeight as any, unit)
|
|
80
|
+
: '1',
|
|
81
|
+
};
|
|
82
|
+
if (textAlign) style.textAlign = textAlign;
|
|
83
|
+
return style;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const buildImageContentStyle = (el: ImageElement) => {
|
|
87
|
+
const style: Record<string, any> = { ...(el.style || {}) };
|
|
88
|
+
const borderWidth = Number(style.borderWidth);
|
|
89
|
+
if (Number.isFinite(borderWidth) && borderWidth > 0) {
|
|
90
|
+
if (!style.borderStyle) style.borderStyle = 'solid';
|
|
91
|
+
if (!style.borderColor) style.borderColor = '#000000';
|
|
92
|
+
}
|
|
93
|
+
return style;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const getTextValue = (el: TextElement) =>
|
|
97
|
+
el.defaultValue !== undefined && el.defaultValue !== null
|
|
98
|
+
? `${el.defaultValue}`
|
|
99
|
+
: '';
|
|
100
|
+
|
|
101
|
+
export const getImageSrc = (el: ImageElement) =>
|
|
102
|
+
el.defaultUrl || el.defaultValue || '';
|
|
103
|
+
|
|
104
|
+
export const getIconName = (el: IconElement) =>
|
|
105
|
+
(el.name || el.defaultValue || '') as string;
|
|
106
|
+
|
|
107
|
+
export const buildTextIconMeta = (el: TextElement, unit: 'px' | 'rpx' = 'px') => {
|
|
108
|
+
const icon = el.icon;
|
|
109
|
+
const enabled = icon?.enable === true;
|
|
110
|
+
if (!icon || !enabled) return null;
|
|
111
|
+
|
|
112
|
+
const style = icon.style || 'fill';
|
|
113
|
+
const baseName = icon.name || el.key || el.binding || el.id;
|
|
114
|
+
let name: string | undefined;
|
|
115
|
+
if (style === 'dot') name = 'round';
|
|
116
|
+
else if (style === 'line') name = baseName ? `${baseName}-line` : undefined;
|
|
117
|
+
else name = baseName || undefined;
|
|
118
|
+
if (!name) return null;
|
|
119
|
+
|
|
120
|
+
const size =
|
|
121
|
+
icon.size !== undefined && icon.size !== null
|
|
122
|
+
? icon.size
|
|
123
|
+
: (el.style?.fontSize as any);
|
|
124
|
+
const gap = icon.gap !== undefined && icon.gap !== null ? icon.gap : 4;
|
|
125
|
+
const color =
|
|
126
|
+
icon.color ??
|
|
127
|
+
((typeof el.style?.color === 'string' ? el.style.color : undefined) as
|
|
128
|
+
| string
|
|
129
|
+
| undefined);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
name: `${name}`,
|
|
133
|
+
size: addUnit(size as any, unit),
|
|
134
|
+
gap: addUnit(gap as any, unit),
|
|
135
|
+
color,
|
|
136
|
+
align: icon.align || 'left',
|
|
137
|
+
wrapperStyle: {
|
|
138
|
+
height:
|
|
139
|
+
el.style?.lineHeight !== undefined && el.style?.lineHeight !== null
|
|
140
|
+
? addUnit(el.style.lineHeight, unit)
|
|
141
|
+
: el.style?.fontSize,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CardLayoutSchema, TemplateItem } from '../interface';
|
|
2
|
+
import { backgroundChange, setElementVisible } from '../ops/changeBackground';
|
|
3
|
+
import { Config } from '../types';
|
|
4
|
+
import { applyItemCollectBindings } from '../utils';
|
|
5
|
+
|
|
6
|
+
export function buildRenderData(
|
|
7
|
+
layout: CardLayoutSchema[],
|
|
8
|
+
items: TemplateItem[],
|
|
9
|
+
config: Config
|
|
10
|
+
): CardLayoutSchema[] {
|
|
11
|
+
// 绑定数据
|
|
12
|
+
let renderLayout = applyItemCollectBindings(layout, items);
|
|
13
|
+
// 设置显示逻辑
|
|
14
|
+
renderLayout = setElementVisible(renderLayout, 'image', config.showAvatar);
|
|
15
|
+
renderLayout = setElementVisible(renderLayout, 'logo', config.showLogo);
|
|
16
|
+
// 设置背景
|
|
17
|
+
renderLayout = renderLayout.map((la, index) =>
|
|
18
|
+
config.currentBg[index] ? backgroundChange(config.currentBg[index], la) : la
|
|
19
|
+
);
|
|
20
|
+
return renderLayout;
|
|
21
|
+
}
|
|
@@ -10,10 +10,19 @@ import type {
|
|
|
10
10
|
CardElement,
|
|
11
11
|
CardLayoutInput,
|
|
12
12
|
CardLayoutSchema,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
TemplateItem,
|
|
14
|
+
TemplateBackground
|
|
15
15
|
} from './interface';
|
|
16
16
|
|
|
17
|
+
export type Config = {
|
|
18
|
+
showAvatar: boolean;
|
|
19
|
+
showLogo: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* 当前背景 (0 为正面背景 1 为背面背景)
|
|
22
|
+
*/
|
|
23
|
+
currentBg: TemplateBackground[];
|
|
24
|
+
};
|
|
25
|
+
|
|
17
26
|
export function addUnit(
|
|
18
27
|
value: string | number | undefined | null,
|
|
19
28
|
unit: 'px' | 'rpx'
|
|
@@ -137,15 +146,65 @@ export function updateElementsStyle(
|
|
|
137
146
|
updates: Record<string, any>
|
|
138
147
|
): CardLayoutSchema;
|
|
139
148
|
|
|
140
|
-
export function
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
export function buildWrapperStyle(
|
|
150
|
+
el: CardElement,
|
|
151
|
+
unit?: 'px' | 'rpx'
|
|
152
|
+
): Record<string, any>;
|
|
153
|
+
|
|
154
|
+
export function buildCardStyle(
|
|
155
|
+
layout: CardLayoutSchema,
|
|
156
|
+
unit?: 'px' | 'rpx'
|
|
157
|
+
): Record<string, any>;
|
|
158
|
+
|
|
159
|
+
export function buildBackgroundStyle(
|
|
160
|
+
layout: CardLayoutSchema,
|
|
161
|
+
unit?: 'px' | 'rpx'
|
|
162
|
+
): Record<string, any>;
|
|
163
|
+
|
|
164
|
+
export function buildBaseContentStyle(
|
|
165
|
+
el: CardElement
|
|
166
|
+
): Record<string, any>;
|
|
146
167
|
|
|
147
|
-
export function
|
|
148
|
-
|
|
149
|
-
data: Record<string, any>,
|
|
168
|
+
export function buildPanelContentStyle(
|
|
169
|
+
el: import('./interface/elements').LayoutPanelElement,
|
|
150
170
|
unit?: 'px' | 'rpx'
|
|
151
|
-
):
|
|
171
|
+
): Record<string, any>;
|
|
172
|
+
|
|
173
|
+
export function buildTextContentStyle(
|
|
174
|
+
el: import('./interface/elements').TextElement,
|
|
175
|
+
unit?: 'px' | 'rpx'
|
|
176
|
+
): Record<string, any>;
|
|
177
|
+
|
|
178
|
+
export function buildImageContentStyle(
|
|
179
|
+
el: import('./interface/elements').ImageElement
|
|
180
|
+
): Record<string, any>;
|
|
181
|
+
|
|
182
|
+
export function getTextValue(
|
|
183
|
+
el: import('./interface/elements').TextElement
|
|
184
|
+
): string;
|
|
185
|
+
|
|
186
|
+
export function getImageSrc(
|
|
187
|
+
el: import('./interface/elements').ImageElement
|
|
188
|
+
): string;
|
|
189
|
+
|
|
190
|
+
export function getIconName(
|
|
191
|
+
el: import('./interface/elements').IconElement
|
|
192
|
+
): string;
|
|
193
|
+
|
|
194
|
+
export function buildTextIconMeta(
|
|
195
|
+
el: import('./interface/elements').TextElement,
|
|
196
|
+
unit?: 'px' | 'rpx'
|
|
197
|
+
): {
|
|
198
|
+
name: string;
|
|
199
|
+
size?: string;
|
|
200
|
+
gap?: string;
|
|
201
|
+
color?: string;
|
|
202
|
+
align: 'left' | 'right';
|
|
203
|
+
wrapperStyle?: Record<string, any>;
|
|
204
|
+
} | null;
|
|
205
|
+
|
|
206
|
+
export function buildRenderData (
|
|
207
|
+
layout: CardLayoutSchema[],
|
|
208
|
+
items: TemplateItem[],
|
|
209
|
+
config: Config
|
|
210
|
+
): CardLayoutSchema[];
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildRenderResult = exports.buildRenderNodes = void 0;
|
|
4
|
-
const helpers_1 = require("../helpers");
|
|
5
|
-
const layout_1 = require("../layout");
|
|
6
|
-
const data_1 = require("../data");
|
|
7
|
-
const buildCardStyle = (layout, unit) => (0, helpers_1.styleObjectToString)({
|
|
8
|
-
width: (0, helpers_1.addUnit)(layout.width, unit),
|
|
9
|
-
height: (0, helpers_1.addUnit)(layout.height, unit),
|
|
10
|
-
color: layout.fontColor,
|
|
11
|
-
borderRadius: layout.borderRadius !== undefined
|
|
12
|
-
? (0, helpers_1.addUnit)(layout.borderRadius, unit)
|
|
13
|
-
: undefined,
|
|
14
|
-
padding: layout.padding !== undefined ? (0, helpers_1.addUnit)(layout.padding, unit) : undefined,
|
|
15
|
-
position: 'relative',
|
|
16
|
-
overflow: 'hidden',
|
|
17
|
-
boxSizing: 'border-box',
|
|
18
|
-
backgroundColor: 'transparent',
|
|
19
|
-
}, unit);
|
|
20
|
-
const buildBackgroundStyle = (layout, unit) => (0, helpers_1.styleObjectToString)({
|
|
21
|
-
zIndex: layout.backgroundZIndex,
|
|
22
|
-
borderRadius: layout.borderRadius !== undefined
|
|
23
|
-
? (0, helpers_1.addUnit)(layout.borderRadius, unit)
|
|
24
|
-
: undefined,
|
|
25
|
-
width: '100%',
|
|
26
|
-
height: '100%',
|
|
27
|
-
position: 'absolute',
|
|
28
|
-
left: 0,
|
|
29
|
-
top: 0,
|
|
30
|
-
}, unit);
|
|
31
|
-
const buildWrapperStyle = (el, unit) => {
|
|
32
|
-
const abs = (0, layout_1.getAbsLayout)(el);
|
|
33
|
-
if (!abs)
|
|
34
|
-
return '';
|
|
35
|
-
return (0, helpers_1.styleObjectToString)({
|
|
36
|
-
position: 'absolute',
|
|
37
|
-
left: (0, helpers_1.addUnit)(abs.x, unit),
|
|
38
|
-
top: (0, helpers_1.addUnit)(abs.y, unit),
|
|
39
|
-
width: (0, helpers_1.addUnit)(abs.width, unit),
|
|
40
|
-
height: (0, helpers_1.addUnit)(abs.height, unit),
|
|
41
|
-
zIndex: abs.zIndex,
|
|
42
|
-
boxSizing: 'border-box',
|
|
43
|
-
}, unit);
|
|
44
|
-
};
|
|
45
|
-
const buildPanelContentStyle = (el, unit) => (0, helpers_1.styleObjectToString)({
|
|
46
|
-
position: 'relative',
|
|
47
|
-
width: '100%',
|
|
48
|
-
height: '100%',
|
|
49
|
-
display: 'block',
|
|
50
|
-
boxSizing: 'border-box',
|
|
51
|
-
...(el.style || {}),
|
|
52
|
-
}, unit);
|
|
53
|
-
const buildTextContentStyle = (el, unit) => {
|
|
54
|
-
var _a, _b, _c;
|
|
55
|
-
const textAlign = ((_a = el.style) === null || _a === void 0 ? void 0 : _a.textAlign) || el.align || undefined;
|
|
56
|
-
const style = {
|
|
57
|
-
...(el.style || {}),
|
|
58
|
-
whiteSpace: 'pre-wrap',
|
|
59
|
-
wordBreak: 'break-word',
|
|
60
|
-
lineHeight: ((_b = el.style) === null || _b === void 0 ? void 0 : _b.lineHeight) !== undefined && ((_c = el.style) === null || _c === void 0 ? void 0 : _c.lineHeight) !== null
|
|
61
|
-
? el.style.lineHeight
|
|
62
|
-
: '1',
|
|
63
|
-
};
|
|
64
|
-
if (textAlign)
|
|
65
|
-
style.textAlign = textAlign;
|
|
66
|
-
return (0, helpers_1.styleObjectToString)(style, unit);
|
|
67
|
-
};
|
|
68
|
-
const buildBaseContentStyle = (el, unit) => (0, helpers_1.styleObjectToString)({
|
|
69
|
-
...(el.style || {}),
|
|
70
|
-
boxSizing: 'border-box',
|
|
71
|
-
}, unit);
|
|
72
|
-
const buildImageContentStyle = (el, unit) => {
|
|
73
|
-
const style = { ...(el.style || {}) };
|
|
74
|
-
const borderWidth = Number(style.borderWidth);
|
|
75
|
-
if (Number.isFinite(borderWidth) && borderWidth > 0) {
|
|
76
|
-
if (!style.borderStyle)
|
|
77
|
-
style.borderStyle = 'solid';
|
|
78
|
-
if (!style.borderColor)
|
|
79
|
-
style.borderColor = '#000000';
|
|
80
|
-
}
|
|
81
|
-
return (0, helpers_1.styleObjectToString)(style, unit);
|
|
82
|
-
};
|
|
83
|
-
const buildTextIcon = (el, unit) => {
|
|
84
|
-
var _a, _b, _c, _d;
|
|
85
|
-
const icon = el.icon;
|
|
86
|
-
if (!icon || icon.enable === false)
|
|
87
|
-
return undefined;
|
|
88
|
-
const style = icon.style || 'fill';
|
|
89
|
-
const baseName = el.key || el.binding || el.id;
|
|
90
|
-
let name;
|
|
91
|
-
if (style === 'dot')
|
|
92
|
-
name = 'round';
|
|
93
|
-
else if (style === 'line')
|
|
94
|
-
name = baseName ? `${baseName}-line` : undefined;
|
|
95
|
-
else
|
|
96
|
-
name = baseName || undefined;
|
|
97
|
-
if (!name)
|
|
98
|
-
return undefined;
|
|
99
|
-
const size = icon.size !== undefined && icon.size !== null
|
|
100
|
-
? icon.size
|
|
101
|
-
: (_a = el.style) === null || _a === void 0 ? void 0 : _a.fontSize;
|
|
102
|
-
const gap = icon.gap !== undefined && icon.gap !== null ? icon.gap : 4;
|
|
103
|
-
const color = (_b = icon.color) !== null && _b !== void 0 ? _b : (typeof ((_c = el.style) === null || _c === void 0 ? void 0 : _c.color) === 'string' ? el.style.color : undefined);
|
|
104
|
-
return {
|
|
105
|
-
name: `${name}`,
|
|
106
|
-
text: `${name}`,
|
|
107
|
-
size: (0, helpers_1.addUnit)(size, unit),
|
|
108
|
-
gap: (0, helpers_1.addUnit)(gap, unit),
|
|
109
|
-
color: color,
|
|
110
|
-
align: icon.align || 'left',
|
|
111
|
-
wrapperStyle: (0, helpers_1.styleObjectToString)({
|
|
112
|
-
display: 'inline-flex',
|
|
113
|
-
alignItems: 'center',
|
|
114
|
-
height: ((_d = el.style) === null || _d === void 0 ? void 0 : _d.lineHeight) || '1',
|
|
115
|
-
}, unit),
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
const buildNode = (el, rootData, unit, context) => {
|
|
119
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
120
|
-
if (!el || el.visible === false)
|
|
121
|
-
return null;
|
|
122
|
-
const wrapperStyle = buildWrapperStyle(el, unit);
|
|
123
|
-
if (el.type === 'layout-panel') {
|
|
124
|
-
return {
|
|
125
|
-
id: el.id,
|
|
126
|
-
type: el.type,
|
|
127
|
-
visible: el.visible,
|
|
128
|
-
wrapperStyle,
|
|
129
|
-
contentStyle: buildPanelContentStyle(el, unit),
|
|
130
|
-
children: (0, exports.buildRenderNodes)(el.children || [], rootData, unit, context),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
const baseStyle = buildBaseContentStyle(el, unit);
|
|
134
|
-
if (el.type === 'text') {
|
|
135
|
-
const value = (_b = (_a = (0, data_1.resolveBindingValue)(el.binding, rootData, context)) !== null && _a !== void 0 ? _a : el.defaultValue) !== null && _b !== void 0 ? _b : '';
|
|
136
|
-
return {
|
|
137
|
-
id: el.id,
|
|
138
|
-
type: el.type,
|
|
139
|
-
wrapperStyle,
|
|
140
|
-
contentStyle: buildTextContentStyle(el, unit),
|
|
141
|
-
text: `${value}`,
|
|
142
|
-
visible: el.visible,
|
|
143
|
-
icon: buildTextIcon(el, unit),
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
if (el.type === 'image') {
|
|
147
|
-
const src = (_e = (_d = (_c = (0, data_1.resolveBindingValue)(el.binding, rootData, context)) !== null && _c !== void 0 ? _c : el.defaultUrl) !== null && _d !== void 0 ? _d : el.defaultValue) !== null && _e !== void 0 ? _e : '';
|
|
148
|
-
const mode = el.fit === 'contain' ? 'aspectFit' : 'aspectFill';
|
|
149
|
-
return {
|
|
150
|
-
id: el.id,
|
|
151
|
-
type: el.type,
|
|
152
|
-
wrapperStyle,
|
|
153
|
-
contentStyle: buildImageContentStyle(el, unit),
|
|
154
|
-
src,
|
|
155
|
-
mode,
|
|
156
|
-
visible: el.visible,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (el.type === 'icon') {
|
|
160
|
-
const name = (_h = (_g = (_f = (0, data_1.resolveBindingValue)(el.binding, rootData, context)) !== null && _f !== void 0 ? _f : el.name) !== null && _g !== void 0 ? _g : el.defaultValue) !== null && _h !== void 0 ? _h : '';
|
|
161
|
-
return {
|
|
162
|
-
id: el.id,
|
|
163
|
-
type: el.type,
|
|
164
|
-
wrapperStyle,
|
|
165
|
-
contentStyle: baseStyle,
|
|
166
|
-
name: `${name}`,
|
|
167
|
-
text: `${name}`,
|
|
168
|
-
visible: el.visible,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
if (el.type === 'custom') {
|
|
172
|
-
return {
|
|
173
|
-
id: el.id,
|
|
174
|
-
type: el.type,
|
|
175
|
-
wrapperStyle,
|
|
176
|
-
contentStyle: baseStyle,
|
|
177
|
-
visible: el.visible,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
181
|
-
};
|
|
182
|
-
const buildRenderNodes = (children, rootData, unit = 'px', context = {}) => {
|
|
183
|
-
if (!Array.isArray(children))
|
|
184
|
-
return [];
|
|
185
|
-
const nodes = [];
|
|
186
|
-
children.forEach(el => {
|
|
187
|
-
if (!el || el.visible === false)
|
|
188
|
-
return;
|
|
189
|
-
const node = buildNode(el, rootData, unit, context);
|
|
190
|
-
if (node)
|
|
191
|
-
nodes.push(node);
|
|
192
|
-
});
|
|
193
|
-
return nodes;
|
|
194
|
-
};
|
|
195
|
-
exports.buildRenderNodes = buildRenderNodes;
|
|
196
|
-
const buildRenderResult = (layoutInput, dataInput, unit = 'px') => {
|
|
197
|
-
const layouts = (0, layout_1.normalizeLayout)(layoutInput);
|
|
198
|
-
return layouts.map(layout => {
|
|
199
|
-
const cardStyle = buildCardStyle(layout, unit);
|
|
200
|
-
const bgStyle = buildBackgroundStyle(layout, unit);
|
|
201
|
-
const renderTree = (0, exports.buildRenderNodes)(layout.children || [], dataInput || {}, unit);
|
|
202
|
-
return {
|
|
203
|
-
renderTree,
|
|
204
|
-
cardStyle,
|
|
205
|
-
backgroundImage: layout.backgroundImage || '',
|
|
206
|
-
backgroundStyle: bgStyle,
|
|
207
|
-
};
|
|
208
|
-
});
|
|
209
|
-
};
|
|
210
|
-
exports.buildRenderResult = buildRenderResult;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { CardElementType, CardElement } from './elements';
|
|
2
|
-
import type { CardLayoutInput, CardLayoutSchema } from './layout';
|
|
3
|
-
|
|
4
|
-
export interface RenderNodeIcon {
|
|
5
|
-
name: string;
|
|
6
|
-
text?: string;
|
|
7
|
-
size?: string;
|
|
8
|
-
color?: string;
|
|
9
|
-
gap?: string;
|
|
10
|
-
align?: 'left' | 'right';
|
|
11
|
-
wrapperStyle?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface RenderNode {
|
|
15
|
-
id: string;
|
|
16
|
-
type: CardElementType | 'text';
|
|
17
|
-
wrapperStyle: string;
|
|
18
|
-
contentStyle: string;
|
|
19
|
-
name?: string;
|
|
20
|
-
text?: string;
|
|
21
|
-
src?: string;
|
|
22
|
-
mode?: string;
|
|
23
|
-
children?: RenderNode[];
|
|
24
|
-
visible?: boolean;
|
|
25
|
-
icon?: RenderNodeIcon;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface RenderPageResult {
|
|
29
|
-
renderTree: RenderNode[];
|
|
30
|
-
cardStyle: string;
|
|
31
|
-
backgroundImage: string;
|
|
32
|
-
backgroundStyle: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type RenderResult = RenderPageResult[];
|
|
36
|
-
|
|
37
|
-
export interface BindingContext {
|
|
38
|
-
/**
|
|
39
|
-
* 当前上下文数据的绑定前缀(预留给嵌套场景)
|
|
40
|
-
*/
|
|
41
|
-
contextBinding?: string;
|
|
42
|
-
/**
|
|
43
|
-
* 当前上下文数据(预留给嵌套场景)
|
|
44
|
-
*/
|
|
45
|
-
contextData?: any;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type {
|
|
49
|
-
CardElement,
|
|
50
|
-
CardElementType,
|
|
51
|
-
CardLayoutInput,
|
|
52
|
-
CardLayoutSchema,
|
|
53
|
-
};
|