km-card-layout-core 0.1.26 → 0.1.27

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/types.d.ts CHANGED
@@ -10,17 +10,15 @@ import type {
10
10
  CardLayoutInput,
11
11
  CardLayoutSchema,
12
12
  TemplateItem,
13
- TemplateBackground
13
+ TemplateBackground,
14
14
  } from './interface';
15
-
16
- export type Config = {
17
- showAvatar: boolean;
18
- showLogo: boolean;
19
- /**
20
- * 当前背景 (0 为正面背景 1 为背面背景)
21
- */
22
- currentBg: TemplateBackground[];
23
- };
15
+ import type {
16
+ AbsoluteLayoutDefinition,
17
+ LayoutPanelElement,
18
+ TextElement,
19
+ ImageElement,
20
+ IconElement,
21
+ } from './interface/elements';
24
22
 
25
23
  export function addUnit(
26
24
  value: string | number | undefined | null,
@@ -48,9 +46,7 @@ export function roundToInt(value: number): number;
48
46
 
49
47
  export function getAbsLayout(
50
48
  el: CardElement
51
- ): import('./interface/elements').AbsoluteLayoutDefinition | null;
52
-
53
- export function collectBindings(elements?: CardElement[]): string[];
49
+ ): AbsoluteLayoutDefinition | null;
54
50
 
55
51
  export function normalizeId(
56
52
  id?: string | number | null
@@ -58,11 +54,6 @@ export function normalizeId(
58
54
 
59
55
  export function parseLayout(input: unknown): CardLayoutSchema | null;
60
56
 
61
- export function areChildrenEqual(
62
- a?: CardLayoutSchema | null,
63
- b?: CardLayoutSchema | null
64
- ): boolean;
65
-
66
57
  export function resolveBindingValue(
67
58
  binding: string | undefined,
68
59
  rootData: Record<string, any>
@@ -74,76 +65,14 @@ export function stripLayoutBindings(
74
65
 
75
66
  export function applyItemCollectBindings(
76
67
  layouts: CardLayoutSchema[],
77
- items?: import('./interface/data/payload').TemplateItem[]
68
+ items?: TemplateItem[]
78
69
  ): CardLayoutSchema[];
79
70
 
80
- export function getTemplateItems(
81
- ids: string,
82
- items: import('./interface/data/payload').TemplateItem[]
83
- ): import('./interface/data/payload').TemplateItem[];
84
-
85
- export function getTemplateBackgrounds(
86
- ids: string,
87
- items: import('./interface/data/payload').TemplateBackground[]
88
- ): import('./interface/data/payload').TemplateBackground[];
89
-
90
71
  export function backgroundChange(
91
- bg: import('./interface/data/payload').TemplateBackground,
72
+ bg: TemplateBackground,
92
73
  layout: CardLayoutSchema
93
74
  ): CardLayoutSchema;
94
75
 
95
- export const DEFAULT_DECOR_COLOR: string;
96
-
97
- export function resolveSpecialStyle(
98
- element: CardElement,
99
- background?: {
100
- id?: string | number;
101
- name?: string;
102
- imageUrl?: string;
103
- mainColor?: string;
104
- specialColors?: { name: string | string[]; color: string }[];
105
- } | null
106
- ): Record<string, any>;
107
-
108
- export function applySpecialStyle(
109
- element: CardElement,
110
- background?: {
111
- id?: string | number;
112
- name?: string;
113
- imageUrl?: string;
114
- mainColor?: string;
115
- specialColors?: { name: string | string[]; color: string }[];
116
- } | null,
117
- options?: { overrideExisting?: boolean; defaultDecorColor?: string }
118
- ): CardElement;
119
-
120
- export function applyBackground(
121
- layout: CardLayoutSchema,
122
- background: {
123
- id?: string | number;
124
- name?: string;
125
- imageUrl?: string;
126
- mainColor?: string;
127
- specialColors?: { name: string | string[]; color: string }[];
128
- },
129
- options?: {
130
- previousBackground?: {
131
- id?: string | number;
132
- name?: string;
133
- imageUrl?: string;
134
- mainColor?: string;
135
- specialColors?: { name: string | string[]; color: string }[];
136
- } | null;
137
- defaultDecorColor?: string;
138
- }
139
- ): CardLayoutSchema;
140
-
141
- export function updateElementsStyle(
142
- layout: CardLayoutSchema,
143
- targetIds: string[],
144
- updates: Record<string, any>
145
- ): CardLayoutSchema;
146
-
147
76
  export function buildWrapperStyle(
148
77
  el: CardElement,
149
78
  unit?: 'px' | 'rpx'
@@ -164,35 +93,39 @@ export function buildBaseContentStyle(
164
93
  ): Record<string, any>;
165
94
 
166
95
  export function buildPanelContentStyle(
167
- el: import('./interface/elements').LayoutPanelElement,
96
+ el: LayoutPanelElement,
168
97
  unit?: 'px' | 'rpx'
169
98
  ): Record<string, any>;
170
99
 
171
100
  export function buildTextContentStyle(
172
- el: import('./interface/elements').TextElement,
101
+ el: TextElement,
102
+ unit?: 'px' | 'rpx'
103
+ ): Record<string, any>;
104
+
105
+ export function buildTextValueStyle(
106
+ el: TextElement,
173
107
  unit?: 'px' | 'rpx'
174
108
  ): Record<string, any>;
175
109
 
176
110
  export function buildImageContentStyle(
177
- el: import('./interface/elements').ImageElement
111
+ el: ImageElement,
112
+ unit?: 'px' | 'rpx'
178
113
  ): Record<string, any>;
179
114
 
180
115
  export function getTextValue(
181
- el: import('./interface/elements').TextElement,
116
+ el: TextElement,
182
117
  data?: Record<string, any>
183
118
  ): string;
184
119
 
185
120
  export function getImageSrc(
186
- el: import('./interface/elements').ImageElement,
121
+ el: ImageElement,
187
122
  data?: Record<string, any>
188
123
  ): string;
189
124
 
190
- export function getIconName(
191
- el: import('./interface/elements').IconElement
192
- ): string;
125
+ export function getIconName(el: IconElement): string;
193
126
 
194
127
  export function buildTextIconMeta(
195
- el: import('./interface/elements').TextElement,
128
+ el: TextElement,
196
129
  unit?: 'px' | 'rpx'
197
130
  ): {
198
131
  name: string;
@@ -203,8 +136,12 @@ export function buildTextIconMeta(
203
136
  wrapperStyle?: Record<string, any>;
204
137
  } | null;
205
138
 
206
- export function buildRenderData (
139
+ export function handleSpecialFields(data: { user: Record<string, any> }): {
140
+ user: Record<string, any>;
141
+ };
142
+
143
+
144
+ export function processCardLayout(
207
145
  layout: CardLayoutSchema[],
208
- items: TemplateItem[],
209
- config: Config
210
- ): CardLayoutSchema[];
146
+ data: Data
147
+ ): CardLayoutSchema[];
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,209 +0,0 @@
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, _e;
85
- const icon = el.icon;
86
- const enabled = (icon === null || icon === void 0 ? void 0 : icon.enable) === true;
87
- if (!icon || !enabled)
88
- return undefined;
89
- const style = icon.style || 'fill';
90
- const baseName = icon.name || el.key || el.binding || el.id;
91
- let name;
92
- if (style === 'dot')
93
- name = 'round';
94
- else if (style === 'line')
95
- name = baseName ? `${baseName}-line` : undefined;
96
- else
97
- name = baseName || undefined;
98
- if (!name)
99
- return undefined;
100
- const size = icon.size !== undefined && icon.size !== null
101
- ? icon.size
102
- : (_a = el.style) === null || _a === void 0 ? void 0 : _a.fontSize;
103
- const gap = icon.gap !== undefined && icon.gap !== null ? icon.gap : 4;
104
- 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);
105
- return {
106
- name: `${name}`,
107
- text: `${name}`,
108
- size: (0, helpers_1.addUnit)(size, unit),
109
- gap: (0, helpers_1.addUnit)(gap, unit),
110
- color: color,
111
- align: icon.align || 'left',
112
- wrapperStyle: (0, helpers_1.styleObjectToString)({
113
- height: ((_d = el.style) === null || _d === void 0 ? void 0 : _d.lineHeight) || ((_e = el.style) === null || _e === void 0 ? void 0 : _e.fontSize),
114
- }, unit),
115
- };
116
- };
117
- const buildNode = (el, rootData, unit, context) => {
118
- var _a, _b, _c, _d, _e, _f, _g, _h;
119
- if (!el || el.visible === false)
120
- return null;
121
- const wrapperStyle = buildWrapperStyle(el, unit);
122
- if (el.type === 'layout-panel') {
123
- return {
124
- id: el.id,
125
- type: el.type,
126
- visible: el.visible,
127
- wrapperStyle,
128
- contentStyle: buildPanelContentStyle(el, unit),
129
- children: (0, exports.buildRenderNodes)(el.children || [], rootData, unit, context),
130
- };
131
- }
132
- const baseStyle = buildBaseContentStyle(el, unit);
133
- if (el.type === 'text') {
134
- const value = (_b = (_a = (0, data_1.resolveBindingValue)(el.binding, rootData, context)) !== null && _a !== void 0 ? _a : el.defaultValue) !== null && _b !== void 0 ? _b : '';
135
- return {
136
- id: el.id,
137
- type: el.type,
138
- wrapperStyle,
139
- contentStyle: buildTextContentStyle(el, unit),
140
- text: `${value}`,
141
- visible: el.visible,
142
- icon: buildTextIcon(el, unit),
143
- };
144
- }
145
- if (el.type === 'image') {
146
- 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 : '';
147
- const mode = el.fit === 'contain' ? 'aspectFit' : 'aspectFill';
148
- return {
149
- id: el.id,
150
- type: el.type,
151
- wrapperStyle,
152
- contentStyle: buildImageContentStyle(el, unit),
153
- src,
154
- mode,
155
- visible: el.visible,
156
- };
157
- }
158
- if (el.type === 'icon') {
159
- 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 : '';
160
- return {
161
- id: el.id,
162
- type: el.type,
163
- wrapperStyle,
164
- contentStyle: baseStyle,
165
- name: `${name}`,
166
- text: `${name}`,
167
- visible: el.visible,
168
- };
169
- }
170
- if (el.type === 'custom') {
171
- return {
172
- id: el.id,
173
- type: el.type,
174
- wrapperStyle,
175
- contentStyle: baseStyle,
176
- visible: el.visible,
177
- };
178
- }
179
- return null;
180
- };
181
- const buildRenderNodes = (children, rootData, unit = 'px', context = {}) => {
182
- if (!Array.isArray(children))
183
- return [];
184
- const nodes = [];
185
- children.forEach(el => {
186
- if (!el || el.visible === false)
187
- return;
188
- const node = buildNode(el, rootData, unit, context);
189
- if (node)
190
- nodes.push(node);
191
- });
192
- return nodes;
193
- };
194
- exports.buildRenderNodes = buildRenderNodes;
195
- const buildRenderResult = (layoutInput, dataInput, unit = 'px') => {
196
- const layouts = (0, layout_1.normalizeLayout)(layoutInput);
197
- return layouts.map(layout => {
198
- const cardStyle = buildCardStyle(layout, unit);
199
- const bgStyle = buildBackgroundStyle(layout, unit);
200
- const renderTree = (0, exports.buildRenderNodes)(layout.children || [], dataInput || {}, unit);
201
- return {
202
- renderTree,
203
- cardStyle,
204
- backgroundImage: layout.backgroundImage || '',
205
- backgroundStyle: bgStyle,
206
- };
207
- });
208
- };
209
- exports.buildRenderResult = buildRenderResult;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildRenderData = buildRenderData;
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
- }
package/dist/utils.js DELETED
@@ -1,25 +0,0 @@
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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
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/render/tool.ts DELETED
@@ -1,21 +0,0 @@
1
- import { CardLayoutSchema, TemplateItem } from '../interface';
2
- import { backgroundChange, setElementVisible } from '../ops/changeBackground';
3
- import { Config } from '../types';
4
- import { applyItemCollectBindings } from '../utils';
5
-
6
- export function buildRenderData(
7
- layout: CardLayoutSchema[],
8
- items: TemplateItem[],
9
- config: Config
10
- ): CardLayoutSchema[] {
11
- // 绑定数据
12
- let renderLayout = applyItemCollectBindings(layout, items);
13
- // 设置显示逻辑
14
- renderLayout = setElementVisible(renderLayout, 'image', config.showAvatar);
15
- renderLayout = setElementVisible(renderLayout, 'logo', config.showLogo);
16
- // 设置背景
17
- renderLayout = renderLayout.map((la, index) =>
18
- config.currentBg[index] ? backgroundChange(config.currentBg[index], la) : la
19
- );
20
- return renderLayout;
21
- }
package/utils.ts DELETED
@@ -1,13 +0,0 @@
1
-
2
-
3
- export * from './bindings';
4
- export {
5
- backgroundChange,
6
- applySpecialStyle,
7
- applyBackground,
8
- updateElementsStyle,
9
- resolveSpecialStyle,
10
- DEFAULT_DECOR_COLOR,
11
- } from './ops/changeBackground';
12
-
13
-