km-card-layout-core 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/dist/index.js CHANGED
@@ -193,49 +193,91 @@ const resolveBindingValue = (binding, rootData, context) => {
193
193
  };
194
194
  exports.resolveBindingValue = resolveBindingValue;
195
195
  /** ---------- 样式构建 ---------- */
196
+ const buildCardStyle = (layout, unit) => (0, exports.styleObjectToString)({
197
+ width: (0, exports.addUnit)(layout.width, unit),
198
+ height: (0, exports.addUnit)(layout.height, unit),
199
+ color: layout.fontColor,
200
+ borderRadius: layout.borderRadius !== undefined
201
+ ? (0, exports.addUnit)(layout.borderRadius, unit)
202
+ : undefined,
203
+ padding: layout.padding !== undefined ? (0, exports.addUnit)(layout.padding, unit) : undefined,
204
+ position: 'relative',
205
+ overflow: 'hidden',
206
+ boxSizing: 'border-box',
207
+ backgroundColor: 'transparent',
208
+ }, unit);
209
+ const buildBackgroundStyle = (layout, unit) => (0, exports.styleObjectToString)({
210
+ zIndex: layout.backgroundZIndex,
211
+ borderRadius: layout.borderRadius !== undefined
212
+ ? (0, exports.addUnit)(layout.borderRadius, unit)
213
+ : undefined,
214
+ width: '100%',
215
+ height: '100%',
216
+ position: 'absolute',
217
+ left: 0,
218
+ top: 0,
219
+ }, unit);
196
220
  /**
197
221
  * 生成元素外层样式(绝对/弹性布局),始终返回内联样式字符串。
198
222
  */
199
223
  const buildWrapperStyle = (el, unit) => {
200
- var _a;
201
224
  const abs = getAbsLayout(el);
202
- if (abs) {
203
- const textAlign = (_a = el === null || el === void 0 ? void 0 : el.style) === null || _a === void 0 ? void 0 : _a.textAlign;
204
- return (0, exports.styleObjectToString)({
205
- position: 'absolute',
206
- left: (0, exports.addUnit)(abs.x, unit),
207
- top: (0, exports.addUnit)(abs.y, unit),
208
- width: (0, exports.addUnit)(abs.width, unit),
209
- height: (0, exports.addUnit)(abs.height, unit),
210
- zIndex: abs.zIndex,
211
- boxSizing: 'border-box',
212
- textAlign,
213
- }, unit);
214
- }
215
- return '';
225
+ if (!abs)
226
+ return '';
227
+ return (0, exports.styleObjectToString)({
228
+ position: 'absolute',
229
+ left: (0, exports.addUnit)(abs.x, unit),
230
+ top: (0, exports.addUnit)(abs.y, unit),
231
+ width: (0, exports.addUnit)(abs.width, unit),
232
+ height: (0, exports.addUnit)(abs.height, unit),
233
+ zIndex: abs.zIndex,
234
+ boxSizing: 'border-box',
235
+ display: 'flex',
236
+ alignItems: 'center',
237
+ }, unit);
216
238
  };
217
- /**
218
- * padding 数组/数字转 CSS 缩写字符串。
219
- */
220
- /**
221
- * 构建 layout-panel 的容器样式(绝对布局容器)。
222
- */
223
- const buildPanelStyle = (el, unit) => {
239
+ const buildPanelContentStyle = (el, unit) => (0, exports.styleObjectToString)({
240
+ position: 'relative',
241
+ width: '100%',
242
+ height: '100%',
243
+ display: 'block',
244
+ boxSizing: 'border-box',
245
+ ...(el.style || {}),
246
+ }, unit);
247
+ const buildTextContentStyle = (el, unit) => {
248
+ var _a, _b, _c;
249
+ const textAlign = ((_a = el.style) === null || _a === void 0 ? void 0 : _a.textAlign) || el.align || undefined;
224
250
  const style = {
225
- display: 'block',
251
+ ...(el.style || {}),
252
+ whiteSpace: 'pre-wrap',
253
+ wordBreak: 'break-word',
254
+ 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
255
+ ? el.style.lineHeight
256
+ : '1.2',
257
+ display: 'inline-flex',
258
+ alignItems: 'center',
226
259
  };
260
+ if (textAlign)
261
+ style.textAlign = textAlign;
227
262
  return (0, exports.styleObjectToString)(style, unit);
228
263
  };
229
- /**
230
- * 元素样式转内联字符串(自动补单位)。
231
- */
232
- const normalizeElementStyle = (style, unit) => {
233
- if (!style)
234
- return '';
264
+ const buildBaseContentStyle = (el, unit) => (0, exports.styleObjectToString)({
265
+ ...(el.style || {}),
266
+ boxSizing: 'border-box',
267
+ }, unit);
268
+ const buildImageContentStyle = (el, unit) => {
269
+ const style = { ...(el.style || {}) };
270
+ const borderWidth = Number(style.borderWidth);
271
+ if (Number.isFinite(borderWidth) && borderWidth > 0) {
272
+ if (!style.borderStyle)
273
+ style.borderStyle = 'solid';
274
+ if (!style.borderColor)
275
+ style.borderColor = '#000000';
276
+ }
235
277
  return (0, exports.styleObjectToString)(style, unit);
236
278
  };
237
279
  const buildTextIcon = (el, unit) => {
238
- var _a, _b, _c;
280
+ var _a, _b, _c, _d;
239
281
  const icon = el.icon;
240
282
  if (!icon || icon.enable === false)
241
283
  return undefined;
@@ -262,6 +304,11 @@ const buildTextIcon = (el, unit) => {
262
304
  gap: (0, exports.addUnit)(gap, unit),
263
305
  color: color,
264
306
  align: icon.align || 'left',
307
+ wrapperStyle: (0, exports.styleObjectToString)({
308
+ display: 'inline-flex',
309
+ alignItems: 'center',
310
+ height: ((_d = el.style) === null || _d === void 0 ? void 0 : _d.lineHeight) || 'auto',
311
+ }, unit),
265
312
  };
266
313
  };
267
314
  /** ---------- 渲染树构建 ---------- */
@@ -286,7 +333,7 @@ exports.buildRenderNodes = buildRenderNodes;
286
333
  * 构建单个渲染节点(layout-panel 递归处理子元素)。
287
334
  */
288
335
  const buildNode = (el, rootData, unit, context) => {
289
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
336
+ var _a, _b, _c, _d, _e, _f, _g, _h;
290
337
  if (!el || el.visible === false)
291
338
  return null;
292
339
  const wrapperStyle = buildWrapperStyle(el, unit);
@@ -296,40 +343,38 @@ const buildNode = (el, rootData, unit, context) => {
296
343
  type: el.type,
297
344
  visible: !!el.visible,
298
345
  wrapperStyle,
299
- contentStyle: buildPanelStyle(el, unit),
346
+ contentStyle: buildPanelContentStyle(el, unit),
300
347
  children: (0, exports.buildRenderNodes)(el.children || [], rootData, unit, context),
301
348
  };
302
349
  }
303
- const baseStyle = normalizeElementStyle(el.style, unit);
350
+ const baseStyle = buildBaseContentStyle(el, unit);
304
351
  if (el.type === 'text') {
305
- const align = ((_a = el.style) === null || _a === void 0 ? void 0 : _a.textAlign) || el.align;
306
- const textStyle = align ? `${baseStyle};text-align:${align}` : baseStyle;
307
- const value = (_c = (_b = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _b !== void 0 ? _b : el.defaultValue) !== null && _c !== void 0 ? _c : '';
352
+ const value = (_b = (_a = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _a !== void 0 ? _a : el.defaultValue) !== null && _b !== void 0 ? _b : '';
308
353
  return {
309
354
  id: el.id,
310
355
  type: el.type,
311
356
  wrapperStyle,
312
- contentStyle: textStyle,
357
+ contentStyle: buildTextContentStyle(el, unit),
313
358
  text: `${value}`,
314
359
  visible: !!el.visible,
315
360
  icon: buildTextIcon(el, unit),
316
361
  };
317
362
  }
318
363
  if (el.type === 'image') {
319
- const src = (_f = (_e = (_d = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _d !== void 0 ? _d : el.defaultUrl) !== null && _e !== void 0 ? _e : el.defaultValue) !== null && _f !== void 0 ? _f : '';
364
+ const src = (_e = (_d = (_c = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _c !== void 0 ? _c : el.defaultUrl) !== null && _d !== void 0 ? _d : el.defaultValue) !== null && _e !== void 0 ? _e : '';
320
365
  const mode = el.fit === 'contain' ? 'aspectFit' : 'aspectFill';
321
366
  return {
322
367
  id: el.id,
323
368
  type: el.type,
324
369
  wrapperStyle,
325
- contentStyle: baseStyle,
370
+ contentStyle: buildImageContentStyle(el, unit),
326
371
  src,
327
372
  mode,
328
373
  visible: !!el.visible,
329
374
  };
330
375
  }
331
376
  if (el.type === 'icon') {
332
- const name = (_j = (_h = (_g = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _g !== void 0 ? _g : el.name) !== null && _h !== void 0 ? _h : el.defaultValue) !== null && _j !== void 0 ? _j : '';
377
+ const name = (_h = (_g = (_f = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _f !== void 0 ? _f : el.name) !== null && _g !== void 0 ? _g : el.defaultValue) !== null && _h !== void 0 ? _h : '';
333
378
  return {
334
379
  id: el.id,
335
380
  type: el.type,
@@ -357,24 +402,8 @@ const buildNode = (el, rootData, unit, context) => {
357
402
  const buildRenderResult = (layoutInput, dataInput, unit = 'px') => {
358
403
  const layouts = (0, exports.normalizeLayout)(layoutInput);
359
404
  return layouts.map(layout => {
360
- const cardStyle = (0, exports.styleObjectToString)({
361
- width: (0, exports.addUnit)(layout.width, unit),
362
- height: (0, exports.addUnit)(layout.height, unit),
363
- color: layout.fontColor,
364
- borderRadius: layout.borderRadius !== undefined
365
- ? (0, exports.addUnit)(layout.borderRadius, unit)
366
- : undefined,
367
- padding: layout.padding !== undefined
368
- ? (0, exports.addUnit)(layout.padding, unit)
369
- : undefined,
370
- position: 'relative',
371
- }, unit);
372
- const bgStyle = (0, exports.styleObjectToString)({
373
- zIndex: layout.backgroundZIndex,
374
- borderRadius: layout.borderRadius !== undefined
375
- ? (0, exports.addUnit)(layout.borderRadius, unit)
376
- : undefined,
377
- }, unit);
405
+ const cardStyle = buildCardStyle(layout, unit);
406
+ const bgStyle = buildBackgroundStyle(layout, unit);
378
407
  const renderTree = (0, exports.buildRenderNodes)(layout.children || [], dataInput || {}, unit);
379
408
  return {
380
409
  renderTree,
package/dist/utils.js CHANGED
@@ -4,6 +4,7 @@ exports.backgroundChange = backgroundChange;
4
4
  exports.stripLayoutBindings = stripLayoutBindings;
5
5
  exports.applyItemCollectBindings = applyItemCollectBindings;
6
6
  exports.getTemplateItems = getTemplateItems;
7
+ exports.getTemplateBackgrounds = getTemplateBackgrounds;
7
8
  function backgroundChange(bg, layout) {
8
9
  const toNameArray = (name) => {
9
10
  if (Array.isArray(name))
@@ -124,3 +125,7 @@ function getTemplateItems(ids, items) {
124
125
  const idArray = ids.split(',').map(id => id.trim());
125
126
  return items.filter(item => idArray.includes(String(item.id)));
126
127
  }
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
+ }
package/index.ts CHANGED
@@ -204,57 +204,131 @@ export const resolveBindingValue = (
204
204
  return value === undefined ? undefined : value;
205
205
  };
206
206
 
207
- /** ---------- 样式构建 ---------- */
208
-
209
- /**
210
- * 生成元素外层样式(绝对/弹性布局),始终返回内联样式字符串。
211
- */
212
- const buildWrapperStyle = (el: CardElement, unit: 'px' | 'rpx'): string => {
213
- const abs = getAbsLayout(el);
214
- if (abs) {
215
- const textAlign = el?.style?.textAlign as string | undefined;
216
- return styleObjectToString(
217
- {
218
- position: 'absolute',
219
- left: addUnit(abs.x, unit),
220
- top: addUnit(abs.y, unit),
221
- width: addUnit(abs.width, unit),
222
- height: addUnit(abs.height, unit),
223
- zIndex: abs.zIndex,
224
- boxSizing: 'border-box',
225
- textAlign,
226
- },
227
- unit
228
- );
229
- }
230
-
231
- return '';
232
- };
233
- /**
234
- * padding 数组/数字转 CSS 缩写字符串。
235
- */
236
- /**
237
- * 构建 layout-panel 的容器样式(绝对布局容器)。
238
- */
239
- const buildPanelStyle = (
240
- el: LayoutPanelElement,
241
- unit: 'px' | 'rpx'
242
- ): string => {
243
- const style = {
244
- display: 'block',
245
- } as Record<string, any>;
246
- return styleObjectToString(style, unit);
247
- };
248
- /**
249
- * 元素样式转内联字符串(自动补单位)。
250
- */
251
- const normalizeElementStyle = (
252
- style: Record<string, any> | undefined,
253
- unit: 'px' | 'rpx'
254
- ): string => {
255
- if (!style) return '';
256
- return styleObjectToString(style, unit);
257
- };
207
+ /** ---------- 样式构建 ---------- */
208
+
209
+ const buildCardStyle = (
210
+ layout: CardLayoutSchema,
211
+ unit: 'px' | 'rpx'
212
+ ): string =>
213
+ styleObjectToString(
214
+ {
215
+ width: addUnit(layout.width, unit),
216
+ height: addUnit(layout.height, unit),
217
+ color: layout.fontColor,
218
+ borderRadius:
219
+ layout.borderRadius !== undefined
220
+ ? addUnit(layout.borderRadius, unit)
221
+ : undefined,
222
+ padding:
223
+ layout.padding !== undefined ? addUnit(layout.padding, unit) : undefined,
224
+ position: 'relative',
225
+ overflow: 'hidden',
226
+ boxSizing: 'border-box',
227
+ backgroundColor: 'transparent',
228
+ },
229
+ unit
230
+ );
231
+
232
+ const buildBackgroundStyle = (
233
+ layout: CardLayoutSchema,
234
+ unit: 'px' | 'rpx'
235
+ ): string =>
236
+ styleObjectToString(
237
+ {
238
+ zIndex: layout.backgroundZIndex,
239
+ borderRadius:
240
+ layout.borderRadius !== undefined
241
+ ? addUnit(layout.borderRadius, unit)
242
+ : undefined,
243
+ width: '100%',
244
+ height: '100%',
245
+ position: 'absolute',
246
+ left: 0,
247
+ top: 0,
248
+ },
249
+ unit
250
+ );
251
+
252
+ /**
253
+ * 生成元素外层样式(绝对/弹性布局),始终返回内联样式字符串。
254
+ */
255
+ const buildWrapperStyle = (el: CardElement, unit: 'px' | 'rpx'): string => {
256
+ const abs = getAbsLayout(el);
257
+ if (!abs) return '';
258
+
259
+ return styleObjectToString(
260
+ {
261
+ position: 'absolute',
262
+ left: addUnit(abs.x, unit),
263
+ top: addUnit(abs.y, unit),
264
+ width: addUnit(abs.width, unit),
265
+ height: addUnit(abs.height, unit),
266
+ zIndex: abs.zIndex,
267
+ boxSizing: 'border-box',
268
+ display: 'flex',
269
+ alignItems: 'center',
270
+ },
271
+ unit
272
+ );
273
+ };
274
+ const buildPanelContentStyle = (
275
+ el: LayoutPanelElement,
276
+ unit: 'px' | 'rpx'
277
+ ): string =>
278
+ styleObjectToString(
279
+ {
280
+ position: 'relative',
281
+ width: '100%',
282
+ height: '100%',
283
+ display: 'block',
284
+ boxSizing: 'border-box',
285
+ ...(el.style || {}),
286
+ },
287
+ unit
288
+ );
289
+
290
+ const buildTextContentStyle = (el: TextElement, unit: 'px' | 'rpx') => {
291
+ const textAlign =
292
+ (el.style?.textAlign as string | undefined) || el.align || undefined;
293
+ const style: Record<string, any> = {
294
+ ...(el.style || {}),
295
+ whiteSpace: 'pre-wrap',
296
+ wordBreak: 'break-word',
297
+ lineHeight:
298
+ el.style?.lineHeight !== undefined && el.style?.lineHeight !== null
299
+ ? el.style.lineHeight
300
+ : '1.2',
301
+ display: 'inline-flex',
302
+ alignItems: 'center',
303
+ };
304
+ if (textAlign) style.textAlign = textAlign;
305
+ return styleObjectToString(style, unit);
306
+ };
307
+
308
+ const buildBaseContentStyle = (
309
+ el: CardElement,
310
+ unit: 'px' | 'rpx'
311
+ ): string =>
312
+ styleObjectToString(
313
+ {
314
+ ...(el.style || {}),
315
+ boxSizing: 'border-box',
316
+ },
317
+ unit
318
+ );
319
+
320
+ const buildImageContentStyle = (
321
+ el: ImageElement,
322
+ unit: 'px' | 'rpx'
323
+ ): string => {
324
+ const style: Record<string, any> = { ...(el.style || {}) };
325
+ const borderWidth = Number(style.borderWidth);
326
+ if (Number.isFinite(borderWidth) && borderWidth > 0) {
327
+ if (!style.borderStyle) style.borderStyle = 'solid';
328
+ if (!style.borderColor) style.borderColor = '#000000';
329
+ }
330
+ return styleObjectToString(style, unit);
331
+ };
258
332
 
259
333
  const buildTextIcon = (
260
334
  el: TextElement,
@@ -283,15 +357,23 @@ const buildTextIcon = (
283
357
  | string
284
358
  | undefined);
285
359
 
286
- return {
287
- name: `${name}`,
288
- text: `${name}`,
289
- size: addUnit(size as any, unit),
290
- gap: addUnit(gap as any, unit),
291
- color: color as any,
292
- align: icon.align || 'left',
293
- };
294
- };
360
+ return {
361
+ name: `${name}`,
362
+ text: `${name}`,
363
+ size: addUnit(size as any, unit),
364
+ gap: addUnit(gap as any, unit),
365
+ color: color as any,
366
+ align: icon.align || 'left',
367
+ wrapperStyle: styleObjectToString(
368
+ {
369
+ display: 'inline-flex',
370
+ alignItems: 'center',
371
+ height: el.style?.lineHeight || 'auto',
372
+ },
373
+ unit
374
+ ),
375
+ };
376
+ };
295
377
 
296
378
  /** ---------- 渲染树构建 ---------- */
297
379
  /**
@@ -326,54 +408,52 @@ const buildNode = (
326
408
  if (!el || el.visible === false) return null;
327
409
  const wrapperStyle = buildWrapperStyle(el, unit);
328
410
 
329
- if (el.type === 'layout-panel') {
330
- return {
331
- id: el.id,
332
- type: el.type,
333
- visible: !!el.visible,
334
- wrapperStyle,
335
- contentStyle: buildPanelStyle(el as LayoutPanelElement, unit),
336
- children: buildRenderNodes(el.children || [], rootData, unit, context),
337
- };
338
- }
339
-
340
- const baseStyle = normalizeElementStyle(el.style, unit);
341
- if (el.type === 'text') {
342
- const align = (el.style?.textAlign as string | undefined) || el.align;
343
- const textStyle = align ? `${baseStyle};text-align:${align}` : baseStyle;
344
- const value =
345
- resolveBindingValue(el.binding, rootData, context) ??
346
- el.defaultValue ??
347
- '';
348
- return {
349
- id: el.id,
350
- type: el.type,
351
- wrapperStyle,
352
- contentStyle: textStyle,
353
- text: `${value}`,
354
- visible: !!el.visible,
355
- icon: buildTextIcon(el as TextElement, unit),
356
- };
357
- }
358
-
359
- if (el.type === 'image') {
360
- const src =
361
- resolveBindingValue(el.binding, rootData, context) ??
362
- (el as ImageElement).defaultUrl ??
363
- el.defaultValue ??
411
+ if (el.type === 'layout-panel') {
412
+ return {
413
+ id: el.id,
414
+ type: el.type,
415
+ visible: !!el.visible,
416
+ wrapperStyle,
417
+ contentStyle: buildPanelContentStyle(el as LayoutPanelElement, unit),
418
+ children: buildRenderNodes(el.children || [], rootData, unit, context),
419
+ };
420
+ }
421
+
422
+ const baseStyle = buildBaseContentStyle(el, unit);
423
+ if (el.type === 'text') {
424
+ const value =
425
+ resolveBindingValue(el.binding, rootData, context) ??
426
+ el.defaultValue ??
427
+ '';
428
+ return {
429
+ id: el.id,
430
+ type: el.type,
431
+ wrapperStyle,
432
+ contentStyle: buildTextContentStyle(el as TextElement, unit),
433
+ text: `${value}`,
434
+ visible: !!el.visible,
435
+ icon: buildTextIcon(el as TextElement, unit),
436
+ };
437
+ }
438
+
439
+ if (el.type === 'image') {
440
+ const src =
441
+ resolveBindingValue(el.binding, rootData, context) ??
442
+ (el as ImageElement).defaultUrl ??
443
+ el.defaultValue ??
364
444
  '';
365
- const mode =
366
- (el as ImageElement).fit === 'contain' ? 'aspectFit' : 'aspectFill';
367
- return {
368
- id: el.id,
369
- type: el.type,
370
- wrapperStyle,
371
- contentStyle: baseStyle,
372
- src,
373
- mode,
374
- visible: !!el.visible,
375
- };
376
- }
445
+ const mode =
446
+ (el as ImageElement).fit === 'contain' ? 'aspectFit' : 'aspectFill';
447
+ return {
448
+ id: el.id,
449
+ type: el.type,
450
+ wrapperStyle,
451
+ contentStyle: buildImageContentStyle(el as ImageElement, unit),
452
+ src,
453
+ mode,
454
+ visible: !!el.visible,
455
+ };
456
+ }
377
457
 
378
458
  if (el.type === 'icon') {
379
459
  const name =
@@ -412,39 +492,14 @@ export const buildRenderResult = (
412
492
  dataInput: Record<string, any>,
413
493
  unit: 'px' | 'rpx' = 'px'
414
494
  ): RenderResult => {
415
- const layouts = normalizeLayout(layoutInput);
416
- return layouts.map(layout => {
417
- const cardStyle = styleObjectToString(
418
- {
419
- width: addUnit(layout.width, unit),
420
- height: addUnit(layout.height, unit),
421
- color: layout.fontColor,
422
- borderRadius:
423
- layout.borderRadius !== undefined
424
- ? addUnit(layout.borderRadius, unit)
425
- : undefined,
426
- padding:
427
- layout.padding !== undefined
428
- ? addUnit(layout.padding, unit)
429
- : undefined,
430
- position: 'relative',
431
- },
432
- unit
433
- );
434
- const bgStyle = styleObjectToString(
435
- {
436
- zIndex: layout.backgroundZIndex,
437
- borderRadius:
438
- layout.borderRadius !== undefined
439
- ? addUnit(layout.borderRadius, unit)
440
- : undefined,
441
- },
442
- unit
443
- );
444
-
445
- const renderTree = buildRenderNodes(
446
- layout.children || [],
447
- dataInput || {},
495
+ const layouts = normalizeLayout(layoutInput);
496
+ return layouts.map(layout => {
497
+ const cardStyle = buildCardStyle(layout, unit);
498
+ const bgStyle = buildBackgroundStyle(layout, unit);
499
+
500
+ const renderTree = buildRenderNodes(
501
+ layout.children || [],
502
+ dataInput || {},
448
503
  unit
449
504
  );
450
505
 
@@ -457,4 +512,4 @@ export const buildRenderResult = (
457
512
  });
458
513
  };
459
514
 
460
- export * from './utils';
515
+ export * from './utils';
@@ -1,3 +1,5 @@
1
+ import { CardLayoutSchema } from "../layout";
2
+
1
3
  /**
2
4
  * 背景项
3
5
  */
@@ -6,11 +8,10 @@ export interface TemplateBackground {
6
8
  name: string;
7
9
  fileId?: number;
8
10
  fontColor?: string;
9
- fontColorExtra?: { name: string | string[]; color: string }[]
11
+ fontColorExtra?: { name: string | string[]; color: string }[];
10
12
  imgUrl: string;
11
13
  }
12
14
 
13
-
14
15
  /**
15
16
  * 元素项
16
17
  */
@@ -25,3 +26,20 @@ export interface TemplateItem {
25
26
  cate: number;
26
27
  required?: 0 | 1;
27
28
  }
29
+
30
+ export interface TemplateLayoutInfo {
31
+ id: number | string;
32
+ name?: string;
33
+ previewImg?: string;
34
+ height?: number;
35
+ width?: number;
36
+ enableBgIds?: string | null;
37
+ enableItemIds?: string | null;
38
+ content?: CardLayoutSchema[];
39
+ isVip?: 0 | 1;
40
+ isDouble?: 0 | 1;
41
+ isMoreCompany?: 0 | 1;
42
+ isBgCustomize?: 0 | 1;
43
+ createAt?: string;
44
+ updateAt?: string;
45
+ }
@@ -8,6 +8,7 @@ export interface RenderNodeIcon {
8
8
  color?: string;
9
9
  gap?: string;
10
10
  align?: 'left' | 'right';
11
+ wrapperStyle?: string;
11
12
  }
12
13
 
13
14
  export interface RenderNode {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "km-card-layout-core",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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/types.d.ts CHANGED
@@ -12,15 +12,10 @@ import type {
12
12
  CardLayoutSchema,
13
13
  RenderNode,
14
14
  RenderResult,
15
+ TemplateBackground,
16
+ TemplateItem,
15
17
  } from './interface';
16
18
 
17
- export type ItemCollectMeta = {
18
- id: string | number;
19
- bind?: string | null;
20
- default?: string | null;
21
- key?: string | null;
22
- };
23
-
24
19
  export function addUnit(
25
20
  value: string | number | undefined | null,
26
21
  unit: 'px' | 'rpx'
@@ -45,7 +40,7 @@ export function stripLayoutBindings(
45
40
 
46
41
  export function applyItemCollectBindings(
47
42
  layouts: CardLayoutSchema[],
48
- items?: ItemCollectMeta[]
43
+ items?: TemplateItem[]
49
44
  ): CardLayoutSchema[];
50
45
 
51
46
  export function buildRenderNodes(
@@ -60,3 +55,7 @@ export function buildRenderResult(
60
55
  data: Record<string, any>,
61
56
  unit?: 'px' | 'rpx'
62
57
  ): RenderResult;
58
+
59
+ export function getTemplateItems(ids: string, items: TemplateItem[]): TemplateItem[];
60
+
61
+ export function getTemplateBackgrounds(ids: string, items: TemplateBackground[]) : TemplateBackground[];
package/utils.ts CHANGED
@@ -1,12 +1,6 @@
1
- import type { CardElement, CardLayoutSchema } from './interface';
1
+ import type { CardElement, CardLayoutSchema, TemplateItem } from './interface';
2
2
  import { TemplateBackground } from './interface/data/payload';
3
3
 
4
- export type ItemCollectMeta = {
5
- id: string | number;
6
- bind?: string | null;
7
- default?: string | null;
8
- key?: string | null;
9
- };
10
4
 
11
5
  export function backgroundChange(
12
6
  bg: TemplateBackground,
@@ -92,10 +86,10 @@ export function stripLayoutBindings(
92
86
  */
93
87
  export function applyItemCollectBindings(
94
88
  layouts: CardLayoutSchema[] = [],
95
- items: ItemCollectMeta[] = []
89
+ items: TemplateItem[] = []
96
90
  ): CardLayoutSchema[] {
97
91
  const targetLayouts = Array.isArray(layouts) ? layouts : [];
98
- const metaMap = new Map<string, ItemCollectMeta>();
92
+ const metaMap = new Map<string, TemplateItem>();
99
93
  const metaList = Array.isArray(items) ? items : [];
100
94
  metaList.forEach(item => {
101
95
  if (item && item.id !== undefined && item.id !== null) {
@@ -135,7 +129,13 @@ export function applyItemCollectBindings(
135
129
  }));
136
130
  }
137
131
 
138
- export function getTemplateItems(ids: string, items: ItemCollectMeta[]) {
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
139
  const idArray = ids.split(',').map(id => id.trim());
140
140
  return items.filter(item => idArray.includes(String(item.id)));
141
141
  }