@mpxjs/webpack-plugin 2.10.18-beta.10 → 2.10.18-beta.11

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.
@@ -1,5 +1,11 @@
1
1
  <script>
2
2
  import mpx from '@mpxjs/core'
3
+
4
+ const isIOS = /iP(hone|od|ad)/.test(navigator.userAgent)
5
+ const innerHeight = (isIOS ? 44 : 48) + 'px'
6
+
7
+ const safeStyle = { paddingTop: 'var(--safe-area-inset-top)' }
8
+
3
9
  export default {
4
10
  name: 'mpx-titlebar',
5
11
  props: {
@@ -16,32 +22,32 @@ export default {
16
22
  },
17
23
  computed: {
18
24
  // 合并全局 window 配置与页面配置(页面配置覆盖全局配置)
19
- cfg () {
25
+ cfg() {
20
26
  return Object.assign({}, this.windowConfig || {}, this.pageConfig || {})
21
27
  },
22
28
  // 标题文本(兼容常见字段名)
23
- titleText () {
29
+ titleText() {
24
30
  return this.cfg.navigationBarTitleText || this.cfg.title || ''
25
31
  },
26
32
  // 背景色(兼容常见字段)
27
- backgroundColor () {
33
+ backgroundColor() {
28
34
  return this.cfg.navigationBarBackgroundColor || '#ffffff'
29
35
  },
30
36
  // 文本颜色,微信小程序中 navigationBarTextStyle 为 white 或 black
31
- textColor () {
37
+ textColor() {
32
38
  const style = this.cfg.navigationBarTextStyle || 'black'
33
39
  return style === 'white' ? '#ffffff' : '#000000'
34
40
  },
35
41
  // navigationStyle: 'default' | 'custom',custom 表示需要自定义绘制
36
- navigationStyle () {
42
+ navigationStyle() {
37
43
  return this.cfg.navigationStyle || 'default'
38
44
  },
39
45
  // 是否隐藏(navigationStyle 为 'custom' 时也应隐藏)
40
- hidden () {
46
+ hidden() {
41
47
  return mpx.config?.webConfig?.enableTitleBar !== true || this.navigationStyle === 'custom'
42
48
  },
43
49
  // 是否展示返回按钮:根据浏览器历史判断(不依赖额外 page 配置)
44
- showBack () {
50
+ showBack() {
45
51
  console.log('showBack', this.$router.stack.length)
46
52
  try {
47
53
  return this.$router.stack.length > 1
@@ -49,52 +55,42 @@ export default {
49
55
  return false
50
56
  }
51
57
  },
52
- // safe area 顶部 padding,使用 env(safe-area-inset-top)
53
- safeStyle () {
54
- // 多数浏览器支持 env(), 为兼容也使用 constant() 备选(旧 iOS Safari)
55
- return {
56
- paddingTop: 'env(safe-area-inset-top, 0px)'
58
+ // 安卓安全高度
59
+ safeAreaInsetTop() {
60
+ if (typeof mpx.config.webConfig.safeAreaInsetTop === 'number' && mpx.config.webConfig.safeAreaInsetTop >= 0) {
61
+ return mpx.config.webConfig.safeAreaInsetTop
57
62
  }
63
+ return 24
58
64
  },
59
- // 内部标题栏高度(遵循小程序常见平台差异)
60
- innerHeight () {
61
- const isIOS = /iP(hone|od|ad)/.test(navigator.userAgent)
62
- return (isIOS ? 44 : 48) + 'px'
65
+ warpStyle() {
66
+ return {
67
+ '--titlebar-height': innerHeight,
68
+ '--safe-area-inset-top': `${isIOS ? 'env(safe-area-inset-top, constant(safe-area-inset-top), 0px)' : this.safeAreaInsetTop + 'px'}`,
69
+ paddingTop: 'calc(var(--safe-area-inset-top) + var(--titlebar-height))',
70
+ }
63
71
  },
64
- rootStyle () {
72
+ rootStyle() {
65
73
  return {
66
74
  background: this.backgroundColor,
67
75
  color: this.textColor
68
76
  }
69
77
  },
70
- innerStyle () {
71
- return {
72
- height: this.innerHeight
73
- }
74
- }
75
- ,
76
- // content wrapper style: padding-top to avoid being covered by fixed titlebar
77
- contentStyle () {
78
- // use calc to combine innerHeight and safe-area inset
78
+ innerStyle() {
79
79
  return {
80
- paddingTop: this.hidden ? '0px' : `calc(${this.innerHeight} + env(safe-area-inset-top, 0px))`,
81
- // create its own layer to avoid overlapping issues
82
- transform: 'translateZ(0)',
83
- willChange: 'transform'
80
+ height: innerHeight
84
81
  }
85
82
  }
86
83
  },
87
84
  methods: {
88
85
  // 左侧点击:派发事件并在可回退时回退
89
- onLeftClick (e) {
86
+ onLeftClick(e) {
90
87
  this.$emit('click-left', e)
91
88
  if (this.showBack) {
92
- try { window.history.back() } catch (err) {}
89
+ try { window.history.back() } catch (err) { }
93
90
  }
94
91
  }
95
92
  },
96
- render (h) {
97
- console.log('render mpx-titlebar', this.cfg, 'windowConfig', this.windowConfig, 'pageConfig', this.pageConfig)
93
+ render(h) {
98
94
  const leftChildren = []
99
95
 
100
96
  // default back button (SVG) — no left slot support
@@ -134,43 +130,42 @@ export default {
134
130
  h('div', { class: 'mpx-titlebar__title', style: { color: this.textColor } }, [this.titleText])
135
131
  ]
136
132
 
137
- // top-level wrapper: contains fixed titlebar and page content wrapper
138
- return h('page', { class: 'mpx-titlebar-wrapper' }, [
139
- // fixed titlebar
140
- h('div', {
141
- class: ['mpx-titlebar', { 'mpx-titlebar--hidden': this.hidden }],
133
+ // top-level wrapper: contains fixed titlebar and page content wrapper
134
+ return h('div', { class: 'mpx-page-warp', style: this.hidden ? {} : this.warpStyle }, [
135
+ this.hidden ? null : h('div', {
136
+ class: ['mpx-titlebar'],
142
137
  style: this.rootStyle
143
138
  }, [
144
- h('div', { class: 'mpx-titlebar__safe', style: this.safeStyle }, [
139
+ h('div', { class: 'mpx-titlebar__safe', style: safeStyle }, [
145
140
  h('div', { class: 'mpx-titlebar__inner', style: this.innerStyle }, [
146
- h('div', { class: 'mpx-titlebar__left', on: { click: this.onLeftClick } }, leftChildren),
147
- h('div', { class: 'mpx-titlebar__center' }, centerChildren),
148
- h('div', { class: 'mpx-titlebar__right' }, [])
141
+ h('div', { class: 'mpx-titlebar__left', on: { click: this.onLeftClick } }, leftChildren),
142
+ h('div', { class: 'mpx-titlebar__center' }, centerChildren),
143
+ h('div', { class: 'mpx-titlebar__right' }, [])
149
144
  ])
150
145
  ])
151
146
  ]),
152
-
153
- // page content wrapper: default slot is page content
154
- h('div', { class: 'mpx-titlebar__content', style: this.contentStyle }, this.$slots.default || [])
147
+ h('page', { style: { position: 'relative'} }, [this.$slots.default])
155
148
  ])
156
149
  }
157
150
  }
158
151
  </script>
159
152
 
160
153
  <style scoped>
161
- .mpx-titlebar {
154
+ .mpx-page-warp {
162
155
  width: 100%;
156
+ height: 100%;
163
157
  box-sizing: border-box;
164
- -webkit-font-smoothing: antialiased;
165
158
  }
159
+
160
+
166
161
  .mpx-titlebar--hidden {
167
162
  display: none;
168
163
  }
164
+
169
165
  .mpx-titlebar__safe {
170
- /* safe area handled by padding-top; include both env and constant for broader iOS support */
171
- padding-top: env(safe-area-inset-top, 0px);
172
- padding-top: constant(safe-area-inset-top, 0px);
166
+ padding-top: var(--safe-area-inset-top);
173
167
  }
168
+
174
169
  .mpx-titlebar__inner {
175
170
  display: flex;
176
171
  align-items: center;
@@ -178,6 +173,7 @@ export default {
178
173
  padding: 0 12px;
179
174
  box-sizing: border-box;
180
175
  }
176
+
181
177
  .mpx-titlebar__left,
182
178
  .mpx-titlebar__right {
183
179
  flex: 0 0 auto;
@@ -185,6 +181,7 @@ export default {
185
181
  display: flex;
186
182
  align-items: center;
187
183
  }
184
+
188
185
  .mpx-titlebar__center {
189
186
  flex: 1 1 auto;
190
187
  display: flex;
@@ -193,6 +190,7 @@ export default {
193
190
  overflow: hidden;
194
191
  padding: 0 8px;
195
192
  }
193
+
196
194
  .mpx-titlebar__title {
197
195
  font-size: 17px;
198
196
  white-space: nowrap;
@@ -200,6 +198,7 @@ export default {
200
198
  overflow: hidden;
201
199
  font-weight: 500;
202
200
  }
201
+
203
202
  .mpx-titlebar__back {
204
203
  background: none;
205
204
  border: none;
@@ -209,27 +208,31 @@ export default {
209
208
  cursor: pointer;
210
209
  }
211
210
 
212
- /* wrapper and content layout */
213
- .mpx-titlebar-wrapper {
214
- position: relative;
215
- width: 100%;
216
- height: 100%;
217
- }
218
-
219
211
  .mpx-titlebar {
212
+ /* flex-shrink: 0; */
213
+ height: calc(var(--safe-area-inset-top) + var(--titlebar-height));
214
+ width: 100%;
215
+ box-sizing: border-box;
216
+ -webkit-font-smoothing: antialiased;
220
217
  position: fixed;
221
218
  top: 0;
222
219
  left: 0;
223
220
  right: 0;
224
- z-index: 1000; /* ensure above page content */
221
+ z-index: 99999;
222
+ /* 脱离上下文,单独渲染加速,修复安卓低端机型在页面滚动时titlebar闪烁问题 */
223
+ transform: translateZ(0);
225
224
  }
226
225
 
227
226
  .mpx-titlebar__content {
228
- position: relative;
227
+ flex: 1;
228
+ overflow: hidden;
229
+ transform: translateZ(0);
230
+ }
231
+
232
+ .mpx-titlebar__scroll {
229
233
  width: 100%;
230
- min-height: 100%;
231
- box-sizing: border-box;
232
- background: transparent;
234
+ height: 100%;
235
+ overflow: auto;
233
236
  }
234
237
 
235
238
  /* SVG icon sizing and inherit color */
@@ -238,6 +241,7 @@ export default {
238
241
  width: 20px;
239
242
  height: 20px;
240
243
  }
244
+
241
245
  .mpx-titlebar__back path {
242
246
  stroke: currentColor;
243
247
  }
@@ -2616,78 +2616,6 @@ function postProcessAliComponentRootView (el, options, meta) {
2616
2616
  }
2617
2617
  }
2618
2618
 
2619
- function getWebTitleBarContainer(root, options, meta) {
2620
- // titlebar 容器(替代 .wx-titlebar)
2621
- const titlebarStyle = 'position:fixed;top:0;left:0;right:0;width:100%;box-sizing:border-box;z-index:99999;background-color:#ffffff;height:calc(44px + env(safe-area-inset-top, 0px));padding-top:env(safe-area-inset-top, 0px);display:flex;align-items:center;justify-content:center;user-select:none;'
2622
- const titlebar = createASTElement('view', [
2623
- { name: 'style', value: titlebarStyle },
2624
- { name: 'wx:if', value: '{{($options?.__mpxPageConfig?.navigationStyle || global?.__mpxPageConfig?.navigationStyle) !== "custom"}}' }
2625
- ])
2626
-
2627
- // 左侧返回按钮容器(替代 .wx-titlebar__left)
2628
- const leftStyle = 'position:absolute;left:12px;top:env(safe-area-inset-top, 0px);height:44px;display:flex;align-items:center;cursor:pointer;opacity:0.9;transition:opacity 0.15s;'
2629
- const left = createASTElement('view', [
2630
- { name: 'style', value: leftStyle },
2631
- { name: '@tap', value: '() => this.$router.back()' }
2632
- ])
2633
-
2634
- // svg 图标(替代 .wx-titlebar__back-icon)
2635
- const svg = createASTElement('svg', [
2636
- { name: 'style', value: 'width:18px;height:18px;fill:#000;' },
2637
- { name: 'viewBox', value: '0 0 1024 1024' }
2638
- ])
2639
-
2640
- const path = createASTElement('path', [
2641
- { name: 'd', value: 'M621.6 170.4L408.8 384l212.8 213.6-59.2 59.2L290.4 384 562.4 111.2z' }
2642
- ])
2643
-
2644
- // 标题(替代 .wx-titlebar__title)
2645
- const titleStyle = 'font-size:17px;font-weight:500;color:#111;line-height:44px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:70%;text-align:center;'
2646
- const title = createASTElement('view', [
2647
- { name: 'style', value: titleStyle }
2648
- ])
2649
-
2650
- const text = {
2651
- type: 3,
2652
- // 支付宝小程序模板解析中未对Mustache进行特殊处理,无论是否decode都会解析失败,无解,只能支付宝侧进行修复
2653
- text: '{{$options.__mpxPageConfig.navigationBarTitleText}}'
2654
- }
2655
-
2656
- // 页面内容容器(替代 .page-content),并保留原始内部 transform
2657
- const contentStyle = 'transform: translateX(0);margin-top:calc(44px + env(safe-area-inset-top, 0px));padding:16px;'
2658
- const content = createASTElement('view', [
2659
- { name: 'style', value: contentStyle }
2660
- ])
2661
-
2662
- // 组装节点树
2663
- addChild(svg, path)
2664
- addChild(left, svg)
2665
-
2666
- addChild(title, text)
2667
-
2668
- addChild(titlebar, left)
2669
- addChild(titlebar, title)
2670
-
2671
- addChild(root, titlebar)
2672
- addChild(root, content)
2673
-
2674
- // processElement(root, root, options, meta)
2675
- processElement(titlebar, root, options, meta)
2676
- closeElement(titlebar, options, meta)
2677
- processElement(left, root, options, meta)
2678
- // closeElement(left, options, meta)
2679
- processElement(svg, root, options, meta)
2680
- processElement(path, root, options, meta)
2681
- processElement(title, root, options, meta)
2682
- processElement(content, root, options, meta)
2683
- processText(text, options, meta)
2684
-
2685
- return {
2686
- content,
2687
- titlebar
2688
- }
2689
- }
2690
-
2691
2619
  // 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
2692
2620
  function getVirtualHostRoot (options, meta) {
2693
2621
  if (srcMode === 'wx') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.18-beta.10",
3
+ "version": "2.10.18-beta.11",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"