km-card-layout-core 0.1.6 → 0.1.7

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/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/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.7",
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
@@ -14,13 +14,6 @@ import type {
14
14
  RenderResult,
15
15
  } from './interface';
16
16
 
17
- export type ItemCollectMeta = {
18
- id: string | number;
19
- bind?: string | null;
20
- default?: string | null;
21
- key?: string | null;
22
- };
23
-
24
17
  export function addUnit(
25
18
  value: string | number | undefined | null,
26
19
  unit: 'px' | 'rpx'
@@ -45,7 +38,7 @@ export function stripLayoutBindings(
45
38
 
46
39
  export function applyItemCollectBindings(
47
40
  layouts: CardLayoutSchema[],
48
- items?: ItemCollectMeta[]
41
+ items?: TemplateItem[]
49
42
  ): CardLayoutSchema[];
50
43
 
51
44
  export function buildRenderNodes(
@@ -60,3 +53,7 @@ export function buildRenderResult(
60
53
  data: Record<string, any>,
61
54
  unit?: 'px' | 'rpx'
62
55
  ): RenderResult;
56
+
57
+ export function getTemplateItems(ids: string, items: TemplateItem[]): TemplateItem[];
58
+
59
+ 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
  }