km-card-layout-component-miniprogram 0.1.7 → 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.
Files changed (24) hide show
  1. package/miniprogram_dist/components/card-layout/index.js +25 -193
  2. package/miniprogram_dist/components/card-layout/index.wxss +3 -1
  3. package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +74 -0
  4. package/miniprogram_dist/vendor/km-card-layout-core/data.js +38 -0
  5. package/miniprogram_dist/vendor/km-card-layout-core/helpers.js +72 -0
  6. package/miniprogram_dist/vendor/km-card-layout-core/index.js +15 -367
  7. package/miniprogram_dist/vendor/km-card-layout-core/layout.js +117 -0
  8. package/miniprogram_dist/vendor/km-card-layout-core/ops/changeBackground.js +135 -0
  9. package/miniprogram_dist/vendor/km-card-layout-core/render/builder.js +210 -0
  10. package/miniprogram_dist/vendor/km-card-layout-core/utils.js +23 -130
  11. package/package.json +1 -1
  12. package/script/sync-core.js +10 -2
  13. package/src/components/card-layout/index.ts +30 -287
  14. package/src/components/card-layout/index.wxss +3 -1
  15. package/src/vendor/km-card-layout-core/bindings.ts +84 -0
  16. package/src/vendor/km-card-layout-core/data.ts +38 -0
  17. package/src/vendor/km-card-layout-core/helpers.ts +76 -0
  18. package/src/vendor/km-card-layout-core/index.ts +21 -460
  19. package/src/vendor/km-card-layout-core/interface/render.ts +1 -0
  20. package/src/vendor/km-card-layout-core/layout.ts +129 -0
  21. package/src/vendor/km-card-layout-core/ops/changeBackground.ts +169 -0
  22. package/src/vendor/km-card-layout-core/render/builder.ts +288 -0
  23. package/src/vendor/km-card-layout-core/types.d.ts +97 -5
  24. package/src/vendor/km-card-layout-core/utils.ts +9 -141
@@ -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;
@@ -1,132 +1,25 @@
1
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
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTemplateBackgrounds = exports.getTemplateItems = exports.applyItemCollectBindings = exports.stripLayoutBindings = exports.backgroundChange = void 0;
4
- function backgroundChange(bg, layout) {
5
- const toNameArray = (name) => {
6
- if (Array.isArray(name))
7
- return name.filter(Boolean);
8
- if (!name)
9
- return [];
10
- return `${name}`
11
- .split(',')
12
- .map(n => n.trim())
13
- .filter(Boolean);
14
- };
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
- function stripLayoutBindings(layouts = []) {
57
- const targetLayouts = Array.isArray(layouts) ? layouts : [];
58
- const stripElement = (el) => {
59
- const { binding: _b, defaultValue: _d, ...rest } = el;
60
- if (el.type === 'layout-panel') {
61
- return {
62
- ...rest,
63
- children: (el.children || []).map(stripElement),
64
- };
65
- }
66
- return rest;
67
- };
68
- return targetLayouts.map(layout => ({
69
- ...layout,
70
- children: (layout.children || []).map(stripElement),
71
- }));
72
- }
73
- exports.stripLayoutBindings = stripLayoutBindings;
74
- /**
75
- * 应用元素数据绑定字段
76
- * @param layouts 布局
77
- * @param items 绑定元素数据
78
- * @returns
79
- */
80
- function applyItemCollectBindings(layouts = [], items = []) {
81
- const targetLayouts = Array.isArray(layouts) ? layouts : [];
82
- const metaMap = new Map();
83
- const metaList = Array.isArray(items) ? items : [];
84
- metaList.forEach(item => {
85
- if (item && item.id !== undefined && item.id !== null) {
86
- metaMap.set(String(item.id), item);
87
- }
88
- });
89
- const assignBinding = (el) => {
90
- const meta = metaMap.get(String(el.id));
91
- const binding = meta && meta.bind !== undefined && meta.bind !== null
92
- ? meta.bind
93
- : el.binding;
94
- const defaultValue = meta && meta.default !== undefined ? meta.default : el.defaultValue;
95
- const key = meta && meta.key !== undefined ? meta.key : el.key;
96
- const base = { ...el };
97
- if (binding !== undefined)
98
- base.binding = binding;
99
- else
100
- delete base.binding;
101
- if (defaultValue !== undefined)
102
- base.defaultValue = defaultValue;
103
- else
104
- delete base.defaultValue;
105
- if (key !== undefined)
106
- base.key = key;
107
- else
108
- delete base.key;
109
- if (el.type === 'layout-panel') {
110
- return {
111
- ...base,
112
- children: (el.children || []).map(assignBinding),
113
- };
114
- }
115
- return base;
116
- };
117
- return targetLayouts.map(layout => ({
118
- ...layout,
119
- children: (layout.children || []).map(assignBinding),
120
- }));
121
- }
122
- exports.applyItemCollectBindings = applyItemCollectBindings;
123
- function getTemplateItems(ids, items) {
124
- const idArray = ids.split(',').map(id => id.trim());
125
- return items.filter(item => idArray.includes(String(item.id)));
126
- }
127
- exports.getTemplateItems = getTemplateItems;
128
- function getTemplateBackgrounds(ids, items) {
129
- const idArray = ids.split(',').map(id => id.trim());
130
- return items.filter(item => idArray.includes(String(item.id)));
131
- }
132
- exports.getTemplateBackgrounds = getTemplateBackgrounds;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "km-card-layout-component-miniprogram",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "",
5
5
  "main": "miniprogram_dist/index.js",
6
6
  "miniprogram": "miniprogram_dist",
@@ -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 = ['index.ts', 'types.d.ts', 'utils.ts'];
9
- const dirsToCopy = ['interface'];
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)) {