km-card-layout-core 0.1.12 → 0.1.15

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateElementsStyle = exports.applyBackground = exports.applySpecialStyle = exports.resolveSpecialStyle = exports.DEFAULT_DECOR_COLOR = void 0;
3
+ exports.setElementVisible = exports.updateElementsStyle = exports.applyBackground = exports.applySpecialStyle = exports.resolveSpecialStyle = exports.DEFAULT_DECOR_COLOR = void 0;
4
4
  exports.backgroundChange = backgroundChange;
5
5
  const toNameArray = (name) => {
6
6
  if (Array.isArray(name))
@@ -133,3 +133,10 @@ const updateElementsStyle = (layout, targetIds, updates) => {
133
133
  };
134
134
  };
135
135
  exports.updateElementsStyle = updateElementsStyle;
136
+ const setElementVisible = (layout, key, visible) => {
137
+ return layout.map(la => ({
138
+ ...la,
139
+ children: la.children.map(el => (el.id === key ? { ...el, visible } : el)),
140
+ }));
141
+ };
142
+ exports.setElementVisible = setElementVisible;
@@ -81,11 +81,12 @@ const buildImageContentStyle = (el, unit) => {
81
81
  return (0, helpers_1.styleObjectToString)(style, unit);
82
82
  };
83
83
  const buildTextIcon = (el, unit) => {
84
- var _a, _b, _c, _d;
84
+ var _a, _b, _c, _d, _e;
85
85
  const icon = el.icon;
86
86
  if (!icon || icon.enable === false)
87
87
  return undefined;
88
88
  const style = icon.style || 'fill';
89
+ // el.extra.icon ||
89
90
  const baseName = el.key || el.binding || el.id;
90
91
  let name;
91
92
  if (style === 'dot')
@@ -109,9 +110,7 @@ const buildTextIcon = (el, unit) => {
109
110
  color: color,
110
111
  align: icon.align || 'left',
111
112
  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',
113
+ height: ((_d = el.style) === null || _d === void 0 ? void 0 : _d.lineHeight) || ((_e = el.style) === null || _e === void 0 ? void 0 : _e.fontSize),
115
114
  }, unit),
116
115
  };
117
116
  };
package/dist/utils.js CHANGED
@@ -15,11 +15,24 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.DEFAULT_DECOR_COLOR = exports.resolveSpecialStyle = exports.updateElementsStyle = exports.applyBackground = exports.applySpecialStyle = exports.backgroundChange = void 0;
18
+ exports.buildRenderData = buildRenderData;
19
+ const km_card_layout_core_1 = require("km-card-layout-core");
20
+ const changeBackground_1 = require("./ops/changeBackground");
18
21
  __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; } });
22
+ var changeBackground_2 = require("./ops/changeBackground");
23
+ Object.defineProperty(exports, "backgroundChange", { enumerable: true, get: function () { return changeBackground_2.backgroundChange; } });
24
+ Object.defineProperty(exports, "applySpecialStyle", { enumerable: true, get: function () { return changeBackground_2.applySpecialStyle; } });
25
+ Object.defineProperty(exports, "applyBackground", { enumerable: true, get: function () { return changeBackground_2.applyBackground; } });
26
+ Object.defineProperty(exports, "updateElementsStyle", { enumerable: true, get: function () { return changeBackground_2.updateElementsStyle; } });
27
+ Object.defineProperty(exports, "resolveSpecialStyle", { enumerable: true, get: function () { return changeBackground_2.resolveSpecialStyle; } });
28
+ Object.defineProperty(exports, "DEFAULT_DECOR_COLOR", { enumerable: true, get: function () { return changeBackground_2.DEFAULT_DECOR_COLOR; } });
29
+ function buildRenderData(layout, items, config) {
30
+ // 绑定数据
31
+ let renderLayout = (0, km_card_layout_core_1.applyItemCollectBindings)(layout, items);
32
+ // 设置显示逻辑
33
+ renderLayout = (0, changeBackground_1.setElementVisible)(renderLayout, 'avatar', config.showAvatar);
34
+ renderLayout = (0, changeBackground_1.setElementVisible)(renderLayout, 'logo', config.showLogo);
35
+ // 设置背景
36
+ renderLayout = renderLayout.map((la, index) => (0, km_card_layout_core_1.backgroundChange)(config.currentBg[index], la));
37
+ return renderLayout;
38
+ }
@@ -21,6 +21,7 @@ export interface TemplateItem {
21
21
  bind: string;
22
22
  key?: string;
23
23
  icon?: string;
24
+ extra?: { icon?: string };
24
25
  default?: string;
25
26
  type: 'text' | 'image';
26
27
  cate: number;
@@ -102,10 +102,9 @@ export const applySpecialStyle = (
102
102
  const specialStyle = resolveSpecialStyle(el, background);
103
103
  const baseStyle = { ...(el.style || {}) };
104
104
  const isCustom = el.type === 'custom';
105
- const hasExplicit =
106
- isCustom
107
- ? Boolean(baseStyle.backgroundColor || baseStyle.background)
108
- : baseStyle.color !== undefined && baseStyle.color !== null;
105
+ const hasExplicit = isCustom
106
+ ? Boolean(baseStyle.backgroundColor || baseStyle.background)
107
+ : baseStyle.color !== undefined && baseStyle.color !== null;
109
108
 
110
109
  const overrideExisting = options.overrideExisting === true;
111
110
  const hasSpecial = Object.keys(specialStyle).length > 0;
@@ -140,8 +139,8 @@ export const applyBackground = (
140
139
  const bgId = Number(background.id);
141
140
  const payload: TemplateBackground = {
142
141
  id: Number.isFinite(bgId) ? bgId : 0,
143
- name: background.name,
144
- imgUrl: background.imageUrl,
142
+ name: background.name!,
143
+ imgUrl: background.imageUrl!,
145
144
  fontColor: background.mainColor,
146
145
  fontColorExtra:
147
146
  background.specialColors?.map(sc => ({
@@ -167,3 +166,14 @@ export const updateElementsStyle = (
167
166
  ),
168
167
  };
169
168
  };
169
+
170
+ export const setElementVisible = (
171
+ layout: CardLayoutSchema[],
172
+ key: string,
173
+ visible: boolean
174
+ ): CardLayoutSchema[] => {
175
+ return layout.map(la => ({
176
+ ...la,
177
+ children: la.children.map(el => (el.id === key ? { ...el, visible } : el)),
178
+ }));
179
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "km-card-layout-core",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
4
4
  "description": "Shared render helpers for CardMaster layout JSON (binding resolution, layout normalization).",
5
5
  "main": "dist/index.js",
6
6
  "types": "types.d.ts",
package/render/builder.ts CHANGED
@@ -126,8 +126,9 @@ const buildTextIcon = (
126
126
  ): RenderNode['icon'] | undefined => {
127
127
  const icon = el.icon;
128
128
  if (!icon || icon.enable === false) return undefined;
129
-
129
+
130
130
  const style = icon.style || 'fill';
131
+ // el.extra.icon ||
131
132
  const baseName = el.key || el.binding || el.id;
132
133
  let name: string | undefined;
133
134
  if (style === 'dot') name = 'round';
@@ -155,9 +156,7 @@ const buildTextIcon = (
155
156
  align: icon.align || 'left',
156
157
  wrapperStyle: styleObjectToString(
157
158
  {
158
- display: 'inline-flex',
159
- alignItems: 'center',
160
- height: el.style?.lineHeight || '1',
159
+ height: el.style?.lineHeight || el.style?.fontSize,
161
160
  },
162
161
  unit
163
162
  ),
package/types.d.ts CHANGED
@@ -149,3 +149,11 @@ export function buildRenderResult(
149
149
  data: Record<string, any>,
150
150
  unit?: 'px' | 'rpx'
151
151
  ): RenderResult;
152
+
153
+
154
+ export function buildRenderData (
155
+ layout: CardLayoutSchema[],
156
+ items: TemplateItem[],
157
+ dataInput: Record<string, any>,
158
+ config: Config
159
+ ): CardLayoutSchema[];
package/utils.ts CHANGED
@@ -1,3 +1,12 @@
1
+ import {
2
+ applyItemCollectBindings,
3
+ backgroundChange,
4
+ CardLayoutSchema,
5
+ TemplateBackground,
6
+ TemplateItem,
7
+ } from 'km-card-layout-core';
8
+ import { setElementVisible } from './ops/changeBackground';
9
+
1
10
  export * from './bindings';
2
11
  export {
3
12
  backgroundChange,
@@ -7,3 +16,29 @@ export {
7
16
  resolveSpecialStyle,
8
17
  DEFAULT_DECOR_COLOR,
9
18
  } from './ops/changeBackground';
19
+
20
+ export type Config = {
21
+ showAvatar: boolean;
22
+ showLogo: boolean;
23
+ /**
24
+ * 当前背景 (0 为正面背景 1 为背面背景)
25
+ */
26
+ currentBg: TemplateBackground[];
27
+ };
28
+
29
+ export function buildRenderData(
30
+ layout: CardLayoutSchema[],
31
+ items: TemplateItem[],
32
+ config: Config
33
+ ): CardLayoutSchema[] {
34
+ // 绑定数据
35
+ let renderLayout = applyItemCollectBindings(layout, items);
36
+ // 设置显示逻辑
37
+ renderLayout = setElementVisible(renderLayout, 'avatar', config.showAvatar);
38
+ renderLayout = setElementVisible(renderLayout, 'logo', config.showLogo);
39
+ // 设置背景
40
+ renderLayout = renderLayout.map((la, index) =>
41
+ backgroundChange(config.currentBg[index], la)
42
+ );
43
+ return renderLayout;
44
+ }