km-card-layout-component-miniprogram 0.1.17 → 0.1.19

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.
Files changed (36) hide show
  1. package/miniprogram_dist/components/card-layout/elements/custom-element/index.wxml +6 -4
  2. package/miniprogram_dist/components/card-layout/elements/icon-element/index.wxml +6 -4
  3. package/miniprogram_dist/components/card-layout/elements/image-element/index.wxml +10 -8
  4. package/miniprogram_dist/components/card-layout/elements/text-element/index.wxml +2 -0
  5. package/miniprogram_dist/components/card-layout/elements/text-element/index.wxss +0 -4
  6. package/miniprogram_dist/components/card-layout/index.js +83 -15
  7. package/miniprogram_dist/components/card-layout/index.json +1 -7
  8. package/miniprogram_dist/components/card-layout/index.wxml +21 -4
  9. package/miniprogram_dist/components/card-layout/index.wxss +83 -0
  10. package/miniprogram_dist/vendor/wxml2canvas-2d/canvas.js +1116 -0
  11. package/miniprogram_dist/vendor/wxml2canvas-2d/constants.js +42 -0
  12. package/miniprogram_dist/vendor/wxml2canvas-2d/element.js +420 -0
  13. package/miniprogram_dist/vendor/wxml2canvas-2d/gradient.js +634 -0
  14. package/miniprogram_dist/vendor/wxml2canvas-2d/index.js +169 -0
  15. package/miniprogram_dist/vendor/wxml2canvas-2d/index.json +4 -0
  16. package/miniprogram_dist/vendor/wxml2canvas-2d/index.wxml +7 -0
  17. package/miniprogram_dist/vendor/wxml2canvas-2d/index.wxss +5 -0
  18. package/package.json +1 -1
  19. package/src/components/card-layout/elements/custom-element/index.wxml +6 -4
  20. package/src/components/card-layout/elements/icon-element/index.wxml +6 -4
  21. package/src/components/card-layout/elements/image-element/index.wxml +10 -8
  22. package/src/components/card-layout/elements/text-element/index.wxml +2 -0
  23. package/src/components/card-layout/elements/text-element/index.wxss +0 -4
  24. package/src/components/card-layout/index.json +1 -7
  25. package/src/components/card-layout/index.ts +108 -16
  26. package/src/components/card-layout/index.wxml +21 -4
  27. package/src/components/card-layout/index.wxss +83 -0
  28. package/src/vendor/km-card-layout-core/types.d.ts +7 -1
  29. package/src/vendor/wxml2canvas-2d/canvas.js +1116 -0
  30. package/src/vendor/wxml2canvas-2d/constants.js +42 -0
  31. package/src/vendor/wxml2canvas-2d/element.js +420 -0
  32. package/src/vendor/wxml2canvas-2d/gradient.js +634 -0
  33. package/src/vendor/wxml2canvas-2d/index.js +169 -0
  34. package/src/vendor/wxml2canvas-2d/index.json +4 -0
  35. package/src/vendor/wxml2canvas-2d/index.wxml +7 -0
  36. package/src/vendor/wxml2canvas-2d/index.wxss +5 -0
@@ -1,5 +1,7 @@
1
- <view class="km-node km-node--custom" style="{{wrapperStyle}}">
2
- <view class="km-node__custom" style="{{contentStyle}}">
3
- <slot name="{{element.id}}"></slot>
1
+ <template name="custom-element">
2
+ <view class="km-node km-node--custom" style="{{wrapperStyle}}">
3
+ <view class="km-node__custom" style="{{contentStyle}}">
4
+ <slot name="{{element.id}}"></slot>
5
+ </view>
4
6
  </view>
5
- </view>
7
+ </template>
@@ -1,5 +1,7 @@
1
- <view class="km-node km-node--icon" style="{{wrapperStyle}}">
2
- <view class="km-node__icon icon" style="{{contentStyle}}">
3
- {{iconText}}
1
+ <template name="icon-element">
2
+ <view class="km-node km-node--icon" style="{{wrapperStyle}}">
3
+ <view class="km-node__icon icon" style="{{contentStyle}}">
4
+ {{iconText}}
5
+ </view>
4
6
  </view>
5
- </view>
7
+ </template>
@@ -1,8 +1,10 @@
1
- <view class="km-node" style="{{wrapperStyle}}">
2
- <image
3
- class="km-node__image"
4
- style="{{contentStyle}}"
5
- src="{{imageSrc}}"
6
- mode="{{mode}}"
7
- />
8
- </view>
1
+ <template name="image-element">
2
+ <view class="km-node" style="{{wrapperStyle}}">
3
+ <image
4
+ class="km-node__image"
5
+ style="{{contentStyle}}"
6
+ src="{{imageSrc}}"
7
+ mode="{{mode}}"
8
+ />
9
+ </view>
10
+ </template>
@@ -1,3 +1,4 @@
1
+ <template name="text-element">
1
2
  <view class="km-node km-node--text" style="{{wrapperStyle}}">
2
3
  <view class="km-node__text" style="{{contentStyle}}">
3
4
  <block wx:if="{{(iconMeta && (iconMeta.name || iconMeta.text)) && (element.icon && element.icon.style !== 'text')}}">
@@ -40,3 +41,4 @@
40
41
  </block>
41
42
  </view>
42
43
  </view>
44
+ </template>
@@ -3,10 +3,6 @@
3
3
  color: inherit;
4
4
  }
5
5
 
6
- .km-node--text {
7
- /* overflow hidden if needed */
8
- }
9
-
10
6
  .km-node--text text {
11
7
  display: inline;
12
8
  }
@@ -2,6 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasCompanyDutyKey = exports.normalizeMoreCompany = void 0;
4
4
  const index_1 = require("../../vendor/km-card-layout-core/index");
5
+ const icon_map_1 = require("./icon-map");
6
+ const mapIconGlyph = (name, fallback) => {
7
+ if (!name)
8
+ return fallback;
9
+ const glyph = icon_map_1.ICON_CODE_MAP[name];
10
+ if (glyph)
11
+ return String.fromCharCode(parseInt(glyph, 16));
12
+ return fallback || name;
13
+ };
5
14
  const EMPTY_COMPANY_DUTY = {
6
15
  company: '',
7
16
  duty: '',
@@ -67,25 +76,84 @@ const pickCardId = (layout, idx) => {
67
76
  return layout.name || layout.id;
68
77
  return `card-${idx}`;
69
78
  };
70
- const decorateElements = (children = []) => (children || []).map(el => {
71
- if (el.type === 'layout-panel') {
72
- const panel = el;
73
- return {
74
- ...panel,
75
- wrapperStyle: (0, index_1.styleObjectToString)((0, index_1.buildWrapperStyle)(panel, 'rpx'), 'rpx'),
76
- contentStyle: (0, index_1.styleObjectToString)((0, index_1.buildPanelContentStyle)(panel, 'rpx'), 'rpx'),
77
- children: decorateElements(panel.children || []),
78
- };
79
- }
80
- return el;
81
- });
82
- const buildCards = (layouts) => {
79
+ const decorateElements = (children = [], rootData) => {
80
+ const data = rootData || {};
81
+ return (children || []).map(el => {
82
+ const wrapperStyle = (0, index_1.styleObjectToString)((0, index_1.buildWrapperStyle)(el, 'rpx'), 'rpx');
83
+ switch (el.type) {
84
+ case 'layout-panel': {
85
+ const panel = el;
86
+ return {
87
+ ...panel,
88
+ wrapperStyle,
89
+ contentStyle: (0, index_1.styleObjectToString)((0, index_1.buildPanelContentStyle)(panel, 'rpx'), 'rpx'),
90
+ children: decorateElements(panel.children || [], rootData),
91
+ };
92
+ }
93
+ case 'image': {
94
+ const imageEl = el;
95
+ const contentStyle = (0, index_1.styleObjectToString)((0, index_1.buildImageContentStyle)(imageEl), 'rpx');
96
+ const imageSrc = (0, index_1.getImageSrc)(imageEl, data);
97
+ const mode = imageEl.fit === 'contain' ? 'aspectFit' : 'aspectFill';
98
+ return {
99
+ ...imageEl,
100
+ wrapperStyle,
101
+ contentStyle,
102
+ imageSrc,
103
+ mode,
104
+ };
105
+ }
106
+ case 'icon': {
107
+ const iconEl = el;
108
+ const contentStyle = (0, index_1.styleObjectToString)((0, index_1.buildBaseContentStyle)(iconEl), 'rpx');
109
+ const name = (0, index_1.getIconName)(iconEl);
110
+ const iconText = mapIconGlyph(name, name || '');
111
+ return {
112
+ ...iconEl,
113
+ wrapperStyle,
114
+ contentStyle,
115
+ iconText,
116
+ };
117
+ }
118
+ case 'custom': {
119
+ const customEl = el;
120
+ const contentStyle = (0, index_1.styleObjectToString)((0, index_1.buildBaseContentStyle)(customEl), 'rpx');
121
+ return {
122
+ ...customEl,
123
+ wrapperStyle,
124
+ contentStyle,
125
+ };
126
+ }
127
+ default: {
128
+ const textEl = el;
129
+ const contentStyle = (0, index_1.styleObjectToString)((0, index_1.buildTextContentStyle)(textEl, 'rpx'), 'rpx');
130
+ const textValue = (0, index_1.getTextValue)(textEl, data);
131
+ const iconRaw = (0, index_1.buildTextIconMeta)(textEl, 'rpx');
132
+ const iconMeta = iconRaw && iconRaw.name
133
+ ? {
134
+ ...iconRaw,
135
+ text: mapIconGlyph(iconRaw.name, iconRaw.name),
136
+ wrapperStyle: (0, index_1.styleObjectToString)(iconRaw.wrapperStyle, 'rpx'),
137
+ }
138
+ : iconRaw;
139
+ return {
140
+ ...textEl,
141
+ wrapperStyle,
142
+ contentStyle,
143
+ textValue,
144
+ iconMeta,
145
+ };
146
+ }
147
+ }
148
+ });
149
+ };
150
+ const buildCards = (layouts, rootData) => {
83
151
  return layouts.map((layout, idx) => ({
84
152
  id: pickCardId(layouts[idx], idx),
85
153
  cardStyle: (0, index_1.styleObjectToString)((0, index_1.buildCardStyle)(layout, 'rpx'), 'rpx'),
86
154
  backgroundImage: layout.backgroundImage || '',
87
155
  backgroundStyle: (0, index_1.styleObjectToString)((0, index_1.buildBackgroundStyle)(layout, 'rpx'), 'rpx'),
88
- elements: decorateElements(layout.children || []),
156
+ elements: decorateElements(layout.children || [], rootData),
89
157
  }));
90
158
  };
91
159
  const hasCompanyDutyKey = (schemas) => {
@@ -155,7 +223,7 @@ Component({
155
223
  return;
156
224
  }
157
225
  const normalizedLayouts = (0, index_1.normalizeLayout)(layoutInput);
158
- const cards = buildCards(normalizedLayouts);
226
+ const cards = buildCards(normalizedLayouts, rootData);
159
227
  this.setData({ cards, rootData });
160
228
  },
161
229
  },
@@ -1,9 +1,3 @@
1
1
  {
2
- "component": true,
3
- "usingComponents": {
4
- "text-element": "./elements/text-element/index",
5
- "image-element": "./elements/image-element/index",
6
- "icon-element": "./elements/icon-element/index",
7
- "custom-element": "./elements/custom-element/index"
8
- }
2
+ "component": true
9
3
  }
@@ -1,3 +1,8 @@
1
+ <import src="./elements/custom-element/index.wxml" />
2
+ <import src="./elements/icon-element/index.wxml" />
3
+ <import src="./elements/image-element/index.wxml" />
4
+ <import src="./elements/text-element/index.wxml" />
5
+
1
6
  <view class="km-card-layout">
2
7
  <block wx:for="{{cards}}" wx:key="id">
3
8
  <view class="km-card-layout__item">
@@ -19,10 +24,16 @@
19
24
 
20
25
  <template name="render-element">
21
26
  <block wx:if="{{el.type === 'image'}}">
22
- <image-element element="{{el}}" rootData="{{rootData}}" />
27
+ <template
28
+ is="image-element"
29
+ data="{{wrapperStyle: el.wrapperStyle, contentStyle: el.contentStyle, imageSrc: el.imageSrc, mode: el.mode}}"
30
+ />
23
31
  </block>
24
32
  <block wx:elif="{{el.type === 'icon'}}">
25
- <icon-element element="{{el}}" rootData="{{rootData}}" />
33
+ <template
34
+ is="icon-element"
35
+ data="{{wrapperStyle: el.wrapperStyle, contentStyle: el.contentStyle, iconText: el.iconText}}"
36
+ />
26
37
  </block>
27
38
  <block wx:elif="{{el.type === 'layout-panel'}}">
28
39
  <view class="km-node" style="{{el.wrapperStyle}}">
@@ -34,9 +45,15 @@
34
45
  </view>
35
46
  </block>
36
47
  <block wx:elif="{{el.type === 'custom'}}">
37
- <custom-element element="{{el}}" rootData="{{rootData}}" />
48
+ <template
49
+ is="custom-element"
50
+ data="{{wrapperStyle: el.wrapperStyle, contentStyle: el.contentStyle, element: el}}"
51
+ />
38
52
  </block>
39
53
  <block wx:else>
40
- <text-element element="{{el}}" rootData="{{rootData}}" />
54
+ <template
55
+ is="text-element"
56
+ data="{{wrapperStyle: el.wrapperStyle, contentStyle: el.contentStyle, textValue: el.textValue, iconMeta: el.iconMeta, element: el}}"
57
+ />
41
58
  </block>
42
59
  </template>
@@ -36,7 +36,90 @@
36
36
  box-sizing: border-box;
37
37
  }
38
38
 
39
+ .km-node__image {
40
+ width: 100%;
41
+ height: 100%;
42
+ display: block;
43
+ }
44
+
45
+ .km-node--text text {
46
+ display: inline;
47
+ }
48
+
49
+ .km-node__text {
50
+ width: 100%;
51
+ height: 100%;
52
+ display: block;
53
+ box-sizing: border-box;
54
+ text-align: inherit;
55
+ }
56
+
57
+ .km-node__text-content {
58
+ display: inline-block;
59
+ vertical-align: middle;
60
+ height: 100%;
61
+ }
62
+
63
+ .km-node__text-icon {
64
+ display: inline-flex;
65
+ align-items: center;
66
+ justify-content: center;
67
+ }
68
+
69
+ .km-node__text-value {
70
+ display: inline-block;
71
+ white-space: pre-wrap;
72
+ word-break: break-word;
73
+ vertical-align: middle;
74
+ }
75
+
76
+ .icon {
77
+ font-family: 'km-icon' !important;
78
+ font-size: 16px;
79
+ font-style: normal;
80
+ -webkit-font-smoothing: antialiased;
81
+ -moz-osx-font-smoothing: grayscale;
82
+ }
83
+
84
+ .km-node__text-icon--wrapper{
85
+ display: inline-block;
86
+ }
87
+
88
+
89
+ .km-node--icon {
90
+ display: flex;
91
+ align-items: center;
92
+ justify-content: center;
93
+ }
94
+
95
+ .km-node__icon {
96
+ display: inline-flex;
97
+ align-items: center;
98
+ justify-content: center;
99
+ width: 100%;
100
+ height: 100%;
101
+ font-family: 'km-icon', 'PingFang SC', 'Microsoft Yahei', sans-serif;
102
+ font-style: normal;
103
+ font-weight: normal;
104
+ }
105
+
106
+ .icon {
107
+ font-family: 'km-icon' !important;
108
+ font-size: 16px;
109
+ font-style: normal;
110
+ -webkit-font-smoothing: antialiased;
111
+ -moz-osx-font-smoothing: grayscale;
112
+ }
39
113
 
114
+ .km-node--custom {
115
+ box-sizing: border-box;
116
+ }
117
+
118
+ .km-node__custom {
119
+ width: 100%;
120
+ height: 100%;
121
+ box-sizing: border-box;
122
+ }
40
123
 
41
124
 
42
125