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.
Files changed (70) hide show
  1. package/example/pages/home/index.js +107 -16
  2. package/miniprogram_dist/components/card-layout/elements/custom-element/index.js +27 -0
  3. package/miniprogram_dist/components/card-layout/elements/custom-element/index.json +3 -0
  4. package/miniprogram_dist/components/card-layout/elements/custom-element/index.wxml +5 -0
  5. package/miniprogram_dist/components/card-layout/elements/custom-element/index.wxss +14 -0
  6. package/miniprogram_dist/components/card-layout/elements/icon-element/index.js +39 -0
  7. package/miniprogram_dist/components/card-layout/elements/icon-element/index.json +3 -0
  8. package/miniprogram_dist/components/card-layout/elements/icon-element/index.wxml +5 -0
  9. package/miniprogram_dist/components/card-layout/elements/icon-element/index.wxss +37 -0
  10. package/miniprogram_dist/components/card-layout/elements/image-element/index.js +31 -0
  11. package/miniprogram_dist/components/card-layout/elements/image-element/index.json +3 -0
  12. package/miniprogram_dist/components/card-layout/elements/image-element/index.wxml +8 -0
  13. package/miniprogram_dist/components/card-layout/elements/image-element/index.wxss +10 -0
  14. package/miniprogram_dist/components/card-layout/elements/text-element/index.js +47 -0
  15. package/miniprogram_dist/components/card-layout/elements/text-element/index.json +3 -0
  16. package/miniprogram_dist/components/card-layout/elements/text-element/index.wxml +29 -0
  17. package/miniprogram_dist/components/card-layout/elements/text-element/index.wxss +59 -0
  18. package/miniprogram_dist/components/card-layout/index.js +16 -201
  19. package/miniprogram_dist/components/card-layout/index.json +7 -1
  20. package/miniprogram_dist/components/card-layout/index.wxml +15 -63
  21. package/miniprogram_dist/components/card-layout/index.wxss +0 -63
  22. package/miniprogram_dist/utils/card-schema.js +12 -3
  23. package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +78 -0
  24. package/miniprogram_dist/vendor/km-card-layout-core/data.js +38 -0
  25. package/miniprogram_dist/vendor/km-card-layout-core/helpers.js +72 -0
  26. package/miniprogram_dist/vendor/km-card-layout-core/index.js +46 -367
  27. package/miniprogram_dist/vendor/km-card-layout-core/interface/index.js +1 -1
  28. package/miniprogram_dist/vendor/km-card-layout-core/layout.js +117 -0
  29. package/miniprogram_dist/vendor/km-card-layout-core/ops/changeBackground.js +142 -0
  30. package/miniprogram_dist/vendor/km-card-layout-core/render/helpers.js +133 -0
  31. package/miniprogram_dist/vendor/km-card-layout-core/render/tool.js +16 -0
  32. package/miniprogram_dist/vendor/km-card-layout-core/utils.js +23 -130
  33. package/package.json +1 -1
  34. package/script/sync-core.js +13 -2
  35. package/src/components/card-layout/elements/custom-element/index.json +3 -0
  36. package/src/components/card-layout/elements/custom-element/index.ts +30 -0
  37. package/src/components/card-layout/elements/custom-element/index.wxml +5 -0
  38. package/src/components/card-layout/elements/custom-element/index.wxss +14 -0
  39. package/src/components/card-layout/elements/icon-element/index.json +3 -0
  40. package/src/components/card-layout/elements/icon-element/index.ts +42 -0
  41. package/src/components/card-layout/elements/icon-element/index.wxml +5 -0
  42. package/src/components/card-layout/elements/icon-element/index.wxss +37 -0
  43. package/src/components/card-layout/elements/image-element/index.json +3 -0
  44. package/src/components/card-layout/elements/image-element/index.ts +35 -0
  45. package/src/components/card-layout/elements/image-element/index.wxml +8 -0
  46. package/src/components/card-layout/elements/image-element/index.wxss +10 -0
  47. package/src/components/card-layout/elements/text-element/index.json +3 -0
  48. package/src/components/card-layout/elements/text-element/index.ts +52 -0
  49. package/src/components/card-layout/elements/text-element/index.wxml +29 -0
  50. package/src/components/card-layout/elements/text-element/index.wxss +59 -0
  51. package/src/components/card-layout/index.json +7 -1
  52. package/src/components/card-layout/index.ts +30 -296
  53. package/src/components/card-layout/index.wxml +15 -63
  54. package/src/components/card-layout/index.wxss +0 -63
  55. package/src/utils/card-schema.ts +11 -4
  56. package/src/vendor/km-card-layout-core/bindings.ts +87 -0
  57. package/src/vendor/km-card-layout-core/data.ts +39 -0
  58. package/src/vendor/km-card-layout-core/helpers.ts +76 -0
  59. package/src/vendor/km-card-layout-core/index.ts +53 -460
  60. package/src/vendor/km-card-layout-core/interface/context.ts +6 -0
  61. package/src/vendor/km-card-layout-core/interface/data/payload.ts +1 -0
  62. package/src/vendor/km-card-layout-core/interface/index.ts +2 -2
  63. package/src/vendor/km-card-layout-core/layout.ts +129 -0
  64. package/src/vendor/km-card-layout-core/ops/changeBackground.ts +179 -0
  65. package/src/vendor/km-card-layout-core/render/helpers.ts +144 -0
  66. package/src/vendor/km-card-layout-core/render/tool.ts +21 -0
  67. package/src/vendor/km-card-layout-core/types.d.ts +166 -15
  68. package/src/vendor/km-card-layout-core/utils.ts +13 -141
  69. package/src/vendor/km-card-layout-core/interface/render.ts +0 -52
  70. /package/miniprogram_dist/vendor/km-card-layout-core/interface/{render.js → context.js} +0 -0
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setElementVisible = 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;
136
+ const setElementVisible = (layout, key, visible) => {
137
+ return layout.map(la => ({
138
+ ...la,
139
+ children: la.children.map(el => (el.key === key ? { ...el, visible } : el)),
140
+ }));
141
+ };
142
+ exports.setElementVisible = setElementVisible;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTextIconMeta = exports.getIconName = exports.getImageSrc = exports.getTextValue = exports.buildImageContentStyle = exports.buildTextContentStyle = exports.buildPanelContentStyle = exports.buildBaseContentStyle = exports.buildBackgroundStyle = exports.buildCardStyle = exports.buildWrapperStyle = void 0;
4
+ const helpers_1 = require("../helpers");
5
+ const layout_1 = require("../layout");
6
+ const buildWrapperStyle = (el, unit = 'px') => {
7
+ const abs = (0, layout_1.getAbsLayout)(el);
8
+ if (!abs)
9
+ return {};
10
+ return {
11
+ position: 'absolute',
12
+ left: (0, helpers_1.addUnit)(abs.x, unit),
13
+ top: (0, helpers_1.addUnit)(abs.y, unit),
14
+ width: (0, helpers_1.addUnit)(abs.width, unit),
15
+ height: (0, helpers_1.addUnit)(abs.height, unit),
16
+ zIndex: abs.zIndex,
17
+ boxSizing: 'border-box',
18
+ };
19
+ };
20
+ exports.buildWrapperStyle = buildWrapperStyle;
21
+ const buildCardStyle = (layout, unit = 'px') => ({
22
+ width: (0, helpers_1.addUnit)(layout.width, unit),
23
+ height: (0, helpers_1.addUnit)(layout.height, unit),
24
+ color: layout.fontColor,
25
+ borderRadius: layout.borderRadius !== undefined
26
+ ? (0, helpers_1.addUnit)(layout.borderRadius, unit)
27
+ : undefined,
28
+ padding: layout.padding !== undefined ? (0, helpers_1.addUnit)(layout.padding, unit) : undefined,
29
+ position: 'relative',
30
+ overflow: 'hidden',
31
+ boxSizing: 'border-box',
32
+ backgroundColor: 'transparent',
33
+ });
34
+ exports.buildCardStyle = buildCardStyle;
35
+ const buildBackgroundStyle = (layout, unit = 'px') => ({
36
+ zIndex: layout.backgroundZIndex,
37
+ borderRadius: layout.borderRadius !== undefined
38
+ ? (0, helpers_1.addUnit)(layout.borderRadius, unit)
39
+ : undefined,
40
+ width: '100%',
41
+ height: '100%',
42
+ position: 'absolute',
43
+ left: 0,
44
+ top: 0,
45
+ });
46
+ exports.buildBackgroundStyle = buildBackgroundStyle;
47
+ const buildBaseContentStyle = (el) => ({
48
+ ...(el.style || {}),
49
+ boxSizing: 'border-box',
50
+ });
51
+ exports.buildBaseContentStyle = buildBaseContentStyle;
52
+ const buildPanelContentStyle = (el, unit = 'px') => ({
53
+ position: 'relative',
54
+ width: '100%',
55
+ height: '100%',
56
+ display: 'block',
57
+ boxSizing: 'border-box',
58
+ ...(el.style || {}),
59
+ });
60
+ exports.buildPanelContentStyle = buildPanelContentStyle;
61
+ const buildTextContentStyle = (el, unit = 'px') => {
62
+ var _a, _b, _c, _d;
63
+ const textAlign = ((_a = el.style) === null || _a === void 0 ? void 0 : _a.textAlign) || el.align || undefined;
64
+ const style = {
65
+ ...(el.style || {}),
66
+ fontSize: (0, helpers_1.addUnit)((_b = el.style) === null || _b === void 0 ? void 0 : _b.fontSize, unit),
67
+ whiteSpace: 'pre-wrap',
68
+ wordBreak: 'break-word',
69
+ lineHeight: ((_c = el.style) === null || _c === void 0 ? void 0 : _c.lineHeight) !== undefined && ((_d = el.style) === null || _d === void 0 ? void 0 : _d.lineHeight) !== null
70
+ ? (0, helpers_1.addUnit)(el.style.lineHeight, unit)
71
+ : '1',
72
+ };
73
+ if (textAlign)
74
+ style.textAlign = textAlign;
75
+ return style;
76
+ };
77
+ exports.buildTextContentStyle = buildTextContentStyle;
78
+ const buildImageContentStyle = (el) => {
79
+ const style = { ...(el.style || {}) };
80
+ const borderWidth = Number(style.borderWidth);
81
+ if (Number.isFinite(borderWidth) && borderWidth > 0) {
82
+ if (!style.borderStyle)
83
+ style.borderStyle = 'solid';
84
+ if (!style.borderColor)
85
+ style.borderColor = '#000000';
86
+ }
87
+ return style;
88
+ };
89
+ exports.buildImageContentStyle = buildImageContentStyle;
90
+ const getTextValue = (el) => el.defaultValue !== undefined && el.defaultValue !== null
91
+ ? `${el.defaultValue}`
92
+ : '';
93
+ exports.getTextValue = getTextValue;
94
+ const getImageSrc = (el) => el.defaultUrl || el.defaultValue || '';
95
+ exports.getImageSrc = getImageSrc;
96
+ const getIconName = (el) => (el.name || el.defaultValue || '');
97
+ exports.getIconName = getIconName;
98
+ const buildTextIconMeta = (el, unit = 'px') => {
99
+ var _a, _b, _c, _d, _e, _f;
100
+ const icon = el.icon;
101
+ const enabled = (icon === null || icon === void 0 ? void 0 : icon.enable) === true;
102
+ if (!icon || !enabled)
103
+ return null;
104
+ const style = icon.style || 'fill';
105
+ const baseName = icon.name || el.key || el.binding || el.id;
106
+ let name;
107
+ if (style === 'dot')
108
+ name = 'round';
109
+ else if (style === 'line')
110
+ name = baseName ? `${baseName}-line` : undefined;
111
+ else
112
+ name = baseName || undefined;
113
+ if (!name)
114
+ return null;
115
+ const size = icon.size !== undefined && icon.size !== null
116
+ ? icon.size
117
+ : (_a = el.style) === null || _a === void 0 ? void 0 : _a.fontSize;
118
+ const gap = icon.gap !== undefined && icon.gap !== null ? icon.gap : 4;
119
+ 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);
120
+ return {
121
+ name: `${name}`,
122
+ size: (0, helpers_1.addUnit)(size, unit),
123
+ gap: (0, helpers_1.addUnit)(gap, unit),
124
+ color,
125
+ align: icon.align || 'left',
126
+ wrapperStyle: {
127
+ height: ((_d = el.style) === null || _d === void 0 ? void 0 : _d.lineHeight) !== undefined && ((_e = el.style) === null || _e === void 0 ? void 0 : _e.lineHeight) !== null
128
+ ? (0, helpers_1.addUnit)(el.style.lineHeight, unit)
129
+ : (_f = el.style) === null || _f === void 0 ? void 0 : _f.fontSize,
130
+ },
131
+ };
132
+ };
133
+ exports.buildTextIconMeta = buildTextIconMeta;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRenderData = void 0;
4
+ const changeBackground_1 = require("../ops/changeBackground");
5
+ const utils_1 = require("../utils");
6
+ function buildRenderData(layout, items, config) {
7
+ // 绑定数据
8
+ let renderLayout = (0, utils_1.applyItemCollectBindings)(layout, items);
9
+ // 设置显示逻辑
10
+ renderLayout = (0, changeBackground_1.setElementVisible)(renderLayout, 'image', config.showAvatar);
11
+ renderLayout = (0, changeBackground_1.setElementVisible)(renderLayout, 'logo', config.showLogo);
12
+ // 设置背景
13
+ renderLayout = renderLayout.map((la, index) => config.currentBg[index] ? (0, changeBackground_1.backgroundChange)(config.currentBg[index], la) : la);
14
+ return renderLayout;
15
+ }
16
+ exports.buildRenderData = buildRenderData;
@@ -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.9",
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)) {
@@ -16,6 +24,9 @@ function ensureFileExists(filePath) {
16
24
 
17
25
  function syncCore() {
18
26
  ensureFileExists(coreRoot);
27
+ if (fs.existsSync(targetDir)) {
28
+ fs.rmSync(targetDir, { recursive: true, force: true });
29
+ }
19
30
  fs.mkdirSync(targetDir, { recursive: true });
20
31
 
21
32
  filesToCopy.forEach((fileName) => {
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
@@ -0,0 +1,30 @@
1
+ import {
2
+ buildBaseContentStyle,
3
+ buildWrapperStyle,
4
+ styleObjectToString,
5
+ type CustomElement,
6
+ } from '../../../../vendor/km-card-layout-core/index';
7
+
8
+ Component({
9
+ options: {
10
+ styleIsolation: 'apply-shared',
11
+ },
12
+ properties: {
13
+ element: {
14
+ type: Object,
15
+ value: {},
16
+ },
17
+ },
18
+ data: {
19
+ wrapperStyle: '',
20
+ contentStyle: '',
21
+ },
22
+ observers: {
23
+ element(el: CustomElement) {
24
+ if (!el) return;
25
+ const wrapperStyle = styleObjectToString(buildWrapperStyle(el, 'rpx'), 'rpx');
26
+ const contentStyle = styleObjectToString(buildBaseContentStyle(el), 'rpx');
27
+ this.setData({ wrapperStyle, contentStyle });
28
+ },
29
+ },
30
+ });
@@ -0,0 +1,5 @@
1
+ <view class="km-node km-node--custom" style="{{wrapperStyle}}">
2
+ <view class="km-node__custom" style="{{contentStyle}}">
3
+ <slot name="{{element.id}}"></slot>
4
+ </view>
5
+ </view>
@@ -0,0 +1,14 @@
1
+ .km-node {
2
+ box-sizing: border-box;
3
+ color: inherit;
4
+ }
5
+
6
+ .km-node--custom {
7
+ box-sizing: border-box;
8
+ }
9
+
10
+ .km-node__custom {
11
+ width: 100%;
12
+ height: 100%;
13
+ box-sizing: border-box;
14
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
@@ -0,0 +1,42 @@
1
+ import {
2
+ buildBaseContentStyle,
3
+ buildWrapperStyle,
4
+ getIconName,
5
+ styleObjectToString,
6
+ type IconElement,
7
+ } from '../../../../vendor/km-card-layout-core/index';
8
+ import { ICON_CODE_MAP } from '../../icon-map';
9
+
10
+ const mapIconGlyph = (name?: string, fallback?: string) => {
11
+ if (!name) return fallback;
12
+ const glyph = ICON_CODE_MAP[name];
13
+ if (glyph) return String.fromCharCode(parseInt(glyph, 16));
14
+ return fallback || name;
15
+ };
16
+
17
+ Component({
18
+ options: {
19
+ styleIsolation: 'apply-shared',
20
+ },
21
+ properties: {
22
+ element: {
23
+ type: Object,
24
+ value: {},
25
+ },
26
+ },
27
+ data: {
28
+ wrapperStyle: '',
29
+ contentStyle: '',
30
+ iconText: '',
31
+ },
32
+ observers: {
33
+ element(el: IconElement) {
34
+ if (!el) return;
35
+ const wrapperStyle = styleObjectToString(buildWrapperStyle(el, 'rpx'), 'rpx');
36
+ const contentStyle = styleObjectToString(buildBaseContentStyle(el), 'rpx');
37
+ const name = getIconName(el);
38
+ const iconText = mapIconGlyph(name, name || '');
39
+ this.setData({ wrapperStyle, contentStyle, iconText });
40
+ },
41
+ },
42
+ });
@@ -0,0 +1,5 @@
1
+ <view class="km-node km-node--icon" style="{{wrapperStyle}}">
2
+ <view class="km-node__icon icon" style="{{contentStyle}}">
3
+ {{iconText}}
4
+ </view>
5
+ </view>
@@ -0,0 +1,37 @@
1
+ .km-node {
2
+ box-sizing: border-box;
3
+ color: inherit;
4
+ }
5
+
6
+ .km-node--icon {
7
+ display: flex;
8
+ align-items: center;
9
+ justify-content: center;
10
+ }
11
+
12
+ .km-node__icon {
13
+ display: inline-flex;
14
+ align-items: center;
15
+ justify-content: center;
16
+ width: 100%;
17
+ height: 100%;
18
+ font-family: 'km-icon', 'PingFang SC', 'Microsoft Yahei', sans-serif;
19
+ font-style: normal;
20
+ font-weight: normal;
21
+ }
22
+
23
+ @font-face {
24
+ font-family: 'km-icon';
25
+ src: url('data:font/woff;charset=utf-8;base64,d09GRgABAAAAAEl4AA0AAAAAcmgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAABJXAAAABoAAAAcrMtJV0dERUYAAEk8AAAAHgAAAB4AKQByT1MvMgAAAaQAAABGAAAAYDw3SVljbWFwAAAC7AAAAM8AAAIW8XL3K2dhc3AAAEk0AAAACAAAAAj//wADZ2x5ZgAABJgAAEBZAABkZPJymXJoZWFkAAABMAAAADEAAAA2MtZiFmhoZWEAAAFkAAAAIAAAACQNagmCaG10eAAAAewAAAD/AAABqqs3Ii9sb2NhAAADvAAAANoAAADaKv0P7G1heHAAAAGEAAAAHwAAACABmQHEbmFtZQAARPQAAAFGAAACgl6CAQJwb3N0AABGPAAAAvUAAATh1g15W3jaY2BkYGAA4lqffPd4fpuvDNwsDCDwVIyfA0b///i/gXMWcyeQy8HABBIFAAVdCfwAAAB42mNgZGBgbvjfwBDDOfP/x///OWcxAEVQQCYAuxgH/XjaY2BkYGDIYdzBoMwAAkxAzAWEDAz/wXwGACjlAl8AeNpjYGFRYJzAwMrAwNTJdIaBgaEfQjO+ZjBi5ACKMrAyM2AFAWmuKQwHnjE+y2Ju+N/AwMB8h6ERKMyIpESBgREAenQNCwAAeNo90cErBGEYx/Hf1LMH7MVxoigHtS600pzWnMjBlt2dFAeiNuWgXLgokgslbpyE/Aduyl38J3ty4aCs7/vOk6lPv+d5531n3nfGVF5JIZlUx9fAbawnEfIFq14/YhddFPjFmynZ9n4TbYzg2tcMW6Epr4NQT3jSJ2lcW9ec1fSEAheMnVume7KKBbQwiMye+5/kEpqYwQoOY59pn1xGw3Lt8NwHS7UY35frivqbet2fNYZp+4j76vj+GpUhjZJreLfxODecay/eTzVPzmIj9uX7VLnUmfdb/2fN4trcv0kYv8Oxe/V5Rzhg7inZ8wzjN5b0f6z8PV2d/AHivi0JAHja3dBFUoVRDITR88PD3d3d3d3d3d33zQqYwwVGbIGk8qV6kK7qIN7vlIsCRdlBRT865iPsWOig318/PwOjbwYd+7mKSZAoSbIUqdKky5ApS7YcufLkK1CoSLESpcqCZ4VKVarVqFWnXoNGTZq1aNWmXYdOXbr16NWn34BBQ4aNGDVm3IRJU6bNmDVn3oJFS5atWLVm3YZNW7bt2LVn34FDR46dOHXm3IVLV67duHXn3oNHT8Hv2YtXbyFaot9HfMeMC4jztyL/vr4AXx4eawAAAAAAAAAAAACwAPIDSgQ8BLIFUgWUBcIF/gY8BpIHCgdAB3wHoAgOCHAIxgk+CV4JzAnqCkQKrgtUC8QMEAxsDNQNFA1SDegONg6qDyQPgg/CEAIQxBEwEaQSHBLYE14T4hRcFPIVTBYMFkwWqBckGGAYxhmYGegaEBpeGuIbXhvwHPQd5B62Hygf6CBeILog9CFUIbgiBCJ0ItQjbCQSJGgkuCVsJcImKib0J44ocijOKSApUCo2KmQqtituK34sJixkLMgtdC3WLpgvPC+QMBww/DGCMagyMgAA') format('woff');
26
+ font-weight: normal;
27
+ font-style: normal;
28
+ font-display: swap;
29
+ }
30
+
31
+ .icon {
32
+ font-family: 'km-icon' !important;
33
+ font-size: 16px;
34
+ font-style: normal;
35
+ -webkit-font-smoothing: antialiased;
36
+ -moz-osx-font-smoothing: grayscale;
37
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
@@ -0,0 +1,35 @@
1
+ import {
2
+ buildImageContentStyle,
3
+ buildWrapperStyle,
4
+ getImageSrc,
5
+ styleObjectToString,
6
+ type ImageElement,
7
+ } from '../../../../vendor/km-card-layout-core/index';
8
+
9
+ Component({
10
+ options: {
11
+ styleIsolation: 'apply-shared',
12
+ },
13
+ properties: {
14
+ element: {
15
+ type: Object,
16
+ value: {},
17
+ },
18
+ },
19
+ data: {
20
+ wrapperStyle: '',
21
+ contentStyle: '',
22
+ imageSrc: '',
23
+ mode: 'aspectFill',
24
+ },
25
+ observers: {
26
+ element(el: ImageElement) {
27
+ if (!el) return;
28
+ const wrapperStyle = styleObjectToString(buildWrapperStyle(el, 'rpx'), 'rpx');
29
+ const contentStyle = styleObjectToString(buildImageContentStyle(el), 'rpx');
30
+ const imageSrc = getImageSrc(el);
31
+ const mode = el.fit === 'contain' ? 'aspectFit' : 'aspectFill';
32
+ this.setData({ wrapperStyle, contentStyle, imageSrc, mode });
33
+ },
34
+ },
35
+ });