km-card-layout-component-miniprogram 0.1.7 → 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 +16 -201
- 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 -63
- package/miniprogram_dist/utils/card-schema.js +12 -3
- package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +78 -0
- package/miniprogram_dist/vendor/km-card-layout-core/data.js +38 -0
- package/miniprogram_dist/vendor/km-card-layout-core/helpers.js +72 -0
- package/miniprogram_dist/vendor/km-card-layout-core/index.js +46 -367
- package/miniprogram_dist/vendor/km-card-layout-core/interface/index.js +1 -1
- package/miniprogram_dist/vendor/km-card-layout-core/layout.js +117 -0
- package/miniprogram_dist/vendor/km-card-layout-core/ops/changeBackground.js +142 -0
- 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/miniprogram_dist/vendor/km-card-layout-core/utils.js +23 -130
- package/package.json +1 -1
- package/script/sync-core.js +13 -2
- 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 +30 -296
- package/src/components/card-layout/index.wxml +15 -63
- package/src/components/card-layout/index.wxss +0 -63
- package/src/utils/card-schema.ts +11 -4
- package/src/vendor/km-card-layout-core/bindings.ts +87 -0
- package/src/vendor/km-card-layout-core/data.ts +39 -0
- package/src/vendor/km-card-layout-core/helpers.ts +76 -0
- package/src/vendor/km-card-layout-core/index.ts +53 -460
- 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/layout.ts +129 -0
- package/src/vendor/km-card-layout-core/ops/changeBackground.ts +179 -0
- 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 +166 -15
- package/src/vendor/km-card-layout-core/utils.ts +13 -141
- package/src/vendor/km-card-layout-core/interface/render.ts +0 -52
- /package/miniprogram_dist/vendor/km-card-layout-core/interface/{render.js → context.js} +0 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { CardElement, CardLayoutSchema } from '../interface';
|
|
2
|
+
import type { TemplateBackground } from '../interface/data/payload';
|
|
3
|
+
|
|
4
|
+
type BackgroundColorMap = {
|
|
5
|
+
name: string | string[];
|
|
6
|
+
color: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type CoreBackgroundConfig = {
|
|
10
|
+
id?: string | number;
|
|
11
|
+
name?: string;
|
|
12
|
+
imageUrl?: string;
|
|
13
|
+
mainColor?: string;
|
|
14
|
+
specialColors?: BackgroundColorMap[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const toNameArray = (name?: string | string[]) => {
|
|
18
|
+
if (Array.isArray(name)) return name.filter(Boolean);
|
|
19
|
+
if (!name) return [];
|
|
20
|
+
return `${name}`
|
|
21
|
+
.split(',')
|
|
22
|
+
.map(n => n.trim())
|
|
23
|
+
.filter(Boolean);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function backgroundChange(
|
|
27
|
+
bg: TemplateBackground,
|
|
28
|
+
layout: CardLayoutSchema
|
|
29
|
+
): CardLayoutSchema {
|
|
30
|
+
const applySpecialColor = (el: CardElement): CardElement => {
|
|
31
|
+
const extras = bg.fontColorExtra || [];
|
|
32
|
+
if (!extras.length) return el;
|
|
33
|
+
|
|
34
|
+
const keys: string[] = [];
|
|
35
|
+
if (el.binding) keys.push(String(el.binding));
|
|
36
|
+
if (el.id) keys.push(String(el.id));
|
|
37
|
+
if (el.type === 'icon') keys.push('icon');
|
|
38
|
+
if (el.type === 'custom') keys.push('decor');
|
|
39
|
+
|
|
40
|
+
const matched = extras.find(sc =>
|
|
41
|
+
toNameArray(sc.name).some(n => keys.some(k => k?.startsWith(n)))
|
|
42
|
+
);
|
|
43
|
+
if (!matched) return el;
|
|
44
|
+
|
|
45
|
+
const baseStyle = { ...(el.style || {}) };
|
|
46
|
+
if (el.type === 'custom') {
|
|
47
|
+
return { ...el, style: { ...baseStyle, backgroundColor: matched.color } };
|
|
48
|
+
}
|
|
49
|
+
return { ...el, style: { ...baseStyle, color: matched.color } };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const traverse = (children: CardElement[] = []): CardElement[] =>
|
|
53
|
+
children.map(el => {
|
|
54
|
+
if (!el) return el;
|
|
55
|
+
if (el.type === 'layout-panel') {
|
|
56
|
+
return {
|
|
57
|
+
...el,
|
|
58
|
+
children: traverse(el.children || []),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return applySpecialColor(el);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
...layout,
|
|
66
|
+
backgroundImage: bg.imgUrl,
|
|
67
|
+
fontColor: bg.fontColor || layout.fontColor,
|
|
68
|
+
children: traverse(layout.children || []),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const DEFAULT_DECOR_COLOR = '#94a3b8';
|
|
73
|
+
|
|
74
|
+
export const resolveSpecialStyle = (
|
|
75
|
+
element: CardElement,
|
|
76
|
+
background?: CoreBackgroundConfig | null
|
|
77
|
+
) => {
|
|
78
|
+
if (!background) return {};
|
|
79
|
+
const keys: string[] = [];
|
|
80
|
+
if (element.binding) keys.push(String(element.binding));
|
|
81
|
+
if (element.id) keys.push(String(element.id));
|
|
82
|
+
if (element.type === 'icon') keys.push('icon');
|
|
83
|
+
if (element.type === 'custom') keys.push('decor');
|
|
84
|
+
|
|
85
|
+
const matched = background.specialColors?.find(sc => {
|
|
86
|
+
const names = toNameArray(sc.name);
|
|
87
|
+
return names.some(n => keys.some(k => k?.startsWith(n)));
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (!matched) return {};
|
|
91
|
+
if (element.type === 'custom') {
|
|
92
|
+
return { backgroundColor: matched.color };
|
|
93
|
+
}
|
|
94
|
+
return { color: matched.color };
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const applySpecialStyle = (
|
|
98
|
+
el: CardElement,
|
|
99
|
+
background: CoreBackgroundConfig | null = null,
|
|
100
|
+
options: { overrideExisting?: boolean; defaultDecorColor?: string } = {}
|
|
101
|
+
): CardElement => {
|
|
102
|
+
const specialStyle = resolveSpecialStyle(el, background);
|
|
103
|
+
const baseStyle = { ...(el.style || {}) };
|
|
104
|
+
const isCustom = el.type === 'custom';
|
|
105
|
+
const hasExplicit = isCustom
|
|
106
|
+
? Boolean(baseStyle.backgroundColor || baseStyle.background)
|
|
107
|
+
: baseStyle.color !== undefined && baseStyle.color !== null;
|
|
108
|
+
|
|
109
|
+
const overrideExisting = options.overrideExisting === true;
|
|
110
|
+
const hasSpecial = Object.keys(specialStyle).length > 0;
|
|
111
|
+
const defaultDecorColor = options.defaultDecorColor || DEFAULT_DECOR_COLOR;
|
|
112
|
+
|
|
113
|
+
if (hasSpecial) {
|
|
114
|
+
if (hasExplicit && !overrideExisting) return el;
|
|
115
|
+
return { ...el, style: { ...baseStyle, ...specialStyle } };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (overrideExisting && hasExplicit) {
|
|
119
|
+
const nextStyle = { ...baseStyle };
|
|
120
|
+
if (isCustom) {
|
|
121
|
+
nextStyle.backgroundColor = background?.mainColor || defaultDecorColor;
|
|
122
|
+
} else {
|
|
123
|
+
delete nextStyle.color;
|
|
124
|
+
}
|
|
125
|
+
return { ...el, style: nextStyle };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return el;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const applyBackground = (
|
|
132
|
+
layout: CardLayoutSchema,
|
|
133
|
+
background: CoreBackgroundConfig,
|
|
134
|
+
_options: {
|
|
135
|
+
previousBackground?: CoreBackgroundConfig | null;
|
|
136
|
+
defaultDecorColor?: string;
|
|
137
|
+
} = {}
|
|
138
|
+
): CardLayoutSchema => {
|
|
139
|
+
const bgId = Number(background.id);
|
|
140
|
+
const payload: TemplateBackground = {
|
|
141
|
+
id: Number.isFinite(bgId) ? bgId : 0,
|
|
142
|
+
name: background.name!,
|
|
143
|
+
imgUrl: background.imageUrl!,
|
|
144
|
+
fontColor: background.mainColor,
|
|
145
|
+
fontColorExtra:
|
|
146
|
+
background.specialColors?.map(sc => ({
|
|
147
|
+
name: sc.name,
|
|
148
|
+
color: sc.color,
|
|
149
|
+
})) || [],
|
|
150
|
+
};
|
|
151
|
+
return backgroundChange(payload, layout);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const updateElementsStyle = (
|
|
155
|
+
layout: CardLayoutSchema,
|
|
156
|
+
targetIds: string[],
|
|
157
|
+
updates: Record<string, any>
|
|
158
|
+
): CardLayoutSchema => {
|
|
159
|
+
const targets = new Set(targetIds);
|
|
160
|
+
return {
|
|
161
|
+
...layout,
|
|
162
|
+
children: layout.children.map(el =>
|
|
163
|
+
targets.has(el.id)
|
|
164
|
+
? { ...el, style: { ...(el.style || {}), ...updates } }
|
|
165
|
+
: el
|
|
166
|
+
),
|
|
167
|
+
};
|
|
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'
|
|
@@ -24,8 +33,37 @@ export function styleObjectToString(
|
|
|
24
33
|
unit?: 'px' | 'rpx'
|
|
25
34
|
): string;
|
|
26
35
|
|
|
36
|
+
export function toNumber(value: unknown): number | undefined;
|
|
37
|
+
|
|
38
|
+
export function isObject(
|
|
39
|
+
val: unknown
|
|
40
|
+
): val is Record<string, any> | any[];
|
|
41
|
+
|
|
27
42
|
export function normalizeLayout(layout: CardLayoutInput): CardLayoutSchema[];
|
|
28
43
|
|
|
44
|
+
export function sanitizeLayout(layout: CardLayoutSchema): CardLayoutSchema;
|
|
45
|
+
|
|
46
|
+
export function sanitizeElement(element: CardElement): CardElement;
|
|
47
|
+
|
|
48
|
+
export function roundToInt(value: number): number;
|
|
49
|
+
|
|
50
|
+
export function getAbsLayout(
|
|
51
|
+
el: CardElement
|
|
52
|
+
): import('./interface/elements').AbsoluteLayoutDefinition | null;
|
|
53
|
+
|
|
54
|
+
export function collectBindings(elements?: CardElement[]): string[];
|
|
55
|
+
|
|
56
|
+
export function normalizeId(
|
|
57
|
+
id?: string | number | null
|
|
58
|
+
): number | string | undefined;
|
|
59
|
+
|
|
60
|
+
export function parseLayout(input: unknown): CardLayoutSchema | null;
|
|
61
|
+
|
|
62
|
+
export function areChildrenEqual(
|
|
63
|
+
a?: CardLayoutSchema | null,
|
|
64
|
+
b?: CardLayoutSchema | null
|
|
65
|
+
): boolean;
|
|
66
|
+
|
|
29
67
|
export function resolveBindingValue(
|
|
30
68
|
binding: string | undefined,
|
|
31
69
|
rootData: Record<string, any>,
|
|
@@ -38,22 +76,135 @@ export function stripLayoutBindings(
|
|
|
38
76
|
|
|
39
77
|
export function applyItemCollectBindings(
|
|
40
78
|
layouts: CardLayoutSchema[],
|
|
41
|
-
items?: TemplateItem[]
|
|
79
|
+
items?: import('./interface/data/payload').TemplateItem[]
|
|
42
80
|
): CardLayoutSchema[];
|
|
43
81
|
|
|
44
|
-
export function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
82
|
+
export function getTemplateItems(
|
|
83
|
+
ids: string,
|
|
84
|
+
items: import('./interface/data/payload').TemplateItem[]
|
|
85
|
+
): import('./interface/data/payload').TemplateItem[];
|
|
86
|
+
|
|
87
|
+
export function getTemplateBackgrounds(
|
|
88
|
+
ids: string,
|
|
89
|
+
items: import('./interface/data/payload').TemplateBackground[]
|
|
90
|
+
): import('./interface/data/payload').TemplateBackground[];
|
|
91
|
+
|
|
92
|
+
export function backgroundChange(
|
|
93
|
+
bg: import('./interface/data/payload').TemplateBackground,
|
|
94
|
+
layout: CardLayoutSchema
|
|
95
|
+
): CardLayoutSchema;
|
|
96
|
+
|
|
97
|
+
export const DEFAULT_DECOR_COLOR: string;
|
|
98
|
+
|
|
99
|
+
export function resolveSpecialStyle(
|
|
100
|
+
element: CardElement,
|
|
101
|
+
background?: {
|
|
102
|
+
id?: string | number;
|
|
103
|
+
name?: string;
|
|
104
|
+
imageUrl?: string;
|
|
105
|
+
mainColor?: string;
|
|
106
|
+
specialColors?: { name: string | string[]; color: string }[];
|
|
107
|
+
} | null
|
|
108
|
+
): Record<string, any>;
|
|
109
|
+
|
|
110
|
+
export function applySpecialStyle(
|
|
111
|
+
element: CardElement,
|
|
112
|
+
background?: {
|
|
113
|
+
id?: string | number;
|
|
114
|
+
name?: string;
|
|
115
|
+
imageUrl?: string;
|
|
116
|
+
mainColor?: string;
|
|
117
|
+
specialColors?: { name: string | string[]; color: string }[];
|
|
118
|
+
} | null,
|
|
119
|
+
options?: { overrideExisting?: boolean; defaultDecorColor?: string }
|
|
120
|
+
): CardElement;
|
|
121
|
+
|
|
122
|
+
export function applyBackground(
|
|
123
|
+
layout: CardLayoutSchema,
|
|
124
|
+
background: {
|
|
125
|
+
id?: string | number;
|
|
126
|
+
name?: string;
|
|
127
|
+
imageUrl?: string;
|
|
128
|
+
mainColor?: string;
|
|
129
|
+
specialColors?: { name: string | string[]; color: string }[];
|
|
130
|
+
},
|
|
131
|
+
options?: {
|
|
132
|
+
previousBackground?: {
|
|
133
|
+
id?: string | number;
|
|
134
|
+
name?: string;
|
|
135
|
+
imageUrl?: string;
|
|
136
|
+
mainColor?: string;
|
|
137
|
+
specialColors?: { name: string | string[]; color: string }[];
|
|
138
|
+
} | null;
|
|
139
|
+
defaultDecorColor?: string;
|
|
140
|
+
}
|
|
141
|
+
): CardLayoutSchema;
|
|
142
|
+
|
|
143
|
+
export function updateElementsStyle(
|
|
144
|
+
layout: CardLayoutSchema,
|
|
145
|
+
targetIds: string[],
|
|
146
|
+
updates: Record<string, any>
|
|
147
|
+
): CardLayoutSchema;
|
|
50
148
|
|
|
51
|
-
export function
|
|
52
|
-
|
|
53
|
-
data: Record<string, any>,
|
|
149
|
+
export function buildWrapperStyle(
|
|
150
|
+
el: CardElement,
|
|
54
151
|
unit?: 'px' | 'rpx'
|
|
55
|
-
):
|
|
152
|
+
): Record<string, any>;
|
|
56
153
|
|
|
57
|
-
export function
|
|
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>;
|
|
167
|
+
|
|
168
|
+
export function buildPanelContentStyle(
|
|
169
|
+
el: import('./interface/elements').LayoutPanelElement,
|
|
170
|
+
unit?: 'px' | 'rpx'
|
|
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>;
|
|
58
181
|
|
|
59
|
-
export function
|
|
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,141 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.map(n => n.trim())
|
|
15
|
-
.filter(Boolean);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const applySpecialColor = (el: CardElement): CardElement => {
|
|
19
|
-
const extras = bg.fontColorExtra || [];
|
|
20
|
-
if (!extras.length) return el;
|
|
21
|
-
|
|
22
|
-
const keys: string[] = [];
|
|
23
|
-
if (el.binding) keys.push(String(el.binding));
|
|
24
|
-
if (el.id) keys.push(String(el.id));
|
|
25
|
-
if (el.type === 'icon') keys.push('icon');
|
|
26
|
-
if (el.type === 'custom') keys.push('decor');
|
|
27
|
-
|
|
28
|
-
const matched = extras.find(sc =>
|
|
29
|
-
toNameArray(sc.name).some(n => keys.some(k => k?.startsWith(n)))
|
|
30
|
-
);
|
|
31
|
-
if (!matched) return el;
|
|
32
|
-
|
|
33
|
-
const baseStyle = { ...(el.style || {}) };
|
|
34
|
-
if (el.type === 'custom') {
|
|
35
|
-
return { ...el, style: { ...baseStyle, backgroundColor: matched.color } };
|
|
36
|
-
}
|
|
37
|
-
return { ...el, style: { ...baseStyle, color: matched.color } };
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const traverse = (children: CardElement[] = []): CardElement[] =>
|
|
41
|
-
children.map(el => {
|
|
42
|
-
if (!el) return el;
|
|
43
|
-
if (el.type === 'layout-panel') {
|
|
44
|
-
return {
|
|
45
|
-
...el,
|
|
46
|
-
children: traverse(el.children || []),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return applySpecialColor(el);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
...layout,
|
|
54
|
-
backgroundImage: bg.imgUrl,
|
|
55
|
-
fontColor: bg.fontColor || layout.fontColor,
|
|
56
|
-
children: traverse(layout.children || []),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function stripLayoutBindings(
|
|
61
|
-
layouts: CardLayoutSchema[] = []
|
|
62
|
-
): CardLayoutSchema[] {
|
|
63
|
-
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
64
|
-
const stripElement = (el: CardElement): CardElement => {
|
|
65
|
-
const { binding: _b, defaultValue: _d, ...rest } = el as any;
|
|
66
|
-
if (el.type === 'layout-panel') {
|
|
67
|
-
return {
|
|
68
|
-
...rest,
|
|
69
|
-
children: (el.children || []).map(stripElement),
|
|
70
|
-
} as CardElement;
|
|
71
|
-
}
|
|
72
|
-
return rest as CardElement;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return targetLayouts.map(layout => ({
|
|
76
|
-
...layout,
|
|
77
|
-
children: (layout.children || []).map(stripElement),
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 应用元素数据绑定字段
|
|
83
|
-
* @param layouts 布局
|
|
84
|
-
* @param items 绑定元素数据
|
|
85
|
-
* @returns
|
|
86
|
-
*/
|
|
87
|
-
export function applyItemCollectBindings(
|
|
88
|
-
layouts: CardLayoutSchema[] = [],
|
|
89
|
-
items: TemplateItem[] = []
|
|
90
|
-
): CardLayoutSchema[] {
|
|
91
|
-
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
92
|
-
const metaMap = new Map<string, TemplateItem>();
|
|
93
|
-
const metaList = Array.isArray(items) ? items : [];
|
|
94
|
-
metaList.forEach(item => {
|
|
95
|
-
if (item && item.id !== undefined && item.id !== null) {
|
|
96
|
-
metaMap.set(String(item.id), item);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const assignBinding = (el: CardElement): CardElement => {
|
|
101
|
-
const meta = metaMap.get(String(el.id));
|
|
102
|
-
const binding =
|
|
103
|
-
meta && meta.bind !== undefined && meta.bind !== null
|
|
104
|
-
? meta.bind
|
|
105
|
-
: el.binding;
|
|
106
|
-
const defaultValue =
|
|
107
|
-
meta && meta.default !== undefined ? meta.default : el.defaultValue;
|
|
108
|
-
const key = meta && meta.key !== undefined ? meta.key : el.key;
|
|
109
|
-
const base: any = { ...el };
|
|
110
|
-
if (binding !== undefined) base.binding = binding;
|
|
111
|
-
else delete base.binding;
|
|
112
|
-
if (defaultValue !== undefined) base.defaultValue = defaultValue;
|
|
113
|
-
else delete base.defaultValue;
|
|
114
|
-
if (key !== undefined) base.key = key;
|
|
115
|
-
else delete base.key;
|
|
116
|
-
|
|
117
|
-
if (el.type === 'layout-panel') {
|
|
118
|
-
return {
|
|
119
|
-
...base,
|
|
120
|
-
children: (el.children || []).map(assignBinding),
|
|
121
|
-
} as CardElement;
|
|
122
|
-
}
|
|
123
|
-
return base as CardElement;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
return targetLayouts.map(layout => ({
|
|
127
|
-
...layout,
|
|
128
|
-
children: (layout.children || []).map(assignBinding),
|
|
129
|
-
}));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function getTemplateItems(ids: string, items: TemplateItem[]) {
|
|
133
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
134
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
export function getTemplateBackgrounds(ids: string, items: TemplateBackground[]){
|
|
139
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
140
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
141
|
-
}
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export * from './bindings';
|
|
4
|
+
export {
|
|
5
|
+
backgroundChange,
|
|
6
|
+
applySpecialStyle,
|
|
7
|
+
applyBackground,
|
|
8
|
+
updateElementsStyle,
|
|
9
|
+
resolveSpecialStyle,
|
|
10
|
+
DEFAULT_DECOR_COLOR,
|
|
11
|
+
} from './ops/changeBackground';
|
|
12
|
+
|
|
13
|
+
|