km-card-layout-core 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.
- package/dist/index.js +92 -63
- package/index.ts +129 -74
- package/interface/data/payload.ts +20 -2
- package/interface/render.ts +1 -0
- package/package.json +1 -1
- package/types.d.ts +3 -1
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
|
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);
|
|
@@ -294,42 +341,40 @@ const buildNode = (el, rootData, unit, context) => {
|
|
|
294
341
|
return {
|
|
295
342
|
id: el.id,
|
|
296
343
|
type: el.type,
|
|
297
|
-
visible:
|
|
344
|
+
visible: el.visible,
|
|
298
345
|
wrapperStyle,
|
|
299
|
-
contentStyle:
|
|
346
|
+
contentStyle: buildPanelContentStyle(el, unit),
|
|
300
347
|
children: (0, exports.buildRenderNodes)(el.children || [], rootData, unit, context),
|
|
301
348
|
};
|
|
302
349
|
}
|
|
303
|
-
const baseStyle =
|
|
350
|
+
const baseStyle = buildBaseContentStyle(el, unit);
|
|
304
351
|
if (el.type === 'text') {
|
|
305
|
-
const
|
|
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:
|
|
357
|
+
contentStyle: buildTextContentStyle(el, unit),
|
|
313
358
|
text: `${value}`,
|
|
314
|
-
visible:
|
|
359
|
+
visible: el.visible,
|
|
315
360
|
icon: buildTextIcon(el, unit),
|
|
316
361
|
};
|
|
317
362
|
}
|
|
318
363
|
if (el.type === 'image') {
|
|
319
|
-
const src = (
|
|
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:
|
|
370
|
+
contentStyle: buildImageContentStyle(el, unit),
|
|
326
371
|
src,
|
|
327
372
|
mode,
|
|
328
|
-
visible:
|
|
373
|
+
visible: el.visible,
|
|
329
374
|
};
|
|
330
375
|
}
|
|
331
376
|
if (el.type === 'icon') {
|
|
332
|
-
const name = (
|
|
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,
|
|
@@ -337,7 +382,7 @@ const buildNode = (el, rootData, unit, context) => {
|
|
|
337
382
|
contentStyle: baseStyle,
|
|
338
383
|
name: `${name}`,
|
|
339
384
|
text: `${name}`,
|
|
340
|
-
visible:
|
|
385
|
+
visible: el.visible,
|
|
341
386
|
};
|
|
342
387
|
}
|
|
343
388
|
if (el.type === 'custom') {
|
|
@@ -346,7 +391,7 @@ const buildNode = (el, rootData, unit, context) => {
|
|
|
346
391
|
type: el.type,
|
|
347
392
|
wrapperStyle,
|
|
348
393
|
contentStyle: baseStyle,
|
|
349
|
-
visible:
|
|
394
|
+
visible: el.visible,
|
|
350
395
|
};
|
|
351
396
|
}
|
|
352
397
|
return null;
|
|
@@ -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 = (
|
|
361
|
-
|
|
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/index.ts
CHANGED
|
@@ -206,53 +206,127 @@ export const resolveBindingValue = (
|
|
|
206
206
|
|
|
207
207
|
/** ---------- 样式构建 ---------- */
|
|
208
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
|
+
|
|
209
252
|
/**
|
|
210
253
|
* 生成元素外层样式(绝对/弹性布局),始终返回内联样式字符串。
|
|
211
254
|
*/
|
|
212
255
|
const buildWrapperStyle = (el: CardElement, unit: 'px' | 'rpx'): string => {
|
|
213
256
|
const abs = getAbsLayout(el);
|
|
214
|
-
if (abs)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return '';
|
|
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
|
+
);
|
|
232
273
|
};
|
|
233
|
-
|
|
234
|
-
* padding 数组/数字转 CSS 缩写字符串。
|
|
235
|
-
*/
|
|
236
|
-
/**
|
|
237
|
-
* 构建 layout-panel 的容器样式(绝对布局容器)。
|
|
238
|
-
*/
|
|
239
|
-
const buildPanelStyle = (
|
|
274
|
+
const buildPanelContentStyle = (
|
|
240
275
|
el: LayoutPanelElement,
|
|
241
276
|
unit: 'px' | 'rpx'
|
|
242
|
-
): string =>
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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;
|
|
246
305
|
return styleObjectToString(style, unit);
|
|
247
306
|
};
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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,
|
|
253
322
|
unit: 'px' | 'rpx'
|
|
254
323
|
): string => {
|
|
255
|
-
|
|
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
|
+
}
|
|
256
330
|
return styleObjectToString(style, unit);
|
|
257
331
|
};
|
|
258
332
|
|
|
@@ -290,6 +364,14 @@ const buildTextIcon = (
|
|
|
290
364
|
gap: addUnit(gap as any, unit),
|
|
291
365
|
color: color as any,
|
|
292
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
|
+
),
|
|
293
375
|
};
|
|
294
376
|
};
|
|
295
377
|
|
|
@@ -330,17 +412,15 @@ const buildNode = (
|
|
|
330
412
|
return {
|
|
331
413
|
id: el.id,
|
|
332
414
|
type: el.type,
|
|
333
|
-
visible:
|
|
415
|
+
visible: el.visible,
|
|
334
416
|
wrapperStyle,
|
|
335
|
-
contentStyle:
|
|
417
|
+
contentStyle: buildPanelContentStyle(el as LayoutPanelElement, unit),
|
|
336
418
|
children: buildRenderNodes(el.children || [], rootData, unit, context),
|
|
337
419
|
};
|
|
338
420
|
}
|
|
339
421
|
|
|
340
|
-
const baseStyle =
|
|
422
|
+
const baseStyle = buildBaseContentStyle(el, unit);
|
|
341
423
|
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
424
|
const value =
|
|
345
425
|
resolveBindingValue(el.binding, rootData, context) ??
|
|
346
426
|
el.defaultValue ??
|
|
@@ -349,9 +429,9 @@ const buildNode = (
|
|
|
349
429
|
id: el.id,
|
|
350
430
|
type: el.type,
|
|
351
431
|
wrapperStyle,
|
|
352
|
-
contentStyle:
|
|
432
|
+
contentStyle: buildTextContentStyle(el as TextElement, unit),
|
|
353
433
|
text: `${value}`,
|
|
354
|
-
visible:
|
|
434
|
+
visible: el.visible,
|
|
355
435
|
icon: buildTextIcon(el as TextElement, unit),
|
|
356
436
|
};
|
|
357
437
|
}
|
|
@@ -368,10 +448,10 @@ const buildNode = (
|
|
|
368
448
|
id: el.id,
|
|
369
449
|
type: el.type,
|
|
370
450
|
wrapperStyle,
|
|
371
|
-
contentStyle:
|
|
451
|
+
contentStyle: buildImageContentStyle(el as ImageElement, unit),
|
|
372
452
|
src,
|
|
373
453
|
mode,
|
|
374
|
-
visible:
|
|
454
|
+
visible: el.visible,
|
|
375
455
|
};
|
|
376
456
|
}
|
|
377
457
|
|
|
@@ -388,7 +468,7 @@ const buildNode = (
|
|
|
388
468
|
contentStyle: baseStyle,
|
|
389
469
|
name: `${name}`,
|
|
390
470
|
text: `${name}`,
|
|
391
|
-
visible:
|
|
471
|
+
visible: el.visible,
|
|
392
472
|
};
|
|
393
473
|
}
|
|
394
474
|
|
|
@@ -398,7 +478,7 @@ const buildNode = (
|
|
|
398
478
|
type: el.type,
|
|
399
479
|
wrapperStyle,
|
|
400
480
|
contentStyle: baseStyle,
|
|
401
|
-
visible:
|
|
481
|
+
visible: el.visible,
|
|
402
482
|
};
|
|
403
483
|
}
|
|
404
484
|
|
|
@@ -414,33 +494,8 @@ export const buildRenderResult = (
|
|
|
414
494
|
): RenderResult => {
|
|
415
495
|
const layouts = normalizeLayout(layoutInput);
|
|
416
496
|
return layouts.map(layout => {
|
|
417
|
-
const cardStyle =
|
|
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
|
-
);
|
|
497
|
+
const cardStyle = buildCardStyle(layout, unit);
|
|
498
|
+
const bgStyle = buildBackgroundStyle(layout, unit);
|
|
444
499
|
|
|
445
500
|
const renderTree = buildRenderNodes(
|
|
446
501
|
layout.children || [],
|
|
@@ -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
|
+
}
|
package/interface/render.ts
CHANGED
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ import type {
|
|
|
12
12
|
CardLayoutSchema,
|
|
13
13
|
RenderNode,
|
|
14
14
|
RenderResult,
|
|
15
|
+
TemplateBackground,
|
|
16
|
+
TemplateItem,
|
|
15
17
|
} from './interface';
|
|
16
18
|
|
|
17
19
|
export function addUnit(
|
|
@@ -56,4 +58,4 @@ export function buildRenderResult(
|
|
|
56
58
|
|
|
57
59
|
export function getTemplateItems(ids: string, items: TemplateItem[]): TemplateItem[];
|
|
58
60
|
|
|
59
|
-
export function getTemplateBackgrounds(ids: string, items: TemplateBackground[]) : TemplateBackground[];
|
|
61
|
+
export function getTemplateBackgrounds(ids: string, items: TemplateBackground[]) : TemplateBackground[];
|