km-card-layout-component-miniprogram 0.1.6 → 0.1.8
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 +1 -351
- package/miniprogram_dist/components/card-layout/index.js +25 -188
- package/miniprogram_dist/components/card-layout/index.wxml +17 -9
- package/miniprogram_dist/components/card-layout/index.wxss +11 -8
- package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +74 -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 +15 -366
- package/miniprogram_dist/vendor/km-card-layout-core/interface/index.js +1 -0
- package/miniprogram_dist/vendor/km-card-layout-core/layout.js +117 -0
- package/miniprogram_dist/vendor/km-card-layout-core/ops/changeBackground.js +135 -0
- package/miniprogram_dist/vendor/km-card-layout-core/render/builder.js +210 -0
- package/miniprogram_dist/vendor/km-card-layout-core/utils.js +25 -0
- package/package.json +1 -1
- package/script/sync-core.js +10 -2
- package/src/components/card-layout/index.ts +30 -278
- package/src/components/card-layout/index.wxml +17 -9
- package/src/components/card-layout/index.wxss +11 -8
- package/src/vendor/km-card-layout-core/bindings.ts +84 -0
- package/src/vendor/km-card-layout-core/data.ts +38 -0
- package/src/vendor/km-card-layout-core/helpers.ts +76 -0
- package/src/vendor/km-card-layout-core/index.ts +21 -458
- package/src/vendor/km-card-layout-core/interface/data/payload.ts +20 -2
- package/src/vendor/km-card-layout-core/interface/index.ts +1 -0
- package/src/vendor/km-card-layout-core/interface/render.ts +1 -0
- package/src/vendor/km-card-layout-core/layout.ts +129 -0
- package/src/vendor/km-card-layout-core/ops/changeBackground.ts +169 -0
- package/src/vendor/km-card-layout-core/render/builder.ts +288 -0
- package/src/vendor/km-card-layout-core/types.d.ts +97 -8
- package/src/vendor/km-card-layout-core/utils.ts +9 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.areChildrenEqual = exports.normalizeLayout = exports.parseLayout = exports.normalizeId = exports.collectBindings = exports.sanitizeLayout = exports.sanitizeElement = exports.getAbsLayout = exports.roundToInt = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const DEFAULT_CARD_WIDTH = 343;
|
|
6
|
+
const DEFAULT_CARD_HEIGHT = 210;
|
|
7
|
+
const roundToInt = (value) => Number.isFinite(value) ? Math.round(value) : value;
|
|
8
|
+
exports.roundToInt = roundToInt;
|
|
9
|
+
const getAbsLayout = (el) => el.layout && el.layout.mode === 'absolute'
|
|
10
|
+
? el.layout
|
|
11
|
+
: null;
|
|
12
|
+
exports.getAbsLayout = getAbsLayout;
|
|
13
|
+
const roundAbsLayout = (layout) => ({
|
|
14
|
+
...layout,
|
|
15
|
+
x: (0, exports.roundToInt)(layout.x),
|
|
16
|
+
y: (0, exports.roundToInt)(layout.y),
|
|
17
|
+
width: (0, exports.roundToInt)(layout.width),
|
|
18
|
+
height: (0, exports.roundToInt)(layout.height),
|
|
19
|
+
zIndex: layout.zIndex !== undefined ? (0, exports.roundToInt)(layout.zIndex) : layout.zIndex,
|
|
20
|
+
});
|
|
21
|
+
const sanitizeElement = (el) => {
|
|
22
|
+
const layout = (0, exports.getAbsLayout)(el);
|
|
23
|
+
const base = layout ? { ...el, layout: roundAbsLayout(layout) } : el;
|
|
24
|
+
if (el.type === 'layout-panel' && el.children) {
|
|
25
|
+
return {
|
|
26
|
+
...base,
|
|
27
|
+
children: el.children.map(child => (0, exports.sanitizeElement)(child)),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return base;
|
|
31
|
+
};
|
|
32
|
+
exports.sanitizeElement = sanitizeElement;
|
|
33
|
+
const sanitizeLayout = (layout) => ({
|
|
34
|
+
...layout,
|
|
35
|
+
width: (0, exports.roundToInt)(layout.width),
|
|
36
|
+
height: (0, exports.roundToInt)(layout.height),
|
|
37
|
+
backgroundZIndex: layout.backgroundZIndex !== undefined
|
|
38
|
+
? (0, exports.roundToInt)(layout.backgroundZIndex)
|
|
39
|
+
: layout.backgroundZIndex,
|
|
40
|
+
children: (layout.children || []).map(child => (0, exports.sanitizeElement)(child)),
|
|
41
|
+
});
|
|
42
|
+
exports.sanitizeLayout = sanitizeLayout;
|
|
43
|
+
const collectBindings = (elements = []) => {
|
|
44
|
+
const result = [];
|
|
45
|
+
elements.forEach(el => {
|
|
46
|
+
if (el.binding)
|
|
47
|
+
result.push(el.binding);
|
|
48
|
+
if (el.type === 'layout-panel' && el.children) {
|
|
49
|
+
result.push(...(0, exports.collectBindings)(el.children));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return Array.from(new Set(result));
|
|
53
|
+
};
|
|
54
|
+
exports.collectBindings = collectBindings;
|
|
55
|
+
const normalizeId = (id) => {
|
|
56
|
+
if (id === undefined || id === null)
|
|
57
|
+
return undefined;
|
|
58
|
+
const num = Number(id);
|
|
59
|
+
return Number.isFinite(num) ? num : id;
|
|
60
|
+
};
|
|
61
|
+
exports.normalizeId = normalizeId;
|
|
62
|
+
const safeParseJson = (input) => {
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(input);
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
console.warn('[km-card-layout-core] parseLayout failed', err);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const parseSingleLayout = (value) => {
|
|
72
|
+
if (!value)
|
|
73
|
+
return null;
|
|
74
|
+
if (Array.isArray(value))
|
|
75
|
+
return parseSingleLayout(value[0]);
|
|
76
|
+
if (typeof value === 'string') {
|
|
77
|
+
return parseSingleLayout(safeParseJson(value));
|
|
78
|
+
}
|
|
79
|
+
if ((0, helpers_1.isObject)(value)) {
|
|
80
|
+
const content = value.content;
|
|
81
|
+
if (content !== undefined) {
|
|
82
|
+
const nested = parseSingleLayout(content);
|
|
83
|
+
if (nested)
|
|
84
|
+
return nested;
|
|
85
|
+
}
|
|
86
|
+
return (0, exports.sanitizeLayout)(value);
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
};
|
|
90
|
+
const parseLayout = (input) => parseSingleLayout(input);
|
|
91
|
+
exports.parseLayout = parseLayout;
|
|
92
|
+
const normalizeLayout = (layout) => {
|
|
93
|
+
if (!Array.isArray(layout))
|
|
94
|
+
return [];
|
|
95
|
+
return layout
|
|
96
|
+
.map(item => {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
if (!item || typeof item !== 'object')
|
|
99
|
+
return null;
|
|
100
|
+
const parsed = item;
|
|
101
|
+
return {
|
|
102
|
+
...parsed,
|
|
103
|
+
width: (_a = (0, helpers_1.toNumber)(parsed.width)) !== null && _a !== void 0 ? _a : DEFAULT_CARD_WIDTH,
|
|
104
|
+
height: (_b = (0, helpers_1.toNumber)(parsed.height)) !== null && _b !== void 0 ? _b : DEFAULT_CARD_HEIGHT,
|
|
105
|
+
container: parsed.container || { mode: 'absolute' },
|
|
106
|
+
children: Array.isArray(parsed.children)
|
|
107
|
+
? parsed.children
|
|
108
|
+
: [],
|
|
109
|
+
};
|
|
110
|
+
})
|
|
111
|
+
.filter((value) => Boolean(value));
|
|
112
|
+
};
|
|
113
|
+
exports.normalizeLayout = normalizeLayout;
|
|
114
|
+
const areChildrenEqual = (a, b) => {
|
|
115
|
+
return JSON.stringify(a === null || a === void 0 ? void 0 : a.children) === JSON.stringify(b === null || b === void 0 ? void 0 : b.children);
|
|
116
|
+
};
|
|
117
|
+
exports.areChildrenEqual = areChildrenEqual;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateElementsStyle = exports.applyBackground = exports.applySpecialStyle = exports.resolveSpecialStyle = exports.DEFAULT_DECOR_COLOR = exports.backgroundChange = void 0;
|
|
4
|
+
const toNameArray = (name) => {
|
|
5
|
+
if (Array.isArray(name))
|
|
6
|
+
return name.filter(Boolean);
|
|
7
|
+
if (!name)
|
|
8
|
+
return [];
|
|
9
|
+
return `${name}`
|
|
10
|
+
.split(',')
|
|
11
|
+
.map(n => n.trim())
|
|
12
|
+
.filter(Boolean);
|
|
13
|
+
};
|
|
14
|
+
function backgroundChange(bg, layout) {
|
|
15
|
+
const applySpecialColor = (el) => {
|
|
16
|
+
const extras = bg.fontColorExtra || [];
|
|
17
|
+
if (!extras.length)
|
|
18
|
+
return el;
|
|
19
|
+
const keys = [];
|
|
20
|
+
if (el.binding)
|
|
21
|
+
keys.push(String(el.binding));
|
|
22
|
+
if (el.id)
|
|
23
|
+
keys.push(String(el.id));
|
|
24
|
+
if (el.type === 'icon')
|
|
25
|
+
keys.push('icon');
|
|
26
|
+
if (el.type === 'custom')
|
|
27
|
+
keys.push('decor');
|
|
28
|
+
const matched = extras.find(sc => toNameArray(sc.name).some(n => keys.some(k => k === null || k === void 0 ? void 0 : k.startsWith(n))));
|
|
29
|
+
if (!matched)
|
|
30
|
+
return el;
|
|
31
|
+
const baseStyle = { ...(el.style || {}) };
|
|
32
|
+
if (el.type === 'custom') {
|
|
33
|
+
return { ...el, style: { ...baseStyle, backgroundColor: matched.color } };
|
|
34
|
+
}
|
|
35
|
+
return { ...el, style: { ...baseStyle, color: matched.color } };
|
|
36
|
+
};
|
|
37
|
+
const traverse = (children = []) => children.map(el => {
|
|
38
|
+
if (!el)
|
|
39
|
+
return el;
|
|
40
|
+
if (el.type === 'layout-panel') {
|
|
41
|
+
return {
|
|
42
|
+
...el,
|
|
43
|
+
children: traverse(el.children || []),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return applySpecialColor(el);
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
...layout,
|
|
50
|
+
backgroundImage: bg.imgUrl,
|
|
51
|
+
fontColor: bg.fontColor || layout.fontColor,
|
|
52
|
+
children: traverse(layout.children || []),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.backgroundChange = backgroundChange;
|
|
56
|
+
exports.DEFAULT_DECOR_COLOR = '#94a3b8';
|
|
57
|
+
const resolveSpecialStyle = (element, background) => {
|
|
58
|
+
var _a;
|
|
59
|
+
if (!background)
|
|
60
|
+
return {};
|
|
61
|
+
const keys = [];
|
|
62
|
+
if (element.binding)
|
|
63
|
+
keys.push(String(element.binding));
|
|
64
|
+
if (element.id)
|
|
65
|
+
keys.push(String(element.id));
|
|
66
|
+
if (element.type === 'icon')
|
|
67
|
+
keys.push('icon');
|
|
68
|
+
if (element.type === 'custom')
|
|
69
|
+
keys.push('decor');
|
|
70
|
+
const matched = (_a = background.specialColors) === null || _a === void 0 ? void 0 : _a.find(sc => {
|
|
71
|
+
const names = toNameArray(sc.name);
|
|
72
|
+
return names.some(n => keys.some(k => k === null || k === void 0 ? void 0 : k.startsWith(n)));
|
|
73
|
+
});
|
|
74
|
+
if (!matched)
|
|
75
|
+
return {};
|
|
76
|
+
if (element.type === 'custom') {
|
|
77
|
+
return { backgroundColor: matched.color };
|
|
78
|
+
}
|
|
79
|
+
return { color: matched.color };
|
|
80
|
+
};
|
|
81
|
+
exports.resolveSpecialStyle = resolveSpecialStyle;
|
|
82
|
+
const applySpecialStyle = (el, background = null, options = {}) => {
|
|
83
|
+
const specialStyle = (0, exports.resolveSpecialStyle)(el, background);
|
|
84
|
+
const baseStyle = { ...(el.style || {}) };
|
|
85
|
+
const isCustom = el.type === 'custom';
|
|
86
|
+
const hasExplicit = isCustom
|
|
87
|
+
? Boolean(baseStyle.backgroundColor || baseStyle.background)
|
|
88
|
+
: baseStyle.color !== undefined && baseStyle.color !== null;
|
|
89
|
+
const overrideExisting = options.overrideExisting === true;
|
|
90
|
+
const hasSpecial = Object.keys(specialStyle).length > 0;
|
|
91
|
+
const defaultDecorColor = options.defaultDecorColor || exports.DEFAULT_DECOR_COLOR;
|
|
92
|
+
if (hasSpecial) {
|
|
93
|
+
if (hasExplicit && !overrideExisting)
|
|
94
|
+
return el;
|
|
95
|
+
return { ...el, style: { ...baseStyle, ...specialStyle } };
|
|
96
|
+
}
|
|
97
|
+
if (overrideExisting && hasExplicit) {
|
|
98
|
+
const nextStyle = { ...baseStyle };
|
|
99
|
+
if (isCustom) {
|
|
100
|
+
nextStyle.backgroundColor = (background === null || background === void 0 ? void 0 : background.mainColor) || defaultDecorColor;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
delete nextStyle.color;
|
|
104
|
+
}
|
|
105
|
+
return { ...el, style: nextStyle };
|
|
106
|
+
}
|
|
107
|
+
return el;
|
|
108
|
+
};
|
|
109
|
+
exports.applySpecialStyle = applySpecialStyle;
|
|
110
|
+
const applyBackground = (layout, background, _options = {}) => {
|
|
111
|
+
var _a;
|
|
112
|
+
const bgId = Number(background.id);
|
|
113
|
+
const payload = {
|
|
114
|
+
id: Number.isFinite(bgId) ? bgId : 0,
|
|
115
|
+
name: background.name,
|
|
116
|
+
imgUrl: background.imageUrl,
|
|
117
|
+
fontColor: background.mainColor,
|
|
118
|
+
fontColorExtra: ((_a = background.specialColors) === null || _a === void 0 ? void 0 : _a.map(sc => ({
|
|
119
|
+
name: sc.name,
|
|
120
|
+
color: sc.color,
|
|
121
|
+
}))) || [],
|
|
122
|
+
};
|
|
123
|
+
return backgroundChange(payload, layout);
|
|
124
|
+
};
|
|
125
|
+
exports.applyBackground = applyBackground;
|
|
126
|
+
const updateElementsStyle = (layout, targetIds, updates) => {
|
|
127
|
+
const targets = new Set(targetIds);
|
|
128
|
+
return {
|
|
129
|
+
...layout,
|
|
130
|
+
children: layout.children.map(el => targets.has(el.id)
|
|
131
|
+
? { ...el, style: { ...(el.style || {}), ...updates } }
|
|
132
|
+
: el),
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
exports.updateElementsStyle = updateElementsStyle;
|
|
@@ -0,0 +1,210 @@
|
|
|
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;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DEFAULT_DECOR_COLOR = exports.resolveSpecialStyle = exports.updateElementsStyle = exports.applyBackground = exports.applySpecialStyle = exports.backgroundChange = void 0;
|
|
18
|
+
__exportStar(require("./bindings"), exports);
|
|
19
|
+
var changeBackground_1 = require("./ops/changeBackground");
|
|
20
|
+
Object.defineProperty(exports, "backgroundChange", { enumerable: true, get: function () { return changeBackground_1.backgroundChange; } });
|
|
21
|
+
Object.defineProperty(exports, "applySpecialStyle", { enumerable: true, get: function () { return changeBackground_1.applySpecialStyle; } });
|
|
22
|
+
Object.defineProperty(exports, "applyBackground", { enumerable: true, get: function () { return changeBackground_1.applyBackground; } });
|
|
23
|
+
Object.defineProperty(exports, "updateElementsStyle", { enumerable: true, get: function () { return changeBackground_1.updateElementsStyle; } });
|
|
24
|
+
Object.defineProperty(exports, "resolveSpecialStyle", { enumerable: true, get: function () { return changeBackground_1.resolveSpecialStyle; } });
|
|
25
|
+
Object.defineProperty(exports, "DEFAULT_DECOR_COLOR", { enumerable: true, get: function () { return changeBackground_1.DEFAULT_DECOR_COLOR; } });
|
package/package.json
CHANGED
package/script/sync-core.js
CHANGED
|
@@ -5,8 +5,16 @@ const pkgRoot = path.resolve(__dirname, '..');
|
|
|
5
5
|
const coreRoot = path.resolve(pkgRoot, '../km-card-layout-core');
|
|
6
6
|
const targetDir = path.resolve(pkgRoot, 'src/vendor/km-card-layout-core');
|
|
7
7
|
|
|
8
|
-
const filesToCopy = [
|
|
9
|
-
|
|
8
|
+
const filesToCopy = [
|
|
9
|
+
'index.ts',
|
|
10
|
+
'types.d.ts',
|
|
11
|
+
'utils.ts',
|
|
12
|
+
'helpers.ts',
|
|
13
|
+
'layout.ts',
|
|
14
|
+
'data.ts',
|
|
15
|
+
'bindings.ts',
|
|
16
|
+
];
|
|
17
|
+
const dirsToCopy = ['interface', 'render', 'ops'];
|
|
10
18
|
|
|
11
19
|
function ensureFileExists(filePath) {
|
|
12
20
|
if (!fs.existsSync(filePath)) {
|